Add `AGENTS.md`

743d57d378abb4cce0b061d03ed2c562f4d32a63dca15067f10df9e351c1bcd2
Alexis Sellier committed ago 1 parent 6138d0b7
.gitignore +0 -1
1 1
# Notes and random stuff
2 2
TODO
3 3
DEBUG
4 4
NOTES
5 -
AGENTS.md
6 5
CLAUDE.md
7 6
/notes
8 7
/tools
9 8
/.research
10 9
/.claude
AGENTS.md added +134 -0
1 +
# AGENTS.md
2 +
3 +
## Scope and completion
4 +
5 +
- Be concise. For questions, give the direct answer. A prompt that ends with
6 +
  `?` is read-only.
7 +
- For action requests, complete implementation and verification within the
8 +
  requested scope. Before fixing a reported issue, explain your understanding
9 +
  and proposed fix, then proceed with authorized work.
10 +
- Use repository evidence for routine decisions. Ask when missing information
11 +
  affects design, correctness, scope, or authorization. Continue independent
12 +
  work while waiting. Do not invent language semantics or API contracts.
13 +
- Preserve unrelated edits. API contract changes require explicit permission.
14 +
  Compatibility with unmerged feature work is not required.
15 +
- Report what changed, checks run, and any remaining limits. Fix failures caused
16 +
  by your changes before declaring completion. If work remains blocked or
17 +
  deferred, record concrete items in the existing TODO file, or `TODO.md`.
18 +
19 +
## Work records in `.ai/`
20 +
21 +
Maintain these records during work that permits file edits. Read-only tasks
22 +
must not create or update logs or TODO files.
23 +
24 +
- Bugs: when you discover a bug, record it in `.ai/issues/<bug-name>.md`.
25 +
  Include observed behavior, expected behavior, and reproduction steps or
26 +
  supporting evidence.
27 +
- Decisions: when you make your own decision, add the decision and its
28 +
  reason to `.ai/decisions/` as a new file with format `YYYY-MM-DD-SLUG`.
29 +
- Suggestions: when you identify a potential improvement to the Radiance
30 +
  language or tooling that would have helped with the current task, create a
31 +
  file under `.ai/suggestions/`. Explain the improvement and how it would have helped.
32 +
- Design questions: record one question per line in `.ai/questions.txt`.
33 +
- Design findings: record one relevant finding per line in `.ai/learnings.txt`.
34 +
35 +
Question and finding logs are required for design tasks, not routine
36 +
implementation. Bug, decision, and suggestion logs apply to both.
37 +
38 +
## Git
39 +
40 +
- Read-only inspection is allowed. Git operations that change repository state
41 +
  require an explicit request. Leave changes uncommitted unless asked to commit.
42 +
- Sign every commit. Create a new commit unless explicitly asked to amend.
43 +
  Include documentation and other non-source files only when asked.
44 +
- Large features require a new worktree under `../worktrees/`. If its creation
45 +
  is not authorized, ask before implementation and continue read-only research.
46 +
- Read `CONTRIBUTING` before writing commit messages.
47 +
48 +
## Radiance implementation
49 +
50 +
Radiance is a self-hosted systems language compiler targeting RV64. It runs in
51 +
an external RISC-V emulator on Linux x86-64. Read representative source and
52 +
relevant specifications when working with unfamiliar syntax; Rust semantics
53 +
are not evidence of Radiance behavior.
54 +
55 +
- Read `STYLE` before changing source; it defines code and documentation style.
56 +
- Correctness and safety are requirements. Among correct designs, prioritize
57 +
  code simplicity and size, then execution speed and memory use, then generated
58 +
  code quality. Use production-quality solutions without workarounds.
59 +
- Fix root causes. Preserve valid changes and tests that expose a compiler bug.
60 +
- Reason from RV64: registers are 64-bit. Choose narrower operations from type
61 +
  and instruction semantics, and verify their cost on this target.
62 +
- Handle errors through the established API: `throw` for recoverable failures,
63 +
  `panic` for impossible invariants. Optionals can represent expected absence;
64 +
  they must not hide errors.
