arkgate 4.2.1 → 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 (44) hide show
  1. package/CHANGELOG.md +59 -3
  2. package/README.md +19 -6
  3. package/bin/ark-mcp-runtime.mjs +64 -0
  4. package/bin/ark.mjs +55 -1
  5. package/bin/lib/adapter-contract.mjs +88 -5
  6. package/bin/lib/agent-projection-command.mjs +396 -0
  7. package/bin/lib/agent-projection.mjs +319 -0
  8. package/bin/lib/agent-skills-package.mjs +266 -0
  9. package/bin/lib/baseline-key.mjs +32 -0
  10. package/bin/lib/ci-and-commands.mjs +44 -0
  11. package/bin/lib/diagnostic-catalog.mjs +155 -0
  12. package/bin/lib/status-command.mjs +369 -0
  13. package/bin/lib/status-manifest.mjs +394 -0
  14. package/dist/eslint/index.cjs +3 -3
  15. package/dist/eslint/index.js +3 -3
  16. package/dist/index.cjs +46 -11
  17. package/dist/index.d.ts +729 -6
  18. package/dist/index.js +46 -11
  19. package/docs/README.md +6 -6
  20. package/docs/agent-guide.md +112 -14
  21. package/docs/configuration.md +7 -0
  22. package/docs/develop.md +8 -0
  23. package/docs/diagnostics.md +606 -0
  24. package/docs/package-surface.md +18 -8
  25. package/docs/product-voice.md +45 -0
  26. package/docs/use.md +23 -0
  27. package/package.json +7 -1
  28. package/schemas/ark.analysis-result.schema.json +14 -1
  29. package/schemas/ark.status-manifest.schema.json +244 -0
  30. package/server.json +2 -2
  31. package/templates/agent-skills/README.md +59 -0
  32. package/templates/agent-skills/ark-adopt/SKILL.md +171 -0
  33. package/templates/agent-skills/ark-architect/SKILL.md +175 -0
  34. package/templates/agent-skills/ark-autopilot/SKILL.md +242 -0
  35. package/templates/agent-skills/ark-contract/SKILL.md +136 -0
  36. package/templates/agent-skills/ark-coverage/SKILL.md +167 -0
  37. package/templates/agent-skills/ark-explain/SKILL.md +210 -0
  38. package/templates/agent-skills/ark-explore/SKILL.md +377 -0
  39. package/templates/agent-skills/ark-fix/SKILL.md +185 -0
  40. package/templates/agent-skills/ark-loop/SKILL.md +180 -0
  41. package/templates/agent-skills/ark-place/SKILL.md +162 -0
  42. package/templates/agent-skills/ark-runtime/SKILL.md +120 -0
  43. package/templates/agent-skills/ark-think/SKILL.md +133 -0
  44. package/templates/agent-skills/ark-upgrade/SKILL.md +218 -0
