arkgate 2.10.0 → 2.12.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 (55) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/README.md +21 -12
  3. package/SECURITY.md +3 -4
  4. package/bin/ark-check.mjs +41 -16
  5. package/bin/ark-mcp.mjs +54 -10
  6. package/bin/ark.mjs +87 -24
  7. package/bin/lib/agent-gates.mjs +68 -2090
  8. package/bin/lib/architecture-scan.mjs +4 -1
  9. package/bin/lib/baseline-key.mjs +17 -0
  10. package/bin/lib/ci-and-commands.mjs +386 -0
  11. package/bin/lib/config-warnings.mjs +22 -0
  12. package/bin/lib/core-layers.mjs +7 -0
  13. package/bin/lib/core-ratchet.mjs +3 -7
  14. package/bin/lib/deploy-path.mjs +205 -0
  15. package/bin/lib/doctor-plan.mjs +29 -5
  16. package/bin/lib/gate-files.mjs +223 -0
  17. package/bin/lib/hook-templates.mjs +99 -0
  18. package/bin/lib/install-migrate.mjs +442 -0
  19. package/bin/lib/mcp-adoption.mjs +423 -0
  20. package/bin/lib/presets.mjs +3 -0
  21. package/bin/lib/safety-diagnostics.mjs +263 -0
  22. package/bin/lib/scan-files.mjs +51 -6
  23. package/bin/lib/skill-install.mjs +259 -0
  24. package/bin/lib/typescript-host.mjs +88 -0
  25. package/bin/lib/violations.mjs +3 -3
  26. package/bin/lib/write-path-detect.mjs +138 -0
  27. package/dist/index.cjs +103 -8
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +5 -3
  30. package/dist/index.d.ts +5 -3
  31. package/dist/index.js +103 -8
  32. package/dist/index.js.map +1 -1
  33. package/dist/nestjs/index.cjs +18 -5
  34. package/dist/nestjs/index.cjs.map +1 -1
  35. package/dist/nestjs/index.d.cts +1 -1
  36. package/dist/nestjs/index.d.ts +1 -1
  37. package/dist/nestjs/index.js +18 -5
  38. package/dist/nestjs/index.js.map +1 -1
  39. package/dist/runtime/index.cjs +103 -8
  40. package/dist/runtime/index.cjs.map +1 -1
  41. package/dist/runtime/index.d.cts +1 -1
  42. package/dist/runtime/index.d.ts +1 -1
  43. package/dist/runtime/index.js +103 -8
  44. package/dist/runtime/index.js.map +1 -1
  45. package/dist/{types-D6Q8WHes.d.cts → types-BZ17b9i5.d.cts} +5 -1
  46. package/dist/{types-D6Q8WHes.d.ts → types-BZ17b9i5.d.ts} +5 -1
  47. package/docs/agent-guide.md +12 -2
  48. package/docs/ai-gates.md +20 -2
  49. package/docs/package-surface.md +10 -3
  50. package/docs/production-hardening.md +5 -0
  51. package/package.json +5 -2
  52. package/server.json +2 -2
  53. package/templates/skills/ark-autopilot.md +77 -45
  54. package/templates/skills/ark-explain.md +2 -1
  55. package/templates/skills/ark-explore.md +135 -34
@@ -1,13 +1,15 @@
1
1
  ---
2
2
  name: ark-explore
3
- description: Exploratory architecture reconnaissance of the real project product map, entry points, coupling hotspots, false-green risks, and suggestive next bets. CLI is a sensor; you read the tree. No gate bypass.
3
+ description: Decision-grade architecture recon sensor + tree + field path + coupling evidence. Rank residual that changes action; optional dual-plan seed (not multi-week roadmaps). CLI is a sensor; you read the tree. No gate bypass.
4
4
  ---
5
5
 
6
6
  # /ark-explore — Recon the real project
7
7
 
8
8
  You are a **staff engineer doing architecture reconnaissance** on *this* repository.
9
- Ark’s CLI is a **sensor** (coverage, doctor, plan). **You** open source, README, entry
10
- points, and git history. Output is **suggestive and ranked**, not a green checkbox.
9
+ Ark’s CLI is a **sensor** (coverage, doctor, plan). **You** open source, entry points,
10
+ install hooks, examples/starters, and coupling evidence. Output is **decision-grade**:
11
+ ranked residual that changes the next command — **not** a celebration of ENFORCE and
12
+ **not** a paraphrase of README/ROADMAP.
11
13
 
