arkgate 2.6.0 → 2.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 (57) hide show
  1. package/CHANGELOG.md +97 -0
  2. package/README.md +98 -70
  3. package/bin/ark-check.mjs +240 -1001
  4. package/bin/ark-layer-match.mjs +153 -147
  5. package/bin/ark-mcp.mjs +102 -5
  6. package/bin/ark-shared.mjs +304 -165
  7. package/bin/ark.mjs +44 -34
  8. package/bin/lib/agent-gates.mjs +448 -15
  9. package/bin/lib/architecture-scan.mjs +279 -0
  10. package/bin/lib/ast-scan.mjs +199 -0
  11. package/bin/lib/baseline-key.mjs +23 -0
  12. package/bin/lib/config-warnings.mjs +228 -0
  13. package/bin/lib/doctor-plan.mjs +11 -4
  14. package/bin/lib/graph-cycles.mjs +56 -0
  15. package/bin/lib/presets.mjs +75 -4
  16. package/bin/lib/remediation.mjs +150 -0
  17. package/bin/lib/scan-files.mjs +69 -0
  18. package/bin/lib/ts-resolve.mjs +215 -0
  19. package/bin/lib/violations.mjs +3 -9
  20. package/dist/eslint/index.cjs +21 -3
  21. package/dist/eslint/index.cjs.map +1 -1
  22. package/dist/eslint/index.d.cts +5 -3
  23. package/dist/eslint/index.d.ts +5 -3
  24. package/dist/eslint/index.js +21 -3
  25. package/dist/eslint/index.js.map +1 -1
  26. package/dist/index.cjs +1 -1
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +3 -3
  29. package/dist/index.d.ts +3 -3
  30. package/dist/index.js +1 -1
  31. package/dist/index.js.map +1 -1
  32. package/dist/nestjs/index.cjs +1 -1
  33. package/dist/nestjs/index.cjs.map +1 -1
  34. package/dist/nestjs/index.d.cts +1 -1
  35. package/dist/nestjs/index.d.ts +1 -1
  36. package/dist/nestjs/index.js +1 -1
  37. package/dist/nestjs/index.js.map +1 -1
  38. package/dist/runtime/index.cjs +3080 -0
  39. package/dist/runtime/index.cjs.map +1 -0
  40. package/dist/runtime/index.d.cts +2 -0
  41. package/dist/runtime/index.d.ts +2 -0
  42. package/dist/runtime/index.js +2998 -0
  43. package/dist/runtime/index.js.map +1 -0
  44. package/dist/{types-DpdVN7Lm.d.cts → types-CP3KkwZt.d.cts} +1 -1
  45. package/dist/{types-DpdVN7Lm.d.ts → types-CP3KkwZt.d.ts} +1 -1
  46. package/docs/agent-guide.md +67 -1
  47. package/docs/migrate-from-ark-runtime-kernel.md +4 -2
  48. package/docs/package-surface.md +72 -0
  49. package/docs/production-hardening.md +3 -0
  50. package/package.json +11 -1
  51. package/server.json +2 -2
  52. package/templates/skills/ark-adopt.md +43 -87
  53. package/templates/skills/ark-autopilot.md +39 -77
  54. package/templates/skills/ark-contract.md +43 -84
  55. package/templates/skills/ark-coverage.md +62 -83
  56. package/templates/skills/ark-fix.md +45 -90
  57. package/templates/skills/ark-loop.md +44 -66
package/CHANGELOG.md CHANGED
@@ -2,6 +2,103 @@
2
2
 
3
3
  All notable changes to ArkGate (`arkgate`; formerly `ark-runtime-kernel`) are documented here.
4
4
 
