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
@@ -64,6 +64,69 @@ npx ark-check --watch # debounced re-check when govern
64
64
  `enthusiastHint` (plain English). `--doctor --json` exposes `doctor.newHere` with
65
65
  `recommendCommand` and `initCommand` when the nudge applies.
66
66
 
67
+ ### Deploy-path quality (lint/types before the host build)
68
+
69
+ Some frameworks run **ESLint and/or typecheck inside the production build** (Next.js by
70
+ default: “Linting and checking validity of types”). Architecture can be green while the
71
+ **deploy host** is the first place a `no-explicit-any` or unused-import error appears.
72
+
73
+ Ark does **not** reimplement general ESLint rules. `--doctor` / adoption gaps **do**
74
+ detect, for **any** consumer repo (framework signals only — deps, scripts, CI files):
75
+
76
+ | Gap id | When |
77
+ |--------|------|
78
+ | `deploy-path-lint-script-missing` | Build embeds ESLint; no `lint` / `eslint` script |
79
+ | `deploy-path-lint-not-in-ci` | Lint script exists; CI workflows never run it |
80
+ | `deploy-path-lint-no-ci` | Build embeds ESLint; no CI workflows at all |
81
+ | `deploy-path-typecheck-script-missing` | Build typechecks; no `typecheck` script |
82
+ | `deploy-path-typecheck-not-in-ci` | Typecheck script exists; CI never runs it |
83
+
84
+ Respects `eslint.ignoreDuringBuilds: true` in `next.config.*`. Recommended pre-merge
85
+ order (universal): `lint` → `typecheck` → `arkgate-check` / `check:architecture` → `build`.
86
+
87
+ ### Empty scope, include roots, and contract adopt
88
+
89
+ When `include` matches **zero** TS/JS files, plan/doctor treat that as **not done**
90
+ (`goal.emptyScope`, adoption gap `empty-scope`) — never “clean architecture.”
91
+
92
+ ```bash
93
+ npx ark-check --suggest-include --json # workspaces + nested package.json+TS roots
94
+ npx ark-check --adopt-contract --write # expand include + UI patterns (no rule weakening)
95
+ npx ark-check --coverage
96
+ ```
97
+
98
+ Polyglot repos: Ark only governs TypeScript/JS. Point include at package roots that have sources.
99
+
100
+ ### Presets
101
+
102
+ - `hexagonal` / `layered` / `feature-sliced` / `monorepo` / **`ui-surface`** (UI/Vite/Remotion-style hooks+lib+routes+components)
103
+
104
+ ### Cycle policy
105
+
106
+ ```json
107
+ { "cyclePolicy": "strict" }
108
+ ```
109
+
110
+ - `strict` (default): value cycles fail the check
111
+ - `soft` / `framework-soft`: value cycles are **warnings** only
112
+ - `off`: skip cycle detection
113
+
114
+ Type-only edges never form cycles (codegen-safe).
115
+
116
+ ### Generated files and type-only cycles
117
+
118
+ By default Ark **does not scan** common codegen paths:
119
+
120
+ - `**/*.gen.ts`, `**/*.gen.tsx`
121
+ - `**/*.generated.ts`, `**/*.generated.tsx`
122
+
123
+ Override with `"excludeGenerated": false` or extend with top-level `"exclude": ["**/vendor/**"]`
124
+ in `ark.config.json`.
125
+
126
+ **Circular dependencies** are computed on **value/runtime** import edges only. A cycle
127
+ closed solely by `import type` (common with generated route trees) is **not** reported as
128
+ `CIRCULAR_DEPENDENCY`. Value cycles still fail.
129
+
67
130
  ### MCP `ark_recommend` and `/ark-architect` (Phase C)
68
131
 
69
132
  The `ark-mcp` server exposes **`ark_recommend`** — same JSON as
