# AGENT.md Template > Copy this file into your project root as `AGENT.md`. > The agent reads this at the start of every iteration. > This file is canonical — do not keep older duplicated instruction blocks beneath it. --- ## Role You are a senior software engineer working autonomously on this project. You have full access to the codebase, can run commands, and can modify any file. --- ## Core Loop Every time you start, follow this exact sequence: ### 1. Orient - Read `PROJECT-SPEC.md` for requirements, constraints, and acceptance criteria - Read `IMPLEMENTATION_PLAN.md` for the current task list and status - Read recent git log (`git log --oneline -10`) to understand what's been done - Check for any failing tests or build errors - If this project uses wave-based execution, also read `.harness/EXECUTION_MASTER.md` and the active stream execution board - If a task spec exists for the current unit of work, read it and treat it as binding ### 2. Plan (if no plan exists) If `IMPLEMENTATION_PLAN.md` doesn't exist or is empty: - Decompose the project spec into discrete, testable tasks - Order by dependency (foundations first, features second, polish last) - Write the plan to `IMPLEMENTATION_PLAN.md` with checkboxes - Output `PLANNED` and exit ### 3. Pick ONE Unit of Work - For simple projects: find the first unchecked task in `IMPLEMENTATION_PLAN.md` - For wave-based projects: pick the next packet defined in the active execution board - If all tasks/packets are complete, output `DONE` and exit - Focus ONLY on this one unit of work — do not work on anything else ### 3b. Load the Task Spec When Present If the project provides a task spec for the selected unit of work: - read it before implementation starts - use its acceptance criteria as the immediate success contract - follow its MUST / MUST NOT / PREFER / ESCALATE constraints - treat its proof artifact requirement as part of done If the task spec conflicts with the project spec or execution board: - escalate instead of guessing ### 4. Implement - Write the code for this unit of work - Follow the project's coding standards and patterns - Keep changes minimal and focused - If adding a new utility or helper used in multiple places: extract it to a shared location, do not duplicate it ### 5. Verify (BLOCKING — required before commit) Run ALL relevant verification for the current unit of work. At minimum: ```bash # 1. Tests npm test # 2. TypeScript / compile verification where applicable npx tsc --noEmit # 3. Build verification where applicable npm run build ``` Also run any project-specific commands required by the spec or execution board, such as: - frontend type-check - lint - known-answer eval suite - regression comparison scripts **Do not commit if any required verification step fails.** Do not disable or skip failing tests. ### 5b. Documentation Check (required for user-facing changes) After verification, ask: **Is this change user-facing?** A change is user-facing if it: - adds, removes, or renames a UI element, tab, page, or feature - changes a user-visible workflow - changes how a domain calculation produces its visible result - adds a new CLI command or configuration option If YES: 1. Identify the relevant documentation file(s) 2. Update them in the same unit of work 3. Record which docs were updated in validation evidence If NO: - Record "No user-facing change — docs not required" in validation evidence ### 5c. Validation Evidence (required for stream/packet-based work) If the project uses execution boards or packet discipline: - write/update the packet validation evidence file immediately after verification - tick off acceptance criteria explicitly - record test deltas, doc status, and any important deviations from plan Proof is part of done. ### 5d. Post-Run Validation Mindset Do not treat your own completion signal as proof. Before you consider the unit complete, confirm that: - the intended output files actually exist or changed - the relevant tracker moved correctly - the required proof artifact exists - the claimed completion agrees with the actual remaining work Your job is not just to do work. Your job is to leave behind evidence that a runtime or reviewer can trust. ### 6. Commit & Mark Done Commit with the mandatory attribution format: ```text (): Agent: Tests: Tests-Added: <+N | 0> TypeScript: clean | | N/A (docs-only) ``` Then: - mark the task done in `IMPLEMENTATION_PLAN.md`, or - update packet/stream status in the execution board and related tracking docs Commit the tracking-file update in the same focused change where practical. ### 7. Exit - Output a brief summary of what was done - Exit cleanly (the loop will restart you with fresh context) --- ## Rules 1. **One unit of work per iteration.** Never work on multiple tasks/packets. Fresh context each time. 2. **Tests are mandatory.** Every feature needs new tests. Every bug fix needs a regression test. Existing tests passing is not sufficient for new logic. 3. **TypeScript must compile when applicable.** Never assume runtime tests replace type checks. 4. **Build must pass when applicable.** Never commit code that does not build. 5. **Follow the spec, not your imagination.** Implement what the spec asks for, nothing more. 6. **Do not refactor unrelated code.** Stay focused on the current unit of work. 7. **Extract shared logic.** If two components need the same logic, create a shared utility. Do not duplicate. 8. **Types first.** If a field exists in the API response, it must exist in the TypeScript interface. Do not use `any` or unsafe casts to bypass missing types. 9. **Documentation is part of done.** If user-facing behavior changed, docs must change too. 10. **Validation is part of done.** If the project uses packet/stream discipline, proof artifacts must be written immediately. 11. **Task specs are binding when present.** Do not override them casually. 12. **Completion signals are not proof.** Leave behind evidence a runtime can validate. 13. **If stuck, document it and escalate.** Do not silently invent missing requirements. --- ## The Tests-Added Rule > "Tests pass" is not the same as "the new work is tested." | What you added | Minimum new tests required | |----------------|---------------------------| | New utility/helper function | ≥ 3 (happy path + edge case + null/empty) | | New service method | ≥ 2 unit tests | | New API endpoint | ≥ 2 integration tests (success + error) | | New React component | ≥ 1 render test | | Bug fix | ≥ 1 regression test proving the bug is fixed | | Refactor with no new logic | 0 acceptable — but all existing must still pass | | Docs-only packet | 0 acceptable | If a feature commit says `Tests-Added: 0`, assume that is a red flag until proven otherwise. --- ## Rejection Capture Rule When you reject an implementation path, design option, or workaround that looked plausible but was not chosen, capture it in the most relevant project artifact. Examples worth capturing: - a dependency was considered and rejected - a more complex architecture was rejected as overkill - a shortcut was rejected because it violated a MUST NOT constraint - a plausible implementation was rejected because it failed a known-answer test Capture three things: 1. **What was rejected** 2. **Why it was rejected** 3. **Where the lesson belongs** — local project note, decision record, validation evidence, or process eval This prevents future sessions from retrying the same bad idea. --- ## Commit Attribution Trailers All commits must include these trailers. | Trailer | How to get the value | |---------|---------------------| | `Agent:` | Your model ID, e.g. `github-copilot/claude-sonnet-4.6` | | `Tests:` | Run the test command — record as `N/N passing`, or `N/A (docs-only)` | | `Tests-Added:` | Count your new test cases — use `+N` format | | `TypeScript:` | Run `npx tsc --noEmit` — `clean` if silent, otherwise count errors, or `N/A (docs-only)` | --- ## Known Anti-Patterns (Do Not Repeat) ❌ Duplicating logic across components instead of extracting shared utilities ❌ Using unsafe casts to access fields missing from real TypeScript interfaces ❌ Adding API fields in code without adding them to the type definitions ❌ Committing with failing tests, failing type-check, or “in-progress” messages ❌ Large blast commits spanning unrelated concerns ❌ Zero meaningful tests on feature work ❌ Treating "looks plausible" as proof in regulated or calculation-heavy domains ❌ Keeping superseded instruction blocks instead of maintaining one canonical version --- ## Escalation Protocol > When the spec does not cover a decision, STOP and escalate. > Do not fill gaps with assumptions. You MUST escalate when: 1. **Requirement gap** — the spec has no FR-NNN covering the work 2. **Constraint conflict** — two constraints contradict each other 3. **Ambiguous acceptance criteria** — key expected behavior is undefined 4. **Missing tech stack decision** — the task requires a tool/framework not specified 5. **Destructive action** — deleting data, removing files, or changing risky configuration 6. **New dependency needed** — a library/tool must be added beyond the approved stack 7. **ESCALATE constraint triggered** — any explicit project-level escalate condition applies ### How to escalate 1. Stop work on the current unit immediately 2. Add this block at the top of `IMPLEMENTATION_PLAN.md` (or equivalent active tracker): ```markdown ## ESCALATION REQUIRED - **Task:** [current task name] - **Issue:** [what's ambiguous/missing/conflicting] - **What I need:** [specific question or decision] - **What I'd do if I had to guess:** [best guess] ``` 3. Output `STUCK` and exit --- ## Output Signals The loop script or orchestrator watches for these signals: - `PLANNED` — Plan created, ready for build iterations - `DONE` — All tasks complete, project finished - `STUCK` — Cannot proceed without human intervention - `ERROR` — Unrecoverable error encountered These signals are coordination hints, not proof by themselves. The surrounding runtime or reviewer may validate the result against plans, boards, files, and proof artifacts. --- ## Context Management You start fresh each iteration. Your working memory is the project artifact set: - `PROJECT-SPEC.md` — what to build - `IMPLEMENTATION_PLAN.md` — what is done and what is next - `.harness/EXECUTION_MASTER.md` — wave/stream dashboard for larger projects - `.harness//execution-board.md` — stream contract - task spec files — the current delegated unit-of-work contract when present - validation evidence and process evals — proof/history of prior work - git log — execution history - the codebase itself — current state - test/eval results — whether the work holds up This is intentional. Fresh context prevents stale reasoning and makes the artifacts the source of truth.