baldart 3.40.0 → 4.0.0

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 (51) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/README.md +1 -1
  3. package/VERSION +1 -1
  4. package/framework/.claude/agents/REGISTRY.md +74 -24
  5. package/framework/.claude/agents/api-perf-cost-auditor.md +12 -5
  6. package/framework/.claude/agents/code-reviewer.md +30 -23
  7. package/framework/.claude/agents/codebase-architect.md +47 -43
  8. package/framework/.claude/agents/coder.md +29 -18
  9. package/framework/.claude/agents/doc-reviewer.md +55 -28
  10. package/framework/.claude/agents/plan-auditor.md +77 -12
  11. package/framework/.claude/agents/prd-card-writer.md +43 -13
  12. package/framework/.claude/agents/prd.md +22 -3
  13. package/framework/.claude/agents/qa-sentinel.md +75 -29
  14. package/framework/.claude/agents/security-reviewer.md +65 -10
  15. package/framework/.claude/agents/senior-researcher.md +8 -1
  16. package/framework/.claude/agents/ui-expert.md +22 -7
  17. package/framework/.claude/commands/check.md +31 -11
  18. package/framework/.claude/commands/codexreview.md +48 -29
  19. package/framework/.claude/commands/new.md +29 -328
  20. package/framework/.claude/commands/qa.md +62 -37
  21. package/framework/.claude/skills/context-primer/SKILL.md +29 -8
  22. package/framework/.claude/skills/doc-writing-for-rag/SKILL.md +36 -36
  23. package/framework/.claude/skills/frontend-design/SKILL.md +10 -8
  24. package/framework/.claude/skills/new/SKILL.md +413 -302
  25. package/framework/.claude/skills/prd/SKILL.md +67 -38
  26. package/framework/.claude/skills/prd/assets/card-template.yml +22 -26
  27. package/framework/.claude/skills/prd/assets/epic-template.yml +5 -5
  28. package/framework/.claude/skills/prd/assets/state-template.md +25 -3
  29. package/framework/.claude/skills/prd/references/api-perf-gate.md +143 -33
  30. package/framework/.claude/skills/prd/references/audit-phase.md +48 -34
  31. package/framework/.claude/skills/prd/references/backlog-phase.md +38 -11
  32. package/framework/.claude/skills/prd/references/discovery-phase.md +121 -44
  33. package/framework/.claude/skills/prd/references/impact-analysis.md +127 -23
  34. package/framework/.claude/skills/prd/references/prd-add-phase.md +18 -214
  35. package/framework/.claude/skills/prd/references/prd-writing-phase.md +52 -42
  36. package/framework/.claude/skills/prd/references/research-phase.md +105 -19
  37. package/framework/.claude/skills/prd/references/ui-design-phase.md +20 -8
  38. package/framework/.claude/skills/prd/references/validation-phase.md +97 -72
  39. package/framework/.claude/skills/prd-add/SKILL.md +70 -20
  40. package/framework/.claude/skills/simplify/SKILL.md +22 -12
  41. package/framework/.claude/skills/ui-design/SKILL.md +26 -7
  42. package/framework/.claude/skills/webapp-testing/SKILL.md +6 -4
  43. package/framework/.claude/skills/worktree-manager/SKILL.md +206 -143
  44. package/framework/agents/coding-standards.md +85 -0
  45. package/framework/agents/index.md +2 -1
  46. package/framework/agents/skills-mapping.md +85 -82
  47. package/framework/agents/testing.md +28 -0
  48. package/framework/templates/baldart.config.template.yml +29 -7
  49. package/package.json +1 -1
  50. package/src/commands/configure.js +43 -9
  51. package/framework/.claude/skills/prd-add/references/impact-analysis.md +0 -233
@@ -91,8 +91,8 @@ dimension from the discovery checklist. Pick exactly one branch:
91
91
  | UI impact = N/A | **Skip totale** | Mark task 2 `completed` ("Skipped — no UI"). `step_3_mode: skipped`. Proceed to PRD Writing Phase. |
92
92
  | `mockups.status: none` AND UI impact ≠ N/A | **3.0 Decision** | Run Step 3.0 above first. Branch A ⇒ fall through to **Full**; Branch B ⇒ STOP, then re-enter. |
93
93
  | `mockups.status: pending_external` | **STOP** | User is in handoff with Claude Design. Do not advance until paths arrive (see § "Re-entry from handoff"). |
94
- | `mockups.status: none` AND user picked Branch A in Step 3.0 | **Full** | Run the standard pipeline 3a → 3b → 3c → 3d as before. `step_3_mode: full`. |
95
- | `mockups.status` ∈ {`provided`, `partial`} AND UI impact ≠ N/A | **Hybrid** | Per-screen routing (see § Hybrid mode below). `step_3_mode: hybrid` (or `skipped` if every screen is covered AND no `mockup_analysis.design_system_alignment.violations`). |
94
+ | `mockups.status: none` AND `mockups.source: internal` | **Full** | Run the standard pipeline 3a → 3b → 3c → 3d → 3e as below. `step_3_mode: full`. |
95
+ | `mockups.status` ∈ {`provided`, `partial`} AND UI impact ≠ N/A | **Hybrid** | Per-screen routing (see § Hybrid mode below). `step_3_mode: hybrid` (or `mockup-only` if every screen is covered AND no `mockup_analysis.design_system_alignment.violations` — distinct from `skipped`, which means no UI at all). |
96
96
 
97
97
  Mark task 2 as `in_progress` for the Full and Hybrid branches.
98
98
 
@@ -110,9 +110,10 @@ The skill handles the full pipeline:
110
110
  | PRD Step | ui-design Skill Step | What happens |
111
111
  |----------|---------------------|--------------|
112
112
  | 3a — UI Context Analysis | Steps A + B | Component discovery, context screenshots, codebase analysis |
113
- | 3b — 3 Design Options | Steps C + D + E | Generate 3 HTML mockups, evaluate with separate agent, open in Safari |
113
+ | 3b — 3 Design Options | Steps C + D + E | Generate 3 HTML mockups, evaluate with separate `ui-expert` agent, open in Safari |
114
114
  | 3c — Design Iteration | Step F | User feedback loop with re-evaluation |
