baldart 4.92.1 → 4.94.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 (48) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/VERSION +1 -1
  3. package/framework/.claude/agents/REGISTRY.md +2 -2
  4. package/framework/.claude/agents/api-perf-cost-auditor.md +1 -1
  5. package/framework/.claude/agents/codebase-architect.md +57 -109
  6. package/framework/.claude/agents/hybrid-ml-architect.md +1 -1
  7. package/framework/.claude/agents/legal-counsel-gdpr.md +1 -1
  8. package/framework/.claude/agents/plan-auditor.md +9 -8
  9. package/framework/.claude/agents/prd-card-writer.md +8 -0
  10. package/framework/.claude/agents/security-reviewer.md +1 -1
  11. package/framework/.claude/commands/codexreview.md +1 -1
  12. package/framework/.claude/skills/bug/CHANGELOG.md +4 -0
  13. package/framework/.claude/skills/bug/SKILL.md +6 -4
  14. package/framework/.claude/skills/context-primer/CHANGELOG.md +10 -0
  15. package/framework/.claude/skills/context-primer/SKILL.md +26 -60
  16. package/framework/.claude/skills/ds-handoff/CHANGELOG.md +4 -0
  17. package/framework/.claude/skills/ds-handoff/SKILL.md +3 -2
  18. package/framework/.claude/skills/e2e-review/CHANGELOG.md +4 -0
  19. package/framework/.claude/skills/e2e-review/SKILL.md +6 -4
  20. package/framework/.claude/skills/new/CHANGELOG.md +4 -0
  21. package/framework/.claude/skills/new/SKILL.md +1 -1
  22. package/framework/.claude/skills/new/references/final-review.md +2 -1
  23. package/framework/.claude/skills/new/references/implement.md +1 -1
  24. package/framework/.claude/skills/new2/CHANGELOG.md +4 -0
  25. package/framework/.claude/skills/new2/SKILL.md +1 -1
  26. package/framework/.claude/skills/prd/CHANGELOG.md +17 -0
  27. package/framework/.claude/skills/prd/SKILL.md +28 -7
  28. package/framework/.claude/skills/prd/references/audit-phase.md +33 -130
  29. package/framework/.claude/skills/prd/references/audit-teammate-prompt.md +144 -0
  30. package/framework/.claude/skills/prd/references/discovery-phase.md +35 -14
  31. package/framework/.claude/skills/prd/references/validation-phase.md +53 -57
  32. package/framework/.claude/skills/prd-add/CHANGELOG.md +4 -0
  33. package/framework/.claude/skills/prd-add/SKILL.md +3 -2
  34. package/framework/.claude/skills/ui-design/CHANGELOG.md +4 -0
  35. package/framework/.claude/skills/ui-design/SKILL.md +2 -2
  36. package/framework/.claude/workflows/new-card-review.js +1 -1
  37. package/framework/.claude/workflows/new-final-review.js +1 -1
  38. package/framework/.claude/workflows/new2.js +6 -2
  39. package/framework/agents/analysis-profiles.md +286 -0
  40. package/framework/agents/index.md +2 -1
  41. package/framework/agents/skills-mapping.md +4 -0
  42. package/framework/scripts/stamp-holistic-audit.js +143 -0
  43. package/framework/scripts/validate-card-baseline.js +51 -5
  44. package/framework/templates/primitives/AGENTS.CHANGELOG.md +10 -0
  45. package/framework/templates/primitives/AGENTS.md +8 -3
  46. package/framework/templates/primitives/CLAUDE.CHANGELOG.md +6 -0
  47. package/framework/templates/primitives/CLAUDE.md +5 -2
  48. package/package.json +1 -1
@@ -589,17 +589,34 @@ user's own folder outside the worktree — never modify or clean it; only read.
589
589
 
590
590
  Then continue to Step 1.6.5 with the selected subset.
591
591
 
592
- ### 1.6.5 — Mockup analysis (MANDATORY before Discovery)
593
-
594
- Analyze ALL provided mockups (visual analysis for chat images, Read for copied files
595
- that are textual like HTML/SVG). Populate `## UI Design` in the state file using the
596
- **Mockup analysis schema** (see appendix at the end of this file).
597
-
598
- When `features.has_design_system: true`, BLOCKING reads of `${paths.design_system}/INDEX.md`
599
- and `${paths.design_system}/tokens-reference.md` apply BEFORE running the alignment
600
- check same protocol as Step 3 (UI Design). Flag every hardcoded value (hex / shadow /
601
- radius / spacing) that conflicts with a known token as a violation in
602
- `mockup_analysis.design_system_alignment.violations[]`.
592
+ ### 1.6.5 — Mockup analysis (MANDATORY before Discovery — DELEGATED, mockup bytes never in the orchestrator)
593
+
594
+ **HARD RULE the orchestrator MUST NOT Read the mockup files** (images OR HTML/SVG
595
+ bundles). A decoded mockup read in the main context rides EVERY subsequent
596
+ full-window API call for the rest of the run (measured on a real session: ~208KB
597
+ dragged through the cache for ~300 events). The only exception is a mockup pasted
598
+ directly in chat as an image — that is already in context; analyze it inline.
599
+
600
+ For all on-disk mockups, **spawn ONE `ui-expert` subagent in read-only analysis
601
+ mode** with this brief:
602
+ - the mockup file paths (`mockups.canonical_paths[]`) — the agent Reads them in ITS
603
+ context (it is multimodal: images render, HTML is read as text);
604
+ - the schema to fill: instruct it to open THIS file
605
+ (`references/discovery-phase.md`) and read ONLY the section
606
+ `## Appendix — Mockup analysis schema` (Grep the heading, Read from that offset);
607
+ - when `features.has_design_system: true`: the paths of
608
+ `${paths.design_system}/INDEX.md` and `${paths.design_system}/tokens-reference.md`
609
+ (BLOCKING reads for the agent — same protocol as Step 3), with the instruction to
610
+ flag every hardcoded value (hex / shadow / radius / spacing) that conflicts with a
611
+ known token as a violation in `mockup_analysis.design_system_alignment.violations[]`;
612
+ - **ROLE BOUNDARY**: analysis only — no code, no file writes, no Task spawns. Its
613
+ final message is the filled `mockup_analysis` YAML and NOTHING else (COMPACT
614
+ return contract).
615
+
616
+ The orchestrator persists the returned YAML into `## UI Design` in the state file
617
+ verbatim. If the agent's YAML is malformed, re-spawn once with the error; on a
618
+ second failure, fall back to inline analysis (and say so — the fallback is visible,
619
+ never silent).
603
620
 
