# Knowledge Base Doc Generation — Per-Subagent Instructions

You are generating **ONE** knowledge base document. You have been given:

1. A **discovery context** — the raw findings from Phase 1 discovery scans,
   passed inline in your prompt
2. A **doc spec** — which file to write and what it should contain
3. A **project brief** (`.forge/init-context.md`) — for names and paths

Your job is to produce exactly one file and return a one-line status.

---

## Rules

1. **Write EXACTLY ONE file** at the path specified in your doc spec.

2. **Confidence header** — every generated doc must open with:
   ```
   <!-- AUTO-GENERATED by /forge:init — confidence: N% -->
   ```
   Set N% based on how much evidence the discovery context provided:
   - 90–100%: directly observed in code/config
   - 70–89%: inferred from conventions or partial evidence
   - below 70%: limited evidence, many `[?]` markers expected

3. **Uncertainty markers** — any fact not directly observed in the discovery
   context must be marked with `[?]`. Do not invent values.

4. **Entity names** — use entity names exactly as they appear in the brief's
   `## Domain Entities` section. Do not rename or abbreviate.

5. **Scope discipline** — generate only what the doc spec prescribes.
   Do not add sections not listed in the spec. Do not cross-reference
   other KB docs that do not yet exist.

6. **`architecture/INDEX.md` and `business-domain/INDEX.md`** — if your
   assigned doc is an INDEX file, link only to docs that exist on disk at
   the time you write. Do not anticipate files that may not have been written.

---

## Self-check (mandatory last step)

After writing the file, verify before returning:

1. Read back the written file
2. Confirm the confidence header is present on the first line
3. Confirm no `{placeholder}` tokens remain
4. Record in the manifest:
   ```sh
   node "$FORGE_ROOT/tools/generation-manifest.cjs" record "{output_path}"
   ```
   (If generation-manifest.cjs is not yet installed, skip silently.)

5. Return **exactly one line**:
   - `done: <first 80 chars of the written file>` — on success
   - `FAILED: <reason>` — if any step above failed or the file could not be written

Do not output anything else after the status line.