@@ -146,7 +209,7 @@ projections, metadata, workflow engine, and 11-layer architecture profile:
146
209
  ```ts
147
210
  import {
148
211
  createStrictArkKernel,
149
- } from 'arkgate';
212
+ } from 'arkgate/runtime';
150
213
 
151
214
  const ark = createStrictArkKernel();
152
215
  // ... define intents, event contracts, metadata, projections, and workflows through ark.*
@@ -156,6 +219,9 @@ const contract = ark.manifest().toJSON();
156
219
  // contract.observability, projections
157
220
  ```
158
221
 
222
+ Prefer `arkgate/runtime` for the optional kernel (root `arkgate` still re-exports for
223
+ compat). Package surface policy: [package-surface.md](package-surface.md).
224
+
159
225
  Agents should read `contract` and `ark.observability.report()` before generating or modifying code.
160
226
 
161
227
  ## Naming Conventions
@@ -131,7 +131,8 @@ Or edit `.grok/config.toml` → `args` use `arkgate-mcp`.
131
131
 
132
132
  ```diff
133
133
  - import { createStrictArkKernelFromConfig } from 'ark-runtime-kernel';
134
- + import { createStrictArkKernelFromConfig } from 'arkgate';
134
+ + import { createStrictArkKernelFromConfig } from 'arkgate/runtime';
135
+ // root `arkgate` still re-exports kernel symbols this major (compat)
135
136
 
136
137
  - import { ArkModule } from 'ark-runtime-kernel/nestjs';
137
138
  + import { ArkModule } from 'arkgate/nestjs';
@@ -140,7 +141,8 @@ Or edit `.grok/config.toml` → `args` use `arkgate-mcp`.
140
141
  + import ark from 'arkgate/eslint';
141
142
  ```
142
143
 
143
- If you only used the CLI + MCP (most projects), **no import changes**.
144
+ If you only used the CLI + MCP (most projects), **no import changes**.
145
+ Surface policy: [package-surface.md](package-surface.md).
144
146
 
145
147
  ---
146
148
 
@@ -0,0 +1,72 @@
1
+ # ArkGate package surface policy
2
+
3
+ **Product wedge:** write gate · CI gate · co-pilot (plan / loop / skills).
4
+ **Not the wedge:** the optional in-process runtime kernel.
5
+
6
+ This document is the consumer contract for **what is stable** vs **what is opt-in**.
7
+
8
+ ---
9
+
10
+ ## Stable surfaces (semver-supported)
11
+
12
+ | Surface | How you use it | Stability notes |
13
+ |---------|----------------|-----------------|
14
+ | **CLI** | `arkgate` / `arkgate-check` (aliases `ark` / `ark-check`) | Flags and human text may improve; **JSON output shapes** for `--json` (check, doctor, plan, coverage, recommend) are stable within a major. Additive fields OK; removals/renames are major. |
15
+ | **MCP tools** | `arkgate-mcp` / `ark://…` resources | Tool names and primary argument shapes are stable within a major. |
16
+ | **`ark.config.json`** | Layer globs, rules, include/exclude, forbiddenGlobals, intent prefixes | Schema fields documented in playbooks/examples are stable; new optional fields may appear. |
17
+ | **Agent skills** | `/ark-*` templates installed by `--install-agent-gates` | Skill *names* and “default flow” are stable; internal skill prose may evolve. |
18
+ | **ESLint subpath** | `arkgate/eslint` | Config-driven layer/import rules; loads consumer `ark.config.json`. |
19
+ | **GitHub Action** | `pedroknigge/arkgate` (see `action.yml`) | Inputs for running the check stay stable within a major. |
20
+
21
+ Gates need **no application code imports**. Most projects only use the CLI + MCP + config.
22
+
23
+ ---
24
+
25
+ ## Opt-in surfaces
26
+
27
+ | Surface | Import path | Notes |
28
+ |---------|-------------|--------|
29
+ | **Runtime kernel** | **`arkgate/runtime`** (preferred) | Event bus, intents, policies, sagas, outbox, projections, `createArkKernel` / strict helpers. Optional. Not required for architecture enforcement. |
30
+ | **Root package barrel** | `arkgate` | Still re-exports the runtime kernel for **compatibility**. Prefer `arkgate/runtime` for new code. Root may be thinned in a future **major**. |
31
+ | **NestJS adapter** | `arkgate/nestjs` | Optional peer `@nestjs/common`. Wires a kernel into Nest DI. |
32
+
33
+ ---
34
+
35
+ ## Recommended imports
36
+
37
+ ```ts
38
+ // Preferred — opt-in runtime kernel
39
+ import {
40
+ createStrictArkKernel,
41
+ createStrictArkKernelFromConfig,
42
+ } from 'arkgate/runtime';
43
+
44
+ // Still works this major (compat; not preferred for new code)
45
+ import { createStrictArkKernel } from 'arkgate';
46
+
47
+ // Nest adapter
48
+ import { ArkModule, InjectArk } from 'arkgate/nestjs';
49
+ ```
50
+
51
+ See [production-hardening.md](./production-hardening.md) for runtime operational guidance.
52
+
53
+ ---
54
+
55
+ ## Explicitly unstable / internal
56
+
57
+ - `bin/lib/*` module layout and private helpers
58
+ - Generated `bin/ark-layer-match.mjs` (edit canonical `src/domain/layerMatch.ts` only)
59
+ - HTML report DOM structure (unless documented as a machine contract)
60
+ - Internal MCP diagnostic fields not listed in agent-guide
61
+
62
+ ---
63
+
64
+ ## Versioning summary
65
+
66
+ | Change | Version bump |
67
+ |--------|----------------|
68
+ | Break CLI JSON field, MCP tool rename, or required `ark.config` field | **major** |
69
+ | New optional config field, new CLI flag, additive JSON | **minor** |
70
+ | Bugfix with no contract change | **patch** |
71
+ | Prefer `arkgate/runtime` over root (docs only; root still exports) | **patch/minor** |
72
+ | Remove root kernel re-exports | **major** (with migration notes) |
@@ -1,5 +1,8 @@
1
1
  # Production Hardening
