arkgate 4.2.1 → 4.4.0

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