fix: add mandatory canonical_refs section to CONTEXT.md (#1015)

* fix: add mandatory canonical_refs section to CONTEXT.md

CONTEXT.md is the bridge between user decisions and downstream agents
(researcher, planner). When projects have external specs, ADRs, or
design docs, these references were being silently dropped — mentioned
inline as "see ADR-019" but never collected into a section that agents
could find and read. This caused agents to plan and implement without
reading the specs they were supposed to follow.

Changes:
- templates/context.md: Add <canonical_refs> section to file template,
  all 3 examples, and guidelines (marked MANDATORY)
- workflows/discuss-phase.md: Add step 1b (extract canonical refs),
  add section to write_context template, add to success criteria
- workflows/plan-phase.md: Add canonical ref extraction to PRD express
  path and its CONTEXT.md template
- workflows/quick.md: Add lightweight canonical_refs to --discuss mode

The section is mandatory but gracefully handles projects without external
docs ("No external specs — requirements fully captured in decisions above").

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: make canonical refs an accumulator across entire discussion

Refs come from 4 sources, not just ROADMAP.md:
1. ROADMAP.md Canonical refs line (initial seed)
2. REQUIREMENTS.md/PROJECT.md referenced specs
3. Codebase scout (code comments citing ADRs)
4. User during discussion ("read adr-014", "check the MCP spec")

Source 4 is often the MOST important — these are docs the user
specifically wants downstream agents to follow. The previous
version only handled source 1 and silently dropped the rest.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Kevin McCarthy
2026-03-12 12:35:39 -05:00
committed by GitHub
parent 2eaed7a847
commit 44cf8ccf48
4 changed files with 122 additions and 3 deletions

View File

@@ -54,6 +54,24 @@ Template for `.planning/phases/XX-name/{phase_num}-CONTEXT.md` - captures implem
</specifics>
<canonical_refs>
## Canonical References
**Downstream agents MUST read these before planning or implementing.**
[List every spec, ADR, feature doc, or design doc that defines requirements or constraints for this phase. Use full relative paths so agents can read them directly. Group by topic area when the phase has multiple concerns.]
### [Topic area 1]
- `path/to/spec-or-adr.md` — [What this doc decides/defines that's relevant]
- `path/to/doc.md` §N — [Specific section and what it covers]
### [Topic area 2]
- `path/to/feature-doc.md` — [What capability this defines]
[If the project has no external specs: "No external specs — requirements are fully captured in decisions above"]
</canonical_refs>
<code_context>
## Existing Code Insights
@@ -124,6 +142,18 @@ Display posts from followed users in a scrollable feed. Users can view posts and
</decisions>
<canonical_refs>
## Canonical References
### Feed display
- `docs/features/social-feed.md` — Feed requirements, post card fields, engagement display rules
- `docs/decisions/adr-012-infinite-scroll.md` — Scroll strategy decision, virtualization requirements
### Empty states
- `docs/design/empty-states.md` — Empty state patterns, illustration guidelines
</canonical_refs>
<specifics>
## Specific Ideas
@@ -186,6 +216,15 @@ CLI command to backup database to local file or S3. Supports full and incrementa
</decisions>
<canonical_refs>
## Canonical References
### Backup CLI
- `docs/features/backup-restore.md` — Backup requirements, supported backends, encryption spec
- `docs/decisions/adr-007-cli-conventions.md` — Flag naming, exit codes, output format standards
</canonical_refs>
<specifics>
## Specific Ideas
@@ -248,6 +287,15 @@ Organize existing photo library into structured folders. Handle duplicates and a
</decisions>
<canonical_refs>
## Canonical References
### Organization rules
- `docs/features/photo-organization.md` — Grouping rules, duplicate policy, naming spec
- `docs/decisions/adr-003-exif-handling.md` — EXIF extraction strategy, fallback for missing metadata
</canonical_refs>
<specifics>
## Specific Ideas
@@ -291,7 +339,14 @@ The output should answer: "What does the researcher need to investigate? What ch
**After creation:**
- File lives in phase directory: `.planning/phases/XX-name/{phase_num}-CONTEXT.md`
- `gsd-phase-researcher` uses decisions to focus investigation
- `gsd-planner` uses decisions + research to create executable tasks
- `gsd-phase-researcher` uses decisions to focus investigation AND reads canonical_refs to know WHAT docs to study
- `gsd-planner` uses decisions + research to create executable tasks AND reads canonical_refs to verify alignment
- Downstream agents should NOT need to ask the user again about captured decisions
**CRITICAL — Canonical references:**
- The `<canonical_refs>` section is MANDATORY. Every CONTEXT.md must have one.
- If your project has external specs, ADRs, or design docs, list them with full relative paths grouped by topic
- If ROADMAP.md lists `Canonical refs:` per phase, extract and expand those
- Inline mentions like "see ADR-019" scattered in decisions are useless to downstream agents — they need full paths and section references in a dedicated section they can find
- If no external specs exist, say so explicitly — don't silently omit the section
</guidelines>

View File

@@ -272,6 +272,15 @@ Analyze the phase to identify gray areas worth discussing. **Use both `prior_dec
1. **Domain boundary** — What capability is this phase delivering? State it clearly.
1b. **Initialize canonical refs accumulator** — Start building the `<canonical_refs>` list for CONTEXT.md. This accumulates throughout the entire discussion, not just this step.
**Source 1 (now):** Copy `Canonical refs:` from ROADMAP.md for this phase. Expand each to a full relative path.
**Source 2 (now):** Check REQUIREMENTS.md and PROJECT.md for any specs/ADRs referenced for this phase.
**Source 3 (scout_codebase):** If existing code references docs (e.g., comments citing ADRs), add those.
**Source 4 (discuss_areas):** When the user says "read X", "check Y", or references any doc/spec/ADR during discussion — add it immediately. These are often the MOST important refs because they represent docs the user specifically wants followed.
This list is MANDATORY in CONTEXT.md. Every ref must have a full relative path so downstream agents can read it directly. If no external docs exist, note that explicitly.
2. **Check prior decisions** — Before generating gray areas, check if any were already decided:
- Scan `<prior_decisions>` for relevant choices (e.g., "Ctrl+C only, no single-key shortcuts")
- These are **pre-answered** — don't re-ask unless this phase has conflicting needs
@@ -420,6 +429,14 @@ Ask 4 questions per area before offering to continue or move on. Each answer oft
- Loop: discuss new areas, then prompt again
- If "I'm ready for context": Proceed to write_context
**Canonical ref accumulation during discussion:**
When the user references a doc, spec, or ADR during any answer — e.g., "read adr-014", "check the MCP spec", "per browse-spec.md" — immediately:
1. Read the referenced doc (or confirm it exists)
2. Add it to the canonical refs accumulator with full relative path
3. Use what you learned from the doc to inform subsequent questions
These user-referenced docs are often MORE important than ROADMAP.md refs because they represent docs the user specifically wants downstream agents to follow. Never drop them.
**Question design:**
- Options should be concrete, not abstract ("Cards" not "Option A")
- Each answer should inform the next question
@@ -481,6 +498,27 @@ mkdir -p ".planning/phases/${padded_phase}-${phase_slug}"
</decisions>
<canonical_refs>
## Canonical References
**Downstream agents MUST read these before planning or implementing.**
[MANDATORY section. Write the FULL accumulated canonical refs list here.
Sources: ROADMAP.md refs + REQUIREMENTS.md refs + user-referenced docs during
discussion + any docs discovered during codebase scout. Group by topic area.
Every entry needs a full relative path — not just a name.]
### [Topic area 1]
- `path/to/adr-or-spec.md` — [What it decides/defines that's relevant]
- `path/to/doc.md` §N — [Specific section reference]
### [Topic area 2]
- `path/to/feature-doc.md` — [What this doc defines]
[If no external specs: "No external specs — requirements fully captured in decisions above"]
</canonical_refs>
<code_context>
## Existing Code Insights
@@ -669,6 +707,7 @@ Route to `confirm_creation` step (existing behavior — show manual next steps).
- Each selected area explored until user satisfied (with code-informed and prior-decision-informed options)
- Scope creep redirected to deferred ideas
- CONTEXT.md captures actual decisions, not vague vision
- CONTEXT.md includes canonical_refs section with full file paths to every spec/ADR/doc downstream agents need (MANDATORY — never omit)
- CONTEXT.md includes code_context section with reusable assets and patterns
- Deferred ideas preserved for future phases
- STATE.md updated with session info

View File

@@ -77,6 +77,7 @@ Generating CONTEXT.md from requirements...
- Extract all requirements, user stories, acceptance criteria, and constraints from the PRD
- Map each to a locked decision (everything in the PRD is treated as a locked decision)
- Identify any areas the PRD doesn't cover and mark as "Claude's Discretion"
- **Extract canonical refs** from ROADMAP.md for this phase, plus any specs/ADRs referenced in the PRD — expand to full file paths (MANDATORY)
- Create CONTEXT.md in the phase directory
4. Write CONTEXT.md:
@@ -106,6 +107,21 @@ Generating CONTEXT.md from requirements...
</decisions>
<canonical_refs>
## Canonical References
**Downstream agents MUST read these before planning or implementing.**
[MANDATORY. Extract from ROADMAP.md and any docs referenced in the PRD.
Use full relative paths. Group by topic area.]
### [Topic area]
- `path/to/spec-or-adr.md` — [What it decides/defines]
[If no external specs: "No external specs — requirements fully captured in decisions above"]
</canonical_refs>
<specifics>
## Specific Ideas

View File

@@ -217,9 +217,18 @@ ${any_specific_references_or_examples_from_discussion}
[If none: "No specific requirements — open to standard approaches"]
</specifics>
<canonical_refs>
## Canonical References
${any_specs_adrs_or_docs_referenced_during_discussion}
[If none: "No external specs — requirements fully captured in decisions above"]
</canonical_refs>
```
Note: Quick task CONTEXT.md omits `<code_context>` and `<deferred>` sections (no codebase scouting, no phase scope to defer to). Keep it lean.
Note: Quick task CONTEXT.md omits `<code_context>` and `<deferred>` sections (no codebase scouting, no phase scope to defer to). Keep it lean. The `<canonical_refs>` section is included when external docs were referenced — omit it only if no external docs apply.
Report: `Context captured: ${QUICK_DIR}/${next_num}-CONTEXT.md`