115
115
  | 3d — Save & Inventory | Step G | Save design.html, extract UI Element Inventory |
116
+ | 3e — Registry Coherence | **Step H** | Post-Intervention Coherence Check — BLOCKING when `features.has_design_system: true`; surfaces `DS_INDEX_DRIFT` / `DS_COMPONENT_STALE` / `DS_TOKENS_DRIFT` findings; must pass before task 2 is marked `completed` |
116
117
 
117
118
  ### What to pass to the skill
118
119
 
@@ -135,8 +136,9 @@ When invoking `ui-design`, ensure it has access to:
135
136
  Before invoking `ui-design`:
136
137
 
137
138
  1. Read `${paths.references_dir}/component-registry.md`.
138
- 2. From feature description, identify UI elements likely needed (tables, forms, modals, etc.).
139
- 3. Match against registry. Pass results to `ui-design`:
139
+ 2. When `features.has_design_system: true`, ALSO read `${paths.design_system}/INDEX.md` (component index + authority matrix) — required by HARD RULE 14 in `prd/SKILL.md` and by the BLOCKING cascade in `ui-design/SKILL.md`. Skipping this read is a protocol violation.
140
+ 3. From feature description, identify UI elements likely needed (tables, forms, modals, etc.).
141
+ 4. Match against both registries. Pass results to `ui-design`:
140
142
 
141
143
  ```
142
144
  ### Existing Components (from component-registry.md)
@@ -154,8 +156,12 @@ This prevents designing new components when 450+ reusable ones already exist.
154
156
  - **After Step 3b:** all 3 polished options open in Safari AND screenshots shown inline.
155
157
  **STOP.** Wait for user to choose.
156
158
  - **After Step 3c:** explicit user approval ("confermo", "va bene", "ok").
157
- - **After Step 3d:** `docs/prd/<slug>/design.html` exists AND `## UI Element Inventory`
159
+ - **After Step 3d:** `${paths.prd_dir}/<slug>/design.html` exists (inside `$WORKTREE_PATH`) AND `## UI Element Inventory`
158
160
  is populated in the state file with at least 3 elements.
161
+ - **After Step 3e (BLOCKING when `features.has_design_system: true`):** ui-design Step H
162
+ (Post-Intervention Coherence Check) must complete with no unresolved `DS_INDEX_DRIFT` /
163
+ `DS_COMPONENT_STALE` / `DS_TOKENS_DRIFT` findings (or every finding explicitly waived
164
+ by the user and logged as such). Do NOT mark task 2 `completed` until this gate clears.
159
165
 
160
166
  Mark task 2 as `completed`. Update state file status to `specs-confirmed`.
161
167
 
@@ -224,8 +230,8 @@ to the design system, approve, and inventory. Generate ONLY the screens not cove
224
230
  also ran. If at least one new screen was generated, the merged `design.html`
225
231
  includes both the new mockups and embeds/links to the existing ones.
226
232
  - For all-covered runs (`generated_in_step_3b: false` everywhere): set
227
- `design.html_path: n/a (mockup-only)` in the state file; the PRD will link
228
- directly to `${paths.prd_dir}/<slug>/mockups/`.
233
+ `design.html_path: n/a (mockup-only)` and `step_3_mode: mockup-only` in the state file;
234
+ the PRD will link directly to `${paths.prd_dir}/<slug>/mockups/`.
229
235
  - Update `## UI Element Inventory` in the state file with at least one row per
230
236
  covered screen + per generated screen.
231
237
 
@@ -239,6 +245,12 @@ to the design system, approve, and inventory. Generate ONLY the screens not cove
239
245
  swapped in the inventory) or explicitly waived by the user (logged as such).
240
246
  - **After 3d:** UI Element Inventory populated with at least one row per screen in
241
247
  `screens_in_scope[]`. `design.html_path` set OR `mockup-only` flag recorded.
248
+ - **After 3e — Registry Coherence (BLOCKING when `features.has_design_system: true`):**
249
+ ui-design Step H (Post-Intervention Coherence Check) must complete with no
250
+ unresolved `DS_INDEX_DRIFT` / `DS_COMPONENT_STALE` / `DS_TOKENS_DRIFT` findings
251
+ (or every finding explicitly waived by the user and logged as such). Applies to
252
+ all Hybrid sub-modes (`hybrid`, `mockup-only`). Do NOT mark task 2 `completed`
253
+ until this gate clears.
242
254
 
243
255
  Mark task 2 as `completed`. Update state file status to `specs-confirmed`.
244
256
 
@@ -2,11 +2,11 @@
2
2
 
3
3
  ## Step 6 — Quality Audit
4
4
 
5
- **Precondition:** Backlog cards approved.
5
+ **Precondition:** Backlog cards have been generated by `backlog-phase.md` and the user has not explicitly asked to abort. (There is no separate approval gate in the `/prd` flow; execution proceeds automatically from Step 5.)
6
6
 
7
7
  Mark task 5 as `in_progress`.
8
8
 
9
- 0. **Agent Specialization Audit (runs FIRST blocks if any failure)** — for each generated child card (epics are skipped):
9
+ 0. **Agent Specialization Audit (runs FIRST, blocks if any failure)** — for each generated child card (epics are skipped):
10
10
 
11
11
  a. **`owner_agent` enum check (BLOCKING)** — read the `owner_agent` field. It MUST equal one of:
