arkgate 4.6.6 → 4.7.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 (66) hide show
  1. package/CHANGELOG.md +139 -2
  2. package/README.md +22 -10
  3. package/SECURITY.md +1 -1
  4. package/bin/ark-check-runtime.mjs +21 -341
  5. package/bin/ark-mcp-runtime.mjs +71 -325
  6. package/bin/ark-shared.mjs +24 -158
  7. package/bin/lib/adapter-contract.mjs +17 -36
  8. package/bin/lib/analysis-engine.mjs +6 -6
  9. package/bin/lib/ark-run-doctor.mjs +144 -0
  10. package/bin/lib/ark-run-facts.mjs +472 -0
  11. package/bin/lib/ark-run-report.mjs +57 -0
  12. package/bin/lib/ark-run-sensors.mjs +309 -0
  13. package/bin/lib/check-args.mjs +173 -0
  14. package/bin/lib/check-config-detect.mjs +101 -0
  15. package/bin/lib/check-watch.mjs +80 -0
  16. package/bin/lib/config-contract.mjs +86 -11
  17. package/bin/lib/deep-module-coach.mjs +3 -0
  18. package/bin/lib/diagnostic-catalog.mjs +8 -0
  19. package/bin/lib/doctor-advisories.mjs +45 -8
  20. package/bin/lib/doctor-human.mjs +519 -0
  21. package/bin/lib/doctor-plan.mjs +62 -445
  22. package/bin/lib/extra-merge-teeth.mjs +187 -0
  23. package/bin/lib/github-enforcement.mjs +22 -9
  24. package/bin/lib/html-report-advisories.mjs +2 -0
  25. package/bin/lib/html-report-depth.mjs +22 -2
  26. package/bin/lib/html-report.mjs +40 -7
  27. package/bin/lib/mcp-hook-payload.mjs +328 -0
  28. package/bin/lib/package-manager.mjs +174 -0
  29. package/bin/lib/policy-delta-io.mjs +4 -0
  30. package/bin/lib/remediation.mjs +132 -0
  31. package/bin/lib/resolved-candidate-facts.mjs +67 -2
  32. package/bin/lib/rules-under-contract.mjs +37 -89
  33. package/bin/lib/snippet-analysis.mjs +43 -2
  34. package/bin/lib/status-command.mjs +28 -0
  35. package/bin/lib/status-manifest.mjs +23 -0
  36. package/bin/lib/team-parliament-io.mjs +4 -0
  37. package/dist/{configTypes-l6XiwiC1.d.ts → configTypes-CgJimx9o.d.ts} +17 -3
  38. package/dist/eslint/index.cjs +6 -2
  39. package/dist/eslint/index.d.ts +70 -2
  40. package/dist/eslint/index.js +6 -2
  41. package/dist/index.cjs +35 -35
  42. package/dist/index.d.ts +787 -272
  43. package/dist/index.js +35 -35
  44. package/docs/README.md +4 -3
  45. package/docs/agent-guide.md +21 -15
  46. package/docs/ai-gates.md +13 -0
  47. package/docs/configuration.md +24 -11
  48. package/docs/develop.md +12 -3
  49. package/docs/diagnostics.md +75 -0
  50. package/docs/enthusiast/README.md +4 -3
  51. package/docs/package-surface.md +17 -13
  52. package/docs/product-voice.md +6 -3
  53. package/docs/threat-model.md +1 -1
  54. package/docs/use.md +5 -4
  55. package/package.json +1 -1
  56. package/schemas/ark.config.schema.json +41 -2
  57. package/schemas/ark.resolved-candidate-facts.schema.json +1 -1
  58. package/schemas/ark.status-manifest.schema.json +47 -0
  59. package/server.json +2 -2
  60. package/templates/agent-skills/README.md +1 -1
  61. package/templates/agent-skills/ark-adopt/SKILL.md +23 -2
  62. package/templates/agent-skills/ark-place/SKILL.md +26 -2
  63. package/templates/agent-skills/ark-runtime/SKILL.md +66 -24
  64. package/templates/skills/ark-adopt.md +23 -2
  65. package/templates/skills/ark-place.md +26 -2
  66. package/templates/skills/ark-runtime.md +66 -24
@@ -19,6 +19,9 @@ description: "Where does new code go? Names the layer, directory, and naming for
19
19
  - `filePath` is known before the call. Description alone is not a path.
20
20
  - Golden pattern is load-bearing when present. Adopt generates it.