2
2
 
3
+ The optional runtime kernel is imported from **`arkgate/runtime`** (preferred). See
4
+ [package-surface.md](package-surface.md).
5
+
3
6
  Ark's built-in stores are intentionally in-memory defaults. They are appropriate for tests,
4
7
  local development, examples, and single-process demos. Production systems should provide
5
8
  stores that match their durability, ordering, retention, and operational requirements.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arkgate",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "ArkGate — architecture co-pilot for AI TypeScript (write gate, CI gate, plan/loop)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -12,6 +12,11 @@
12
12
  "import": "./dist/index.js",
13
13
  "require": "./dist/index.cjs"
14
14
  },
15
+ "./runtime": {
16
+ "types": "./dist/runtime/index.d.ts",
17
+ "import": "./dist/runtime/index.js",
18
+ "require": "./dist/runtime/index.cjs"
19
+ },
15
20
  "./eslint": {
16
21
  "types": "./dist/eslint/index.d.ts",
17
22
  "import": "./dist/eslint/index.js",
@@ -46,6 +51,7 @@
46
51
  "docs/ark-check-example.json",
47
52
  "docs/assets",
48
53
  "docs/brownfield-adoption.md",
54
+ "docs/package-surface.md",
49
55
  "docs/production-hardening.md",
50
56
  "tests/fixtures/ts-consumer",
51
57
  "templates",
@@ -63,6 +69,10 @@
63
69
  "typecheck": "tsc --noEmit",
64
70
  "security:audit": "npm audit --omit=dev --audit-level=high",
65
71
  "check:architecture": "node bin/ark-check.mjs --root . --config ark.config.json --strict-config",
72
+ "generate:layer-match": "node scripts/generate-layer-match.mjs",
73
+ "check:layer-match": "node scripts/generate-layer-match.mjs --check",
74
+ "generate:cli-pure": "node scripts/generate-cli-pure.mjs",
75
+ "check:cli-pure": "node scripts/generate-cli-pure.mjs --check",
66
76
  "test:ts-compat": "node scripts/ts-compat-matrix.mjs 5.9.3 && node scripts/ts-compat-matrix.mjs 6.0.3 && node scripts/ts-compat-matrix.mjs 7.0.2",
67
77
  "eval:agent": "node eval/run.mjs",
68
78
  "eval:comparative": "node eval/comparative-run.mjs",
package/server.json CHANGED
@@ -6,12 +6,12 @@
6
6
  "url": "https://github.com/pedroknigge/arkgate",
7
7
  "source": "github"
8
8
  },