12
14
  Use alone when the user wants a map / options / “what should we do next?”.
13
15
  `/ark-autopilot`, `/ark-coverage`, and `/ark-adopt` embed a lighter version of this pass.
@@ -17,17 +19,48 @@ Use alone when the user wants a map / options / “what should we do next?”.
17
19
  - **Greenfield / thin tree:** `/ark-architect` or `ark-check --recommend` / `ark start`.
18
20
  - **Brownfield:** `/ark-adopt` after the map (or hand off from explore STOP paths).
19
21
  - **Default path:** `ark start` → `/ark-autopilot` → `ark-check --doctor`.
22
+ - **Execute dual plan + apply:** `/ark-autopilot` (explore is recon / seed, not the loop).
20
23
 
21
24
  ## Dual engine (mandatory)
22
25
 
23
26
  | Engine | Role | Never confuse with |
24
27
  |--------|------|--------------------|
25
28
  | **Deterministic** | Contract truth: layers, rules, violations, `mechanical-safe` kinds, exit codes | Product vision or “good enough” |
26
- | **Exploratory** | Your judgment from **reading this tree**: product surface, hotspots, false greens, opportunities | Only paraphrasing CLI JSON |
29
+ | **Exploratory** | Your judgment from **reading this tree**: product surface, field path, hotspots, false greens / false promises, design patterns lived | Only paraphrasing CLI JSON or docs |
27
30
 
28
- **Incomplete:** doctor/coverage dump with no file paths you opened.
29
- **Complete:** map + ranked bets + “así te lo re-soluciono” with real paths.
31
+ **Incomplete:** doctor/coverage dump with no file paths you opened; or a long map that
32
+ only restates README; or a multi-week roadmap when the user only asked for a map.
33
+ **Complete:** dry headline + field evidence + ranked bets with **así te lo re-soluciono**
34
+ (real paths, concrete next step, **success signal**) + honest handoff when residual is
35
+ *not* layer debt.
30
36
 
37
+ **ENFORCE / 100% governed / empty plan is baseline, not a finding.** Lead with residual
38
+ that still matters (dogfood gaps, soft starters, identity drift, **semantic false-green**,
39
+ coupling that blocks evolution). If residual is truly none, say so in one line and hand
40
+ off `stop`.
41
+
42
+ ## Output mode (pick one — do not invent a third)
43
+
44
+ | Mode | When | Deliverable |
45
+ |------|------|-------------|
46
+ | **Recon (default)** | map / residual / “what next?” / bare `/ark-explore` | Headline → map → ranked table → **Top 3** → residue → Completion |
47
+ | **Dual-plan seed** | user asks for a **plan**, mejora, roadmap, o “Ark + patrón de diseño” | Same recon **plus** a short **§ Dual-plan seed** (below). **Cap 3–5 B bets.** |
48
+
49
+ **Forbidden in either mode:**
50
+ - A 6-phase / multi-week implementation roadmap as the default explore product.
51
+ - Phases with week estimates, long PR stacks, or vanity “Domain ≥ N files” as done criteria.
52
+ - Auto-applying anything (explore does not edit the contract or product code unless the user
53
+ separately asks to execute a bet).
54
+
55
+ **Dual-plan seed shape (mode 2 only):**
56
+
57
+ | Section | Content |
58
+ |---------|---------|
59
+ | **A. Remediation** | From `--plan` — usually empty when ENFORCE; one line if so |
60
+ | **B. Pattern / evolution** | **3–5** bets max from the ranked table; each: evidence · así te lo re-soluciono · **success signal** · next skill · **kill-switch** if proposing a new layer/big move |
61
+
62
+ Long multi-PR execution plans belong to **`/ark-autopilot`** (or a human-owned doc after
63
+ the seed), not to explore by default.
31
64
 
32
65
  ## Subagent fan-out (optional, host-dependent)
33
66
 
@@ -46,63 +79,131 @@ feature dirs, plan clusters), you **may** dispatch **subagents**:
46
79
  4. Parent owns the **### Completion** block (union of **Opened**, single **Handoff**).
47
80
  5. Do **not** use subagents to weaken the gate or invent `mechanical-safe` kinds.
48
81
 
82
+ Useful split when present: **core product tree** vs **field path** (`examples/`,
83
+ `templates/`, gallery starters, eval fixtures) vs **agent install surfaces** (hooks,
84
+ MCP, CI templates).
85
+
49
86
  ## Anti-wrapper rule
50
87
 
51
- **Forbidden:** only `ark-check --json` / `--coverage` / `--doctor` paraphrase.
88
+ **Forbidden:**
89
+ - Only `ark-check --json` / `--coverage` / `--doctor` paraphrase.
90
+ - Echoing README / ROADMAP / marketing as if it were recon.
91
+ - Padding the ranked table with “architecture is clean” rows when the sensor already said that.
92
+ - Ranking debt by **LOC alone** without fan-in, exports, or call-site evidence.
93
+ - **Vanity success metrics** as bet done criteria (e.g. “Domain ≥ 20 files”, “add a layer
94
+ because the diagram is prettier”) without multi-surface proof or a kill-switch.
95
+ - Multi-week roadmaps when mode is recon-only.
52
96
 
53
97
  **Required:**
54
98
  1. Sensor: `--coverage --json`, `--doctor`, optional `--plan --json` / normal check.
55
- 2. **Product + code pass** (below) — min **12 source files** across **≥4 directories** that matter for *this* product (apps, packages, features, domain, adapters, API routes).
56
- 3. Ranked **suggestions** (opportunities), not only residual violations.
57
- 4. Hard lines: never weaken the contract; never invent mechanical-safe kinds.
99
+ 2. **Product + code pass** — min **12 source files** across **≥4 directories** that matter for *this* product (apps, packages, features, domain, adapters, API routes, CLIs).
100
+ 3. **Field path** when scaffolds exist (see §E); for pure apps, **internal field path** (see §E).
101
+ 4. **Coupling evidence** beyond “large file” (see §C).
102
+ 5. **Path-correct vs design-correct** pass (see §B).
103
+ 6. Ranked rows that **change a decision**; each bet has a **success signal** (not a file count).
104
+ 7. Hard lines: never weaken the contract; never invent mechanical-safe kinds; never claim ENFORCE from type-only cleanup while false-green doctor ids are active.
58
105
 
59
106
  ## Reconnaissance pass (do all that apply)
60
107
 
61
108
  ### A. Product surface (what the system is)
62
- - README / package.json `description` / scripts / monorepo workspace roots.
63
- - User-facing entry: Next/Nest/Express routes, CLIs, workers, public APIs.
109
+ - README / package.json `description` / scripts / monorepo workspace roots — **skim for entry points**, do not restate the pitch.
110
+ - User-facing entry: Next/Nest/Express routes, CLIs, workers, public APIs, package exports.
64
111
  - Deploy shape if obvious (apps/, packages/, services/).
65
- - One paragraph: **“What does this product do for a real user?”**
112
+ - One dry line: **what a real user/agent gets** (not the slogan).
66
113
 
67
- ### B. Architecture as lived (not only as configured)
114
+ ### B. Architecture as lived path-correct vs design-correct
68
115
  - Map top dirs → intended layer vs what code *actually* does (UI, use-cases, I/O, pure domain).
69
- - Empty Domain / Persistence while Application owns `airtable|supabase|prisma|repositories` → **false-green** (doctor id `contract-false-green-io-under-application`).
116
+ - Classic false-green: empty Domain / Persistence while Application owns `airtable|supabase|prisma|repositories` → doctor id `contract-false-green-io-under-application`.
117
+ - **Semantic false-green** (edges green, names lie) — flag when you see it:
118
+ - HTTP handlers / route bodies living under `repositories/` or Persistence globs.
119
+ - Presentation/routes defaulting to a data facade (`platform/*`, raw db) while “repos exist”.
120
+ - Domain layer thin while pure business rules sit in Application with no I/O (should be Domain).
121
+ - Layer labels that match globs but not role (gate path-correct, design wrong).
70
122
  - Framework guts vs product code (Nest modules, Next app router, generated clients).
