baldart 3.41.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/VERSION +1 -1
  3. package/framework/.claude/agents/REGISTRY.md +72 -24
  4. package/framework/.claude/agents/api-perf-cost-auditor.md +17 -10
  5. package/framework/.claude/agents/code-reviewer.md +31 -24
  6. package/framework/.claude/agents/codebase-architect.md +47 -43
  7. package/framework/.claude/agents/coder.md +29 -18
  8. package/framework/.claude/agents/doc-reviewer.md +57 -30
  9. package/framework/.claude/agents/plan-auditor.md +85 -20
  10. package/framework/.claude/agents/prd-card-writer.md +44 -14
  11. package/framework/.claude/agents/prd.md +22 -3
  12. package/framework/.claude/agents/qa-sentinel.md +33 -15
  13. package/framework/.claude/agents/security-reviewer.md +65 -10
  14. package/framework/.claude/agents/senior-researcher.md +8 -1
  15. package/framework/.claude/agents/ui-expert.md +22 -7
  16. package/framework/.claude/commands/check.md +31 -11
  17. package/framework/.claude/commands/codexreview.md +48 -29
  18. package/framework/.claude/commands/new.md +29 -330
  19. package/framework/.claude/commands/qa.md +57 -37
  20. package/framework/.claude/skills/api-design-principles/SKILL.md +2 -2
  21. package/framework/.claude/skills/bug/SKILL.md +8 -8
  22. package/framework/.claude/skills/bug/references/logging-patterns.md +8 -2
  23. package/framework/.claude/skills/context-primer/SKILL.md +29 -8
  24. package/framework/.claude/skills/doc-writing-for-rag/SKILL.md +36 -36
  25. package/framework/.claude/skills/frontend-design/SKILL.md +10 -8
  26. package/framework/.claude/skills/new/SKILL.md +409 -302
  27. package/framework/.claude/skills/prd/SKILL.md +67 -38
  28. package/framework/.claude/skills/prd/assets/card-template.yml +22 -26
  29. package/framework/.claude/skills/prd/assets/epic-template.yml +5 -5
  30. package/framework/.claude/skills/prd/assets/prd-template.md +1 -1
  31. package/framework/.claude/skills/prd/assets/state-template.md +25 -3
  32. package/framework/.claude/skills/prd/references/api-perf-gate.md +143 -33
  33. package/framework/.claude/skills/prd/references/audit-phase.md +48 -34
  34. package/framework/.claude/skills/prd/references/backlog-phase.md +38 -11
  35. package/framework/.claude/skills/prd/references/discovery-phase.md +121 -44
  36. package/framework/.claude/skills/prd/references/impact-analysis.md +127 -23
  37. package/framework/.claude/skills/prd/references/prd-add-phase.md +18 -214
  38. package/framework/.claude/skills/prd/references/prd-writing-phase.md +52 -42
  39. package/framework/.claude/skills/prd/references/research-phase.md +105 -19
  40. package/framework/.claude/skills/prd/references/ui-design-phase.md +20 -8
  41. package/framework/.claude/skills/prd/references/validation-phase.md +97 -72
  42. package/framework/.claude/skills/prd-add/SKILL.md +70 -20
  43. package/framework/.claude/skills/simplify/SKILL.md +22 -12
  44. package/framework/.claude/skills/ui-design/SKILL.md +26 -7
  45. package/framework/.claude/skills/webapp-testing/SKILL.md +6 -4
  46. package/framework/.claude/skills/worktree-manager/SKILL.md +206 -143
  47. package/framework/agents/coding-standards.md +85 -0
  48. package/framework/agents/skills-mapping.md +85 -82
  49. package/framework/agents/testing.md +6 -4
  50. package/framework/templates/baldart.config.template.yml +29 -7
  51. package/package.json +1 -1
  52. package/src/commands/configure.js +43 -9
  53. package/framework/.claude/skills/prd-add/references/impact-analysis.md +0 -233
@@ -8,10 +8,20 @@ Run BEFORE any other step.
8
8
  the main repo and scan for an entry with `kind: "docs"` whose `slug` matches
9
9
  the feature the user just mentioned (or that you can infer from their
10
10
  message — e.g., `/prd-add` for an active PRD).
11
- - **Found**: `cd` into the worktree's `path` (save as `$WORKTREE_PATH`),
11
+ - **Found — worktree path exists on disk**: `cd` into the worktree's `path`
12
+ (save as `$WORKTREE_PATH`), verify that `pwd` prints the worktree path,
12
13
  log "Resuming PRD session in worktree `<path>`", then continue to step 2.
13
14
  All subsequent file paths in this skill resolve under `$WORKTREE_PATH`
14
15
  (HARD RULE 17).
