@sabaiway/agent-workflow-kit 13.2.0 → 13.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.
- package/CHANGELOG.md +53 -0
- package/SKILL.md +1 -1
- package/capability.json +1 -1
- package/package.json +1 -1
- package/references/modes/bootstrap.md +1 -1
- package/references/modes/upgrade.md +4 -4
- package/references/templates/vehicles.json +8 -0
- package/tools/ensure-configs.mjs +8 -7
- package/tools/ensure-ops.mjs +15 -7
- package/tools/ensure-vocabulary.mjs +1 -1
- package/tools/vehicle-settings.mjs +127 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,59 @@ Semantically versioned ([semver](https://semver.org)), newest first. The `versio
|
|
|
4
4
|
is the current release. `upgrade` mode reads a project's `docs/ai/.workflow-version` and applies
|
|
5
5
|
every `migrations/<version>-<slug>.md` newer than it, in semver order.
|
|
6
6
|
|
|
7
|
+
## 13.3.0 — the executor vehicle's model becomes a project setting: `vehicle-settings.mjs` reads `docs/ai/vehicles.json` through two readers over one three-state table and resolves it to one posture, the seed `vehicles.json` ships, and the config ensure gains a seventh op, `vehicles`, fourth in the fixed order (AD-142)
|
|
8
|
+
|
|
9
|
+
**MINOR: one new tool, one new seed template, one new ensure op; no existing verb, token, cause or order of the six
|
|
10
|
+
prior ops moves.** The placed executor vehicle carried one model hard-wired in the bundled template — a project that
|
|
11
|
+
wanted another edited the placed file, which the placer then reported as a customization it never refreshed, and
|
|
12
|
+
when that model's quota ran out the slice died with it. This release ships the setting and its readers (story S1 of
|
|
13
|
+
the epic `EXECUTOR-VEHICLE-PINS-ONE-MODEL-AND-DIES-ON-ITS-QUOTA`); deriving the placed body from it and retrying a
|
|
14
|
+
refused slice on the fallback are the epic's second story. The contract is `docs/ai/specs/kit/vehicle-settings.md`
|
|
15
|
+
(live, revision 1, S1–S5 bound).
|
|
16
|
+
|
|
17
|
+
- **`tools/vehicle-settings.mjs` (127 lines, imports only `node:fs` and `node:path`).** The setting is ONE
|
|
18
|
+
strict-JSON file, `docs/ai/vehicles.json`, beside `orchestration.json` and `autonomy.json` — never a key of
|
|
19
|
+
`orchestration.json`. Its shape is closed: an optional `_README` string, then exactly one `executor` section of
|
|
20
|
+
exactly three non-empty bare-token string keys `model`, `effort` and `fallback` (`fallback` differing from `model`,
|
|
21
|
+
since an equal fallback retries into the same quota); every other form is MALFORMED, the reason naming the rel
|
|
22
|
+
path and the offending key or value. `readVehicles(cwd, readFile, lstat)` probes with lstat FIRST and never throws:
|
|
23
|
+
ENOENT alone answers `{ state: 'absent' }`; a directory, a symlink dangling or not, any other node kind, a
|
|
24
|
+
permission or read error, a parse error and a malformed body answer `{ state: 'unreadable', reason }` — the door
|
|
25
|
+
the read-only surfaces walk through; a well-formed regular file answers `{ state: 'present', settings }`.
|
|
26
|
+
`loadVehicles` is the same table with `unreadable` raised as the module-local `fail(1, reason)` (the
|
|
27
|
+
orchestration-config idiom, defined locally as every sibling reader does, so the module stays a leaf the read-only
|
|
28
|
+
surfaces can import). `resolveExecutor(answer)` is pure and answers `{ posture, reason }`: `present` the file's
|
|
29
|
+
three values with `source: 'file'`; `absent` the ONE frozen `EXECUTOR_DEFAULTS` — `model: 'opus'`, `effort: 'high'`,
|
|
30
|
+
`fallback: 'sonnet'` — with `source: 'default'`; `unreadable` a `null` posture and the reader's reason, so a broken
|
|
31
|
+
file is never mistaken for a healthy default. Exactly six exports: `VEHICLES_REL`, `EXECUTOR_DEFAULTS`,
|
|
32
|
+
`validateVehicles`, `readVehicles`, `loadVehicles`, `resolveExecutor`; no side effects on import.
|
|
33
|
+
- **`references/templates/vehicles.json` (new).** The seed: a `_README` sentence, then `executor` at the three
|
|
34
|
+
defaults; the suite pins its parsed `executor` equal to `EXECUTOR_DEFAULTS`, so no second hand-copy exists.
|
|
35
|
+
- **The seventh config ensure, `vehicles`, fourth in the fixed order after `autonomy`.** `ENSURE_OPS` in
|
|
36
|
+
`tools/ensure-vocabulary.mjs` reads `orchestration, gates, autonomy, vehicles, scripts, specs, index`;
|
|
37
|
+
`ensureVehicles` in `tools/ensure-ops.mjs` rides the existing `seedFromTemplate` door — create-only from the
|
|
38
|
+
bundled template, a present file preserved byte for byte and never read (a malformed present file is preserved,
|
|
39
|
+
not repaired: the readers are what name it), `wrong-node-kind` loud, `would-seed` under `--dry-run`, the outcome
|
|
40
|
+
tokens the seed family already had. `tools/ensure-configs.mjs` composes the table as before and says seven; the
|
|
41
|
+
op counts and banner ordinals inside `ensure-ops.mjs` were removed rather than renumbered, so the order lives in
|
|
42
|
+
`ENSURE_OPS` alone.
|
|
43
|
+
- **The mode docs count what runs.** `references/modes/upgrade.md`'s `configs` step performs all seven ensures and
|
|
44
|
+
names the vehicles declaration after the autonomy declaration with the shared `seeded` / `already-present` tokens
|
|
45
|
+
(both report clauses say seven); `references/modes/bootstrap.md` step 6 names the fourth seeded strict-JSON
|
|
46
|
+
config, `docs/ai/vehicles.json`, which the template loop now deploys on a fresh kit-path deployment. A deployment
|
|
47
|
+
on the memory package's own templates gets the file at its first upgrade run's ensure.
|
|
48
|
+
- **Tests.** `tools/vehicle-settings.test.mjs` (315 lines): one case per scenario S1–S5, the module and the ensure op
|
|
49
|
+
imported dynamically with throwing fallbacks so the suite loaded red on the tree before either existed; S3 walks
|
|
50
|
+
the whole malformed-form table, S4 six node kinds and IO errors with the lstat/readFile call order recorded, S5
|
|
51
|
+
the ensure's six outcomes plus the registry and the order. `ensure-configs.test.mjs`'s three outcome sequences
|
|
52
|
+
carry `vehicles: seeded` fourth; `composed-lines-ux.test.mjs`'s slot count reads `ENSURE_OPS.length`; the shipped
|
|
53
|
+
tarball pin is 311 (309 + the tool + the seed).
|
|
54
|
+
- **How it was built.** The story ran on the task tier as the pilot's measurement: ten ledger rows became ten
|
|
55
|
+
briefed tasks on wave `p1` — an author dispatch wrote each `TASK-` brief (kit-stamped against a fresh checkpoint),
|
|
56
|
+
an execute dispatch landed it — twenty codex-exec threads on one held session, every one folded first pass; the
|
|
57
|
+
diff council's findings were folded before the release; the plan council took six rounds. Figures:
|
|
58
|
+
`docs/ai/history/pilot-measure-2026-09-13.md`.
|
|
59
|
+
|
|
7
60
|
## 13.2.0 — the task tier lands: `checkpoint.mjs` mints, orders, verifies and prunes tree snapshots of a plan's sequence, `checkpoint-restore.mjs` restores one in three proven steps, `task-brief.mjs` stamps and checks a brief against the newest checkpoint, and `TASK-` is a scratch name (AD-141)
|
|
8
61
|
|
|
9
62
|
**MINOR: three new tools and one added arm of the scratch-name predicate; no existing verb, record, transition or
|
package/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: agent-workflow-kit
|
|
|
3
3
|
description: Deploy or upgrade a portable AI-agent memory-and-workflow system in any project. Use when the user wants to bootstrap `docs/ai/` + an entry-point `AGENTS.md` (+ `CLAUDE.md` alias) + cap/archive/index enforcement in a new or existing repo, set up the Memory Map and session protocols, install the docs-rotation pre-commit hook, or run `/agent-workflow-kit` / `/agent-workflow-kit upgrade`. Triggers on phrases like "set up the memory system", "deploy the AI workflow here", "bootstrap docs/ai", "upgrade the workflow".
|
|
4
4
|
disable-model-invocation: true
|
|
5
5
|
metadata:
|
|
6
|
-
version: '13.
|
|
6
|
+
version: '13.3.0'
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
# agent-workflow-kit
|
package/capability.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sabaiway/agent-workflow-kit",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.3.0",
|
|
4
4
|
"description": "Portable, cross-agent memory & workflow for AI coding agents — Claude Code, Codex, Cursor, Devin Desktop. One command deploys an AGENTS.md entry point + docs/ai context with cap/archive/index enforcement into any repo.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai-agents",
|
|
@@ -21,7 +21,7 @@ Requires: ${CLAUDE_SKILL_DIR}/references/shared/report-footer.md · ${CLAUDE_SKI
|
|
|
21
21
|
3. **Choose conversational language — answered in the step-2 batch.** Which language should the agent *talk to them* in — questions, explanations, summaries, status updates? Offer the language they're already writing in as the default. Carry the answer into the `{{COMM_LANGUAGE}}` slot of the *Communication language* block when `AGENTS.md` is created (step 5). See [Communication contract](${CLAUDE_SKILL_DIR}/references/contracts.md#communication-contract). This sets the **dialogue** language only — never the files.
|
|
22
22
|
4. **Choose agent attribution — answered in the step-2 batch.** May the agent attribute work to itself / to AI — `Co-Authored-By` trailers, "Generated with …" footers, "AI"/agent/model mentions in code, comments, commit messages, PR titles/bodies, or docs? **Default to `off`** (no agent/AI mention anywhere) unless they opt in — people are routinely surprised to find an AI listed as a repo contributor. Carry the answer into the `{{AGENT_ATTRIBUTION}}` slot of the *Attribution* block when `AGENTS.md` is created (step 5). **If `off` and the project uses Claude Code**, also set `"includeCoAuthoredBy": false` in the project's `.claude/settings.json` (create it if absent) — the trailer is added by the harness, so a doc directive alone won't stop it. See [Attribution contract](${CLAUDE_SKILL_DIR}/references/contracts.md#attribution-contract).
|
|
23
23
|
5. **Entry-point doc.** If `AGENTS.md` / `CLAUDE.md` already exist (step-1 recon), do **not** overwrite — show the user and ask whether to merge or replace. Otherwise create `AGENTS.md` (the cross-agent standard — Codex / Cursor / Devin Desktop / Copilot read it natively) from `${CLAUDE_SKILL_DIR}/references/templates/AGENTS.md`, and symlink `CLAUDE.md -> AGENTS.md` (`ln -s AGENTS.md CLAUDE.md`) for Claude Code — single source, no duplication. For nested context, add a subdir `AGENTS.md` (+ a `CLAUDE.md` symlink beside it for Claude Code).
|
|
24
|
-
6. **Deploy `docs/ai/`.** Create every `docs/ai/` file + `pages/` + the seed `adr/` store + the seed `specs/` store from `${CLAUDE_SKILL_DIR}/references/templates/` (the template loop deploys every template except `AGENTS.md`, `adr-record.md` and `SPEC_TEMPLATE.md` — the latter two are skill-home authoring references, never deployed). This deploys the HOT ADR window **`docs/ai/decisions.md`** and the seed navigator **`docs/ai/adr/log.md`** (its `adr/` subdir copies in wholesale), the spec store root **`docs/ai/specs/index.md`** (its `specs/` subdir copies in wholesale), the `.md` docs, **and** the
|
|
24
|
+
6. **Deploy `docs/ai/`.** Create every `docs/ai/` file + `pages/` + the seed `adr/` store + the seed `specs/` store from `${CLAUDE_SKILL_DIR}/references/templates/` (the template loop deploys every template except `AGENTS.md`, `adr-record.md` and `SPEC_TEMPLATE.md` — the latter two are skill-home authoring references, never deployed). This deploys the HOT ADR window **`docs/ai/decisions.md`** and the seed navigator **`docs/ai/adr/log.md`** (its `adr/` subdir copies in wholesale), the spec store root **`docs/ai/specs/index.md`** (its `specs/` subdir copies in wholesale), the `.md` docs, **and** the four seeded, user-editable strict-JSON configs: **`docs/ai/orchestration.json`** (the per-project recipe defaults the `procedures` advisor reads), **`docs/ai/gates.json`** (the project's gate declaration — seeded as the no-consent EMPTY list; FILLING it is the consented `gates-init` preview, `${CLAUDE_SKILL_DIR}/references/modes/gates.md`), **`docs/ai/autonomy.json`** (the per-project autonomy policy — seeded SPARSE with the onboarding note only, so it is exactly the computed defaults until the user declares levels via `/agent-workflow-kit set-autonomy` or by hand), and **`docs/ai/vehicles.json`** (the executor vehicle's model, effort and fallback as a setting the kit's readers resolve into one posture; the placed executor's body follows it from the release that derives it — seeded once, hand-edited, never clobbered). Keep each `.md` file's frontmatter (`type / lastUpdated / scope / staleAfter / owner / maxLines`); the `.json` seeds carry no frontmatter (the docs cap-validator globs `*.md` only, so they are inherently skipped).
|
|
25
25
|
7. **Fill templates** per the table below. **Then materialize the navigator, as the last `docs/ai` step:** the entry point declares `docs/ai/index.md` always-loaded and it is a GENERATED artifact with no template, so run `node ${CLAUDE_SKILL_DIR}/references/scripts/check-docs-size.mjs --ensure-index --root=<project>` and relay its one outcome line (`ensure-index: regenerated` / `already-current`, or a `write-refused` / `probe-failed` line naming the offending path — either is a STOP: resolve it before reporting the deploy, since the navigator the entry point declares does not exist yet). The generator runs from **this skill's own directory**, so a project with **no Node runtime** is covered too: the agent host runs it, and step 8's copy is not a precondition.
|
|
26
26
|
8. **Offer enforcement on every project, preview-first.** Explain in one line that the dependency-free Node scripts are available because the agent host already runs their step-7 navigator; the only skip condition is that the agent host cannot run them. Preview the source and destination list and ask; on a yes copy `${CLAUDE_SKILL_DIR}/references/scripts/*.mjs` (+ `*.test.mjs`) into the project's `scripts/`. On a no, skip the hook in step 9 and say so; the docs command slots then name no project-local command — fill `env_commands.md` and the `Docs caps + index freshness` row of `AGENTS.md` with the same note: the caps + index gate run from the agent's own skill copy (the step-7 `--root=<project>` form) and the archive rotations need the scripts deployed. Never write the skill's absolute path into a deployed doc. They self-configure (project name from `package.json` or, without one, the directory basename; hierarchical/on-demand sections auto-discovered). The hook calls `node scripts/<x>.mjs` directly, so a committer without `node` on PATH gets the hook's own loud failure.
|
|
27
27
|
9. **Wire / hide** per visibility (see [Visibility contract](${CLAUDE_SKILL_DIR}/references/contracts.md#visibility-contract)). When the user accepts the enforcement offer, install the pre-commit hook: `node scripts/install-git-hooks.mjs`. If the installer reports a pre-existing non-marker hook, stop and ask the user to merge it manually rather than overwriting. Once the gate declaration is final-run-capable, the installer's optional consented `--commit-guard <kit commit-guard.mjs path>` arm binds commits to the green `run-gates --final` receipt (the Recommendations advisor surfaces the exact one-liner).
|
|
@@ -31,7 +31,7 @@ Requires: ${CLAUDE_SKILL_DIR}/references/shared/report-footer.md · ${CLAUDE_SKI
|
|
|
31
31
|
|
|
32
32
|
**`footprint` — hidden-mode footprint reconcile (D9 / AD-014).** A deployment does not record whether it chose `hidden`, so first **infer visibility** — the dry-run writes **zero bytes** and reports one of — **visible** (the entry point is tracked) → nothing to do; **ambiguous** (untracked but not ignored — could be a fresh uncommitted repo, or a hide that broke) → **ASK** the user which it is, never guess; **hidden** → re-run without `--dry-run` to migrate any older **machine-global** hide to the **project-local** `.git/info/exclude` (one managed block; folds in the legacy `.claude/skills/` line), idempotently (a clean re-run is zero-diff). Handle its surfaced paths exactly as bootstrap step 9 (`${CLAUDE_SKILL_DIR}/references/modes/bootstrap.md`) (already-committed → show `git rm --cached`, ask before `--include`; generic-name present file → ask; **leftover machine-wide ignore block → ASK before `--remove-global`**, default keep + report). No Node on the agent host / Windows → as bootstrap step 9 (`${CLAUDE_SKILL_DIR}/references/modes/bootstrap.md`). This runs on **every** hidden upgrade, like the methodology slot — no lineage-head bump, no migration file.
|
|
33
33
|
|
|
34
|
-
**`configs` — the project-configuration ensures, ONE run.** The ONE command performs **all
|
|
34
|
+
**`configs` — the project-configuration ensures, ONE run.** The ONE command performs **all seven** ensures — orchestration config · gate declaration · autonomy declaration · vehicles declaration · enforcement scripts · spec layer · navigator index — in a fixed order, and prints **one outcome line per ensure**: paste those lines into the step 4 / step 8 success report. Every SEED is **create-only** (an existing file is preserved byte-for-byte); the three refresh-class ops are named apart — the orchestration onboarding note (refreshed only while it still matches a canonical this kit shipped), the spec-layer reader and checker pairs (below) and the **navigator index**, a GENERATED artifact regenerated whenever it is missing or stale (never authored content, so there is nothing to preserve). One ensure failing **never** skips the others: each reports its own outcome and the run exits non-zero when any of them `failed`. The outcome tokens, by ensure: orchestration → `seeded` / `note-refreshed` / `already-current` / `customized-preserved` / `malformed-preserved`; gates, autonomy and vehicles → `seeded` / `already-present`; scripts → `seeded` / `already-present` / `old-adr-layout-migration-instructed` / `skipped-no-node-evidence`; specs → `seeded` / `refreshed` / `already-present` / `customized-preserved` / `skipped-no-node-evidence`; index → `regenerated` / `already-current`; and any ensure may report `failed`, whose line OPENS with the cause (relay it with that cause — never soften it into a skip; an op that copies file by file also states when it stopped partway). The cause vocabulary is CLOSED — one of `race-unresolved`, `template-unreadable`, `bundle-unreadable`, `adr-layout-unverifiable`, `node-evidence-unverifiable`, `wrong-node-kind`, `write-refused`, `unexpected-error`, `generator-unlaunchable`, `generator-failed`, `index-probe-failed`, `index-stale-after-write` — and every cause that can only arise AFTER the generator ran (`generator-failed`, and `index-probe-failed` / `index-stale-after-write` when they follow a reported regeneration) DISCLOSES in its own line that a write may already have landed. **A non-zero exit STOPs this upgrade** — report the failed line and stop there, before the equal-head exit, the migrations and the re-stamp. Add `--dry-run` to preview without writing a byte. Like the pointer slots + the footprint reconcile, all seven reach an equal-head deployment **without a lineage-head bump or a migration file** (they are `.json` / `scripts/` / a generated artifact / a seeded store root, inherently outside the docs cap-validator).
|
|
35
35
|
|
|
36
36
|
**What the orchestration-config ensure does.** `docs/ai/orchestration.json` must exist **and its onboarding note must be current**: created from the canonical seed if missing; if it already exists, **every activity/slot the user set is preserved** and ONLY the `_README` note is refreshed, and only when the existing one still matches a known prior canonical — the tested `refreshIfCanonical` / `refreshReadme` in `tools/orchestration-config.mjs` is the source of truth for that decision (it normalizes CRLF/whitespace before comparing; a *customized* `_README` is preserved verbatim → `customized-preserved`; a *malformed* existing config is **preserved untouched + LOUD** → `malformed-preserved`, never clobbered and never silently skipped). The current note points at `/agent-workflow-kit set-recipe`. **Kit-owned:** in the **delegated** path memory only seeds/preserves the file (memory upgrade step 2) and this ensure applies the `_README` refresh; in the **fallback** path it does both. (Memory stays standalone.)
|
|
37
37
|
|
|
@@ -39,7 +39,7 @@ Requires: ${CLAUDE_SKILL_DIR}/references/shared/report-footer.md · ${CLAUDE_SKI
|
|
|
39
39
|
|
|
40
40
|
**What the autonomy-declaration ensure does.** `docs/ai/autonomy.json` must exist: created from `${CLAUDE_SKILL_DIR}/references/templates/autonomy.json` if missing (the kit's own template twin — a stale memory never silently loses the seed); **an existing file is preserved byte-for-byte** (a declared policy is authored content). The seed is SPARSE (the onboarding note only) and **defaults-equivalent** — deploying it never changes behavior (the computed defaults stay the policy until the user declares levels with `/agent-workflow-kit set-autonomy` or by hand).
|
|
41
41
|
|
|
42
|
-
**What the enforcement-script ensure does.** A deployment older than the ADR-cascade feature has no `scripts/archive-decisions.mjs`, and an equal-head exit would otherwise never deliver it. The pairs must exist in the project's `scripts/`: `archive-decisions.mjs` + `archive-decisions.test.mjs` and `markdown-blocks.mjs` + `markdown-blocks.test.mjs`, copied from `${CLAUDE_SKILL_DIR}/references/scripts/` if missing; **an existing file is preserved, never overwritten** (drift repair belongs to a lineage migration). Nothing else is seeded — the other tokenizer-era tests red beside OLD archivers. **OLD ADR-store layout — DETECTED FIRST, never auto-migrated (AD-051, Decision 13):** on a `docs/ai/history/decisions-archive*.md` monolith (`old`), or no monolith but a deployed rotator predating the store (`old-unrotated`), the project is on the RETIRED 3-tier cascade, so the ensure writes NOTHING and reports `old-adr-layout-migration-instructed` (the new `archive-decisions.mjs` beside un-migrated monoliths would red their ADR gate). Relay it as the LOUD instruct it is: the fix is the opt-in **`/agent-workflow-kit migrate-adr-store`** (consent-gated; previews first, never commits), and the seed lands on the next upgrade. A layout the ensure cannot READ is `failed`, not a seed — it never writes on an unverifiable tree. The seed applies ONLY to a clean layout (neither signal). **Whether Node runs here is PROVEN, never proxied:** the ensure seeds on a regular `package.json` at the root OR on any kit-seeded `scripts/*.mjs` already deployed (a bootstrap places them into projects that never carry a `package.json`); only when every probe answers absent does it report `skipped-no-node-evidence`, a line naming every probe it checked, while the
|
|
42
|
+
**What the enforcement-script ensure does.** A deployment older than the ADR-cascade feature has no `scripts/archive-decisions.mjs`, and an equal-head exit would otherwise never deliver it. The pairs must exist in the project's `scripts/`: `archive-decisions.mjs` + `archive-decisions.test.mjs` and `markdown-blocks.mjs` + `markdown-blocks.test.mjs`, copied from `${CLAUDE_SKILL_DIR}/references/scripts/` if missing; **an existing file is preserved, never overwritten** (drift repair belongs to a lineage migration). Nothing else is seeded — the other tokenizer-era tests red beside OLD archivers. **OLD ADR-store layout — DETECTED FIRST, never auto-migrated (AD-051, Decision 13):** on a `docs/ai/history/decisions-archive*.md` monolith (`old`), or no monolith but a deployed rotator predating the store (`old-unrotated`), the project is on the RETIRED 3-tier cascade, so the ensure writes NOTHING and reports `old-adr-layout-migration-instructed` (the new `archive-decisions.mjs` beside un-migrated monoliths would red their ADR gate). Relay it as the LOUD instruct it is: the fix is the opt-in **`/agent-workflow-kit migrate-adr-store`** (consent-gated; previews first, never commits), and the seed lands on the next upgrade. A layout the ensure cannot READ is `failed`, not a seed — it never writes on an unverifiable tree. The seed applies ONLY to a clean layout (neither signal). **Whether Node runs here is PROVEN, never proxied:** the ensure seeds on a regular `package.json` at the root OR on any kit-seeded `scripts/*.mjs` already deployed (a bootstrap places them into projects that never carry a `package.json`); only when every probe answers absent does it report `skipped-no-node-evidence`, a line naming every probe it checked, while the config ensures still run; a probe that cannot be read is `failed` with the cause `node-evidence-unverifiable`, nothing written. **A `skipped-*` outcome whose stated reason this tool could itself disprove may not exist** — the retired `skipped-no-node` was exactly that, printed beside twenty deployed Node scripts. The deployed pre-commit hook gains the `archive-decisions.mjs --check` line only when the hook itself is next refreshed (re-run `node scripts/install-git-hooks.mjs` after the ensure and it will refuse a non-marker hook as always); an OLD hook without the line stays consistent-safe — the decisions gate is simply not enforced yet, never a broken hook.
|
|
43
43
|
|
|
44
44
|
**What the navigator ensure does.** `docs/ai/index.md` is the always-loaded navigator the entry point declares, and it is GENERATED — no template ships it, so a deployment that never ran the generator boots from a broken entry point (and, on a Node project, carries a pre-commit hook that fails its own index check). The ensure runs the bundled generator's finalizer and reports `regenerated` (it was missing or stale — it was written) or `already-current` (nothing written). It never skips a No-Node project: the generator runs from `${CLAUDE_SKILL_DIR}/references/scripts/` on the agent host, not from the project's `scripts/`. **Its position in the run-list is EARLY and therefore NOT authoritative** — `lens` (and, on the migrated path, steps 6–7) still change `docs/ai` afterwards — so the authoritative run is the LATE `--only index` rung documented at both exits; the early one is idempotent and costs at most an `already-current` line.
|
|
45
45
|
|
|
@@ -90,7 +90,7 @@ Requires: ${CLAUDE_SKILL_DIR}/references/shared/report-footer.md · ${CLAUDE_SKI
|
|
|
90
90
|
**The LATE navigator finalizer — the AUTHORITATIVE run, after the last `docs/ai` mutation.** `lens` above rewrites `docs/ai/agent_rules.md`, so the step-3 index ensure is already behind by the time the run-list ends. Re-run that ONE op here, before the step-4 report: `node ${CLAUDE_SKILL_DIR}/tools/ensure-configs.mjs --reconcile --only index --cwd <project>`. Relay **this** line in the report (it supersedes the early one; an untouched tree reports `already-current`, a failure STOPs the upgrade like any other ensure). On the migrated path the same rung runs again at the END of step 7 — after the migrations, before the step-8 re-stamp.
|
|
91
91
|
4. **Equal-head exit — a real successful-exit report, not a bare stop.** If the stamp **equals** the head, the lineage is up to date — but step 3 (the stamp-independent reconciles) ran first and may have changed things, so this is a proper exit report, not a no-op:
|
|
92
92
|
- **A skip line that contradicts the observed tree is a FINDING, never pasted as neutral.** Every ensure skip names the fact it proved (the probes that answered absent, the layout it read); if the tree you can see disproves that reason — a "no Node" skip beside deployed Node scripts, a "not deployed" skip beside a stamped `docs/ai` — do not relay the line as an outcome: raise it in the report as a defect of the tool, with the contradicting fact named, and stop short of any step that would build on the skip.
|
|
93
|
-
- **Report step 3's outcome in plain language** — for **each** `pointers` slot (workflow-methodology, orchestration-recipes and autonomy-policy) whether it was *added*, was *already present* (nothing changed), or was *skipped* (the soft-skip from step 3, with its reason — over the line limit / engine too old / the autonomy pointer's anchor absent); the **
|
|
93
|
+
- **Report step 3's outcome in plain language** — for **each** `pointers` slot (workflow-methodology, orchestration-recipes and autonomy-policy) whether it was *added*, was *already present* (nothing changed), or was *skipped* (the soft-skip from step 3, with its reason — over the line limit / engine too old / the autonomy pointer's anchor absent); the **seven project-configuration ensure** (`configs`) lines exactly as the one ensure run composed them (orchestration config, gate declaration, autonomy declaration, vehicles declaration, enforcement scripts, spec layer, navigator index — their outcome tokens are enumerated in step 3), each rendered in plain language: what was created, what was left exactly as the user wrote it, and — for a `failed` line — what stopped it; for the navigator, relay the **late** `--only index` line, not the early one; the **`gates-migration`** result — *nothing to migrate*, the shown plan *applied* on your explicit yes, or the plan *left unapplied* (consent not given), with any INERT checker or CUSTOMIZED entries named; the **placed-bridge refresh** (`bridges`) outcome — paste the tool's per-bridge lines verbatim (they are already plain: *refreshed* / *already current* / *skipped — not placed* / `skipped-readonly` with its re-scan verdict / *could not refresh* + recovery); the **agent-rules lens** (`lens`) outcome (*refreshed* / *already current* / *custom edit preserved + note* / *file absent* / *engine too old* / *over the line cap*) and the **Communication-section** outcome (its own set: refreshed / already current / custom preserved + note / section absent — noted / over the cap — refused); the **bridge-settings reconcile** (`bridge-settings`) outcome (paste the tool's line(s) verbatim); and, for a hidden deployment, whether the hidden-mode footprint (`footprint`) was *moved to project-local*, was *already project-local* (nothing changed), or needed a question (ambiguous visibility / a leftover machine-wide block). Plain wording only — never the reconcile/slot/anchor/marker terms (the never-leak-kit-internals Gotcha — `${CLAUDE_SKILL_DIR}/references/shared/deploy-tail.md`).
|
|
94
94
|
- **Never surface the structure number on this exit.** Whatever step 3 did, do **not** recite the `docs/ai` structure version, the internal versioning vocabulary, or the two-axes note here — the number is inert on an equal-head exit; it belongs to *Version disclosure* in `${CLAUDE_SKILL_DIR}/references/shared/report-footer.md` (shown at the never-downgrade STOP, the explicit status view, or on an explicit ask). Frame the success itself per the final bullet: if step 3 changed anything, say **what changed** in plain human terms; only a pure zero-diff no-op is *settings already current — no update needed*.
|
|
95
95
|
- **Render the mandatory Recommendations section — on this exit too, BEFORE the footer.** Run `node ${CLAUDE_SKILL_DIR}/tools/recommendations.mjs --cwd <project-root>` and PRESENT its output — from the `## Recommendations (agent-workflow)` header — in the user's conversational language: every fact, count and item from the tool, nothing added or dropped; commands, paths, hosts and rule strings byte-exact; show the raw tool block on request. The section is present-even-when-empty (with everything optimal the body is exactly `no recommendations — flow optimal.`) and VERDICT-FIRST — the composed verdict line renders from the frozen templates `{K} item(s) need attention` / `nothing is broken` / `{N} optional recommendation(s), apply any you want` / `optimality NOT attested — {M} probe check(s) skipped`. Then OFFER the consent-gated applies: the user picks items in plain language; surface each picked item's posture note, get the explicit confirm, then run EXACTLY the rendered one-liners (a HAND-APPLY item is never run by you) — the full lane in `${CLAUDE_SKILL_DIR}/references/modes/recommendations.md`. Pinned order on this exit: Recommendations block → optional applies → report footer → the commit ask (the advisor/apply lane never lands after the commit ask).
|
|
96
96
|
- **Live host/session facts are tool-composed only.** Any claim this report makes about the current host or session state — prompts fired, sandbox scope, whether a bypass was needed, network reachability, approval counts — must trace to **live tool output** from **this session** (the lines you just composed, or a probe you ran this run); a memory/handover snapshot is **context, never report facts**, and a claim with no live signal is **omitted or explicitly marked unverified** — never asserted from recollection. Full clause: *Live host/session facts* in `${CLAUDE_SKILL_DIR}/references/shared/report-footer.md`.
|
|
@@ -99,4 +99,4 @@ Requires: ${CLAUDE_SKILL_DIR}/references/shared/report-footer.md · ${CLAUDE_SKI
|
|
|
99
99
|
5. Show the relevant `${CLAUDE_SKILL_DIR}/CHANGELOG.md` diff (entries newer than the project's stamp).
|
|
100
100
|
6. **Collect the migration answers FIRST, then apply.** If `AGENTS.md` is missing BOTH the *Communication language* and *Attribution* blocks — i.e. both blocks are missing (a pre-1.1.0 deployment) — ask the two questions as ONE structured multi-question prompt; record each answer individually, write nothing until ALL are answered, and carry the answers into the migrations below: a migration whose answer was already collected never re-asks (its own "Ask the user" step is the standalone fallback); a single missing block keeps its single ask (step 7). Then apply `${CLAUDE_SKILL_DIR}/migrations/<version>-<slug>.md` in **semver order**, only those newer than the project's stamp. Migrations are **idempotent** — safe to re-run.
|
|
101
101
|
7. Reconcile drift: add any kernel files/scripts the project is missing; never clobber project-authored content (their `decisions.md`, `known_issues.md`, page specs stay). Any user question a migration raises follows the same rule as bootstrap — **structured multiple-choice where supported** (`AskUserQuestion` in Claude Code), otherwise prose. If `AGENTS.md` has no *Communication language* block (pre-1.1.0 deployment), **ask the user their conversational language** and insert the block — see `migrations/1.1.0-communication-language.md`. If it has no *Attribution* block (pre-1.2.0 deployment), **ask whether the agent may attribute work to itself / AI** and insert the block (defaulting to `off`) — see `migrations/1.2.0-agent-attribution.md`. (An answer already collected by the step-6 batched prompt is carried in — never re-asked here.) **Then, before the stamp, re-run the LATE navigator finalizer:** the migrations of steps 6–7 may have added or changed `docs/ai` files, so run the one op again — `node ${CLAUDE_SKILL_DIR}/tools/ensure-configs.mjs --reconcile --only index --cwd <project>` — and relay THAT line in the step-8 report (idempotent: an untouched tree reports `already-current`; a failure STOPs this upgrade like any other ensure).
|
|
102
|
-
8. Re-stamp `docs/ai/.workflow-version` to the **deployment-lineage head** (`3.0.0`, not the package version — mechanics unchanged: the atomic write to the stamp file). In the report, **describe what the upgrade changed in plain human terms** — which parts of their `docs/ai` are now different (the migrations that ran), plus the step-3 run-list outcomes, each as step 4 words it: the `pointers` slots, the `footprint` visibility verdict (and what a consented re-run migrated), the **
|
|
102
|
+
8. Re-stamp `docs/ai/.workflow-version` to the **deployment-lineage head** (`3.0.0`, not the package version — mechanics unchanged: the atomic write to the stamp file). In the report, **describe what the upgrade changed in plain human terms** — which parts of their `docs/ai` are now different (the migrations that ran), plus the step-3 run-list outcomes, each as step 4 words it: the `pointers` slots, the `footprint` visibility verdict (and what a consented re-run migrated), the **seven project-configuration ensure** (`configs`) lines (orchestration config, gate declaration, autonomy declaration, vehicles declaration, enforcement scripts, spec layer, navigator index) — the navigator one being the late `--only index` run at the end of step 7, the **`gates-migration`** result, the **placed-bridge refresh** (`bridges`) lines (pasted verbatim), the **agent-rules lens** (`lens`) + **Communication-section** outcomes (same outcome sets as step 4), and the **bridge-settings reconcile** (`bridge-settings`) outcome (line(s) pasted verbatim) — rather than reciting a version number; **omit the raw structure number**, and do **not** print the two-axes note here (it belongs to *Version disclosure* in `${CLAUDE_SKILL_DIR}/references/shared/report-footer.md`, on demand only). Then **render the mandatory Recommendations section**: run `node ${CLAUDE_SKILL_DIR}/tools/recommendations.mjs --cwd <project-root>` and PRESENT its output — from the `## Recommendations (agent-workflow)` header — in the user's conversational language (every fact, count and item, nothing added or dropped; commands, paths, hosts and rule strings byte-exact; raw tool block on request; present-even-when-empty: `no recommendations — flow optimal.`), then OFFER the consent-gated applies (per picked item: posture note → explicit confirm → run EXACTLY the rendered one-liner; a HAND-APPLY item is never run by you — `${CLAUDE_SKILL_DIR}/references/modes/recommendations.md`). **Every current host/session claim in this report is tool-composed only** — prompts fired, sandbox scope, whether a bypass was needed, network reachability and approval counts must trace to **live tool output** from **this session**, a memory/handover snapshot is **context, never report facts**, and an unbacked claim is **omitted or explicitly marked unverified** (full clause: *Live host/session facts* in `${CLAUDE_SKILL_DIR}/references/shared/report-footer.md`). Then **print the report footer** in the canonical order (version block → one-line backend-status line → welcome mat — the shared contracts in `${CLAUDE_SKILL_DIR}/references/shared/report-footer.md`; rendered from the helpers, same host-can't-run skip-with-reason; the welcome mat closes on one caveat-aware next step). Then **ask before committing** — the pinned order on this exit is: Recommendations block → optional applies → report footer → the commit ask.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_README": "The executor vehicle's model, effort and fallback as a project setting, read by the kit's vehicle-settings readers into one posture, which the placed executor's body follows only from the release that derives it; seeded once and never clobbered, hand-edited as three bare tokens with fallback differing from model.",
|
|
3
|
+
"executor": {
|
|
4
|
+
"model": "opus",
|
|
5
|
+
"effort": "high",
|
|
6
|
+
"fallback": "sonnet"
|
|
7
|
+
}
|
|
8
|
+
}
|
package/tools/ensure-configs.mjs
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// ensure-configs.mjs — ONE runnable command for the
|
|
2
|
+
// ensure-configs.mjs — ONE runnable command for the seven stamp-independent upgrade ensures:
|
|
3
3
|
//
|
|
4
4
|
// orchestration docs/ai/orchestration.json seed, or refresh a still-canonical onboarding note
|
|
5
5
|
// gates docs/ai/gates.json seed-if-missing (an existing declaration is authored content)
|
|
6
6
|
// autonomy docs/ai/autonomy.json seed-if-missing (same)
|
|
7
|
+
// vehicles docs/ai/vehicles.json seed-if-missing (same)
|
|
7
8
|
// scripts scripts/<ADR enforcement> seed-if-missing, ADR-layout detect FIRST
|
|
8
9
|
// specs scripts/<spec layer> reader + checker pairs seeded when absent, refreshed only on
|
|
9
10
|
// + docs/ai/specs/index.md a shipped prior body, store root seeded behind a current checker
|
|
10
11
|
// index docs/ai/index.md regenerate-if-missing-or-stale (a GENERATED artifact)
|
|
11
12
|
//
|
|
12
13
|
// Each was prose in references/modes/upgrade.md that an agent performed by hand. One command instead
|
|
13
|
-
// of
|
|
14
|
-
// has a single invocation point whose
|
|
14
|
+
// of seven is deliberate: seven independent runs would be seven chances to skip one, and the mode doc now
|
|
15
|
+
// has a single invocation point whose seven outcome lines it relays.
|
|
15
16
|
//
|
|
16
17
|
// The contract (pinned by this module's tests):
|
|
17
18
|
// • --reconcile is REQUIRED. A bare run is a usage error, so nothing writes by accident.
|
|
@@ -19,7 +20,7 @@
|
|
|
19
20
|
// • The ops run in a FIXED order and one op's failure NEVER skips the rest: every op reports its own
|
|
20
21
|
// token, and the exit is non-zero when any of them failed.
|
|
21
22
|
// • The deployment gate runs ONCE, before any op: an absent/symlinked docs/ai stops the whole run
|
|
22
|
-
// with the gate's own message rather than
|
|
23
|
+
// with the gate's own message rather than seven copies of it.
|
|
23
24
|
//
|
|
24
25
|
// Output is ENGLISH/structured (repo-artifact Hard Constraint); the agent localizes when narrating.
|
|
25
26
|
// Exit codes: 0 every op fine · 1 an op failed, or the deployment gate stopped the run · 2 usage.
|
|
@@ -51,12 +52,12 @@ const EMPTY_ONLY = `--only needs one operation name (${ENSURE_OPS.join(' | ')})
|
|
|
51
52
|
const REPEATED_ONLY = '--only was passed more than once — this selector names exactly ONE operation';
|
|
52
53
|
const unknownOp = (value) => `--only ${value}: no such operation (${ENSURE_OPS.join(' | ')}) — nothing was run`;
|
|
53
54
|
|
|
54
|
-
const HELP = `ensure-configs — the
|
|
55
|
+
const HELP = `ensure-configs — the seven stamp-independent upgrade ensures, as ONE command.
|
|
55
56
|
|
|
56
57
|
Usage:
|
|
57
58
|
node ensure-configs.mjs --reconcile [--dry-run] [--only <op>] [--cwd <project>]
|
|
58
59
|
|
|
59
|
-
--reconcile required — run the
|
|
60
|
+
--reconcile required — run the seven ensures (${ENSURE_OPS.join(', ')})
|
|
60
61
|
--dry-run report what each ensure WOULD do; write nothing
|
|
61
62
|
--only <op> run EXACTLY ONE of them (an unknown, missing or repeated value is a usage error)
|
|
62
63
|
--cwd <dir> the target project (default: the current directory)
|
|
@@ -148,7 +149,7 @@ export const main = (argv = [], ctx = {}) => {
|
|
|
148
149
|
const cwd = resolve(args.cwd ?? ctx.cwd ?? process.cwd());
|
|
149
150
|
const deps = ctx.deps ?? {};
|
|
150
151
|
// ONE deployment gate for the whole run (see the header): with no docs/ai there is nothing to
|
|
151
|
-
// reconcile, and
|
|
152
|
+
// reconcile, and seven identical STOPs would read as seven separate problems.
|
|
152
153
|
assertDocsAiDeployment(cwd, deps, { noun: 'the project configuration', rel: 'under docs/ai' });
|
|
153
154
|
const outcomes = runEnsures({ cwd, kitRoot: ctx.kitRoot ?? KIT_ROOT, dryRun: args.dryRun, deps, only: args.only });
|
|
154
155
|
return {
|
package/tools/ensure-ops.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// ensure-ops.mjs —
|
|
2
|
-
// outcome shape; the
|
|
1
|
+
// ensure-ops.mjs — the upgrade ensure operations this module owns, one function each, behind one shared
|
|
2
|
+
// outcome shape; the spec-layer ensure (ensure-specs.mjs) composes its outcomes through
|
|
3
3
|
// the same door and probes exported below. The CLI that orders and runs them is ensure-configs.mjs —
|
|
4
4
|
// it owns the op table, so the import graph stays acyclic; this module owns what each ensure DOES
|
|
5
5
|
// and, more importantly, what it is allowed to CLAIM.
|
|
@@ -32,6 +32,7 @@ import { seedConfig, writeConfig } from './orchestration-write.mjs';
|
|
|
32
32
|
import { lstatNoFollow, writeDocsAiFileAtomic, writeProjectFileCreateOnly } from './atomic-write.mjs';
|
|
33
33
|
import { GATES_REL } from './gates-declaration.mjs';
|
|
34
34
|
import { AUTONOMY_REL } from './autonomy-config.mjs';
|
|
35
|
+
import { VEHICLES_REL } from './vehicle-settings.mjs';
|
|
35
36
|
import { surveyAdrLayoutStrict } from './family-registry.mjs';
|
|
36
37
|
import { ENSURE_TOKENS, FAILURE_CAUSES, SEED_SCRIPTS } from './ensure-vocabulary.mjs';
|
|
37
38
|
import { NODE_EVIDENCE, describeNodeProbes, probeNodeEvidence } from './node-evidence.mjs';
|
|
@@ -51,6 +52,9 @@ export {
|
|
|
51
52
|
} from './ensure-vocabulary.mjs';
|
|
52
53
|
|
|
53
54
|
const SCRIPTS_DIR = 'scripts';
|
|
55
|
+
const VEHICLES_OP = 'vehicles';
|
|
56
|
+
const VEHICLES_TEMPLATE = 'vehicles.json';
|
|
57
|
+
const VEHICLES_NOUN = 'a vehicle settings declaration';
|
|
54
58
|
|
|
55
59
|
const outcome = (op, token, lines, failed = false) => {
|
|
56
60
|
if (!ENSURE_TOKENS.includes(token)) {
|
|
@@ -98,7 +102,7 @@ export const probeSeedTarget = (abs, lstat) => {
|
|
|
98
102
|
export const tmpNote = (rel, tmpLeftBehind) =>
|
|
99
103
|
(tmpLeftBehind ? [`${rel}: the write stands, but its temp file could not be removed — delete it by hand: ${tmpLeftBehind}`] : []);
|
|
100
104
|
|
|
101
|
-
// ──
|
|
105
|
+
// ── orchestration.json — seed, or refresh ONLY a still-canonical onboarding note ────────────────
|
|
102
106
|
|
|
103
107
|
// Which no-change outcome is it? refreshReadme returns `changed: false` for two very different trees:
|
|
104
108
|
// a note that already IS the current canonical, and a note the user rewrote. Reporting both as
|
|
@@ -173,7 +177,7 @@ export const ensureOrchestration = ({ cwd, dryRun = false, deps = {} }) => {
|
|
|
173
177
|
return { ...refreshed, lines: [...refreshed.lines, ...seedNote] };
|
|
174
178
|
};
|
|
175
179
|
|
|
176
|
-
// ──
|
|
180
|
+
// ── gates.json + autonomy.json + vehicles.json — seed-if-missing, existing file preserved byte-for-byte ───────
|
|
177
181
|
|
|
178
182
|
const seedFromTemplate = ({ op, rel, template, noun, cwd, kitRoot, dryRun, deps }) => {
|
|
179
183
|
const lstat = deps.lstat ?? lstatSync;
|
|
@@ -202,7 +206,10 @@ export const ensureGates = ({ cwd, kitRoot, dryRun = false, deps = {} }) =>
|
|
|
202
206
|
export const ensureAutonomy = ({ cwd, kitRoot, dryRun = false, deps = {} }) =>
|
|
203
207
|
seedFromTemplate({ op: 'autonomy', rel: AUTONOMY_REL, template: 'autonomy.json', noun: 'an autonomy policy', cwd, kitRoot, dryRun, deps });
|
|
204
208
|
|
|
205
|
-
|
|
209
|
+
export const ensureVehicles = ({ cwd, kitRoot, dryRun = false, deps = {} }) =>
|
|
210
|
+
seedFromTemplate({ op: VEHICLES_OP, rel: VEHICLES_REL, template: VEHICLES_TEMPLATE, noun: VEHICLES_NOUN, cwd, kitRoot, dryRun, deps });
|
|
211
|
+
|
|
212
|
+
// ── scripts/ — the ADR-cascade enforcement pairs, detect-first ──────────────────────────────────
|
|
206
213
|
|
|
207
214
|
// The Node-evidence refusal every ensure that places Node scripts shares (contract: kit/node-evidence):
|
|
208
215
|
// null when Node provably runs here, else the ONE outcome the caller returns — a stated skip naming the
|
|
@@ -288,7 +295,7 @@ export const ensureScripts = ({ cwd, kitRoot, dryRun = false, deps = {} }) => {
|
|
|
288
295
|
return outcome('scripts', anyCreated ? 'seeded' : 'already-present', lines, false);
|
|
289
296
|
};
|
|
290
297
|
|
|
291
|
-
// ──
|
|
298
|
+
// ── docs/ai/index.md — the GENERATED navigator, regenerated when missing or stale ───────────────
|
|
292
299
|
|
|
293
300
|
// The only ensure whose target is generated rather than authored: there is nothing to preserve, and
|
|
294
301
|
// nothing to seed from either — the bundled generator IS the writer, driven through its idempotent
|
|
@@ -363,12 +370,13 @@ export const ensureIndex = ({ cwd, kitRoot, dryRun = false, deps = {} }) => {
|
|
|
363
370
|
return loud('index', 'index-probe-failed', `${INDEX_REL}: the generator reported a regeneration, but the verifying probe answered neither fresh nor stale — ${MAY_HAVE_WRITTEN}. ${verify.error ? causeOf(verify.error) : verdict}`);
|
|
364
371
|
};
|
|
365
372
|
|
|
366
|
-
// The
|
|
373
|
+
// The ops this module owns, by name. The CLI composes the full ENSURE_OPS table from these plus
|
|
367
374
|
// the spec-layer ensure (ensure-specs.mjs imports THIS module, so the table cannot live here).
|
|
368
375
|
export const OWN_IMPLEMENTATIONS = Object.freeze({
|
|
369
376
|
orchestration: ensureOrchestration,
|
|
370
377
|
gates: ensureGates,
|
|
371
378
|
autonomy: ensureAutonomy,
|
|
379
|
+
vehicles: ensureVehicles,
|
|
372
380
|
scripts: ensureScripts,
|
|
373
381
|
index: ensureIndex,
|
|
374
382
|
});
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// The FIXED order the CLI runs them in — the order references/modes/upgrade.md already prescribed.
|
|
11
11
|
// `specs` sits after `scripts` (its reader pair is a scripts/ seed too) and BEFORE `index`: the store
|
|
12
12
|
// root it seeds is a docs/ai file the navigator must count.
|
|
13
|
-
export const ENSURE_OPS = Object.freeze(['orchestration', 'gates', 'autonomy', 'scripts', 'specs', 'index']);
|
|
13
|
+
export const ENSURE_OPS = Object.freeze(['orchestration', 'gates', 'autonomy', 'vehicles', 'scripts', 'specs', 'index']);
|
|
14
14
|
|
|
15
15
|
// Tokens that assert a WRITE happened. --dry-run may never emit one of these (the CLI's contract test
|
|
16
16
|
// walks this set), and each has exactly one `would-` counterpart below. `refreshed` is the spec-layer
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { readFileSync, lstatSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
export const VEHICLES_REL = 'docs/ai/vehicles.json';
|
|
5
|
+
export const EXECUTOR_DEFAULTS = Object.freeze({ model: 'opus', effort: 'high', fallback: 'sonnet' });
|
|
6
|
+
|
|
7
|
+
const README_KEY = '_README';
|
|
8
|
+
const EXECUTOR_KEY = 'executor';
|
|
9
|
+
const TOP_LEVEL_KEYS = Object.freeze([README_KEY, EXECUTOR_KEY]);
|
|
10
|
+
const EXECUTOR_KEYS = Object.freeze(Object.keys(EXECUTOR_DEFAULTS));
|
|
11
|
+
const OBJECT_TYPE = 'object';
|
|
12
|
+
const STRING_TYPE = 'string';
|
|
13
|
+
const EMPTY_STRING = '';
|
|
14
|
+
const TOKEN_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
15
|
+
const ABSENT = 'absent';
|
|
16
|
+
const PRESENT = 'present';
|
|
17
|
+
const UNREADABLE = 'unreadable';
|
|
18
|
+
const FILE_SOURCE = 'file';
|
|
19
|
+
const DEFAULT_SOURCE = 'default';
|
|
20
|
+
const MISSING_ENTRY_CODE = 'ENOENT';
|
|
21
|
+
const ENCODING = 'utf8';
|
|
22
|
+
const CONFIG_EXIT_CODE = 1;
|
|
23
|
+
const BODY_NAME = 'body';
|
|
24
|
+
const UNKNOWN_KEY = 'unknown key';
|
|
25
|
+
const REQUIRED_KEY = 'required key is missing';
|
|
26
|
+
const OBJECT_REQUIRED = 'must be a plain object';
|
|
27
|
+
const STRING_REQUIRED = 'must be a string';
|
|
28
|
+
const NONEMPTY_REQUIRED = 'must not be empty';
|
|
29
|
+
const TOKEN_REQUIRED = 'must be a bare token';
|
|
30
|
+
const DISTINCT_FALLBACK_REQUIRED = 'fallback must differ from model';
|
|
31
|
+
const DIRECTORY_KIND = 'directory';
|
|
32
|
+
const SYMLINK_KIND = 'symlink';
|
|
33
|
+
const OTHER_KIND = 'not a regular file';
|
|
34
|
+
const UNKNOWN_STATE = 'unknown state';
|
|
35
|
+
|
|
36
|
+
const fail = (exitCode, message) => Object.assign(new Error(message), { exitCode });
|
|
37
|
+
const isPlainObject = (value) => {
|
|
38
|
+
if (value === null || typeof value !== OBJECT_TYPE || Array.isArray(value)) return false;
|
|
39
|
+
const prototype = Object.getPrototypeOf(value);
|
|
40
|
+
return prototype === Object.prototype || prototype === null;
|
|
41
|
+
};
|
|
42
|
+
const refuseValue = (rel, key, problem) => ({ ok: false, reason: `${rel}: ${key} ${problem}` });
|
|
43
|
+
const unreadable = (reason) => ({ state: UNREADABLE, reason });
|
|
44
|
+
const describeError = (error) => String(error?.code ?? error?.message ?? error);
|
|
45
|
+
const formatReadError = (error) => `${VEHICLES_REL}: ${UNREADABLE} (${describeError(error)})`;
|
|
46
|
+
|
|
47
|
+
export const validateVehicles = (value, rel = VEHICLES_REL) => {
|
|
48
|
+
if (!isPlainObject(value)) return refuseValue(rel, BODY_NAME, OBJECT_REQUIRED);
|
|
49
|
+
for (const key of Object.keys(value)) {
|
|
50
|
+
if (!TOP_LEVEL_KEYS.includes(key)) return refuseValue(rel, key, UNKNOWN_KEY);
|
|
51
|
+
}
|
|
52
|
+
if (Object.hasOwn(value, README_KEY) && typeof value[README_KEY] !== STRING_TYPE) {
|
|
53
|
+
return refuseValue(rel, README_KEY, STRING_REQUIRED);
|
|
54
|
+
}
|
|
55
|
+
if (!Object.hasOwn(value, EXECUTOR_KEY)) return refuseValue(rel, EXECUTOR_KEY, REQUIRED_KEY);
|
|
56
|
+
const executor = value[EXECUTOR_KEY];
|
|
57
|
+
if (!isPlainObject(executor)) return refuseValue(rel, EXECUTOR_KEY, OBJECT_REQUIRED);
|
|
58
|
+
for (const key of Object.keys(executor)) {
|
|
59
|
+
if (!EXECUTOR_KEYS.includes(key)) return refuseValue(rel, `${EXECUTOR_KEY}.${key}`, UNKNOWN_KEY);
|
|
60
|
+
}
|
|
61
|
+
for (const key of EXECUTOR_KEYS) {
|
|
62
|
+
const qualifiedKey = `${EXECUTOR_KEY}.${key}`;
|
|
63
|
+
if (!Object.hasOwn(executor, key)) return refuseValue(rel, qualifiedKey, REQUIRED_KEY);
|
|
64
|
+
const token = executor[key];
|
|
65
|
+
if (typeof token !== STRING_TYPE) return refuseValue(rel, qualifiedKey, STRING_REQUIRED);
|
|
66
|
+
if (token === EMPTY_STRING) return refuseValue(rel, qualifiedKey, NONEMPTY_REQUIRED);
|
|
67
|
+
if (!TOKEN_PATTERN.test(token) || token.trim() !== token) {
|
|
68
|
+
return refuseValue(rel, qualifiedKey, TOKEN_REQUIRED);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (executor.fallback === executor.model) {
|
|
72
|
+
return refuseValue(rel, EXECUTOR_KEY, DISTINCT_FALLBACK_REQUIRED);
|
|
73
|
+
}
|
|
74
|
+
const { model, effort, fallback } = executor;
|
|
75
|
+
return { ok: true, settings: { executor: { model, effort, fallback } } };
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const probeEntry = (path, lstat) => {
|
|
79
|
+
try {
|
|
80
|
+
return { entry: lstat(path) };
|
|
81
|
+
} catch (error) {
|
|
82
|
+
return error?.code === MISSING_ENTRY_CODE
|
|
83
|
+
? { state: ABSENT }
|
|
84
|
+
: unreadable(formatReadError(error));
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const describeNodeKind = (entry) => {
|
|
88
|
+
if (entry.isSymbolicLink()) return SYMLINK_KIND;
|
|
89
|
+
if (entry.isDirectory()) return DIRECTORY_KIND;
|
|
90
|
+
return OTHER_KIND;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const readVehicles = (cwd, readFile = readFileSync, lstat = lstatSync) => {
|
|
94
|
+
try {
|
|
95
|
+
const path = join(cwd, VEHICLES_REL);
|
|
96
|
+
const probe = probeEntry(path, lstat);
|
|
97
|
+
if (probe.state) return probe;
|
|
98
|
+
const { entry } = probe;
|
|
99
|
+
if (entry.isSymbolicLink() || !entry.isFile()) {
|
|
100
|
+
return unreadable(`${VEHICLES_REL}: ${describeNodeKind(entry)}`);
|
|
101
|
+
}
|
|
102
|
+
const value = JSON.parse(readFile(path, ENCODING));
|
|
103
|
+
const validation = validateVehicles(value);
|
|
104
|
+
return validation.ok
|
|
105
|
+
? { state: PRESENT, settings: validation.settings }
|
|
106
|
+
: unreadable(validation.reason);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
return unreadable(formatReadError(error));
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const loadVehicles = (cwd, readFile = readFileSync, lstat = lstatSync) => {
|
|
113
|
+
const answer = readVehicles(cwd, readFile, lstat);
|
|
114
|
+
if (answer.state === UNREADABLE) throw fail(CONFIG_EXIT_CODE, answer.reason);
|
|
115
|
+
return answer;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export const resolveExecutor = (answer) => {
|
|
119
|
+
if (answer?.state === PRESENT) {
|
|
120
|
+
return { posture: { ...answer.settings.executor, source: FILE_SOURCE }, reason: null };
|
|
121
|
+
}
|
|
122
|
+
if (answer?.state === ABSENT) {
|
|
123
|
+
return { posture: { ...EXECUTOR_DEFAULTS, source: DEFAULT_SOURCE }, reason: null };
|
|
124
|
+
}
|
|
125
|
+
if (answer?.state === UNREADABLE) return { posture: null, reason: answer.reason };
|
|
126
|
+
throw fail(CONFIG_EXIT_CODE, `${VEHICLES_REL}: ${UNKNOWN_STATE} ${String(answer?.state)}`);
|
|
127
|
+
};
|