71
-
72
- ### C. Coupling & debt beyond the plan list
73
- - Import hotspots, god modules, cross-feature leaks (`peerIsolation` candidates).
123
+ - **Identity risk:** which layer owns the product *wedge* vs file-count / public barrel.
124
+ - **Concurrent design patterns** (short table when ≥2 styles coexist): name each pattern,
125
+ one example path, quality (`canonical` / `gate-green design-weak` / `legacy`). Mark the
126
+ **golden** pattern to copy. Do not only list layer file counts.
127
+
128
+ ### C. Coupling & debt (measure, don’t guess)
129
+ Prefer evidence over aesthetics:
130
+ - **Fan-in / importers** of hot modules (who imports the suspect file?).
131
+ - **Export surface** (how many public symbols does the orchestration module re-export?).
132
+ - Import cycles, cross-feature leaks (`peerIsolation` candidates).
74
133
  - Business rules in UI/hooks (`can*`, `calculate*`, policy constants) → Domain / intents.
75
- - Dead or aspirational globs; layers with files but no rules.
134
+ - Dead or aspirational globs; layers with files but no rules; **starter/preset rules weaker than sibling archetypes** (soft green).
135
+ - LOC is a **hint** only — pair it with fan-in or export count before calling something a god module.
76
136
 
77
- ### D. Agent / gate reality
137
+ ### D. Agent / gate reality (installed vs generated)
78
138
  - Write gate + CI + `/ark-*` skills present? Stale skills? Global vs pinned `arkgate`?
139
+ - **Installed hooks vs install templates:** compare project PreToolUse / write-hook commands to what `--install-agent-gates` would emit (e.g. reject-only `--hook` vs `--hook-repair`). Doctor `writePath` / adoption gaps are leads — **verify on disk**.
140
+ - MCP config present and pointing at a real binary? `prepare-write` / autoPatch surface vs hook mode.
79
141
  - Baseline: real debt or hiding contract smell?
80
-
81
- ### E. Suggestive bets (not commits yet)
142
+ - CI: is architecture check required on the default branch path this repo actually uses?
143
+ - **Origin:** is `.ark/reports/origin.json` present? (Day-zero picture; missing → note as agent-dx / adopt gap, not a layer violation.)
144
+
145
+ ### E. Field path (consumer promise or internal)
146
+ When `examples/`, `templates/`, gallery starters, eval fixtures, or docs claim “copy this and stay green”:
147
+ 1. Open **≥2** scaffolds (prefer one minimal gallery + one “deep” / runnable demo).
148
+ 2. **Run** their documented check script when cheap (`npm run check`, `ark-check --strict-config`); record pass/fail — do not trust README alone.
149
+ 3. Diff **rule strength** across archetypes (missing denies = soft false-green for consumers).
150
+ 4. Note import style vs package surface docs (`arkgate` root barrel vs preferred subpath).
151
+ 5. Flag **false promises**: demo fails under its own check, or green with a hollow contract.
152
+
153
+ If the repo is a **pure app** (no examples): state **Field path: internal** and do one of:
154
+ - Name the **norm for new code** that the residual implies (e.g. “no new `platform/db` in routes”), or
155
+ - Point at one **smoke** the team could add (lint/CI allowlist, PR checklist) — do not invent a full CI system.
156
+
157
+ ### F. Suggestive bets (not commits yet)
82
158
  For each opportunity: **impact × effort × enforceability** (can the gate hold it after?).
83
159
 
84
- ## Output format
160
+ **Success signal (required per bet)** — observable, not vanity:
161
+ - Good: `doctor.writePath = repair`; `ark-check` green after promote; API + UI import same pure `computeX`; 0 new routes with facade SQL; pilot cluster migrated + kill-switch decision recorded.
162
+ - Bad: “Domain has ≥ N files”; “add layer X”; “more documentation”.
163
+
164
+ **Kill-switch (required if the bet adds a layer, peerIsolation wall, or big-bang move):**
165
+ - Name a **pilot** (one cluster) and a **stop condition** (e.g. “if pilot does not reduce confusion in 2 real PRs → prefer handlers-under-domain without a new layer”).
166
+ - Prefer **forward-only + migrate-on-touch** over big-bang.
167
+
168
+ Prefer bets the user can run next (`command` / skill), not vague “improve DX”.
169
+
170
+ ## Output format (keep tight)
85
171
 