16
+ - **Found — worktree path MISSING on disk** (`stale-registry-but-worktree-exists`):
17
+ the registry entry is present but the directory was deleted (e.g. after a
18
+ failed `/cw` or disk cleanup). HALT and surface:
19
+ `WORKTREE_STALE: Registry entry for slug '<slug>' points to '<path>' but
20
+ that path does not exist on disk. Options: (a) re-create the worktree with
21
+ the same slug via nw-docs and restore files from git history, (b) start a
22
+ fresh session (new slug).`
23
+ **Do NOT proceed** — writing files without a valid working directory will
24
+ silently corrupt the session.
15
25
  - **Not found, but main repo has a stale state file** at
16
26
  `${paths.prd_dir}/sessions/*-<slug>-state.md`: this is a pre-v3.22.0 PRD
17
27
  session created before the worktree mandate. ASK the user: "Found a
@@ -21,11 +31,23 @@ Run BEFORE any other step.
21
31
  files into it. If legacy mode: STOP and warn that parallel sessions
22
32
  will pollute `git status`.
23
33
  - **Not found and no state file**: fresh session, proceed to Step 1.
24
- 2. With `$WORKTREE_PATH` resolved (or null for fresh sessions), check if
25
- `$WORKTREE_PATH/${paths.prd_dir}/sessions/` contains a state file for the
26
- current feature.
27
- 3. If found: read it, identify last completed step, resume from next pending step.
28
- 4. If not found: proceed to Step 1.
34
+ 2. **Only when `$WORKTREE_PATH` is non-null** (i.e. this is a resume, not a
35
+ fresh session): check if `$WORKTREE_PATH/${paths.prd_dir}/sessions/` contains
36
+ a state file for the current feature. If `$WORKTREE_PATH` is null (fresh
37
+ session), skip this check entirely and proceed to Step 1.
38
+ 3. If state file found: read it, identify last completed step and any
39
+ in-progress sub-state, then apply the **resume dispatch table** below.
40
+ 4. If state file not found: proceed to Step 1.
41
+
42
+ **Resume dispatch table** — after reading the state file, check its status
43
+ field and apply the matching branch before resuming the normal step sequence:
44
+
45
+ | State file status | Branch |
46
+ |---|---|
47
+ | `mockups.status: requested` AND `mockups.format: pending` | **`mockups pending-input`**: the session was waiting for the user to provide mockup paths/images (Step 1.6.3 STOP). Re-ask: "Stiamo riprendendo la sessione PRD per `<slug>`. Stavi per fornirmi i mockup — in che forma me li passi? (immagini in chat / path locali / archivio .zip)" STOP and wait. |
48
+ | `status: research-in-progress` (background researcher was running) | **`research in-progress`**: log "Resuming — `senior-researcher` was running in background. Attempting to retrieve result." Invoke `senior-researcher` retrieve (or re-launch if result is unavailable). Process findings per the Research Trigger exit check (§ Exit condition) before proceeding. |
49
+ | `status: pending-external-handoff` | **`pending_external_handoff`**: a prior session ended mid-flow waiting on an external dependency (API contract, design handoff, credentials, etc.). Inform the user: "La sessione era in attesa di: `<state.pending_reason>`. Il blocco è stato risolto?" Wait for confirmation before resuming. |
50
+ | Any other status | Resume from the next uncovered step/dimension normally. |
29
51
 
30
52
  Triggers: session start, context compression, re-invocation of `/prd`, every
31
53
  `/prd-add` invocation.
@@ -81,13 +103,15 @@ this is a fresh session (no existing state file).
81
103
  - `[PRD] Validazione, commit & merge`
82
104
  6. Mark task 1 as `in_progress`.
83
105
  7. **Context Loading (MANDATORY):** invoke the context-primer skill (`/cont`) with
84
- 2-4 keywords extracted from the user's feature description. This launches
85
- `codebase-architect` which searches the Obsidian-first LightRAG MCP index,
86
- docs, backlog, source code, and git history. The returned context informs all
87
- subsequent discovery dimensions. Additionally, run `search_docs` MCP with `mode: "hybrid"` for the
88
- feature domain. Use Obsidian hits for concept context, then verify
89
- implementation and stateful claims against repo docs/code before carrying
90
- them into the PRD.
106
+ 2-4 keywords extracted from the user's feature description and
107
+ `task_type: "new-feature"` (always explicit do NOT let context-primer
108
+ default to `"query"` for domain keywords, which produces a narrower
109
+ RAG-only context). context-primer internally calls `codebase-architect`
110
+ which runs `search_docs mode: hybrid`, checks docs, backlog, source code,
111
+ and git history. The returned context informs all subsequent discovery
112
+ dimensions. **Do NOT issue a separate `search_docs` call** — context-primer
113
+ already covers it, and a second call with the same query wastes context
114
+ window and doubles wiki_log telemetry entries.
91
115
  8. Mark clearly irrelevant dimensions as "N/A" with reason
