arkgate 4.2.0 → 4.3.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 (46) hide show
  1. package/CHANGELOG.md +86 -4
  2. package/README.md +20 -6
  3. package/bin/ark-mcp-runtime.mjs +64 -0
  4. package/bin/ark-shared.mjs +16 -4
  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 +44 -0
  12. package/bin/lib/diagnostic-catalog.mjs +155 -0
  13. package/bin/lib/physical-cohesion.mjs +2 -1
  14. package/bin/lib/status-command.mjs +369 -0
  15. package/bin/lib/status-manifest.mjs +394 -0
  16. package/dist/eslint/index.cjs +3 -3
  17. package/dist/eslint/index.js +3 -3
  18. package/dist/index.cjs +46 -11
  19. package/dist/index.d.ts +729 -6
  20. package/dist/index.js +46 -11
  21. package/docs/README.md +6 -6
  22. package/docs/agent-guide.md +112 -14
  23. package/docs/configuration.md +7 -0
  24. package/docs/develop.md +8 -0
  25. package/docs/diagnostics.md +606 -0
  26. package/docs/package-surface.md +19 -8
  27. package/docs/product-voice.md +45 -0
  28. package/docs/use.md +23 -0
  29. package/package.json +11 -1
  30. package/schemas/ark.analysis-result.schema.json +14 -1
  31. package/schemas/ark.status-manifest.schema.json +244 -0
  32. package/server.json +2 -2
  33. package/templates/agent-skills/README.md +59 -0
  34. package/templates/agent-skills/ark-adopt/SKILL.md +171 -0
  35. package/templates/agent-skills/ark-architect/SKILL.md +175 -0
  36. package/templates/agent-skills/ark-autopilot/SKILL.md +242 -0
  37. package/templates/agent-skills/ark-contract/SKILL.md +136 -0
  38. package/templates/agent-skills/ark-coverage/SKILL.md +167 -0
  39. package/templates/agent-skills/ark-explain/SKILL.md +210 -0
  40. package/templates/agent-skills/ark-explore/SKILL.md +377 -0
  41. package/templates/agent-skills/ark-fix/SKILL.md +185 -0
  42. package/templates/agent-skills/ark-loop/SKILL.md +180 -0
  43. package/templates/agent-skills/ark-place/SKILL.md +162 -0
  44. package/templates/agent-skills/ark-runtime/SKILL.md +120 -0
  45. package/templates/agent-skills/ark-think/SKILL.md +133 -0
  46. package/templates/agent-skills/ark-upgrade/SKILL.md +218 -0
