arkgate 4.2.0 → 4.3.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 (46) hide show
  1. package/CHANGELOG.md +86 -4
  2. package/README.md +20 -6
  3. package/bin/ark-mcp-runtime.mjs +64 -0
  4. package/bin/ark-shared.mjs +16 -4
  5. package/bin/ark.mjs +55 -1
  6. package/bin/lib/adapter-contract.mjs +88 -5
  7. package/bin/lib/agent-projection-command.mjs +396 -0
  8. package/bin/lib/agent-projection.mjs +319 -0
  9. package/bin/lib/agent-skills-package.mjs +266 -0
  10. package/bin/lib/baseline-key.mjs +32 -0
  11. package/bin/lib/ci-and-commands.mjs +44 -0
  12. package/bin/lib/diagnostic-catalog.mjs +155 -0
  13. package/bin/lib/physical-cohesion.mjs +2 -1
  14. package/bin/lib/status-command.mjs +369 -0
  15. package/bin/lib/status-manifest.mjs +394 -0
  16. package/dist/eslint/index.cjs +3 -3
  17. package/dist/eslint/index.js +3 -3
  18. package/dist/index.cjs +46 -11
  19. package/dist/index.d.ts +729 -6
  20. package/dist/index.js +46 -11
  21. package/docs/README.md +6 -6
  22. package/docs/agent-guide.md +112 -14
  23. package/docs/configuration.md +7 -0
  24. package/docs/develop.md +8 -0
  25. package/docs/diagnostics.md +606 -0
  26. package/docs/package-surface.md +19 -8
  27. package/docs/product-voice.md +45 -0
  28. package/docs/use.md +23 -0
  29. package/package.json +11 -1
  30. package/schemas/ark.analysis-result.schema.json +14 -1
  31. package/schemas/ark.status-manifest.schema.json +244 -0
  32. package/server.json +2 -2
  33. package/templates/agent-skills/README.md +59 -0
  34. package/templates/agent-skills/ark-adopt/SKILL.md +171 -0
  35. package/templates/agent-skills/ark-architect/SKILL.md +175 -0
  36. package/templates/agent-skills/ark-autopilot/SKILL.md +242 -0
  37. package/templates/agent-skills/ark-contract/SKILL.md +136 -0
  38. package/templates/agent-skills/ark-coverage/SKILL.md +167 -0
  39. package/templates/agent-skills/ark-explain/SKILL.md +210 -0
  40. package/templates/agent-skills/ark-explore/SKILL.md +377 -0
  41. package/templates/agent-skills/ark-fix/SKILL.md +185 -0
  42. package/templates/agent-skills/ark-loop/SKILL.md +180 -0
  43. package/templates/agent-skills/ark-place/SKILL.md +162 -0
  44. package/templates/agent-skills/ark-runtime/SKILL.md +120 -0
  45. package/templates/agent-skills/ark-think/SKILL.md +133 -0
  46. package/templates/agent-skills/ark-upgrade/SKILL.md +218 -0