92
116
  (e.g., backend-only -> UI impact = N/A).
93
117
  If UI impact is N/A, immediately mark task 2 as `completed` ("Skipped — no UI").
@@ -116,7 +140,7 @@ Descrizione: <user's description>
116
140
  Contesto: <one-line summary from context-primer>
117
141
 
118
142
  Tutti i file del PRD vivono nel worktree — il main repo resta pulito.
119
- Al termine commit + merge automatico in develop + cleanup worktree, seamless.
143
+ Al termine commit + merge automatico in `git.trunk_branch` + cleanup worktree, seamless.
120
144
  (Se in qualunque momento mi dici "non mergiare", mi fermo dopo il commit.)
121
145
 
122
146
  Ora comincio la fase di **Discovery** — ti faro delle domande per capire bene
@@ -125,9 +149,12 @@ la feature prima di scrivere qualsiasi documento.
125
149
  <Progress Bar>
126
150
  ```
127
151
 
128
- **Gate:** docs worktree created (registry entry with `kind: "docs"` present)
129
- AND state file exists on disk inside the worktree AND all tasks created AND
130
- context loaded.
152
+ **MONITORING SIGNAL (non-blocking):** docs worktree created (registry entry with
153
+ `kind: "docs"` present) AND state file exists on disk inside the worktree AND
154
+ all tasks created AND context loaded. These are logged for observability; they
155
+ do not halt execution. Precondition failures that would surface as a STOP are
156
+ already handled by the BLOCKING gates in points 3 and 4 above — this note is
157
+ a post-completion consistency reminder only, not an additional gate.
131
158
 
132
159
  **Immediately proceed to Step 1.6** — do NOT stop here. Show the kickoff message
133
160
  and ask the mockup intake question in the same turn.
@@ -286,7 +313,8 @@ Build the scope vector from the Kickoff state (Step 1):
286
313
  - Verbatim screen names the user mentioned in the initial description.
287
314
  - Keywords from `feature_objective_one_sentence` (strip stopwords).
288
315
 
289
- For each candidate, compute a relevance score 0-100:
316
+ For each candidate, compute a relevance score 0-100
317
+ [CALIBRATION-NEEDED: weights below are heuristic; validate against a labeled mockup corpus]:
290
318
  - `+40` if any scope keyword appears in the filename (case-insensitive,
291
319
  whole-word; for kebab/snake/camelCase, split before matching).
292
320
  - `+30` if any scope keyword appears in the HTML `<title>` or `<h1>`.
@@ -296,11 +324,12 @@ For each candidate, compute a relevance score 0-100:
296
324
  - `-20` if the filename matches typical non-screen patterns (`icon`, `logo`,
297
325
  `favicon`, `thumbnail`, `og-image`, `sitemap`, `manifest`).
298
326
 
299
- Selection threshold: keep candidates with `score 30` as the auto-selected set.
300
- If fewer than 3 candidates clear the threshold, lower to `≥ 20` and surface the
301
- fact. If zero candidates clear `≥ 20`, surface "selezione non automatizzabile —
302
- ti chiedo di indicarmi a mano quali sono rilevanti" and present the full
303
- candidate list.
327
+ Selection threshold [CALIBRATION-NEEDED: ≥30/≥20/min-3 are heuristic; no labeled
328
+ dataset validates these cut-offs]: keep candidates with `score 30` as the
329
+ auto-selected set. If fewer than 3 candidates clear the threshold, lower to
330
+ `≥ 20` and surface the fact. If zero candidates clear `≥ 20`, surface
331
+ "selezione non automatizzabile — ti chiedo di indicarmi a mano quali sono
332
+ rilevanti" and present the full candidate list.
304
333
 
305
334
  Record per-candidate: `score`, `matched_keywords[]`, `selected: bool`.
306
335
 
@@ -388,12 +417,15 @@ nei mockup. Le ambiguità rilevate diventeranno domande mirate.
388
417
 
389
418
  ### Coordination with `/cont`
390
419
 
391
- The `/cont` skill invoked in Step 1.5 runs synchronously and completes before the
392
- kickoff output. The mockup intake question is asked in the same message; if the user
393
- answers "Sì", the STOP gives the codebase context time to settle in conversation
394
- history while we wait. When the mockups arrive, the visual analysis combines with the
395
- already-loaded codebase context to inform Discovery dimension selection (especially
396
- dimension 5 UI impact and partially dimension 2 User journey, both of which can be
420
+ The `/cont` skill is invoked at **Step 1, point 7** (after the worktree and
421
+ state file are created and macro-tasks are registered, but before the Business
422
+ Rationale Extraction at point 9). It runs synchronously and completes before
423
+ the kickoff output is displayed. The mockup intake question (Step 1.6.1) is
424
+ asked in the same output message; if the user answers "Sì", the STOP gives the
425
+ codebase context time to settle in conversation history while we wait. When the
426
+ mockups arrive, the visual analysis combines with the already-loaded codebase
427
+ context to inform Discovery dimension selection (especially dimension 5 UI
428
+ impact and partially dimension 2 User journey, both of which can be
397
429
  pre-populated from `mockup_analysis`).
398
430
 
399
431
  ## Step 2 — Discovery Question Loop
@@ -406,7 +438,7 @@ update state, send NEXT question, STOP again.
406
438
 
407
439
  ### Dimension 0 — Business Rationale (ALWAYS FIRST)
408
440
 
409
- If already covered in Step 1.7, skip to dimension 1.
441
+ If already covered in Step 1, point 9 (Business Rationale Extraction), skip to dimension 1.
410
442
 
411
443
  Otherwise, present this question:
412
444
 
@@ -433,9 +465,10 @@ section of the state file. Mark dimension as covered.
433
465
  **Precondition:** at least one dimension has status `-` (uncovered).
434
466
 
435
467
  1. Select next uncovered dimension (in checklist order).
436
- 2. **Use the context already loaded by context-primer (Step 1.5)** to check if
437
- the codebase already answers this dimension. The context-primer output includes
438
- key docs, key code paths, status, and gotchas — use these to evaluate.
468
+ 2. **Use the context already loaded by context-primer (Step 1, point 7)** to
469
+ check if the codebase already answers this dimension. The context-primer
470
+ output includes key docs, key code paths, status, and gotchas — use these
471
+ to evaluate.
439
472
  If more specific detail is needed beyond what context-primer provided,
440
473
  invoke `codebase-architect` agent (foreground) with a targeted question:
441
474
  ```