@@ -0,0 +1,171 @@
1
+ ---
2
+ name: ark-adopt
3
+ description: Brownfield onboarding — match contract to real product code, classify ungoverned dirs, mine business rules, freeze only real debt, seed Shape dual-plan B for spaghetti residual. Deep source analysis required.
4
+ ---
5
+
6
+ # /ark-adopt — Bring Ark into an existing codebase
7
+
8
+ Goal: contract reflects **product reality**, most code governed, only genuine debt frozen
9
+ with a burn-down. A green check over a wrong contract is a **false green**.
10
+
11
+ **Adopt is Align + Stabilize, then seed Shape.** Freezing debt without a pattern plan leaves
12
+ spaghetti “ENFORCE · design-weak”. Always end with dual-plan **B** seeds (or handoff explore)
13
+ when design smells remain after the contract is honest.
14
+
15
+ ## When / not when
16
+
17
+ | Use `/ark-adopt` when… | Do **not** use it when… |
18
+ |------------------------|-------------------------|
19
+ | Existing messy repo; contract ≠ folders | Empty greenfield shape → `/ark-architect` |
20
+ | False-green / concentrated edge needs contract truth | Map-only without writing config/baseline → `/ark-explore` |
21
+ | Mine loose business rules into Domain / intents | Single violation fix → `/ark-fix` |
22
+ | Freeze **real** debt after contract is honest | Grind plan A only → `/ark-loop`; full apply loop → `/ark-autopilot` |
23
+
24
+ ## Dual engine (mandatory)
25
+
26
+ | Engine | Role |
27
+ |--------|------|
28
+ | **Deterministic** | coverage, doctor, baseline, strict-config after edits |
29
+ | **Exploratory** | walk the real monorepo/app layout; reclassify; mine rules; suggest shape |
30
+
31
+
32
+
33
+ ## MCP workspace binding (mandatory)
34
+
35
+ Before any `ark_*` MCP tool, call `ark_identity` with `project.expectedRoot` set to the exact
36
+ workspace root. Continue only when `binding.status === "matched"` and `authoritative === true`;
37
+ retain `projectIdentity.projectId`, then pass both `expectedRoot` and `expectedProjectId` under
38
+ `project` on every later MCP call. If identity is missing, mismatched, unverified, or the root is
39
+ uncertain, do not consume MCP analysis: use the workspace-local CLI and report that MCP
40
+ restart/retargeting is required. `ark://manifest` never satisfies this preflight.
41
+
42
+ ## Dual plane — layers + ArkRules (mandatory, except /ark-runtime)
43
+
44
+ ArkGate has **two opt-in planes**. The user chooses which to use; you **always label** findings so they never blur.
45
+
46
+ | Plane | What it protects | Where it lives | Sensors / tools |
47
+ |-------|------------------|----------------|-----------------|
48
+ | **Layers** (inter-layer) | Who may import whom, capabilities, pure/forbiddenGlobals, peerIsolation | `ark.config.json` → `layers[]`, `rules[]` | graph check, baseline edges, doctor coverage % |
49
+ | **ArkRules** (intra-layer) | Structure inside a layer + domain invariants as data | `arkRules` map + `arkrules/<ExactLayerName>.json` | structure sensors, invariant coverage, `--rules-inventory`, doctor `rulesUnderContract` |
50
+
51
+ **Rules for every report / answer:**
52
+ 1. Prefix each finding or next step with **`[Layer]`** or **`[ArkRules]`** (or a two-column table with those headers).
53
+ 2. Never call an import-edge violation an “invariant” or an aggregate sensor a “layer deny.”
54
+ 3. Absence of `arkRules` is **valid** — do not force ArkRules unless the user wants them or residual inventory clearly wants a pilot.
55
+ 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).
56
+ 5. CLI helpers: `ark-check --rules-inventory --json`, doctor JSON `rulesUnderContract`, sensors emit `ARKRULE_*` / `INVARIANT_UNCOVERED` with `evidence.arkruleId`.
57
+
58
+
59
+ ### Adopt + ArkRules
60
+ - After classify: emit or refresh `arkRules` for matched layers (exact names; generic mold for unknowns).
61
+ - Mine rules → inventory + propose invariants/structure; land via `/ark-contract`.
62
+ - Freeze baseline is **[Layer]** debt; inventory residual is **[ArkRules]** — report both.
63
+
64
+ ## Subagent fan-out (optional, host-dependent)
65
+
66
+ When the user asks to go faster **or** the work naturally splits (multiple packages,
67
+ feature dirs, plan clusters), you **may** dispatch **subagents**:
68
+
69
+ | Host capability | Behavior |
70
+ |-----------------|----------|
71
+ | **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. |
72
+ | **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. |
73
+
74
+ **Rules:**
75
+ 1. Give each subagent a **tight brief**: paths in scope, sensor commands allowed, deliverable shape (paths opened + findings JSON or bullets).
76
+ 2. **No shared mutable files** across parallel writers.
77
+ 3. STOP handoffs and dual-engine rules still apply in every agent.
78
+ 4. Parent owns the **### Completion** block (union of **Opened**, single **Handoff**).
79
+ 5. Do **not** use subagents to weaken the gate or invent `mechanical-safe` kinds.
80
+
81
+ ## Related onboarding
82
+
83
+ - **Greenfield:** `/ark-architect` or `ark-check --recommend` / `ark start`.
84
+ - **Brownfield:** `/ark-adopt` — match contract to reality; do not force a starter preset.
85
+ - **Deep map only:** `/ark-explore`.
86
+ - **Default path:** `ark start` → `/ark-autopilot` → `ark-check --doctor`.
87
+
88
+ ## Anti-wrapper rule (mandatory)
89
+
90
+ **Forbidden:** only running `--init` / `--update-baseline` / coverage JSON without reading the tree.
91
+
92
+ **Required:**
93
+ 1. CLI sensor: `--coverage --json`, check `--json` (`summary`), doctor.
94
+ 2. **Product map** — what ships, which apps/packages, entry routes/CLIs.
95
+ 3. **Read real source** in largest ungoverned dirs and top import edges (min **12 files**
96
+ across **≥4 dirs**).
97
+ 4. **“Así te lo re-soluciono”** — concrete layer globs, file moves, manifest/intent proposals.
98
+ 5. **Suggestive burn-down** — ranked next steps after adopt (not only “baseline done”).
99
+ 6. Never freeze a concentrated edge without investigating contract smell / false-green.
100
+
101
+ ## Guiding principle
102
+
103
+ Ark protects the **boundary around** a framework, not its internals. Nest/DI public surface = one layer; internals black box.
104
+
105
+ ## Steps
106
+
107
+ 1. **Config** — missing → `ark-check --init` (detection). Keep existing unless asked to regenerate.
108
+ If the tree is `src/features` + `shared`/`lib` **without** FSD `entities`/`widgets`, prefer
109
+ `vertical-slice` (or pack `enthusiast-vertical-slice`) — do **not** force hexagonal.
110
+ If `src/contexts` or `src/bounded-contexts` exists, prefer `ddd-bounded-contexts`.
111
+ **Next.js:** `app/api/**` / `pages/api/**` (and route-group `app/(…)/api/**`) default to
112
+ **ApplicationOrchestration**, not Presentation — do not reclassify API shells as UI.
113
+ 2. **Check + diagnose** — `summary.concentrated` / dominant edge → fix contract first, don’t freeze.
114
+ Cross-slice / cross-context `peerIsolation` hits are judgment: extract shared or events.
115
+ If one edge dominates residual debt: **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).
116
+ Empty Domain/Persistence + I/O under Application → false-green.
117
+ **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`.
118
+ 3. **Classify ungoverned** — use coverage `suggestions` **plus** dirs you discovered by reading;
119
+ add layers/patterns via `/ark-contract`.
120
+ 4. **Mine business rules → manifiesto** (model job — this is why the skill exists):
121
+ - Scan for loose domain: validators, pricing/policy functions, `can*`/`calculate*`, magic business constants, publish/intent strings, logic in UI/hooks that belongs in Domain.
122
+ - **ArkRules inventory (AR13):** run `ark-check --rules-inventory --json` for deterministic candidates
123
+ (validation-in-controller, magic constants, anemic entities). Counts are **not a score**.
124
+ - Propose: Domain files, `intentPrefixes`, intent names (`Domain.*` / `Application.*`), kernel `defineIntent` stubs if runtime is used;
125
+ land structure/invariant entries under `arkrules/<Layer>.json` via `/ark-contract` (ADR 0015 routing).
126
+ - Apply config through `/ark-contract` discipline; move pure rules into Domain when safe; validate with ark-check.
127
+ - Deliver section **“Así te lo re-soluciono en el manifiesto”** with before/after contract snippets.
128
+ 5. **Freeze only real debt** — `--update-baseline` (zero debt → **no empty baseline file** left behind).
129
+ 6. **Gates + skills** — `--install-agent-gates` (CI monorepo-aware when `frontend/package.json` exists).
130
+ 7. **Ratchet + Shape seed (mandatory exploratory close)** — after freeze/gates:
131
+ - Name phase: **Align** (contract honesty) → **Stabilize** (baseline real) → **Shape** (golden pattern).
132
+ - If plan A is empty but the tree still shows concurrent patterns, god modules, facade SQL,
133
+ domain logic in UI, or semantic false-green: emit **dual-plan B** (3–5 bets) with pilot,
134
+ success signal, kill-switch, and extraction cards for I/O moves — same bar as `/ark-explore` §G.
135
+ - Do **not** claim “adopt complete / healthy” solely because the check is green.
136
+ - Prefer handoff `/ark-autopilot` for B execution with user ok, or `/ark-explore` shape-focus
137
+ if the user only wanted a plan.
138
+
139
+ ## Operating modes
140
+
141
+ Explain modes as **detected stages** (Setup / Align / Guard), not user settings.
142
+ **Guard on the contract ≠ Shape done.** Say `ENFORCE · design-weak` when B residual remains.
143
+
144
+ ## Verify
145
+
146
+ `ark-check --root . --config ark.config.json --strict-config` (+ baseline only if non-empty file retained).
147
+ Report: governed% before/after, files written, frozen count, false positives avoided, manifest/intent
148
+ proposals applied or deferred, **phase**, **top Shape / design-weak opportunities still open**
149
+ (with success signals).
150
+
151
+ ## Never
152
+
153
+ - Freeze false positives to get green.
154
+ - Force runtime kernel over existing Nest/DI.
155
+ - Claim Enforce while governed% is low, cores empty with I/O in Application, or core bags ungoverned.
156
+ - End adopt with only “baseline written” when design-weak residual is visible in files you opened.
157
+
158
+ ## Completion contract (skill incomplete if missing)
159
+
160
+ End with **exactly** these headings (markdown `###`):
161
+
162
+ ### Completion
163
+ - **Sensor:** commands/tools run
164
+ - **Opened:** real paths read (or `n/a` only if pure install/upgrade with no source analysis)
165
+ - **Result:** one-line outcome
166
+ - **Planes:** one-line split of residual **[Layer]** vs **[ArkRules]** (or `n/a` if unused)
167
+ - **Handoff:** `/ark-…` / CLI / `none`
168
+ - **Incomplete?** `no` | `yes — <what is missing>`
169
+
170
+ If a **STOP** handoff applies and you continued as if done, set **Incomplete?** to `yes`.
171
+ **Skill incomplete if missing** any of the bullets above.
@@ -0,0 +1,175 @@
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
+ ## When / not when
9
+
10
+ | Use `/ark-architect` when… | Do **not** use it when… |
11
+ |----------------------------|-------------------------|
12
+ | Greenfield / thin tree; pick shape + phase-1 layers | Existing spaghetti brownfield → `/ark-adopt` (+ `/ark-explore` first if map missing) |
13
+ | Enthusiast before heavy codegen | Enforcement residual on mature tree → `/ark-autopilot` |
14
+
15
+ The user is building something new or early in Ark adoption. They may not know
16
+ layered architecture jargon. Your job: translate **what they want to build**
17
+ (application shape, not framework name) into an Ark preset, a phase-1 layer plan,
18
+ conventional directories, and a passing honest check — without weakening the gate.
19
+
20
+ Commands below are written as `ark-check` / `ark`; run each through the project's
21
+ package manager (`pnpm exec`, `yarn`, `npx`) — match the lockfile.
22
+
23
+ ## Dual engine (mandatory)
24
+
25
+ | Engine | Role |
26
+ |--------|------|
27
+ | **Deterministic** | CLI / MCP / contract sensors — exit codes, plan kinds, coverage numbers, install status |
28
+ | **Exploratory** | You open **this** repo's real files and product surface before concluding |
29
+
30
+ The CLI is a **sensor**, never the whole job. Claiming done without the exploratory bar for this skill is **incomplete**.
31
+
32
+
33
+
34
+ ## MCP workspace binding (mandatory)
35
+
36
+ Before any `ark_*` MCP tool, call `ark_identity` with `project.expectedRoot` set to the exact
37
+ workspace root. Continue only when `binding.status === "matched"` and `authoritative === true`;
38
+ retain `projectIdentity.projectId`, then pass both `expectedRoot` and `expectedProjectId` under
39
+ `project` on every later MCP call. If identity is missing, mismatched, unverified, or the root is
40
+ uncertain, do not consume MCP analysis: use the workspace-local CLI and report that MCP
41
+ restart/retargeting is required. `ark://manifest` never satisfies this preflight.
42
+
43
+ ## Dual plane — layers + ArkRules (mandatory, except /ark-runtime)
44
+
45
+ ArkGate has **two opt-in planes**. The user chooses which to use; you **always label** findings so they never blur.
46
+
47
+ | Plane | What it protects | Where it lives | Sensors / tools |
48
+ |-------|------------------|----------------|-----------------|
49
+ | **Layers** (inter-layer) | Who may import whom, capabilities, pure/forbiddenGlobals, peerIsolation | `ark.config.json` → `layers[]`, `rules[]` | graph check, baseline edges, doctor coverage % |
50
+ | **ArkRules** (intra-layer) | Structure inside a layer + domain invariants as data | `arkRules` map + `arkrules/<ExactLayerName>.json` | structure sensors, invariant coverage, `--rules-inventory`, doctor `rulesUnderContract` |
51
+
52
+ **Rules for every report / answer:**
53
+ 1. Prefix each finding or next step with **`[Layer]`** or **`[ArkRules]`** (or a two-column table with those headers).
54
+ 2. Never call an import-edge violation an “invariant” or an aggregate sensor a “layer deny.”
55
+ 3. Absence of `arkRules` is **valid** — do not force ArkRules unless the user wants them or residual inventory clearly wants a pilot.
56
+ 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).
57
+ 5. CLI helpers: `ark-check --rules-inventory --json`, doctor JSON `rulesUnderContract`, sensors emit `ARKRULE_*` / `INVARIANT_UNCOVERED` with `evidence.arkruleId`.
58
+
59
+
60
+ ### Architect + ArkRules
61
+ - Preset/init should emit lean `arkRules` + templates for phase-1 layers (exact names).
62
+ - Explain to the user: layers = boundaries; arkrules = habits inside Domain/App/adapters (opt-in, start advisory).
63
+
64
+ ## Subagent fan-out (optional, host-dependent)
65
+
66
+ If the host supports **parallel subagents** and the task splits cleanly (e.g. multiple
67
+ dirs to sample), fan out read-only scouts; otherwise **fall back to sequential**.
68
+ Parent merges and still emits the **### Completion** contract. Never parallel-write
69
+ the same files or weaken the gate.
70
+
71
+ ## Relationship to other skills
72
+
73
+ | Skill | When |
74
+ |-------|------|
75
+ | **/ark-architect** | **Before** — greenfield or fresh config; pick shape + phase 1 |
76
+ | /ark-adopt | **After** — messy existing repo |
77
+ | /ark-contract | **During** — evolve config safely |
78
+ | /ark-place | **During** — one new file |
79
+ | /ark-explain | **After** — understand what exists |
80
+
81
+ ## Steps
82
+
83
+ 1. **Bind and detect the shape** — complete the mandatory `ark_identity` preflight first, then
84
+ call MCP tool **`ark_recommend`** with the bound `project` envelope (or run the workspace-local
85
+ `ark-check --recommend --json`). Never use an unverified recommendation. Read `archetype`, `preset`, `confidence`,
86
+ `adoptInOrder.phase1`, `analogy`, `why`, `evidence`, and `requiresConfirmation`.
87
+ Ask at most **two** questions only if `requiresConfirmation` is true (or for compatibility
88
+ with older ArkGate output, `confidence < 0.5`):
89
+ - "Will this app save data between sessions?"
90
+ - "Is this one app or several in one repository?"
91
+
92
+ 2. **Present in plain English** — name the application shape (e.g. "product with
93
+ UI and stored data"), not the framework. One analogy. List **phase-1 layers only**.
94
+
95
+ 3. **Map to Ark** — if `ark.config.json` is missing, run
96
+ `ark init --archetype <archetype> --yes` (maps playbook id → preset + gates),
97
+ or `ark-check --apply-policy-pack enthusiast-<preset>` for the enthusiast variant.
98
+ Optional team record: `ark-check --recommend --write-plan` → `ark-adoption-plan.json`.
99
+ If a config already exists, use `/ark-contract` to align it — do not regenerate
100
+ unasked. On a messy brownfield tree: **STOP — do not continue this skill as complete.** Invoke **/ark-adopt** instead of forcing greenfield shape.
101
+
102
+ 4. **Scaffold phase 1** — create conventional directories from the preset/playbook
103
+ (`src/domain`, `src/application`, …). Add a one-line README per folder explaining
104
+ what belongs there. Match the nearest sibling file style if code already exists.
105
+ Flat layouts (`src/` + `lib/` + `api/` at the repo root) are common in Vite and
106
+ serverless projects — use `/ark-contract` to map them to layers instead of forcing
107
+ everything under `src/**/domain/**` only.
108
+
109
+ 5. **Install gates** when the user uses AI coding tools and gates are missing:
110
+ `ark-check --install-agent-gates`.
111
+
112
+ 6. **Verify honestly** — run `ark-check --doctor` and `ark-check --coverage --json`.
113
+ Report `governed.percent`. Say explicitly what is **not** governed yet
114
+ (ungoverned directories, empty layers).
115
+
116
+ 7. **Deliver to the user**
117
+ - ASCII diagram (≤3 boxes for phase 1, inner → outer)
118
+ - Table: "when you build X, put it in Y"
119
+ - Three rules the agent must not break (no domain→database imports, no raw
120
+ `publish()`, no weakening `ark.config.json` to pass)
121
+ - Optional book refs from `books` in the recommendation JSON under "go deeper"
122
+ - **Gallery starter** — point the user at the matching clonable example:
123
+
124
+ | Archetype | Example directory |
125
+ |-----------|-------------------|
126
+ | `crud-product` | `examples/crud-product-starter/` |
127
+ | `api-backend` | `examples/api-backend-starter/` |
128
+ | `worker-pipeline` | `examples/worker-pipeline-starter/` |
129
+ | `multi-app-workspace` | `examples/multi-app-workspace-starter/` |
130
+ | `vertical-slice-product` | `examples/vertical-slice-starter/` |
131
+ | `ddd-bounded-contexts` | `examples/ddd-context-starter/` |
132
+
133
+ Say they can copy that folder as a baseline (`npm install && npm run check`).
134
+ For a runnable API with break exercises, mention `examples/hexagonal-order-api/`.
135
+ Full enthusiast track: `docs/enthusiast/README.md`.
136
+
137
+ ## Operating rules
138
+
139
+ - Never weaken `ark.config.json`, the baseline, CI, or agent settings to pass.
140
+ - Never invent layers outside the 11-layer profile or named presets
141
+ (`hexagonal`, `layered`, `feature-sliced`, `monorepo`, `ui-surface`,
142
+ `vertical-slice`, `ddd-bounded-contexts`).
143
+ - Flag unrecognized dirs (`utils/`, `lib/`) — user must classify via `/ark-contract`.
144
+ - Default to smallest viable phase 1; unlock phase 2 only when the user describes need.
145
+ - All user-facing copy is **English**.
146
+
147
+ ## Merge cards (X04 reshape — judgment only)
148
+
149
+ When `doctor.physicalCohesion` reports a mirrored concept and the user asks whether files
150
+ should be **merged**, treat it as domain modeling, never deduplication (field fact: zero
151
+ structural clones among 123 same-concept files). Produce a **merge card** per candidate group:
152
+ which files, the domain concept they express, 2–3 shapes the merged module could take, and what
153
+ each shape costs — **no default action, no auto-merge, never a codemod**. Physical **moves**
154
+ belong to `/ark-loop`'s pilot loop; your job here is the judgment about what the concept IS.
155
+
156
+ ## Verify and report
157
+
158
+ End with `ark-check --root . --config ark.config.json --strict-config` when the
159
+ tree is ready. Report: archetype + preset, directories created, governed %, and
160
+ the next command if anything remains ungoverned.
161
+
162
+ ## Completion contract (skill incomplete if missing)
163
+
164
+ End with **exactly** these headings (markdown `###`):
165
+
166
+ ### Completion
167
+ - **Sensor:** commands/tools run
168
+ - **Opened:** real paths read (or `n/a` only if pure install/upgrade with no source analysis)
169
+ - **Result:** one-line outcome
170
+ - **Planes:** one-line split of residual **[Layer]** vs **[ArkRules]** (or `n/a` if unused)
171
+ - **Handoff:** `/ark-…` / CLI / `none`
172
+ - **Incomplete?** `no` | `yes — <what is missing>`
173
+
174
+ If a **STOP** handoff applies and you continued as if done, set **Incomplete?** to `yes`.
175
+ **Skill incomplete if missing** any of the bullets above.
@@ -0,0 +1,242 @@
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
+ ## When / not when
20
+
21
+ | Use `/ark-autopilot` when… | Do **not** use it when… |
22
+ |----------------------------|-------------------------|
23
+ | “Make architecture sound” end-to-end | Map only, no apply → `/ark-explore` |
24
+ | Brownfield or greenfield with apply | Only fitness numbers → `/ark-coverage` |
25
+ | User wants A + B planned and A executed | Single edge fix → `/ark-fix`; plan A only → `/ark-loop` |
26
+ | **Apply half of Q01 post-green path** (after explore map / when user wants full apply) | Skipping explore when doctor primary is Shape map-first |
27
+ | Spaghetti under ENFORCE: Shape work with user ok on B | Contract false-green first → `/ark-adopt` / `/ark-contract` STOP paths |
28
+
29
+ **Q01:** doctor’s single door is `/ark-explore` shape-focus → dual-plan B, **then** this skill only
30
+ to apply B with OK. Prefer that order when `postGreenPath` / design-weak is the primary residual.
31
+
32
+ ## Related onboarding
33
+
34
+ - **Greenfield:** `/ark-architect` or `ark-check --recommend` / `ark start`.
35
+ - **Brownfield:** `/ark-adopt` — match contract to reality; do not force a starter preset.
36
+ - **Deep map only:** `/ark-explore` — full recon / dual-plan seed without applying.
37
+ - **Adoption fitness only:** `/ark-coverage` — governed% + capability gaps (not pattern dual-plan).
38
+ - **Default path:** `ark start` → `ark-check --doctor` → **`/ark-autopilot`** (this skill) for guided work.
39
+
40
+ ## Dual engine (mandatory)
41
+
42
+ | Engine | Role |
43
+ |--------|------|
44
+ | **Deterministic** | `ark-check` plan/coverage/doctor, mechanical-safe kinds, write/CI gates, exit codes, origin snapshot |
45
+ | **Exploratory** | You map **this** product’s real tree: entry points, coupling, false greens, field path, pattern debt |
46
+
47
+ **Forbidden:** only printing `--plan` JSON or “4 safe / 4 judgment — approve?” without a
48
+ decision-grade explore pass **and** without opening violating files.
49
+
50
+ **Required:**
51
+ 1. **Explore pass** (below) **before** claiming a loop strategy — same bar as `/ark-explore`, budgeted.
52
+ 2. CLI sensors: `--plan --json`, `--coverage --json` / `--doctor` as needed.
53
+ 3. **Dual plan** always emitted (sections A and B).
54
+ 4. **Open every file** in plan A `steps[]` (and `target` if present) before classifying a fix.
55
+ 5. **“Así te lo re-soluciono”** for each A cluster and each B pattern bet.
56
+ 6. Apply A → re-run ark-check → rollback on regression. **Never auto-apply B** as mechanical-safe.
57
+ 7. **Q04 pilot loop for B:** when design-weak, take **`pilotLoop.nextPilot`** (one extraction card)
58
+ → apply **only** that pilot with user OK → **re-doctor**. Never multi-pilot batch B; residual
59
+ outside the pilot may remain and must not be called “healthy finished.”
60
+ 8. **Y01 reshape verdicts:** read `doctor.physicalCohesion.reshapeDecisions` before acting on
61
+ mirror facts. Outcome first: a current rejected/deferred verdict means “intentional/deferred
62
+ layout — no pilot”; never reconstruct that dead card from `findings`. When the user accepts,
63
+ defers, or rejects a live card, persist its exact `decisionTarget` with a non-empty reason and
64
+ optional `reviewBy` in `.ark/reshape-decisions.json`; never infer a verdict from golden prose.
65
+
66
+
67
+
68
+ ## MCP workspace binding (mandatory)
69
+
70
+ Before any `ark_*` MCP tool, call `ark_identity` with `project.expectedRoot` set to the exact
71
+ workspace root. Continue only when `binding.status === "matched"` and `authoritative === true`;
72
+ retain `projectIdentity.projectId`, then pass both `expectedRoot` and `expectedProjectId` under
73
+ `project` on every later MCP call. If identity is missing, mismatched, unverified, or the root is
74
+ uncertain, do not consume MCP analysis: use the workspace-local CLI and report that MCP
75
+ restart/retargeting is required. `ark://manifest` never satisfies this preflight.
76
+
77
+ ## Dual plane — layers + ArkRules (mandatory, except /ark-runtime)
78
+
79
+ ArkGate has **two opt-in planes**. The user chooses which to use; you **always label** findings so they never blur.
80
+
81
+ | Plane | What it protects | Where it lives | Sensors / tools |
82
+ |-------|------------------|----------------|-----------------|
83
+ | **Layers** (inter-layer) | Who may import whom, capabilities, pure/forbiddenGlobals, peerIsolation | `ark.config.json` → `layers[]`, `rules[]` | graph check, baseline edges, doctor coverage % |
84
+ | **ArkRules** (intra-layer) | Structure inside a layer + domain invariants as data | `arkRules` map + `arkrules/<ExactLayerName>.json` | structure sensors, invariant coverage, `--rules-inventory`, doctor `rulesUnderContract` |
85
+
86
+ **Rules for every report / answer:**
87
+ 1. Prefix each finding or next step with **`[Layer]`** or **`[ArkRules]`** (or a two-column table with those headers).
88
+ 2. Never call an import-edge violation an “invariant” or an aggregate sensor a “layer deny.”
89
+ 3. Absence of `arkRules` is **valid** — do not force ArkRules unless the user wants them or residual inventory clearly wants a pilot.
90
+ 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).
91
+ 5. CLI helpers: `ark-check --rules-inventory --json`, doctor JSON `rulesUnderContract`, sensors emit `ARKRULE_*` / `INVARIANT_UNCOVERED` with `evidence.arkruleId`.
92
+
93
+
94
+ ### Autopilot + ArkRules
95
+ - After explore/doctor: if inventory has high-confidence candidates **or** user wants domain rules, include **[ArkRules] plan A/B**:
96
+ - A: mechanical-safe remains inter-layer only; structure/invariant fixes are **judgment**.
97
+ - B: one pilot = one rule (declare in `arkrules/<Layer>.json` → implement → test title/symbol → re-doctor).
98
+ - Never promote advisory→enforced without coverage evidence (`canPromoteInvariant` / policy-delta).
99
+ - End report must list what was **layer-edge** work vs **intra-layer rule** work.
100
+
101
+ ## Subagent fan-out (optional, host-dependent)
102
+
103
+ When the user asks to go faster **or** the work naturally splits (multiple packages,
104
+ feature dirs, plan clusters), you **may** dispatch **subagents**:
105
+
106
+ | Host capability | Behavior |
107
+ |-----------------|----------|
108
+ | **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. |
109
+ | **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. |
110
+
111
+ **Rules:**
112
+ 1. Give each subagent a **tight brief**: paths in scope, sensor commands allowed, deliverable shape (paths opened + findings JSON or bullets).
113
+ 2. **No shared mutable files** across parallel writers.
114
+ 3. STOP handoffs and dual-engine rules still apply in every agent.
115
+ 4. Parent owns the **### Completion** block (union of **Opened**, single **Handoff**).
116
+ 5. Do **not** use subagents to weaken the gate or invent `mechanical-safe` kinds.
117
+
118
+ Useful first wave: **core product tree** | **field path** (examples/starters) | **agent install surfaces** (hooks vs templates).
119
+
120
+ ## Explore pass (phase 0 — mandatory, first)
121
+
122
+ Do this **before** grinding plan A — plan lists *violations*, not *product reality*.
123
+ Use the **`/ark-explore` decision-grade bar** (compressed into the autopilot report, not optional fluff).
124
+ Include explore **§G** when spaghetti / design-weak signals fire.
125
+
126
+ 1. **Headline** — product one-liner + honesty (mode, governed%, false-green / false-promise /
127
+ **ENFORCE·design-weak** risk).
128
+ 2. **Map** — entry points, lived layout vs globs (one screen). **Concurrent patterns** table when ≥2 styles.
129
+ 3. **Phase ladder** — name **Align | Stabilize | Shape** (explore §G).
130
+ 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.
131
+ 5. **Agent/gate reality** — installed hooks vs install templates (e.g. `--hook` vs `--hook-repair`); MCP; CI gate present.
132
+ 6. **Coupling** — fan-in / exports / importers for hotspots (LOC alone is a hint).
133
+ 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:
134
+ **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`.
135
+ 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).
136
+
137
+ Min bar: **≥12 source files** across **≥4 meaningful directories** (not only files in `steps[]`).
138
+ Standalone long report: `/ark-explore`. Adoption fitness only: `/ark-coverage`.
139
+
140
+ ## Dual plan (always emit)
141
+
142
+ | Section | Source | Question | Auto-apply? |
143
+ |---------|--------|----------|-------------|
144
+ | **A. Remediation** | `--plan --json` + opened step files | What must change so the **gate** is honest? | Only `mechanical-safe` by default |
145
+ | **B. Pattern / Shape** | Explore §B/§G (not coverage alone) | What **design** must improve even if A is empty? | **Never** as mechanical-safe |
146
+
147
+ **Section A** — group by edge; treat `peerIsolation` / cross-slice as **judgment**.
148
+ **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).
149
+
150
+ B does **not** count as “architecture healthy finished.” Report B as `proposed | deferred | applied-with-user-ok`.
151
+ When A is empty and B is non-empty: status is **`goal.met on edges · Shape residual open`** — never “done” without listing B.
152
+ Prefer CLI `patternBets[]` / `designSmells[]` when present; apply B only with explicit user ok using
153
+ **extraction cards** (`docs/brownfield-adoption.md` §6) — never mechanical-safe, never silent.
154
+ If B will take multiple PRs, offer (do not require) persisting a short Shape plan under the
155
+ repo so the next agent session continues the same pilot — still never auto-apply B.
156
+
157
+ ## Origin snapshot (day-zero picture)
158
+
159
+ - **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.
160
+ - **How:** `ark-check --report ark-report.html` (writes origin once under `.ark/reports/`).
161
+ - **Never** `--reset-origin` unless the user explicitly wants a new baseline.
162
+ - **Do not** wait until the end of the loop to create origin the first time — later reports need a frozen “before” picture.
163
+ - End of run: re-`--report` for **latest** + evolution vs origin (origin stays frozen).
164
+
165
+ ## Operating modes (detected, not picked)
166
+
167
+ Status lights from doctor — not settings you choose. Rank residual honestly:
168
+
169
+ | Light | Means | Your move (this skill) |
170
+ |-------|--------|------------------------|
171
+ | **Suggest** | Thin/new tree; contract not control plane | Finish `ark start` → re-doctor; do not skill-shop |
172
+ | **Adapt** | Contract/tree disagree or debt open | Explore + adopt/loop/contract; do not claim guarded |
173
+ | **Enforce** | Honest coverage + clean checked **edges** | Confirm gates + CI; emit dual-plan B only if residual found |
174
+ | **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. |
175
+
176
+ - **Setup (Suggest):** no config → `ark start` (start freezes origin after config, before gates).
177
+ - **Align (Adapt):** open debt, low honesty, or false-green → explore + adopt/loop; do not claim “guarded”.
178
+ - **Guard (Enforce):** `goal.met`, solid governed%, no false-green → confirm gates; still emit dual plan B if explore found residual.
179
+ - **Guard · design-weak:** same as Enforce on edges, **plus** mandatory dual-plan B / pilot card; Incomplete? must not claim healthy finished while residual remains.
180
+
181
+ ## Flow
182
+
183
+ 0. **Explore pass** — decision-grade recon (see above); seed plan B.
184
+ 1. **Setup if needed** — `ark start` if no `ark.config.json`. Trust `--recommend` / playbook:
185
+ `vertical-slice-product` and `ddd-bounded-contexts` are first-class shapes (not hexagonal by default).
186
+ 2. **Origin if missing** — freeze day-zero (`--report`) immediately after contract exists.
187
+ 3. **Sensors** — `--plan --json`, doctor/coverage as needed.
188
+ 4. **Emit dual plan** — A from plan steps (files opened); B from explore (3–5 bets).
189
+ 5. **Concentrated edge?** — if one edge dominates A:
190
+ **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).
191
+ 6. **Worktree preferred** — discardable git worktree when possible.
192
+ 7. **Mechanical-safe (A only)** — kinds from `/ark-loop` table; one step, validate, rollback.
193
+ 8. **Judgment (A)** — default: propose with full “así te lo re-soluciono”. If user authorized full apply: implement, validate, rollback on fail.
194
+ 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.
195
+ 10. **Manifiesto** — loose business rules → Domain placement + `intentPrefixes` / intents via `/ark-contract` discipline.
196
+ 11. **Final report** — re-`--report`; evolution vs origin; A applied vs open; B proposed/deferred; gates on.
197
+ 12. **Strict check** — `ark-check --strict-config` (dead preset globs are advisory; real violations still fail).
198
+ 13. **Core ratchet (when green)** — if plan `goal.met` and doctor still **ADAPT** only because
199
+ populated cores are `optional: true`, run `ark-check --ratchet-cores` then `--doctor`.
200
+ Never ratchet while active violations remain or false-green gap is open.
201
+
202
+ ## Mechanical-edit hygiene (Y04 — outcome gate)
203
+
204
+ - Header injection must **merge into the existing doc comment**; the kept result has one `/**`, not stacked headers.
205
+ - 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.
206
+ - 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.
207
+ - Keep the edit only when the **previously clean file stays typecheck-clean**. Otherwise roll it back and treat the change as judgment.
208
+
209
+ ## Never
210
+
211
+ - Disable rules, broaden allows, or baseline **new** debt to “finish”.
212
+ - Claim clean while judgment A steps were skipped without user decision.
213
+ - Claim ENFORCE / “done” when doctor reports `contract-false-green-io-under-application` (adopt first).
214
+ - Claim “done” solely because plan A is empty while explore/B residual remains unlisted.
215
+ - Replace host Nest/DI with the runtime kernel unasked.
216
+ - Auto-apply pattern (B) bets as if they were mechanical-safe.
217
+ - Create origin only after a long cleanup (freezes a polished “before” that never was).
218
+
219
+ ## Done criteria
220
+
221
+ - Explore pass completed (decision-grade map + paths + field path or n/a + phase + B seeds).
222
+ - Dual plan emitted (A and/or B; if both empty, one-line justification with evidence no design-weak smells).
223
+ - Origin present under `.ark/reports/origin.*` (frozen this run or earlier).
224
+ - Every applied A step validated by real `ark-check`.
225
+ - Final plan `goal.met` true **or** remaining A steps listed with file-level proposals.
226
+ - Open **B / Shape opportunities** listed with success signals; report HTML paths cited when used.
227
+ - If A empty and design-weak present: B listed — **Incomplete?** must not claim full healthy stop.
228
+
229
+ ## Completion contract (skill incomplete if missing)
230
+
231
+ End with **exactly** these headings (markdown `###`):
232
+
233
+ ### Completion
234
+ - **Sensor:** commands/tools run
235
+ - **Opened:** real paths read (or `n/a` only if pure install/upgrade with no source analysis)
236
+ - **Result:** one-line outcome
237
+ - **Planes:** one-line split of residual **[Layer]** vs **[ArkRules]** (or `n/a` if unused)
238
+ - **Handoff:** `/ark-…` / CLI / `none`
239
+ - **Incomplete?** `no` | `yes — <what is missing>`
240
+
241
+ If a **STOP** handoff applies and you continued as if done, set **Incomplete?** to `yes`.
242
+ **Skill incomplete if missing** any of the bullets above.