86
- 1. **Headline** product in one sentence + honesty (mode, governed%, false-green risk).
87
- 2. **Map** — entry points, major packages/dirs, shape name (or “no honest shape yet”).
88
- 3. **What I opened** — bullet list of paths (prove the explore pass).
89
- 4. **Ranked table**
172
+ State **Mode: recon | dual-plan seed** in the headline or first line.
90
173
 
91
- | # | Kind | Finding | Evidence (path) | Suggestion | Next skill / command |
174
+ 1. **Headline** product in one sentence + honesty line (mode, governed%, false-green / semantic false-green / false-promise risk). ENFORCE is context, not the story.
175
+ 2. **Map** — one short table or bullet map: entry points, major dirs, shape name (or “no honest shape yet”). One screen max. Include **patterns concurrent** table when relevant (§B).
176
+ 3. **What I opened** — paths + sensors that prove the pass (include field/hook/origin paths when used).
177
+ 4. **Ranked table** — **only rows that change a decision**. Prefer **3–6** hard rows; drop filler.
178
+
179
+ | # | Kind | Finding | Evidence (path) | Así te lo re-soluciono | Success signal | Next skill / command |
92
180
 
93
181
  Kinds: `risk` | `false-green` | `debt` | `opportunity` | `shape` | `manifiesto` | `agent-dx`
94
182
 
95
- 5. **Top 3 bets** if the user says “go”, which skill runs first and why.
183
+ **Así te lo re-soluciono** must be concrete: files to touch, command to run.
184
+ **Success signal** must be falsifiable (see §F). If proposing a new layer / wall: add kill-switch in the así-te-lo cell or a footnote.
185
+
186
+ 5. **Field path summary** (scaffolds and/or internal norm).
187
+ 6. **Top 3 bets** — if the user says “go”, ordered execution. First bet = highest leverage residual, even when plan is empty (agent-dx / field honesty / design-correct — not “run loop on zero steps”).
96
188
  On false-green dominant: **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`.
97
189
  On concentrated edge dominant: **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).
98
- 6. **Deterministic residue** — if plan has steps, point to `/ark-loop` / `/ark-fix` without claiming they are the whole architecture story.
190
+ 7. **Dual-plan seed** — **only in mode 2**; A + B with cap 3–5 B rows; no multi-week phase chart.
191
+ 8. **Deterministic residue** — compact: plan steps, violations, doctor top action. Point to
192
+ `/ark-loop` / `/ark-fix` **only when steps exist**; never pretend loop is the architecture story when goal is already met.
193
+
194
+ Optional when useful: **Diff vs naive sensor-only read** (one short list: what reading the tree changed).
99
195
 
100
196
  ## Done criteria
101
197
 
102
- - ≥12 source files read and cited.
103
- - At least **3 suggestive** rows (not only “fix violation X”).
104
- - Clear handoff: `/ark-adopt` | `/ark-contract` | `/ark-autopilot` | `/ark-loop` | stop.
105
- - No gate weakening; no false ENFORCE claim.
198
+ - ≥12 source files read and cited across ≥4 directories.
199
+ - Field path: scaffolds run/opened **or** pure-app internal norm stated.
200
+ - At least **3 decision-grade** rows (not “fix violation X” and not “layers are clean”).
201
+ - Coupling claims backed by fan-in / exports / importers (or clearly marked as LOC-only hint).
202
+ - Path vs design called out when concurrent patterns or semantic false-green exist.
203
+ - Every Top-3 / B bet has a **success signal**; new-layer bets have a **kill-switch**.
204
+ - Mode respected: no multi-week roadmap in recon mode; dual-plan seed capped at 3–5 B bets.
205
+ - Clear handoff: `/ark-adopt` | `/ark-contract` | `/ark-autopilot` | `/ark-loop` | `/ark-fix` | CLI command | `stop`.
206
+ - No gate weakening; no false ENFORCE claim; no README echo as primary content.
106
207
 
107
208
  ## Completion contract (skill incomplete if missing)
108
209