@@ -488,9 +521,13 @@ section of the state file. Mark dimension as covered.
488
521
  Vuoi che avvii un'analisi di impatto (/prd-add) per integrarla nel PRD,
489
522
  oppure la notiamo come out-of-scope?`
490
523
  - **STOP.** Wait for user response.
491
- - If user confirms: read [prd-add-phase.md](prd-add-phase.md) and execute
492
- the Change Request flow. After it completes, resume discovery from the
493
- next uncovered dimension.
524
+ - If user confirms: record in the state file under `## Discovery Cursor`
525
+ the current dimension index (e.g. `cursor: 5`) and the current
526
+ comprehension score before entering the CR flow. Then invoke the
527
+ canonical **`prd-add` skill** ([../../prd-add/SKILL.md](../../prd-add/SKILL.md))
528
+ — the worktree-aware implementation, NOT the `prd-add-phase.md` stub — and
529
+ execute the Change Request flow. After it completes, read `## Discovery Cursor` from the state
530
+ file to restore position, then resume from the next uncovered dimension.
494
531
  - If user says out-of-scope: note in Discovery Log and continue.
495
532
  - **New-Screen Check** (only when `mockups.status` ∈ {`provided`, `partial`}):
496
533
  When the user's answer reveals a UI screen NOT present in
@@ -598,8 +635,15 @@ Instead, run the E2E Evaluation Decision Tree and present the result.
598
635
  **Result categories:**
599
636
  - **NOT NEEDED**: auto-resolve — log reason, mark dimension covered, show inline
600
637
  summary, continue to next dimension (no STOP, no user confirmation needed).
601
- - **RECOMMENDED**: auto-accept (default: yes) proceed to credential gathering
602
- without asking. Show inline: `E2E: RECOMMENDED — accettato automaticamente.`
638
+ - **RECOMMENDED**: present the verdict and ask for explicit confirmation — do
639
+ NOT auto-accept. Show inline:
640
+ ```
641
+ E2E: RECOMMENDED (>3 UI acceptance criteria, no critical-path triggers).
642
+ Vuoi includerla nel piano di test? (Sì / No)
643
+ ```
644
+ **STOP.** If the user confirms: proceed to credential gathering. If the user
645
+ declines: log `e2e: skipped (user declined RECOMMENDED)`, mark dimension
646
+ covered, continue.
603
647
  - **REQUIRED**: E2E tests MUST be planned. Proceed to credential gathering.
604
648
 
605
649
  **When E2E is REQUIRED or user accepts RECOMMENDED:**
@@ -662,13 +706,25 @@ Instead, run the E2E Evaluation Decision Tree and present the result.
662
706
  > file are intentionally generic. Project-specific defaults live in
663
707
  > `.baldart/overlays/prd.md` (consumer-owned, not redistributed).
