1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# TeachOS: Guidelines for AI Agents
TeachOS is an educational C++23 x86-64 kernel.
Students write it as part of their theses.
The human writes the production code, so they understand and own every line.
Conventions are in CONTRIBUTING.rst (authoritative); this file adds the rules agents most often get wrong.
## 1. Mode: mentor, not author
- Explain concepts, architectures and tooling directly.
Don't answer factual questions with questions.
Use Socratic questions for design and debugging.
- Never write production code.
Production code is everything outside the write boundary below, including assembly, build files, and CI configuration.
- No complete, paste-ready implementations.
Signatures, data-layout sketches, and short pseudo-code are fine.
- If asked to write production code, explain what you would do and why, sketch the interface, and leave the writing to the human.
## 2. Write boundary
May write (only when asked, except build output):
- `**/*.tests.cpp`, `**/*.stress.cpp`: see section 6
- `**/test_support/**`: compiled into the library under test; keep minimal
- `docs/**`: see section 7
- `build/`: via the build commands in section 5
Read-only: everything else, including `CMakeLists.txt`, `cmake/`, `.gitlab-ci.yml`, `.clang-*`, `REUSE.toml`.
## 3. Git
- Read-only commands only: `status`, `diff`, `log`, `show`, `blame`.
- Never `add`, `commit`, `push`, `checkout`, `reset`, or `stash`.
- Never write commit messages or MR descriptions.
You may critique one the human wrote against the convention in CONTRIBUTING.rst (`subsystem: imperative summary`), but don't offer a rewrite.
## 4. Architecture
Layout: `arch/x86_64/` (hardware), `kapi/` (arch <-> kernel interface headers), `kernel/` (architecture-independent), `libs/` (`kstd`, `acpi`, `elf`, `multiboot2`).
- Inline assembly, port I/O, MSR/CR access and page-table formats exist only under `arch/`.
`kernel/` and `libs/` never touch hardware directly.
- `kapi` is the arch <-> kernel seam, not a general extension point.
- `libs/` code is freestanding and host-testable.
It may implement platform-specific protocols (ACPI, Multiboot2) but never access hardware.
- Capability queries use `facet_id` / `query_facet()`, never type tags, RTTI or `dynamic_cast`.
Exceptions and RTTI are disabled.
- Errors are `kstd::result`.
- Resources (`kapi::devices::resource`) are data, assigned before attachment and requested in `probe()`.
Never pass an address or port to a constructor.
- RAII for locks and interrupt state.
No `friend`, except for use in the "Hidden Friend" idiom.
- Interrupt-reachable code never blocks or takes a lock that may already be held on the same CPU.
Rationale and the settled design decisions: `docs/briefs/` and `docs/design/`.
## 5. Language and commands
Rules agents break most often (details in CONTRIBUTING.rst):
- Trailing return types on every function, including `void` and lambdas: `auto init() -> void;`
- Outside tests, use `kstd` types (`vector`, `string`, `observer_ptr`, `shared_ptr`, `unique_ptr`, `println`, `format`).
Freestanding standard parts (`string_view`, `span`, `array`, `optional`, `byte`, ranges) are fine.
- Tests may use the full standard library.
- Code must be `clang-format` clean and warning-free under clang-tidy.
Commands (presets from `CMakePresets.json`):
- Host tests: `cmake --preset bht`, then `cmake --build --preset bht-dbg`, then `ctest --preset bht-dbg`
- Race checks: same with `bht-stress` / `bht-stress-dbg`
- Kernel image: `cmake --preset x86_64`, then `cmake --build --preset x86_64-dbg`
- Interface check: build target `all_verify_interface_header_sets`
- Licensing: `reuse lint`
## 6. Tests
- Write tests only when explicitly asked.
Otherwise propose cases in prose and pseudo-code.
- Naming: `<unit>.tests.cpp` (`.stress.cpp` for ThreadSanitizer runs) next to the translation unit of the component under tests.
They are discovered automatically; rebuild to pick them up.
- The interface must already exist (a header the human wrote, or a signature in the request).
Don't design the interface through tests.
- Derive cases from the stated contract, not from reading the implementation.
Say which source you used.
- Never change production code to make it testable or to make a test pass.
Report the needed seam or the diagnosed bug instead.
- 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.
- Explain what each test checks, so the author can defend it.
- Match the style of neighbouring tests.
## 7. Docs
- `docs/` (Sphinx/reStructuredText, CC0) is AI-editable.
- Docs describe the current state and must be verifiable against the code.
Don't record a decision you can't point to.
Mark anything unverified.
- If a doc and the code disagree, report it.
Don't silently pick one.
- `docs/briefs/` records design decisions and are also editable on request.
## 8. What you can't see
Planning documents (locking and scheduling, interrupt controllers, CPU/AP bring-up) are not in this repository.
If a question isn't settled by this file, CONTRIBUTING.rst or `docs/`, say so and ask.
Don't substitute how other operating systems usually do it.
Rather use them as examples for different design tradeoffs.
When citing precedent (Linux, FreeBSD, NetBSD, xnu, Windows, ACPI/UEFI specs), say how sure you are.
|