604
621
  ### 1.6.6 — Output and handoff to Discovery
605
622
 
@@ -681,7 +698,9 @@ section of the state file. Mark dimension as covered.
681
698
  If more specific detail is needed beyond what context-primer provided,
682
699
  invoke `codebase-architect` agent (foreground) with a targeted question:
683
700
  ```
684
- OUTPUT=terse — machine consumer (discovery dimension resolution), not human Q&A.
701
+ PROFILE=discovery OUTPUT=terse — machine consumer (discovery dimension resolution),
702
+ not human Q&A. Resolve your analysis profile per `agents/analysis-profiles.md`
703
+ (Grep "### PROFILE: discovery", read only that section).
685
704
  For feature `<slug>`: regarding the dimension `<dimension>`, does the codebase
686
705
  already answer this? Specifically check: existing collections, routes, components,
687
706
  permissions, and patterns. Report what you find with file references — structured
@@ -763,8 +782,10 @@ Instead, run the ISA scan and present findings for validation.
763
782
  1. Invoke `codebase-architect` agent with this specific prompt:
764
783
 
765
784
  ```
766
- OUTPUT=terse — machine consumer (ISA table builder), not human Q&A: per-touchpoint
767
- rows only, no narrative overview.
785
+ PROFILE=impact OUTPUT=terse — machine consumer (ISA table builder), not human Q&A:
786
+ per-touchpoint rows only, no narrative overview. Resolve your analysis profile per
787
+ `agents/analysis-profiles.md` (Grep "### PROFILE: impact", read only that section —
788
+ the structural tier is your primary source when its flag is on).
768
789
  For feature `<slug>`: perform an Integration Surface Analysis (ISA).
769
790
  Find ALL existing code that should reference, link to, or interact with this
770
791
  new feature. Scan these categories systematically:
@@ -6,15 +6,26 @@
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)** — two layers:
10
10
 
11
- a. **`owner_agent` enum check (BLOCKING)** read the `owner_agent` field. It MUST equal one of:
12
- ```
13
- coder | ui-expert | plan | visual-designer | motion-expert
14
- ```
15
- Empty string, missing field, `claude`, or any other value = **BLOCKER**.
16
- Message to the user: `"Card <ID> has owner_agent: '<value>' — must be one of {coder, ui-expert, plan, visual-designer, motion-expert}. Fix the card YAML before commit."`
17
- Halt the audit. No subsequent checks run on a card that fails this gate.
11
+ **0-i. Deterministic gate EXECUTED, never recited (BLOCKING).** Run the framework validator in `/prd` mode on EVERY generated card (epics included — it is profile-aware):
12
+
13
+ ```bash
14
+ node .framework/framework/scripts/validate-card-baseline.js --prd \
15
+ "$WORKTREE_PATH/${paths.backlog_dir}"/FEAT-XXXX-*.yml
16
+ ```
17
+ (resolve the script path for your install; only if it is genuinely unreachable, fall back to reciting the checks below and say so explicitly in the audit log).
18
+
19
+ Exit 1 = **BLOCKER**: print the per-field errors verbatim, fix the card YAML, re-run until exit 0. No subsequent checks run on a card while it fails this gate. The script covers deterministically:
20
+ - **`owner_agent` enum** — must be one of `{coder, ui-expert, plan, visual-designer, motion-expert}` (empty/missing/`claude` = blocker);
21
+ - **`review_profile` enum + epic `skip`** — `skip|light|balanced|deep`; missing/empty = blocker (the card-writer must compute it via `prd-card-writer.md § Rule C`); epics MUST be `skip`;
22
+ - **conditional `requirements` presence (PO1)** — a child/standalone card with non-empty `acceptance_criteria` + `scope` MUST carry `requirements` (a fresh `/prd` card without them shifts a measured ~3–4M-token back-fill into `/new`'s orchestrator — see `card-schema.md` § "Authoring completeness invariants");
23
+ - **unresolved `[NEEDS CLARIFICATION: …]` markers** — a card carrying a planning ambiguity is NOT implementable. Resolve each marker (with the user via `AskUserQuestion` when it needs a human answer, or from Discovery/PRD material when it does not), edit the card, re-run;
24
+ - the universal field-state matrix + remaining enums (`card-schema.md`).
25
+
26
+ **Why executed and not recited:** the prose version of this gate has already failed silently on a real run (a whole card family shipped with zero audit trail). A recited check degrades under context pressure; an executed one cannot.
27
+
28
+ **0-ii. Semantic checks (the model reads the cards — not scriptable):**
18
29
 
19
30
  b. **UI-only scope heuristic (WARN — soft gate, not blocking)** — for each card with `owner_agent: ui-expert`:
20
31
  - Concatenate `scope.summary`, `requirements[]`, and `acceptance_criteria[]` into one lowercase string.
@@ -24,23 +35,7 @@ Mark task 5 as `in_progress`.
24
35
  - 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
36
  - 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
37
 
27
- c. **`review_profile` enum check (BLOCKING)**read the `review_profile` field on each child card. It MUST equal one of:
28
- ```
29
- skip | light | balanced | deep
30
- ```
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
- - **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` 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
- - **Epics**: `review_profile` MUST be `skip` (trackers have no code work). Any other value = WARN, normalize to `skip`.
35
-
36
- d. **`requirements` presence (BLOCKING — PO1)** — for each CHILD/STANDALONE card whose
37
- `acceptance_criteria` AND `scope` are both non-empty, `requirements` MUST be present and
38
- non-empty. A freshly authored `/prd` card with derivable material but no `requirements` is an
39
- authoring miss that shifts a measured ~3–4M-token back-fill into `/new`'s orchestrator context
40
- (see `card-schema.md` § "Authoring completeness invariants"). `/prd` fixes it now for free.
41
- Message: `"Card <ID> has acceptance_criteria + scope but no requirements — emit requirements
42
- (faithful restatement of AC + scope) before commit."` (The `/new` conditional back-fill remains
43
- only as the safety net for legacy / externally-authored cards.)
38
+ c. **Rule C consistency (WARN — soft gate)**: 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. (The enum/presence/epic-`skip` checks are handled deterministically by 0-i.)
44
39
 
