arkgate 4.2.1 → 4.4.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 (63) hide show
  1. package/CHANGELOG.md +85 -3
  2. package/README.md +24 -8
  3. package/bin/ark-check-runtime.mjs +16 -1
  4. package/bin/ark-mcp-runtime.mjs +64 -0
  5. package/bin/ark.mjs +55 -1
  6. package/bin/lib/adapter-contract.mjs +88 -5
  7. package/bin/lib/agent-projection-command.mjs +396 -0
  8. package/bin/lib/agent-projection.mjs +319 -0
  9. package/bin/lib/agent-skills-package.mjs +266 -0
  10. package/bin/lib/baseline-key.mjs +32 -0
  11. package/bin/lib/ci-and-commands.mjs +55 -5
  12. package/bin/lib/diagnostic-catalog.mjs +155 -0
  13. package/bin/lib/doctor-plan.mjs +25 -0
  14. package/bin/lib/html-report-advisories.mjs +33 -0
  15. package/bin/lib/html-report-depth.mjs +24 -0
  16. package/bin/lib/improvement-compass-doctor.mjs +106 -0
  17. package/bin/lib/improvement-compass.mjs +630 -0
  18. package/bin/lib/status-command.mjs +369 -0
  19. package/bin/lib/status-manifest.mjs +431 -0
  20. package/dist/eslint/index.cjs +3 -3
  21. package/dist/eslint/index.js +3 -3
  22. package/dist/index.cjs +46 -11
  23. package/dist/index.d.ts +886 -6
  24. package/dist/index.js +46 -11
  25. package/docs/README.md +9 -8
  26. package/docs/agent-guide.md +128 -14
  27. package/docs/configuration.md +7 -0
  28. package/docs/develop.md +12 -1
  29. package/docs/diagnostics.md +606 -0
  30. package/docs/package-surface.md +44 -31
  31. package/docs/product-voice.md +71 -0
  32. package/docs/use.md +60 -1
  33. package/package.json +7 -1
  34. package/schemas/ark.analysis-result.schema.json +14 -1
  35. package/schemas/ark.status-manifest.schema.json +270 -0
  36. package/server.json +2 -2
  37. package/templates/agent-skills/README.md +59 -0
  38. package/templates/agent-skills/ark-adopt/SKILL.md +191 -0
  39. package/templates/agent-skills/ark-architect/SKILL.md +195 -0
  40. package/templates/agent-skills/ark-autopilot/SKILL.md +262 -0
  41. package/templates/agent-skills/ark-contract/SKILL.md +156 -0
  42. package/templates/agent-skills/ark-coverage/SKILL.md +187 -0
  43. package/templates/agent-skills/ark-explain/SKILL.md +230 -0
  44. package/templates/agent-skills/ark-explore/SKILL.md +397 -0
  45. package/templates/agent-skills/ark-fix/SKILL.md +205 -0
  46. package/templates/agent-skills/ark-loop/SKILL.md +200 -0
  47. package/templates/agent-skills/ark-place/SKILL.md +182 -0
  48. package/templates/agent-skills/ark-runtime/SKILL.md +127 -0
  49. package/templates/agent-skills/ark-think/SKILL.md +153 -0
  50. package/templates/agent-skills/ark-upgrade/SKILL.md +238 -0
  51. package/templates/skills/ark-adopt.md +20 -0
  52. package/templates/skills/ark-architect.md +21 -1
  53. package/templates/skills/ark-autopilot.md +25 -5
  54. package/templates/skills/ark-contract.md +20 -0
  55. package/templates/skills/ark-coverage.md +20 -0
  56. package/templates/skills/ark-explain.md +20 -0
  57. package/templates/skills/ark-explore.md +23 -3
  58. package/templates/skills/ark-fix.md +22 -2
  59. package/templates/skills/ark-loop.md +22 -2
  60. package/templates/skills/ark-place.md +20 -0
  61. package/templates/skills/ark-runtime.md +7 -0
  62. package/templates/skills/ark-think.md +20 -0
  63. package/templates/skills/ark-upgrade.md +20 -0