21
21
  - Do not default a repository to Presentation.
22
+ - When `arkRun` is on: scaffold through the kernel (no `new` of managed types; declare
23
+ `uses` / `reactsTo` / `raises` / `sends`). Extra off → do not introduce the kernel. Enable it
24
+ via `/ark-adopt`. Skills never enforce.
22
25
 
23
26
  ## Autonomy contract
24
27
 
@@ -62,6 +65,7 @@ patterns are **out-of-scope** lenses — say so; do not invent Ark enforcement f
62
65
  |------------------------|-------------------------|
63
66
  | New artifact: where + **write** under the config | Existing violation cluster → `/ark-autopilot` |
64
67
  | Naming / directory for a known kind | Session 0 / config missing or lying → `/ark-adopt` (then come back) |
68
+ | Kernel-managed artifact when `arkRun` is already on | Extra not chosen yet → `/ark-adopt` (advisory `arkRun`); evaluate / migrate a hand-rolled bus → `/ark-runtime` |
65
69
 
66
70
  The user describes something they need to build (a saga, a background job, an
67
71
  event handler, a repository, an HTTP client, a use case, a projection, …).
@@ -104,19 +108,32 @@ ArkGate has **two opt-in planes**. The user chooses which to use; you **always l
104
108
  |-------|------------------|----------------|-----------------|
105
109
  | **Layers** (inter-layer) | Who may import whom, capabilities, pure/forbiddenGlobals, peerIsolation | `ark.config.json` → `layers[]`, `rules[]` | graph check, baseline edges, doctor coverage % |
106
110
  | **ArkRules** (intra-layer) | Structure inside a layer + domain invariants as data | `arkRules` map + `arkrules/<ExactLayerName>.json` | structure sensors, invariant coverage, `--rules-inventory`, doctor `rulesUnderContract` |
111
+ | **ArkRun** (extra) | Kernel usage + complete declarations | `arkRun` on `ark.config.json` (schema `1.2+`) + companion `@arkgate/runtime` | `ARKRUN_*`, doctor `arkRun` (`notAScore`) |
107
112
 
108
113
  **Rules for every report / answer:**
109
- 1. Prefix each finding or next step with **`[Layer]`** or **`[ArkRules]`** (or a two-column table with those headers).
114
+ 1. Prefix each finding or next step with **`[Layer]`** or **`[ArkRules]`** or **`[ArkRun]`** (or a two-column table with those headers).
110
115
  2. Never call an import-edge violation an “invariant” or an aggregate sensor a “layer deny.”
111
116
  3. Absence of `arkRules` is **valid** — do not force ArkRules unless the user wants them or residual inventory clearly wants a pilot.
112
117
  4. Missing layer home: add it via **`/ark-adopt`** in this session if needed, then write the file; never invent `mechanical-safe`.
113
118
  5. CLI helpers: `ark-check --rules-inventory --json`, doctor JSON `rulesUnderContract`, sensors emit `ARKRULE_*` / `INVARIANT_UNCOVERED` with `evidence.arkruleId`.
119
+ 6. Absence of `arkRun` is **valid**. Do not introduce the kernel speculatively. Skills never enforce this extra.
114
120
 
115
121
 
116
122
  ### Place + ArkRules
117
123
  - Choose layer from contract **and** check structure sensors for that layer (private state, factory, thin adapter).
118
124
  - Scaffold to satisfy **[ArkRules]** when present; state which sensors apply.
119
125
 
126
+ ### Place + ArkRun
127
+ When `arkRun` is present on the architecture config:
128
+ - Scaffold kernel-managed artifacts **through the kernel**, not `new` of an admitted type (`ARKRUN_DIRECT_NEW`).
129
+ - Call `createStrictArkKernel` (or an admission sibling) only inside `arkRun.compositionRoots`. Each call is a new instance — no process-wide `getKernel()`.
130
+ - Domain-role files stay kernel-free (`ARKRUN_KERNEL_IN_DOMAIN`). Import from `@arkgate/runtime` (or `/nestjs`), never a removed `arkgate/runtime` shim.
131
+ - List `uses` / `reactsTo` / `raises` / `sends` when `requireDeclarations` is on. Adding an existing call-site literal to the declaration list is the only mechanical-safe ArkRun edit; inventing a new emit / handle / depend is judgment.
132
+ - Do not import a homemade bus (`EventEmitter`, queue clients) in `managedLayers` — send on the kernel transport (`local` / `localBlocking` / `broker`; `ephemeral` defaults true). No shipped cloud SDKs.
133
+ - In-memory stores are **not** production durability. Doctor `arkRun` is `notAScore`.
134
+ - Absence of the extra: place with **[Layer]** + **[ArkRules]** only. Enable advisory extra via `/ark-adopt`; evaluate a hand-rolled bus via `/ark-runtime`. Do not invent `/ark-run`.
135
+ - Skills never enforce.
136
+
120
137
  ## Subagent fan-out (optional, host-dependent)