5
+ ## Unreleased
6
+
7
+ ## 2.7.0 — 2026-07-09
8
+
9
+ Maintainability release (roadmap **R1–R4**): single-source layer matching, package surface policy,
10
+ `ark-check` orchestration split, and typed pure CLI helpers. **No intentional CLI flag or JSON
11
+ shape breaks** for the gate/co-pilot path.
12
+
13
+ ### Added
14
+
15
+ - **`arkgate/runtime`** package subpath (ESM/CJS + types) — preferred entry for the optional
16
+ runtime kernel. Root `arkgate` still re-exports kernel symbols for this major (compat).
17
+ - **`docs/package-surface.md`** — stable surfaces (CLI JSON, MCP, `ark.config`) vs opt-in runtime.
18
+ - **Generated pure CLI helpers:** `bin/lib/remediation.mjs`, `bin/lib/baseline-key.mjs` from
19
+ Domain TS (`npm run generate:cli-pure` / `check:cli-pure`).
20
+ - **`ark-check` scan pipeline modules** under `bin/lib/`: `scan-files`, `config-warnings`,
21
+ `ts-resolve`, `ast-scan`, `graph-cycles`, `architecture-scan`.
22
+
23
+ ### Changed
24
+
25
+ - **R1 — layer globs SoT:** canonical `src/domain/layerMatch.ts` → generated
26
+ `bin/ark-layer-match.mjs`; `npm run check:layer-match` drift guard in CI.
27
+ `normalizeGlobSeparators` keeps Windows path seps without eating glob escapes.
28
+ - **R2 — package surface = product wedge:** README / agent-guide / migrate / production-hardening
29
+ recommend `arkgate/runtime` for kernel usage.
30
+ - **R3 — `ark-check` entry slim-down:** entry is orchestration-only (~2.4k → ~1.4k LOC);
31
+ `runArchitectureScan` owns the check pipeline. Flags and JSON shapes unchanged.
32
+ - **R4 — typed pure core:** `classifyRemediation`, `enrichViolationWithFixClass`, and
33
+ `baselineKey` live in `src/domain/*` with generated CLI load paths; unit tests import Domain
34
+ sources without spawning the CLI.
35
+
36
+ ### Docs / CI
37
+
38
+ - CI steps for layer-match and cli-pure drift guards.
39
+ - CONTRIBUTING / AGENTS: regenerate commands after editing pure Domain algorithms.
40
+
41
+ ## 2.6.1 — 2026-07-09
42
+
43
+ Field-test release: Next/monorepo honesty (deer-flow-style hosts), simplified **one-flow** UX for
44
+ humans and autonomous agents, and skills that require real source remediation—not CLI paraphrase.
45
+
46
+ ### Fixed — false greens & strict CI noise (Next / monorepo)
47
+
48
+ - **Next application bag:** framework overlay classifies `src/core/**` and `**/core/**` as
49
+ ApplicationOrchestration so monorepos like `frontend/src/core` are governed on day one
50
+ (not left as dark matter under a “clean” plan).
51
+ - **Nested Next detection:** `collectAggregatedDeps` + scan of `frontend/`/`web`/`client` so
52
+ `next` only under `frontend/package.json` (root arkgate-only) still enables the Next overlay
53
+ and `app/page.tsx` path matching (middle segment optional).
54
+ - **Next noise excludes:** public assets, tool configs, and scripts are excluded by default on
55
+ Next detection so demo JS does not pollute coverage.
56
+ - **Domain `**/types.ts` trap removed** from monorepo and ui-surface presets. Bare
57
+ `core/**/types.ts` no longer becomes Domain and invents Domain→Application edges.
58
+ - **`CONFIG_LAYER_PATTERN_NO_MATCHES` is advisory** (`failsStrict: false`). Dead preset globs
59
+ (`app/**`, `src/layouts/**` when `include` is `frontend`) no longer fail `--strict-config`
60
+ alone while architecture edges are clean.
61
+ - **Empty baseline policy:** `--update-baseline` with zero violations **deletes** an existing
62
+ empty `.ark-baseline.json` instead of leaving an orphan “is the ratchet on?” file.
63
+ - **Monorepo CI install:** generated workflow `npm install` also installs `frontend/` when
64
+ `frontend/package.json` exists (root-only arkgate + app under frontend).
65
+
66
+ ### Changed — one-flow UX (humans + agents)
67
+
68
+ - **README:** leads with **The only flow** — `ark start` → `/ark-autopilot` → `doctor`. Skills
69
+ are escapes, not a flat curriculum. Operating modes documented as **status lights**, not
70
+ settings.
71
+ - **`ark start` wrap-up:** always ends with the three next steps (agent autopilot, doctor,
72
+ strict check) instead of a long mode-specific essay.
73
+ - **Generated `AGENTS.md`:** “Default agent flow (if unsure, do only this)” — autopilot first;
74
+ other `/ark-*` skills are optional escapes.
75
+ - **Doctor operating mode copy:** plain-language Setup / Align / Guard and “you do not pick
76
+ this mode”.
77
+
78
+ ### Changed — skills (deep co-pilot, not CLI wrappers)
79
+
80
+ Templates under `templates/skills/` (and project `.grok/skills` copies) for at least:
81
+
82
+ `ark-coverage`, `ark-autopilot`, `ark-loop`, `ark-adopt`, `ark-fix`, `ark-contract`
83
+
84
+ - **Anti-wrapper rule:** must read real source; CLI is a sensor.
85
+ - **“Así te lo re-soluciono”** remediation deliverable (file-level plans).
86
+ - **Adopt / contract:** mine loose business rules into the Ark **manifest** (layers,
87
+ `intentPrefixes`, Domain placement, intent naming)—not config vibes only.
88
+
89
+ ### Tests
90
+
91
+ - Fixture-style unit tests drive real `bin/ark-check.mjs`: Next core governance; deer-flow-like
92
+ monorepo (`frontend` + `core/**/types.ts` not Domain); strict-config with dead globs;
93
+ empty baseline removal.
94
+
95
+ ### Also in 2.6.1 train (from Unreleased product priorities)
96
+
97
+ - Empty-scope honesty, auto-include TS packages, AGENTS non-clobber, `--adopt-contract`,
98
+ UI surface preset, MCP place/suggest-include, Codex multi-project, deploy-path adoption
99
+ gaps, soft cycle policy, Rush/Lerna monorepo roots, type-only cycle graph, default skip
100
+ `*.gen.ts` / `*.generated.ts`.
101
+
5
102
  ## 2.6.0 — 2026-07-09