12
12
  ```
@@ -22,7 +22,7 @@ Mark task 5 as `in_progress`.
22
22
  - For each marker hit, log a WARN line in the audit output:
23
23
  `"[UI-SCOPE-WARN] Card <ID> (ui-expert) mentions '<marker>' — review whether logic belongs in a sibling coder card. See backlog-phase.md § Rule B."`
24
24
  - The check is intentionally a soft gate: substrings like "API contract per il mock" or "consumes the auth state from `useAuth()`" are legitimate UI references. The WARN exists to prompt human review, not to block.
25
- - Exception (no WARN): the marker appears INSIDE a quoted string that explicitly says "consume", "mock", "contract reference", or "exposed by sibling card" — those are UI cards reading an upstream contract, which is expected.
25
+ - Exception (no WARN): the marker appears INSIDE a quoted string that explicitly says "consume", "mock", "contract reference", or "exposed by sibling card" — those are UI cards reading an upstream contract, which is expected. **[SEMANTIC — not purely deterministic]** Determining whether a marker substring is (a) inside a YAML quoted string and (b) that string contains one of the escape phrases requires contextual interpretation across multiple YAML quoting styles (single-quote, double-quote, block scalar). FP posture: when in doubt, log the WARN and let the human decide — do not suppress a WARN based on uncertain quoting analysis.
26
26
 
27
27
  c. **`review_profile` enum check (BLOCKING)** — read the `review_profile` field on each child card. It MUST equal one of:
28
28
  ```
@@ -30,12 +30,12 @@ Mark task 5 as `in_progress`.
30
30
  ```
31
31
  - **Missing or empty** = **BLOCKER** — the card-writer must compute it via `prd-card-writer.md § Rule C` (the SSOT mapping table). Message: `"Card <ID> has no review_profile — compute it from Rule C (skip|light|balanced|deep) before commit."`
32
32
  - **Out-of-enum value** = **BLOCKER**. Message: `"Card <ID> has review_profile: '<value>' — must be one of {skip, light, balanced, deep}."`
33
- - **Consistency WARN (soft)**: a `feature`/`enhancement` card with `review_profile: light` violates Rule C ("never light for feature/enhancement"). Log `"[REVIEW-PROFILE-WARN] Card <ID> is feature/enhancement but review_profile: light — Rule C floors these at balanced."` and bump to `balanced` unless the author left an explicit override note.
33
+ - **Consistency WARN (soft)**: a `feature`/`enhancement` card with `review_profile: light` may violate Rule C. Log `"[REVIEW-PROFILE-WARN] Card <ID> is feature/enhancement but review_profile: light — verify against Rule C in prd-card-writer.md."` **Do NOT auto-bump the field** — `review_profile` is computed by `prd-card-writer` (Rule C); see `prd-card-writer.md` for the criteria. This is a soft gate: log the warning and surface it for human review.
34
34
  - **Epics**: `review_profile` MUST be `skip` (trackers have no code work). Any other value = WARN, normalize to `skip`.
35
35
 
36
36
  **Gate**: every card has `owner_agent` AND `review_profile` in their enums. WARN entries from checks (b)/(c) are noted in the audit log; user may accept them after review.
37
37
 
38
- 1. **Field Name Audit (runs BEFORE audit agents)** — for each generated card:
38
+ 1. **Field Name Audit (runs after item 0 — only when item 0 passes for a given card; skipped for cards blocked in item 0)** — for each generated card:
39
39
 
40
40
  a. Verify every `data_fields` entry has `ts_verified: true` OR `status: new` with `schema_ref`.
41
41
  b. For cards with `estimated_complexity: HIGH` or `MEDIUM`:
@@ -54,19 +54,27 @@ Mark task 5 as `in_progress`.
54
54
  Then execute the audit protocol described within, using the card IDs from Step 5.
55
55
  The protocol auto-detects which agents to include (security and performance
56
56
  are signal-triggered, no manual profile selection needed).
57
+ **I/O contract:** `audit-phase.md` may edit card YAML files (e.g. its Step 6.9 normalisation pass). The list of all card paths modified by the audit (including those edited in Step 6.9) is the complete set that Step 7 item 6 must stage. The glob `FEAT-XXXX-*.yml (all cards from Step 5)` in item 6 covers this; note it explicitly so that context compaction does not cause a model to stage only the pre-audit originals.
57
58
  3. Wait for audit report and card edits.
58
59
 
59
- **Gate:** all HIGH/MEDIUM findings resolved, no open `[MANUAL]` items.
60
+ **Gate:** all HIGH/MEDIUM findings resolved, no open `[MANUAL]` items that require external human input beyond this orchestrator. (Items that the orchestrator can resolve autonomously are resolved before this gate; items that need a human decision were already routed to `AskUserQuestion` inside `audit-phase.md`. Items that survive to Step 7 item 1 are those that received a human answer but required card re-edits — these are explicitly handled there.)
60
61
 
61
62
  ## Step 7 — Resolution, Commit & Merge
62
63
 
63
64
  **Precondition:** Step 6 complete; the session is running inside a docs worktree
64
65
  created by Step 1 (HARD RULE 17). `$WORKTREE_PATH` is set in the state file.
65
66
 
67
+ **Variable guard (R6).** Before executing any item in Step 7, resolve and verify:
68
+ - `$WORKTREE_PATH` — read from the state file `## Worktree / path:`. HALT with `"ABORT: WORKTREE_PATH not set in state file — cannot commit or merge."` if absent or empty.
69
+ - `$MAIN` — the absolute path of the main (non-worktree) git repository root. **READ the persisted value from the state file `## Worktree / main_path:`** (written at SKILL.md Step 1, the R6 persist-then-read pattern `/new` uses). HALT with `"ABORT: MAIN absent from state — re-run from a session whose Step 1 persisted main_path."` if the field is absent or empty. Only when the field is genuinely missing (legacy state file) FALL BACK to deriving it once via `git -C "$WORKTREE_PATH" rev-parse --git-common-dir` (strips `/.git`). Every subsequent `git` command that runs outside the worktree MUST use `git -C "$MAIN" …`; never use a bare `git` command whose cwd is undefined. (This is the same variable name and resolution contract `/new` uses — the two skills must agree.)
70
+
66
71
  ### Resolve remaining items
67
72
 
68
- 1. If `[MANUAL]` items remain: resolve each one.
73
+ 1. If `[MANUAL]` items remain: resolve each one. (These are items that the orchestrator could not auto-resolve in Step 6 and whose human decision was provided via `AskUserQuestion` — they survived the Step 6 gate legally. See gate text above.)
69
74
  2. If resolution required card re-edits: re-run the audit protocol (audit-phase.md) on affected cards.
