baldart 4.63.0 → 4.65.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 (34) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +3 -2
  3. package/VERSION +1 -1
  4. package/bin/baldart.js +15 -0
  5. package/framework/.claude/agents/REGISTRY.md +3 -0
  6. package/framework/.claude/agents/code-reviewer.md +25 -11
  7. package/framework/.claude/agents/codebase-architect.md +13 -5
  8. package/framework/.claude/agents/doc-reviewer.md +26 -12
  9. package/framework/.claude/agents/merge-conflict-resolver.md +58 -0
  10. package/framework/.claude/agents/ui-expert.md +18 -10
  11. package/framework/.claude/skills/context-primer/SKILL.md +7 -0
  12. package/framework/.claude/skills/design-system-init/SKILL.md +164 -156
  13. package/framework/.claude/skills/design-system-init/scripts/component-spec.template.md +26 -3
  14. package/framework/.claude/skills/design-system-init/scripts/extract-manifest.mjs +151 -0
  15. package/framework/.claude/skills/new/references/merge-cleanup.md +23 -18
  16. package/framework/.claude/skills/worktree-manager/SKILL.md +19 -0
  17. package/framework/.claude/skills/worktree-manager/scripts/merge-worktree.sh +518 -0
  18. package/framework/.claude/workflows/new2.js +14 -3
  19. package/framework/agents/component-manifest-schema.md +145 -0
  20. package/framework/agents/design-system-protocol.md +63 -23
  21. package/framework/agents/index.md +2 -0
  22. package/framework/docs/COMPONENT-MANIFEST-LAYER.md +100 -0
  23. package/framework/routines/ds-drift.routine.yml +19 -12
  24. package/framework/templates/baldart.config.template.yml +22 -0
  25. package/package.json +1 -1
  26. package/src/commands/configure.js +54 -0
  27. package/src/commands/doctor.js +85 -0
  28. package/src/commands/tokens.js +80 -0
  29. package/src/commands/update.js +7 -0
  30. package/src/utils/token-emitters/README.md +36 -0
  31. package/src/utils/token-emitters/css.js +18 -0
  32. package/src/utils/token-emitters/index.js +47 -0
  33. package/src/utils/token-emitters/ts.js +32 -0
  34. package/src/utils/tokens-generator.js +165 -0
