feat(analyze-before-plan): read-before bookend — scan memory (+code) before planning

Shared include lib/analyze-before-plan.md (two-pass on '## <PREFIX>-' headings, disposition-not-reading invariant, guarded no-op). Wired into the dev flows: ship-feature STEP 0d (analyzer code+memory, INPUT INJECTION into brainstorm/plan + STEP 3 reconciliation gate), bugfix STEP 2.5 (blockers-first), feat STEP 0.6 (decisions-first, MINI-PLAN names in-force or states none), hotfix opt-in. analyzer gains a RELATED MEMORY output section pointing at the include (DRY). init-project / onboard no-op by construction (guarded scan on absent/empty registries).

Mirror of the coupled-capitalize write-after (BDR-034): read-before / write-after bookend.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ho5EQCFTSvYamuRtVZpp2d
This commit is contained in:
Bastien Chanot
2026-06-26 23:46:41 +02:00
co-authored by Claude Opus 4.8
parent 07e846f0a6
commit 67c6a8165d
6 changed files with 228 additions and 2 deletions
+26
View File
@@ -64,6 +64,12 @@ RISKS:
OPEN QUESTIONS:
- <ambiguity to clarify>
RELATED MEMORY:
- IN FORCE: <id> — <title> — <how it constrains this work> [status] (detail each)
- ALREADY SEEN: <BLK-id> — <title> [status] (known cause/fix — don't re-derive)
- NON-BINDING: <c> surfaced, none binding — <bare id refs> (superseded / N-A — counted)
- SELECTION: scanned <N> headings — surfaced <K> = in-force <a> + seen <b> + non-binding <c>
```
Surface discovered patterns and conventions in the analysis output
@@ -73,6 +79,26 @@ happens in the main thread via the gated capitalize flow.
---
## RELATED MEMORY (read-before)
When `.claude/memory/` exists and holds entries, run the memory-relevance scan per
`$HOME/.claude/lib/analyze-before-plan.md` (PASS 1: grep `## <PREFIX>-` headings →
select on titles → PASS 2: full-read only the selected bodies) and populate the
RELATED MEMORY section of OUTPUT.
The contract is DISPOSITION, not retrieval: every surfaced ID gets a verdict —
in-force / already-seen / non-binding. Detail the binding ones (IN FORCE, ALREADY SEEN —
they constrain the work); COUNT the non-binding (superseded / N-A) as one line with bare
refs — a per-entry paragraph on a non-binding match dilutes the in-force ones that bite.
A surfaced ID left undisposed is the gap this closes. You judge bearing; the main-thread
plan decides what to DO.
Read-only here too: reading registries is within Read/Grep; the "Do not modify files" rule
still forbids any write — Index backfill or new entries are never your job. Empty or absent
registries → omit the section (no-op).
---
## EDGE CASES
| Situation | Action |
+12
View File
@@ -60,6 +60,18 @@ Trace the bug from symptom to root cause:
# grep for the same pattern to assess blast radius
```
## STEP 2.5 — MEMORY READ-BEFORE (blockers-first)
Run the scan per `$HOME/.claude/lib/analyze-before-plan.md`, blockers-weighted: a resolved
BLK may already name THIS exact root cause; an in-force BDR may constrain the fix. Emit
RELATED MEMORY. Consumption is NATURAL — the agent emitting this IS the one writing STEP 3's
diagnosis (reader = planner, no external skill to inject into).
TEETH: STEP 3's DIAGNOSIS must name any binding prior (`PRIOR: BLK-xxx — known cause/fix`,
or `honors BDR-xxx`) OR the RELATED MEMORY line states none bears. Reading blockers then
diagnosing without naming a match is the read-then-ignore failure this prevents.
`.claude/memory/` absent → guarded no-op, proceed.
## STEP 3 — HYPOTHESIZE + PLAN
Present findings before fixing:
+10
View File
@@ -58,6 +58,13 @@ Follow `$HOME/.claude/lib/design-gate.md`:
tell the user to run `/profile design` before proceeding.
- If no signals → skip (zero overhead).
## STEP 0.6 — MEMORY READ-BEFORE (decisions-first)
Run the scan per `$HOME/.claude/lib/analyze-before-plan.md`, decisions-weighted: a BDR may
already constrain or forbid the approach; an LRN may name a gotcha to apply. Emit RELATED
MEMORY; feed STEP 1 MINI-PLAN. Inline consumption — reader = planner, no injection.
`.claude/memory/` absent → guarded no-op (zero overhead on a memory-less repo).
## STEP 1 — MINI-PLAN
Quick mental model, not a formal plan document:
@@ -66,6 +73,9 @@ Quick mental model, not a formal plan document:
2. Describe the approach in 2-5 bullet points.
3. Note any edge cases to handle.
4. If tests exist for the area, note which tests to add/update.
5. Disposition (from STEP 0.6): name each in-force BDR/LRN this plan honors
(`honors BDR-xxx by …`), or state `no in-force decision constrains this feature`.
A plan with neither = read-then-ignore; the disposition must surface as a trace.
Print the plan as a compact checklist:
```
+8
View File
@@ -31,6 +31,14 @@ git log --oneline -3
"This looks deeper than a hotfix. Load `$HOME/.claude/agents/bugfixer.md`
and run the BUGFIXER agent on this target."
OPTIONAL — memory check (exempt by default; hotfix = obvious fix, mirror of its capitalize
skip). For a RECURRING or urgent bug only, a quick blockers-only glance may save time:
[ -d .claude/memory ] && grep -nE '^## BLK-' .claude/memory/blockers.md # "déjà vu ?"
If a prior BLK names this bug, jump to its solution. Not mandatory; no RELATED MEMORY
disposition required at hotfix weight.
## STEP 1.5 — DESIGN GATE
Follow `$HOME/.claude/lib/design-gate.md`: