arkgate 2.9.1 → 2.10.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 (43) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/README.md +14 -2
  3. package/bin/ark-mcp.mjs +282 -102
  4. package/bin/lib/agent-gates.mjs +181 -6
  5. package/bin/lib/architecture-scan.mjs +19 -0
  6. package/bin/lib/auto-patch.mjs +264 -0
  7. package/bin/lib/doctor-plan.mjs +54 -0
  8. package/bin/lib/port-proof.mjs +309 -0
  9. package/bin/lib/prepare-write.mjs +130 -0
  10. package/bin/lib/remediation.mjs +21 -0
  11. package/dist/index.cjs +13 -4
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +1 -1
  14. package/dist/index.d.ts +1 -1
  15. package/dist/index.js +13 -4
  16. package/dist/index.js.map +1 -1
  17. package/dist/nestjs/index.cjs +1 -1
  18. package/dist/nestjs/index.cjs.map +1 -1
  19. package/dist/nestjs/index.js +1 -1
  20. package/dist/nestjs/index.js.map +1 -1
  21. package/dist/runtime/index.cjs +13 -4
  22. package/dist/runtime/index.cjs.map +1 -1
  23. package/dist/runtime/index.js +13 -4
  24. package/dist/runtime/index.js.map +1 -1
  25. package/docs/agent-guide.md +14 -0
  26. package/docs/ai-gates.md +43 -3
  27. package/docs/enthusiast/how-to-agent-gates.md +8 -0
  28. package/docs/enthusiast/reference-commands.md +1 -1
  29. package/package.json +2 -1
  30. package/server.json +2 -2
  31. package/templates/skills/ark-adopt.md +57 -10
  32. package/templates/skills/ark-architect.md +33 -2
  33. package/templates/skills/ark-autopilot.md +75 -20
  34. package/templates/skills/ark-contract.md +36 -0
  35. package/templates/skills/ark-coverage.md +81 -27
  36. package/templates/skills/ark-explain.md +35 -2
  37. package/templates/skills/ark-explore.md +119 -0
  38. package/templates/skills/ark-fix.md +47 -2
  39. package/templates/skills/ark-loop.md +50 -3
  40. package/templates/skills/ark-place.md +36 -0
  41. package/templates/skills/ark-runtime.md +36 -0
  42. package/templates/skills/ark-think.md +63 -12
  43. package/templates/skills/ark-upgrade.md +33 -1
@@ -178,6 +178,20 @@ reference, and explanation for the full path (recommend → init → gallery →
178
178
  5. Use `/ark-place` or `ark_place` for individual files after the contract exists.
179
179
  6. Verify with `ark-check --root . --config ark.config.json --strict-config`.
180
180
 
181
+ ### Write protocol (2.10+ / Track W)
182
+
183
+ Prefer preparing the write before the host commits it to disk:
184
+
185
+ | Surface | Role |
186
+ |---------|------|
187
+ | MCP **`ark_prepare_write`** | Place + constrain + validate + optional `autoPatch` + `judgmentBrief` + contentHash in one call |
188
+ | Write-gate **`autoPatch`** | Mechanical-safe **import type** rewrites only; post-patch revalidation green or discarded |
189
+ | PreToolUse **`--hook-repair`** | On deny: `ARK_REPAIR_JSON` / `ARK_AUTOPATCH_JSON` on stderr (still exit 2 — never silent write) |
190
+ | Doctor **`writePath`** | Reports `repair` \| `reject-only` \| `mcp-only` \| `none` for installed gates |
191
+
192
+ Port-proof inject binding is **judgment** for auto-apply (signature/arity change), not write-path autoPatch.
193
+ Full reference: [ai-gates.md](ai-gates.md). Loop-cost harness: `npm run eval:loop-cost`.
194
+
181
195
  Do not invent layers outside the 11-layer profile or named presets. Unrecognized
182
196
  directories (`utils/`, `lib/`) must be classified explicitly via `/ark-contract`.
183
197
 
package/docs/ai-gates.md CHANGED
@@ -38,6 +38,11 @@ GitHub Actions, `AGENTS.md`, a Codex TOML snippet under `docs/`, and (when
38
38
  selected) Grok Build project files under `.grok/`. It skips existing files unless
39
39
  you pass `--force`, so review and commit only the templates that match your project.
40
40
 
41
+ **Doctor (W5):** `ark-check --doctor --json` includes `doctor.writePath`
42
+ (`mode`: `repair` | `reject-only` | `mcp-only` | `none`, plus `prepareWrite` /
43
+ `autoPatch` flags) so leads can see whether the write path is repair-capable or
44
+ still reject-only.
45
+
41
46
  If your project uses Codex or Grok, treat MCP registration as part of the default
42
47
  setup, not an optional extra. Ark works best when the agent can read `ark://manifest`
43
48
  before it writes code; that is the fast path to avoiding architecture drift during
@@ -52,6 +57,40 @@ violations relative to the file's current on-disk state, so files with pre-exist
52
57
  (baselined) violations stay editable — they just can't get worse. New files block on
53
58
  every violation.
54
59
 
60
+ ### Opt-in repair payload (W4)
61
+
62
+ Default is **hard block with prose** on stderr. Hosts that can re-inject a fixed write
63
+ can enable a **machine-readable repair payload** (still exit `2` — **never** silent write):
64
+
65
+ | Enable | Effect on deny |
66
+ |--------|----------------|
67
+ | `--hook-repair` | Emit `ARK_REPAIR_JSON:…` and, when available, `ARK_AUTOPATCH_JSON:…` on stderr |
68
+ | `ARK_HOOK_REPAIR=1` | Same as `--hook-repair` (env, no template rewrite) |
69
+
70
+ `ARK_REPAIR_JSON` shape (stable additive):
71
+
72
+ ```json
73
+ {
74
+ "mode": "repair",
75
+ "decision": "deny",
76
+ "filePath": "src/domain/use.ts",
77
+ "layer": "DomainModel",
78
+ "autoPatch": {
79
+ "source": "import type { Row } from '../infra/types-only';\n…",
80
+ "remediationKind": "import-type-from-pure-type-module",
81
+ "confidence": 0.85,
82
+ "valid": true
83
+ }
84
+ }
85
+ ```
86
+
87
+ When no mechanical-safe patch applies, `autoPatch` is `null` (host still re-reasons or uses
88
+ `ark_prepare_write` / judgment). Grok deny JSON also includes `autoPatch` + `"repair": true`
89
+ when repair mode is on.
90
+
91
+ `--install-agent-gates` writes Claude/Grok PreToolUse commands with `--hook-repair` enabled.
92
+ Reject-only installs: drop `--hook-repair` (or unset `ARK_HOOK_REPAIR`).
93
+
55
94
  Add to your project's `.claude/settings.json`:
56
95
 
57
96
  ```json
@@ -63,7 +102,7 @@ Add to your project's `.claude/settings.json`:
63
102
  "hooks": [
64
103
  {
65
104
  "type": "command",
66
- "command": "npx ark-mcp --hook --root \"$CLAUDE_PROJECT_DIR\" --config ark.config.json"
105
+ "command": "npx ark-mcp --hook --hook-repair --root \"$CLAUDE_PROJECT_DIR\" --config ark.config.json"
67
106
  }
68
107
  ]
69
108
  }
@@ -124,10 +163,11 @@ prints nothing and exits 0, so non-Ark projects are untouched.
124
163
 
125
164
  ## Claude Code — MCP server (contract discovery + on-demand validation)
126
165
 
127
- The MCP server exposes a resource and four tools agents can use proactively:
166
+ The MCP server exposes a resource and tools agents can use proactively (not an exhaustive list — `tools/list` is authoritative):
128
167
 
129
168
  - **`ark://manifest`** (resource) — the machine-readable architecture contract (layers + rules), so the agent can read the architecture before generating code.
130
- - **`validate_code`** (tool) — validates a snippet against the architecture on demand (the write-path gate).
169
+ - **`validate_code`** (tool) — validates a snippet against the architecture on demand (the write-path gate). May return additive **`autoPatch`** (W1) for mechanical-safe import-type rewrites.
170
+ - **`ark_prepare_write`** (tool) — **W2:** place + constrain + validate + optional autoPatch + judgmentBrief + contentHash in one call (composes `ark_place` + write gate).
131
171
  - **`ark_place`** (tool) — given a target file path, returns its layer, forbidden globals, and which layers it may / must not import. Call it *before* writing a new file so generated code lands in a governed location.
132
172
  - **`ark_check`** (tool) — runs the full architecture check and returns structured violations (applies the baseline automatically when one exists).
133
173
  - **`ark_coverage`** (tool) — per-layer file counts, the full unclassified-file list, and layers whose patterns match nothing.
@@ -9,6 +9,10 @@ npx arkgate-check --install-agent-gates --tools claude,cursor,codex,grok
9
9
  Installs:
10
10
 
11
11
  - Write-gate hook configuration (Claude / Grok PreToolUse; Cursor advisory + MCP)
12
+ — PreToolUse uses **`--hook-repair`** (W4): on deny, stderr may include
13
+ `ARK_REPAIR_JSON` / `ARK_AUTOPATCH_JSON` for hosts that re-inject a patch.
14
+ Still exit 2 / hard block; never silent write. Drop `--hook-repair` for
15
+ reject-only prose, or set `ARK_HOOK_REPAIR=0` and omit the flag.
12
16
  - MCP server entry (`.mcp.json`, Cursor/Codex/Grok equivalents)
13
17
  - `/ark-*` skills including **`/ark-architect`**, **`/ark-autopilot`**, **`/ark-loop`**
14
18
  (with current `mechanical-safe` remediation kinds)
@@ -35,6 +39,10 @@ npx arkgate-check --doctor
35
39
  npx arkgate-check --require-gates
36
40
  ```
37
41
 
42
+ Doctor JSON (`--doctor --json`) includes **`writePath`**: whether PreToolUse is
43
+ `repair` (machine-readable autoPatch on deny), `reject-only`, `mcp-only`, or
44
+ `none` — plus `prepareWrite` / `autoPatch` booleans for leads.
45
+
38
46
  After upgrading the package, refresh skills so agents see the latest plan kinds:
39
47
 
40
48
  ```bash
@@ -52,7 +52,7 @@ arkgate-check --watch
52
52
  | `class` | Agent may auto-apply? | Examples (`remediationKind`) |
53
53
  |---------|----------------------|------------------------------|
54
54
  | `mechanical-safe` | Yes (validate + rollback) | `type-only-import-move`, `pure-type-file-relocate`, `import-type-from-pure-type-module`, `import-type-of-type-exports` |
55
- | `judgment` | No — propose | value imports, ports, infra relocate, cycles |
55
+ | `judgment` | No — propose | free value-import uses, multi-file ports, **W6 port-proof inject** (arity change), infra relocate, cycles |
56
56
  | `deferred` | No | unclear shape |
57
57
 
58
58
  ## Violation JSON (enthusiast fields)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arkgate",
3
- "version": "2.9.1",
3
+ "version": "2.10.0",
4
4
  "description": "ArkGate — architecture co-pilot for AI TypeScript (write gate, CI gate, plan/loop)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -79,6 +79,7 @@
79
79
  "eval:agent": "node eval/run.mjs",
80
80
  "eval:corpus": "node eval/validate-corpus.mjs",
81
81
  "eval:comparative": "node eval/comparative-run.mjs",
82
+ "eval:loop-cost": "node eval/loop-cost-run.mjs",
82
83
  "clean": "rm -rf dist",
83
84
  "release:npm": "node scripts/release-npm.mjs",
84
85
  "prepack": "npm run build"
package/server.json CHANGED
@@ -6,12 +6,12 @@
6
6
  "url": "https://github.com/pedroknigge/arkgate",
7
7
  "source": "github"
8
8
  },
9
- "version": "2.9.1",
9
+ "version": "2.10.0",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "identifier": "arkgate",
14
- "version": "2.9.1",
14
+ "version": "2.10.0",
15
15
  "runtimeHint": "npx",
16
16
  "transport": {
17
17
  "type": "stdio"
@@ -1,18 +1,44 @@
1
1
  ---
2
2
  name: ark-adopt
3
- description: Brownfield onboarding — match contract to real code, classify ungoverned dirs, mine loose business rules into the Ark manifest/intents, freeze only real debt. Deep source analysis required.
3
+ description: Brownfield onboarding — exploratory match of contract to real product code, classify ungoverned dirs, mine business rules into the manifest, freeze only real debt. Deep source analysis required.
4
4
  ---
5
5
 
6
6
  # /ark-adopt — Bring Ark into an existing codebase
7
7
 
8
- Goal: contract reflects reality, most code governed, only genuine debt frozen with a burn-down.
9
- A green check over a wrong contract is a **false green**.
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
10
 
11
11
 
12
+ ## Dual engine (mandatory)
13
+
14
+ | Engine | Role |
15
+ |--------|------|
16
+ | **Deterministic** | coverage, doctor, baseline, strict-config after edits |
17
+ | **Exploratory** | walk the real monorepo/app layout; reclassify; mine rules; suggest shape |
18
+
19
+
20
+ ## Subagent fan-out (optional, host-dependent)
21
+
22
+ When the user asks to go faster **or** the work naturally splits (multiple packages,
23
+ feature dirs, plan clusters), you **may** dispatch **subagents**:
24
+
25
+ | Host capability | Behavior |
26
+ |-----------------|----------|
27
+ | **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. |
28
+ | **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. |
29
+
30
+ **Rules:**
31
+ 1. Give each subagent a **tight brief**: paths in scope, sensor commands allowed, deliverable shape (paths opened + findings JSON or bullets).
32
+ 2. **No shared mutable files** across parallel writers.
33
+ 3. STOP handoffs and dual-engine rules still apply in every agent.
34
+ 4. Parent owns the **### Completion** block (union of **Opened**, single **Handoff**).
35
+ 5. Do **not** use subagents to weaken the gate or invent `mechanical-safe` kinds.
36
+
12
37
  ## Related onboarding
13
38
 
14
39
  - **Greenfield:** `/ark-architect` or `ark-check --recommend` / `ark start`.
15
40
  - **Brownfield:** `/ark-adopt` — match contract to reality; do not force a starter preset.
41
+ - **Deep map only:** `/ark-explore`.
16
42
  - **Default path:** `ark start` → `/ark-autopilot` → `ark-check --doctor`.
17
43
 
18
44
  ## Anti-wrapper rule (mandatory)
@@ -21,9 +47,12 @@ A green check over a wrong contract is a **false green**.
21
47
 
22
48
  **Required:**
23
49
  1. CLI sensor: `--coverage --json`, check `--json` (`summary`), doctor.
24
- 2. **Read real source** in largest ungoverned dirs and top import edges (min **10 files**).
25
- 3. **“Así te lo re-soluciono”** concrete layer globs, file moves, and manifest/intent proposals.
26
- 4. Never freeze a concentrated edge without investigating contract smell.
50
+ 2. **Product map** what ships, which apps/packages, entry routes/CLIs.
51
+ 3. **Read real source** in largest ungoverned dirs and top import edges (min **12 files**
52
+ across **≥4 dirs**).
53
+ 4. **“Así te lo re-soluciono”** — concrete layer globs, file moves, manifest/intent proposals.
54
+ 5. **Suggestive burn-down** — ranked next steps after adopt (not only “baseline done”).
55
+ 6. Never freeze a concentrated edge without investigating contract smell / false-green.
27
56
 
28
57
  ## Guiding principle
29
58
 
@@ -37,7 +66,11 @@ Ark protects the **boundary around** a framework, not its internals. Nest/DI pub
37
66
  If `src/contexts` or `src/bounded-contexts` exists, prefer `ddd-bounded-contexts`.
38
67
  2. **Check + diagnose** — `summary.concentrated` / dominant edge → fix contract first, don’t freeze.
39
68
  Cross-slice / cross-context `peerIsolation` hits are judgment: extract shared or events.
40
- 3. **Classify ungoverned** — use coverage `suggestions`; add layers/patterns via `/ark-contract`.
69
+ If one edge dominates residual debt: **STOPdo 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).
70
+ Empty Domain/Persistence + I/O under Application → false-green.
71
+ **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`.
72
+ 3. **Classify ungoverned** — use coverage `suggestions` **plus** dirs you discovered by reading;
73
+ add layers/patterns via `/ark-contract`.
41
74
  4. **Mine business rules → manifiesto** (model job — this is why the skill exists):
42
75
  - Scan for loose domain: validators, pricing/policy functions, `can*`/`calculate*`, magic business constants, publish/intent strings, logic in UI/hooks that belongs in Domain.
43
76
  - Propose: Domain files, `intentPrefixes`, intent names (`Domain.*` / `Application.*`), kernel `defineIntent` stubs if runtime is used.
@@ -45,7 +78,7 @@ Ark protects the **boundary around** a framework, not its internals. Nest/DI pub
45
78
  - Deliver section **“Así te lo re-soluciono en el manifiesto”** with before/after contract snippets.
46
79
  5. **Freeze only real debt** — `--update-baseline` (zero debt → **no empty baseline file** left behind).
47
80
  6. **Gates + skills** — `--install-agent-gates` (CI monorepo-aware when `frontend/package.json` exists).
48
- 7. **Ratchet plan** — ranked edges + which are false positives avoided.
81
+ 7. **Ratchet + opportunity plan** — ranked residual edges + **explore-style bets** (what to improve next week).
49
82
 
50
83
  ## Operating modes
51
84
 
@@ -54,10 +87,24 @@ Explain modes as **detected stages** (Setup / Align / Guard), not user settings.
54
87
  ## Verify
55
88
 
56
89
  `ark-check --root . --config ark.config.json --strict-config` (+ baseline only if non-empty file retained).
57
- Report: governed% before/after, files written, frozen count, false positives avoided, manifest/intent proposals applied or deferred.
90
+ Report: governed% before/after, files written, frozen count, false positives avoided, manifest/intent proposals applied or deferred, **top opportunities still open**.
58
91
 
59
92
  ## Never
60
93
 
61
94
  - Freeze false positives to get green.
62
95
  - Force runtime kernel over existing Nest/DI.
63
- - Claim Enforce while governed% is low or core bags ungoverned.
96
+ - Claim Enforce while governed% is low, cores empty with I/O in Application, or core bags ungoverned.
97
+
98
+ ## Completion contract (skill incomplete if missing)
99
+
100
+ End with **exactly** these headings (markdown `###`):
101
+
102
+ ### Completion
103
+ - **Sensor:** commands/tools run
104
+ - **Opened:** real paths read (or `n/a` only if pure install/upgrade with no source analysis)
105
+ - **Result:** one-line outcome
106
+ - **Handoff:** `/ark-…` / CLI / `none`
107
+ - **Incomplete?** `no` | `yes — <what is missing>`
108
+
109
+ If a **STOP** handoff applies and you continued as if done, set **Incomplete?** to `yes`.
110
+ **Skill incomplete if missing** any of the bullets above.
@@ -13,6 +13,23 @@ conventional directories, and a passing honest check — without weakening the g
13
13
  Commands below are written as `ark-check` / `ark`; run each through the project's
14
14
  package manager (`pnpm exec`, `yarn`, `npx`) — match the lockfile.
15
15
 
16
+ ## Dual engine (mandatory)
17
+
18
+ | Engine | Role |
19
+ |--------|------|
20
+ | **Deterministic** | CLI / MCP / contract sensors — exit codes, plan kinds, coverage numbers, install status |
21
+ | **Exploratory** | You open **this** repo's real files and product surface before concluding |
22
+
23
+ The CLI is a **sensor**, never the whole job. Claiming done without the exploratory bar for this skill is **incomplete**.
24
+
25
+
26
+ ## Subagent fan-out (optional, host-dependent)
27
+
28
+ If the host supports **parallel subagents** and the task splits cleanly (e.g. multiple
29
+ dirs to sample), fan out read-only scouts; otherwise **fall back to sequential**.
30
+ Parent merges and still emits the **### Completion** contract. Never parallel-write
31
+ the same files or weaken the gate.
32
+
16
33
  ## Relationship to other skills
17
34
 
18
35
  | Skill | When |
@@ -40,7 +57,7 @@ package manager (`pnpm exec`, `yarn`, `npx`) — match the lockfile.
40
57
  or `ark-check --apply-policy-pack enthusiast-<preset>` for the enthusiast variant.
41
58
  Optional team record: `ark-check --recommend --write-plan` → `ark-adoption-plan.json`.
42
59
  If a config already exists, use `/ark-contract` to align it — do not regenerate
43
- unasked.
60
+ unasked. On a messy brownfield tree: **STOP — do not continue this skill as complete.** Invoke **/ark-adopt** instead of forcing greenfield shape.
44
61
 
45
62
  4. **Scaffold phase 1** — create conventional directories from the preset/playbook
46
63
  (`src/domain`, `src/application`, …). Add a one-line README per folder explaining
@@ -91,4 +108,18 @@ package manager (`pnpm exec`, `yarn`, `npx`) — match the lockfile.
91
108
 
92
109
  End with `ark-check --root . --config ark.config.json --strict-config` when the
93
110
  tree is ready. Report: archetype + preset, directories created, governed %, and
94
- the next command if anything remains ungoverned.
111
+ the next command if anything remains ungoverned.
112
+
113
+ ## Completion contract (skill incomplete if missing)
114
+
115
+ End with **exactly** these headings (markdown `###`):
116
+
117
+ ### Completion
118
+ - **Sensor:** commands/tools run
119
+ - **Opened:** real paths read (or `n/a` only if pure install/upgrade with no source analysis)
120
+ - **Result:** one-line outcome
121
+ - **Handoff:** `/ark-…` / CLI / `none`
122
+ - **Incomplete?** `no` | `yes — <what is missing>`
123
+
124
+ If a **STOP** handoff applies and you continued as if done, set **Incomplete?** to `yes`.
125
+ **Skill incomplete if missing** any of the bullets above.
@@ -1,11 +1,11 @@
1
1
  ---
2
2
  name: ark-autopilot
3
- description: End-to-end architecture co-pilot — setup, deep plan from real code, apply mechanical-safe fixes, design and apply judgment fixes when the user asks for full apply. CLI is a sensor; you remediate files.
3
+ description: End-to-end architecture co-pilot — exploratory map of the real project, then setup, deep plan from source, mechanical-safe fixes, and judgment design. CLI is a sensor; you read and remediate files.
4
4
  ---
5
5
 
6
6
  # /ark-autopilot — Get to a sound architecture, end to end
7
7
 
8
- Composes **setup + plan + loop**. Safe default: auto-apply only `mechanical-safe`;
8
+ Composes **explore + setup + plan + loop**. Safe default: auto-apply only `mechanical-safe`;
9
9
  when the user says full apply / “al mango” / apply everything, also execute
10
10
  **judgment** fixes you design from reading source (still validate with ark-check,
11
11
  never weaken the gate).
@@ -15,47 +15,86 @@ never weaken the gate).
15
15
 
16
16
  - **Greenfield:** `/ark-architect` or `ark-check --recommend` / `ark start`.
17
17
  - **Brownfield:** `/ark-adopt` — match contract to reality; do not force a starter preset.
18
+ - **Deep map only:** `/ark-explore` — reconnaissance without applying fixes.
18
19
  - **Default path:** `ark start` → `/ark-autopilot` → `ark-check --doctor`.
19
20
 
20
- ## Anti-wrapper rule (mandatory)
21
+ ## Dual engine (mandatory)
21
22
 
22
- **Forbidden:** only printing `--plan` JSON or “4 safe / 4 judgment — approve?” without reading the violating files.
23
+ | Engine | Role |
24
+ |--------|------|
25
+ | **Deterministic** | `ark-check` plan/coverage/doctor, mechanical-safe kinds, write/CI gates, exit codes |
26
+ | **Exploratory** | You map **this** product’s real tree: entry points, packages, coupling, false greens, opportunities |
27
+
28
+ **Forbidden:** only printing `--plan` JSON or “4 safe / 4 judgment — approve?” without reading the violating files **and** without a short product map.
23
29
 
24
30
  **Required:**