65 +
- Use camelCase for Radiance functions, methods, and variables. Prefer optionals
66 +
  to sentinels, `if-let` or `let-else` for matching, and `append` for slice growth.
67 +
- Use ASCII in source comments and strings, and simple English in technical
68 +
  documentation. Document all top-level declarations and record/union fields,
69 +
  plus non-obvious private code.
70 +
- Comments describe stable purpose, invariants, and non-obvious constraints.
71 +
  Do not narrate migrations or review history. Preserve comments during code
72 +
  simplification. Describe clean cutovers by supported behavior and files changed.
73 +
74 +
## Tests
75 +
76 +
- For features and bug fixes, write a failing test first at the appropriate
77 +
  level: std, lowering, or assembly. Verify that it fails for the intended reason,
78 +
  apply the implementation, and verify that it passes.
79 +
- Cover affected branches, boundaries, errors, and relevant language interactions
80 +
  such as guards, `if-let`, `let-else`, and `while-let`. Include adversarial
81 +
  executable cases for safety changes where applicable.
82 +
- Use `assert` for expected values. Nonzero exit expectations are for tests of
83 +
  failure or exit behavior. Remove tests for functionality the user asks to remove.
84 +
- Run focused tests during development and `make test` after the final source,
85 +
  test, or build change. Repeat successful checks only after further changes or
86 +
  to investigate an unresolved concern.
87 +
- For documentation-only changes, verify content, paths, commands, and formatting;
88 +
  no compiler tests are needed. Distinguish checks performed from untested claims.
89 +
90 +
## Build and test entry points
91 +
92 +
Use Make to compile: its recipes supply required memory and stack settings.
93 +
Use timeouts for builds, tests, scripts, and emulator runs. These limits are
94 +
starting points; investigate timeouts before increasing them. Export
95 +
`RAD_EMULATOR` when selecting an emulator so Make and scripts use the same one.
96 +
97 +
```bash
98 +
timeout 300 make           # Build bin/radiance.rv64.dev from the seed
99 +
timeout 600 make test      # Seed format, std, and binary tests
100 +
timeout 300 make std-test  # Standard library tests
101 +
timeout 300 make bin-test  # All IL and executable checks
102 +
```
103 +
104 +
For one executable fixture, replace `NAME` with its basename:
105 +
106 +
```bash
107 +
timeout 300 make test/runner.rv64 test/tests/NAME.rv64
108 +
timeout 10 test/run test/tests/NAME.rad
109 +
```
110 +
111 +
For an IL-only fixture, build only `test/runner.rv64` before `test/run`.
112 +
The harness runs existing binaries; it does not build them.
113 +
114 +
## Task-specific references
115 +
116 +
- Compiler work: `compiler/radiance.rad` is the entry point; `lib/std/lang/`
117 +
  contains scanner, parser, resolver, lowering, and code generation modules.
118 +
  RV64 backend and assembler code is in `lib/std/arch/rv64/`.
119 +
- Tests: read nearby fixtures and `test/run` for supported checks. `.ril` files
120 +
  check IL; `//! returns: N` requests an executable check. Success fixtures use
121 +
  `@default fn main`, assertions, and a zero return. Inspect generated IL before
122 +
  accepting a new snapshot.
123 +
- Session fixtures: `//! session-support` uses `test/support/std.lib`. Keep
124 +
  individual golden checks below one second. Test production std behavior in std
125 +
  unit suites. Module lists are in `std.lib` and `std.lib.test`.
126 +
- Backend debugging: locate the first incorrect stage, from AST and resolution
127 +
  through IL, assembly, and execution. Use Make recipes with the existing
128 +
  `RADIANCE` settings for diagnostic compilation.
129 +
- Bootstrap changes: read `seed/README`. The seed must compile checked-in source.
130 +
  Update it only when needed, through `timeout 600 make seed` or the documented
131 +
  alternate-seed workflow with a timeout. `make test` checks seed image format,
132 +
  not fixed-point reproducibility.
133 +
134 +
Use the current Makefile, scripts, and source to resolve stale command examples.