75
+ **Re-audit iteration cap:** maximum 2 re-audit iterations. If HIGH/MEDIUM findings or open `[MANUAL]` items persist after iteration 2, raise ONE `AskUserQuestion`:
76
+ - Question: `"After 2 re-audit rounds, <N> finding(s) remain unresolved. Options: [Accept remaining findings and proceed to commit] / [Abort this PRD session] / [Show me the findings and decide]"`
77
+ Act on the answer; do not continue looping silently.
70
78
 
71
79
  ### Update knowledge base (inside the worktree)
72
80
 
@@ -78,12 +86,12 @@ created by Step 1 (HARD RULE 17). `$WORKTREE_PATH` is set in the state file.
78
86
  Context with PRD completion. **Skip when the file does not exist.**
79
87
 
80
88
  **Note on cross-PRD collisions.** Both files (`ssot-registry.md` and
81
- `project-status.md`) live on `develop` and are touched by other PRD sessions
82
- in parallel. The rebase in step 8 below brings the worktree up to the latest
83
- `origin/develop` BEFORE the merge, so two parallel PRDs ending at the same
84
- time produce a clean append-only diff in most cases. If the rebase reports
85
- conflicts on these two files, `worktree-manager mw-docs` does **not** ask
86
- immediately: it strips the markers ("keep both sides", which on append-only
89
+ `project-status.md`) live on `git.trunk_branch` and are touched by other PRD
90
+ sessions in parallel. The rebase in step 8 below brings the worktree up to the
91
+ latest `origin/git.trunk_branch` BEFORE the merge, so two parallel PRDs ending
92
+ at the same time produce a clean append-only diff in most cases. If the rebase
93
+ reports conflicts on these two files, `worktree-manager mw-docs` does **not**
94
+ ask immediately: it strips the markers ("keep both sides", which on append-only
87
95
  registries is the correct additive result) and then runs a structural
88
96
  validation. The merge proceeds automatically when the validation passes. It
89
97
  escalates to the user **only** in the rare case where both PRDs modified the
@@ -92,10 +100,10 @@ created by Step 1 (HARD RULE 17). `$WORKTREE_PATH` is set in the state file.
92
100
 
93
101
  ### Commit (inside the worktree)
94
102
 
95
- 5. **Run the Metrics Log step from SKILL.md** ("Metrics Log — MANDATORY") FIRST
96
- — it appends the run summary to `$WORKTREE_PATH/docs/metrics/skill-runs.jsonl`,
97
- which must be part of the same commit. Non-blocking: if it fails, log
98
- "Metrics Log: SKIPPED" in the progress bar and continue.
103
+ 5. **Run the Metrics Log step from SKILL.md** ("Metrics Log — MONITORING SIGNAL, non-blocking") FIRST
104
+ — it appends the run summary to `$WORKTREE_PATH/${paths.metrics}/skill-runs.jsonl`
105
+ (`paths.metrics` default: `docs/metrics`), which must be part of the same commit.
106
+ Non-blocking: if it fails, log "Metrics Log: SKIPPED" in the progress bar and continue.
99
107
 
100
108
  6. Stage ONLY PRD session artefacts by explicit file name (NEVER `git add .`
101
109
  or `git add -A`):
@@ -104,53 +112,55 @@ created by Step 1 (HARD RULE 17). `$WORKTREE_PATH` is set in the state file.
104
112
  - `$WORKTREE_PATH/${paths.prd_dir}/<slug>/design.html` (if exists)
105
113
  - `$WORKTREE_PATH/${paths.prd_dir}/<slug>/mockups/**` (if any)
106
114
  - `$WORKTREE_PATH/${paths.backlog_dir}/FEAT-XXXX-*.yml` (all cards from Step 5)
107
- - `$WORKTREE_PATH/${paths.references_dir}/ssot-registry.md` (if updated)
108
- - `$WORKTREE_PATH/${paths.references_dir}/project-status.md` (if updated)
109
- - `$WORKTREE_PATH/docs/metrics/skill-runs.jsonl` (if the Metrics Log step in 5 wrote a line)
115
+ - `$WORKTREE_PATH/${paths.references_dir}/ssot-registry.md` (only if item 3 wrote the file)
116
+ - `$WORKTREE_PATH/${paths.references_dir}/project-status.md` (only if item 4 wrote the file)
117
+ - `$WORKTREE_PATH/${paths.metrics}/skill-runs.jsonl` (only if the Metrics Log step in 5 wrote a line)
118
+ - `$WORKTREE_PATH/${paths.metrics}/sessions/prd-<slug>.md` (only if `-stats` was active and the sessions file was written)
110
119
 
111
120
  Verify staged set with `git -C "$WORKTREE_PATH" diff --staged --name-only`.
112
121
 
113
- 7. Update state file: status -> `completed`, add `worktree.branch`, will fill
114
- commit hash after the commit lands.
122
+ 7. Update state file: status -> `committing`, add `worktree.branch`.
123
+ (Status is set to `committing` — not `completed` — so that if the commit in
124
+ item 8 fails, any subsequent `/prd` recovery session sees an incomplete run
125
+ rather than a false `completed` with no SHA.)
115
126
 
116
127
  8. Commit with format: `[PRD] <slug>: <brief description>`
117
128
  ```bash
118
129
  git -C "$WORKTREE_PATH" commit -m "[PRD] <slug>: <brief description>"
119
130
  ```