664
708
 
665
- ### Research Trigger (evaluated at ~75% comprehension)
709
+ ### Research Trigger (SEMANTIC gate — evaluated at ~75% comprehension)
710
+ [CALIBRATION-NEEDED: "6 non-test dimensions" ≈ 75% of 10 is the trigger point; validate
711
+ threshold against session data — earlier triggers may reduce re-work on complex features.]
666
712
 
667
713
  When 6+ non-test dimensions are covered, evaluate complexity signals from
668
- discovery answers and codebase-architect findings. Read
669
- [research-phase.md](research-phase.md) for full signal list and logic.
670
-
671
- **Quick decision:**
714
+ discovery answers and `codebase-architect` findings using the signal table
715
+ S1–S6 below. (The same table also appears in `research-phase.md`; either
716
+ source is authoritative — do NOT issue a separate file-read mid-discovery.)
717
+
718
+ | ID | Signal | Example |
719
+ |----|--------|---------|
720
+ | S1 | Unfamiliar technical domain | edge caching, payment SCA, WebRTC |
721
+ | S2 | Regulatory / compliance requirement | GDPR, PCI-DSS, PSD2 |
722
+ | S3 | Complex algorithm / heuristic | scoring, ranking, scheduling |
723
+ | S4 | Integration with external system | third-party API, webhook consumer |
724
+ | S5 | User expressed uncertainty | "non so se X sia fattibile" |
725
+ | S6 | Prior art uncertain | no known precedent in codebase |
726
+
727
+ **SEMANTIC decision:**
672
728
  - **2+ signals OR regulatory (S2) OR user uncertainty (S5)** → HIGH confidence
673
729
  → launch `senior-researcher` in **background immediately**, continue discovery.
674
730
  Update progress bar: `Ricerca: 🔍 in corso (background)`.
@@ -681,7 +737,28 @@ If research launched in background: it runs in parallel with remaining questions
681
737
 
682
738
  Comprehension >= 99% OR user explicitly says to proceed.
683
739
 
684
- **Before exiting, check research status** (read [research-phase.md](research-phase.md)):
740
+ **Comprehension formula:** `covered / relevant * 100`, where:
741
+ - **`relevant`** = all dimensions whose status is not "N/A".
742
+ - **`covered`** = dimensions whose status is "covered" (any source).
743
+ - Dimension 9 (ISA — auto-scan) and dimension 10 (Test Strategy) ARE included
744
+ in both `relevant` and `covered` once they resolve. The Research Trigger
745
+ uses "6+ non-test dimensions" to avoid waiting for dim 10, but the exit
746
+ formula counts all non-N/A dimensions uniformly.
747
+
748
+ **Before exiting, resolve mockup gaps (BLOCKING check):**
749
+ Scan `mockup_analysis.screens[].gaps[]` across all screens in the state file.
750
+ Every gap entry must be either:
751
+ - Converted to a Discovery question (already asked and answered), OR
752
+ - Explicitly recorded in the Discovery Log as `"skipped — outside mockup scope"`.
753
+
754
+ If any gap remains unresolved (neither answered nor skipped), DO NOT proceed
755
+ to Step 3/4. Either ask the gap as the next Discovery question, or ask the
756
+ user: `"Gap '<gap text>' dal mockup non è stato risolto. Lo includo come
757
+ domanda di discovery, oppure lo segniamo come fuori scope?"` **STOP** and wait.
758
+
759
+ **Before exiting, check research status** (refer to signal table in § Research
760
+ Trigger; read `research-phase.md` only if you need its credential-gathering
761
+ appendix or extended context, not for the signal table):
685
762
  1. **HIGH confidence, researcher returned** → process findings, ask follow-up
686
763
  questions if gaps found, then exit.
687
764
  2. **HIGH confidence, researcher still running** → inform user, wait for result.
@@ -1,8 +1,9 @@
1
1
  # ICIAS Impact Analysis Protocol
2
2
 
3
3
  Full protocol for Change Impact Analysis on PRD sessions.
4
- Based on ProReFiCIA (Etezadi et al. 2025), CodePlan (Bairi et al. 2023),
5
- and FMEA-adapted scoring.
4
+ [DESIGN-CHOICE: multi-dimensional impact scoring adapted from FMEA risk-priority
5
+ scoring and structural-propagation principles from dependency-graph research.
6
+ Artifact Stakes and threshold bands are heuristics — see Calibration Notes.]
6
7
 
7
8
  ---
8
9
 
@@ -22,10 +23,12 @@ For each of the 10 dimensions, determine:
22
23
 
23
24
  ### Refinement pass (mandatory)
24
25
 