package/CHANGELOG.md CHANGED
@@ -5,6 +5,45 @@ All notable changes to BALDART will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [4.65.0] - 2026-06-23
9
+
10
+ **Machine-readable component manifest + DTCG token SSOT — from a real slow-discovery diagnosis on a consumer (mayo).** UI component discovery was slow because the design-system `INDEX.md` had become a 33KB monolith read in full on every UI task, there was no token reference (tokens parsed from a 17KB `tokens.ts`), and 0/~135 components had a per-component spec — so every reuse lookup degraded to reading component source. The framework already prescribes per-component specs (owned by `doc-reviewer`, gated by `code-reviewer`, audited by `ds-drift`); this release **evolves that existing layer** (no twin) into a machine-readable, on-demand one, and gives tokens a real W3C DTCG source of truth.
11
+
12
+ **MINOR** — adds a CLI verb + a schema module + a util registry + config keys; additive, backward-compatible with existing prose specs, rides on `features.has_design_system` (NO new feature flag). The **schema-change propagation rule applies** to the new `paths.design_tokens` + `design_tokens:` block (template + configure + update detector + doctor + CHANGELOG).
13
+
14
+ ### Added
15
+
16
+ - **`framework/agents/component-manifest-schema.md`** — SSOT for the machine-readable frontmatter HEAD on each `components/<Name>.md`: deterministic fields (from TS/git — `name`/`source`/`source_sha`/`props`/`variants`/`composes`/`category`/`status`) vs agentic fields (curated by `doc-reviewer` — `purpose`/`token_bindings`/`a11y`/`related`/`must_rules`). Defines the on-demand read contract (INDEX router → frontmatter-first, prose only when modifying), the `source_sha`-anchored regeneration contract, and the **transition-leniency** rule (prose-only specs and empty deterministic fields stay valid — the HEAD is an upgrade target, not a new floor). Mirrors `card-schema.md`. Registered in `agents/index.md`.
17
+ - **DTCG token SSOT + generator (zero npm dependency)** — `src/utils/token-emitters/` (REGISTRY pattern: `ts` + `css` emitters, extensible) + `src/utils/tokens-generator.js` (parse `.tokens.json`, resolve `{aliases}` with cycle guard, `build()`/`isStale()`) + the **`baldart tokens build`** CLI verb (`src/commands/tokens.js`). Generated outputs carry a `baldart-generated from .tokens.json` banner.
18
+ - **Deterministic, Codex-portable extractor** — `framework/.claude/skills/design-system-init/scripts/extract-manifest.mjs` (pure Node, no deps): emits the deterministic HEAD from React+TS sources with **no subagent** (validated on mayo's real 73 components: 100% source_sha, ~73% props).
19
+ - **`framework/docs/COMPONENT-MANIFEST-LAYER.md`** — authoritative layer design / lifecycle / invariants (parallels `I18N-LAYER.md` / `CODE-GRAPH-LAYER.md`).
20
+ - **Config keys** `paths.design_tokens` (DTCG source) + `design_tokens.outputs[]` (generation targets) — propagated through template, `configure` (autodetect + prompt, gated on `has_design_system`), `update` detector (nested block + array), and `doctor`.
21
+
22
+ ### Changed
23
+
24
+ - **`/design-system-init`** — now bootstraps OR upgrades: a GREENFIELD mode and an UPGRADE mode (the mayo "prose-only / monolith / no DTCG" case) that regenerates the per-component HEAD from source, lifts prose into agentic fields, rebuilds the **thin INDEX router**, and bootstraps `.tokens.json` from the existing token file with a **round-trip verify**. No longer refuses on an existing registry. Spec template (`component-spec.template.md`) gains the frontmatter HEAD.
25
+ - **`design-system-protocol.md`** — canonical sources updated (INDEX = generated router; DTCG token SSOT inversion; `tokens-reference.md` demoted to a generated/narrative view); Authority Matrix made canonical in the protocol (out of the generated INDEX); Post-Intervention Check (b)/(c) require HEAD regeneration + DTCG edit-then-build; `DS_TOKENS_DRIFT` redefined as "generated output ≠ `baldart tokens build`".
26
+ - **Consumers wired** — `code-reviewer` Rule 8 (HEAD-first reads + transition leniency), `codebase-architect` Reuse Analysis (frontmatter-first discovery), `ui-expert` (read HEAD-first; write HEAD in the completion gate), `doc-reviewer` (owns the agentic HEAD fields; DTCG-aware token reconciliation), `context-primer` (UI fast-path), `ds-drift` routine (`source_sha` + DTCG output checks).
27
+ - **`baldart doctor`** — two backfills under `has_design_system`: `tokens-build` (regenerate drifted token outputs, autoOk) and `ds-manifest-nudge` (registry present but specs missing/prose-only → run `/design-system-init`) — the "default-on + nudge" behavior achieved without a new flag.
28
+
29
+ ## [4.64.0] - 2026-06-23
30
+
31
+ **Off-context final-merge conflict resolution — from a real heavy-drift `/mw` on `/new`.** On a long epic batch the trunk had drifted 45 commits while the batch ran; the final `/mw` (invoked via `Skill()`, so it runs IN the orchestrator's context) hit mixed conflicts and resolved them **inline** — Read/grep/sed/python churn re-reading the giant end-of-batch cache, exactly when tokens cost the most (the `~20M-token` hand-merge regression `merge-cleanup.md` already measured). This release moves the merge off that context the right way, without repeating the v4.46.0/v4.53.0 "model-in-the-loop for plumbing" mistake.
32
+
33
+ **MINOR** — adds one agent + one SSOT script; opt-in, additive, runtime-detected, with the legacy `Skill(/mw)` path kept as the fallback. **No new `baldart.config.yml` key** → the schema-change propagation rule does NOT apply.
34
+
35
+ ### Added
36
+
37
+ - **`scripts/merge-worktree.sh` — the deterministic SSOT for the whole merge** (the merge analogue of `setup-worktree.sh`), consumed identically by `/mw`, `/new` Phase 6, and `new2`. It runs the entire sequence — safety commit → rebase onto `origin/$TRUNK` → **deterministic** resolution of the ADDITIVE conflict classes (structured registries with `validate_structured_md`, metrics JSONL, generic docs/config) → toolchain-aware build (hard timeout, SKIP tier) → land via `git.merge_strategy` (`pr`/`local-push`) → local-trunk sync (markers written to the **status file**, not stdout) → worktree cleanup → registry removal. It writes a structured status file on **every** exit path (`success | code_conflict | build_fail | sync_needs_decision | error`) with a **provisional non-terminal** status written before any mutation, so a kill mid-rebase/mid-build never leaves a stale `success` (no false-pass). The ONE thing it never does is resolve a **code** conflict (irreducible judgment): it pauses the rebase, records `conflict_files`, and exits `code_conflict` for the resolver. "A deterministic script cannot fabricate or stall."
38
+ - **`merge-conflict-resolver` agent (Sonnet, effort medium)** — the judgment layer, spawned by `/new` Phase 6 / `/mw` **only** on `status:code_conflict`. It classifies each paused code/test hunk **additive** (distinct imports/decls/rows, colliding index → renumber → resolve, build-verified) vs **semantic** (same logic/value/signature → STOP, never guess), then re-invokes `merge-worktree.sh --continue` (looping per replayed commit) to land — all in a **fresh, isolated context** so the conflict churn never re-enters the orchestrator. It is the ONE bounded exception to `coder`'s "branches off-limits" rule (worktree-scoped, merge phase only) and returns COMPACT (a one-line `MERGED <sha>` / `STOP: <file>:<hunk> semantic` + `path:line`). The orchestrator runs an **anti-fabrication disk gate** on its return (no residual markers + `status:success`) — "came to rest ≠ done", never trusts the prose.
39
+
40
+ ### Changed
41
+
42
+ - **`/new` Phase 6 launches the script as a BACKGROUND Bash and reads only the small status file** (`merge-cleanup.md`), instead of `Skill(/mw)` inline — so the orchestrator's in-context cost is one launch + one status read, with the conflict churn entirely off-context (deterministic in the script, judgment in the resolver subagent). The HARD "the orchestrator never hand-merges" rule stays (the script is a deterministic delegate, the resolver a subagent); `code_conflict` → spawn the resolver; `build_fail`/semantic-STOP/`error` → interactive `AskUserQuestion` / autonomous follow-up; **script absent OR `Task` tool unavailable (Codex / older subtree) → fall back to the legacy `Skill(/mw)` inline** (zero regression). Sync markers are transcribed from the status file into the tracker so Phase 6c's hygiene gate is unchanged.
43
+ - **`/mw` (worktree-manager skill) now consumes `merge-worktree.sh`** (new step 1b) the same way `/nw` consumes `setup-worktree.sh`; the inline steps 2–7 remain as the human-readable SSOT the script mirrors and the fallback for older subtrees.
44
+ - **`new2` merge phase runs the deterministic script** instead of the model-in-the-loop "/mw programmatic, run git yourself" prose — removing the model from the merge plumbing. Honoring its OPS/GIT role boundary (never edits source, F-030), a `code_conflict` is left+reported → tracked as a merge blocker → follow-up (behavior-preserving vs today's `/mw`-STOP); the full off-context resolver is wired on the classic `/new` path. `MERGE_SCHEMA` gains `status` + `conflictFiles`.
45
+ - **`new-session-audit.mjs` + `/new-audit`** gain a **merge-phase telemetry detector** (turns/cache_read between the merge launch and Phase 6b + `code_conflict_hit` YES/NO) — non-blocking, to measure ex-post that the off-context move reduced Phase 6 cost and to gauge real conflict frequency.
46
+
8
47
  ## [4.63.0] - 2026-06-23
9
48
 
10
49
  **Fixes from the FEAT-0042 post-mortem — the first real `/new` run on v4.62.0.** v4.62.0 worked (that run billed −29% vs the FEAT-0041 baseline, 1 unplanned fix-coder vs 4, `/mw` and the durable tracker held), but the deep post-mortem surfaced a new class of bug and two real leaks — including one *introduced by* v4.62.0 itself.
package/README.md CHANGED
@@ -82,10 +82,10 @@ No additional activation steps needed — once installed, Claude Code (and Codex
82
82
  ### Core Protocol
83
83
 
84
84
  - **AGENTS.md**: Mandatory coordination rules (MUST/SHOULD/OPTIONAL)
85
- - **agents/**: 25 domain modules (architecture, workflows, testing, security, card-schema, i18n-protocol, return-contract-protocol, etc.)
85
+ - **agents/**: 26 domain modules (architecture, workflows, testing, security, card-schema, i18n-protocol, return-contract-protocol, component-manifest-schema, etc.)
86
86
  - **Routing**: If you touch X, read Y - minimize context loading
87
87
 
88
- ### AI Agents (30 specialized agents)
88
+ ### AI Agents (31 specialized agents)
89
89
 
90
90
  **Core (required for every project)**
91
91
  1. **codebase-architect**: MANDATORY before planning/implementation - understands codebase structure
@@ -123,6 +123,7 @@ No additional activation steps needed — once installed, Claude Code (and Codex
123
123
  27. **deep-human-insight**: Psychological / sociological analysis for B2C UX and adoption
124
124
  28. **skill-improver**: Weekly auto-improvement of skills/agents based on review/QA findings
125
125
  29. **i18n-translator** (v4.52.0): Context-aware label translation into native locale files (Sonnet, low-effort, flag-not-guess) — invoked by `/i18n` + the `i18n-align` routine
126
+ 30. **merge-conflict-resolver** (v4.64.0): Resolves the final-merge **code** conflicts OFF the orchestrator context — auto-spawned by `/new` Phase 6 / `/mw` only when the deterministic `merge-worktree.sh` pauses on a code/test conflict. Adjudicates additive-vs-semantic hunks (semantic → STOP), then lets the script land. Runs in a fresh isolated context so the conflict churn never re-enters the bloated end-of-batch orchestrator
126
127
 
127
128
  REGISTRY.md is the single source of truth for agent routing and capabilities.
128
129
 
package/VERSION CHANGED
@@ -1 +1 @@
1
- 4.63.0
1
+ 4.65.0
package/bin/baldart.js CHANGED
@@ -174,6 +174,21 @@ program
174
174
  await teardownCommand({ cwd: options.cwd, json: !!options.json });
175
175
  });
176
176
 
177
+ const tokensGroup = program
178
+ .command('tokens')
179
+ .description('Design-token operations. The DTCG `.tokens.json` (paths.design_tokens) is the SSOT; `tokens build` regenerates the stack-native artifacts (tokens.ts / CSS vars) from it.');
180
+
181
+ tokensGroup
182
+ .command('build')
183
+ .description('Regenerate design_tokens.outputs[] from the DTCG source. No source / no outputs → no-op. A malformed .tokens.json or write failure → exit 1.')
184
+ .option('--cwd <path>', 'Project root (defaults to the current directory).')
185
+ .option('--json', 'Machine-readable output: emit a single JSON result object on stdout')
186
+ .action(async (options) => {
187
+ const tokens = require('../src/commands/tokens');
188
+ const code = await tokens.build({ cwd: options.cwd, json: !!options.json });
189
+ if (typeof code === 'number' && code !== 0) process.exitCode = code;
190
+ });
191
+
177
192
  const overlayGroup = program
178
193
  .command('overlay')
179
194
  .description('Author and check .baldart/overlays/ — scaffolds, validates, and detects drift on skill/agent/command overlays');
@@ -21,6 +21,7 @@ Quick-reference for all custom agents. Use this to route tasks to the right spec
21
21
  | **code-reviewer** | Code | Review code post-implementation for bugs/quality | Security analysis, code quality, registry-first UI compliance (when `features.has_design_system: true`) — flags re-implemented primitives and bypassed tokens as HIGH per `framework/agents/design-system-protocol.md`. NOT a visual-design evaluator (that is `ui-expert` / `visual-fidelity-verifier`). | No (review-only role — emits findings; fixes are applied by `coder`. The `bypassPermissions` tool-mode all agents run under is execution access, not an implementer role) | Static analysis, security audit |
22
22
  | **security-reviewer** | Code | Review security-sensitive code, configs, auth, secrets, and infra changes | AppSec audit, threat modeling, hardening guidance | No | Security review, trust-boundary analysis |
23
23
  | **qa-sentinel** | QA | **Mechanical gate runner** — lint, typecheck, test suite, build, security audit, markdownlint. Returns PASS/FAIL verdict only. Does NOT analyze code, verify ACs, or review security/performance (those are Phase 2.5 and code-reviewer responsibilities). | Gate execution, verdicts | No (reports failures, coder fixes) | ESLint, tsc, node --test, npm run build, npm audit, markdownlint |
24
+ | **merge-conflict-resolver** | DevOps | Resolve the final-merge **code** conflicts OFF the orchestrator context. Auto-spawned by `/new` Phase 6 (and standalone `/mw`) ONLY when the deterministic `scripts/merge-worktree.sh` pauses with `status:code_conflict` — the script already resolved every additive doc/registry/JSONL conflict; this agent adjudicates the irreducible code/test hunks then lets the script land. Runs in a fresh isolated context so the conflict churn never re-enters the bloated end-of-batch orchestrator. Never spawned ad-hoc. | Additive-vs-semantic hunk judgment (semantic → STOP), `merge-worktree.sh --continue` rebase loop, anti-fabrication disk gate, COMPACT return | Yes — the **ONE bounded exception** to coder's "branches off-limits" rule: worktree-scoped, merge phase only, post-checks-passed; lands via the script, never hand-rolled git | git conflict resolution, `merge-worktree.sh --continue` |
24
25
  | **hybrid-ml-architect** | ML | Design/implement ML systems end-to-end | Recommender, ranking, embeddings | Yes | Model design, evaluation, monitoring |
25
26
  | **i18n-translator** | Localization | Translate user-facing labels into the maintained target languages (invoked by `/i18n` + the `i18n-align` routine). Gated on `features.has_i18n`. | Context-aware translation using the per-key registry context, ICU/placeholder preservation, glossary adherence; bounded "flag-not-guess" self-healing (`needs-attention`) | Yes (writes native locale files ONLY — never app code, never the registry) | Native locale files, optional bulk backends (lingo.dev/languine) |
26
27
  | **ui-expert** | Design | Design, implement, and review UI/UX | Mobile-first, accessibility, registry-first protocol gate (when `features.has_design_system: true`) — BLOCKING reads on `${paths.design_system}/INDEX.md` + `tokens-reference.md` + `components/<Name>.md` per `framework/agents/design-system-protocol.md`, Component Discovery cascade before any design | Yes (generates UI / HTML mockups in `ui-design` Step C; a separate fresh instance acts as design-quality evaluator in Step D) | ui-ux-pro-max, Playwright |
@@ -112,6 +113,7 @@ Mechanical gate run? (see QA Protocol) --> qa-sentinel ← gate-runner only, PA
112
113
  Write a regression test? --> coder (qa-sentinel cannot write code)
113
114
  Collateral impact detection? --> code-reviewer / codebase-architect
114
115
  Check runtime logs / console errors? --> code-reviewer (requires code-aware analysis)
116
+ Final-merge CODE conflict to resolve? --> merge-conflict-resolver (auto-spawned by /new Phase 6 / /mw on merge-worktree.sh status:code_conflict — not a manual route)
115
117
 
116
118
  New feature/bug to scope? --> prd
117
119
  PRD approved, need backlog cards? --> prd-card-writer (called by /prd skill)
@@ -194,6 +196,7 @@ Use this table when spawning agents via the `Task` tool. The `model` field in ea
194
196
  | **doc-reviewer** | sonnet | — (always sonnet) | Documentation work, sonnet handles well |
195
197
  | **security-reviewer** | sonnet | opus for auth/payments/multi-tenant | Elevate for high-risk security analysis |
196
198
  | **qa-sentinel** | sonnet | — (always sonnet) | Mechanical gate runner, no reasoning needed |
199
+ | **merge-conflict-resolver** | sonnet | — (always sonnet) | Bounded additive-vs-semantic judgment over small hunks; the deterministic plumbing lives in `merge-worktree.sh`, not the agent |
197
200
  | **codebase-architect** | sonnet | — (always sonnet) | Code navigation + pattern analysis |
198
201
  | **plan-auditor** | sonnet | opus for >5 card epics | Complex plan audits benefit from deeper reasoning |
199
202
  | **prd** | opus | — (always opus) | PRD creation requires deep product thinking |
@@ -51,14 +51,20 @@ this file).
51
51
  Concrete enforcement contract for the review pass:
52
52
 
53
53
  1. When `features.has_design_system: true`, read `${paths.design_system}/INDEX.md`
54
- (component index + Canonical Authority Matrix) before reviewing UI diffs.
55
- 2. For any component in the diff, cross-check against
56
- `${paths.design_system}/components/<Name>.md` — variants, states, required
57
- props, accessibility contract.
58
- 3. Enforce design-system MUST rules from the project's INDEX as HIGH-confidence
59
- findings. Typical rules include:
60
- - No hardcoded hex, shadow, radius, spacing literals only tokens from
61
- `${paths.design_system}/tokens-reference.md`.
54
+ (the thin router) before reviewing UI diffs, then read the **frontmatter HEAD**
55
+ of each in-scope `components/<Name>.md` (per
56
+ `framework/agents/component-manifest-schema.md`)not the whole monolith, not
57
+ the source. Read a spec's prose body only when the diff modifies that primitive.
58
+ 2. For any component in the diff, cross-check against its
59
+ `components/<Name>.md` HEAD variants, props, `token_bindings`, a11y,
60
+ `must_rules`. A `token_bindings` ID that does not resolve in the DTCG source
61
+ (`paths.design_tokens`) is `DS_TOKENS_DRIFT`.
62
+ 3. Enforce design-system MUST rules (the spec HEAD's `must_rules` + project INDEX)
63
+ as HIGH-confidence findings. Typical rules include:
64
+ - No hardcoded hex, shadow, radius, spacing literals — only tokens. When
65
+ `paths.design_tokens` is set, the SSOT is the DTCG `.tokens.json`; the
66
+ generated `tokens.ts`/CSS output must NOT be hand-edited (output ≠
67
+ `baldart tokens build` = `DS_TOKENS_DRIFT`). Otherwise the project token file.
62
68
  - Text/background pairing rules for themed surfaces (see the relevant
63
69
  pattern doc when `features.multi_tenant_theming: true`).
64
70
  - Overlay/z-index decisions follow the project's overlay decision tree.
@@ -76,15 +82,23 @@ Concrete enforcement contract for the review pass:
76
82
  conditions defined in [`design-system-protocol.md`](../../agents/design-system-protocol.md)
77
83
  § "Post-Intervention Coherence Check":
78
84
  (a) new primitive ⇒ `components/<Name>.md` spec present in the same diff,
79
- (b) modified primitive ⇒ spec updated in the same diff,
80
- (c) new/changed token `tokens-reference.md` updated in the same diff,
81
- (d) silently-existing primitive reused ⇒ INDEX entry added in the same diff.
85
+ (b) modified primitive ⇒ spec updated in the same diff, **including its
86
+ frontmatter HEAD** (deterministic `props`/`variants`/`composes`/`source_sha`
87
+ regenerated; agentic fields re-verified),
88
+ (c) new/changed token ⇒ DTCG `.tokens.json` updated + outputs regenerated
89
+ (`baldart tokens build`) when `paths.design_tokens` is set, else the
90
+ project token source/reference,
91
+ (d) silently-existing primitive reused ⇒ INDEX router entry added in the same diff.
82
92
  Each failing condition is a HIGH finding with the canonical code
83
93
  (`DS_INDEX_DRIFT` / `DS_COMPONENT_STALE` / `DS_TOKENS_DRIFT`). This is the
84
94
  third and final gate after `ui-design`/`ui-expert`'s own post-intervention
85
95
  check and the weekly `ds-drift` routine; if it trips here at review time,
86
96
  it means the upstream checks were skipped — flag the protocol violation
87
97
  alongside the drift.
98
+ **Transition leniency (do not raise the floor):** a prose-only spec lacking a
99
+ HEAD is NOT `DS_COMPONENT_STALE` merely for that; empty deterministic HEAD
100
+ fields (non-TS stack, unresolved prop) are advisory, never blocking. The HEAD
101
+ is an upgrade target — see `component-manifest-schema.md` § Transition leniency.
88
102
 
89
103
  When `features.has_design_system: false`, the registry reads are skipped but
90
104
  the review still flags hardcoded values and inconsistencies against
@@ -79,9 +79,13 @@ When analyzing a feature, resolve documentation authority in this order:
79
79
  **UI / design-system questions** follow a parallel resolution path (paths are
80
80
  project-specific; the convention below is recommended):
81
81
 
82
- 1. `${paths.design_system}/INDEX.md` — agentic-first component index + authority matrix
83
- 2. `${paths.design_system}/components/<Name>.md` — per-component spec (variants, props)
84
- 3. `${paths.design_system}/tokens-reference.md`token contract
82
+ 1. `${paths.design_system}/INDEX.md` — thin router (name source → purpose → spec)
83
+ 2. `${paths.design_system}/components/<Name>.md` — read the **frontmatter HEAD**
84
+ first (props/variants/composes/token_bindings/a11yschema in
85
+ `framework/agents/component-manifest-schema.md`); the prose body only if you
86
+ must understand rationale. This is the on-demand discovery fast path — never
87
+ read the source to learn a primitive's API when its HEAD has it.
88
+ 3. `${paths.design_tokens}` (DTCG `.tokens.json`) — token SSOT; `tokens-reference.md` is a generated view
85
89
  4. `${paths.design_system}/patterns/*` — theming, overlays, animations, platform quirks
86
90
  5. `${paths.references_dir}/ui-guidelines.md` — brand philosophy and aesthetic rules
87
91
  6. `${paths.references_dir}/component-registry.md` — inventory of shared components
@@ -226,8 +230,12 @@ component discovery.
226
230
 
227
231
  1. **Identify what the feature needs**: List the UI components, hooks, utilities, API patterns, and data flows the feature will require.
228
232
  2. **Search for existing matches**:
229
- - Check `${paths.references_dir}/component-registry.md` (read the
230
- relevant table section only, not the full file).
233
+ - When `features.has_design_system: true`, the **fastest reuse signal is the
234
+ spec HEADs**: scan `${paths.design_system}/INDEX.md` (thin router) then the
235
+ frontmatter HEAD of the candidate `components/<Name>.md` — structured
236
+ props/variants/purpose without reading source. Prefer this over Grep.
237
+ - Else check `${paths.references_dir}/component-registry.md` (relevant table
238
+ section only).
231
239
  - Grep only for 2-3 specific component names, not broad semantic sweeps.
232
240
  3. **Classify each candidate**:
233
241
  - **Direct reuse**: Component works as-is, just import it
@@ -60,21 +60,35 @@ When running in parallel with other agents (code-reviewer, security-reviewer):
60
60
 
61
61
  If your project ships a design-system SSOT (typically under `${paths.design_system}/**`
62
62
  with INDEX, per-component docs, tokens reference, pattern docs), include it in your
63
- documentation scope. Standard drift checks against this corpus:
64
-
65
- - **INDEX coverage**: compare the component index against the actual shared-component
66
- inventory (derive counts from a component registry doc). Flag mismatches as
67
- `DS_INDEX_DRIFT`.
68
- - **Per-component accuracy**: for each per-component doc, verify it lines up with
69
- the corresponding source file (variants, props, exported constants). If a doc has
70
- not been re-verified in more than 7 days and the source has changed in git, flag
71
- `DS_COMPONENT_STALE`.
63
+ documentation scope.
64
+
65
+ **You own the AGENTIC half of the per-component manifest HEAD** (schema:
66
+ `framework/agents/component-manifest-schema.md`): `purpose`, `a11y`,
67
+ `token_bindings`, `related`, `must_rules`, `last_verified`. You curate these —
68
+ you do NOT hand-write the deterministic half (`name`/`source`/`source_sha`/
69
+ `props`/`variants`/`composes`), which is regenerated from source by the extractor.
70
+ Never clobber a filled agentic field on a refresh. (This is the design-system twin
71
+ of your i18n-registry ownership: you curate context, tooling fills the mechanical part.)
72
+
73
+ Standard drift checks against this corpus:
74
+
75
+ - **INDEX coverage**: the `INDEX.md` router must list every primitive that has a
76
+ spec; flag mismatches as `DS_INDEX_DRIFT`. The router is generated — fix by
77
+ regenerating, not hand-editing.
78
+ - **Per-component accuracy**: for each spec, verify the HEAD lines up with the
79
+ source — `source_sha` matches the current blob, `props`/`variants` match the TS
80
+ types. If the source changed in git and the HEAD's `source_sha` is stale (or
81
+ `last_verified` >7 days with source change), flag `DS_COMPONENT_STALE`. A
82
+ prose-only spec with no HEAD is an upgrade candidate (`/design-system-init`), not
83
+ itself stale — see `component-manifest-schema.md` § Transition leniency.
72
84
  - **Animations reconciliation**: the animations pattern doc must match keyframes
73
85
  defined in the project's global styles. Flag `DS_ANIMATIONS_DRIFT` if a keyframe
74
86
  exists in code but not in the doc, or vice versa.
75
- - **Tokens reconciliation**: when token source files change, verify the
76
- tokens-reference doc is in sync and the relevant CSS custom properties still
77
- exist in the project's global styles. Flag `DS_TOKENS_DRIFT`.
87
+ - **Tokens reconciliation**: when `paths.design_tokens` is set, the DTCG
88
+ `.tokens.json` is the SSOT and the `tokens.ts`/CSS outputs + `tokens-reference.md`
89
+ are GENERATED verify they equal `baldart tokens build` (a hand-edit to a
90
+ generated file, or a dangling `token_bindings` ID, is `DS_TOKENS_DRIFT`). When it
91
+ is unset, fall back to checking the project token source vs its reference doc.
78
92
 
79
93
  Add a `## Design System Drift` section to the deliverables when any of these flags fire.
80
94
 
@@ -0,0 +1,58 @@
1
+ ---
2
+ name: merge-conflict-resolver
3
+ description: "Resolve the final-merge CODE conflicts off the orchestrator's context. Spawned ONLY when scripts/merge-worktree.sh pauses with status:code_conflict — the deterministic script already resolved every additive doc/registry/JSONL conflict; you adjudicate the irreducible code/test hunks (additive → resolve; semantic → STOP), then re-invoke the script with --continue to land the merge. You run in a fresh, isolated context so the conflict churn never re-enters the bloated orchestrator. Returns COMPACT (a one-line verdict + path:line), never the churn."
4
+ model: sonnet
5
+ effort: medium
6
+ color: orange
7
+ ---
8
+
9
+ > **YOLO MODE**: All agents spawned via the Task tool MUST use `mode: "bypassPermissions"`. No exceptions.
10
+
11
+ You are **Merge Conflict Resolver** — the judgment layer of the deterministic final-merge pipeline. You exist so that the irreducible *judgment* on code conflicts (additive vs semantic) happens in a **fresh, isolated context**, not in the orchestrator whose context is already enormous at end-of-batch. Every additive doc / structured-registry / metrics-JSONL conflict was ALREADY resolved deterministically by `scripts/merge-worktree.sh` before you were spawned — you never touch those. Your job is narrow: adjudicate the **code/test** hunks the script could not, then let the script finish.
12
+
13
+ ## Git authority — the ONE bounded exception
14
+
15
+ The `coder` agent is forbidden from any branch/merge operation (`coder.md` § "Git Branches Are Off-Limits"). **You are the single bounded exception**: you may resolve conflicts, `git add`, and re-invoke the merge script — but ONLY:
16
+ - inside the **worktree you were given** (the one paused mid-rebase), never the main repo working tree;
17
+ - via `scripts/merge-worktree.sh --continue` for build/land/cleanup — you do **not** hand-roll `git push` / `git rebase --continue` / `gh pr merge` yourself (the script owns the deterministic plumbing; re-authoring it is the duplication CLAUDE.md forbids and re-introduces the fabrication risk the script exists to remove);
18
+ - post-checks-passed (the orchestrator only spawns you after final review + QA passed).
19
+
20
+ **WORKTREE ISOLATION (HARD).** Capture the worktree root at startup: `WT="<worktreePath from the task brief>"`. Every path you `Edit` MUST be under `$WT`. An absolute path (or `../`) landing in the main repo silently pollutes shared state — FORBIDDEN, most of all for shared/generated/locale files.
21
+
22
+ ## Inputs (from the task brief)
23
+
24
+ - `worktreePath` — the paused worktree (absolute).
25
+ - `statusPath` — the status file `merge-worktree.sh` wrote (`status: code_conflict`, `conflict_files: <csv>`). Read it; the `conflict_files` list is your work-list.
26
+ - `manifestPath` — the status file to pass back to the script on `--continue` (usually the same path).
27
+
28
+ ## Procedure
29
+
30
+ 1. **Read the status file** at `statusPath`. Confirm `status: code_conflict`. Take `conflict_files` (CSV of repo-relative paths) — these are the UNRESOLVED code/test files, all under `$WT`.
31
+ 2. **For EACH conflicted file**, read it and classify every conflict hunk:
32
+ - **ADDITIVE** — the two sides add *independent* things at the same spot and BOTH belong: distinct imports, separate declarations/functions, distinct array/object/enum members, distinct table or changelog rows, a colliding numeric index (renumber yours to the next free value). → Resolve by keeping both sides (strip the `<<<<<<< / ======= / >>>>>>>` markers, union the content, fix ordering/numbering).
33
+ - **SEMANTIC** — the two sides change the *same* logic/value/signature/control-flow incompatibly (same function body, same constant, same condition). → Do **NOT** guess. Leave it for a human.
34
+ - When uncertain whether a hunk is additive or semantic, treat it as **SEMANTIC** (default to STOP — a wrong "additive" merge silently ships a logic regression).
35
+ 3. **If every conflicted file was fully additive** → after editing, stage them: `git -C "$WT" add <files>`. Then re-invoke the script (resolve its path like the callers do):
36
+ ```bash
37
+ SCRIPT="$(ls "$WT/.framework/framework/.claude/skills/worktree-manager/scripts/merge-worktree.sh" "$WT/.claude/skills/worktree-manager/scripts/merge-worktree.sh" 2>/dev/null | head -1)"
38
+ bash "$SCRIPT" --worktree "$WT" --manifest "<manifestPath>" --continue
39
+ ```
40
+ Re-read the status file. The rebase may surface a **fresh** `code_conflict` at the next replayed commit — if so, **loop** (back to step 2) on the new `conflict_files`. Keep looping until the status is terminal (`success` / `build_fail` / `error` / `sync_needs_decision`). This loop is the per-commit rebase cost — it is paid HERE, in your isolated context, never in the orchestrator.
41
+ 4. **If ANY hunk is SEMANTIC** → do NOT continue the merge. Leave the rebase paused (do not abort it), do not stage the semantic file. Return a terminal STOP (below). A human resolves the semantic conflict.
42
+
43
+ ## Anti-fabrication (you are inside the gate, not above it)
44
+
45
+ The orchestrator re-verifies on disk (no residual markers, build green, push landed) — it does **not** trust your prose. So never report `MERGED` unless the script's status file actually reads `status: success`. If the script returns `build_fail`, the rebase introduced an incompatibility you may have caused (a wrong additive merge) — report it as STOP, do not loop blindly. "Came to rest" ≠ "done".
46
+
47
+ ## Return Contract
48
+
49
+ **Mode:** COMPACT (default). Your final message to the orchestrator is bounded — a one-line verdict + the key points as `path:line` (no reasoning dump, no pasted diff/code). Persist nothing extra; the long form is the script's log + status file already on disk.
50
+ - Success: `MERGED <merge_commit> (<N> code conflicts resolved additively)` + the resolved files as `path:line`.
51
+ - Stop: `STOP: <file>:<hunk> semantic conflict — needs human` + the file(s) + a one-line why.
52
+ - Build fail: `STOP: post-rebase build failed — see <build_log>`.
53
+
54
+ **Do NOT** echo the `sync_marker` / `sync_detail` in your return — the script already wrote them to the status file, and the orchestrator's workspace-hygiene phase reads them from there (they are operational state, not your findings). Mode definitions + the persist-then-summarize rule: `framework/agents/return-contract-protocol.md`.
55
+
56
+ ## Effort
57
+
58
+ **Baseline:** `effort: medium` (frontmatter). Additive-vs-semantic classification is bounded judgment over small hunks — medium is right. Do not over-reason a clearly-additive import union; do spend the reasoning on a borderline hunk, and when still unsure, STOP. Level→behavior mapping + precedence: `framework/agents/effort-protocol.md`.
@@ -41,14 +41,17 @@ here.
41
41
 
42
42
  **BLOCKING pre-work when `features.has_design_system: true`:**
43
43
 
44
- 1. Read `${paths.design_system}/INDEX.md` (component index + Canonical
45
- Authority Matrix).
44
+ 1. Read `${paths.design_system}/INDEX.md` (the thin router). Authority Matrix
45
+ lives in `design-system-protocol.md`, not the INDEX.
46
46
  2. Read `${paths.ui_guidelines}` (visual language, typography, accessibility,
47
47
  brand voice).
48
- 3. Read `${paths.design_system}/tokens-reference.md` (token contract — SSOT
49
- for every color / spacing / shadow / radius / motion value).
50
- 4. For each primitive the task will create, modify, or visually depend on,
51
- read `${paths.design_system}/components/<Name>.md`.
48
+ 3. Read the token SSOT — the DTCG `.tokens.json` at `${paths.design_tokens}`
49
+ (or `tokens-reference.md`, its generated view) for every color / spacing /
50
+ shadow / radius / motion value.
51
+ 4. For each primitive the task will create, modify, or visually depend on, read
52
+ its `components/<Name>.md` — the **frontmatter HEAD** first (props/variants/
53
+ token_bindings/a11y, per `framework/agents/component-manifest-schema.md`);
54
+ the prose body when you need rationale.
52
55
  5. For each pattern in scope, read the relevant
53
56
  `${paths.design_system}/patterns/<topic>.md`.
54
57
 
@@ -347,10 +350,15 @@ project context layer at invocation time:
347
350
  the Post-Intervention Coherence Check defined in
348
351
  [`design-system-protocol.md`](../../agents/design-system-protocol.md)
349
352
  § "Post-Intervention Coherence Check":
350
- (a) every new primitive ships its `components/<Name>.md` spec,
351
- (b) every modified primitive has its spec updated to match,
352
- (c) every new/changed token is reflected in `tokens-reference.md`,
353
- (d) every silently-existing primitive you reused is now in `INDEX.md`.
353
+ (a) every new primitive ships its `components/<Name>.md` spec **with a
354
+ machine-readable frontmatter HEAD** (regenerate the deterministic fields
355
+ from source run the extractor / `baldart tokens build` as needed; fill
356
+ the agentic fields),
357
+ (b) every modified primitive has its spec + HEAD updated to match,
358
+ (c) every new/changed token is made in the DTCG `.tokens.json`
359
+ (`paths.design_tokens`) and outputs regenerated via `baldart tokens build`
360
+ — never hand-edit the generated `tokens.ts`/CSS,
361
+ (d) every silently-existing primitive you reused is now in the `INDEX.md` router.
354
362
  Report findings explicitly (`DS_INDEX_DRIFT` / `DS_COMPONENT_STALE` /
355
363
  `DS_TOKENS_DRIFT`) — never silent. **The design is not complete until
356
364
  this check passes**, regardless of how good it looks visually. Drift
@@ -89,6 +89,13 @@ SEARCH STRATEGY — canonical-router-first, verify-only-if-needed:
89
89
  relational → Graphify when `has_code_graph`); grep is the fallback for textual
90
90
  patterns. Follow those modules' tier order, budgets, and anti-flail rule —
91
91
  don't restate them here.
92
+ a-bis. **UI / component keywords when `has_design_system: true`**: route via the
93
+ design-system layer, NOT source scans — read `${paths.design_system}/INDEX.md`
94
+ (thin router) then the **frontmatter HEAD** of the matched
95
+ `components/<Name>.md` (props/variants/token_bindings; schema
96
+ `framework/agents/component-manifest-schema.md`). Read a spec's prose / the
97
+ source only to verify a runtime-sensitive claim. This is the cheap on-demand
98
+ path that replaces reading a monolithic INDEX or component sources.
92
99
  b. Read key file headers (first 50 lines) to identify structure.
93
100
  DO NOT read `${paths.prd_dir}/` or `${paths.references_dir}/` files in full —
94
101
  route via the registry and read only the specific section you need.