120
- Capture the SHA via `git -C "$WORKTREE_PATH" rev-parse HEAD` and write it
121
- back into the state file under `## Validation`.
122
-
123
- ### Merge into develop (worktree-manager mw-docs)
124
-
125
- 9. **Invoke `worktree-manager` programmatic mw-docs immediately** — no
126
- confirmation prompt, no "vuoi che mergi e pulisca il worktree?" question.
127
- The user opted into the full PRD pipeline when they ran `/prd`; chiedere
128
- conferma a fine sessione è friction inutile e rompe il "seamless" che è il
129
- punto della v3.22.0. Merge **and** worktree cleanup run automatically.
130
-
131
- **The ONLY thing that stops the automatic merge is a conflict `mw-docs`
132
- genuinely cannot auto-resolve** (a code/test conflict, or a structured
133
- registry whose strip+validate failed see step 10). Everything `mw-docs`
134
- can auto-resolve (additive docs/YAML/JSONL, append-only registries that pass
131
+ After the commit succeeds: capture the SHA via `git -C "$WORKTREE_PATH" rev-parse HEAD`,
132
+ then update the state file atomically: status -> `completed`, write the SHA
133
+ under `## Validation`. If the commit fails, leave status as `committing` and
134
+ HALT with the git error verbatim.
135
+
136
+ ### Merge into `git.trunk_branch` (worktree-manager mw-docs)
137
+
138
+ 9. **Invoke `worktree-manager` programmatic mw-docs** no confirmation prompt.
139
+ The user opted into the full PRD pipeline when they ran `/prd`; asking for
140
+ confirmation at the end is unnecessary friction and breaks the seamless
141
+ flow (v3.22.0 design intent). Merge and worktree cleanup run automatically.
142
+
143
+ **Why:** the ONLY thing that stops the automatic merge is a conflict
144
+ `mw-docs` genuinely cannot auto-resolve (a code/test conflict, or a
145
+ structured registry whose strip+validate failed). Everything `mw-docs` can
146
+ auto-resolve (additive docs/YAML/JSONL, append-only registries that pass
135
147
  validation) merges with zero questions. Do NOT pre-empt the merge with a
136
148
  confirmation gate "just in case there might be conflicts" — let `mw-docs`
137
149
  run and only surface what it actually reports as unresolvable.
138
150
 
139
151
  The merge is recoverable: if something goes wrong post-merge the user can
140
- `git revert` on develop just like any other commit. The hard-to-reverse
152
+ `git revert` on `git.trunk_branch` just like any other commit. The hard-to-reverse
141
153
  operations (`git push`, branch deletion) happen inside `mw-docs` which
142
154
  has its own failure handling (rebase abort, push rejection, gh CLI error)
143
155
  — none of which silently corrupts state.
144
156
 
145
- **Escape hatch.** If the user explicitly says "non mergiare" or "lascia il
146
- worktree" at any point during Step 7 (e.g. they want to review the PRD
147
- manually before it lands on develop), respect that and STOP after the
148
- commit — the worktree stays on disk, ready for a future manual `/mw` or
157
+ **Escape hatch.** If the user explicitly says "do not merge" or "leave the
158
+ worktree" at any point during Step 7, respect that and STOP after the commit
159
+ the worktree stays on disk, ready for a future manual `/mw` or
149
160
  `worktree-manager mw-docs`. This is a user-initiated override, not a
150
161
  default gate.
151
162
 
152
- 10. **Invoke `worktree-manager` programmatic mw-docs**:
153
-
163
+ **Invocation (one call only):**
154
164
  ```
155
165
  Skill: worktree-manager
156
166
  Mode: programmatic, mw-docs
@@ -158,8 +168,11 @@ created by Step 1 (HARD RULE 17). `$WORKTREE_PATH` is set in the state file.
158
168
  ```
159
169
 
160
170
  The skill executes:
161
- - Safety commit (idempotent — likely no-op after step 8).
162
- - `git fetch origin develop` + `git rebase origin/develop` inside the worktree.
171
+ - Safety commit (idempotent — likely no-op after step 8; if any file was
172
+ missed by item 6's explicit list, the safety commit picks it up, but the
173
+ tip commit message will be the safety message rather than `[PRD] …`. To
174
+ avoid this, ensure item 6 stages every file written in Steps 5-7).
175
+ - `git fetch origin git.trunk_branch` + `git rebase origin/git.trunk_branch` inside the worktree.
163
176
  - Conflict auto-resolution table (see `/mw` step 4b): additive docs/yaml and
164
177
  append-only `.jsonl` files auto-resolve; **structured registries**