6
103
 
7
104
  ### Changed — maintainability hygiene (#11 / #12)
package/README.md CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  # ArkGate — Architecture Co-pilot for AI TypeScript
4
4
 
5
- **Write gate · CI gate · co-pilot** for TypeScript projects that use AI agents.
5
+ **One contract. One gate. One co-pilot.**
6
6
 
7
- Your AI writes most of the code. **ArkGate** keeps that code inside an architecture you can
8
- trust — and makes sure a “green” check means something real.
7
+ Your AI writes most of the code. ArkGate keeps that code inside an architecture you can trust —
8
+ and makes sure a “green” check means something real.
9
9
 
10
10
  [![CI](https://github.com/pedroknigge/arkgate/actions/workflows/ci.yml/badge.svg)](https://github.com/pedroknigge/arkgate/actions/workflows/ci.yml)
11
11
  [![npm](https://img.shields.io/npm/v/arkgate?color=cb3837&label=npm)](https://www.npmjs.com/package/arkgate)
@@ -17,21 +17,42 @@ trust — and makes sure a “green” check means something real.
17
17
 
18
18
  ---
19
19
 
20
- ## What it is
20
+ ## The only flow (humans and agents)
21
21
 
22
- **ArkGate** is a **machine-readable architecture contract** for TypeScript, enforced in three places:
22
+ If you remember nothing else:
23
23
 
24
- | When | Tool | What happens |
25
- |------|------|----------------|
26
- | **While the AI writes** | `arkgate-mcp` (write gate) | Blocks bad edits; agent self-corrects |
27
- | **Before merge** | `arkgate-check` (CI) | Full TypeScript import graph + rules |
28
- | **At runtime** *(optional)* | `createArkKernel()` | Event/intent governance if you opt in |
24
+ ```text
25
+ 1. npx arkgate start ← install shape + gates + origin report
26
+ 2. /ark-autopilot ← in your agent: adopt, fix, leave gates on
27
+ 3. npx arkgate-check --doctor “where am I?” anytime (one status screen)
28
+ ```
29
+
30
+ | Stuck on… | Do this |
31
+ |-----------|---------|
32
+ | Gate failed after an edit | `/ark-fix` |
33
+ | “Where does this new file go?” | `/ark-place` |
34
+ | Contract globs / layers wrong | `/ark-contract` |
35
+ | New ArkGate version | `/ark-upgrade` |
36
+
37
+ **Everything else is optional.** You do not need to learn “modes”, 11 skills, or the runtime
38
+ kernel to get value. Agents that are unsure should **only** run `/ark-autopilot` (or the three
39
+ commands above).
40
+
41
+ ---
42
+
43
+ ## What it is (30 seconds)
44
+
45
+ **ArkGate** = a machine-readable architecture file (`ark.config.json`) enforced in two places
46
+ you always care about:
47
+
48
+ | When | Tool |
49
+ |------|------|
50
+ | **While the AI writes** | `arkgate-mcp` write gate (blocks bad edits) |
51
+ | **Before merge** | `arkgate-check` CI |
29
52
 
30
- One file drives all of it: **`ark.config.json`**.
53
+ Optional later: runtime kernel (`createArkKernel`) if you want event/intent governance.
31
54
 
32
- It is **not** a web framework, ORM, or job runner — and the optional runtime kernel is not
33
- the product. The product is the **agent-native architecture gate** (write path + CI + plan/loop)
34
- plus tools agents can read *before* generating code (`ark_place`, `ark://manifest`, …).
55
+ It is **not** a web framework, ORM, or job runner.
35
56
 
36
57
  ![Write gate: agent blocked, then self-corrects](docs/assets/ark-write-gate.svg)
37
58
 
@@ -39,31 +60,30 @@ plus tools agents can read *before* generating code (`ark_place`, `ark://manifes
39
60
 
40
61
  ## Who it’s for
41
62
 
42
- | You are… | You want… | Start with |
43
- |----------|-----------|------------|
44
- | **Builder with AI** (not necessarily an architect) | Order without learning “hexagonal” first | `npx arkgate start` → `/ark-autopilot` |
45
- | **Engineer / tech lead** | A strict contract, CI, baselines, precise control | `ark init` + `ark-check` + write gate |
46
- | **Team on a messy repo** | Truth about coverage + a cleanup path, not a false green | `ark-check --coverage` → `/ark-adopt` |
63
+ Same start for almost everyone: **`npx arkgate start` `/ark-autopilot`**.
47
64
 
48
- **Not for:** projects with no TypeScript, people who only want a one-off lint rule and no agent workflow, or anyone looking for an app framework.
65
+ | You are… | Same start, then… |
66
+ |----------|-------------------|
67
+ | Builder with AI | Stay on autopilot until doctor is happy |
68
+ | Tech lead on a messy monorepo | Autopilot (or deeper `/ark-adopt` if you want a focused brownfield pass) |
69
+ | Power user | Same flow; use `ark-check --plan` / `--coverage` when you want the raw sensor |
70
+
71
+ **Not for:** no TypeScript, “just one lint rule”, or looking for an app framework.
49
72
 
50
73
  ---
51
74
 
52
- ## What you get (in plain language)
75
+ ## Status, not settings (“modes”)
53
76
 
54
- 1. **A shape** Ark looks at your repo (Nest, Next, API, library, …) and suggests how to organize it.
55
- 2. **Guardrails** — config + agent gates + CI so new code can’t quietly break layers.
56
- 3. **A plan** — what’s safe for an agent to fix vs what needs your decision (`mechanical-safe` vs judgment).
57
- 4. **Honesty** — if Ark only governs 10% of the tree, it says so. “Clean” with almost no coverage is not success.
58
- 5. **Adoption health** — `arkgate-check --doctor` checks co-pilot completeness (hosts, MCP argv, Codex home, core-layer optionality, origin report) **separately** from the 0–100 fitness score.
77
+ `ark-check --doctor` may say **Suggest / Adapt / Enforce**. That is a **status light**, not a
78
+ mode you configure:
59
79
 
60
- Three **operating modes** (not “user types”) on the same contract:
80
+ | Light | Means | Your move |
81
+ |-------|--------|-----------|
82
+ | **Suggest** | New/thin project | Finish `start` + autopilot |
83
+ | **Adapt** | Not fully protected yet | Keep autopilot / adopt until clean |
84
+ | **Enforce** | Gates can honestly protect you | Build features; fix with `/ark-fix` if blocked |
61
85
 
62
- | Mode | Meaning |
63
- |------|---------|
64
- | **Suggest** | Install a starting shape |
65
- | **Adapt** | Match the contract to real folders / raise coverage |
66
- | **Enforce** | Gates actually protect you |
86
+ You **arrive** at Enforce. You never “turn on Enforce”.
67
87
 
68
88
  ---
69
89
 
@@ -85,58 +105,61 @@ Full checklist (CI, MCP, Codex, imports): **[docs/migrate-from-ark-runtime-kerne
85
105
 
86
106
  ```bash
87
107
  npm install -D arkgate typescript
88
- npx arkgate start # look at the project → setup plan (plain language)
89
- # (aliases: ark start / ark-check / ark-mcp still work)
108
+ npx arkgate start # setup + origin report
109
+ # in agent:
110
+ # /ark-autopilot
111
+ npx arkgate-check --doctor # status light + next action
90
112
  ```
91
113
 
92
- Then, in your agent (Claude / Cursor / Codex / **Grok** / …):
114
+ Aliases `ark` / `ark-check` / `ark-mcp` still work. **npm / pnpm / yarn**. No install lifecycle scripts.
93
115
 
94
- ```text
95
- /ark-autopilot
96
- ```
116
+ <details>
117
+ <summary>What <code>/ark-autopilot</code> does under the hood (optional detail)</summary>
97
118
 
98
- That is the **co-pilot**: set up → plan → apply safe fixes (validated, reversible) → propose the rest → leave gates on.
119
+ 1. Setup if needed (`ark start`).
120
+ 2. Origin architecture report (before picture in `.ark/reports/`).
121
+ 3. Adoption: match contract to real folders, raise governed %.
122
+ 4. Plan + safe auto-fixes; judgment when you ask for full apply.
123
+ 5. Gates on + after report (evolution vs origin).
99
124
 
100
- **Prefer manual control?**
125
+ </details>
126
+
127
+ <details>
128
+ <summary>Manual / power-user CLI only</summary>
101
129
 
102
130
  ```bash
103
- npx arkgate init # config + gates
104
- npx arkgate-check # CI gate
105
- npx arkgate-check --plan # classified fix list
131
+ npx arkgate init
132
+ npx arkgate-check
133
+ npx arkgate-check --plan
106
134
  npx arkgate-check --coverage
107
135
  ```
108
136
 
109
- Works with **npm, pnpm, and yarn**. No install lifecycle scripts (safe for hardened CI).
137
+ </details>
110
138
 
111
139
  ---
112
140
 
113
- ## Agent skills (`/ark-*`)
141
+ ## Other skills (only when you need them)
114
142
 
115
- Install with agent gates:
143
+ Install once: `npx arkgate-check --install-agent-gates`
144
+ (`--tools claude,cursor,codex,grok` to pick hosts.)
116
145
 
117
- ```bash
118
- npx arkgate-check --install-agent-gates
119
- # or pick hosts: --tools claude,cursor,codex,grok
120
- ```
121
-
122
- | Skill | What it does |
123
- |-------|----------------|
124
- | **`/ark-autopilot`** | End-to-end co-pilot: setup → plan → safe auto-fixes → propose the rest → leave gates on |
125
- | **`/ark-loop`** | Drive the plan in a worktree; auto-apply only `mechanical-safe` (type-only move, pure-type file relocate, `import type` of pure-type modules) |
126
- | **`/ark-architect`** | Greenfield: pick application shape, phase-1 layers, scaffold, verify honestly |
127
- | **`/ark-adopt`** | Brownfield: match contract to reality, raise coverage, freeze only real debt |
128
- | **`/ark-contract`** | Safely edit `ark.config.json` (smallest change, strict re-check) |
129
- | **`/ark-place`** | Where does this new artifact go? Layer, path, naming — then scaffold |
130
- | **`/ark-fix`** | Fix violations at the source (no disable comments, no gate weakening) |
131
- | **`/ark-explain`** | Explain the current contract, coverage, and report in plain language |
132
- | **`/ark-coverage`** | Audit which Ark capabilities you are not using yet |
133
- | **`/ark-runtime`** | Opt-in: migrate hand-rolled bus/outbox/sagas onto the runtime kernel |
134
- | **`/ark-upgrade`** | Bump the package and refresh gates + skills for every agent host (also normalizes MCP bins + Codex home) |
146
+ **Default is always `/ark-autopilot`.** The rest are escapes, not a second curriculum:
135
147
 
136
- Supported agent hosts for full MCP/hook gates: **Claude Code**, **Cursor**, **OpenAI Codex**, **Grok Build**. Instruction-tier hosts (Windsurf, Cline, Copilot, …) get rule files. See [docs/ai-gates.md](docs/ai-gates.md).
137
-
138
- After upgrade, run **`npx arkgate-check --doctor`**: it flags incomplete hosts, dual `ark-mcp`/`arkgate-mcp` args, Codex home pointing at a temp path, core layers still `optional` while populated, and a missing origin report.
148
+ | Need | Skill |
149
+ |------|--------|
150
+ | Only the apply loop (plan already exists) | `/ark-loop` |
151
+ | Empty greenfield shape/scaffold | `/ark-architect` |
152
+ | Deep brownfield / manifest mining alone | `/ark-adopt` |
153
+ | New file placement | `/ark-place` |
154
+ | Gate violation on a change | `/ark-fix` |
155
+ | Edit `ark.config.json` safely | `/ark-contract` |
156
+ | Plain-language tour of the report | `/ark-explain` |
157
+ | Deep “what am I not using?” audit | `/ark-coverage` |
158
+ | Migrate hand-rolled bus/outbox (TS) | `/ark-runtime` |
159
+ | Bump ArkGate + refresh all agent hosts | `/ark-upgrade` |
139
160
 
161
+ Hosts with full MCP/hooks: **Claude Code**, **Cursor**, **Codex**, **Grok Build**.
162
+ More: [docs/ai-gates.md](docs/ai-gates.md). Health: **`npx arkgate-check --doctor`**.
140
163
  ---
141
164
 
142
165
  ## How it works (short)
@@ -195,13 +218,17 @@ CI (example):
195
218
 
196
219
  ## Optional: runtime kernel
197
220
 
198
- Gates need **no app code changes**. If you also want runtime intent/event contracts:
221
+ Gates need **no app code changes**. If you also want runtime intent/event contracts,
222
+ use the **opt-in** subpath (preferred):
199
223
 
200
224
  ```ts
201
- import { createStrictArkKernelFromConfig } from 'arkgate';
202
- // see docs/production-hardening.md and package exports
225
+ import { createStrictArkKernelFromConfig } from 'arkgate/runtime';
226
+ // see docs/production-hardening.md and docs/package-surface.md
203
227
  ```
204
228
 
229
+ Root `import { … } from 'arkgate'` still re-exports kernel symbols for compatibility
230
+ in this major; prefer `arkgate/runtime` for new code.
231
+
205
232
  NestJS: `arkgate/nestjs` (optional peer `@nestjs/common`).
206
233
 
207
234
  ---
@@ -211,6 +238,7 @@ NestJS: `arkgate/nestjs` (optional peer `@nestjs/common`).
211
238
  | Audience | Link |
212
239
  |----------|------|
213
240
  | New builders (plain language) | [docs/enthusiast/](docs/enthusiast/README.md) |
241
+ | **Package surface (stable vs opt-in)** | [docs/package-surface.md](docs/package-surface.md) |
214
242
  | Wire Claude / Cursor / Codex / Grok + **ESLint (CI-parity)** | [docs/ai-gates.md](docs/ai-gates.md) |
215
243
  | **TypeScript 5 / 6 / 7 support** | [docs/typescript-support.md](docs/typescript-support.md) |
216
244
  | Migrate from `ark-runtime-kernel` | [docs/migrate-from-ark-runtime-kernel.md](docs/migrate-from-ark-runtime-kernel.md) |