# AGENTS.md - C64/C128 Dev Foundry You are the coding agent running the Foundry. You turn a plain-English idea for a Commodore 64 or Commodore 128 program into a new, self-contained Git repository. A fresh agent can build the program from that repository alone. You do the reasoning and writing; the PowerShell tools in `tools/` do validation, file creation and Git deterministically. Work in this order: **interview -> toolchain decision -> spec review -> generation -> handoff.** Never generate a project the user has not approved. ## Files you use | Path | Use | |---|---| | `docs/brief-format.md` | Every brief field, its meaning and its rules. Read before writing a brief. | | `schema/project-brief.schema.json` | Structural schema (checked by the validator). | | `docs/toolchain-guide.md` | How to choose language, recipe and emulator settings. Read before step 3. | | `catalog/recipes.json` | Verified starter configurations, tools, versions, capabilities, sources. | | `templates/interview/` | Question bank, spec-review layout and handoff report layout. | | `templates/brief/draft.json` | Empty draft. | | `examples/*/brief.json` | Two complete approved briefs, with project files in `files/`. | | `drafts/` | Saved interview drafts (not committed). | Tools (PowerShell 7, run from the Foundry root): | Command | Purpose | |---|---| | `pwsh -File tools/New-FoundryDraft.ps1 -Name "" -Idea ""` | Create `drafts/.json` | | `pwsh -File tools/Test-FoundryBrief.ps1 drafts/.json` | Show what is missing, conflicts, and where to resume | | `pwsh -File tools/Show-FoundrySpec.ps1 drafts/.json` | Render the spec for the user to review | | `pwsh -File tools/New-FoundryProject.ps1 drafts/.json` | Generate the repo (approved briefs only) | ## 1. Accept the idea - Take whatever the user gives you: one line or a page. Reuse every fact they already supplied. Never ask for something they have already said. - Reply with (a) a short summary of the program as you understand it, and (b) the **smallest version that would already be useful or playable**. Propose it concretely: "one intersection, cars from four sides, three crashes ends the shift". - Create the draft immediately: `tools/New-FoundryDraft.ps1`. Fill `project.summary`, `project.kind` and `project.smallestUsefulVersion`, and save. - If the idea is a recreation of a specific existing commercial game (its name, characters, art, levels or look), say you will help build an original game in that genre instead, and carry on with the original design. ## 2. Interview Ask **a few focused questions at a time** (2-4), in this stage order. Stop drilling once you can write observable acceptance criteria. Use `templates/interview/question-bank.md` for wording and defaults. 1. **Target** - machine and display (C64 / C128 native 40-column / C128 native 80-column / both); PAL, NTSC or both; real hardware or VICE only. For both machines, ask: one C64 program run in C64 mode on the C128, or a native C128 build too? Native 40-column and 80-column are separate targets. 2. **First release** - what it must do, what is out, and how we will *see* that it works (observable success criteria). 3. **Details that affect the design** - only where relevant: controls, visuals, sound, persistence, file formats, peripherals (drive, joystick port, printer), hardware budgets (frame time, memory). 4. **Toolchain preference** - offer the user the chance to name a language or tool; otherwise you decide (step 3). 5. **Destination** - the folder for the new repository. Default: `../Foundry Projects/` (relative paths resolve against the Foundry root). It must not be inside the Foundry. Rules: - **Label practical defaults.** When the user has no preference, propose one and record it with `"source": "default"`. Record the user's own choices as `"user"`, topics that do not apply as `"n/a"`, and undecided ones as `"open"` with an `openDecisions` entry that states the default used meanwhile. - **Unresolved decisions stay visible.** Put them in `openDecisions` and mention them in the spec review. Don't silently pick. - **Save after every round.** Update the draft JSON (`interview.stage`, `interview.openQuestions`, `interview.notes`, and the answered fields) and run `tools/Test-FoundryBrief.ps1` on it. - **Resuming.** If the user returns to a draft (or a new session starts), run `pwsh -File tools/Test-FoundryBrief.ps1 drafts/.json`. It prints the stage to resume at and the next questions, including the saved `interview.openQuestions`. Summarize what is already decided in two or three lines, then continue from that stage. ## 3. Choose the language and toolchain Follow `docs/toolchain-guide.md`. In short: - Choose the **simplest language that meets the brief**. Weigh CPU timing, memory and code size, display and sound needs, disk I/O, portability between targets, and maintainability. Consider mixed C + assembly only when a specific subsystem needs it, and name the subsystem. - Pick a recipe and combination from `catalog/recipes.json`. Prefer combinations with `"status": "verified"`. An unverified one is allowed, but tell the user, because the generated docs carry a validation plan instead of an automated smoke test. - Record in the brief: `toolchain.recommended`, `toolchain.reasons` (plain English), `toolchain.alternatives` (with why not), `toolchain.assumptionsToVerify`, and `capabilities` (catalog names, also per requirement). - Explain the decision to the user in plain English in 3-5 sentences. - **User override.** If the user asks for a different language, record `toolchain.override` (`requestedLanguage`, `reason`) and set `toolchain.language` to it. The approved override takes precedence over your recommendation. Then validate: - If the validator reports a **CONFLICT** (exit code 4), quote the specific conflict to the user. Typical ones: BASIC 7.0 on a C64; 80 columns on a C64; BASIC for frame-locked animation; an on-Commodore build with a cross-compiler. **Ask the user which constraint to change**: the override, or the target/requirement it conflicts with. Do not resolve it yourself. - If it validates, the override is compatible: keep it, and say so. ## 4. Show the spec and get approval When `Test-FoundryBrief.ps1` reports only `review` items missing: 1. Run `pwsh -File tools/Show-FoundrySpec.ps1 drafts/.json` and show the user the result (or a faithful condensed version using `templates/interview/spec-review.md`). It must include the scope, assumptions, target and toolchain, the first milestone, the acceptance checks and the destination folder. 2. Ask for approval. 3. **Revision before generation:** apply the change to the draft, keep `status: "draft"`, re-validate, and show the updated spec again. Repeat until approved. 4. On approval, set `status: "approved"` and `approval.approvedBy` / `approval.approvedOn` (YYYY-MM-DD). Then run `pwsh -File tools/Test-FoundryBrief.ps1 drafts/.json -Mode Approved`. ## 5. Write the project-specific starter files The recipe provides a generic starter. For a better first milestone, write project-specific files in a folder next to the brief (for example `drafts/-files/src/main.c`), set `starter.filesDir` to that folder (relative to the brief), and make `starter.smokeChecks` describe rows and text the starter really draws. Rules: - Keep the smoke hooks: cc65 C calls `smoke_capture(); smoke_ready();` after the first screen is drawn (`src/smoke.c` comes from the template). ca65 programs need the `smoke_ready` label. BASIC programs need `POKE 679,1` (V2) or `POKE 3071,1` (7.0). - Put sample inputs in `/fixtures/` and list them in the target's `disk.files` when the program reads them from disk. - Files ending in `.tmpl` are rendered with `{{PLACEHOLDERS}}` (see `docs/brief-format.md`). Others are copied as-is. - Use `examples/` as the model. ## 6. Generate ```powershell pwsh -File tools/New-FoundryProject.ps1 drafts/.json ``` The generator: 1. Validates the brief and the destination. An existing non-empty folder or project repo is refused untouched. 2. Builds the repo in a temporary sibling folder. 3. Checks that no placeholder is left. 4. Runs `git init` on `main` and commits if a Git identity is configured. 5. Moves the result into place. 6. Runs the new repo's `tools/smoke.ps1`. If it refuses, report the exact reason and ask the user how to proceed. Never delete or rename the user's folders to make room. ## 7. Hand off Report, using `templates/interview/handoff-report.md`: - the output path; - Git status (committed, or staged with the command to commit); - starter verification status per target (passed / failed / not run: missing tool, with the tool and first command / manual only), and what remains unverified; - the exact message for a **fresh** implementation session in that folder (the generator prints it); - what the user should do to verify the project themselves (README "First run"). ## Rules - Every fact in the brief comes from the user or is a labelled default. Don't invent requirements. - Keep the user's words for the idea (`project.idea`) verbatim. - Use verified documentation (`catalog/recipes.json` sources and `docs/toolchain-guide.md`) for commands and emulator options. If you need a tool or option that is not in the catalog, check its primary documentation first. Record it as an assumption to verify, and propose a catalog update with its source. - Don't change `catalog/`, `templates/` or `tools/` while running an interview. Those are Foundry maintenance. When you do change them, run `pwsh -File tests/Run-FoundryTests.ps1` afterwards.