@@ -0,0 +1,195 @@
1
+ ---
2
+ name: ark-architect
3
+ description: Choose the application shape, adopt phase-1 layers, scaffold directories, and verify honestly — for enthusiasts before codegen. Autonomous.
4
+ ---
5
+
6
+ # /ark-architect — Choose your application shape and adopt Ark
7
+
8
+ ## Improvement compass (process preflight)
9
+
10
+ When doctor is available, read `doctor.improvementCompass` (or the human **Improvement compass** section).
11
+ Name 1–3 **residual** lenses in plain language before skill-shopping. Always `notAScore` — never invent
12
+ 0–10 scores or Excellent/Good ranks.
13
+
14
+ **What the user should feel next:** fewer blocked AI writes, clearer folders, safer domain — then jargon.
15
+
16
+ **Anti false-done:** empty plan A + residual lenses / design-weak → **Incomplete? yes**. Green edges alone
17
+ are not “architecture finished.”
18
+
19
+ **AI-easy architecture:** ports over concrete I/O in domain; one concern per module; golden pattern for
20
+ new files; place before write (`/ark-place` / prepare-write).
21
+
22
+ **Out of scope (honest):** scalability/performance, full app-security tooling (SAST), and full resilience
23
+ patterns are **out-of-scope** lenses — say so; do not invent Ark enforcement for them.
24
+
25
+ **Greenfield that is AI-easy day one:** golden norm + thin layers so the next agent turn stays ordered.
26
+
27
+ ## When / not when
28
+
29
+ | Use `/ark-architect` when… | Do **not** use it when… |
30
+ |----------------------------|-------------------------|
31
+ | Greenfield / thin tree; pick shape + phase-1 layers | Existing spaghetti brownfield → `/ark-adopt` (+ `/ark-explore` first if map missing) |
32
+ | Enthusiast before heavy codegen | Enforcement residual on mature tree → `/ark-autopilot` |
33
+
34
+ The user is building something new or early in Ark adoption. They may not know
35
+ layered architecture jargon. Your job: translate **what they want to build**
36
+ (application shape, not framework name) into an Ark preset, a phase-1 layer plan,
37
+ conventional directories, and a passing honest check — without weakening the gate.
38
+
39
+ Commands below are written as `ark-check` / `ark`; run each through the project's
40
+ package manager (`pnpm exec`, `yarn`, `npx`) — match the lockfile.
41
+
42
+ ## Dual engine (mandatory)
43
+
44
+ | Engine | Role |
45
+ |--------|------|
46
+ | **Deterministic** | CLI / MCP / contract sensors — exit codes, plan kinds, coverage numbers, install status |
47
+ | **Exploratory** | You open **this** repo's real files and product surface before concluding |
48
+
49
+ The CLI is a **sensor**, never the whole job. Claiming done without the exploratory bar for this skill is **incomplete**.
50
+
51
+
52
+
53
+ ## MCP workspace binding (mandatory)
54
+
55
+ Before any `ark_*` MCP tool, call `ark_identity` with `project.expectedRoot` set to the exact
56
+ workspace root. Continue only when `binding.status === "matched"` and `authoritative === true`;
57
+ retain `projectIdentity.projectId`, then pass both `expectedRoot` and `expectedProjectId` under
58
+ `project` on every later MCP call. If identity is missing, mismatched, unverified, or the root is
59
+ uncertain, do not consume MCP analysis: use the workspace-local CLI and report that MCP
60
+ restart/retargeting is required. `ark://manifest` never satisfies this preflight.
61
+
62
+ ## Dual plane — layers + ArkRules (mandatory, except /ark-runtime)
63
+
64
+ ArkGate has **two opt-in planes**. The user chooses which to use; you **always label** findings so they never blur.
65
+
66
+ | Plane | What it protects | Where it lives | Sensors / tools |
67
+ |-------|------------------|----------------|-----------------|
68
+ | **Layers** (inter-layer) | Who may import whom, capabilities, pure/forbiddenGlobals, peerIsolation | `ark.config.json` → `layers[]`, `rules[]` | graph check, baseline edges, doctor coverage % |
69
+ | **ArkRules** (intra-layer) | Structure inside a layer + domain invariants as data | `arkRules` map + `arkrules/<ExactLayerName>.json` | structure sensors, invariant coverage, `--rules-inventory`, doctor `rulesUnderContract` |
70
+
71
+ **Rules for every report / answer:**
72
+ 1. Prefix each finding or next step with **`[Layer]`** or **`[ArkRules]`** (or a two-column table with those headers).
73
+ 2. Never call an import-edge violation an “invariant” or an aggregate sensor a “layer deny.”
74
+ 3. Absence of `arkRules` is **valid** — do not force ArkRules unless the user wants them or residual inventory clearly wants a pilot.
75
+ 4. Editing `arkrules/*` or promoting modes is **`/ark-contract`**; fixing code under a structure sensor is **`/ark-fix`** / **`/ark-loop`** (judgment, never invent mechanical-safe).
76
+ 5. CLI helpers: `ark-check --rules-inventory --json`, doctor JSON `rulesUnderContract`, sensors emit `ARKRULE_*` / `INVARIANT_UNCOVERED` with `evidence.arkruleId`.
77
+
78
+
79
+ ### Architect + ArkRules
80
+ - Preset/init should emit lean `arkRules` + templates for phase-1 layers (exact names).
81
+ - Explain to the user: layers = boundaries; arkrules = habits inside Domain/App/adapters (opt-in, start advisory).
82
+
83
+ ## Subagent fan-out (optional, host-dependent)
84
+
85
+ If the host supports **parallel subagents** and the task splits cleanly (e.g. multiple
86
+ dirs to sample), fan out read-only scouts; otherwise **fall back to sequential**.
87
+ Parent merges and still emits the **### Completion** contract. Never parallel-write
88
+ the same files or weaken the gate.
89
+
90
+ ## Relationship to other skills
91
+
92
+ | Skill | When |
93
+ |-------|------|
94
+ | **/ark-architect** | **Before** — greenfield or fresh config; pick shape + phase 1 |
95
+ | /ark-adopt | **After** — messy existing repo |
96
+ | /ark-contract | **During** — evolve config safely |
97
+ | /ark-place | **During** — one new file |
98
+ | /ark-explain | **After** — understand what exists |
99
+
100
+ ## Steps
101
+
102
+ 1. **Bind and detect the shape** — complete the mandatory `ark_identity` preflight first, then
103
+ call MCP tool **`ark_recommend`** with the bound `project` envelope (or run the workspace-local
104
+ `ark-check --recommend --json`). Never use an unverified recommendation. Read `archetype`, `preset`, `confidence`,
105
+ `adoptInOrder.phase1`, `analogy`, `why`, `evidence`, and `requiresConfirmation`.
106
+ Ask at most **two** questions only if `requiresConfirmation` is true (or for compatibility
107
+ with older ArkGate output, `confidence < 0.5`):
108
+ - "Will this app save data between sessions?"
109
+ - "Is this one app or several in one repository?"
110
+
111
+ 2. **Present in plain English** — name the application shape (e.g. "product with
112
+ UI and stored data"), not the framework. One analogy. List **phase-1 layers only**.
113
+
114
+ 3. **Map to Ark** — if `ark.config.json` is missing, run
115
+ `ark init --archetype <archetype> --yes` (maps playbook id → preset + gates),
116
+ or `ark-check --apply-policy-pack enthusiast-<preset>` for the enthusiast variant.
117
+ Optional team record: `ark-check --recommend --write-plan` → `ark-adoption-plan.json`.
118
+ If a config already exists, use `/ark-contract` to align it — do not regenerate
119
+ unasked. On a messy brownfield tree: **STOP — do not continue this skill as complete.** Invoke **/ark-adopt** instead of forcing greenfield shape.
120
+
121
+ 4. **Scaffold phase 1** — create conventional directories from the preset/playbook
122
+ (`src/domain`, `src/application`, …). Add a one-line README per folder explaining
123
+ what belongs there. Match the nearest sibling file style if code already exists.
124
+ Flat layouts (`src/` + `lib/` + `api/` at the repo root) are common in Vite and
125
+ serverless projects — use `/ark-contract` to map them to layers instead of forcing
126
+ everything under `src/**/domain/**` only.
127
+
128
+ 5. **Install gates** when the user uses AI coding tools and gates are missing:
129
+ `ark-check --install-agent-gates`.
130
+
131
+ 6. **Verify honestly** — run `ark-check --doctor` and `ark-check --coverage --json`.
132
+ Report `governed.percent`. Say explicitly what is **not** governed yet
133
+ (ungoverned directories, empty layers).
134
+
135
+ 7. **Deliver to the user**
136
+ - ASCII diagram (≤3 boxes for phase 1, inner → outer)
137
+ - Table: "when you build X, put it in Y"
138
+ - Three rules the agent must not break (no domain→database imports, no raw
139
+ `publish()`, no weakening `ark.config.json` to pass)
140
+ - Optional book refs from `books` in the recommendation JSON under "go deeper"
141
+ - **Gallery starter** — point the user at the matching clonable example:
142
+
143
+ | Archetype | Example directory |
144
+ |-----------|-------------------|
145
+ | `crud-product` | `examples/crud-product-starter/` |
146
+ | `api-backend` | `examples/api-backend-starter/` |
147
+ | `worker-pipeline` | `examples/worker-pipeline-starter/` |
148
+ | `multi-app-workspace` | `examples/multi-app-workspace-starter/` |
149
+ | `vertical-slice-product` | `examples/vertical-slice-starter/` |
150
+ | `ddd-bounded-contexts` | `examples/ddd-context-starter/` |
151
+
152
+ Say they can copy that folder as a baseline (`npm install && npm run check`).
153
+ For a runnable API with break exercises, mention `examples/hexagonal-order-api/`.
154
+ Full enthusiast track: `docs/enthusiast/README.md`.
155
+
156
+ ## Operating rules
157
+
158
+ - Never weaken `ark.config.json`, the baseline, CI, or agent settings to pass.
159
+ - Never invent layers outside the 11-layer profile or named presets
160
+ (`hexagonal`, `layered`, `feature-sliced`, `monorepo`, `ui-surface`,
161
+ `vertical-slice`, `ddd-bounded-contexts`).
162
+ - Flag unrecognized dirs (`utils/`, `lib/`) — user must classify via `/ark-contract`.
163
+ - Default to smallest viable phase 1; unlock phase 2 only when the user describes need.
164
+ - All user-facing copy is **English**.
165
+
166
+ ## Merge cards (physical cohesion reshape — judgment only)
167
+
168
+ When `doctor.physicalCohesion` reports a mirrored concept and the user asks whether files
169
+ should be **merged**, treat it as domain modeling, never deduplication (field fact: zero
170
+ structural clones among 123 same-concept files). Produce a **merge card** per candidate group:
171
+ which files, the domain concept they express, 2–3 shapes the merged module could take, and what
172
+ each shape costs — **no default action, no auto-merge, never a codemod**. Physical **moves**
173
+ belong to `/ark-loop`'s pilot loop; your job here is the judgment about what the concept IS.
174
+
175
+ ## Verify and report
176
+
177
+ End with `ark-check --root . --config ark.config.json --strict-config` when the
178
+ tree is ready. Report: archetype + preset, directories created, governed %, and
179
+ the next command if anything remains ungoverned.
180
+
181
+ ## Completion contract (skill incomplete if missing)
182
+
183
+ End with **exactly** these headings (markdown `###`):
184
+
185
+ ### Completion
186
+ - **Sensor:** commands/tools run
187
+ - **Opened:** real paths read (or `n/a` only if pure install/upgrade with no source analysis)
188
+ - **Result:** one-line outcome
189
+ - **Planes:** one-line split of residual **[Layer]** vs **[ArkRules]** (or `n/a` if unused)
190
+ - **Compass:** top residual lenses | `n/a`
191
+ - **Handoff:** `/ark-…` / CLI / `none`
192
+ - **Incomplete?** `no` | `yes — <what is missing>`
193
+
194
+ If a **STOP** handoff applies and you continued as if done, set **Incomplete?** to `yes`.
195
+ **Skill incomplete if missing** any of the bullets above.
@@ -0,0 +1,262 @@
1
+ ---
2
+ name: ark-autopilot
3
+ description: Guided end-to-end path for layers and opt-in ArkRules — doctor next action when unsure. Explore first; dual plan A (edges) + B (shape); mechanical-safe only by default; B with user OK, one pilot at a time. Empty plan A is not healthy if design-weak. CLI is a sensor; you read and remediate files.
4
+ ---
5
+
6
+ # /ark-autopilot — Guided end-to-end architecture path
7
+
8
+ **This is the full guided co-pilot** after the compact router. Prefer it when the user wants
9
+ architecture cleaned end-to-end, not when they only need a map (`/ark-explore`) or a single
10
+ edge fix (`/ark-fix`). Doctor remains the control plane: re-check status after each major step.
11
+
12
+ Composes **explore → sensors → dual plan → loop**. Safe default: auto-apply only
13
+ `mechanical-safe`; when the user says full apply / apply everything, also execute **judgment**
14
+ fixes you design from reading source (still validate with ark-check, never weaken the gate).
15
+
16
+ **Not a plan grinder.** Empty `--plan` does **not** mean “architecture is healthy” without
17
+ the explore pass and dual-plan section B (pattern / Shape bets).
18
+
19
+ ## Improvement compass (process preflight)
20
+
21
+ When doctor is available, read `doctor.improvementCompass` (or the human **Improvement compass** section).
22
+ Name 1–3 **residual** lenses in plain language before skill-shopping. Always `notAScore` — never invent
23
+ 0–10 scores or Excellent/Good ranks.
24
+
25
+ **What the user should feel next:** fewer blocked AI writes, clearer folders, safer domain — then jargon.
26
+
27
+ **Anti false-done:** empty plan A + residual lenses / design-weak → **Incomplete? yes**. Green edges alone
28
+ are not “architecture finished.”
29
+
30
+ **AI-easy architecture:** ports over concrete I/O in domain; one concern per module; golden pattern for
31
+ new files; place before write (`/ark-place` / prepare-write).
32
+
33
+ **Out of scope (honest):** scalability/performance, full app-security tooling (SAST), and full resilience
34
+ patterns are **out-of-scope** lenses — say so; do not invent Ark enforcement for them.
35
+
36
+ **Guided vibe path:** phase 0 = doctor + compass residual. Shape only with user OK. Never script “done” while residual lenses remain.
37
+
38
+ ## When / not when
39
+
40
+ | Use `/ark-autopilot` when… | Do **not** use it when… |
41
+ |----------------------------|-------------------------|
42
+ | “Make architecture sound” end-to-end | Map only, no apply → `/ark-explore` |
43
+ | Brownfield or greenfield with apply | Only fitness numbers → `/ark-coverage` |
44
+ | User wants A + B planned and A executed | Single edge fix → `/ark-fix`; plan A only → `/ark-loop` |
45
+ | **Apply half of post-green Shape path** (after explore map / when user wants full apply) | Skipping explore when doctor primary is Shape map-first |
46
+ | Spaghetti under ENFORCE: Shape work with user ok on B | Contract false-green first → `/ark-adopt` / `/ark-contract` STOP paths |
47
+
48
+ **Post-green door:** doctor’s single door is `/ark-explore` shape-focus → dual-plan B, **then** this skill only
49
+ to apply B with OK. Prefer that order when `postGreenPath` / design-weak is the primary residual.
50
+
51
+ ## Related onboarding
52
+
53
+ - **Greenfield:** `/ark-architect` or `ark-check --recommend` / `ark start`.
54
+ - **Brownfield:** `/ark-adopt` — match contract to reality; do not force a starter preset.
55
+ - **Deep map only:** `/ark-explore` — full recon / dual-plan seed without applying.
56
+ - **Adoption fitness only:** `/ark-coverage` — governed% + capability gaps (not pattern dual-plan).
57
+ - **Default path:** `ark start` → `ark-check --doctor` → **`/ark-autopilot`** (this skill) for guided work.
58
+
59
+ ## Dual engine (mandatory)
60
+
61
+ | Engine | Role |
62
+ |--------|------|
63
+ | **Deterministic** | `ark-check` plan/coverage/doctor, mechanical-safe kinds, write/CI gates, exit codes, origin snapshot |
64
+ | **Exploratory** | You map **this** product’s real tree: entry points, coupling, false greens, field path, pattern debt |
65
+
66
+ **Forbidden:** only printing `--plan` JSON or “4 safe / 4 judgment — approve?” without a
67
+ decision-grade explore pass **and** without opening violating files.
68
+
69
+ **Required:**
70
+ 1. **Explore pass** (below) **before** claiming a loop strategy — same bar as `/ark-explore`, budgeted.
71
+ 2. CLI sensors: `--plan --json`, `--coverage --json` / `--doctor` as needed.
72
+ 3. **Dual plan** always emitted (sections A and B).
73
+ 4. **Open every file** in plan A `steps[]` (and `target` if present) before classifying a fix.
74
+ 5. **“Así te lo re-soluciono”** for each A cluster and each B pattern bet.
75
+ 6. Apply A → re-run ark-check → rollback on regression. **Never auto-apply B** as mechanical-safe.
76
+ 7. **One-pilot loop for B:** when design-weak, take **`pilotLoop.nextPilot`** (one extraction card)
77
+ → apply **only** that pilot with user OK → **re-doctor**. Never multi-pilot batch B; residual
78
+ outside the pilot may remain and must not be called “healthy finished.”
79
+ 8. **Reshape decision memory:** read `doctor.physicalCohesion.reshapeDecisions` before acting on
80
+ mirror facts. Outcome first: a current rejected/deferred verdict means “intentional/deferred
81
+ layout — no pilot”; never reconstruct that dead card from `findings`. When the user accepts,
82
+ defers, or rejects a live card, persist its exact `decisionTarget` with a non-empty reason and
83
+ optional `reviewBy` in `.ark/reshape-decisions.json`; never infer a verdict from golden prose.
84
+
85
+
86
+
87
+ ## MCP workspace binding (mandatory)
88
+
89
+ Before any `ark_*` MCP tool, call `ark_identity` with `project.expectedRoot` set to the exact
90
+ workspace root. Continue only when `binding.status === "matched"` and `authoritative === true`;
91
+ retain `projectIdentity.projectId`, then pass both `expectedRoot` and `expectedProjectId` under
92
+ `project` on every later MCP call. If identity is missing, mismatched, unverified, or the root is
93
+ uncertain, do not consume MCP analysis: use the workspace-local CLI and report that MCP
94
+ restart/retargeting is required. `ark://manifest` never satisfies this preflight.
95
+
96
+ ## Dual plane — layers + ArkRules (mandatory, except /ark-runtime)
97
+
98
+ ArkGate has **two opt-in planes**. The user chooses which to use; you **always label** findings so they never blur.
99
+
100
+ | Plane | What it protects | Where it lives | Sensors / tools |
101
+ |-------|------------------|----------------|-----------------|
102
+ | **Layers** (inter-layer) | Who may import whom, capabilities, pure/forbiddenGlobals, peerIsolation | `ark.config.json` → `layers[]`, `rules[]` | graph check, baseline edges, doctor coverage % |
103
+ | **ArkRules** (intra-layer) | Structure inside a layer + domain invariants as data | `arkRules` map + `arkrules/<ExactLayerName>.json` | structure sensors, invariant coverage, `--rules-inventory`, doctor `rulesUnderContract` |
104
+
105
+ **Rules for every report / answer:**
106
+ 1. Prefix each finding or next step with **`[Layer]`** or **`[ArkRules]`** (or a two-column table with those headers).
107
+ 2. Never call an import-edge violation an “invariant” or an aggregate sensor a “layer deny.”
108
+ 3. Absence of `arkRules` is **valid** — do not force ArkRules unless the user wants them or residual inventory clearly wants a pilot.
109
+ 4. Editing `arkrules/*` or promoting modes is **`/ark-contract`**; fixing code under a structure sensor is **`/ark-fix`** / **`/ark-loop`** (judgment, never invent mechanical-safe).
110
+ 5. CLI helpers: `ark-check --rules-inventory --json`, doctor JSON `rulesUnderContract`, sensors emit `ARKRULE_*` / `INVARIANT_UNCOVERED` with `evidence.arkruleId`.
111
+
112
+
113
+ ### Autopilot + ArkRules
114
+ - After explore/doctor: if inventory has high-confidence candidates **or** user wants domain rules, include **[ArkRules] plan A/B**:
115
+ - A: mechanical-safe remains inter-layer only; structure/invariant fixes are **judgment**.
116
+ - B: one pilot = one rule (declare in `arkrules/<Layer>.json` → implement → test title/symbol → re-doctor).
117
+ - Never promote advisory→enforced without coverage evidence (`canPromoteInvariant` / policy-delta).
118
+ - End report must list what was **layer-edge** work vs **intra-layer rule** work.
119
+
120
+ ## Subagent fan-out (optional, host-dependent)
121
+
122
+ When the user asks to go faster **or** the work naturally splits (multiple packages,
123
+ feature dirs, plan clusters), you **may** dispatch **subagents**:
124
+
125
+ | Host capability | Behavior |
126
+ |-----------------|----------|
127
+ | **Parallel subagents supported** (e.g. multi-agent / `spawn_subagent` / concurrent Agent tools) | Launch **2–N** agents in **one wave** with **disjoint path scopes**. Prefer **read-only** explore agents for mapping; at most **one writer** unless the host gives isolated worktrees. Parent merges findings, then runs `ark-check` once. |
128
+ | **Not supported** (single agent only) | **Fall back to sequential** — same checklist, one cluster/step at a time. Never claim parallel work you did not run. |
129
+
130
+ **Rules:**
131
+ 1. Give each subagent a **tight brief**: paths in scope, sensor commands allowed, deliverable shape (paths opened + findings JSON or bullets).
132
+ 2. **No shared mutable files** across parallel writers.
133
+ 3. STOP handoffs and dual-engine rules still apply in every agent.
134
+ 4. Parent owns the **### Completion** block (union of **Opened**, single **Handoff**).
135
+ 5. Do **not** use subagents to weaken the gate or invent `mechanical-safe` kinds.
136
+
137
+ Useful first wave: **core product tree** | **field path** (examples/starters) | **agent install surfaces** (hooks vs templates).
138
+
139
+ ## Explore pass (phase 0 — mandatory, first)
140
+
141
+ Do this **before** grinding plan A — plan lists *violations*, not *product reality*.
142
+ Use the **`/ark-explore` decision-grade bar** (compressed into the autopilot report, not optional fluff).
143
+ Include explore **§G** when spaghetti / design-weak signals fire.
144
+
145
+ 1. **Headline** — product one-liner + honesty (mode, governed%, false-green / false-promise /
146
+ **ENFORCE·design-weak** risk).
147
+ 2. **Map** — entry points, lived layout vs globs (one screen). **Concurrent patterns** table when ≥2 styles.
148
+ 3. **Phase ladder** — name **Align | Stabilize | Shape** (explore §G).
149
+ 4. **Field path** — if `examples/` / gallery / starter docs exist: open ≥2, **run** their check when cheap; flag soft-green or broken demos. Else `Field path: n/a` + internal norm.
150
+ 5. **Agent/gate reality** — installed hooks vs install templates (e.g. `--hook` vs `--hook-repair`); MCP; CI gate present.
151
+ 6. **Coupling** — fan-in / exports / importers for hotspots (LOC alone is a hint).
152
+ 7. **False-green soft block** — doctor/coverage: empty Domain/Persistence while Application owns I/O (`airtable`, `supabase`, `prisma`, `drizzle`, `repositories`, …). Doctor gap id: `contract-false-green-io-under-application`. If so:
153
+ **STOP — do not continue this skill as complete.** **STOP — false-green: invoke /ark-adopt or /ark-contract before claiming ENFORCE.** Do not claim goal.met / ENFORCE from type-only cleanup while doctor reports `contract-false-green-io-under-application`.
154
+ 8. **Seed dual plan B** — 2–5 pattern / Shape bets ranked (impact × effort × enforceability). Each B row needs pilot + success signal; I/O bets need an **extraction card** (explore §G).
155
+
156
+ Min bar: **≥12 source files** across **≥4 meaningful directories** (not only files in `steps[]`).
157
+ Standalone long report: `/ark-explore`. Adoption fitness only: `/ark-coverage`.
158
+
159
+ ## Dual plan (always emit)
160
+
161
+ | Section | Source | Question | Auto-apply? |
162
+ |---------|--------|----------|-------------|
163
+ | **A. Remediation** | `--plan --json` + opened step files | What must change so the **gate** is honest? | Only `mechanical-safe` by default |
164
+ | **B. Pattern / Shape** | Explore §B/§G (not coverage alone) | What **design** must improve even if A is empty? | **Never** as mechanical-safe |
165
+
166
+ **Section A** — group by edge; treat `peerIsolation` / cross-slice as **judgment**.
167
+ **Section B** examples: choose golden pattern + pilot migrate-on-touch, peerIsolation, move rules out of UI, write-path repair, split god modules, Domain placement / intents, facade SQL → port/adapter (extraction card). Cap **3–5** B rows. Each row: evidence path + **así te lo re-soluciono** + next skill/command + **success signal** + **pilot** (+ kill-switch if new layer).
168
+
169
+ B does **not** count as “architecture healthy finished.” Report B as `proposed | deferred | applied-with-user-ok`.
170
+ When A is empty and B is non-empty: status is **`goal.met on edges · Shape residual open`** — never “done” without listing B.
171
+ Prefer CLI `patternBets[]` / `designSmells[]` when present; apply B only with explicit user ok using
172
+ **extraction cards** (`docs/brownfield-adoption.md` §6) — never mechanical-safe, never silent.
173
+ If B will take multiple PRs, offer (do not require) persisting a short Shape plan under the
174
+ repo so the next agent session continues the same pilot — still never auto-apply B.
175
+
176
+ ## Origin snapshot (day-zero picture)
177
+
178
+ - **When:** as soon as `ark.config.json` exists and `.ark/reports/origin.json` is missing — **before** applying fixes and **before** treating “done”. Prefer that `ark start` / `ark init` already froze origin **before** agent docs; if missing, freeze now.
179
+ - **How:** `ark-check --report ark-report.html` (writes origin once under `.ark/reports/`).
180
+ - **Never** `--reset-origin` unless the user explicitly wants a new baseline.
181
+ - **Do not** wait until the end of the loop to create origin the first time — later reports need a frozen “before” picture.
182
+ - End of run: re-`--report` for **latest** + evolution vs origin (origin stays frozen).
183
+
184
+ ## Operating modes (detected, not picked)
185
+
186
+ Status lights from doctor — not settings you choose. Rank residual honestly:
187
+
188
+ | Light | Means | Your move (this skill) |
189
+ |-------|--------|------------------------|
190
+ | **Suggest** | Thin/new tree; contract not control plane | Finish `ark start` → re-doctor; do not skill-shop |
191
+ | **Adapt** | Contract/tree disagree or debt open | Explore + adopt/loop/contract; do not claim guarded |
192
+ | **Enforce** | Honest coverage + clean checked **edges** | Confirm gates + CI; emit dual-plan B only if residual found |
193
+ | **Enforce · design-weak** | Edges clean; design smells remain | **Primary Shape door:** explore shape-focus → dual-plan **B** → apply **one** pilot with user OK. Empty plan A ≠ done. Never mechanical-safe B. False-done forbidden. |
194
+
195
+ - **Setup (Suggest):** no config → `ark start` (start freezes origin after config, before gates).
196
+ - **Align (Adapt):** open debt, low honesty, or false-green → explore + adopt/loop; do not claim “guarded”.
197
+ - **Guard (Enforce):** `goal.met`, solid governed%, no false-green → confirm gates; still emit dual plan B if explore found residual.
198
+ - **Guard · design-weak:** same as Enforce on edges, **plus** mandatory dual-plan B / pilot card; Incomplete? must not claim healthy finished while residual remains.
199
+
200
+ ## Flow
201
+
202
+ 0. **Explore pass** — decision-grade recon (see above); seed plan B.
203
+ 1. **Setup if needed** — `ark start` if no `ark.config.json`. Trust `--recommend` / playbook:
204
+ `vertical-slice-product` and `ddd-bounded-contexts` are first-class shapes (not hexagonal by default).
205
+ 2. **Origin if missing** — freeze day-zero (`--report`) immediately after contract exists.
206
+ 3. **Sensors** — `--plan --json`, doctor/coverage as needed.
207
+ 4. **Emit dual plan** — A from plan steps (files opened); B from explore (3–5 bets).
208
+ 5. **Concentrated edge?** — if one edge dominates A:
209
+ **STOP — do not continue this skill as complete.** **STOP — concentrated edge: invoke /ark-contract with source evidence** (do not freeze a wrong contract or grind N freezes).
210
+ 6. **Worktree preferred** — discardable git worktree when possible.
211
+ 7. **Mechanical-safe (A only)** — kinds from `/ark-loop` table; one step, validate, rollback.
212
+ 8. **Judgment (A)** — default: propose with full “así te lo re-soluciono”. If user authorized full apply: implement, validate, rollback on fail.
213
+ 9. **Pattern bets (B)** — propose; apply only with explicit user go + correct skill (`/ark-contract`, refactor, install gates, etc.). Never weaken the gate to clear B.
214
+ 10. **Manifiesto** — loose business rules → Domain placement + `intentPrefixes` / intents via `/ark-contract` discipline.
215
+ 11. **Final report** — re-`--report`; evolution vs origin; A applied vs open; B proposed/deferred; gates on.
216
+ 12. **Strict check** — `ark-check --strict-config` (dead preset globs are advisory; real violations still fail).
217
+ 13. **Core ratchet (when green)** — if plan `goal.met` and doctor still **ADAPT** only because
218
+ populated cores are `optional: true`, run `ark-check --ratchet-cores` then `--doctor`.
219
+ Never ratchet while active violations remain or false-green gap is open.
220
+
221
+ ## Mechanical-edit hygiene (outcome gate)
222
+
223
+ - Header injection must **merge into the existing doc comment**; the kept result has one `/**`, not stacked headers.
224
+ - Route completion or movement must **preserve the original typed `defineRoute<…>(opts, handler)` call**; reconstruct that call instead of extracting untyped opts/handler constants that drop generics or contextual typing.
225
+ - A convention-only `*-data.ts` stub is not a fix: move the real code or **leave the placeholder file uncreated**; never write `import "server-only"; export {}` as an empty naming token.
226
+ - Keep the edit only when the **previously clean file stays typecheck-clean**. Otherwise roll it back and treat the change as judgment.
227
+
228
+ ## Never
229
+
230
+ - Disable rules, broaden allows, or baseline **new** debt to “finish”.
231
+ - Claim clean while judgment A steps were skipped without user decision.
232
+ - Claim ENFORCE / “done” when doctor reports `contract-false-green-io-under-application` (adopt first).
233
+ - Claim “done” solely because plan A is empty while explore/B residual remains unlisted.
234
+ - Replace host Nest/DI with the runtime kernel unasked.
235
+ - Auto-apply pattern (B) bets as if they were mechanical-safe.
236
+ - Create origin only after a long cleanup (freezes a polished “before” that never was).
237
+
238
+ ## Done criteria
239
+
240
+ - Explore pass completed (decision-grade map + paths + field path or n/a + phase + B seeds).
241
+ - Dual plan emitted (A and/or B; if both empty, one-line justification with evidence no design-weak smells).
242
+ - Origin present under `.ark/reports/origin.*` (frozen this run or earlier).
243
+ - Every applied A step validated by real `ark-check`.
244
+ - Final plan `goal.met` true **or** remaining A steps listed with file-level proposals.
245
+ - Open **B / Shape opportunities** listed with success signals; report HTML paths cited when used.
246
+ - If A empty and design-weak present: B listed — **Incomplete?** must not claim full healthy stop.
247
+
248
+ ## Completion contract (skill incomplete if missing)
249
+
250
+ End with **exactly** these headings (markdown `###`):
251
+
252
+ ### Completion
253
+ - **Sensor:** commands/tools run
254
+ - **Opened:** real paths read (or `n/a` only if pure install/upgrade with no source analysis)
255
+ - **Result:** one-line outcome
256
+ - **Planes:** one-line split of residual **[Layer]** vs **[ArkRules]** (or `n/a` if unused)
257
+ - **Compass:** top residual lenses | `n/a`
258
+ - **Handoff:** `/ark-…` / CLI / `none`
259
+ - **Incomplete?** `no` | `yes — <what is missing>`
260
+
261
+ If a **STOP** handoff applies and you continued as if done, set **Incomplete?** to `yes`.
262
+ **Skill incomplete if missing** any of the bullets above.
@@ -0,0 +1,156 @@
1
+ ---
2
+ name: ark-contract
3
+ description: Safely edit ark.config.json layers/rules and arkrules/* (structure + invariants); land business rules under the dual plane. Validated with strict ark-check. Deep source evidence required.
4
+ ---
5
+
6
+ # /ark-contract — Change the architecture contract (safely)
7
+
8
+ ## Improvement compass (process preflight)
9
+
10
+ When doctor is available, read `doctor.improvementCompass` (or the human **Improvement compass** section).
11
+ Name 1–3 **residual** lenses in plain language before skill-shopping. Always `notAScore` — never invent
12
+ 0–10 scores or Excellent/Good ranks.
13
+
14
+ **What the user should feel next:** fewer blocked AI writes, clearer folders, safer domain — then jargon.
15
+
16
+ **Anti false-done:** empty plan A + residual lenses / design-weak → **Incomplete? yes**. Green edges alone
17
+ are not “architecture finished.”
18
+
19
+ **AI-easy architecture:** ports over concrete I/O in domain; one concern per module; golden pattern for
20
+ new files; place before write (`/ark-place` / prepare-write).
21
+
22
+ **Out of scope (honest):** scalability/performance, full app-security tooling (SAST), and full resilience
23
+ patterns are **out-of-scope** lenses — say so; do not invent Ark enforcement for them.
24
+
25
+ **Contract edits are last resort.** Policy-delta honesty; do not weaken rules to clear compass residual.
26
+
27
+ ## When / not when
28
+
29
+ | Use `/ark-contract` when… | Do **not** use it when… |
30
+ |---------------------------|-------------------------|
31
+ | Edit layers/rules/includes/intents with source evidence | Move product code without config change → `/ark-fix` / `/ark-loop` |
32
+ | Concentrated-edge / false-green STOP from other skills | Full map without config edit → `/ark-explore` |
33
+
34
+ The **one sanctioned way** to change layers/rules/`intentPrefixes`/includes.
35
+ Also used to **land mined business rules** into the executable manifest (`ark.config.json` +
36
+ intent naming that the project-bound `ark_manifest` tool exposes authoritatively).
37
+
38
+
39
+ ## Dual engine (mandatory)
40
+
41
+ | Engine | Role |
42
+ |--------|------|
43
+ | **Deterministic** | CLI / MCP / contract sensors — exit codes, plan kinds, coverage numbers, install status |
44
+ | **Exploratory** | You open **this** repo's real files and product surface before concluding |
45
+
46
+ The CLI is a **sensor**, never the whole job. Claiming done without the exploratory bar for this skill is **incomplete**.
47
+
48
+
49
+
50
+ ## MCP workspace binding (mandatory)
51
+
52
+ Before any `ark_*` MCP tool, call `ark_identity` with `project.expectedRoot` set to the exact
53
+ workspace root. Continue only when `binding.status === "matched"` and `authoritative === true`;
54
+ retain `projectIdentity.projectId`, then pass both `expectedRoot` and `expectedProjectId` under
55
+ `project` on every later MCP call. If identity is missing, mismatched, unverified, or the root is
56
+ uncertain, do not consume MCP analysis: use the workspace-local CLI and report that MCP
57
+ restart/retargeting is required. `ark://manifest` never satisfies this preflight.
58
+
59
+ ## Dual plane — layers + ArkRules (mandatory, except /ark-runtime)
60
+
61
+ ArkGate has **two opt-in planes**. The user chooses which to use; you **always label** findings so they never blur.
62
+
63
+ | Plane | What it protects | Where it lives | Sensors / tools |
64
+ |-------|------------------|----------------|-----------------|
65
+ | **Layers** (inter-layer) | Who may import whom, capabilities, pure/forbiddenGlobals, peerIsolation | `ark.config.json` → `layers[]`, `rules[]` | graph check, baseline edges, doctor coverage % |
66
+ | **ArkRules** (intra-layer) | Structure inside a layer + domain invariants as data | `arkRules` map + `arkrules/<ExactLayerName>.json` | structure sensors, invariant coverage, `--rules-inventory`, doctor `rulesUnderContract` |
67
+
68
+ **Rules for every report / answer:**
69
+ 1. Prefix each finding or next step with **`[Layer]`** or **`[ArkRules]`** (or a two-column table with those headers).
70
+ 2. Never call an import-edge violation an “invariant” or an aggregate sensor a “layer deny.”
71
+ 3. Absence of `arkRules` is **valid** — do not force ArkRules unless the user wants them or residual inventory clearly wants a pilot.
72
+ 4. Editing `arkrules/*` or promoting modes is **`/ark-contract`**; fixing code under a structure sensor is **`/ark-fix`** / **`/ark-loop`** (judgment, never invent mechanical-safe).
73
+ 5. CLI helpers: `ark-check --rules-inventory --json`, doctor JSON `rulesUnderContract`, sensors emit `ARKRULE_*` / `INVARIANT_UNCOVERED` with `evidence.arkruleId`.
74
+
75
+
76
+ ### Contract + ArkRules
77
+ - You own **both** `layers/rules` and `arkRules`/`arkrules/*.json`.
78
+ - Report diffs in two blocks: **[Layer] config** and **[ArkRules] files**.
79
+ - Promotion ladder: advisory→enforced only with coverage; demote = hash-ack weakening.
80
+
81
+ ## Subagent fan-out (optional, host-dependent)
82
+
83
+ If the host supports **parallel subagents** and the task splits cleanly (e.g. multiple
84
+ dirs to sample), fan out read-only scouts; otherwise **fall back to sequential**.
85
+ Parent merges and still emits the **### Completion** contract. Never parallel-write
86
+ the same files or weaken the gate.
87
+
88
+ ## Related onboarding
89
+
90
+ - **Greenfield:** `/ark-architect` or `ark-check --recommend` / `ark start`.
91
+ - **Brownfield:** `/ark-adopt` — match contract to reality; do not force a starter preset.
92
+ - **Default path:** `ark start` → `/ark-autopilot` → `ark-check --doctor`.
93
+
94
+ ## Anti-wrapper rule (mandatory)
95
+
96
+ **Forbidden:** editing globs from vibes without reading the directories those globs claim to cover.
97
+
98
+ **Required:**
99
+ 1. Snapshot before using CLI as **sensor**: coverage + check JSON.
100
+ 2. **Read source** in dirs you reclassify (sample files).
101
+ 3. **“Así te lo re-soluciono”** — exact JSON fields + which files become governed/ungoverned.
102
+ 4. After write: `ark-check --strict-config` must be the validation gate (dead pattern noise is advisory; unclassified + real violations still matter).
103
+
104
+ ## What you may edit
105
+
106
+ - `include` / `exclude`
107
+ - `layers[]` (`name`, `patterns`, `optional`, `forbiddenGlobals`, `intentPrefixes`, layer `exclude`)
108
+ - `rules[]` (from/to/allowed)
109
+ - **`arkRules` map + `arkrules/<Layer>.json`** (ADR 0012/0014) — structure sensors + invariant catalog;
110
+ promote advisory→enforced only with coverage evidence; demote/delete requires hash-bound policy ack
111
+ - Never: disable the check, delete CI gates, or add blanket `allowed: true` for a bad edge without a facade design
112
+
113
+ ## Steps
114
+
115
+ 1. **Snapshot** — coverage governed%, unclassified samples, current violations.
116
+ 2. **Smallest edit** for the user intent:
117
+ - New layer + neighbor rules
118
+ - Expand patterns for ungoverned dirs (`suggestions` from coverage)
119
+ - Facade: public surface patterns more specific than internals
120
+ - **Business rules → manifiesto:**
121
+ - Add/adjust `intentPrefixes` (`Domain.`, `Application.`, …)
122
+ - Point Domain patterns at real pure folders (`**/domain/**`, not bare `**/types.ts`)
123
+ - Document proposed intent names for the app to register (kernel) or for agents to use
124
+ 3. **Impact** — re-run coverage/check; report before/after governed% and violation delta.
125
+ 4. **Rollback** if strict fails for reasons other than pre-existing debt the user accepted.
126
+
127
+ ## Operating modes
128
+
129
+ Contract edits are most common in **Align (Adapt)**. In **Guard (Enforce)**, treat edits as high-risk product decisions.
130
+
131
+ ## Critical handoffs
132
+
133
+ - After contract is honest but residual violations remain: **STOP — do not continue this skill as complete.** **STOP — bulk residual debt: invoke /ark-loop or /ark-autopilot** instead of ad-hoc multi-file grinding without a plan.
134
+ - New artifact home after reclassify: **STOP — do not continue this skill as complete.** **STOP — new file placement: invoke /ark-place** when the user needs a new artifact home.
135
+
136
+ ## Done
137
+
138
+ - Diff of `ark.config.json` explained in plain language.
139
+ - **Así te lo re-soluciono en el manifiesto** when intents/Domain were part of the request.
140
+ - Strict check result captured.
141
+
142
+ ## Completion contract (skill incomplete if missing)
143
+
144
+ End with **exactly** these headings (markdown `###`):
145
+
146
+ ### Completion
147
+ - **Sensor:** commands/tools run
148
+ - **Opened:** real paths read (or `n/a` only if pure install/upgrade with no source analysis)
149
+ - **Result:** one-line outcome
150
+ - **Planes:** one-line split of residual **[Layer]** vs **[ArkRules]** (or `n/a` if unused)
151
+ - **Compass:** top residual lenses | `n/a`
152
+ - **Handoff:** `/ark-…` / CLI / `none`
153
+ - **Incomplete?** `no` | `yes — <what is missing>`
154
+
155
+ If a **STOP** handoff applies and you continued as if done, set **Incomplete?** to `yes`.
156
+ **Skill incomplete if missing** any of the bullets above.