25
- 1. CLI sensor: `ark-check --plan --json`, coverage/doctor as needed.
26
- 2. **Open every file** in the plan’s `steps[]` (and its `target` if present) before classifying a fix.
27
- 3. **“Así te lo re-soluciono”** for each cluster of steps: exact moves (extract type, relocate file, invert dependency).
28
- 4. Apply re-run ark-check rollback on regression.
31
+ 1. **Explore pass** (below) before claiming a loop strategy.
32
+ 2. CLI sensor: `ark-check --plan --json`, coverage/doctor as needed.
33
+ 3. **Open every file** in the plan’s `steps[]` (and its `target` if present) before classifying a fix.
34
+ 4. **“Así te lo re-soluciono”** for each cluster: exact moves (extract type, relocate file, invert dependency).
35
+ 5. Apply → re-run ark-check → rollback on regression.
36
+
37
+
38
+ ## Subagent fan-out (optional, host-dependent)
39
+
40
+ When the user asks to go faster **or** the work naturally splits (multiple packages,
41
+ feature dirs, plan clusters), you **may** dispatch **subagents**:
42
+
43
+ | Host capability | Behavior |
44
+ |-----------------|----------|
45
+ | **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. |
46
+ | **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. |
47
+
48
+ **Rules:**
49
+ 1. Give each subagent a **tight brief**: paths in scope, sensor commands allowed, deliverable shape (paths opened + findings JSON or bullets).
50
+ 2. **No shared mutable files** across parallel writers.
51
+ 3. STOP handoffs and dual-engine rules still apply in every agent.
52
+ 4. Parent owns the **### Completion** block (union of **Opened**, single **Handoff**).
53
+ 5. Do **not** use subagents to weaken the gate or invent `mechanical-safe` kinds.
54
+
55
+ ## Explore pass (before grinding the plan)
56
+
57
+ Do this even if the plan is non-empty — plan lists *violations*, not *product reality*.
58
+
59
+ 1. **Product one-liner** — README + main package(s) + what the user gets.
60
+ 2. **Entry points** — apps, APIs, CLIs, workers (min paths named).
61
+ 3. **Lived layout** — which dirs are really Domain / Application / I/O / UI vs what globs claim.
62
+ 4. **False-green soft block** — doctor / coverage: empty Domain/Persistence while Application
63
+ globs still cover I/O (`airtable`, `supabase`, `prisma`, `drizzle`, `repositories`, …).
64
+ Doctor gap id: `contract-false-green-io-under-application`. If so:
65
+ **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`.
66
+ 5. **Suggestive top bets** — 2–5 opportunities ranked (shape, extract, manifiesto, gates/DX),
67
+ separate from mechanical-safe steps. User may defer; still list them.
68
+
69
+ Min bar: **≥8 source files** across **≥3 meaningful directories** (not only files in `steps[]`).
70
+
71
+ For a full reconnaissance report, run or fold in `/ark-explore`.
29
72
 
30
73
  ## Operating modes (detected, not picked)
31
74
 
32
75
  - **Setup (Suggest):** no config → `ark start` / recommend shape.
33
- - **Align (Adapt):** open debt or low honesty → drive loop; do not claim “guarded”.
34
- - **Guard (Enforce):** `goal.met` and solid governed% → install/confirm gates and stop.
76
+ - **Align (Adapt):** open debt, low honesty, or false-green explore + adopt/loop; do not claim “guarded”.
77
+ - **Guard (Enforce):** `goal.met`, solid governed%, no false-green → install/confirm gates and stop.
35
78
 
36
79
  ## Flow
37
80
 
38
- 0. **False-green soft block (mandatory before victory)** Run `ark-check --doctor` (or `--coverage`).
39
- If Domain/Persistence (or similar cores) are **empty** while Application-class globs still cover
40
- I/O dirs (`airtable`, `supabase`, `prisma`, `drizzle`, `repositories`, …), **do not** claim
41
- ENFORCE / `goal.met` from type-only cleanup alone. Route to **`/ark-adopt`** or **`/ark-contract`**
42
- first: reclassify real persistence/auth out of Application. Doctor gap id:
43
- `contract-false-green-io-under-application`.
81
+ 0. **Explore pass** product map + false-green check + suggestive bets (see above).
44
82
  1. **Setup if needed** — `ark start` if no `ark.config.json`. Trust `--recommend` / playbook:
45
83
  `vertical-slice-product` and `ddd-bounded-contexts` are first-class shapes (not hexagonal by default).
46
84
  2. **Origin report** — `ark-check --report ark-report.html` (do not `--reset-origin` unless asked).
47
85
  3. **Plan + code read** — `--plan --json`; read each step’s source/target; group by edge.
48
86
  Treat `peerIsolation` / cross-slice steps as **judgment** (never mechanical-safe).
49
- 4. **Concentrated edge?** — if one edge dominates, route to `/ark-contract` with a **source-based** diagnosis (not freeze).
87
+ 4. **Concentrated edge?** — if one edge dominates:
88
+ **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).
50
89
  5. **Worktree preferred** — discardable git worktree when possible.
51
90
  6. **Mechanical-safe** — only kinds from `/ark-loop` table; one step, validate, rollback.
52
91
  7. **Judgment** — default: propose with full “así te lo re-soluciono”. If user authorized full apply: implement the designed fix, validate, rollback on fail.
53
92
  8. **Manifiesto** — if loose business rules surface (domain logic in UI/core), propose Domain placement + `intentPrefixes` / intents; apply config only via `/ark-contract` discipline (strict check after).
54
- 9. **Final report** — `--report` again; evolution vs origin; honest summary of auto vs judgment vs deferred.
93
+ 9. **Final report** — re-`--report`; evolution vs origin; **explore bets** still open vs auto vs judgment applied vs deferred.
55
94
  10. **Strict check** — `ark-check --strict-config` (dead preset globs are advisory; real violations still fail).
56
95
  11. **Core ratchet (when green)** — if plan `goal.met` and doctor still **ADAPT** only because
57
96
  populated cores are `optional: true`, run `ark-check --ratchet-cores` then `--doctor`.
58
- Never ratchet while active violations remain.
97
+ Never ratchet while active violations remain or false-green gap is open.
59
98
 
60
99
  ## Never
61
100
 
@@ -63,9 +102,25 @@ never weaken the gate).
63
102
  - Claim clean while judgment steps were skipped without user decision.
64
103
  - Claim ENFORCE / “done” when doctor reports `contract-false-green-io-under-application` (adopt first).
65
104
  - Replace host Nest/DI with the runtime kernel unasked.
105
+ - Treat “plan empty” as “architecture is healthy” without the explore pass.
66
106
 
67
107
  ## Done criteria
68
108
 
109
+ - Explore pass completed (product map + paths read + bets listed).
69
110
  - Every applied step validated by real `ark-check`.
70
111
  - Final plan `goal.met` true **or** remaining steps listed with file-level proposals and why blocked.
71
- - Report cites paths you changed and reports HTML paths.
112
+ - Report cites paths you changed, open **opportunities**, and report HTML paths.
113
+
114
+ ## Completion contract (skill incomplete if missing)
115
+
116
+ End with **exactly** these headings (markdown `###`):
117
+
118
+ ### Completion
119
+ - **Sensor:** commands/tools run
120
+ - **Opened:** real paths read (or `n/a` only if pure install/upgrade with no source analysis)
121
+ - **Result:** one-line outcome
122
+ - **Handoff:** `/ark-…` / CLI / `none`
123
+ - **Incomplete?** `no` | `yes — <what is missing>`
124
+
125
+ If a **STOP** handoff applies and you continued as if done, set **Incomplete?** to `yes`.
126
+ **Skill incomplete if missing** any of the bullets above.
@@ -9,6 +9,23 @@ The **one sanctioned way** to change layers/rules/`intentPrefixes`/includes.
9
9
  Also used to **land mined business rules** into the executable manifest (`ark.config.json` + intent naming that `ark://manifest` exposes).
