diff options
Diffstat (limited to '.agents/skills')
| -rw-r--r-- | .agents/skills/debug-session/SKILL.md | 76 | ||||
| -rw-r--r-- | .agents/skills/design-discussion/SKILL.md | 64 | ||||
| -rw-r--r-- | .agents/skills/review-changes/SKILL.md | 104 | ||||
| -rw-r--r-- | .agents/skills/review-subsystem/SKILL.md | 71 | ||||
| -rw-r--r-- | .agents/skills/write-tests/SKILL.md | 82 |
5 files changed, 397 insertions, 0 deletions
diff --git a/.agents/skills/debug-session/SKILL.md b/.agents/skills/debug-session/SKILL.md new file mode 100644 index 00000000..57ce0cdb --- /dev/null +++ b/.agents/skills/debug-session/SKILL.md @@ -0,0 +1,76 @@ +--- +name: debug-session +description: Guide hypothesis-driven debugging of a TeachOS problem: a failing host test or sanitizer report, a QEMU boot hang, triple fault or reset loop, or unexpected kernel behavior. Coaches the investigation and explains root causes. Does not edit code or hand over the fix. +--- + +# Debug session + +Mentor mode applies (AGENTS.md §1). +You can't edit production code, including temporary debug prints. +The human adds instrumentation and applies the fix. +Your job is to make the investigation efficient and to explain what happened. + +## 1. Pin down the symptom + +Ask for what is missing, one thing at a time: host test or QEMU kernel, build type (Debug and Release behave differently), exact output, whether it is reproducible, and the last known good commit. +Don't speculate before you have the evidence. + +## 2. Collect evidence first + +Host tests: +- failing test name and output (`ctest --preset bht-dbg --output-on-failure -R <name>`); +- sanitizer reports (ASan, LSan, UBSan, and TSan for stress tests): + read the top frames, and note whether they are in kernel code or in test code. +- Host and target differ. + Host tests run against the `test_support` fakes of the architecture layer, so a host pass doesn't prove the kernel works. + +Kernel under QEMU: +- `qemu-debugcon-<Type>.log` (kernel output via the debug console) and `qemu-stderr-<Type>.log` (QEMU's own trace). + The debug run uses `-d int,cpu_reset -no-reboot`, so the stderr log lists exceptions, faulting addresses and resets. + Read the first exception, not the last. +- A GDB session: + the `(gdb) QEMU` launch config connects to `localhost:1234` and loads `kernel.sym`. + The pretty printers in `kapi/gdb` and `scripts/gdb` decode addresses, frames, pages and devices. + `.gdbinit` only loads if the repository is on the autoload safe path. +- Ask the human to run QEMU and share the logs. + Don't start it yourself unless asked. + +## 3. Form hypotheses + +List two to four, ranked. +For each: what it predicts, and the cheapest observation that would separate it from the others. +Ask which one the human suspects and why, then test that one first. +One experiment at a time. + +## 4. Instrument, don't fix + +Suggest where the human could add output (`kstd::println` reaches the debug console), an assertion, a GDB breakpoint or a watchpoint, and say exactly what result confirms or rules out the hypothesis. +Narrow with the help of: +- `git bisect` by commit (the human runs it, it changes the working tree); +- Debug versus Release, sanitizers on or off; +- a minimal reproduction as a host test. + If asked, write it under the write-tests rules. + A failing regression test is a good end state. + +## 5. Typical suspects (check, don't assume) + +- Reset loop or triple fault: stack overflow, bad descriptor tables, a fault while handling a fault, an unmapped address. +- Page fault: read the faulting address and error code, then ask whether it is a missing mapping, a stale TLB entry, or a bad pointer. +- Hang: a lock taken in interrupt context that the interrupted code already holds; interrupts left disabled. +- Corruption: double free in an allocator, use after free, out-of-bounds in a fixed buffer, alignment. +- Works on host, fails on target: a `test_support` fake that behaves differently from the hardware. + +## 6. When the cause is found + +Explain it end to end: the mechanism, why it produced this symptom, and which invariant was broken, with `path:line`. +Then give the direction of the fix and the test that should pin it. +The human writes both. + +## 7. If stuck + +After a few rounds without progress, summarize what has been ruled out, what is still open, and the cheapest next observation. + +Rules: separate observation from inference. +Say how sure you are. +Stop and ask when a needed artifact is missing. +Never run `git checkout`, `reset`, `stash` or `bisect` yourself.
\ No newline at end of file diff --git a/.agents/skills/design-discussion/SKILL.md b/.agents/skills/design-discussion/SKILL.md new file mode 100644 index 00000000..ce5a2384 --- /dev/null +++ b/.agents/skills/design-discussion/SKILL.md @@ -0,0 +1,64 @@ +--- +name: design-discussion +description: Structure a TeachOS design or architecture discussion: choosing between approaches, a new bus, facet, subsystem or interface, a reorganization, or "how should we design X". Produces options with trade-offs, precedent, and a stated position. Discussion only, no implementation. +--- + +# Design discussion + +Mentor mode applies (AGENTS.md §1). +Interface sketches (signatures, data layout in words) are fine. +Complete implementations are not. + +## 1. Frame the decision + +Restate the question in a few sentences: what is being decided, the constraints, and what is not in scope. +Then ask what the person already has in mind, and engage with that first. +Offer your own options up front only if they ask. +Developers learn more from defending a design than from receiving one. + +## 2. Ground it in the repository + +Read the relevant headers, `docs/briefs/` (device-model topics: facets, registries, resources, driver self-registration) and AGENTS.md §4. +Separate: +- what is already decided, and where it is recorded; +- what is open; +- what contradicts itself across documents. Say so; don't pick silently. +Planning documents outside the repo are invisible to you. +If the question touches them, say that and ask. + +## 3. Lay out the real options + +Two to four options that someone could defend, not strawmen. +For each: +- the idea at interface level; +- what it makes easy and what it makes hard; +- fit with existing mechanisms (facets, resources, registries, kapi seam); +- cost for the audience: complexity, teachability, testability on the host; +- reversibility. +A compact table helps when comparing three or more. + +## 4. Precedent, with calibration + +Compare with real systems (Linux, NetBSD, FreeBSD, xnu, Windows, ACPI/UEFI specs). +Label each claim: firmly known, recalled loosely, or not known. +Provide references or links to the sources when possible. +Don't invent function or struct names you aren't sure of. +Say where TeachOS should deliberately differ because it teaches. + +## 5. Take a position + +Recommend one option, say why, and say what would change your mind. +If it is a close call, say so. +If the person disagrees with a precise argument, update. +If you were wrong earlier, say that plainly. + +## 6. Cost of the decision + +What must change in code, tests and docs, and what could go in separate steps. +Name the first small step that tests the idea. + +## 7. Close + +Offer a short written summary of the decision and its reasons. +If the person wants it recorded and it belongs in `docs/` (for example a technical brief), you may draft prose there when asked. +Planning notes that live outside the repo stay there.
\ No newline at end of file diff --git a/.agents/skills/review-changes/SKILL.md b/.agents/skills/review-changes/SKILL.md new file mode 100644 index 00000000..be335c91 --- /dev/null +++ b/.agents/skills/review-changes/SKILL.md @@ -0,0 +1,104 @@ +--- +name: review-changes +description: Review a pending TeachOS change: a branch or merge request against its base, staged changes, or unstaged changes. Use when asked to review a diff, MR, branch, commit range, or "my changes". For auditing existing code with no diff, use review-subsystem instead. +--- + +# Review pending changes + +Mentor mode applies (AGENTS.md §1): report findings and direction, never patches. +Quote at most a few lines of the changed code to point at a problem. +Deliver the report in the conversation. Do not write it to the repository. + +## 1. Pin down the scope + +Ask only if unclear. +State which mode you used and the base you chose. + +- Branch or MR: `git diff <base>...<head>` and `git log --oneline <base>..<head>`. + Base is `origin/develop`, unless the branch belongs to a thesis (see CONTRIBUTING.rst: `<semester>/develop`, e.g. `fa26/develop`). + Then use that branch. + If you can't tell which, ask. +- Staged: `git diff --staged`. +- Unstaged: `git diff`, plus `git status` for untracked files. + Diffs omit new untracked files, so read those directly. +- If several are non-empty, review what was asked and mention the rest. + +Run `git diff --stat` first. +If the change is very large [threshold: ~800 changed lines or ~25 files], say so and propose a reading order (headers, then implementations, then tests) instead of skimming. + +## 2. Establish intent before judging + +Read commit messages and any MR text. +Write 2-3 sentences on what you think the change is for. +If you can't tell, that is your first finding. +Note whether it is a single logical change (CONTRIBUTING.rst asks for that). + +## 3. Read the code, not just the hunks + +For each touched non-test file, read the whole enclosing function or class and the header it implements. +For changed signatures, find callers and implementors with `git grep`. +A review from hunks alone misses most real problems. + +## 4. What to review + +CI covers mechanical style (clang-format, clang-tidy: trailing return types, naming, `enum class`, and so on). +Don't spend findings on those unless the tools were not run. +Lambdas are not covered by the trailing-return check, so glance at them. +Focus on: + +a. Correctness: + Trace the real logic, including error paths, boundary values, integer width and sign, lifetimes and ownership, resource cleanup. +b. Architecture against recorded decisions: + AGENTS.md §4 and `docs/briefs/`. + Flag a change that contradicts or silently extends a documented decision. + If the decision isn't documented, say so. + Don't invent one. +c. Execution context and concurrency: + Who calls this, from which context (boot, thread, interrupt), holding what? + Lock ordering. + RAII guards. +d. Freestanding discipline: + Includes outside the freestanding set, hidden allocation, exceptions or RTTI, large stack objects. +e. Tests: + Is new behavior covered, including edge and error cases? + Do tests check the contract or just mirror the implementation? + Name 2-4 missing cases in prose. +f. Clarity for the audience: + Could a bachelor student follow it? + Naming, function size, comments that explain why, abstractions that earn their keep. +g. Docs: + Does a public interface change appear in `docs/`? + Are doc claims still true? +h. Hygiene: + Moved or renamed files: is CMake updated? + Debug leftovers, commented-out code, unowned TODOs, unrelated changes mixed in. + Commit messages against `subsystem: imperative summary`. + Critique only, no rewrites. + +Detection helpers (read-only, limit to changed files): +- Layering: `git grep -nE '\b(asm|__asm__)\b|rdmsr|wrmsr' -- kernel libs` +- Banned machinery: `git grep -nE 'dynamic_cast|typeid|\bthrow\b|friend '` +- Hosted headers outside tests: `git grep -nE '#include <(vector|memory|string|map|iostream)>'` + +## 5. Verify what you can + +Build out of tree and run the host tests (`cmake --preset bht`, `cmake --build --preset bht-dbg`, `ctest --preset bht-dbg`). +Also `clang-format --dry-run --Werror <changed files>` and `reuse lint`. +Anything you can't run goes under "Not verified". + +## 6. Report + +1. Summary: your reading of the intent, then a one-line verdict. +2. Findings: + Most severe first. + Each has: location (`path:line`), what is wrong, why it matters (cite the principle, decision or precedent), and a direction to fix it, not a patch. + Severity: Blocking / Should fix / Consider / Question. + Mark confidence: verified in code or suspected. +3. Questions for the author where intent is unclear. + Don't assume a bug. +4. Not verified: what you did not run or read. + +Rules: a review that finds nothing must still say what was checked. +Look for real problems, including in code the author considers finished. +Separate what you verified from what you suspect. +When citing precedent (Linux, FreeBSD, NetBSD, xnu, Windows, ACPI/UEFI specs), say how sure you are and provide references when possible.
\ No newline at end of file diff --git a/.agents/skills/review-subsystem/SKILL.md b/.agents/skills/review-subsystem/SKILL.md new file mode 100644 index 00000000..1367c575 --- /dev/null +++ b/.agents/skills/review-subsystem/SKILL.md @@ -0,0 +1,71 @@ +--- +name: review-subsystem +description: Architecture and code review of an existing TeachOS subsystem (for example VFS, memory allocators, the device model, kstd, ACPI) with no diff involved. Use for design audits, preparing a refactoring or extension, or getting oriented in an area. For pending diffs, branches or MRs, use review-changes. +--- + +# Review an existing subsystem + +Mentor mode applies (AGENTS.md §1): analysis, trade-offs and direction, never implementations. +Report in the conversation, not in the repository. + +## 1. Scope + +If the subsystem is ambiguous, ask. +List its files: `git ls-files <dirs>`, split into interface headers, implementation, tests and docs. +State the boundary. +If it is large [threshold: ~40 files], review a vertical slice and say what you left out. + +## 2. Reading order + +1. Interface headers, then the relevant `docs/briefs/` and `docs/`. +2. Implementation. +3. Tests. +4. History: `git log --oneline -- <paths>`. + Recent churn shows unstable or unclear areas. + +## 3. Build a model before critiquing + +Write a short "what this is" that the maintainer can confirm or correct: responsibilities, key types and who owns them, lifecycle, dependencies in and out (map includes with `git grep -n '#include'`), execution contexts (boot, thread, interrupt), and the invariants the code relies on. + +## 4. Analyses (each may yield findings) + +- Architecture: + cohesion, coupling, layering violations, whether the abstractions fit, use of the `kapi` seam, consistency with recorded decisions. + List places where docs and code disagree. +- Correctness risks: + error paths, cleanup, lifetimes, state machines, integer edge cases, unimplemented branches. +- Concurrency and interrupts: + inventory the shared state, what protects it, lock ordering, what can run in interrupt context. +- Freestanding discipline: + kstd use, hidden allocation, stack use. +- Tests: + what is covered against the risks above, and what is untestable and why (usually coupling to hardware). +- Teachability: + could this be explained in a lecture? + Separate essential complexity from accidental complexity. + Is it a good teaching example, or an advanced topic that needs prerequisites? +- Precedent: + how Linux, the BSDs, xnu or Windows handle the same problem, with a confidence label, and what is worth borrowing or avoiding. + Provide references when possible. + +## 5. Design questions + +Where a real choice exists, lay out the options with trade-offs, then take a position and say what would change it. +Don't present one answer as obvious. + +## 6. Report + +1. Overview: the model from step 3. +2. Strengths: specific and factual, not praise. +3. Findings: + most severe first. + Each has `path:line`, what and why, severity (High / Medium / Low), and confidence (verified or inferred). +4. Design trade-offs. +5. Docs versus code divergences. +6. Follow-ups, each sized roughly (afternoon / week / thesis-sized). +7. Not covered: what you didn't read, and any question that depends on planning documents outside this repository. + +Rules: every finding cites a location. +Don't claim a property of the code you did not read. +If a conclusion depends on a decision that isn't recorded in the repository, say so and ask. +Don't rewrite anything.
\ No newline at end of file diff --git a/.agents/skills/write-tests/SKILL.md b/.agents/skills/write-tests/SKILL.md new file mode 100644 index 00000000..5dcd2b99 --- /dev/null +++ b/.agents/skills/write-tests/SKILL.md @@ -0,0 +1,82 @@ +--- +name: write-tests +description: Write or extend Catch2 host tests (BHT) for TeachOS when the user explicitly asks for tests, including regression tests that reproduce a bug and stress tests. If the user only asks what to test, answer in prose and use this skill only once they ask for the code. Never changes production code. +--- + +# Write tests + +## Hard limits + +- Write only to `**/*.tests.cpp`, `**/*.stress.cpp` and `**/test_support/**`. +- Never edit production code. + That includes temporary edits to check that a test can fail, and includes making a type printable (see below). +- No git commands that change state. +- If a test needs a seam in production code (an injection point, an extracted function), stop and report what is needed and why. + Don't add it. + +## 1. Confirm the contract + +The interface under test must already exist (a header the human wrote, or a signature given in the request). +If it does not, stop and propose cases in prose instead. +State the source of the expected behavior: the header's docs, `docs/`, or the user's description. +Derive cases from the contract, not from reading the implementation. +If the contract is ambiguous, ask. + +## 2. Learn local conventions + +Read the neighbouring `*.tests.cpp` files and the `test_support/` of the library. +Reuse what exists: simulated memory, the bump frame allocator, the log buffer, the VFS and ext2 fixtures, and the `kapi` fakes that stand in for the architecture layer. +Add a new fake only if nothing fits. +Keep it minimal, put it under `test_support/`, and say so in the report. + +## 3. Plan the cases + +List the cases in a few lines before writing: happy path, boundaries, error paths (assert the specific `kstd::errc` when the contract names one), and state transitions. +If the request was broad, wait for a go-ahead. + +## 4. Write + +Match the neighbours: +- `SCENARIO("<behavior in plain words>", "[layer][subsystem]")` with `GIVEN` / `WHEN` / `THEN`. + One assertion idea per `THEN`. +- Tags are layer plus subsystem, as in `[kapi][devices]` or `[filesystem][path]`. + They become ctest labels, so don't invent new ones casually. +- Include order follows the neighbours: unit header, kstd, Catch2, standard library. + Tests may use the full standard library. +- `REQUIRE` when later steps depend on it, `CHECK` for independent assertions. +- Deterministic only: no sleeps, no timing assumptions. + Concurrency goes in `*.stress.cpp` (ThreadSanitizer), bounded in run time. +- To print a type in failures, add a `Catch::StringMaker` to the library's `test_support/string_makers.hpp`. + Never touch kernel code for that. +- Binary assets (`*.img`) are out of scope. + Ask the human. +- ASan, LSan and UBSan are on. + Tests must be clean. + Don't suppress reports. +- Test files need no license header. + `REUSE.toml` covers them. + +## 5. Run + +New files are picked up by the next build. +- `cmake --preset bht`, then `cmake --build --preset bht-dbg` +- `ctest --preset bht-dbg --output-on-failure -R <name>` (or `-L <tag>`) +- Concurrency: the `bht-stress` presets. + +If a test fails, decide which side is wrong. +Test wrong: fix the test. +Production wrong: stop, report the diagnosis with evidence, and leave the fix to the human. + +## 6. Check the tests can fail + +For each test, say which kind of bug it would catch. +Reason about it; don't break production code to find out. + +## 7. Report + +Files touched. +For each test, what it checks, in one line. +The contract source. +Cases deliberately not covered, and why. +Seams you would need in production code. +Anything you couldn't run.
\ No newline at end of file |