121
138
 
122
139
  If the host supports **parallel subagents** and the task splits cleanly (e.g. multiple
@@ -148,6 +165,10 @@ the same files or weaken the gate.
148
165
  that matches the direction (driven/persistence vs driving/http).
149
166
  - Reacts to events, long-running coordination (saga/workflow), scheduled
150
167
  jobs, projections → the event/workflow layers if the config declares them.
168
+ When `arkRun` is on, wire those through the kernel (register + declarations),
169
+ not a homemade emitter.
170
+ - Kernel-managed application service when `arkRun` is on → composition-root factory
171
+ + `register({ uses, reactsTo, raises, sends })`; never `new` of the admitted type.
151
172
  - **`vertical-slice` contract:** put co-located feature code under
152
173
  `src/features/<slice>/…` (never import a sibling slice); shared primitives
153
174
  under `src/shared/`; infra under `src/lib/`; shell under `src/app/`.
@@ -175,6 +196,9 @@ the same files or weaken the gate.
175
196
  (not place one new artifact): place only the new file under the golden/contract home, then
176
197
  hand off **one** pilot via `pilotLoop.nextPilot` / `/ark-explore` shape-focus — never multi-pilot
177
198
  batch reshape from this skill.
199
+ - If `arkRun` is on and the user is grinding skip violations (`new` of managed types, homemade
200
+ bus) across many files: place this artifact through the kernel, then leftover `/ark-fix` /
201
+ `/ark-autopilot`. Extra not on → `/ark-adopt` (advisory) or `/ark-runtime` (evaluate).
178
202
 
179
203
  ## Operating rules
180
204
 
@@ -207,7 +231,7 @@ End with **exactly** these headings (markdown `###`):
207
231
  - **Sensor:** commands/tools run
208
232
  - **Opened:** real paths read (or `n/a` only if pure install/upgrade with no source analysis)
209
233
  - **Result:** one-line outcome
210
- - **Planes:** one-line split of residual **[Layer]** vs **[ArkRules]** (or `n/a` if unused)
234
+ - **Planes:** one-line split of residual **[Layer]** vs **[ArkRules]** vs **[ArkRun]** (or `n/a` if unused)
211
235
  - **Compass:** top residual lenses | `n/a`
212
236
  - **Done axes:** architecture residual (status/doctor/compass) | feature/ticket residual (outside package). Enforce green ≠ feature done
213
237
  - **Handoff:** `/ark-…` / CLI / `none`
@@ -1,25 +1,36 @@
1
1
  ---
2
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.
3
+ description: Evaluate and wire the experimental ArkRun companion (@arkgate/runtime) against hand-rolled event bus, outbox, saga, projection, policy, or NestJS code. One candidate. Extra on via /ark-adopt; new files via /ark-place. Skills never enforce.
4
4
  ---
5
5
 
6
- # /ark-runtime — Evaluate the runtime kernel (experimental opt-in)
6
+ # /ark-runtime — Evaluate and wire ArkRun (experimental opt-in)
7
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.
8
+ The ArkRun companion (`@arkgate/runtime`) is currently **experimental**. It is **not** required
9
+ for ArkGate enforcement and is **not** production durability. Use this skill when the user wants
10
+ to evaluate or wire the kernel. **This skill never enforces** — the write / CI / ESLint plane
11
+ does when the `arkRun` extra is on. Do **not** invent `/ark-run`.
10
12
 
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.
13
+ **When:** evaluate a hand-rolled bus / outbox / saga / projection / policy / Nest adapter against
14
+ the companion, or wire an extra that is already on (composition root, declarations, transport).
15
+ **Not when:** session 0 / extra not chosen (`/ark-adopt`); one new file (`/ark-place`); skip-violation
16
+ grind (`/ark-autopilot` / leftover `/ark-fix`).
17
+
18
+ ## Extra vs companion (mandatory)
19
+
20
+ | Piece | What it is | What it is not |
21
+ |-------|------------|----------------|
22
+ | **ArkRun extra** (`arkRun` on `ark.config.json`, schema `1.2+`) | Gate contract: kernel usage + complete declarations | A score; Layers / ArkRules replacement; merge teeth while `advisory` |
23
+ | **Companion** `@arkgate/runtime` | Kernel you construct with `createStrictArkKernel` (one instance per call) | Bundled in the `arkgate` tarball; a process-wide `getKernel()`; shipped cloud broker SDKs |
24
+
25
+ Absence of the extra is **silent** — Layers and ArkRules verdicts stay identical. Doctor / status
26
+ `arkRun` is always `notAScore`. Never invent 0–10 scores or pass/fail from this skill.
17
27
 
18
28
  ## Improvement compass note
19
29
 
20
30
  This skill is **experimental runtime** only. Do **not** treat runtime adoption as residual on the
21
31
  resilience lens unless the user explicitly opts into the experimental kernel. Prefer doctor compass
22
32
  for static architecture residual; hand static residual to `/ark-explore` / `/ark-autopilot`.
33
+ Doctor `arkRun` residual is a finding-id count (`ARKRUN_*`), never a compass score.
23
34
 
24
35
  ## Dual engine (mandatory)
25
36
 
@@ -41,7 +52,7 @@ restart/retargeting is required. `ark://manifest` never satisfies this preflight
41
52
 
42
53
  ## Out of scope for ArkRules
43
54
 
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.
55
+ 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. Label kernel-usage residual **`[ArkRun]`** so it never blurs with **`[Layer]`** or **`[ArkRules]`**.
45
56
 
46
57
  ## Subagent fan-out (optional, host-dependent)
47
58
 
@@ -62,23 +73,45 @@ the same files or weaken the gate.
62
73
  - policy/authorization checks scattered across use cases
63
74
  Also check whether `@nestjs/common` is present → the `@arkgate/runtime/nestjs`
64
75
  adapters apply.
65
- 2. **Pick ONE target** — the smallest, most self-contained candidate (fewest
76
+ 2. **Read the extra** — open `ark.config.json`. If `arkRun` is absent and the user wants the extra,
77
+ **STOP — do not continue this skill as complete.** Handoff **`/ark-adopt`** to write **advisory**
78
+ `arkRun` (schema `1.2+`; `compositionRoots`, `managedLayers`, `requireDeclarations`). Do not
79
+ invent the extra here. If the extra is present, note `mode`, roots, managed layers, and
80
+ `requireDeclarations`; doctor `arkRun` is `notAScore`.
81
+ 3. **Pick ONE target** — the smallest, most self-contained candidate (fewest
66
82
  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
83
+ rest as follow-ups in the report. New files after the extra is on go through **`/ark-place`**.
84
+ 4. **Resolve availability** — run `npm view @arkgate/runtime dist-tags --json`. If an
69
85
  `experimental` tag exists, install that exact companion. Otherwise continue only from an
70
86
  ArkGate source checkout: run `npm run build:runtime` at its root and install its local
71
87
  `packages/runtime` folder into the target. Outside a source checkout, stop and report that the
72
88
  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
89
+ Import from `@arkgate/runtime` (or `@arkgate/runtime/nestjs`) never a removed `arkgate/runtime`
90
+ shim.
91
+ 5. **Wire through the kernel** — read the
74
92
  [runtime package guide](https://github.com/pedroknigge/arkgate/blob/main/packages/runtime/README.md)
75
93
  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
94
+ writing code.
95
+ - Call `createStrictArkKernel` (or an admission sibling: `createArkKernel`, `*FromConfig`) **only**
96
+ inside `arkRun.compositionRoots`. Each call is a new instance no process-wide singleton.
97
+ - Keep Domain-role layers kernel-free (`ARKRUN_KERNEL_IN_DOMAIN`).
98
+ - Resolve managed types from the kernel; do not construct admitted types with `new`
99
+ (`ARKRUN_DIRECT_NEW`).
100
+ - On `register()`, declare `uses` / `reactsTo` / `raises` / `sends`. `extendedInfo` is
101
+ tooling-only and is **not** a gate verdict. Adding an existing call-site literal to the
102
+ declaration list is the only mechanical-safe ArkRun edit; inventing a new emit / handle /
103
+ depend is judgment.
104
+ - Send on kernel transport: `local` / `localBlocking` / `broker`. `ephemeral` defaults **true**.
105
+ Broker adapters are ports you inject — this package does not ship cloud SDKs. Unbound
106
+ `broker` falls back in-process local. Do not import `EventEmitter` or a homemade bus in
107
+ `managedLayers` (`ARKRUN_TRANSPORT_BYPASS`).
108
+ - Optional inspector: `startInspector()` on `127.0.0.1`, refuses `NODE_ENV=production`, no
109
+ public bind. Snapshots / `requestGraph` (process or technical + Mermaid) are tooling, not a
110
+ score. `getDependencyInformationPackage()` never includes factories, live instances, or
111
+ input DTOs.
112
+ - In-memory stores lose state on restart — **not** production durability. Note bounded history
113
+ (`maxHistorySize` 1000) if the hand-rolled version retained everything.
114
+ 6. **Delete the hand-rolled version** once call sites are moved — the point is
82
115
  less code, not a second parallel system. Deleting code is a destructive move:
83
116
  confirm with the user before removing the old implementation, and never delete
84
117
  something the inventory only *suspects* is dead (a misclassified load-bearing
@@ -87,6 +120,8 @@ the same files or weaken the gate.
87
120
  ## Critical handoffs
88
121
 
89
122
  - No static gates yet: **STOP — do not continue this skill as complete.** Run `/ark-adopt` first (`ark-check --recommend` / leftover `/ark-architect`).
123
+ - Extra absent and the user wants it: **STOP — do not continue this skill as complete.** **`/ark-adopt`** writes advisory `arkRun`.
124
+ - Skip cluster (`new` of managed types, homemade bus, kernel in Domain) after the extra is on: leftover **`/ark-fix`** / **`/ark-loop`** or **`/ark-autopilot`** — this skill still wires one candidate.
90
125
  - Runtime companion unavailable from npm and no ArkGate source checkout: **STOP** and report the distribution boundary.
91
126
  - Inventory finds nothing: stop; do not introduce kernel speculatively.
92
127
 
@@ -96,20 +131,26 @@ the same files or weaken the gate.
96
131
  introduce the runtime kernel speculatively. Static enforcement alone is a
97
132
  complete, valid use of Ark.
98
133
  - Keep the migration diff reviewable: one feature per invocation.
134
+ - Skills never enforce; never weaken `ark.config.json` to skip `ARKRUN_*`.
135
+ - Never a process-wide kernel singleton. Never shipped cloud broker SDKs.
136
+ - Never claim in-memory stores are production-durable.
99
137
  - Plain-language reporting: one sentence per concept ("outbox = events are
100
138
  saved in the same transaction as your data, then published — so you never
101
139
  publish something that didn't commit").
102
140
 
103
141
  ## Related onboarding
104
142
 
105
- - Adopt static gates and application shape **first** (`/ark-adopt`).
106
- - Runtime kernel is optional and separate from enthusiast onboarding.
143
+ - Adopt static gates and application shape **first** (`/ark-adopt`). Brownfield: same door —
144
+ advisory extra only until the team promotes; absence is valid.
145
+ - Runtime kernel is optional and separate from enthusiast onboarding. Do not put `arkRun` on the
146
+ compact starter.
107
147
 
108
148
  ## Verify and report
109
149
 
110
150
  Run the project's tests plus `ark-check --root . --config ark.config.json
111
151
  --strict-config`. Report: what was migrated, lines deleted vs added, remaining
112
- candidates ranked, and any behavior differences (e.g. bounded history).
152
+ candidates ranked, behavior differences (e.g. bounded history), and **`[ArkRun]`** residual
153
+ (`ARKRUN_*` / doctor `arkRun`, `notAScore`) separately from Layers / ArkRules.
113
154
 
114
155
  ## Completion contract (skill incomplete if missing)
115
156
 
@@ -119,6 +160,7 @@ End with **exactly** these headings (markdown `###`):
119
160
  - **Sensor:** commands/tools run
120
161
  - **Opened:** real paths read (or `n/a` only if pure install/upgrade with no source analysis)
121
162
  - **Result:** one-line outcome
163
+ - **Planes:** **`[ArkRun]`** residual (or `n/a` if extra absent) — do not mix with `[Layer]` / `[ArkRules]`
122
164
  - **Compass:** `n/a` (runtime skill; static residual → explore/fix) | top residual if doctor was run
123
165
  - **Handoff:** `/ark-…` / CLI / `none`
124
166
  - **Incomplete?** `no` | `yes — <what is missing>`