@@ -0,0 +1,180 @@
1
+ ---
2
+ name: ark-loop
3
+ description: Drive ark-check --plan to zero active violations. Read real source, auto-apply only mechanical-safe kinds, design judgment from the product tree. CLI validates — you edit code.
4
+ ---
5
+
6
+ # /ark-loop — Apply the plan safely
7
+
8
+ Read Ark’s classified **plan**, work toward **goal.met**, one small step at a time,
9
+ validating every change with `ark-check` and rolling back regressions.
10
+
11
+ Deterministic kinds stay **tight**. Your job is still **exploratory on the files**: open
12
+ importers/targets, see if the plan step is a symptom of wrong shape / false Domain / I/O
13
+ under Application — escalate to `/ark-contract` or `/ark-explore` when the wall is structural.
14
+
15
+ ## When / not when
16
+
17
+ | Use `/ark-loop` when… | Do **not** use it when… |
18
+ |-----------------------|-------------------------|
19
+ | Plan A has steps; drive to `goal.met` | Plan A empty — **stop**; residual Shape → `/ark-explore` / `/ark-autopilot` B |
20
+ | Mechanical-safe + approved judgment only | Full product recon first → explore inside `/ark-autopilot` |
21
+ | User already has a plan and wants the apply loop | Brownfield contract false-green → `/ark-adopt` |
22
+
23
+ **Empty plan is not success for the product** — only for *edge remediation*. If `goal.met` and
24
+ (`goal.designWeak` or non-empty `patternBets` from `--plan --json`): do **not** invent
25
+ mechanical-safe kinds; hand off `/ark-explore` shape-focus or `/ark-autopilot` for dual-plan B.
26
+ Pattern bets always have `neverMechanicalSafe: true` — extraction cards only
27
+ (`docs/brownfield-adoption.md` §6).
28
+
29
+ ## Related onboarding
30
+
31
+ - **Greenfield:** `/ark-architect` or `ark-check --recommend` / `ark start`.
32
+ - **Brownfield:** `/ark-adopt` — match contract to reality; do not force a starter preset.
33
+ - **Map / opportunities:** `/ark-explore`.
34
+ - **Default path:** `ark start` → `/ark-autopilot` → `ark-check --doctor`.
35
+
36
+ ## Dual engine (mandatory)
37
+
38
+ | Engine | Role |
39
+ |--------|------|
40
+ | **Deterministic** | Only the four `mechanical-safe` kinds auto-apply; plan tags; gate re-check |
41
+ | **Exploratory** | Read sources; detect concentrated edges / false-green / wrong layer home before grinding |
42
+
43
+
44
+
45
+ ## MCP workspace binding (mandatory)
46
+
47
+ Before any `ark_*` MCP tool, call `ark_identity` with `project.expectedRoot` set to the exact
48
+ workspace root. Continue only when `binding.status === "matched"` and `authoritative === true`;
49
+ retain `projectIdentity.projectId`, then pass both `expectedRoot` and `expectedProjectId` under
50
+ `project` on every later MCP call. If identity is missing, mismatched, unverified, or the root is
51
+ uncertain, do not consume MCP analysis: use the workspace-local CLI and report that MCP
52
+ restart/retargeting is required. `ark://manifest` never satisfies this preflight.
53
+
54
+ ## Dual plane — layers + ArkRules (mandatory, except /ark-runtime)
55
+
56
+ ArkGate has **two opt-in planes**. The user chooses which to use; you **always label** findings so they never blur.
57
+
58
+ | Plane | What it protects | Where it lives | Sensors / tools |
59
+ |-------|------------------|----------------|-----------------|
60
+ | **Layers** (inter-layer) | Who may import whom, capabilities, pure/forbiddenGlobals, peerIsolation | `ark.config.json` → `layers[]`, `rules[]` | graph check, baseline edges, doctor coverage % |
61
+ | **ArkRules** (intra-layer) | Structure inside a layer + domain invariants as data | `arkRules` map + `arkrules/<ExactLayerName>.json` | structure sensors, invariant coverage, `--rules-inventory`, doctor `rulesUnderContract` |
62
+
63
+ **Rules for every report / answer:**
64
+ 1. Prefix each finding or next step with **`[Layer]`** or **`[ArkRules]`** (or a two-column table with those headers).
65
+ 2. Never call an import-edge violation an “invariant” or an aggregate sensor a “layer deny.”
66
+ 3. Absence of `arkRules` is **valid** — do not force ArkRules unless the user wants them or residual inventory clearly wants a pilot.
67
+ 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).
68
+ 5. CLI helpers: `ark-check --rules-inventory --json`, doctor JSON `rulesUnderContract`, sensors emit `ARKRULE_*` / `INVARIANT_UNCOVERED` with `evidence.arkruleId`.
69
+
70
+
71
+ ### Loop + ArkRules
72
+ - Drive plan to zero **active** debt on the plane the user cares about; keep **[Layer]** and **[ArkRules]** queues separate.
73
+ - One pilot at a time for ArkRules extraction cards (`pilotLoop` / inventory).
74
+
75
+ ## Subagent fan-out (optional, host-dependent)
76
+
77
+ When the user asks to go faster **or** the work naturally splits (multiple packages,
78
+ feature dirs, plan clusters), you **may** dispatch **subagents**:
79
+
80
+ | Host capability | Behavior |
81
+ |-----------------|----------|
82
+ | **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. |
83
+ | **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. |
84
+
85
+ **Rules:**
86
+ 1. Give each subagent a **tight brief**: paths in scope, sensor commands allowed, deliverable shape (paths opened + findings JSON or bullets).
87
+ 2. **No shared mutable files** across parallel writers.
88
+ 3. STOP handoffs and dual-engine rules still apply in every agent.
89
+ 4. Parent owns the **### Completion** block (union of **Opened**, single **Handoff**).
90
+ 5. Do **not** use subagents to weaken the gate or invent `mechanical-safe` kinds.
91
+
92
+ ## Anti-wrapper rule (mandatory)
93
+
94
+ **Forbidden:** re-printing plan JSON without opening sources, or inventing new “safe” kinds.
95
+
96
+ **Required:**
97
+ 1. `--plan --json` as sensor.
98
+ 2. For each step you touch: **read** `file` and `target` source (and enough callers to know the edge).
99
+ 3. **“Así te lo re-soluciono”** — exact edit before applying.
100
+ 4. After each apply: full gate re-run; rollback if targeted violation remains or new ones appear.
101
+ 5. If one edge dominates: **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).
102
+ 6. If empty cores + I/O under Application: **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`.
103
+
104
+ ## mechanical-safe only (auto)
105
+
106
+ | `remediationKind` | What to do |
107
+ |-------------------|------------|
108
+ | `type-only-import-move` | Move type to owning layer; re-export for back-compat |
109
+ | `pure-type-file-relocate` | Relocate pure-type file to owning layer (or rename out of false Domain globs) |
110
+ | `import-type-from-pure-type-module` | Convert value import of pure-type module to `import type` |
111
+ | `import-type-of-type-exports` | Convert value-syntax named import/export of type-only exports from a mixed module to `import type` / `export type` |
112
+ | *(none for port-proof)* | **W6** `port-proof-inject-binding` is **judgment** (arity change) — propose inject; do not auto-apply |
113
+
114
+ Never auto: free value uses of imports, multi-import files, dynamic import/require, forbidden globals, cycles, port-proof inject, multi-file adapter scaffolding without proof.
115
+
116
+ ## Mechanical-edit hygiene (Y04 — outcome gate)
117
+
118
+ - Header injection must **merge into the existing doc comment**; the kept result has one `/**`, not stacked headers.
119
+ - 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.
120
+ - 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.
121
+ - Keep the edit only when the **previously clean file stays typecheck-clean**. Otherwise roll it back and treat the change as judgment.
122
+
123
+ ## Reshape pilots (X04 — physical cohesion, advisory)
124
+
125
+ When `ark-check --doctor --json` carries `doctor.physicalCohesion.reshapePilot.nextPilot`,
126
+ you may run **that one pilot** — never more:
127
+
128
+ 1. Read `physicalCohesion.reshapeDecisions` first. A current rejected/deferred target has no live
129
+ card: respect the explicit record and do not reconstruct it from raw facts. Read a live card's
130
+ `pilotTarget`, `decisionTarget`, `moveSample`/`movesTotal`, `successSignal`, `killSwitch`, `doNot[]`.
131
+ 2. Moves are **proposed only** — enumerate the full move set for the pilot anchor, express it as
132
+ an architecture change map, and validate through the atomic preflight (`ark_prepare_change`
133
+ with the matched `project` envelope / the write gate) **before** any file moves. A move the preflight rejects is a finding, not a
134
+ thing to force.
135
+ 3. Never move anything under `app/` or `pages/` (fixed by framework convention). Never merge
136
+ files here — merges are judgment cards for `/ark-architect` / `/ark-fix`.
137
+ 4. After the move set: full gate re-run + re-doctor. Success = the concept's cluster count drops
138
+ and the verdict stays green; otherwise use the kill switch (revert the move set, nothing else).
139
+ 5. Re-doctor decides whether a next card exists. One pilot per loop iteration, always.
140
+ 6. If the user accepts, defers, or rejects the target, persist that explicit verdict in
141
+ `.ark/reshape-decisions.json` using the card's exact `decisionTarget`, a reason, and optional
142
+ `reviewBy`. `accepted` keeps this execution path; `deferred`/`rejected` stop repeat pressure.
143
+ Never infer a decision from `.ark/golden-pattern.json` prose.
144
+
145
+ ## Steps
146
+
147
+ 1. **Plan** — `ark-check --plan --json` (+ `--baseline` if used). If `goal.met`: stop **A**;
148
+ if design-weak residual is visible, hand off explore/autopilot B — do not claim architecture done.
149
+ 2. **Worktree** — prefer discardable git worktree.
150
+ 3. **Apply mechanical-safe** one-by-one with validate/rollback.
151
+ 4. **Judgment** — propose with source-based design; apply only if user approved (or parent autopilot said full apply).
152
+ 5. **Re-plan** after each round until dry, `goal.met`, or only judgment left without approval.
153
+ 6. **Report** — auto-applied / proposed / deferred with paths; never claim clean if skipped.
154
+
155
+ ## Operating rules
156
+
157
+ - Never weaken the gate (no rule disables, no fresh baselining of new debt).
158
+ - Concentrated single edge → stop and hand to `/ark-contract` with code evidence.
159
+ - When unsure behavior preservation → judgment, not mechanical-safe.
160
+
161
+ ## Done criteria
162
+
163
+ - Gate confirms each kept edit.
164
+ - Honest residual list with **Así te lo re-soluciono** for anything left.
165
+ - If residual steps hide domain/business rules in the wrong layer, call out **manifiesto** work (`intentPrefixes` / Domain placement) via `/ark-contract` or `/ark-adopt`.
166
+
167
+ ## Completion contract (skill incomplete if missing)
168
+
169
+ End with **exactly** these headings (markdown `###`):
170
+
171
+ ### Completion
172
+ - **Sensor:** commands/tools run
173
+ - **Opened:** real paths read (or `n/a` only if pure install/upgrade with no source analysis)
174
+ - **Result:** one-line outcome
175
+ - **Planes:** one-line split of residual **[Layer]** vs **[ArkRules]** (or `n/a` if unused)
176
+ - **Handoff:** `/ark-…` / CLI / `none`
177
+ - **Incomplete?** `no` | `yes — <what is missing>`
178
+
179
+ If a **STOP** handoff applies and you continued as if done, set **Incomplete?** to `yes`.
180
+ **Skill incomplete if missing** any of the bullets above.
@@ -0,0 +1,162 @@
1
+ ---
2
+ name: ark-place
3
+ description: "Where does new code go? Names the layer, directory, and naming for a new artifact from the contract, and scaffolds it there. Autonomous."
4
+ ---
5
+
6
+ # /ark-place — Where does this code go?
7
+
8
+ ## When / not when
9
+
10
+ | Use `/ark-place` when… | Do **not** use it when… |
11
+ |------------------------|-------------------------|
12
+ | New artifact: where + scaffold under contract | Existing violation fix → `/ark-fix` |
13
+ | Naming / directory for a known kind | Contract layers wrong → `/ark-contract`; full shape choice greenfield → `/ark-architect` |
14
+
15
+ The user describes something they need to build (a saga, a background job, an
16
+ event handler, a repository, an HTTP client, a use case, a projection, …).
17
+ Your job: name the layer it belongs to, the directory, the naming convention,
18
+ and — if they asked to build it — scaffold it there correctly.
19
+
20
+ **No artifact given?** If the skill is invoked with nothing to place, don't error
21
+ and don't guess — the artifact is the one thing only the user knows. Read the
22
+ contract (step 1) and print the placement map from it: one row per declared layer
23
+ with what belongs there, its directory, and which layers it may/may not import,
24
+ plus the not-yet-adopted `suggestedLayers` as a footnote. Then ask what they want
25
+ to place. That map is derived entirely from the repo, so producing it is real work,
26
+ not a stalling question.
27
+
28
+ ## Dual engine (mandatory)
29
+
30
+ | Engine | Role |
31
+ |--------|------|
32
+ | **Deterministic** | CLI / MCP / contract sensors — exit codes, plan kinds, coverage numbers, install status |
33
+ | **Exploratory** | You open **this** repo's real files and product surface before concluding |
34
+
35
+ The CLI is a **sensor**, never the whole job. Claiming done without the exploratory bar for this skill is **incomplete**.
36
+
37
+
38
+
39
+ ## MCP workspace binding (mandatory)
40
+
41
+ Before any `ark_*` MCP tool, call `ark_identity` with `project.expectedRoot` set to the exact
42
+ workspace root. Continue only when `binding.status === "matched"` and `authoritative === true`;
43
+ retain `projectIdentity.projectId`, then pass both `expectedRoot` and `expectedProjectId` under
44
+ `project` on every later MCP call. If identity is missing, mismatched, unverified, or the root is
45
+ uncertain, do not consume MCP analysis: use the workspace-local CLI and report that MCP
46
+ restart/retargeting is required. `ark://manifest` never satisfies this preflight.
47
+
48
+ ## Dual plane — layers + ArkRules (mandatory, except /ark-runtime)
49
+
50
+ ArkGate has **two opt-in planes**. The user chooses which to use; you **always label** findings so they never blur.
51
+
52
+ | Plane | What it protects | Where it lives | Sensors / tools |
53
+ |-------|------------------|----------------|-----------------|
54
+ | **Layers** (inter-layer) | Who may import whom, capabilities, pure/forbiddenGlobals, peerIsolation | `ark.config.json` → `layers[]`, `rules[]` | graph check, baseline edges, doctor coverage % |
55
+ | **ArkRules** (intra-layer) | Structure inside a layer + domain invariants as data | `arkRules` map + `arkrules/<ExactLayerName>.json` | structure sensors, invariant coverage, `--rules-inventory`, doctor `rulesUnderContract` |
56
+
57
+ **Rules for every report / answer:**
58
+ 1. Prefix each finding or next step with **`[Layer]`** or **`[ArkRules]`** (or a two-column table with those headers).
59
+ 2. Never call an import-edge violation an “invariant” or an aggregate sensor a “layer deny.”
60
+ 3. Absence of `arkRules` is **valid** — do not force ArkRules unless the user wants them or residual inventory clearly wants a pilot.
61
+ 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).
62
+ 5. CLI helpers: `ark-check --rules-inventory --json`, doctor JSON `rulesUnderContract`, sensors emit `ARKRULE_*` / `INVARIANT_UNCOVERED` with `evidence.arkruleId`.
63
+
64
+
65
+ ### Place + ArkRules
66
+ - Choose layer from contract **and** check structure sensors for that layer (private state, factory, thin adapter).
67
+ - Scaffold to satisfy **[ArkRules]** when present; state which sensors apply.
68
+
69
+ ## Subagent fan-out (optional, host-dependent)
70
+
71
+ If the host supports **parallel subagents** and the task splits cleanly (e.g. multiple
72
+ dirs to sample), fan out read-only scouts; otherwise **fall back to sequential**.
73
+ Parent merges and still emits the **### Completion** contract. Never parallel-write
74
+ the same files or weaken the gate.
75
+
76
+ ## Steps
77
+
78
+ 1. **Read the contract, not your intuition.** If the `ark` MCP server is available, complete
79
+ the mandatory `ark_identity` preflight first, then call **`ark_place`** with the target file
80
+ path and bound `project` envelope — it returns the layer,
81
+ its forbidden globals, and exactly which layers the file may / must not import,
82
+ straight from the contract (no guessing). When present, also honor optional
83
+ **`goldenPattern`** (from `.ark/golden-pattern.json`) for **NEW code only** —
84
+ advisory layout norm; never overrides the gate and never clears design-weak.
85
+ Absent golden is normal. Otherwise load `ark.config.json`; after the matched preflight,
86
+ `ark_manifest` with the same bound envelope includes `suggestedLayers` with conventional
87
+ directories for layers not yet adopted. The `ark://manifest` resource is compatibility-only and always
88
+ unverified/non-authoritative. The project's `AGENTS.md` placement table, if present, is
89
+ authoritative too.
90
+ 2. **Classify the artifact** by what it does, not what it's called:
91
+ - Pure business rules/entities/value objects → domain-model layer.
92
+ - When Domain ArkRules require private state / factories (`aggregate-private-state`,
93
+ `always-valid-factory`), scaffold private fields + static factory — do not emit public
94
+ mutable aggregates.
95
+ - Orchestrates a use case, no I/O of its own → application layer.
96
+ - Talks to a database, queue, API, filesystem → an adapter layer on the side
97
+ that matches the direction (driven/persistence vs driving/http).
98
+ - Reacts to events, long-running coordination (saga/workflow), scheduled
99
+ jobs, projections → the event/workflow layers if the config declares them.
100
+ - **`vertical-slice` contract:** put co-located feature code under
101
+ `src/features/<slice>/…` (never import a sibling slice); shared primitives
102
+ under `src/shared/`; infra under `src/lib/`; shell under `src/app/`.
103
+ - **`ddd-bounded-contexts` contract:** put code under
104
+ `src/contexts/<context>/{domain,application,infrastructure,presentation}/`;
105
+ shared kernel only under `src/shared/kernel/`. Cross-context imports at the
106
+ same technical layer are peerIsolation violations.
107
+ 3. **Answer concretely**: layer name, target directory (from the layer's
108
+ `patterns`), intent-name prefix if the layer declares `intentPrefixes`, and
109
+ which layers it may/may not import (from `rules`).
110
+ 4. **If the layer isn't adopted yet** (suggested but no directory): say so,
111
+ give the conventional directory from `suggestedLayers`, and offer
112
+ `/ark-contract` to adopt it — don't silently drop the code into a
113
+ wrong-but-existing layer.
114
+ 5. **If asked to create it**: scaffold the file(s) in place, following the
115
+ nearest existing sibling's style, and any port/adapter split the rules force.
116
+
117
+ ## Critical handoffs
118
+
119
+ - If the user needs bulk adoption / wrong contract, not a single artifact: **STOP — do not continue this skill as complete.** **STOP — wrong skill: invoke /ark-adopt or /ark-contract** instead of ad-hoc multi-file grinding without a plan.
120
+ - If contract lacks a home for the artifact: **STOP — do not continue this skill as complete.** Adopt the layer via `/ark-contract` first.
121
+ - If doctor is **ENFORCE · design-weak** and the user is asking to reshape existing structure
122
+ (not place one new artifact): place only the new file under the golden/contract home, then
123
+ hand off **one** pilot via `pilotLoop.nextPilot` / `/ark-explore` shape-focus — never multi-pilot
124
+ batch reshape from this skill.
125
+
126
+ ## Operating rules
127
+
128
+ - Never ask "which layer do you prefer?" — the contract decides; you translate.
129
+ Only surface a question when the artifact genuinely spans two legal designs
130
+ with different trade-offs, and then recommend one.
131
+ - Explain the placement in one plain-language sentence ("this goes in
132
+ `src/domain` because it's a business rule that shouldn't know about the
133
+ database") — assume the user may be new to layered architecture.
134
+
135
+ ## Related onboarding
136
+
137
+ - Run **after** shape adoption: `/ark-architect` or `ark init --archetype` on greenfield;
138
+ `/ark-adopt` on brownfield.
139
+ - `ark-check --recommend` / MCP `ark_recommend` picks phase-1 dirs; gallery starters in
140
+ `examples/*-starter/` show correct placement per archetype.
141
+ - Related demos: `docs/demos/` (write-gate self-correction, brownfield, autopilot).
142
+
143
+ ## Verify and report
144
+
145
+ If you created files, run `ark-check --root . --config ark.config.json
146
+ --strict-config` and make it pass. Report: placement + why, files created (if
147
+ any), and the import rules the new code must respect going forward.
148
+
149
+ ## Completion contract (skill incomplete if missing)
150
+
151
+ End with **exactly** these headings (markdown `###`):
152
+
153
+ ### Completion
154
+ - **Sensor:** commands/tools run
155
+ - **Opened:** real paths read (or `n/a` only if pure install/upgrade with no source analysis)
156
+ - **Result:** one-line outcome
157
+ - **Planes:** one-line split of residual **[Layer]** vs **[ArkRules]** (or `n/a` if unused)
158
+ - **Handoff:** `/ark-…` / CLI / `none`
159
+ - **Incomplete?** `no` | `yes — <what is missing>`
160
+
161
+ If a **STOP** handoff applies and you continued as if done, set **Incomplete?** to `yes`.
162
+ **Skill incomplete if missing** any of the bullets above.
@@ -0,0 +1,120 @@
1
+ ---
2
+ name: ark-runtime
3
+ description: Evaluate the experimental Ark runtime kernel against hand-rolled event bus, outbox, audit, saga, projection, policy, or NestJS code. Finds one candidate, wires one, verifies.
4
+ ---
5
+
6
+ # /ark-runtime — Evaluate the runtime kernel (experimental opt-in)
7
+
8
+ The runtime kernel is currently **experimental** and is not required for ArkGate enforcement or
9
+ presented as production-ready. Use this skill only when the user explicitly wants to evaluate it.
10
+
11
+ The separate `@arkgate/runtime` source package contains the experimental runtime kernel
12
+ (`createArkKernel`) with an event bus, event contracts, outbox, audit trail,
13
+ policy engine, workflow/saga coordination, projections, observability hooks,
14
+ and NestJS adapters. The stable `arkgate` package is the architecture gate; it does not bundle
15
+ the runtime implementation. This skill migrates hand-rolled versions of those to the kernel,
16
+ one feature at a time.
17
+
18
+ ## Dual engine (mandatory)
19
+
20
+ | Engine | Role |
21
+ |--------|------|
22
+ | **Deterministic** | CLI / MCP / contract sensors — exit codes, plan kinds, coverage numbers, install status |
23
+ | **Exploratory** | You open **this** repo's real files and product surface before concluding |
24
+
25
+ The CLI is a **sensor**, never the whole job. Claiming done without the exploratory bar for this skill is **incomplete**.
26
+
27
+ ## MCP workspace binding (mandatory)
28
+
29
+ Before any `ark_*` MCP tool, call `ark_identity` with `project.expectedRoot` set to the exact
30
+ workspace root. Continue only when `binding.status === "matched"` and `authoritative === true`;
31
+ retain `projectIdentity.projectId`, then pass both `expectedRoot` and `expectedProjectId` under
32
+ `project` on every later MCP call. If identity is missing, mismatched, unverified, or the root is
33
+ uncertain, do not consume MCP analysis: use the workspace-local CLI and report that MCP
34
+ restart/retargeting is required. `ark://manifest` never satisfies this preflight.
35
+
36
+ ## Out of scope for ArkRules
37
+
38
+ This skill is **runtime-kernel only**. Do not mix ArkRules structure/invariants here; hand off to `/ark-contract` / `/ark-adopt` / `/ark-explore` for static contract planes.
39
+
40
+ ## Subagent fan-out (optional, host-dependent)
41
+
42
+ If the host supports **parallel subagents** and the task splits cleanly (e.g. multiple
43
+ dirs to sample), fan out read-only scouts; otherwise **fall back to sequential**.
44
+ Parent merges and still emits the **### Completion** contract. Never parallel-write
45
+ the same files or weaken the gate.
46
+
47
+ ## Steps
48
+
49
+ 1. **Inventory** — grep the codebase for hand-rolled equivalents:
50
+ - event bus / emitter used for domain events (`EventEmitter`, homemade
51
+ pub/sub, ad-hoc handler registries)
52
+ - outbox tables or "save event + publish later" code
53
+ - audit/history logs written manually
54
+ - saga/workflow orchestration (multi-step processes with compensation)
55
+ - read-model/projection builders
56
+ - policy/authorization checks scattered across use cases
57
+ Also check whether `@nestjs/common` is present → the `@arkgate/runtime/nestjs`
58
+ adapters apply.
59
+ 2. **Pick ONE target** — the smallest, most self-contained candidate (fewest
60
+ call sites). Migrating everything at once is how adoptions die. List the
61
+ rest as follow-ups in the report.
62
+ 3. **Resolve availability** — run `npm view @arkgate/runtime dist-tags --json`. If an
63
+ `experimental` tag exists, install that exact companion. Otherwise continue only from an
64
+ ArkGate source checkout: run `npm run build:runtime` at its root and install its local
65
+ `packages/runtime` folder into the target. Outside a source checkout, stop and report that the
66
+ runtime is unavailable; never fall back to the deprecated root shims as if they contained it.
67
+ 4. **Migrate** — import from `@arkgate/runtime` or `@arkgate/runtime/nestjs`, and read the
68
+ [runtime package guide](https://github.com/pedroknigge/arkgate/blob/main/packages/runtime/README.md)
69
+ plus the [experimental surface policy](https://github.com/pedroknigge/arkgate/blob/main/docs/package-surface.md#experimental-opt-in-surfaces) before
70
+ writing code. Wire the kernel at the composition root; keep the domain
71
+ ignorant of it (handlers/ports, not kernel imports inside domain code —
72
+ the architecture check enforces this; Claude/Grok hooks can block it earlier). Note: the kernel bounds in-memory
73
+ history by default (`maxHistorySize` 1000); mention this if the hand-rolled
74
+ version retained everything.
75
+ 5. **Delete the hand-rolled version** once call sites are moved — the point is
76
+ less code, not a second parallel system. Deleting code is a destructive move:
77
+ confirm with the user before removing the old implementation, and never delete
78
+ something the inventory only *suspects* is dead (a misclassified load-bearing
79
+ emitter must not be removed on a guess).
80
+
81
+ ## Critical handoffs
82
+
83
+ - No static gates yet: **STOP — do not continue this skill as complete.** Run `/ark-architect` or `/ark-adopt` first.
84
+ - Runtime companion unavailable from npm and no ArkGate source checkout: **STOP** and report the distribution boundary.
85
+ - Inventory finds nothing: stop; do not introduce kernel speculatively.
86
+
87
+ ## Operating rules
88
+
89
+ - If the inventory finds NO hand-rolled equivalents, say so and stop — do not
90
+ introduce the runtime kernel speculatively. Static enforcement alone is a
91
+ complete, valid use of Ark.
92
+ - Keep the migration diff reviewable: one feature per invocation.
93
+ - Plain-language reporting: one sentence per concept ("outbox = events are
94
+ saved in the same transaction as your data, then published — so you never
95
+ publish something that didn't commit").
96
+
97
+ ## Related onboarding
98
+
99
+ - Adopt static gates and application shape **first** (`/ark-architect`, `/ark-adopt`).
100
+ - Runtime kernel is optional and separate from enthusiast onboarding.
101
+
102
+ ## Verify and report
103
+
104
+ Run the project's tests plus `ark-check --root . --config ark.config.json
105
+ --strict-config`. Report: what was migrated, lines deleted vs added, remaining
106
+ candidates ranked, and any behavior differences (e.g. bounded history).
107
+
108
+ ## Completion contract (skill incomplete if missing)
109
+
110
+ End with **exactly** these headings (markdown `###`):
111
+
112
+ ### Completion
113
+ - **Sensor:** commands/tools run
114
+ - **Opened:** real paths read (or `n/a` only if pure install/upgrade with no source analysis)
115
+ - **Result:** one-line outcome
116
+ - **Handoff:** `/ark-…` / CLI / `none`
117
+ - **Incomplete?** `no` | `yes — <what is missing>`
118
+
119
+ If a **STOP** handoff applies and you continued as if done, set **Incomplete?** to `yes`.
120
+ **Skill incomplete if missing** any of the bullets above.
@@ -0,0 +1,133 @@
1
+ ---
2
+ name: ark-think
3
+ description: Host-side architectural reasoning — 2–3 enforceable options on layer and/or ArkRules planes for ONE decision. Not full recon (use /ark-explore). No gate bypass. No package LLM call.
4
+ ---
5
+
6
+ # /ark-think — Architectural reasoning (host LLM only)
7
+
8
+ You are the user's architecture thinking partner **inside** the project's Ark contract.
9
+ This skill does **not** call any LLM API from the arkgate package. **You** (the host agent)
10
+ reason; the write-gate and CI remain deterministic.
11
+
12
+ ## When / not when
13
+
14
+ | Use `/ark-think` when… | Do **not** use it when… |
15
+ |------------------------|-------------------------|
16
+ | One decision: new layer vs slice, port vs shared, peerIsolation choice | Full map / ranked residual / dual-plan seed → `/ark-explore` |
17
+ | 2–3 options already bounded by a known surface | Apply remediation → `/ark-fix` / `/ark-loop` / `/ark-autopilot` |
18
+ | Trade-offs before writing a **new** feature | Brownfield contract wrong / false-green → `/ark-adopt` then `/ark-contract` |
19
+ | Explain *why* a rule exists in *this* tree | HTML tour → `/ark-explain`; fitness numbers → `/ark-coverage` |
20
+
21
+ If you lack a product map and the tree is messy: run a **compressed** explore pass first
22
+ (≥8 files) **or** **STOP** and invoke `/ark-explore` — do not invent options from diagrams alone.
23
+
24
+ ## Dual engine (mandatory)
25
+
26
+ | Engine | Role |
27
+ |--------|------|
28
+ | **Deterministic** | What the contract and doctor *prove* today (layers, rules, governed%, gaps) |
29
+ | **Exploratory** | What *this* decision surface wants — options grounded in files you open |
30
+
31
+ Never reason only from abstract hexagons. Open real modules before recommending a shape.
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
+ ### Think + ArkRules
61
+ - For ONE decision, consider options on **both** planes when relevant: e.g. new layer wall **vs** structure sensor **vs** invariant catalog entry.
62
+ - Every option must state enforceability: which plane holds it after the change.
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
+ ## Steps
82
+
83
+ 1. **Load the contract** — `ark.config.json`; when MCP is available, call `ark_identity` with
84
+ the exact project root followed by `ark_manifest` with the same root plus returned project
85
+ id. The `ark://manifest` resource is compatibility-only and always
86
+ unverified/non-authoritative. Use `ark-check --coverage --json` / `--doctor` for honesty
87
+ about governed% and false-green.
88
+ 2. **Touch the decision surface** — README skim + **≥5 source files** on the feature/package/boundary
89
+ under discussion. Name paths in the answer.
90
+ 3. **Name the active shape** — which preset/archetype fits (hexagonal, vertical-slice,
91
+ ddd-bounded-contexts, feature-sliced, monorepo, …). If none, run `--recommend --json`
92
+ **and** say whether detection matches the tree you opened.
93
+ 4. **Name concurrent patterns** on the decision surface (if ≥2): which is **golden** vs legacy.
94
+ 5. **Reason within bounds** — propose **2–3 options** that **stay enforceable** by the gate.
95
+ Prefer concrete paths and import rules over abstract diagrams.
96
+ 6. **Explore alternatives** — for each option: coupling, testability, **AI-agent safety**,
97
+ migration cost, **pilot + kill-switch** if the option adds a layer or wall.
98
+ 7. **Surface hard lines** — never suggest: weakening `ark.config.json` to pass, silent
99
+ judgment auto-apply, codemod engines, or skipping write-gate/CI.
100
+ 8. **Hand off** — placement `/ark-place`; config `/ark-contract`; bulk debt `/ark-loop` /
101
+ `/ark-autopilot`; map-only `/ark-explore`; violations `/ark-fix`.
102
+ When the user needs action not advice: **STOP — do not continue this skill as complete** — invoke the handoff skill.
103
+
104
+ ## Output format
105
+
106
+ - **Context:** product + contract + what you opened (paths) + phase if known (Align/Stabilize/Shape)
107
+ - **Options:** 2–3 alternatives with trade-offs (coupling, testability, agent safety, enforceability)
108
+ - **Recommendation:** one option + why it is enforceable **today**
109
+ - **Pilot / kill-switch:** if the choice changes shape or adds a layer
110
+ - **Risks if we pick wrong:** one sentence user-visible impact
111
+ - **Next command:** exact `ark-check` / skill to run next
112
+
113
+ ## Related
114
+
115
+ - Greenfield shape: `/ark-architect`
116
+ - Brownfield: `/ark-adopt`
117
+ - Full recon / dual-plan seed: `/ark-explore`
118
+ - Explain existing: `/ark-explain`
119
+
120
+ ## Completion contract (skill incomplete if missing)
121
+
122
+ End with **exactly** these headings (markdown `###`):
123
+
124
+ ### Completion
125
+ - **Sensor:** commands/tools run
126
+ - **Opened:** real paths read (or `n/a` only if pure install/upgrade with no source analysis)
127
+ - **Result:** one-line outcome
128
+ - **Planes:** one-line split of residual **[Layer]** vs **[ArkRules]** (or `n/a` if unused)
129
+ - **Handoff:** `/ark-…` / CLI / `none`
130
+ - **Incomplete?** `no` | `yes — <what is missing>`
131
+
132
+ If a **STOP** handoff applies and you continued as if done, set **Incomplete?** to `yes`.
133
+ **Skill incomplete if missing** any of the bullets above.