165
178
  (`project-status.md`, `ssot-registry.md`, `field-registry.*`,
@@ -169,7 +182,7 @@ created by Step 1 (HARD RULE 17). `$WORKTREE_PATH` is set in the state file.
169
182
  conflicts always abort and escalate.
170
183
  - Merge via the configured `git.merge_strategy` (`pr` or `local-push`).
171
184
  - Cleanup: `git worktree remove` + `git branch -d` + registry entry removal.
172
- - Local develop ref sync (only if main repo HEAD is already `develop`).
185
+ - Local `git.trunk_branch` ref sync (only if main repo HEAD is already on `git.trunk_branch`).
173
186
 
174
187
  On success it returns `{ merged: true, mergeCommit, prNumber, strategy,
175
188
  worktreeRemoved: true }`.
@@ -180,48 +193,59 @@ created by Step 1 (HARD RULE 17). `$WORKTREE_PATH` is set in the state file.
180
193
  retry automatically — the next attempt should be user-driven.
181
194
 
182
195
  **Gate:** `mw-docs` returned `merged: true` AND `worktreeRemoved: true` AND
183
- the state file (now on `develop` via the merge) shows `completed`.
196
+ `strategy` is one of `pr` or `local-push` (well-formedness check ensures
197
+ the return object is complete before the final summary reads it) AND the
198
+ state file (now on `git.trunk_branch` via the merge) shows `completed`.
184
199
 
185
200
  Mark task 5 as `completed`.
186
201
 
187
202
  ### Step 7.5 — Workspace hygiene & finalization (BLOCKING — the run MUST conclude clean)
188
203
 
189
204
  **Why this exists (v3.39.0).** A PRD run used to end by handing the user a list of
190
- "azioni tue, non bloccanti" — an uncommitted file blocking the local `develop`
205
+ "non-blocking manual actions" — an uncommitted file blocking the local `git.trunk_branch`
191
206
  fast-forward, a remote branch left undeleted. That is a half-finished process.
192
207
  `/prd` now closes the loop exactly like `/new` Phase 6c: **no residue is ever
193
208
  surfaced as a passive manual TODO.** Every leftover is either auto-resolved or put
194
209
  behind ONE explicit `AskUserQuestion` gate.
195
210
 
211
+ **Requires `$MAIN`** (resolved in the Step 7 variable guard above).
212
+
196
213
  Scan the captured `mw-docs` stdout (the merge step above) for the structured
197
214
  markers it can emit, then act:
198
215
 
199
- 1. **`[SYNC-NEEDS-DECISION] …`** — the local `develop` could not fast-forward and
200
- the blocker is a **foreign** uncommitted file (one this run does not own), or a
201
- genuine divergence/rebase conflict. Do NOT auto-commit foreign work. Raise ONE
202
- `AskUserQuestion`:
203
- - Question: `"Il develop locale non si è sincronizzato: <dettaglio dal marker>. Come chiudo?"`
204
- - Options: `[Committa tu adesso (descrivi cosa)]` / `[Lo gestisco iochiudi senza sync locale]` / `[Mostrami il diff e decidiamo]`.
216
+ 1. **`[SYNC-NEEDS-DECISION] …`** — the local `git.trunk_branch` could not
217
+ fast-forward and the blocker is a **foreign** uncommitted file (one this run
218
+ does not own), or a genuine divergence/rebase conflict. Do NOT auto-commit
219
+ foreign work. Raise ONE `AskUserQuestion`:
220
+ - Question: `"Local <git.trunk_branch> did not sync: <detail from marker>. How should we close?"`
221
+ - Options: `[Commit the pending file now (describe it)]` / `[I will handle it close without local sync]` / `[Show me the diff and we decide]`.
205
222
  Act on the answer in this turn. Never leave it as a printed note.
206
223
 
207
- 2. **`[SYNC-DEFERRED] …`** (main repo HEAD ≠ `develop`) — fetch already updated
208
- `refs/remotes/origin/develop`. If the user's HEAD is now `develop`, run
209
- `git -C "$MAIN" pull --ff-only origin develop`. Otherwise raise ONE
210
- `AskUserQuestion` (`[ff-pull adesso]` / `[Lascio deferred, riconcilio io]`).
224
+ 2. **`[SYNC-DEFERRED] …`** (main repo HEAD ≠ `git.trunk_branch`) — fetch already
225
+ updated `refs/remotes/origin/git.trunk_branch`. If the user's HEAD is now
226
+ `git.trunk_branch`, run `git -C "$MAIN" pull --ff-only origin git.trunk_branch`.
227
+ Otherwise raise ONE `AskUserQuestion`:
228
+ `[Pull now (fast-forward only)]` / `[Leave deferred, I will reconcile]`.
211
229
 
212
230
  3. **No marker** — `mw-docs` already fast-forwarded (or auto-reconciled the
213
- framework telemetry log). Nothing to do; the tree is clean.
231
+ framework telemetry log). If `mw-docs` stdout contains the auto-reconcile
232
+ message (`✅ Reconciled stale metrics log…`), check whether local
233
+ `git.trunk_branch` is 1 commit ahead of `origin/git.trunk_branch`
234
+ (`git -C "$MAIN" status --porcelain -b`). If it is, run
235
+ `git -C "$MAIN" push origin git.trunk_branch`. On push failure, treat
236
+ as a `[SYNC-NEEDS-DECISION]` case.
237
+ If neither condition applies: nothing to do; the tree is clean.
214
238
 
215
239
  4. **Remote feature branch** — `mw-docs` deletes the merged remote branch as
216
240
  routine cleanup (see AGENTS.md § branch deletion: deleting an **already-merged**
217
241
  feature branch is NOT the gated "branch deletion" that needs owner approval).
218
- If for any reason the deletion was blocked, do NOT print "puoi cancellarlo a
219
- mano": run `git push origin --delete <branch>` now, and only if THAT is denied
220
- raise ONE `AskUserQuestion`.
242
+ If for any reason the deletion was blocked, do NOT print "you can delete it
243
+ manually": run `git -C "$MAIN" push origin --delete <branch>` now,
244
+ and only if THAT is denied raise ONE `AskUserQuestion`.
221
245
 
222
- **Gate:** `git -C "$MAIN" status --porcelain` for framework-owned paths is empty,
223
- no `[SYNC-NEEDS-DECISION]` marker is left unhandled, and the merged remote branch
224
- is gone (or its deletion is explicitly user-deferred).
246
+ **Gate:** `git -C "$MAIN" status --porcelain` for framework-owned paths is
247
+ empty, no `[SYNC-NEEDS-DECISION]` marker is left unhandled, and the merged remote
248
+ branch is gone (or its deletion is explicitly user-deferred).
225
249
 
226
250
  ### Final output
227
251
 
@@ -234,11 +258,12 @@ Print final summary:
234
258
  - PR number (if `strategy = pr`) or merge SHA (if `local-push`)
235
259
  - Confirmation that the worktree was cleaned up AND the remote branch was deleted
236
260
 
237
- **HARD RULE — no passive deferral.** The final summary MUST NOT contain a "azioni
238
- tue / note non bloccanti / puoi farlo a mano" section. If something genuinely needs
239
- the user, it was already raised as an `AskUserQuestion` in Step 7.5 and acted on —
240
- it does not reappear here as a TODO. A run that prints "il develop locale non si è
241
- fast-forwardato, gestisci tu il file e poi pulla" has FAILED Step 7.5 go back and
242
- resolve it before printing the summary.
261
+ **HARD RULE — no passive deferral.** The final summary MUST NOT contain a
262
+ "your manual actions / non-blocking notes / you can do it yourself" section.
263
+ If something genuinely needed the user, it was already raised as an
264
+ `AskUserQuestion` in Step 7.5 and acted on — it does not reappear here as a TODO.
265
+ A run that prints "local `git.trunk_branch` did not fast-forward, handle the file
266
+ yourself and then pull" has FAILED Step 7.5 — go back and resolve it before
267
+ printing the summary.
243
268
 