25
- After initial scan, re-read the change request and check dimensions 4-7
26
- again (the "middle" of the list — LLMs tend to under-evaluate items in
27
- the middle of lists, per "lost-in-the-middle" research). Adjust any
28
- dimension that was initially scored 0 but deserves >= 1 on second look.
26
+ After initial scan, re-read the change request and check dimensions D4–D7
27
+ again (API, UI, Permissions, Edge Cases).
28
+ [DESIGN-CHOICE: explicit second-pass on middle dimensions guards against
29
+ systematic under-evaluation of non-first/non-last items in structured lists.]
30
+ Adjust any dimension that was initially scored 0 but deserves >= 1 on
31
+ second look.
29
32
 
30
33
  ---
31
34
 
@@ -40,8 +43,19 @@ Apply the coupling matrix to find transitive (cascade) impacts.
40
43
  3. If edge strength >= 2 AND target dimension has I = 0: mark as cascade impact.
41
44
  - Cascade I = max(1, source_I - 1) (degrades by hop)
42
45
  - Cascade C = source_C - 1 (min 1) (confidence degrades)
43
- 4. Max hop depth = 2. Do NOT propagate beyond 2 hops.
46
+ - Note: at min C=1, a two-hop cascade is indistinguishable from a one-hop
47
+ cascade by confidence alone. The scored verdict (I×C×A) still differentiates
48
+ them via I degradation across hops.
49
+ 4. Max hop depth = 2. Do NOT propagate beyond 2 hops. [CALIBRATION-NEEDED:
50
+ the 2-hop cap is a heuristic chosen to bound transitive blast radius; a
51
+ deeper cap may surface real far cascades, a shallower one fewer false ones —
52
+ validate against observed missed/false cascades after 10–15 change requests.]
53
+ **Cycle guard**: maintain a visited set of dimension IDs for each traversal
54
+ path. If the next target is already in the visited set, do NOT propagate —
55
+ skip that edge entirely. This prevents the D3↔D4 mutual-coupling cycle from
56
+ overwriting a Phase 1 direct score with a phantom hop-2 cascade score.
44
57
  5. If a dimension is reached by both direct and cascade: use direct (higher confidence).
58
+ 6. If a dimension is reached by cascade via two different paths: use the higher score.
45
59
 
46
60
  ### Coupling Matrix (10x10)
47
61
 
@@ -81,6 +95,26 @@ D10 TS 0 0 0 0 0 0 0 0 0 -
81
95
 
82
96
  ---
83
97
 
98
+ ### Semantic Override Rule (Phase 2 only)
99
+
100
+ A **semantic override** sets a cascade dimension's I to 0 when explicit
101
+ information in the CR contradicts the computed cascade. Precedence rules:
102
+
103
+ 1. **Only the executing agent may apply a semantic override** — never silently.
104
+ 2. **Eligible cases**: the CR contains an explicit, unambiguous statement that
105
+ negates the cascade (e.g. "no schema changes", "same endpoint contract").
106
+ Absence of mention does NOT qualify as a semantic override.
107
+ 3. **A=3 dimensions (D3 Data Model, D4 API, D9 Integration Surface) require
108
+ user confirmation** before a semantic override is accepted. Present the
109
+ computed cascade and the stated reason; receive explicit acknowledgement.
110
+ Do NOT proceed silently.
111
+ 4. **Document every override** in the state file under `## Semantic Overrides`
112
+ (dimension, original cascade I/C, stated reason, user confirmed: yes/no).
113
+ 5. If the override is disputed or unclear: **do not override** — retain the
114
+ computed cascade value.
115
+
116
+ ---
117
+
84
118
  ## Phase 3 — ICIAS Scoring
85
119
 
86
120
  For each dimension with I > 0 (direct or cascade):
@@ -101,7 +135,11 @@ For each dimension with I > 0 (direct or cascade):
101
135
  | 2 | Probable | Logical deduction, codebase pattern suggests it |
102
136
  | 3 | Certain | Explicitly stated in CR, or direct code dependency |
103
137
 
104
- **A = Artifact Stakes** (pre-assigned, fixed per dimension):
138
+ **A = Artifact Stakes** (pre-assigned, fixed per dimension) [CALIBRATION-NEEDED:
139
+ these bands are FMEA-borrowed heuristics; D8 Rollout/Migration at A=1 may
140
+ under-weight data-migration risk in production systems — review after 10–15
141
+ real change requests and recalibrate if D8 produces false-PATCH verdicts]:
142
+
105
143
  | A=3 (High stakes) | A=2 (Medium stakes) | A=1 (Low stakes) |
106
144
  |-------------------|---------------------|-------------------|
107
145
  | D3 Data Model | D2 User Journey | D1 Target Users |
@@ -109,20 +147,50 @@ For each dimension with I > 0 (direct or cascade):
109
147
  | D9 Integration Surface | D6 Permissions | D8 Rollout/Migration |