45
40
  e. **files_likely_touched coverage (BLOCKING — P1/P2 closure)** — two sub-checks:
46
41
  - **⊆ coverage (P2):** every file path named in a card's `requirements` /
@@ -58,9 +53,10 @@ Mark task 5 as `in_progress`.
58
53
  no card — assign it to a card's files_likely_touched."`
59
54
  Both are SEMANTIC (path extraction from prose / ISA needs interpretation) — bias toward flagging.
60
55
 
61
- **Gate**: every card has `owner_agent` AND `review_profile` in their enums, `requirements` present when
62
- derivable (d), and full files_likely_touched coverage (e). WARN entries from checks (b)/(c) are noted in
63
- the audit log; user may accept them after review. The (d)/(e) BLOCKERs must be fixed before commit.
56
+ **Gate**: the 0-i validator exits 0 on every card (enums, conditional `requirements`, zero
57
+ `[NEEDS CLARIFICATION]` markers) AND full files_likely_touched coverage (e). WARN entries from
58
+ checks (b)/(c) are noted in the audit log; user may accept them after review. The 0-i and (e)
59
+ BLOCKERs must be fixed before commit.
64
60
 
65
61
  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:
66
62
 
@@ -132,37 +128,37 @@ created by Step 1 (HARD RULE 17). `$WORKTREE_PATH` is set in the state file.
132
128
  (`paths.metrics` default: `docs/metrics`), which must be part of the same commit.
133
129
  Non-blocking: if it fails, log "Metrics Log: SKIPPED" in the progress bar and continue.
134
130
 
135
- 5b. **Holistic-audit provenance backstop (BLOCKING on the STAMP, never on the PRD).**
136
- The per-card stamp write in `audit-phase.md` Step 6.9.4 is model-driven and is the
137
- single most-omitted step under context pressure. When it is skipped, every card
138
- ships WITHOUT `metadata.holistic_audit` — and `/new` (`implement.md` Phase 1 step 4,
139
- P1) + `new2` then spawn the plan-auditor on **every** card even when the batch is
140
- implemented immediately after this audit (nothing changed). Step 6 is complete (its
141
- gate passed), so the audit genuinely ran: this is the authoritative, deterministic
142
- point to guarantee the stamp lands. **Do NOT re-derive the semantics** reuse the
143
- run-level values and the YAML block DEFINED in `audit-phase.md` § "Holistic-audit
144
- provenance stamp".
145
- - Recompute the three run-level values ONCE (same snippet as audit-phase.md), inside
146
- `$WORKTREE_PATH`:
147
- ```bash
148
- HOLISTIC_AUDITED_AT="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
149
- HOLISTIC_AUDITED_COMMIT="$(git -C "$WORKTREE_PATH" merge-base HEAD "${git.trunk_branch}" 2>/dev/null || git -C "$WORKTREE_PATH" rev-parse "${git.trunk_branch}" 2>/dev/null || echo "")"
150
- # audited_set = the sorted Step-5 child card IDs (the joint cross-card scope).
151
- ```
152
- - For EACH **non-EPIC** card from Step 5: if it lacks `metadata.holistic_audit` with a
153
- non-empty `audited_commit`, WRITE the block (additive never overwrite other
154
- `metadata` keys). A card that already carries it (from Step 6.9.4) is untouched —
155
- **idempotent**. EPIC-parent cards are excluded (they carry `planning_session` only
156
- `card-schema.md`).
157
- - Re-read one backfilled card to verify the block landed. Log
158
- `holistic_audit provenance: N/N cards stamped (M backfilled here)`.
131
+ 5b. **Holistic-audit provenance backstop (BLOCKING on the STAMP, never on the PRD)
132
+ EXECUTED via script.** The per-card stamp write in `audit-phase.md` Step 6.9.4 is
133
+ model-driven and is the single most-omitted step under context pressure; when it is
134
+ skipped, every card ships WITHOUT `metadata.holistic_audit` — and `/new`
135
+ (`implement.md` Phase 1 step 4, P1) + `new2` then spawn the plan-auditor on **every**
136
+ card even when the batch is implemented immediately after this audit. Step 6 is
137
+ complete (its gate passed), so the audit genuinely ran: guarantee the stamp lands by
138
+ RUNNING the deterministic stamper (semantics defined in `audit-phase.md`
139
+ § "Holistic-audit provenance stamp" the script only mechanizes the write):
140
+ ```bash
141
+ HOLISTIC_AUDITED_AT="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
142
+ HOLISTIC_AUDITED_COMMIT="$(git -C "$WORKTREE_PATH" merge-base HEAD "${git.trunk_branch}" 2>/dev/null || git -C "$WORKTREE_PATH" rev-parse "${git.trunk_branch}" 2>/dev/null || echo "")"
143
+ # --set = the sorted Step-5 child card IDs (the joint cross-card scope), comma-separated.
144
+ node .framework/framework/scripts/stamp-holistic-audit.js \
145
+ --at "$HOLISTIC_AUDITED_AT" --commit "$HOLISTIC_AUDITED_COMMIT" \
146
+ --set "<ID1,ID2,...>" "$WORKTREE_PATH/${paths.backlog_dir}"/FEAT-XXXX-*.yml
147
+ ```
148
+ The script is **idempotent** (a card already stamped by Step 6.9.4 is untouched),
149
+ **additive** (never overwrites other `metadata` keys), skips EPIC cards (they carry
150
+ `planning_session` only `card-schema.md`), and verifies its own writes. Log its
151
+ summary line (`holistic_audit provenance: N/N non-epic cards stamped (M written
152
+ here, …)`) in the audit log. Only if the script is genuinely unreachable in this
153
+ install, fall back to the manual per-card write per `audit-phase.md` § "Holistic-audit
154
+ provenance stamp" and say so explicitly.
159
155
  **Fail-safe (unchanged contract):** the stamp is an OPTIMIZATION hint, never a