244
269
  Display completed Progress Bar.
@@ -3,7 +3,7 @@ name: prd-add
3
3
  description: "Change Request skill for active PRD sessions. Use when the user says /prd-add, 'aggiungi requisito', 'serve anche', 'manca un endpoint', or describes a new requirement that impacts an existing PRD. Also auto-triggered by /prd during discovery when the user's answer reveals a new sub-feature not covered by the original scope. Runs ICIAS impact analysis (semantic scan + structural propagation + scoring) to determine which PRD phases need SKIP/PATCH/REDO, then executes only affected phases."
4
4
  ---
5
5
 
6
- # /prd-add — Change Request per PRD attivi
6
+ # /prd-add — Change Request for Active PRD Sessions
7
7
 
8
8
  Add a new requirement to an existing PRD session. Uses the ICIAS protocol
9
9
  (Impact-Confidence-Artifact Stakes) to determine which phases and artifacts
@@ -31,6 +31,13 @@ description, the `/prd` skill invokes `/prd-add` automatically.
31
31
  Detection signal: the user's answer introduces NEW entities (endpoints, collections,
32
32
  pages, roles, flows) that were not part of the original feature scope.
33
33
 
34
+ **IMPORTANT — auto-trigger target:** `/prd`'s dispatch table row `2→CR` points to
35
+ `references/prd-add-phase.md` (a legacy stub). When executing a Change Request,
36
+ **this SKILL.md is the canonical spec** — use it, not the stub. The stub lacks the
37
+ worktree registry scan (Step 0), the `WORKING_DIRECTORY` discipline, and the
38
+ side-effect rules; executing via the stub will operate on the main repo and break
39
+ session isolation. Always load and follow this file (`framework/.claude/skills/prd-add/SKILL.md`).
40
+
34
41
  ---
35
42
 
36
43
  ## EXECUTION MODEL
@@ -52,7 +59,7 @@ Sequential, single-turn analysis + selective multi-turn re-execution.
52
59
 
53
60
  1. NEVER start from scratch. Always build on the existing PRD session.
54
61
  2. Read the state file and PRD before any analysis.
55
- 3. Follow ICIAS protocol exactly — read [impact-analysis.md](references/impact-analysis.md).
62
+ 3. Follow ICIAS protocol exactly — read [impact-analysis.md](../prd/references/impact-analysis.md) (canonical SSOT; see B4).
56
63
  4. Present verdict BEFORE executing changes. Wait for user confirmation.
57
64
  5. When re-running phases, follow the SAME reference files as `/prd` (discovery-phase.md, etc.).
58
65
  6. Update the state file with a `## Change Requests` section tracking all CR history.
@@ -79,21 +86,40 @@ legacy sessions.
79
86
  together with its `WORKING_DIRECTORY` = `<entry.path>` and `branch` =
80
87
  `<entry.branch>`.
81
88
 
89
+ **Registry absent or entry missing with worktree dir present:** If
90
+ `.worktrees/registry.json` does not exist, OR it is parseable but contains
91
+ zero `kind: "docs"` entries, AND a directory matching
92
+ `.worktrees/docs-*` exists on disk: surface a diagnostic —
93
+ `REGISTRY_MISMATCH: .worktrees/registry.json is absent or has no docs entries
94
+ but a docs worktree directory exists on disk. Running a CR from the main repo
95
+ would break session isolation.` — then HALT and ask the user to manually
96
+ provide the docs worktree path before continuing. Do NOT silently fall through
97
+ to the legacy scan in this case.
98
+
82
99
  2. **Also list `${paths.prd_dir}/sessions/` on the main repo** (legacy
83
100
  pre-v3.22.0 sessions). Collect any state files there as candidates with
84
101
  `WORKING_DIRECTORY` = main repo root.
102
+ This fallback only applies when Step 1 produced zero registry entries AND no
103
+ on-disk docs-worktree directory was detected.
85
104
 
86
105
  3. Merge the two lists. Behavior:
87
- - **Exactly ONE active session**: use it. Save its `WORKING_DIRECTORY` and
88
- `branch` for every subsequent step.
106
+ - **Exactly ONE active session**: use it. **Write `WORKING_DIRECTORY` and
107
+ `BRANCH` to the state file tracker under `## CR Session`** before proceeding
108
+ — every later consumer reads them from there. These variables must survive
109
+ context compaction; every step that uses them MUST begin with a
110
+ presence-and-non-empty guard: if either is absent or empty in the tracker,
111
+ HALT with `MISSING_VAR: WORKING_DIRECTORY / BRANCH not found in state file`.
89
112
  - **Multiple active sessions**: ask the user which one, surfacing
90
113
  `WORKING_DIRECTORY` (worktree path or "main repo") in the choice list so
91
- they know where the CR will be written.
114
+ they know where the CR will be written. Write chosen values to tracker.
92
115
  - **Zero sessions**: inform user, suggest `/prd` instead.
93
116
 
94
117
  4. **`cd "$WORKING_DIRECTORY"`** before any read or write — every subsequent
95
118
  step in this skill (intake → impact analysis → selective execution → delta
96
- commit) MUST happen inside the selected session's directory.
119
+ commit) MUST use absolute paths rooted at `$WORKING_DIRECTORY`. Note: Claude
120
+ Code's Read/Write/Edit tools require absolute paths and do not honor a working
121
+ directory state set by a prior shell `cd`; always concatenate
122
+ `$WORKING_DIRECTORY/<relative-path>` explicitly for every tool call.
97
123
 
98
124
  5. Read the state file AND the PRD document (if exists), both resolved under
99
125
  `$WORKING_DIRECTORY`.
@@ -141,7 +167,7 @@ Record in state file under `## Change Requests`:
141
167
 
142
168
  ## Step 2 — Impact Analysis (ICIAS Protocol)
143
169
 
144
- **Read [references/impact-analysis.md](references/impact-analysis.md) for the full protocol.**
170
+ **Read [../prd/references/impact-analysis.md](../prd/references/impact-analysis.md) for the full protocol.**
145
171
 