110
148
  | | D10 Test Strategy | |
111
149
 
150
+ > **A=1 scoring ceiling**: D1, D7, D8 have a *raw-score* ceiling of 9
151
+ > (3×3×1) → PATCH at most **by score alone**. This is a ceiling of the
152
+ > arithmetic, not a hard cap on the verdict: a structural change on an A=1
153
+ > dimension CAN still reach REDO through the **structural scope exception**
154
+ > in the Verdict thresholds section below (a user-confirmed verdict
155
+ > escalation), so REDO remains reachable for D1, D7, D8.
156
+
112
157
  ### Verdict thresholds
113
158
 
159
+ [CALIBRATION-NEEDED: the SKIP/PATCH/REDO score-band cut-points (1–2, 3–9,
160
+ 10–27) are FMEA-adapted heuristics, not empirically tuned for PRD CIA; the
161
+ true cut-points that minimise false-PATCH and missed-REDO verdicts should be
162
+ revisited after 10–15 real change requests — see Calibration Notes.]
163
+
114
164
  | Score Range | Verdict | Meaning |
115
165
  |-------------|---------|---------|
116
166
  | 0 | SKIP | No impact detected |
117
- | 1–3 | SKIP | Negligible impact, no revision needed |
118
- | 4–9 | PATCH | Moderate impact, surgical update to affected sections |
167
+ | 1–2 | SKIP | Negligible impact, no revision needed |
168
+ | 3–9 | PATCH | Moderate impact, surgical update to affected sections |
119
169
  | 10–27 | REDO | Major impact, phase must be substantially re-executed |
120
170
 
171
+ > **Structural scope exception — A=1 dimensions CAN reach REDO.** By raw score
172
+ > alone, D1, D7, D8 top out at 9 (always PATCH). But a structural change
173
+ > (I=3) on one of these dimensions can still demand a full phase
174
+ > re-execution — e.g. fully re-running a rollout/migration plan (D8) or
175
+ > completely re-specifying the edge-case set (D7). When the executing agent
176
+ > judges that the scored PATCH understates the real work, it MUST:
177
+ > 1. Flag a **structural scope exception** (do not silently accept the PATCH).
178
+ > 2. Present the dimension, its score, and the reason the work is REDO-scale
179
+ > to the user via `AskUserQuestion` (PATCH vs escalate-to-REDO).
180
+ > 3. On explicit user confirmation, **escalate the verdict to REDO** (a
181
+ > verdict-level override, recorded alongside the score; the raw score is
182
+ > left intact for calibration). Without confirmation, retain PATCH.
183
+ >
184
+ > This keeps REDO genuinely reachable for A=1 dimensions while preventing a
185
+ > silent over- or under-escalation. [DESIGN-CHOICE: escalation is a
186
+ > user-gated verdict override rather than an A-value bump, so the FMEA score
187
+ > stays comparable across change requests and the override is auditable.]
188
+
121
189
  ### Bias rule
122
190
 
123
191
  **False negatives are worse than false positives.** When uncertain:
124
192
  - Round C up, not down
125
- - Prefer PATCH over SKIP when on the boundary (score = 3)
193
+ - Score = 3 resolves to PATCH (not SKIP) per the threshold table above
126
194
  - Prefer REDO over PATCH only when I = 3 (structural)
127
195
 
128
196
  ---
@@ -133,8 +201,11 @@ After scoring all dimensions, map to PRD phases:
133
201
 
134
202
  ### Discovery phase impact
135
203
  - ANY dimension with PATCH/REDO → Discovery needs delta update
136
- - PATCH: update state file checklist, run codebase-architect on affected dims
137
- - REDO: re-run discovery question loop for affected dims
204
+ - PATCH: update state file checklist; invoke codebase-architect on affected
205
+ dimensions using the dimensional prompt template defined in
206
+ `references/discovery-phase.md` Step 2 dimension loop (do not use an
207
+ unstructured invocation).
208
+ - REDO: re-run discovery question loop for affected dims (see discovery-phase.md)
138
209
 
139
210
  ### UI Design phase impact
140
211
  - D2 Journey REDO OR D5 UI REDO → UI Design REDO
@@ -158,8 +229,18 @@ After scoring all dimensions, map to PRD phases:
158
229
  | D9 Integration | 15 (ISA) |
159
230
  | D10 Tests | 13 (Test Plan) |
160
231
 
232
+ ### Integration Surface Analysis (ISA) — always re-scan
233
+
234
+ **Trigger**: ANY dimension receives verdict PATCH or REDO (regardless of which
235
+ dimension). The ISA re-scan is mandatory and cannot be suppressed by a SKIP
236
+ verdict on D9.
237
+
238
+ Procedure: run a delta ISA scan focused on the new requirement; merge new
239
+ touchpoints into the existing ISA table; assign new ISA-N IDs.
240
+
161
241
  ### Backlog Cards impact