@@ -0,0 +1,218 @@
1
+ ---
2
+ name: ark-upgrade
3
+ description: Upgrade ArkGate through a content-identity preview, preserve customized files, and verify the active host and architecture contract.
4
+ ---
5
+
6
+ # /ark-upgrade — managed ArkGate upgrade
7
+
8
+ Upgrade the published `arkgate` package and its managed gates without treating a
9
+ filename, package version, or similar-looking file as proof of ownership. The
10
+ preview is the source of truth: inspect it before applying anything.
11
+
12
+ For greenfield onboarding, start with `/ark-architect` (or
13
+ `ark-check --recommend`); for a brownfield repository, use `/ark-adopt` before
14
+ this upgrade flow.
15
+
16
+ ## Dual engine (mandatory)
17
+
18
+ Use the semantic sensor (`ark-check --doctor --json` plus the strict contract
19
+ check) and direct inspection of every managed file the preview will change.
20
+ Neither signal replaces the other.
21
+
22
+
23
+ ## MCP workspace binding (mandatory)
24
+
25
+ Before any `ark_*` MCP tool, call `ark_identity` with `project.expectedRoot` set to the exact
26
+ workspace root. Continue only when `binding.status === "matched"` and `authoritative === true`;
27
+ retain `projectIdentity.projectId`, then pass both `expectedRoot` and `expectedProjectId` under
28
+ `project` on every later MCP call. If identity is missing, mismatched, unverified, or the root is
29
+ uncertain, do not consume MCP analysis: use the workspace-local CLI and report that MCP
30
+ restart/retargeting is required. `ark://manifest` never satisfies this preflight.
31
+
32
+ ## Dual plane — layers + ArkRules (mandatory, except /ark-runtime)
33
+
34
+ ArkGate has **two opt-in planes**. The user chooses which to use; you **always label** findings so they never blur.
35
+
36
+ | Plane | What it protects | Where it lives | Sensors / tools |
37
+ |-------|------------------|----------------|-----------------|
38
+ | **Layers** (inter-layer) | Who may import whom, capabilities, pure/forbiddenGlobals, peerIsolation | `ark.config.json` → `layers[]`, `rules[]` | graph check, baseline edges, doctor coverage % |
39
+ | **ArkRules** (intra-layer) | Structure inside a layer + domain invariants as data | `arkRules` map + `arkrules/<ExactLayerName>.json` | structure sensors, invariant coverage, `--rules-inventory`, doctor `rulesUnderContract` |
40
+
41
+ **Rules for every report / answer:**
42
+ 1. Prefix each finding or next step with **`[Layer]`** or **`[ArkRules]`** (or a two-column table with those headers).
43
+ 2. Never call an import-edge violation an “invariant” or an aggregate sensor a “layer deny.”
44
+ 3. Absence of `arkRules` is **valid** — do not force ArkRules unless the user wants them or residual inventory clearly wants a pilot.
45
+ 4. Editing `arkrules/*` or promoting modes is **`/ark-contract`**; fixing code under a structure sensor is **`/ark-fix`** / **`/ark-loop`** (judgment, never invent mechanical-safe).
46
+ 5. CLI helpers: `ark-check --rules-inventory --json`, doctor JSON `rulesUnderContract`, sensors emit `ARKRULE_*` / `INVARIANT_UNCOVERED` with `evidence.arkruleId`.
47
+
48
+
49
+ ### Upgrade + ArkRules
50
+ - Refresh skills + note if templates gained ArkRules deepen; do not force consumers to adopt `arkRules`.
51
+ - After upgrade: doctor `rulesUnderContract` if map exists; dual-truth note if `--no-install` left package pin old.
52
+
53
+ ## Safety contract
54
+
55
+ - Always invoke the **project-local** CLI (`npx arkgate` /
56
+ `node node_modules/arkgate/bin/ark.mjs`). Bare PATH `ark` / `arkgate` is unsafe
57
+ when a global 2.x install shadows the project (mutative legacy upgrade).
58
+ - `ark upgrade` (managed era) is read-only. It reports the selected profile and hosts, every
59
+ managed asset, its content state, and the exact next command.
60
+ - The first `ark upgrade --apply` updates the dependency and lockfile, then runs
61
+ the newly installed CLI to produce another read-only preview. It does **not**
62
+ apply that preview's gate or skill changes.
63
+ - The post-update/no-install preview's `nextCommand` includes
64
+ `--plan-digest <sha256:…>` and applies only that exact candidate. A changed file
65
+ or selection invalidates the digest instead of being overwritten.
66
+ - Missing or conflicted assets previously recorded as managed require explicit
67
+ `--accept-conflicts`. Stop and obtain user consent before using it.
68
+ - Customized files are preserved. Unrelated source files and similar filenames
69
+ are never adopted. The command never writes a Codex home or another global
70
+ directory implicitly.
71
+ - Do not combine this flow with legacy `--force`, `--migrate-commands`, or
72
+ `--codex-home` repair commands. Diagnose any older adoption debt separately.
73
+
74
+ ## Read the states
75
+
76
+ | State | Meaning | Action |
77
+ |---|---|---|
78
+ | `current` | Content identity matches the candidate. | Record/adopt safely; metadata-only stamps may refresh. |
79
+ | `stale` | Recorded managed content still matches its old identity. | Safe candidate replacement. |
80
+ | `missing` | Candidate is absent. | Create if new; require consent if a recorded asset was deleted. |
81
+ | `customized` | User content diverged without a competing managed base. | Preserve it. |
82
+ | `conflicted` | Both managed base and user content diverged. | Preserve and require explicit consent. |
83
+ | `retired` | A recorded asset is no longer selected by the candidate. | Preserve its file and manifest identity; take no action. |
84
+
85
+ ## Procedure
86
+
87
+ 1. **Resolve the project CLI (mandatory before any upgrade command).** Prefer the
88
+ **project-local** binary — never bare `ark` / `arkgate` from PATH unless you
89
+ prove it is this project's install.
90
+
91
+ Resolution order:
92
+
93
+ 1. `node node_modules/arkgate/bin/ark.mjs` from the repository root (both `arkgate`
94
+ and `ark` package bins map to this file).
95
+ 2. Package-manager exec from the project: `npx arkgate`, `pnpm exec arkgate`,
96
+ `yarn arkgate`, etc.
97
+
98
+ **Do not** use bare `ark` / `arkgate` from PATH unless `which ark` (or the
99
+ resolved realpath) is under this project's `node_modules/arkgate`, or the
100
+ binary reports the **same** version as `node_modules/arkgate/package.json` and
101
+ supports managed upgrade.
102
+
103
+ **Capability probe (abort if missing):** run
104
+ `node node_modules/arkgate/bin/ark.mjs upgrade --help` (or the resolved local
105
+ equivalent) and require a **managed upgrade** surface — help text must mention
106
+ `--plan-digest` (and read-only `upgrade --json` preview). If the only available
107
+ CLI is old (global Homebrew / npm global 2.x, or any binary whose help lacks
108
+ `--plan-digest`), **stop**: skill incomplete; do **not** preview or apply.
109
+ Global 2.x `ark upgrade` is mutative and can rewrite managed skills, forcing a
110
+ later `--accept-conflicts` recovery.
111
+
112
+ **Recovery (preferred → optional):**
113
+
114
+ - Preferred: package-manager runner from project / `--root`
115
+ (`npx arkgate upgrade …` / `pnpm exec arkgate upgrade …` / `yarn arkgate upgrade …`).
116
+ This works when arkgate is **hoisted** and a nested package has no shallow
117
+ `node_modules/arkgate`.
118
+ - Secondary: `node node_modules/arkgate/bin/ark.mjs upgrade …` from the
119
+ **workspace install root** (not a nested package lacking a local install).
120
+ - Optional: refresh a global install with `npm i -g arkgate@latest` only if the
121
+ user wants a global binary; still prefer project-local for this procedure.
122
+
123
+ Record the resolved CLI path/version, read
124
+ `node_modules/arkgate/package.json`, query `npm view arkgate version`, identify
125
+ the repository package manager, and open the intervening entries in the
126
+ shipped `CHANGELOG.md` (fall back to registry or release notes and name that
127
+ source). Do not infer “latest” from `node_modules` alone.
128
+
129
+ 2. **Preview managed content.** Using the **project-local** CLI from step 1
130
+ (never a bare PATH `ark` that failed the probe), run:
131
+
132
+ ```bash
133
+ npx arkgate upgrade --json
134
+ # or: node node_modules/arkgate/bin/ark.mjs upgrade --json
135
+ ```
136
+
137
+ Pass `--root <path>` and `--tools <active-host>` when selection would otherwise
138
+ be ambiguous. Open the reported files that matter to this repository. Confirm
139
+ that customized files remain non-applying and that any deletion/conflict is
140
+ blocked.
141
+
142
+ 3. **Update and re-preview.** If the registry is newer, run (project-local CLI):
143
+
144
+ ```bash
145
+ npx arkgate upgrade --apply
146
+ ```
147
+
148
+ This updates through the detected package manager and hands control to the new
149
+ package for a fresh preview. Review that new preview; do not assume the old
150
+ candidate and new candidate are identical. If already on the latest package,
151
+ retain the current read-only preview.
152
+
153
+ For pnpm repositories with `minimumReleaseAge`, use the repository's existing
154
+ trusted first-party exception mechanism when the new release is still cooling
155
+ off, and prove `pnpm install --frozen-lockfile` succeeds.
156
+
157
+ 4. **Apply only the reviewed candidate.** When there are no blocked assets, run
158
+ the preview's **exact** `nextCommand` as emitted (JSON field / human “Apply the
159
+ exact preview with: …”). That command is already **project-local**
160
+ (`npx arkgate` / `pnpm exec arkgate` / `yarn arkgate` — never bare PATH `ark`).
161
+ Do **not** rewrite it to bare `ark upgrade`; pasting through a global 2.x PATH
162
+ reintroduces the mutative footgun. Shape:
163
+
164
+ ```bash
165
+ npx arkgate upgrade --apply --no-install --plan-digest <preview-digest>
166
+ ```
167
+
168
+ If recorded deletion/conflict recovery is desired, ask first and then add
169
+ `--accept-conflicts`. Never add it merely to make the run green. Run a second
170
+ preview and require `summary.changed: 0`.
171
+
172
+ 5. **Verify enforcement and architecture.** Run
173
+ `npx arkgate-check --doctor --json` (or the project-local `ark-check`) and
174
+ the same fail-closed architecture command used by managed apply (normally
175
+ `npx arkgate-check --root . --config ark.config.json --strict-merge --json`).
176
+ Require `completeness: "complete"` and `ok: true`. Treat provider-unavailable CI
177
+ required-check evidence as `unverified`, never as proof that merges are
178
+ blocked. If new violations appear, hand off to `/ark-fix` for a small set or
179
+ `/ark-loop` / `/ark-autopilot` for residual debt; do not regenerate a baseline
180
+ without explicit approval.
181
+
182
+ ## Active host vs deferred hosts
183
+
184
+ **Active host:** its repo-local gate, skills, MCP/advisory surface, doctor evidence,
185
+ and strict check must be coherent before completion.
186
+
187
+ **Deferred hosts:** inactive hosts may remain untouched and must be named with a
188
+ future repair command when relevant. Deferred hosts never make Incomplete? `yes`
189
+ once the active host and shared repository surfaces are verified. A temporary
190
+ upgrade path or an actively selected host is not deferred.
191
+
192
+ The managed manifest retains the selected host set, so a later preview does not
193
+ silently switch to a different host. Home-level Codex setup is separate and is
194
+ never an implicit side effect of this skill.
195
+
196
+ ## Subagent fan-out (optional, host-dependent)
197
+
198
+ Parallelize independent preview, changelog, and enforcement checks when the
199
+ host supports isolated subagents; otherwise fall back to sequential execution.
200
+
201
+ ## Completion contract (skill incomplete if missing)
202
+
203
+ Skill incomplete if missing any required verification or any field below.
204
+
205
+ End with exactly this structure:
206
+
207
+ ### Completion
208
+ - **Sensor:** commands/tools run
209
+ - **Opened:** real project and changelog paths read
210
+ - **Active host:** host and verified status
211
+ - **Deferred hosts:** `none` or host plus future action
212
+ - **Result:** old → new version and managed-upgrade outcome
213
+ - **Planes:** one-line split of residual **[Layer]** vs **[ArkRules]** (or `n/a` if unused)
214
+ - **Handoff:** `/ark-…`, CLI action, or `none`
215
+ - **Incomplete?** `no` or `yes — <missing work>`
216
+
217
+ If a required verification did not run or a conflict remains blocked, report the
218
+ task incomplete. Deferred hosts (including Codex when inactive) never make Incomplete? yes.