9
- "version": "2.6.0",
9
+ "version": "2.7.0",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "identifier": "arkgate",
14
- "version": "2.6.0",
14
+ "version": "2.7.0",
15
15
  "runtimeHint": "npx",
16
16
  "transport": {
17
17
  "type": "stdio"
@@ -1,103 +1,59 @@
1
1
  ---
2
2
  name: ark-adopt
3
- description: Onboard an existing codebase onto Ark get the contract to reflect reality, classify ungoverned code, then freeze only genuine debt with a plan. Autonomous.
3
+ description: Brownfield onboardingmatch contract to real code, classify ungoverned dirs, mine loose business rules into the Ark manifest/intents, freeze only real debt. Deep source analysis required.
4
4
  ---
5
5
 
6
6
  # /ark-adopt — Bring Ark into an existing codebase
7
7
 
8
- You are onboarding this repository onto Ark. The goal is NOT "make the check
9
- green" it is to leave the project with a contract that reflects its real
10
- architecture, most of the code actually governed, and only genuine debt frozen
11
- with a plan to burn it down. A green check over a wrong contract or an ungoverned
12
- tree is a FALSE green — worse than no gate, because it looks safe. Work autonomously.
8
+ Goal: contract reflects reality, most code governed, only genuine debt frozen with a burn-down.
9
+ A green check over a wrong contract is a **false green**.
13
10
 
14
- Commands below are written as `ark-check` / `ark`; run each through the project's
15
- package manager — `pnpm exec ark-check …` in a pnpm repo, `yarn ark-check …` in a
16
- yarn repo, `npx ark-check …` under npm. Match the lockfile; never hardcode `npx` in
17
- a pnpm/yarn repo (AGENTS.md shows the exact runner for this project).
18
11
 
19
- ## The guiding principle
12
+ ## Related onboarding
13
+
14
+ - **Greenfield:** `/ark-architect` or `ark-check --recommend` / `ark start`.
15
+ - **Brownfield:** `/ark-adopt` — match contract to reality; do not force a starter preset.
16
+ - **Default path:** `ark start` → `/ark-autopilot` → `ark-check --doctor`.
17
+
18
+ ## Anti-wrapper rule (mandatory)
19
+
20
+ **Forbidden:** only running `--init` / `--update-baseline` / coverage JSON without reading the tree.
21
+
22
+ **Required:**
23
+ 1. CLI sensor: `--coverage --json`, check `--json` (`summary`), doctor.
24
+ 2. **Read real source** in largest ungoverned dirs and top import edges (min **10 files**).
25
+ 3. **“Así te lo re-soluciono”** — concrete layer globs, file moves, and manifest/intent proposals.
26
+ 4. Never freeze a concentrated edge without investigating contract smell.
20
27
 
21
- **Ark protects the boundary AROUND a framework, not its internals.** If the repo
22
- uses a DI/kernel framework (dcouplr, NestJS, a custom kernel), do NOT try to govern
23
- its inside declare its PUBLIC SURFACE (the entrypoints app code is meant to
24
- import) as one layer and treat the rest as a black box. Governing the internals
25
- duplicates the framework's own wiring and fights it.
28
+ ## Guiding principle
29
+
30
+ Ark protects the **boundary around** a framework, not its internals. Nest/DI public surface = one layer; internals black box.
26
31
 
27
32
  ## Steps
28
33
 
29
- 1. **Config** — if `ark.config.json` is missing, run `ark-check --init`. It detects
30
- the layer directories that exist, writes a config for them, and PROPOSES a layer
31
- for every ungoverned directory (sourced from the 11-layer profile + presets),
32
- flagging the ones it cannot place. If a config exists, keep it don't regenerate
33
- unasked.
34
-
35
- 2. **Check + DIAGNOSE before you freeze anything** run
36
- `ark-check --root . --config ark.config.json --json` and read `summary`: it groups
37
- violations by edge, ranked. The critical signal is `summary.concentrated` /
38
- `dominantShare`: **when most violations are a single edge, the CONTRACT is almost
39
- always wrong, not the code.** (Real case: hundreds of API routes "violating"
40
- app→kernel because the framework's own `defineRoute` is the sanctioned entrypoint
41
- — false positives, not debt.) Investigate the dominant edge:
42
- - App-land reaching a framework/kernel through a legitimate entrypoint → fix the
43
- contract (step 3), do NOT freeze it.
44
- - Unrelated layers genuinely importing each other → real debt for the baseline.
45
-
46
- 3. **Make the contract reflect reality (via /ark-contract) BEFORE freezing:**
47
- - **Classify the ungoverned tree.** Run `ark-check --coverage --json`; read
48
- `governed.percent` and `suggestions`. If Ark governs a minority of the code, a
49
- green check means almost nothing. Add the proposed layers for the recognized
50
- directories; decide a layer for the ones flagged "unrecognized". Get `governed`
51
- high before trusting any check.
52
- - **Fix a concentrated edge at its source.** If the dominant edge is intended,
53
- either allow it or — better — split the target layer into a PUBLIC SURFACE (the
54
- entrypoints app code may import) and INTERNALS (denied). The breakdown's target
55
- subtrees show where the surface is. This facade split turns a wall of false
56
- positives into ~0 while still forbidding reach-arounds into internals.
57
- Re-run the check; the remainder should now be the genuine minority.
58
-
59
- 4. **Freeze the genuine debt** — run `ark-check --update-baseline`. If the set is
60
- still lopsided on one edge, Ark REFUSES and tells you the contract still looks
61
- wrong — heed it and return to step 3; do NOT `--force` past it just to get green.
62
- On success it writes `.ark-baseline.json`; tell the user to commit it (don't commit
63
- for them). From now `ark-check --baseline` fails only on NEW violations — the
64
- ratchet only moves toward zero (fixing a frozen violation shrinks the baseline).
65
-
66
- 5. **Gates + skills everywhere** — run `ark-check --install-agent-gates`. It
67
- auto-detects the agent CLIs in the repo and writes the write gate, rule files,
68
- package-manager-aware CI workflow, and the `/ark-*` skills for each (Kiro gets
69
- only its steering rule; Copilot only via `--tools copilot`). If a baseline was
70
- created, the generated CI already carries `--baseline`. For Codex, prompts load
71
- from `$CODEX_HOME/prompts`, not the repo — install there too with
72
- `ark-check --install-agent-gates --codex-home` (writes to their home dir; say so).
73
-
74
- 6. **Ratchet plan** — from `summary.edges` (ranked), write a short prioritized
75
- burn-down: which edge/cluster to fix first (biggest, or the one on the
76
- most actively-edited files per `git log`), that `/ark-fix` resolves each, and
77
- which items are real debt vs. deferred contract decisions.
78
-
79
- ## Operating rules
80
-
81
- - Explain each step's WHY in one plain sentence — this is often the user's first
82
- contact with Ark. Define jargon inline ("baseline = the list of violations that
83
- existed before Ark, frozen so they don't block you while you fix them over time").
84
- - Do NOT chase green by freezing false positives or loosening the contract blindly.
85
- The order is: contract reflects reality → classify → freeze only what's left.
86
- Getting to green the wrong way is the exact failure this skill exists to prevent.
87
- - Don't overwrite customized files (`--force`) unless asked. Don't adopt the runtime
88
- kernel here (that's `/ark-runtime`) — a repo with its own DI framework should keep it.
34
+ 1. **Config** — missing `ark-check --init` (detection). Keep existing unless asked to regenerate.
35
+ 2. **Check + diagnose** `summary.concentrated` / dominant edge fix contract first, don’t freeze.
36
+ 3. **Classify ungoverned** use coverage `suggestions`; add layers/patterns via `/ark-contract`.
37
+ 4. **Mine business rules manifiesto** (model job this is why the skill exists):
38
+ - Scan for loose domain: validators, pricing/policy functions, `can*`/`calculate*`, magic business constants, publish/intent strings, logic in UI/hooks that belongs in Domain.
39
+ - Propose: Domain files, `intentPrefixes`, intent names (`Domain.*` / `Application.*`), kernel `defineIntent` stubs if runtime is used.
40
+ - Apply config through `/ark-contract` discipline; move pure rules into Domain when safe; validate with ark-check.
41
+ - Deliver section **“Así te lo re-soluciono en el manifiesto”** with before/after contract snippets.
42
+ 5. **Freeze only real debt** `--update-baseline` (zero debt → **no empty baseline file** left behind).
43
+ 6. **Gates + skills** `--install-agent-gates` (CI monorepo-aware when `frontend/package.json` exists).
44
+ 7. **Ratchet plan** ranked edges + which are false positives avoided.
89
45
 
90
- ## Related onboarding
46
+ ## Operating modes
47
+
48
+ Explain modes as **detected stages** (Setup / Align / Guard), not user settings.
49
+
50
+ ## Verify
91
51
 
92
- - **This skill is for brownfield** existing messy repos. Do **not** use `/ark-architect` here.
93
- - Greenfield users: `/ark-architect`, `ark-check --recommend`, gallery starters (`examples/README.md`).
94
- - Demo: `docs/demos/02-brownfield-baseline-adoption.md`. Playbook: `docs/brownfield-adoption.md`.
95
- - Violation JSON may include `fixClass`, `effort`, `enthusiastHint` for burn-down ordering.
52
+ `ark-check --root . --config ark.config.json --strict-config` (+ baseline only if non-empty file retained).
53
+ Report: governed% before/after, files written, frozen count, false positives avoided, manifest/intent proposals applied or deferred.
96
54
 
97
- ## Verify and report
55
+ ## Never
98
56
 
99
- Finish with `ark-check --root . --config ark.config.json --strict-config
100
- --baseline .ark-baseline.json` (omit `--baseline` if none) it must pass. Report:
101
- governed % before/after, files written, violations frozen (and how many false
102
- positives you AVOIDED freezing by fixing the contract), the ratchet plan, and the
103
- commands the team needs (`check`, `/ark-fix`, `/ark-coverage`).
57
+ - Freeze false positives to get green.
58
+ - Force runtime kernel over existing Nest/DI.
59
+ - Claim Enforce while governed% is low or core bags ungoverned.
@@ -1,97 +1,59 @@
1
1
  ---
2
2
  name: ark-autopilot
3
- description: The end-to-end architecture co-pilot for non-developers. One flow: look at the project, set up the guardrails, then drive the plan to a clean architecture — auto-applying the safe fixes and proposing the rest, always validated by ark-check, never weakening the gate. Composes setup + plan + the apply loop. Autonomous within those limits.
3
+ description: End-to-end architecture co-pilot setup, deep plan from real code, apply mechanical-safe fixes, design and apply judgment fixes when the user asks for full apply. CLI is a sensor; you remediate files.
4
4
  ---
5
5
 
6
6
  # /ark-autopilot — Get to a sound architecture, end to end
7
7
 
8
- This is the co-pilot's top-level flow. It composes the three primitives — **plan** (Phase F),
9
- the guided setup (Phase G), and the **loop** (Phase H) into one experience that takes a
10
- non-developer from "I have a project" to "governed, cleaned up, and enforced from now on."
8
+ Composes **setup + plan + loop**. Safe default: auto-apply only `mechanical-safe`;
9
+ when the user says full apply / “al mango” / apply everything, also execute
10
+ **judgment** fixes you design from reading source (still validate with ark-check,
11
+ never weaken the gate).
11
12
 
12
- **The rule that keeps it safe:** you (the agent) make edits; **Ark decides what may land.** Only
13
- `mechanical-safe` changes are auto-applied (validated, with rollback); everything `judgment` is
14
- PROPOSED for a human decision. Code only — never DB/schema, never weakening the gate.
15
13
 
16
- ## Two entry styles, three operating modes, one contract
14
+ ## Related onboarding
17
15
 
18
- **Who is driving** (entry style):
16
+ - **Greenfield:** `/ark-architect` or `ark-check --recommend` / `ark start`.
17
+ - **Brownfield:** `/ark-adopt` — match contract to reality; do not force a starter preset.
18
+ - **Default path:** `ark start` → `/ark-autopilot` → `ark-check --doctor`.
19
19
 
20
- - **Newbie (default here):** run the WHOLE flow with plain-language explanations and an
21
- approval prompt before anything non-trivial. The user never needs to know a preset or a rule
22
- name. This skill is that flow.
23
- - **Expert:** skip the autopilot and use the pieces directly — `ark init` / `/ark-contract` to
24
- shape the contract, `ark-check --plan` to see the work, `/ark-fix` for targeted fixes,
25
- `ark-check --strict-config` as the gate. Point them there and stop.
20
+ ## Anti-wrapper rule (mandatory)
26
21
 
27
- **What Ark is doing right now** (operating mode read from `ark start` / `--plan` / `--coverage`):
22
+ **Forbidden:** only printing `--plan` JSON or “4 safe / 4 judgment approve?” without reading the violating files.
28
23
 
29
- - **Suggest** — thin or greenfield project: propose an application shape and install a starter contract.
30
- - **Adapt** brownfield or low `governed%`: match the contract to the real layout, raise coverage,
31
- freeze only real debt. A clean plan with ~0% governed is **not** done route to `--coverage` / `/ark-adopt`.
32
- - **Enforce** `goal.met` is true *and* governed coverage is meaningful: write gate + CI hold the line.
24
+ **Required:**
25
+ 1. CLI sensor: `ark-check --plan --json`, coverage/doctor as needed.
26
+ 2. **Open every file** in the plan’s `steps[]` (and its `target` if present) before classifying a fix.
27
+ 3. **“Así te lo re-soluciono”** for each cluster of steps: exact moves (extract type, relocate file, invert dependency).
28
+ 4. Apply → re-run ark-check → rollback on regression.
33
29
 
34
- Never tell a user "your architecture is guarded" while `--plan` reports `goal.met: false` or
35
- `governedPercent` is low.
30
+ ## Operating modes (detected, not picked)
36
31
 
37
- ## Flow (newbie tier)
32
+ - **Setup (Suggest):** no config → `ark start` / recommend shape.
33
+ - **Align (Adapt):** open debt or low honesty → drive loop; do not claim “guarded”.
34
+ - **Guard (Enforce):** `goal.met` and solid governed% → install/confirm gates and stop.
38
35
 
39
- 1. **Set up if needed.** If there's no `ark.config.json`, run the guided setup: `ark start`
40
- (which itself uses `ark-check --recommend` to suggest a shape in plain language, then writes
41
- the config + agent/CI gates, and captures the **origin** architecture report under
42
- `.ark/reports/`). On an established codebase it adopts the real structure. If
43
- Ark is already set up, skip to step 2.
36
+ ## Flow
44
37
 
45
- 2. **Freeze / confirm the starting picture.** Always run once before changing code:
38
+ 1. **Setup if needed** `ark start` if no `ark.config.json`.
39
+ 2. **Origin report** — `ark-check --report ark-report.html` (do not `--reset-origin` unless asked).
40
+ 3. **Plan + code read** — `--plan --json`; read each step’s source/target; group by edge.
41
+ 4. **Concentrated edge?** — if one edge dominates, route to `/ark-contract` with a **source-based** diagnosis (not freeze).
42
+ 5. **Worktree preferred** — discardable git worktree when possible.
43
+ 6. **Mechanical-safe** — only kinds from `/ark-loop` table; one step, validate, rollback.
44
+ 7. **Judgment** — default: propose with full “así te lo re-soluciono”. If user authorized full apply: implement the designed fix, validate, rollback on fail.
45
+ 8. **Manifiesto** — if loose business rules surface (domain logic in UI/core), propose Domain placement + `intentPrefixes` / intents; apply config only via `/ark-contract` discipline (strict check after).
46
+ 9. **Final report** — `--report` again; evolution vs origin; honest summary of auto vs judgment vs deferred.
47
+ 10. **Strict check** — `ark-check --strict-config` (dead preset globs are advisory; real violations still fail).
46
48
 
47
- ```bash
48
- npx ark-check --root . --config ark.config.json --report ark-report.html
49
- ```
49
+ ## Never
50
50
 
51
- - If `.ark/reports/origin.json` did not exist, this **creates the origin snapshot** (day-one
52
- baseline). Do **not** pass `--reset-origin` unless the user explicitly wants a new baseline.
53
- - Open / point the user at `ark-report.html` (and `.ark/reports/origin.html` when first created).
54
- - This is the “before” picture the autopilot will improve against.
51
+ - Disable rules, broaden allows, or baseline **new** debt to “finish”.
52
+ - Claim clean while judgment steps were skipped without user decision.
53
+ - Replace host Nest/DI with the runtime kernel unasked.
55
54
 
56
- 3. **Show the plan.** Run `ark-check --plan` and explain it in outcome terms: how many fixes are
57
- _safe to auto-apply_ vs _need your decision_ vs _deferred_, and what the goal is (a clean,
58
- enforced architecture). Safe auto steps are only the three `mechanical-safe` kinds:
59
- type-only type move, pure-type **file** relocate, and converting static imports of pure-type
60
- modules to `import type` (see `/ark-loop`). Confirm before changing anything.
55
+ ## Done criteria
61
56
 
62
- 4. **Drive the loop.** Hand off to **`/ark-loop`**: in a discardable git worktree, auto-apply
63
- the `mechanical-safe` steps one at a time (match each `remediationKind`; validate with
64
- `ark-check`, roll back regressions), and PROPOSE each `judgment` step in plain language for
65
- a yes/no. Loop until the plan's `goal.met` is true or a round makes no progress.
66
-
67
- 5. **Confirm it stays clean.** Verify the gates are installed and active so the architecture is
68
- enforced from now on (in CI, and at write time if the MCP hook is wired) — the
69
- "and stays that way" half of the promise. Run the final `ark-check --strict-config`.
70
-
71
- 6. **Close with the after report + evolution.** Run again:
72
-
73
- ```bash
74
- npx ark-check --root . --config ark.config.json --report ark-report.html
75
- ```
76
-
77
- The HTML now includes **Evolution vs origin** (score, governed%, violations, files per layer)
78
- when origin already existed. Point the user at:
79
- - `ark-report.html` / `.ark/reports/latest.html` — **after**
80
- - `.ark/reports/origin.html` — **before** (frozen)
81
- - `.ark/reports/history/` — optional JSON trail
82
-
83
- 7. **Report honestly, in plain language.** Summarize what was auto-applied, what you proposed
84
- and the user decided, and what's deferred (and why). Tie the narrative to the before/after
85
- report numbers. Show the diff. Only merge the worktree back after the user reviews. Never
86
- report "done / clean" while steps were skipped.
87
-
88
- ## Operating rules
89
-
90
- - Never weaken the gate to finish: no disabling rules, editing `ark.config.json` to allow a bad
91
- edge, or baselining a fresh violation. Fix the code, or propose a contract change via
92
- `/ark-contract` with its before/after impact.
93
- - If most violations concentrate on one edge, that's a contract smell — stop and route to
94
- `/ark-contract`, don't grind N fixes.
95
- - Bias to proposing: when unsure a change preserves behavior, treat it as `judgment`.
96
- - Everything traces to Ark's own outputs (`ark-check --plan --json`, `--recommend`) — never
97
- invent architecture advice.
57
+ - Every applied step validated by real `ark-check`.
58
+ - Final plan `goal.met` true **or** remaining steps listed with file-level proposals and why blocked.
59
+ - Report cites paths you changed and reports HTML paths.