10
10
 
11
11
 
12
+ ## Dual engine (mandatory)
13
+
14
+ | Engine | Role |
15
+ |--------|------|
16
+ | **Deterministic** | CLI / MCP / contract sensors — exit codes, plan kinds, coverage numbers, install status |
17
+ | **Exploratory** | You open **this** repo's real files and product surface before concluding |
18
+
19
+ The CLI is a **sensor**, never the whole job. Claiming done without the exploratory bar for this skill is **incomplete**.
20
+
21
+
22
+ ## Subagent fan-out (optional, host-dependent)
23
+
24
+ If the host supports **parallel subagents** and the task splits cleanly (e.g. multiple
25
+ dirs to sample), fan out read-only scouts; otherwise **fall back to sequential**.
26
+ Parent merges and still emits the **### Completion** contract. Never parallel-write
27
+ the same files or weaken the gate.
28
+
12
29
  ## Related onboarding
13
30
 
14
31
  - **Greenfield:** `/ark-architect` or `ark-check --recommend` / `ark start`.
@@ -50,8 +67,27 @@ Also used to **land mined business rules** into the executable manifest (`ark.co
50
67
 
51
68
  Contract edits are most common in **Align (Adapt)**. In **Guard (Enforce)**, treat edits as high-risk product decisions.
52
69
 
70
+ ## Critical handoffs
71
+
72
+ - 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.
73
+ - 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.
74
+
53
75
  ## Done
54
76
 
55
77
  - Diff of `ark.config.json` explained in plain language.
56
78
  - **Así te lo re-soluciono en el manifiesto** when intents/Domain were part of the request.
57
79
  - Strict check result captured.
80
+
81
+ ## Completion contract (skill incomplete if missing)
82
+
83
+ End with **exactly** these headings (markdown `###`):
84
+
85
+ ### Completion
86
+ - **Sensor:** commands/tools run
87
+ - **Opened:** real paths read (or `n/a` only if pure install/upgrade with no source analysis)
88
+ - **Result:** one-line outcome
89
+ - **Handoff:** `/ark-…` / CLI / `none`
90
+ - **Incomplete?** `no` | `yes — <what is missing>`
91
+
92
+ If a **STOP** handoff applies and you continued as if done, set **Incomplete?** to `yes`.
93
+ **Skill incomplete if missing** any of the bullets above.