162
- - New structural entities (I=3) → new cards needed
242
+ - New verdict REDO on any dimension evaluate whether new cards are needed
243
+ - New structural entities confirmed (I=3, REDO verdict) → new cards needed
163
244
  - Changed acceptance criteria → update existing cards
164
245
  - Changed dependencies → update `depends_on` fields
165
246
 
@@ -188,11 +269,27 @@ Change type: Addition (new endpoint)
188
269
 
189
270
  ### Phase 2 — Structural Propagation
190
271
 
272
+ Visited set for D4 traversal: {D4}
273
+
191
274
  From D4 (API, I=3):
192
- - D4→D3 (strength=3): cascade. D3 I=max(1, 3-1)=2, C=2 → but wait,
193
- CR says "same schema" override to I=0. No cascade (semantic override).
194
- - D4→D9 (strength=3): cascade. D9 I=2, C=2
195
- - D4D10 (strength=3): cascade. D10 I=2, C=2
275
+ - D4→D3 (strength=3): cascade candidate. D3 I=max(1,3-1)=2, C=2.
276
+ CR states "same reservation schema" **semantic override requested** on
277
+ A=3 dimension. **Requires user confirmation** (per Semantic Override Rule §3).
278
+ Confirmed by user override to I=0. Record in state file `## Semantic
279
+ Overrides`: D3, cascade I=2/C=2, reason="same schema per CR", confirmed=yes.
280
+ No cascade on D3.
281
+ - D4→D9 (strength=3): cascade. D9 I=2, C=2. Add D9 to visited.
282
+ - D4→D10 (strength=3): cascade. D10 I=2, C=2. Add D10 to visited.
283
+
284
+ From D2 (Journey, I=2), visited={D2}:
285
+ - D2→D5 (strength=3): D5 already has direct I=2 (Phase 1) → use direct.
286
+ - D2→D9 (strength=1): below threshold (strength < 2), skip.
287
+
288
+ From D5 (UI, I=2), visited={D5}:
289
+ - No outgoing strength>=2 edges.
290
+
291
+ From D7 (Edge Cases, I=2), visited={D7}:
292
+ - D7→D10 (strength=1): below threshold, skip.
196
293
 
197
294
  ### Phase 3 — ICIAS Score
198
295
 
@@ -213,21 +310,28 @@ From D4 (API, I=3):
213
310
 
214
311
  | Phase | Verdict | Scope |
215
312
  |-------|---------|-------|
216
- | Discovery | PATCH | Update D2, D4, D5, D7, D9, D10 in checklist |
313
+ | Discovery | PATCH | Update D2, D4, D5, D7, D9, D10 in checklist (use discovery-phase.md §Step 2 prompt) |
217
314
  | UI Design | REDO | New batch selection flow |
218
315
  | PRD | REDO | Sections 4, 6, 7, 10, 13, 15 |
219
- | Backlog Cards | PATCH | New cards for bulk endpoint + UI; update deps |
316
+ | Backlog Cards | REDO | New cards for bulk endpoint + UI; update deps |
317
+ | ISA | RE-SCAN | Mandatory — REDO/PATCH verdicts present; delta scan for new touchpoints |
220
318
 
221
319
  ---
222
320
 
223
321
  ## Calibration Notes
224
322
 
225
- These thresholds are FMEA-adapted heuristics, not empirically validated
226
- for PRD CIA. After 10-15 real change requests, review:
323
+ These thresholds and A-value bands are FMEA-adapted heuristics, not
324
+ empirically validated for PRD CIA. All bands marked [CALIBRATION-NEEDED]
325
+ are candidates for revision. After 10–15 real change requests, review:
227
326
 
228
327
  1. Were any SKIPs that should have been PATCHes? → Lower threshold.
229
328
  2. Were any REDOs that could have been PATCHes? → Raise threshold.
230
329
  3. Did the coupling matrix miss any real cascades? → Add/strengthen edges.
231
330
  4. Did the coupling matrix produce false cascades? → Weaken/remove edges.
331
+ 5. Were any A=1 dimensions (D1, D7, D8) under-weighted (structural scope
332
+ exceptions raised)? → Consider raising their A value to 2.
232
333
 
233
- Track calibration data in state file `## Change Requests` section.
334
+ Calibration is the responsibility of the team running `/prd-add` regularly.
335
+ Record observed false negatives and false positives in a project-owned log
336
+ (e.g. a retrospective doc or the project wiki) — impact-analysis.md itself
337
+ is a read-only reference module and cannot write to state files.