146
172
  Quick summary — 3 phases executed in sequence:
147
173
 
@@ -177,18 +203,24 @@ Present the impact matrix to the user:
177
203
  | D3 | Data model | - | D4->D3 | 1 | 2 | 3 | 6 | PATCH |
178
204
  | ... | ... | ... | ... | ... | ... | ... | ... | ... |
179
205
 
180
- **Fasi da rieseguire:**
181
- - Discovery: PATCH (D2, D4 da aggiornare)
182
- - UI Design: REDO (nuovo flow)
183
- - PRD: PATCH (sezioni 4, 6, 9)
184
- - Backlog Cards: PATCH (nuove cards + update esistenti)
206
+ **Phases to re-execute:**
207
+ - Discovery: PATCH (D2, D4 to update)
208
+ - UI Design: REDO (new flow)
209
+ - PRD: PATCH (sections 4, 6, 9)
210
+ - Backlog Cards: PATCH (new cards + update existing)
185
211
 
186
- Vuoi procedere con questa analisi?
212
+ Proceed with this analysis?
187
213
  ```
188
214
 
189
215
  **STOP.** Wait for user confirmation.
190
216
 
191
- If user disagrees with any verdict, adjust manually and re-present.
217
+ If user disagrees with any verdict: re-score the contested dimension at their
218
+ direction (record the override and the reason in the state file under CR-N),
219
+ then re-present the full matrix. **Maximum 2 re-presentations per CR**; after
220
+ the second re-presentation the agent must accept the user's overrides as final
221
+ and proceed. Any SKIP override from PATCH/REDO that removes a mandatory gate
222
+ (D3 schema section, API gate) is recorded as `USER_OVERRIDE` in the state file
223
+ for audit but does not block execution.
192
224
 
193
225
  ---
194
226
 
@@ -207,7 +239,11 @@ Execute ONLY phases with PATCH or REDO verdict, in original phase order.
207
239
 
208
240
  - **PATCH**: Describe changes needed to existing design.html. Ask user
209
241
  if they want a full design refresh or text-only update to PRD.
210
- - **REDO**: Re-run full UI Design phase (Steps 3a-3d from /prd).
242
+ - **REDO**: Re-run the full UI Design phase following
243
+ [../prd/references/ui-design-phase.md](../prd/references/ui-design-phase.md)
244
+ (Steps 3.0 Precondition → 3.1 Full / Hybrid pipeline as applicable). Pass
245
+ `WORKING_DIRECTORY=$WORKING_DIRECTORY` to `ui-design` per the side-effect
246
+ rules in Step 0 of this skill.
211
247
 
212
248
  ### For PRD (PATCH/REDO)
213
249
 
@@ -225,6 +261,15 @@ Execute ONLY phases with PATCH or REDO verdict, in original phase order.
225
261
  - **REDO**: Regenerate affected cards via `prd-card-writer` agent.
226
262
  Preserve cards that are unaffected.
227
263
 
264
+ **BLOCKING pre-check before invoking `prd-card-writer`:** If the PRD
265
+ dimension also has a PATCH or REDO verdict (step 4c), confirm that 4c is
266
+ complete AND that the PRD document contains an up-to-date
267
+ `## Schema Verification` section (field registry with `ts_verified: true`)
268
+ before starting card generation. `prd-card-writer`'s Field Grounding Rule
269
+ mandates this section exists and is current — invoking the agent before 4c
270
+ finishes will cause it to halt after writing partial cards. Do not proceed
271
+ if the section is absent or stale.
272
+
228
273
  ### For ISA (always re-scan if any PATCH/REDO exists)
229
274
 
230
275
  Run a delta ISA scan focused on the new requirement. Merge new
@@ -238,7 +283,12 @@ touchpoints into existing ISA table. Assign new ISA-N IDs.
238
283
  - CR status: `applied`
239
284
  - Update comprehension checklist with changes
240
285
  - Update `## Change Requests` with summary of what was done
241
- 2. Re-run API Performance Gate (Step 4.5) if API/data model changed.
286
+ 2. **Re-run API Performance Gate** if the CR produces a PATCH or REDO verdict on
287
+ D3 (Data model) or D4 (API contracts). Read
288
+ [../prd/references/api-perf-gate.md](../prd/references/api-perf-gate.md) for
289
+ the full gate protocol. Invoke `api-perf-cost-auditor` following the same
290
+ pattern as `/prd` Step 4.5. Record the gate result in the state file
291
+ `## Change Requests › CR-N` section before the delta commit.
242
292
  3. Stage ONLY modified files (explicit names).
243
293
  4. Commit: `[PRD-ADD] <slug>: <CR description>`
244
294
 
@@ -250,16 +300,16 @@ touchpoints into existing ISA table. Assign new ISA-N IDs.
250
300
  ---
251
301
  🔄 **Change Request: <slug> — CR-N**
252
302
 
253
- | # | Fase | Verdict | Stato |
254
- |---|------|---------|-------|
303
+ | # | Phase | Verdict | Status |
304
+ |---|-------|---------|--------|
255
305
  | 1 | Intake | - | ⬜/✅ |
256
306
  | 2 | Impact Analysis | - | ⬜/🔄/✅ |
257
- | 3 | Verdict & conferma | - | ⬜/🔄/✅ |
307
+ | 3 | Verdict & confirm | - | ⬜/🔄/✅ |
258
308
  | 4a | Discovery (delta) | SKIP/PATCH/REDO | ⬜/🔄/✅/⏭️ |
259
309
  | 4b | UI Design (delta) | SKIP/PATCH/REDO | ⬜/🔄/✅/⏭️ |
260
310
  | 4c | PRD (delta) | SKIP/PATCH/REDO | ⬜/🔄/✅/⏭️ |
261
311
  | 4d | Backlog Cards (delta) | SKIP/PATCH/REDO | ⬜/🔄/✅/⏭️ |
262
312
  | 5 | Delta Commit | - | ⬜/✅ |
263
313
 
264
- Prossimo passo: <what happens next>
314
+ Next: <what happens next>
265
315
  ```