160
156
  *correctness* gate — if `HOLISTIC_AUDITED_COMMIT` resolves to `""` (git genuinely
161
- unavailable), write it explicitly as `""` so `/new` treats it as drift and RUNS the
162
- plan-auditor. **NEVER block or abort the PRD over the stamp**; the only thing this gate
163
- blocks is shipping cards with the stamp SILENTLY absent. Runtime-neutral (bash + YAML
164
- edits) → identical on Claude and Codex. The backfilled YAMLs are staged by item 6's
165
- existing `FEAT-XXXX-*.yml` glob.
157
+ unavailable), the script writes it explicitly as `""` so `/new` treats it as drift and
158
+ RUNS the plan-auditor. **NEVER block or abort the PRD over the stamp**; the only thing
159
+ this gate blocks is shipping cards with the stamp SILENTLY absent. Runtime-neutral
160
+ (node + YAML edits) → identical on Claude and Codex. The backfilled YAMLs are staged
161
+ by item 6's existing `FEAT-XXXX-*.yml` glob.
166
162
 
167
163
  6. Stage ONLY PRD session artefacts by explicit file name (NEVER `git add .`
168
164
  or `git add -A`):
@@ -2,6 +2,10 @@
2
2
 
3
3
  Formato: [Keep a Changelog](https://keepachangelog.com/) · [SemVer](https://semver.org/).
4
4
 
5
+ ## 1.1.0 — 2026-07-02
6
+
7
+ - **Analysis-profile contract (framework v4.94.0)**: PATCH-mode re-discovery passes `PROFILE=impact` to `codebase-architect` (blast-radius scoping per `framework/agents/analysis-profiles.md`).
8
+
5
9
  ## 1.0.0 — 2026-07-01
6
10
 
7
11
  - Baseline: versioning per-skill introdotto al framework v4.82.0.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: prd-add
3
3
  effort: medium
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  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."
6
6
  ---
7
7
 
@@ -241,7 +241,8 @@ Execute ONLY phases with PATCH or REDO verdict, in original phase order.
241
241
 
242
242
  ### For Discovery dimensions (PATCH/REDO)
243
243
 
244
- - **PATCH**: Run `codebase-architect` on affected dimensions only.
244
+ - **PATCH**: Run `codebase-architect` on affected dimensions only — pass
245
+ `PROFILE=impact` (blast-radius scoping per `agents/analysis-profiles.md`).
245
246
  Update state file checklist entries. No user questions unless ambiguous.
246
247
  - **REDO**: Full re-discovery for that dimension (same as /prd Step 2 loop
247
248
  but scoped to affected dimensions only). May require user questions.
@@ -2,6 +2,10 @@
2
2
 
3
3
  Formato: [Keep a Changelog](https://keepachangelog.com/) · [SemVer](https://semver.org/).
4
4
 
5
+ ## 1.1.0 — 2026-07-02
6
+
7
+ - **Analysis-profile contract (framework v4.94.0)**: Step B adjacent-UI analysis passes `PROFILE=ui OUTPUT=terse` to `codebase-architect` (registry-cascade-first per `framework/agents/analysis-profiles.md`).
8
+
5
9
  ## 1.0.0 — 2026-07-01
6
10
 
7
11
  - Baseline: versioning per-skill introdotto al framework v4.82.0.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: ui-design
3
3
  effort: medium
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  description: "UI design workflow. Generates context-aware mockups with GAN-inspired generator/evaluator separation, visual verification via Playwright, and structured sprint contracts. Use when: (1) designing new pages or components, (2) the /prd skill reaches its UI design phase (Step 3), (3) redesigning existing pages, (4) creating design options for user review, (5) any task involving 'design UI', 'mockup', 'opzioni di design', 'progetta interfaccia', '3 opzioni', 'design page', 'UI design'. Not for: bug fixes, small tweaks, copy-only changes, or implementing an already-chosen design."
6
6
  ---
7
7
 
@@ -120,7 +120,7 @@ Read [references/generation.md](references/generation.md) § Context Capture.
120
120
  render harness over full-page Playwright — `baldart render build && /ds-render`
121
121
  gives per-primitive PNGs of the REAL registry components (Storybook-backed). Use
122
122
  full-page Playwright for page-level context. No Storybook → fall back to Playwright.
123
- 3. Invoke `codebase-architect` to analyze adjacent UI components, layout patterns, and design tokens. Report file paths and rendered structure.
123
+ 3. Invoke `codebase-architect` with `PROFILE=ui OUTPUT=terse` (profile contract: `agents/analysis-profiles.md` — registry-cascade-first, component reuse table, token findings) to analyze adjacent UI components, layout patterns, and design tokens. Report file paths and structure.
124
124
 
125
125
  ### Step C — Generate 3 Options (GENERATOR)
126
126
 
@@ -274,7 +274,7 @@ if (baselinePaths.length) {
274
274
  log(`Baseline: reusing ${baselinePaths.length} per-card baseline file(s).`)
275
275
  } else {
276
276
  const arch = await agent(
277
- `You are grounding a post-implementation code review. Map the EXISTING architecture, critical patterns, and high-risk code paths relevant to this wave's changed files, so downstream reviewers can spot regressions.\n\n${waveBrief}\n\nReturn a concise baseline (key modules, their contracts, the regression-prone seams touched by this diff). Do not review the changes yet.`,
277
+ `PROFILE=baseline — resolve your analysis profile per agents/analysis-profiles.md (Grep "### PROFILE: baseline", Read only that section; v4.94.0). You are grounding a post-implementation code review. Map the EXISTING architecture, critical patterns, and high-risk code paths relevant to this wave's changed files, so downstream reviewers can spot regressions.\n\n${waveBrief}\n\nReturn a concise baseline (key modules, their contracts, the regression-prone seams touched by this diff). Do not review the changes yet.`,
278
278
  { label: 'arch-baseline', phase: 'Baseline', agentType: 'codebase-architect',
279
279
  schema: { type: 'object', required: ['baseline'], additionalProperties: false, properties: { baseline: { type: 'string' } } } }
280
280
  )
@@ -265,7 +265,7 @@ if (baselinePaths.length) {
265
265
  log(`Baseline: reusing ${baselinePaths.length} per-card baseline file(s).`)
266
266
  } else {
267
267
  const arch = await agent(
268
- `You are grounding a post-implementation code review. Map the EXISTING architecture, critical patterns, and high-risk code paths relevant to this batch's changed files, so downstream reviewers can spot regressions.\n\n${scopeBrief}\n\nReturn a concise baseline (the key modules, their contracts, and the regression-prone seams touched by this diff). Do not review the changes yet.`,
268
+ `PROFILE=baseline — resolve your analysis profile per agents/analysis-profiles.md (Grep "### PROFILE: baseline", Read only that section; v4.94.0). You are grounding a post-implementation code review. Map the EXISTING architecture, critical patterns, and high-risk code paths relevant to this batch's changed files, so downstream reviewers can spot regressions.\n\n${scopeBrief}\n\nReturn a concise baseline (the key modules, their contracts, and the regression-prone seams touched by this diff). Do not review the changes yet.`,
269
269
  { label: 'arch-baseline', phase: 'Baseline', agentType: 'codebase-architect',
270
270
  schema: { type: 'object', required: ['baseline'], additionalProperties: false, properties: { baseline: { type: 'string' } } } }
271
271
  )
@@ -552,8 +552,12 @@ async function runCard(cardId, cardPath) {
552
552
  let arch = null
553
553
  try {
554
554
  arch = await agentSafe(
555
- `You are the Phase-1 context retriever for card ${cardId} (per ${REF}/implement.md Phase 1 step 3 / 5b). cd into the worktree ${sharedCtx.worktreePath}.\n\n${cardBrief}\n\n` +
556
- `Explore the codebase exactly as your system prompt mandates for this card's scope (requirements + files_likely_touched: ${JSON.stringify(node.filesLikelyTouched || [])}). Write your COMPLETE untruncated findings (file paths, type signatures, patterns, high-risk paths) to ${baselinePath} — refresh it if a stale copy exists. The owner agent and the per-card reviewers will Read that file; keep your structured return MINIMAL.\n\n` +
555
+ `You are the Phase-1 context retriever for card ${cardId} (per ${REF}/implement.md Phase 1 step 3 / 5b). cd into the worktree ${sharedCtx.worktreePath}.\n\n` +
556
+ // Analysis profile (v4.94.0 implement.md step 3 parallel): deterministic from the
557
+ // pre-flight hasMockup bit, mirroring the mockup-first build routing (§6a). SSOT:
558
+ // agents/analysis-profiles.md § 3 caller routing table.
559
+ `PROFILE=${node.hasMockup ? 'ui' : 'feature'} OUTPUT=terse — resolve your analysis profile per agents/analysis-profiles.md (Grep "### PROFILE: ${node.hasMockup ? 'ui' : 'feature'}", Read only that section + its cited shared blocks).\n\n${cardBrief}\n\n` +
560
+ `Explore the codebase exactly as your system prompt + profile mandate for this card's scope (requirements + files_likely_touched: ${JSON.stringify(node.filesLikelyTouched || [])}). Write your COMPLETE untruncated findings (file paths, type signatures, patterns, high-risk paths) to ${baselinePath} — refresh it if a stale copy exists. The owner agent and the per-card reviewers will Read that file; keep your structured return MINIMAL.\n\n` +
557
561
  `Also report missingPaths: every path in files_likely_touched that does NOT exist in the worktree (factual ls/test check — no judgement). Return: { ok, missingPaths:[...], note }`,
558
562
  { label: `architect:${cardId}`, phase: 'Implement', agentType: 'codebase-architect',
559
563
  schema: { type: 'object', required: ['ok'], additionalProperties: true, properties: { ok: { type: 'boolean' }, missingPaths: { type: 'array', items: { type: 'string' } }, note: { type: 'string' } } } }
@@ -0,0 +1,286 @@
1
+ # Analysis Profiles — the codebase-architect investigation contract
2
+
3
+ **Purpose**: `codebase-architect` is the single read-only analyst every surface delegates
4
+ to, but "understand the codebase" is not one job — grounding an implementer, tracing a
5
+ bug, measuring blast radius, loading planning context, and inventorying UI primitives
6
+ need different retrieval plans and different output blocks. This module is the **single
7
+ SSOT of those plans**. The agent body carries the shared engine (canonical-router-first,
8
+ tiered code search, read-size discipline, memory); each profile here scopes WHICH parts
9
+ of that engine run, what to read/skip, and which output blocks the caller receives.
10
+
11
+ This is the retrieval-side twin of `effort-protocol.md` (how deeply to reason) and
12
+ `return-contract-protocol.md` (how compactly to report). Same mechanism as `OUTPUT=terse`
13
+ (v4.49.0): a prompt-level token, zero new config keys, zero runtime dependency.
14
+
15
+ **Consumers**: `codebase-architect` (dispatcher — reads its matching profile section at
16
+ spawn), every caller that spawns it (`/new` implement.md, `new2.js` B7, the review
17
+ workflows, `/prd`, `/prd-add`, `/bug`, `/ui-design`, `/ds-handoff`, `/codexreview`,
18
+ `plan-auditor`, `/e2e-review`), and `context-primer` (maps its task types onto profiles
19
+ instead of restating search strategy).
20
+
21
+ ---
22
+
23
+ ## 1. Contract
24
+
25
+ - **Token**: the invoking prompt contains `PROFILE=<feature|bug|impact|discovery|ui|baseline>`
26
+ (one token, anywhere in the prompt — same parsing style as `OUTPUT=terse` and
27
+ `effort=<level>`). Composable with `OUTPUT=terse` and an explicit token budget.
28
+ - **Dispatch (agent side)**: parse the token FIRST. Then Grep this file for the heading
29
+ `### PROFILE: <name>` and Read ONLY that section (plus any `§ Shared block` it cites) —
30
+ never read this module end-to-end.
31
+ - **No token → deterministic inference**, in this exact priority order (first match wins):
32
+ 1. prompt names a mockup / `links.design` / `component_bindings` / design-system
33
+ registry / tokens → `ui`
34
+ 2. prompt asks blast-radius / affected surface / "what depends on" / refactor scope →
35
+ `impact`
36
+ 3. prompt reports an error / crash / regression / "non funziona" → `bug`
37
+ 4. prompt grounds a post-implementation review over a diff/batch → `baseline`
38
+ 5. prompt loads context for planning / PRD / a question about docs or product intent →
39
+ `discovery`
40
+ 6. otherwise → `full` (legacy monolith behavior: run every protocol, all output blocks).
41
+ - **Caller side**: prefer the explicit token — inference is the fallback, not the design.
42
+ The routing table in § 3 is normative for framework callers.
43
+ - **Invariants that hold for EVERY profile** (they live in the agent body, not here):
44
+ read-only role boundary; Return Contract (COMPACT); canonical-router-first engine;
45
+ anti-flail gate; read-size discipline; `## Canonical Evidence` block in every analysis;
46
+ Hot-File Map on terse output for in-scope files > 800 lines; memory hygiene.
47
+ - **Precedence**: an explicit instruction in the invoking prompt (e.g. a caller-supplied
48
+ token budget or an extra output field) overrides the profile default. A profile never
49
+ overrides the role boundary or the Return Contract.
50
+
51
+ ## 2. Profiles
52
+
53
+ ### PROFILE: feature
54
+
55
+ - **Question**: what exists in this area, which patterns must a change follow, what can
56
+ be reused, where are the risks?
57
+ - **Callers**: `/new` implement.md Phase 1 step 3 + `new2.js` B7 (cards WITHOUT a
58
+ mockup), ad-hoc pre-implementation grounding, `hybrid-ml-architect` /
59
+ `security-reviewer` / `legal-counsel-gdpr` Phase-0 grounding.
60
+ - **Retrieval**: full engine — canonical router → git log (if thin) → structural tier
61
+ (graph/LSP per `code-search-protocol.md` / `code-graph-protocol.md`) → targeted reads.
62
+ - **Run**: § Shared block: Reuse Analysis · § Shared block: Documentation Reliability
63
+ Scan (when docs are evidence).
64
+ - **Skip**: nothing engine-side; skip the UI cascade unless the scope touches components
65
+ (then the caller should have routed `ui`).
66
+ - **Output blocks**: `## Reuse Analysis` + `## Canonical Evidence` + affected-code rows
67
+ (`path:line — symbol — pattern/role`) + high-risk rows + `## Hot-File Map` + `totals:`.
68
+ - **Budget**: ≤ 20K tokens.
69
+
70
+ ### PROFILE: bug
71
+
72
+ - **Question**: what is the code path from entry point to failure, and what changed
73
+ recently on it?
74
+ - **Callers**: `/bug` Phase 0; context-primer `task_type: bug-fix`.
75
+ - **Retrieval**: entry-point location (structural tier first for the failing
76
+ symbol/handler) → trace the path → `git log --oneline -15 -- <suspect paths>` for
77
+ recent-change candidates → targeted range reads of suspects only.
78
+ - **Run**: nothing extra — speed is the point.
79
+ - **Skip**: § Reuse Analysis (no component discovery in a bug hunt) · architecture docs
80
+ and ADRs unless the failure is a contract violation · broad domain reads.
81
+ - **Output blocks**: `## Canonical Evidence` + a **code-path map** (ordered
82
+ `path:line — step` rows from entry to failure) + a **recent-change list**
83
+ (`sha — path — why suspect`) + `## Hot-File Map` for any suspect file > 800 lines +
84
+ `totals:`.
85
+ - **Budget**: ≤ 15K tokens.
86
+
87
+ ### PROFILE: impact
88
+
89
+ - **Question**: if X changes, what breaks — which files, contracts, and consumers are in
90
+ the blast radius?
91
+ - **Callers**: `plan-auditor` FULL-mode grounding; `/prd` Step 2 ISA (Impact Surface
92
+ Analysis); `/prd-add` PATCH mode (affected dimensions only); `/e2e-review` route/
93
+ primitive reverse lookup; refactor scoping; context-primer `task_type: refactor`.
94
+ - **Retrieval**: **structural tier is PRIMARY** — `graphify affected`/`path` when
95
+ `features.has_code_graph: true`, LSP `find-references` when `has_lsp_layer: true`,
96
+ else exports/imports reads per the engine's anti-flail rule. Router only to resolve
97
+ the owning contract docs of the affected surface.
98
+ - **Run**: § Shared block: Documentation Reliability Scan only for the contract docs you
99
+ cite.
100
+ - **Skip**: § Reuse Analysis · full-file reads of dependents (list them, read only the
101
+ coupling site) · design rationale.
102
+ - **Output blocks**: `## Canonical Evidence` + an **affected-surface table**
103
+ (`path:line — dependent symbol — direction (uses/used-by) — contract at risk`) +
104
+ transitive one-hop notes + `totals:`.
105
+ - **Budget**: ≤ 15K tokens.
106
+
107
+ ### PROFILE: discovery
108
+
109
+ - **Question**: what context does a planner (or a human asking a question) need —
110
+ constraints, canonical sources, current state — before any decision?
111
+ - **Callers**: `context-primer` (`task_type: new-feature | query | doc-update`); `/prd`
112
+ discovery-loop targeted questions.
113
+ - **Retrieval**: docs-first — canonical router → matched reference/ADR sections →
114
+ backlog cards → wiki overlay (when `features.has_wiki_overlay: true`, verify wiki
115
+ claims against canonicals) → agent memory. **Source code only to verify a
116
+ runtime-sensitive claim** (auth pattern, API contract, current schema).
117
+ - **Task-type deltas** (passed through by context-primer): `query`/`doc-update` → docs +
118
+ memory only, skip source entirely; `new-feature` → also map the domain's existing
119
+ patterns (2-3 exemplar `path:line` anchors) and relevant ADRs.
120
+ - **Run**: § Shared block: Documentation Reliability Scan (docs ARE the evidence here —
121
+ mandatory).
122
+ - **Skip**: § Reuse Analysis · code-wide scans · reading any `${paths.prd_dir}` /
123
+ `${paths.references_dir}` file end-to-end (route via the registry, read sections).
124
+ - **Output blocks**: `## Canonical Evidence` + § Reliability Scan block + constraints-
125
+ first summary (the caller may impose its own envelope, e.g. context-primer's XML —
126
+ honor it verbatim).
127
+ - **Budget**: ≤ 15K tokens.
128
+
129
+ ### PROFILE: ui
130
+
131
+ - **Question**: which registry primitives/tokens/patterns serve this UI scope, what is
132
+ reused vs variant vs genuinely new, and what does the current implementation state
133
+ look like — **answered from the registry and code, never from pixels**.
134
+ - **Callers**: `/new` implement.md + `new2.js` B7 (cards WITH a mockup —
135
+ `links.design`/`links.design_src` non-empty); `/ui-design` Step 3 adjacent-UI
136
+ analysis; `/ds-handoff` entity/field probe; context-primer UI-keyword branch.
137
+ - **Retrieval**: § Shared block: UI Resolution Path is the PRIMARY route — INDEX.md
138
+ (thin router) → frontmatter **HEAD** of matched `components/<Name>.md` → DTCG tokens →
139
+ patterns. **Never read component source to learn an API its HEAD already carries**;
140
+ read source only for undocumented primitives or to verify a runtime-sensitive claim.
141
+ When `features.has_design_system: false`, degrade to
142
+ `${paths.references_dir}/component-registry.md` + targeted source reads.
143
+ - **Run**: § Shared block: Reuse Analysis (component-flavored — candidates come from the
144
+ registry cascade, classification uses the card's `component_bindings` vocabulary
145
+ `reuse / reuse-variant / new` when present).
146
+ - **Skip**: backend/data-model deep dives (one-line integration notes only) · § UI
147
+ boundary below.
148
+ - **Output blocks**: `## Reuse Analysis` (component table) + `## Canonical Evidence` +
149
+ binding/coverage notes (`region — bound component — status`) + token findings
150
+ (hardcoded-value risks as `path:line — value — owning token`) + `## Hot-File Map` +
151
+ `totals:`.
152
+ - **Budget**: ≤ 15K tokens.
153
+ - **UI boundary (binding)**: this profile is **code/registry-side only**. Rendered
154
+ evidence — mockup images, screenshots, live routes — belongs to the multimodal
155
+ specialists: analysis of mockup pixels → a read-only `ui-expert` spawn (the
156
+ `/prd` Step 1.6.5 precedent), fidelity verdicts → the verifier trio via `/e2e-review`.
157
+ If the invoking prompt asks you to judge pixels, flag it as over-scoped and return the
158
+ code/registry map (same rule as the Role boundary for implementation asks).
159
+
160
+ ### PROFILE: baseline
161
+
162
+ - **Question**: what is the EXISTING architecture around this diff/batch, so reviewers
163
+ can spot regressions?
164
+ - **Callers**: `new-final-review.js` / `new-card-review.js` Phase Baseline (fallback
165
+ when no per-card baselines exist); `/codexreview` Step 1; `/new` final-review F.2
166
+ inline fallback.
167
+ - **Retrieval**: diff-scoped — start from the changed-files list, resolve each file's
168
+ module/contract via router + structural tier; NO topic-wide exploration beyond the
169
+ seams the diff touches.
170
+ - **Run**: nothing extra.
171
+ - **Skip**: § Reuse Analysis · § Reliability Scan (cite doc freshness only if a doc
172
+ contradicts the code) · product-intent docs.
173
+ - **Output blocks**: `## Canonical Evidence` + key-module map (`path — contract — why it
174
+ matters to this diff`) + regression-prone seams (`path:line — risk`) +
175
+ `## Hot-File Map` + `totals:`. Persist to the caller-named file when one is given
176
+ (e.g. `/tmp/arch-baseline-<CARD-ID>.md`) — persist-then-summarize per the Return
177
+ Contract.
178
+ - **Budget**: ≤ 20K tokens (batch scope); ≤ 15K per single card.
179
+
180
+ ### PROFILE: full (fallback — no token, no inference match)
181
+
182
+ Legacy monolith behavior: run the whole engine, § Reuse Analysis when the task builds or
183
+ changes code, § Reliability Scan when docs are evidence, UI Resolution Path when the
184
+ query concerns UI. All output blocks that apply. Budget ≤ 20K. Callers in the framework
185
+ payload should never rely on `full` — pass a token.
186
+
187
+ ## 3. Caller routing table (normative for framework surfaces)
188
+
189
+ | Caller | Profile |
190
+ |---|---|
191
+ | `/new` implement.md Phase 1 step 3 · `new2.js` B7 | `ui` if card has non-empty `links.design` OR `links.design_src` (the `hasMockup` bit), else `feature` |
192
+ | `new-final-review.js` / `new-card-review.js` Phase Baseline · `/codexreview` Step 1 | `baseline` |
193
+ | `plan-auditor` FULL-mode grounding spawn | `impact` |
194
+ | `/prd` discovery-loop targeted question | `discovery` |
195
+ | `/prd` Step 2 ISA touchpoint mapping · `/prd-add` PATCH | `impact` |
196
+ | `/bug` Phase 0 | `bug` |
197
+ | `/ui-design` Step 3 · `/ds-handoff` probe | `ui` |
198
+ | `/e2e-review` route/primitive reverse lookup | `impact` |
199
+ | `context-primer` | by task type: `bug-fix→bug` · `refactor→impact` · `new-feature/query/doc-update→discovery` · UI keywords + `has_design_system:true` → `ui` |
200
+
201
+ ## 4. Shared blocks
202
+
203
+ ### § Shared block: Reuse Analysis
204
+
205
+ Run **only when a profile lists it** (feature, ui, full-when-building).
206
+
207
+ 1. **Identify what the task needs**: UI components, hooks, utilities, API patterns, data
208
+ flows.
209
+ 2. **Search for existing matches**:
210
+ - `features.has_design_system: true` → the fastest reuse signal is the **spec HEADs**:
211
+ `${paths.design_system}/INDEX.md` (thin router), then the frontmatter HEAD of
212
+ candidate `components/<Name>.md` (schema: `component-manifest-schema.md`). Prefer
213
+ this over Grep.
214
+ - Else `${paths.references_dir}/component-registry.md` (relevant table section only).
215
+ - Grep only for 2-3 specific component names, never broad semantic sweeps.
216
+ 3. **Classify each candidate**: **Direct reuse** (works as-is) · **Refactor & reuse**
217
+ (≥70% fit — generalize via props/config) · **Extract & share** (logic duplicated in
218
+ 2+ places) · **No match** (build new — document why).
219
+ 4. **Agent memory**: read `.claude/agent-memory/codebase-architect/shared-components.md`
220
+ only when the task involves UI components; update it with new discoveries.
221
+
222
+ Output format (emit in every analysis whose profile runs this block; if nothing is
223
+ reusable, emit the section with "No reusable components found — all new code required"
224
+ and why):
225
+
226
+ ```markdown
227
+ ## Reuse Analysis
228
+
229
+ ### Reusable Components Found
230
+ | Need | Existing Component | Path | Classification | Action |
231
+ |------|-------------------|------|----------------|--------|
232
+
233
+ ### No Match (Must Build New)
234
+ - [component/pattern]: [why nothing existing fits]
235
+
236
+ ### Refactoring Opportunities
237
+ - [duplication worth consolidating, even if adjacent to this task]
238
+ ```
239
+
240
+ ### § Shared block: UI Resolution Path
241
+
242
+ The design-system resolution cascade (paths are project-specific; this order is the
243
+ convention — the protocol SSOT is `design-system-protocol.md`):
244
+
245
+ 1. `${paths.design_system}/INDEX.md` — thin router (name → source → purpose → spec)
246
+ 2. `${paths.design_system}/components/<Name>.md` — **frontmatter HEAD first**
247
+ (props/variants/composes/token_bindings/a11y — schema in
248
+ `component-manifest-schema.md`); prose body only for rationale. Never read source to
249
+ learn an API the HEAD carries.
250
+ 3. `${paths.design_tokens}` (DTCG `.tokens.json`) — token SSOT; `tokens-reference.md` is
251
+ a generated view
252
+ 4. `${paths.design_system}/patterns/*` — theming, overlays, animations, platform quirks
253
+ 5. `${paths.references_dir}/ui-guidelines.md` — brand philosophy and aesthetic rules
254
+ 6. `${paths.references_dir}/component-registry.md` — shared-component inventory
255
+
256
+ ### § Shared block: Documentation Reliability Scan
257
+
258
+ Run when a profile lists it AND documentation is part of the evidence set:
259
+
260
+ 1. **Registry coverage** — the feature exists in `${paths.references_dir}/ssot-registry.md`;
261
+ backlog/PRD-only → report `REGISTRY_GAP`
262
+ 2. **Freshness markers** — `Last updated`/change-log markers vs `git log -1` on the doc
263
+ 3. **Link quality** — markdown links vs raw paths; path-heavy PRDs lower retrieval quality
264
+ 4. **Retrieval risk** — doc exceeds repo thresholds (reference >400 lines, API >800,
265
+ PRD/spec >800) → headings + targeted sections, never a full read
266
+ 5. **Router fit** — registry maps the feature to a canonical doc → prefer that route
267
+
268
+ Emit in every analysis that materially depends on docs:
269
+
270
+ ```markdown
271
+ ## Documentation Reliability Scan
272
+
273
+ - Registry coverage: [ok | REGISTRY_GAP: ...]
274
+ - Freshness status: [fresh | stale | unknown] (git evidence)
275
+ - Link quality: [ok | PATH_HEAVY: ...]
276
+ - Retrieval risk: [ok | OVERSIZE_DOC: ...]
277
+ - Router fit: [ok | WEAK_ROUTER_MATCH: ...]
278
+ ```
279
+
280
+ ---
281
+
282
+ **Codex parity: portable.** The token is prompt-level; this module ships in the bulk-
283
+ symlinked `agents/` payload both runtimes read; the agent body (dispatcher) transpiles to
284
+ `.codex/agents/codebase-architect.toml` unchanged. No new config key — profiles gate on
285
+ flags that already exist (`has_design_system`, `has_code_graph`, `has_lsp_layer`,
286
+ `has_wiki_overlay`), so the schema-change propagation rule does not apply.