@sabaiway/agent-workflow-kit 23.3.1 → 23.4.1
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 +33 -0
- package/README.md +1 -1
- package/SKILL.md +1 -1
- package/bridges/antigravity-cli-bridge/SKILL.md +2 -2
- package/bridges/antigravity-cli-bridge/bin/agy-review-harness.test.mjs +7 -1
- package/bridges/antigravity-cli-bridge/bin/agy-review-honesty.test.mjs +2 -1
- package/bridges/antigravity-cli-bridge/bin/agy-review-model-screen.test.mjs +2 -1
- package/bridges/antigravity-cli-bridge/bin/agy-review.sh +18 -10
- package/bridges/antigravity-cli-bridge/bin/agy-review.test.mjs +50 -50
- package/bridges/antigravity-cli-bridge/bin/agy.sh +6 -2
- package/bridges/antigravity-cli-bridge/bin/agy.test.mjs +5 -5
- package/bridges/antigravity-cli-bridge/capability.json +2 -2
- package/bridges/antigravity-cli-bridge/references/models-and-flags.md +1 -1
- package/bridges/antigravity-cli-bridge/setup/README.md +1 -1
- package/bridges/codex-cli-bridge/SKILL.md +1 -1
- package/bridges/codex-cli-bridge/bin/codex-exec-jev.test.mjs +73 -93
- package/bridges/codex-cli-bridge/bin/codex-exec.sh +7 -3
- package/bridges/codex-cli-bridge/bin/codex-exec.test.mjs +6 -10
- package/bridges/codex-cli-bridge/bin/codex-fixtures-harness.test.mjs +77 -0
- package/bridges/codex-cli-bridge/bin/codex-fixtures.test.mjs +215 -0
- package/bridges/codex-cli-bridge/bin/codex-model-posture.test.mjs +18 -18
- package/bridges/codex-cli-bridge/bin/codex-review-honesty.test.mjs +2 -1
- package/bridges/codex-cli-bridge/bin/codex-review-jev.test.mjs +13 -13
- package/bridges/codex-cli-bridge/bin/codex-review.sh +17 -10
- package/bridges/codex-cli-bridge/bin/codex-review.test.mjs +30 -29
- package/bridges/codex-cli-bridge/capability.json +1 -1
- package/bridges/typesafe-jev-bridge/SKILL.md +19 -12
- package/bridges/typesafe-jev-bridge/bin/jev-ask-harness.test.mjs +109 -0
- package/bridges/typesafe-jev-bridge/bin/jev-ask.sh +9 -4
- package/bridges/typesafe-jev-bridge/bin/jev-ask.test.mjs +108 -104
- package/bridges/typesafe-jev-bridge/bin/jev-client.mjs +27 -13
- package/bridges/typesafe-jev-bridge/capability.json +11 -1
- package/capability.json +1 -1
- package/package.json +2 -1
- package/references/modes/bridge-settings.md +6 -5
- package/references/modes/coverage-check.md +1 -1
- package/tools/apply-danger-check.mjs +2 -2
- package/tools/bridge-settings-read.mjs +8 -3
- package/tools/bridge-settings.mjs +28 -43
- package/tools/coverage-check.mjs +9 -8
- package/tools/detect-backends.mjs +1 -1
- package/tools/distribution-files/retired.mjs +7 -7
- package/tools/distribution-files/scripts.mjs +10 -11
- package/tools/ensure-ops.mjs +21 -21
- package/tools/ensure-specs.mjs +10 -9
- package/tools/family-registry.mjs +4 -4
- package/tools/git-hooks.mjs +5 -5
- package/tools/manifest/schema.md +4 -1
- package/tools/manifest/validate.mjs +10 -0
- package/tools/node-evidence.mjs +14 -12
- package/tools/recommendations.mjs +2 -2
- package/tools/review-state-build.mjs +3 -2
- package/tools/review-state.mjs +1 -1
- package/tools/write-lanes.mjs +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sabaiway/agent-workflow-kit",
|
|
3
|
-
"version": "23.
|
|
3
|
+
"version": "23.4.1",
|
|
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",
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"!tools/**/*.test.mjs",
|
|
56
56
|
"!tools/manifest/fixtures/**",
|
|
57
57
|
"!tools/project-rules/fixtures/**",
|
|
58
|
+
"!tools/checker-verdict/**",
|
|
58
59
|
"!references/scripts/**/*.test.mjs",
|
|
59
60
|
"!references/scripts/archives/index.mjs",
|
|
60
61
|
"!references/scripts/test-support/**"
|
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
<!-- opt-in-capability: codex-fast -->
|
|
4
4
|
|
|
5
|
-
The reader + consent-gated **writer** for the **host-level** bridge settings file — the answer to *"turn on the codex Fast tier (or another bridge knob) once, predictably, so it survives kit upgrades."* The four bridge wrappers read `${XDG_CONFIG_HOME:-~/.config}/agent-workflow/bridge-settings.conf` (`KEY=VALUE` lines, **parsed never sourced**); this is the ONLY writer for it. The file lives **outside every kit-managed tree**, so a kit refresh never writes or clobbers it — upgrade-survival is structural (D2). It **previews by default**; `--apply` writes. Hand-editing the file stays fully supported — this is an offered convenience, never a lock.
|
|
5
|
+
The reader + consent-gated **writer** for the **host-level** bridge settings file — the answer to *"turn on the codex Fast tier (or another bridge knob) once, predictably, so it survives kit upgrades."* The four bridge wrappers and the judge's wrapper read `${XDG_CONFIG_HOME:-~/.config}/agent-workflow/bridge-settings.conf` (`KEY=VALUE` lines, **parsed never sourced**); this is the ONLY writer for it. The file lives **outside every kit-managed tree**, so a kit refresh never writes or clobbers it — upgrade-survival is structural (D2). It **previews by default**; `--apply` writes. Hand-editing the file stays fully supported — this is an offered convenience, never a lock.
|
|
6
6
|
|
|
7
|
-
**The knobs are the bundled bridges' own `settings` blocks** (manifest-as-source, D6) — the tool never invents a key or a value rule, and what it writes always passes the wrappers' own validation. **The model keys set each bridge's host posture** — the model every run of that bridge uses (codex: and its effort); a set one is checked against the models the installed CLI offers **before anything is written**. Run **`/agent-workflow-kit bridge-settings`** (`node ${CLAUDE_SKILL_DIR}/tools/bridge-settings.mjs`) to see the live list and the models on offer; today:
|
|
7
|
+
**The knobs are the bundled bridges' own `settings` blocks** (manifest-as-source, D6) — the tool never invents a key or a value rule, and what it writes always passes the wrappers' own validation. **The model keys set each bridge's host posture** — the model every run of that bridge uses (codex: and its effort); a set one is checked against the models the installed CLI offers, or for the judge's `JEV_MODEL`, the versions in its manifest's `offered` list, **before anything is written**. Run **`/agent-workflow-kit bridge-settings`** (`node ${CLAUDE_SKILL_DIR}/tools/bridge-settings.mjs`) to see the live list and the models on offer; today:
|
|
8
8
|
|
|
9
9
|
| key | bridge | values | note |
|
|
10
10
|
|---|---|---|---|
|
|
11
11
|
| `CODEX_MODEL` | codex | a model the installed codex offers | the host posture's model; default `gpt-6.1-sol`. |
|
|
12
12
|
| `CODEX_EFFORT` | codex | an effort that model offers | the host posture's reasoning effort; default `high`. |
|
|
13
13
|
| `AGY_MODEL` | agy | a display string the installed agy offers | the host posture's model; default `Gemini 3.8 Flash (High)`. |
|
|
14
|
+
| `JEV_MODEL` | the judge | a version its manifest offers | the judge's model; default the manifest's `posture.model`. |
|
|
14
15
|
| `CODEX_SERVICE_TIER` | codex | `priority` | **SPEND KNOB** — the "Fast" tier: "2x speed, **increased usage**" in the codex catalog's own words for gpt-6.1-sol (cache fetched 2026-10-03); it states no credit-rate figure; quality-neutral (same model). Default unset ⇒ standard tier. |
|
|
15
16
|
| `CODEX_HARD_TIMEOUT` | codex | integer `1..86400` | hard wall-clock cap (seconds) via `timeout(1)`. |
|
|
16
17
|
| `CODEX_REVIEW_MAX_TOTAL_BYTES` | codex | integer `1..100000000` | codex-review payload size above which the diff rides a temp file (never truncated). |
|
|
@@ -20,11 +21,11 @@ The reader + consent-gated **writer** for the **host-level** bridge settings fil
|
|
|
20
21
|
|
|
21
22
|
**Invocations:**
|
|
22
23
|
|
|
23
|
-
1. **Read** — `node ${CLAUDE_SKILL_DIR}/tools/bridge-settings.mjs [--json]` prints every knob's **effective value + source** (`env` / `file` / `default`; a model key's `environment` / `setting` / `default`, as the wrappers' banner names it), each bridge's host posture with the models its installed CLI offers (read with `codex debug models` / `agy models`, never a model run; an unreadable or missing CLI is one stated line, exit 0), and flags any unknown/duplicate/malformed lines. Read-only.
|
|
24
|
+
1. **Read** — `node ${CLAUDE_SKILL_DIR}/tools/bridge-settings.mjs [--json]` prints every knob's **effective value + source** (`env` / `file` / `default`; a model key's `environment` / `setting` / `default`, as the wrappers' banner names it), each codex/agy bridge's host posture with the models its installed CLI offers (read with `codex debug models` / `agy models`, never a model run; an unreadable or missing CLI is one stated line, exit 0), and the judge's host posture with the offered versions from its manifest (no CLI run), and flags any unknown/duplicate/malformed lines. Read-only.
|
|
24
25
|
2. **Preview a change** — `--set KEY=VALUE` (or `--unset KEY`) prints `before → after` and writes **nothing**. Re-run with **`--apply`** to write. Multiple `--set`/`--unset` ops apply in one atomic write.
|
|
25
26
|
3. **`--apply`** writes via the hardened out-of-tree atomic writer (creates the dir + file on first use; symlink/parent/TOCTOU-safe; last-writer-wins). It touches **only** the `KEY=` line it owns — every comment / blank / other line is preserved verbatim.
|
|
26
27
|
|
|
27
|
-
**Precedence at run time:** explicit env (even empty — `KEY=` disables the knob for one run) **>** this file **>** the wrapper's built-in default. So an operator can always override one run without editing the file; the reader shows which source wins.
|
|
28
|
+
**Precedence at run time:** explicit env (even empty — `KEY=` disables the knob for one run) **>** this file **>** the wrapper's built-in default. So an operator can always override one run without editing the file; the reader shows which source wins. For codex and agy, a model key is the exception: an environment value off the host posture is a one-off, which `codex-exec`, `codex-review` and `agy-review` refuse unless it is a probe (the bridge-model contract). An environment `JEV_MODEL` is that run's version, turned away by the judge's wrapper when its manifest does not offer it; a version other than the default marks the notes uncalibrated.
|
|
28
29
|
|
|
29
30
|
**Refusals (the guarded contract):** an **unknown key** or an **invalid / out-of-range value** (a model key: empty, padded with whitespace, or carrying a control byte) → exit `2` (nothing read of the file, nothing written). A **model the catalog does not offer**, or a codex **effort that model does not offer**, → exit `2` with the offered list, nothing written; an unreadable catalog leaves the value unchecked and says so. A file that already carries **duplicate keys** → exit `1`, named and left **byte-untouched** (fix the duplicates by hand first — the writer never edits blindly around them). A **symlinked / non-regular / unreadable** settings file → exit `1` (refuses to write through it). `--apply` with `--dry-run`, a duplicate op for one key, or a malformed `--set` → usage exit `2`.
|
|
30
31
|
|
|
@@ -32,4 +33,4 @@ The reader + consent-gated **writer** for the **host-level** bridge settings fil
|
|
|
32
33
|
|
|
33
34
|
Output is **English/structured** — **localize it to the user's conversational language** when you narrate.
|
|
34
35
|
|
|
35
|
-
**Invariants:** writer (writes only the host settings file — outside any project/kit tree) · never commits · never runs a model (only the two read-only catalog commands) · previews by default · allowlist + value rules from the bundled manifests · a model key is judged against its bridge's catalog before any write · the host file survives every kit refresh.
|
|
36
|
+
**Invariants:** writer (writes only the host settings file — outside any project/kit tree) · never commits · never runs a model (only the two read-only catalog commands) · the judge's catalog read runs no CLI · previews by default · allowlist + value rules from the bundled manifests · a model key is judged against its bridge's catalog before any write · the host file survives every kit refresh.
|
|
@@ -7,7 +7,7 @@ The **final-run checker** (strip-the-kit D3(c)+(d)) — two deterministic arms o
|
|
|
7
7
|
Run `node ${CLAUDE_SKILL_DIR}/tools/coverage-check.mjs --check [--cwd <dir>]`:
|
|
8
8
|
|
|
9
9
|
0. **Attestation precondition (the provenance arm).** An lcov on disk carries no evidence of the tree it came from, so reading one and issuing a verdict certifies whatever happens to be there — the false GREEN direction is the dangerous one, because a line appended AFTER the suite ran has no `DA` entry and therefore reads non-executable ("nothing to cover"). Provenance is a CONSEQUENCE in exactly one context: a `run-gates --final` run deletes the artifact before any gate spawns. That runner mints a random nonce and writes `final-start.attempt` as a ONE-WAY COMMITMENT over `{nonce, tree fingerprint, base}`; the raw nonce rides the environment to this child, which recomputes the commitment and requires the record to carry it. Neither half suffices alone — a bare nonce is unverifiable, a persisted attempt id is reconstructible from public repo state — and the commitment is also the only place the BASE is bound, since no record stores it. The raw nonce is stripped from the red-proof probe environment so no descendant retains a live capability. `attested=` states whether a coverage VERDICT was ISSUED — pass **or** fail — never whether coverage passed: a valid handshake over an lcov that lists uncovered lines still reads `attested=yes` and still exits 1. Outcomes: **attested** → the coverage verdict is issued; **no handshake** → `attested=no` + `NO VERDICT` (exit 0, findings still printed, uncovered lines still exit 1 — the findings contract is unchanged); **a valid handshake over a run that read NO lcov BYTES** (the file is absent, or the path was refused as a non-regular file) → `attested=no` + `NO VERDICT`: the run owned the artifact's lifetime and read nothing, so it certifies NOTHING — reading `yes` there would be the false green this arm exists to close, one layer up. The predicate is the consumed bytes (`lcov-sha256` is a digest, not `none`), never the skip flag, so a refused path can never attest either. The two halves are independent: WITHHOLDING the verdict never changes an exit code — an absent file stays exit 0 (the loud `skipped-no-lcov`), and the refused non-regular path keeps its OWN fail-closed exit 1; **a handshake describing another tree or matching no recorded attempt** → `REFUSED` (exit 1), never a verdict in either direction. One fully anchored `coverage-check: attested=<yes|no>` machine line rides every run, on the same exactly-once contract as the sha line — and a withheld verdict TRAVELS: `run-gates` carries it as `coverage=not-run` on the summary line and names it on the checker's table row, and `core-evidence summary` never renders an unqualified GREEN over a final record that consumed no lcov. Stated residuals, both named rather than implied: (a) an operator who runs both processes can forge the store or the code — the kit's standing self-discipline posture, not a security boundary; (b) **"the run owns the artifact" is exclusive by CONVENTION over the fixed path, not enforced** — a writer outside the run (a second `run-gates`, a hand-run `--only unit-tests`, an orphaned test process) can place foreign evidence between the deletion and the checker's read, and every check then agrees. Closing (b) needs an attempt-unique artifact path, which the runner can name but the declared producer cmd must reference — queued as LCOV-EXCLUSIVE-OWNERSHIP. What this arm removes is the false green that needs no second process and nobody trying: evidence that predates the edit.
|
|
10
|
-
1. **Coverage arm (D3(d)):** every CHANGED executable Node line (`.mjs`/`.cjs`/`.js`, tracked working-vs-HEAD changes + untracked-not-ignored files) must be covered — uncovered lines are LISTED `file:line` and fail; a changed file ABSENT from the lcov map is a file-level red (never "non-executable" by silence); changed out-of-domain files (e.g. `.sh`) and unsupported-source files (e.g. `.ts`) are LISTED — the claim is narrowed honestly, not widened. NO lcov file at the path = a LOUD `skipped-no-lcov` (exit 0, stated — produce the file via the unit-tests gate's lcov reporters); a symlink at the path is a refusal (lstat, no-follow).
|
|
10
|
+
1. **Coverage arm (D3(d)):** every CHANGED executable Node line (`.mjs`/`.cjs`/`.js`, tracked working-vs-HEAD changes + untracked-not-ignored files) must be covered — uncovered lines are LISTED `file:line` and fail; a changed file ABSENT from the lcov map is a file-level red (never "non-executable" by silence); changed out-of-domain files (e.g. `.sh`) and unsupported-source files (e.g. `.ts`) are LISTED — the claim is narrowed honestly, not widened. NO lcov file at the path (ENOENT) = a LOUD `skipped-no-lcov` (exit 0, stated — produce the file via the unit-tests gate's lcov reporters); any other status failure exits 1 naming the path and the code where it has one; a symlink at the path is a refusal (lstat, no-follow).
|
|
11
11
|
2. **Red-proof arm (D3(c)):** every authoritative current-base `red-proof` declaration must verify — the bound test file exists (deleted fails), its content sha256 matches the declaration (custody), the test resolves (zero-match fails) and runs green N/N NOW, and the declaration's pre-fix fingerprint differs from the current tree (equal = reuse/forgery, refused). A malformed evidence store fails CLOSED.
|
|
12
12
|
|
|
13
13
|
Wire it as the LAST declared gate in `docs/ai/gates.json` — `run-gates --final` REFUSES a declaration where the canonical coverage-check gate is not last (nothing may run after the checker consumed the lcov) or where its cmd is not ONE plain invocation of the kit's OWN tool (a masked form or a lookalike path never counts).
|
|
@@ -24,7 +24,7 @@ import { planFor } from './jev-skill.mjs';
|
|
|
24
24
|
import { SKILL_FILES, claudeDirOf, skillAccepted, skillState, skillTargets } from './jev-facts.mjs';
|
|
25
25
|
import { findOnPath } from './detect-backends.mjs';
|
|
26
26
|
import { consoleArgv } from './write-lanes.mjs';
|
|
27
|
-
import {
|
|
27
|
+
import { readDeployedScripts, INSTALLER_REL, formatPlan, planGitHooks } from './git-hooks.mjs';
|
|
28
28
|
import { ATTRIBUTION_HIDDEN, ATTRIBUTION_KEY, writeAttribution } from './attribution.mjs';
|
|
29
29
|
import { globalRemovalOf, planGlobalRemoval } from './hide-footprint.mjs';
|
|
30
30
|
import { isDirectRun } from './direct-run.mjs';
|
|
@@ -234,7 +234,7 @@ export const scopeOf = (variant, facts, deps = {}) => {
|
|
|
234
234
|
}
|
|
235
235
|
if (GIT_VARIANTS.includes(variant)) {
|
|
236
236
|
// Each deployed path under the kit folder, and each folder on its way below the root.
|
|
237
|
-
const copies = variant === 'hook-checks' ? [] :
|
|
237
|
+
const copies = variant === 'hook-checks' ? [] : readDeployedScripts().map(({ deployed }) => join(facts.root, deployed));
|
|
238
238
|
directories.splice(0);
|
|
239
239
|
for (const path of copies) {
|
|
240
240
|
for (let at = dirname(path); at !== facts.root && covers(facts.root, at) && !directories.includes(at); at = dirname(at)) directories.push(at);
|
|
@@ -39,7 +39,7 @@ const bridgeDirs = (ctx) =>
|
|
|
39
39
|
.filter((m) => m.kind === 'execution-backend')
|
|
40
40
|
.map((m) => ({ name: m.name, dir: join(ctx.bundleRoot ?? DEFAULT_BUNDLE_ROOT, m.name) }));
|
|
41
41
|
|
|
42
|
-
// Load the union of
|
|
42
|
+
// Load the union of the bundled bridges' `settings` blocks → a Map keyed by settings key, each entry carrying
|
|
43
43
|
// its typed rule + the owning bridge. A missing/corrupt bundle is a loud STOP (a writer cannot be
|
|
44
44
|
// honored without a trustworthy allowlist; a reader/snapshot caller catches it to degrade). The
|
|
45
45
|
// registry is validated at build time (manifest validate --strict + the mirror drift-guard); here we
|
|
@@ -75,7 +75,9 @@ export const allowedLabel = (entry) => {
|
|
|
75
75
|
case 'integer': return `integer ${entry.min}..${entry.max}`;
|
|
76
76
|
case 'duration': return 'duration (e.g. 5m, 30m, 90s — a unit is required, nonzero)';
|
|
77
77
|
case 'boolean': return '"0" | "1"';
|
|
78
|
-
case 'posture': return
|
|
78
|
+
case 'posture': return Array.isArray(entry.offered)
|
|
79
|
+
? entry.offered.map((value) => `"${value}"`).join(' | ')
|
|
80
|
+
: 'a value the installed CLI offers (checked when set)';
|
|
79
81
|
default: return entry.kind;
|
|
80
82
|
}
|
|
81
83
|
};
|
|
@@ -180,13 +182,16 @@ const REFUSED = (key, v) => ({ value: null, source: 'default', configuredIn: 'en
|
|
|
180
182
|
// (AGY_MODEL: no model, agy's own settings decide); else a non-empty, control-free file value; else the
|
|
181
183
|
// default. Its sources are the wrappers' banner words: default, setting, environment.
|
|
182
184
|
const EMPTY_ENV_DROPS_MODEL = new Set(['AGY_MODEL']);
|
|
185
|
+
const JUDGE_MODEL_KEY = 'JEV_MODEL';
|
|
183
186
|
const postureOf = (entry, parsed, getenv) => {
|
|
184
187
|
const key = entry.key;
|
|
185
188
|
if (Object.prototype.hasOwnProperty.call(getenv, key)) {
|
|
186
189
|
const v = getenv[key];
|
|
187
190
|
if (v === '' && EMPTY_ENV_DROPS_MODEL.has(key)) return { value: null, source: 'environment', configuredIn: 'env', note: `the env ${key}= drops the model — agy's own settings decide` };
|
|
188
191
|
if (v === '') return { value: entry.default, source: 'environment', configuredIn: 'env', note: `the env ${key}= selects the built-in default` };
|
|
189
|
-
if (hasControlByte(v)) return { value: null, source: 'environment', configuredIn: 'env', note: `env value "${safeShow(v)}" carries control bytes for ${key} — ${
|
|
192
|
+
if (hasControlByte(v)) return { value: null, source: 'environment', configuredIn: 'env', note: `env value "${safeShow(v)}" carries control bytes for ${key} — ${key === JUDGE_MODEL_KEY
|
|
193
|
+
? `${entry.appliesTo.join(', ')} refuses the run before any request`
|
|
194
|
+
: entry.bridge === 'antigravity-cli-bridge'
|
|
190
195
|
? 'agy-review refuses the run pre-spend; agy-run has no control-byte screen and refuses it only through its catalog check (it runs it when the catalog is unreadable)'
|
|
191
196
|
: 'the codex wrappers refuse the run pre-spend'}` };
|
|
192
197
|
return { value: v, source: 'environment', configuredIn: 'env' };
|
|
@@ -1,35 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// bridge-settings.mjs — the reader + consent-gated WRITER for the host-level bridge settings file
|
|
3
|
-
// (bridges 2.3.0, D6). The four bridge wrappers READ ${XDG_CONFIG_HOME:-~/.config}/agent-workflow/
|
|
4
|
-
// bridge-settings.conf (KEY=VALUE lines, parsed never sourced; env > file > built-in default); this is
|
|
5
|
-
// the ONLY writer for it. It lives OUTSIDE every kit-managed tree, so a kit refresh never touches it
|
|
6
|
-
// (D2 — upgrade-survival is structural). The allowlist + typed validation come from the BUNDLED bridge
|
|
7
|
-
// manifests' `settings` blocks (manifest-as-source): the tool never invents a key or a value rule, and
|
|
8
|
-
// what it writes always passes the wrappers' own aw_settings_valid (the shared settingValueValid).
|
|
9
|
-
//
|
|
10
|
-
// Posture (D3, guarded): PREVIEW BY DEFAULT; --apply writes. It refuses an unknown key, an invalid /
|
|
11
|
-
// out-of-range value, and — loudly, naming the key — a file that already carries DUPLICATE keys (it
|
|
12
|
-
// never emits duplicates and never edits blindly around them). It touches only the KEY= line it owns,
|
|
13
|
-
// preserving every comment/blank/other line verbatim, and creates the dir + file on first apply via
|
|
14
|
-
// the hardened out-of-tree atomic writer (symlink/parent/TOCTOU-safe). The model keys (kind `posture`,
|
|
15
|
-
// spec bridge-settings) are settable: the read-out shows each bridge's host posture and the models its
|
|
16
|
-
// installed CLI offers, and a set naming a model key is judged against that bridge's catalog before
|
|
17
|
-
// any write. It runs only the catalog commands, never a model. CODEX_SERVICE_TIER carries the
|
|
18
|
-
// credit-rate caveat wherever it renders (from the manifest `effect`).
|
|
19
|
-
//
|
|
20
|
-
// Output is ENGLISH/structured (repo-artifact Hard Constraint); the agent localizes when narrating.
|
|
21
|
-
// Exit codes: 0 success (reader, preview, or apply); 2 usage (bad args / unknown key / invalid value /
|
|
22
|
-
// a model or effort the catalog does not offer); 1 precondition STOP (duplicate-carrying / symlinked /
|
|
23
|
-
// unreadable file, a write STOP) or a corrupt bundle (cannot determine the allowlist).
|
|
24
|
-
// main(argv, ctx) → Promise of { code, stdout, stderr }; getenv / home / bundleRoot / fs and the
|
|
25
|
-
// catalog bounds are injectable for host-independent tests.
|
|
26
|
-
//
|
|
27
|
-
// Dependency-free, Node >= 22. No side effects on import (the isDirectRun idiom).
|
|
28
2
|
|
|
29
3
|
import { isDirectRun } from './direct-run.mjs';
|
|
30
4
|
import { settingValueValid } from './manifest/validate.mjs';
|
|
31
5
|
import { writeHostConfigFileAtomic } from './atomic-write.mjs';
|
|
32
|
-
import { readCatalogs } from './bridge-catalog.mjs';
|
|
6
|
+
import { CATALOG_BOUNDS_MS, readCatalogs } from './bridge-catalog.mjs';
|
|
33
7
|
import {
|
|
34
8
|
SETTINGS_SUBDIR, SETTINGS_FILENAME, fail, loadRegistry, allowedLabel, settingsDir, settingsPath,
|
|
35
9
|
joinLines, readFileState, parseSettings, duplicateKeys, effectiveOf, displayValue,
|
|
@@ -39,6 +13,16 @@ import {
|
|
|
39
13
|
|
|
40
14
|
const slotOf = (key) => (key.endsWith('_EFFORT') ? 'effort' : 'model');
|
|
41
15
|
const postureBridges = (registry) => [...new Set([...registry.values()].filter((e) => e.kind === 'posture').map((e) => e.bridge))];
|
|
16
|
+
const usesOfferedCatalog = (entry) => Object.hasOwn(entry, 'offered') || !Object.hasOwn(CATALOG_BOUNDS_MS, entry.bridge);
|
|
17
|
+
const readPostureCatalogs = async (bridges, registry, ctx) => {
|
|
18
|
+
const models = bridges.map((bridge) => [...registry.values()].find((entry) => entry.bridge === bridge && entry.kind === 'posture' && slotOf(entry.key) === 'model'));
|
|
19
|
+
const catalogs = await readCatalogs(models.filter((entry) => !usesOfferedCatalog(entry)).map((entry) => entry.bridge), ctx);
|
|
20
|
+
return Object.fromEntries(models.map((entry) => [entry.bridge, usesOfferedCatalog(entry)
|
|
21
|
+
? Array.isArray(entry.offered) && entry.offered.length > 0 && entry.offered.every((model) => typeof model === 'string' && settingValueValid(entry, model))
|
|
22
|
+
? { state: 'offered', cause: null, entries: entry.offered.map((model) => ({ model })) }
|
|
23
|
+
: { state: 'unreadable', cause: 'the bundled manifest has no usable offered list', entries: [] }
|
|
24
|
+
: catalogs[entry.bridge]]));
|
|
25
|
+
};
|
|
42
26
|
|
|
43
27
|
// One bridge's posture as { model: {key, value, source, note}, effort?: … } under the given env.
|
|
44
28
|
const postureOfBridge = (registry, parsed, getenv, bridge) => Object.fromEntries([...registry.values()]
|
|
@@ -57,7 +41,7 @@ const catalogWarning = (bridge, catalog) => (catalog.state === 'not-installed'
|
|
|
57
41
|
: `⚠ ${bridge}: the model catalog is unreadable (${catalog.cause}) — the offered list is unknown`);
|
|
58
42
|
|
|
59
43
|
const renderPosture = (registry, parsed, getenv, catalogs) => {
|
|
60
|
-
const lines = ['', ' host posture (the model each bridge runs;
|
|
44
|
+
const lines = ['', ' host posture (the model each bridge runs; offered models come from the installed CLI or the bundled manifest, none is run):'];
|
|
61
45
|
for (const bridge of postureBridges(registry)) {
|
|
62
46
|
const p = postureOfBridge(registry, parsed, getenv, bridge);
|
|
63
47
|
const effort = p.effort ? ` · effort ${showModel(p.effort.value)} [${p.effort.source}]` : '';
|
|
@@ -80,7 +64,7 @@ const judgePosture = async (ops, registry, newLines, ctx) => {
|
|
|
80
64
|
const bridges = [...new Set(ops.map((op) => registry.get(op.key)).filter((e) => e.kind === 'posture').map((e) => e.bridge))];
|
|
81
65
|
if (!bridges.length) return [];
|
|
82
66
|
const after = parseSettings(joinLines(newLines));
|
|
83
|
-
const catalogs = await
|
|
67
|
+
const catalogs = await readPostureCatalogs(bridges, registry, ctx);
|
|
84
68
|
const unchecked = [];
|
|
85
69
|
for (const bridge of bridges) {
|
|
86
70
|
const { model, effort } = postureOfBridge(registry, after, {}, bridge);
|
|
@@ -90,7 +74,7 @@ const judgePosture = async (ops, registry, newLines, ctx) => {
|
|
|
90
74
|
continue;
|
|
91
75
|
}
|
|
92
76
|
const entry = catalog.entries.find((e) => e.model === model.value);
|
|
93
|
-
if (!entry) throw fail(2, `${model.key}=${model.value} is not a model the
|
|
77
|
+
if (!entry) throw fail(2, `${model.key}=${model.value} is not a model the ${bridge} catalog offers — refusing before any write. Offered: ${catalog.entries.map((e) => e.model).join(', ')}`);
|
|
94
78
|
if (effort && entry.efforts === null) unchecked.push(`${bridge}: the effort was not checked — the catalog entry for ${model.value} lists no efforts; the wrapper checks it at run time`);
|
|
95
79
|
else if (effort && !entry.efforts.includes(effort.value)) {
|
|
96
80
|
throw fail(2, `${effort.key}=${effort.value} is not an effort the installed ${bridge} catalog offers for ${model.value} — refusing before any write. Offered: ${entry.efforts.join(', ')}`);
|
|
@@ -253,22 +237,22 @@ const changeLine = (c) => {
|
|
|
253
237
|
return ` ${c.key}: ${b} → ${a}`;
|
|
254
238
|
};
|
|
255
239
|
|
|
256
|
-
// A model key's env value off the host posture is a one-off the wrappers refuse (spec bridge-model),
|
|
257
|
-
// so its shadow line says that instead of "it wins".
|
|
258
240
|
const SHADOW_EFFECT = {
|
|
259
241
|
'codex-cli-bridge': 'an environment value off the host posture is a one-off, which codex-exec and codex-review refuse unless CODEX_PROBE=1; unset it.',
|
|
260
242
|
'antigravity-cli-bridge': 'an environment value off the host posture (an empty one included) is a one-off, which agy-review refuses unless AGY_PROBE=1 (agy-run, the probe role, runs it); unset it.',
|
|
261
243
|
};
|
|
262
|
-
const shadowLine = (entry) => ` ⚠ ${entry.key} is currently set in the environment — ${entry.kind === 'posture'
|
|
263
|
-
?
|
|
244
|
+
const shadowLine = (entry, getenv) => ` ⚠ ${entry.key} is currently set in the environment — ${entry.kind === 'posture'
|
|
245
|
+
? usesOfferedCatalog(entry)
|
|
246
|
+
? getenv[entry.key] === '' ? 'the empty value selects the default for that run; unset it.' : `the value ${JSON.stringify(getenv[entry.key])} runs for that run; the judge's wrapper turns it away unless the manifest's offered list includes it; a version other than the default marks the notes uncalibrated; unset it.`
|
|
247
|
+
: SHADOW_EFFECT[entry.bridge] : 'the env value overrides the file for this session (unset it, or it wins until you do).'}`;
|
|
264
248
|
|
|
265
|
-
const renderWriter = ({ registry, changes, wrote, path, willWrite, envShadows, caveats, unchecked }) => {
|
|
249
|
+
const renderWriter = ({ registry, changes, wrote, path, willWrite, envShadows, caveats, unchecked, getenv }) => {
|
|
266
250
|
const lines = [];
|
|
267
251
|
lines.push(wrote ? `wrote ${path}` : 'bridge-settings — preview (nothing written; re-run with --apply to write)');
|
|
268
252
|
for (const c of changes) lines.push(changeLine(c));
|
|
269
253
|
for (const cav of caveats) lines.push(` ↳ ${cav}`);
|
|
270
254
|
for (const u of unchecked) lines.push(` ⚠ ${u}`);
|
|
271
|
-
for (const key of envShadows) lines.push(shadowLine(registry.get(key)));
|
|
255
|
+
for (const key of envShadows) lines.push(shadowLine(registry.get(key), getenv));
|
|
272
256
|
if (!wrote && willWrite) lines.push('', `re-run with --apply to write ${path}.`);
|
|
273
257
|
if (!wrote && !willWrite) lines.push(' no change — the file already reads this way.');
|
|
274
258
|
return lines.join('\n');
|
|
@@ -283,7 +267,7 @@ const HELP = `bridge-settings — read / write the host-level bridge settings fi
|
|
|
283
267
|
Usage:
|
|
284
268
|
node bridge-settings.mjs show every knob's effective value + source, each
|
|
285
269
|
bridge's model (codex: and effort) and the models
|
|
286
|
-
its installed CLI offers
|
|
270
|
+
its installed CLI or bundled manifest offers
|
|
287
271
|
node bridge-settings.mjs --set KEY=VALUE preview a change (writes nothing)
|
|
288
272
|
node bridge-settings.mjs --set KEY=VALUE --apply write the change (atomic; creates the file on first use)
|
|
289
273
|
node bridge-settings.mjs --unset KEY [--apply] return a knob to its built-in default
|
|
@@ -292,9 +276,10 @@ Usage:
|
|
|
292
276
|
keys (preserved verbatim), never writes
|
|
293
277
|
|
|
294
278
|
Precedence at run time: explicit env (even empty: KEY= disables) > this file > the wrapper's built-in
|
|
295
|
-
default. Allowed keys + value rules come from the bundled bridge manifests.
|
|
296
|
-
|
|
297
|
-
|
|
279
|
+
default. Allowed keys + value rules come from the bundled bridge manifests. Model keys (codex: and
|
|
280
|
+
effort) set each bridge's host posture; a set is checked against that bridge's catalog before any
|
|
281
|
+
write. The judge's model uses its bundled manifest's offered list, with no CLI or time bound.
|
|
282
|
+
An unreadable catalog leaves the value unchecked, and says so. The
|
|
298
283
|
command runs only the catalog commands, never a model. This host file survives every kit upgrade —
|
|
299
284
|
a kit refresh never writes or clobbers it.
|
|
300
285
|
|
|
@@ -322,7 +307,7 @@ export const main = async (argv = [], ctx = {}) => {
|
|
|
322
307
|
if (ops.length === 0) {
|
|
323
308
|
const fileState = readFileState(path, ctx);
|
|
324
309
|
const parsed = parseSettings(fileState.text ?? '');
|
|
325
|
-
const catalogs = await
|
|
310
|
+
const catalogs = await readPostureCatalogs(postureBridges(registry), registry, ctx);
|
|
326
311
|
const stdout = json
|
|
327
312
|
? JSON.stringify(buildReaderJson(registry, parsed, fileState, ctx, path, catalogs), null, 2)
|
|
328
313
|
: renderReader(registry, parsed, fileState, ctx, path, catalogs);
|
|
@@ -367,7 +352,7 @@ export const main = async (argv = [], ctx = {}) => {
|
|
|
367
352
|
if (!apply || noop) {
|
|
368
353
|
const stdout = json
|
|
369
354
|
? JSON.stringify(jsonBody(false), null, 2)
|
|
370
|
-
: renderWriter({ registry, changes, wrote: false, path, willWrite: !noop, envShadows, caveats, unchecked });
|
|
355
|
+
: renderWriter({ registry, changes, wrote: false, path, willWrite: !noop, envShadows, caveats, unchecked, getenv });
|
|
371
356
|
return { code: 0, stdout, stderr: '' };
|
|
372
357
|
}
|
|
373
358
|
|
|
@@ -375,7 +360,7 @@ export const main = async (argv = [], ctx = {}) => {
|
|
|
375
360
|
writeHostConfigFileAtomic(settingsDir(ctx), SETTINGS_FILENAME, body, ctx, { noun: 'the bridge settings file' });
|
|
376
361
|
const stdout = json
|
|
377
362
|
? JSON.stringify(jsonBody(true), null, 2)
|
|
378
|
-
: renderWriter({ registry, changes, wrote: true, path, willWrite: false, envShadows, caveats, unchecked });
|
|
363
|
+
: renderWriter({ registry, changes, wrote: true, path, willWrite: false, envShadows, caveats, unchecked, getenv });
|
|
379
364
|
return { code: 0, stdout, stderr: '' };
|
|
380
365
|
} catch (err) {
|
|
381
366
|
return { code: err.exitCode ?? 1, stdout: '', stderr: `bridge-settings: ${err.message}` };
|
package/tools/coverage-check.mjs
CHANGED
|
@@ -73,11 +73,12 @@ const checkCoverage = ({ rootTop, lcovPath }) => {
|
|
|
73
73
|
let st = null;
|
|
74
74
|
try {
|
|
75
75
|
st = lstatSync(lcovPath);
|
|
76
|
-
} catch {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if (error?.code === 'ENOENT') {
|
|
78
|
+
return { failures, notes: [`skipped-no-lcov: no lcov file at ${lcovPath} — NO coverage check ran (produce it via the declared unit-tests gate cmd's lcov reporters)`], skipped: true, lcovSha256: null };
|
|
79
|
+
}
|
|
80
|
+
failures.push(`${lcovPath}: status could not be read (${error?.code ?? 'fs error'})`);
|
|
81
|
+
return { failures, notes, skipped: false, lcovSha256: null };
|
|
81
82
|
}
|
|
82
83
|
if (!st.isFile()) {
|
|
83
84
|
failures.push(`${lcovPath}: not a regular file (a symlink/device is never read — fail closed)`);
|
|
@@ -318,9 +319,9 @@ deleted fresh by run-gates --final), lists uncovered CHANGED executable Node lin
|
|
|
318
319
|
lists changed out-of-domain files (the coverage claim is narrowed to Node lines), and VERIFIES
|
|
319
320
|
every current-base red-proof record: bound test present, content hash unchanged, green N/N
|
|
320
321
|
(AW_CORE_EVIDENCE_RERUNS, default 3), pre-fix fingerprint differing from the current tree.
|
|
321
|
-
An absent lcov file is a LOUD skipped-no-lcov (exit 0 — NO coverage check ran, stated)
|
|
322
|
-
symlinked lcov path, an uncovered line, a broken red-proof
|
|
323
|
-
store fails (exit 1).
|
|
322
|
+
An absent lcov file (ENOENT) is a LOUD skipped-no-lcov (exit 0 — NO coverage check ran, stated).
|
|
323
|
+
Any other lcov status failure, a symlinked lcov path, an uncovered line, a broken red-proof
|
|
324
|
+
obligation, or a malformed evidence store fails (exit 1).
|
|
324
325
|
|
|
325
326
|
A coverage VERDICT is issued ONLY inside the run that owns the artifact's lifetime: run-gates
|
|
326
327
|
--final deletes the lcov before any gate spawns and hands this checker an attestation context
|
|
@@ -146,7 +146,7 @@ const RAW_BACKENDS = [
|
|
|
146
146
|
],
|
|
147
147
|
receipt: "side effect — a successful review appends one JSON receipt line to <git dir>/agent-workflow-review-receipts.jsonl (AW_REVIEW_RECEIPTS overrides; plan/diff outside a git tree: warn + skip unless overridden): fingerprint = sha256 over the canonical uncommitted-state payload (staged diff + unstaged diff + untracked-not-ignored contents — the review-payload domain; never-committable untracked paths — character/block devices, FIFOs, sockets — are excluded from the domain entirely, untracked symlinks/directories ride as name-only notes) in code mode, the artifact-file sha256 in plan/diff mode; durationS = integer wall-clock seconds from CLI start through verdict parsing and the wrapper prints review duration: <n>s; blocking = the count of numbered items in the first ### Blocking section; artifactPath = the normalized realpath on plan/diff receipts only (repo-relative inside the work tree, absolute otherwise), while a double quote, backslash or control byte refuses pre-spend because the receipt encoder cannot carry it; verdict recorded verbatim from the mandated '### Verdict' section (SHIP / SHIP WITH NITS / REWORK); grounded = whether a NON-EMPTY --facts payload was supplied (code mode refuses pre-spend without one — no run, no receipt — unless --ungrounded/AGY_PROBE=1; in plan/diff an empty payload records grounded:false — fail-closed, the state gate rejects it), factsHash = sha256 of the facts payload; a continuation receipt is fresh:false (informational-only — it cannot attest the folded tree); probe = whether the run relaxed the quality guards (AGY_PROBE=1), written on EVERY receipt so it self-declares — the kit's review-state gate rejects a probe-marked receipt (a probe review never attests) and equally rejects an unmarked one (silence is not a declaration); posture = the ACTUAL run posture {model} (agy has no tier), written on EVERY receipt (D5) — the gate rejects a receipt with an absent/invalid posture (a pre-D5 wrapper minted it; re-run the review), one stderr banner line states the same posture, a one-off model (an explicitly empty AGY_MODEL included) refuses pre-spend unless AGY_PROBE=1, and a model string carrying control bytes refuses pre-spend in every mode; delivery = how the change set REACHED the model, currently emitted as 'inline' (the whole set rode one prompt — proven by construction) or 'fed' (a chunked feed whose per-part echo proof verified); REQUIRED on every agy code receipt and its ABSENCE is what stops a pre-fed-lane receipt attesting, while the gate accepts any well-formed declaration rather than a particular value; absent by construction on plan/diff/continuation receipts, which carry no change set; a run whose output carries NO recognized '### Verdict' section — empty output included — exits 4 with NO receipt (D4: a FAILED review to RE-RUN, never a fatal session error); when the dispatch nonce seam is supplied — the AW_REVIEW_NONCE environment value or its plain-argument equivalent --nonce <n> (one seam: the flag assigns the same value; supplying both with different values refuses pre-spend) — under the safe grammar [A-Za-z0-9._-]{1,64} (anything else refuses pre-spend), the wrapper first mints the finding MANIFEST {schema, backend, nonce, fingerprint, findings} beside the receipts file (agent-workflow-finding-manifest-<backend>-<nonce>.json; atomic, no-clobber — a byte-identical rewrite is an idempotent no-op, different bytes refuse loudly) ORDERED before the receipt append — a failed manifest write EXCLUDES the receipt append, so a nonce-supplied dispatch can never land a receipt without its readable manifest; a nonce-less invocation adds NO nonce field and mints NO finding manifest (the existing wrapperVersion field still changes with each bridge release); a write failure warns, never fails the review",
|
|
148
148
|
notes: [
|
|
149
|
-
'transport: every review dispatch drives the CLI in --output-format json (plus --disable-slash-commands) and the returned envelope is parsed in node (bin/agy-envelope.mjs) — the operator-facing invocations and flags above do NOT change, and on a ZERO exit the wrapper still PRINTS the review text, never JSON. A missing or unreadable envelope on a zero exit is a loud failure with NO receipt, never a downgraded verdict and never a fallback to raw-stdout parsing; a non-zero CLI exit keeps its own code and message, and publishes the captured stdout unchanged from the SINGLE dispatch or the FINAL fed turn (which may therefore be a JSON or partial payload — the envelope is parsed only on a zero exit); an INTERMEDIATE feed turn is the exception, its output stays private (Invariant E) and its failure prints only a named error. Enforced by a PRE-SPEND capability probe, not a version floor: agy --help must advertise --output-format and --disable-slash-commands, node must be >= 22, and bin/agy-envelope.mjs must be present — otherwise the review refuses before any run is spent and names the missing capability',
|
|
149
|
+
'transport: every review dispatch drives the CLI in --output-format json (plus --disable-slash-commands) and the returned envelope is parsed in node (bin/agy-envelope.mjs) — the operator-facing invocations and flags above do NOT change, and on a ZERO exit the wrapper still PRINTS the review text, never JSON. A missing or unreadable envelope on a zero exit is a loud failure with NO receipt, never a downgraded verdict and never a fallback to raw-stdout parsing; a non-zero CLI exit keeps its own code and message, and publishes the captured stdout unchanged from the SINGLE dispatch or the FINAL fed turn (which may therefore be a JSON or partial payload — the envelope is parsed only on a zero exit); an INTERMEDIATE feed turn is the exception, its output stays private (Invariant E) and its failure prints only a named error. Enforced by a PRE-SPEND capability probe, not a version floor: agy --help must advertise --output-format and --disable-slash-commands, node must be >= 22.21, and bin/agy-envelope.mjs must be present — otherwise the review refuses before any run is spent and names the missing capability',
|
|
150
150
|
'pre-dispatch host-diff: before the FIRST dispatch of this bridge, diff the hosts of the services its manifest names against the live sandbox allow-list — a missing host is surfaced to the maintainer BEFORE dispatching, never fired into a known prompt',
|
|
151
151
|
'the review posture banner appends a banner-only source=model:<s> field — where the model came from: default, setting or environment — then a banner-only timeout=<duration> field — exactly the duration agy-run hands to timeout(1); the hard-timeout preflight fails CLOSED when no timeout/gtimeout binary exists (the wrapper refuses by name before any CLI run, so an uncapped review run can no longer happen), and neither field enters the receipt posture or the D5 banner↔receipt parity',
|
|
152
152
|
'quote the posture banner verbatim when labeling this dispatch — the banner is the machine-stated posture; a prose re-type drifts',
|
|
@@ -3,11 +3,11 @@ import { lstatSync, readFileSync, readdirSync, unlinkSync } from 'node:fs';
|
|
|
3
3
|
import { join, posix } from 'node:path';
|
|
4
4
|
import { lstatNoFollow } from '../atomic-write.mjs';
|
|
5
5
|
import { stripGitLocationEnv } from '../git-env.mjs';
|
|
6
|
-
import {
|
|
6
|
+
import { readDeployedScripts, KIT_SCRIPTS_DIR, SCRIPTS_DIR } from '../node-evidence.mjs';
|
|
7
7
|
import { PRIOR_FILES, SCRIPT_PRIORS, digestOf } from '../script-priors.mjs';
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const readDeployedByName = () => new Map(readDeployedScripts().map((entry) => [posix.basename(entry.path), entry]));
|
|
10
|
+
const readCommand = () => readDeployedScripts().find((entry) => !entry.module);
|
|
11
11
|
const normalizeBody = (bytes) => String(bytes).replaceAll('\r\n', '\n');
|
|
12
12
|
const flatPath = (name) => `${SCRIPTS_DIR}/${name}`;
|
|
13
13
|
const isRegular = (cwd, rel, lstat) => lstatNoFollow(join(cwd, rel), lstat)?.isFile() === true;
|
|
@@ -16,7 +16,7 @@ const errorCode = (error) => error.code ?? error.message;
|
|
|
16
16
|
export const isRetiredKitScript = (name, bytes, kitRoot, read = readFileSync) => {
|
|
17
17
|
const digest = digestOf(normalizeBody(bytes));
|
|
18
18
|
if (SCRIPT_PRIORS.some((row) => row.file === name && row.digest === digest)) return true;
|
|
19
|
-
const entry =
|
|
19
|
+
const entry = readDeployedByName().get(name);
|
|
20
20
|
return Boolean(entry && digest === digestOf(normalizeBody(read(join(kitRoot, entry.bundled)))));
|
|
21
21
|
};
|
|
22
22
|
|
|
@@ -56,7 +56,7 @@ export const retireScripts = ({ cwd, kitRoot, dryRun = false, deps = {}, placedS
|
|
|
56
56
|
const lstat = deps.lstat ?? lstatSync;
|
|
57
57
|
const read = deps.readFile ?? readFileSync;
|
|
58
58
|
const standing = (rel) => (dryRun && placedScripts.includes(rel)) || isRegular(cwd, rel, lstat);
|
|
59
|
-
const commandStands = standing(
|
|
59
|
+
const commandStands = standing(readCommand().deployed);
|
|
60
60
|
const classified = new Map();
|
|
61
61
|
const removed = [];
|
|
62
62
|
const lines = [];
|
|
@@ -79,8 +79,8 @@ export const retireScripts = ({ cwd, kitRoot, dryRun = false, deps = {}, placedS
|
|
|
79
79
|
if (owned === null) continue;
|
|
80
80
|
classified.set(name, owned ? 'kit' : 'foreign');
|
|
81
81
|
if (!owned) { lines.push(foreignLine(name)); continue; }
|
|
82
|
-
const replacement =
|
|
83
|
-
const missing = !commandStands ?
|
|
82
|
+
const replacement = readDeployedByName().get(name);
|
|
83
|
+
const missing = !commandStands ? readCommand().deployed : replacement && !standing(replacement.deployed) ? replacement.deployed : null;
|
|
84
84
|
if (missing) { lines.push(keptLine(name, missing, dryRun)); continue; }
|
|
85
85
|
if (!dryRun) {
|
|
86
86
|
try {
|
|
@@ -19,7 +19,7 @@ import { lstatSync, readFileSync } from 'node:fs';
|
|
|
19
19
|
import { join, posix } from 'node:path';
|
|
20
20
|
import { lstatNoFollow, writeContainedFileAtomic, writeProjectFileCreateOnly } from '../atomic-write.mjs';
|
|
21
21
|
import { bundledImportsOf, composeFailure, composeOutcome, dependenciesFirst, nodeEvidenceRefusal, probeSeedTarget, tmpNote } from '../ensure-ops.mjs';
|
|
22
|
-
import {
|
|
22
|
+
import { readDeployedScripts, INSTALLER_REL, KIT_SCRIPTS_DIR, SCRIPTS_DIR } from '../node-evidence.mjs';
|
|
23
23
|
import { SCRIPT_PRIORS, classifyDeployedScript } from '../script-priors.mjs';
|
|
24
24
|
import { VEHICLES_REL } from '../vehicle-settings.mjs';
|
|
25
25
|
import { retireScripts } from './retired.mjs';
|
|
@@ -34,10 +34,6 @@ export const HOOK_CHANNEL = '.claude/hooks/<name>.local.mjs';
|
|
|
34
34
|
const ROTATOR = 'archives/archive-decisions.mjs';
|
|
35
35
|
// The family: every deployed entry outside the specs op's files (its three modules and the command), in manifest order.
|
|
36
36
|
const SPECS_MODULES = ['spec-schema', 'docs-size', 'test-reporter'];
|
|
37
|
-
const FAMILY = DEPLOYED_SCRIPTS.filter((e) => e.module && !SPECS_MODULES.includes(e.module));
|
|
38
|
-
// The manifest paths a run of a component that is not accepted judges: the rotator and what it loads.
|
|
39
|
-
export const SEED_NAMES = Object.freeze(FAMILY.filter((e) => e.seed).map((e) => e.path));
|
|
40
|
-
const FOLDERS = [...new Set([SCRIPTS_DIR, KIT_SCRIPTS_DIR, ...FAMILY.map((e) => posix.dirname(e.deployed))])];
|
|
41
37
|
|
|
42
38
|
const causeOf = (err) => String((err && err.message) || err);
|
|
43
39
|
const kindOfDir = (st) => (st.isSymbolicLink() ? 'a symlink' : st.isFile() ? 'a regular file' : 'not a directory');
|
|
@@ -49,8 +45,9 @@ const wrongKind = (rel, kind) => composeFailure(OP, 'wrong-node-kind', `${rel}:
|
|
|
49
45
|
const inWriteOrder = (files) => [...files.filter((f) => f.rel === INSTALLER_REL), ...dependenciesFirst(files.filter((f) => f.rel !== INSTALLER_REL))];
|
|
50
46
|
|
|
51
47
|
// Each folder on the way, lstat-ed without following a link: → { refusal } | {}.
|
|
52
|
-
const surveyFolders = (cwd, lstat) => {
|
|
53
|
-
|
|
48
|
+
const surveyFolders = (cwd, family, lstat) => {
|
|
49
|
+
const folders = [...new Set([SCRIPTS_DIR, KIT_SCRIPTS_DIR, ...family.map((e) => posix.dirname(e.deployed))])];
|
|
50
|
+
for (const rel of folders) {
|
|
54
51
|
const st = lstatNoFollow(join(cwd, rel), lstat);
|
|
55
52
|
if (st !== null && (!st.isDirectory() || st.isSymbolicLink())) return { refusal: wrongKind(`${rel}/`, kindOfDir(st)) };
|
|
56
53
|
}
|
|
@@ -60,13 +57,15 @@ const surveyFolders = (cwd, lstat) => {
|
|
|
60
57
|
// → { refusal } | { files, accepted }. A family path of another node kind is judged before the
|
|
61
58
|
// component, so a linked family file is never placed over.
|
|
62
59
|
const survey = ({ cwd, kitRoot, deps, read, lstat }) => {
|
|
63
|
-
const
|
|
60
|
+
const family = readDeployedScripts().filter((e) => e.module && !SPECS_MODULES.includes(e.module));
|
|
61
|
+
const seedNames = family.filter((e) => e.seed).map((e) => e.path);
|
|
62
|
+
const folders = surveyFolders(cwd, family, lstat);
|
|
64
63
|
if (folders.refusal) return folders;
|
|
65
|
-
const probes =
|
|
64
|
+
const probes = family.map((e) => ({ path: e.path, rel: e.deployed, bundled: e.bundled, probe: probeSeedTarget(join(cwd, e.deployed), lstat) }));
|
|
66
65
|
const wrong = probes.find((f) => f.probe.wrongKind);
|
|
67
66
|
if (wrong) return { refusal: wrongKind(wrong.rel, wrong.probe.wrongKind) };
|
|
68
67
|
const flatInstaller = probeSeedTarget(join(cwd, SCRIPTS_DIR, posix.basename(INSTALLER_REL)), lstat);
|
|
69
|
-
const accepted = probes.some((f) => f.probe.present && !
|
|
68
|
+
const accepted = probes.some((f) => f.probe.present && !seedNames.includes(f.path)) || (flatInstaller.present && !flatInstaller.wrongKind);
|
|
70
69
|
const byPath = new Map();
|
|
71
70
|
for (const f of probes) {
|
|
72
71
|
try {
|
|
@@ -76,7 +75,7 @@ const survey = ({ cwd, kitRoot, deps, read, lstat }) => {
|
|
|
76
75
|
return { refusal: composeFailure(OP, 'bundle-unreadable', `${f.rel}: the bundled script could not be read, so nothing was written — reinstall the kit. ${causeOf(err)}`) };
|
|
77
76
|
}
|
|
78
77
|
}
|
|
79
|
-
const files = inWriteOrder([...byPath.values()]).filter((f) => accepted ||
|
|
78
|
+
const files = inWriteOrder([...byPath.values()]).filter((f) => accepted || seedNames.includes(f.path)).map(({ path, rel, bundle, probe }) => {
|
|
80
79
|
const bytes = probe.present ? read(join(cwd, rel)) : undefined;
|
|
81
80
|
return { path, rel, bundle, state: probe.present ? classifyDeployedScript(bytes, path, bundle, deps.priors ?? SCRIPT_PRIORS) : 'absent' };
|
|
82
81
|
});
|
package/tools/ensure-ops.mjs
CHANGED
|
@@ -36,7 +36,7 @@ import { GATES_REL } from './gates-declaration.mjs';
|
|
|
36
36
|
import { AUTONOMY_REL } from './autonomy-config.mjs';
|
|
37
37
|
import { VEHICLES_REL } from './vehicle-settings.mjs';
|
|
38
38
|
import { ENSURE_TOKENS, FAILURE_CAUSES } from './ensure-vocabulary.mjs';
|
|
39
|
-
import {
|
|
39
|
+
import { readDeployedScripts, NODE_EVIDENCE, describeNodeProbes, probeNodeEvidence } from './node-evidence.mjs';
|
|
40
40
|
import { classifyDeployedScript } from './script-priors.mjs';
|
|
41
41
|
import { parseFrontmatter } from '../references/scripts/docs-size/index.mjs';
|
|
42
42
|
|
|
@@ -233,7 +233,7 @@ export const nodeEvidenceRefusal = (op, cwd, lstat) => {
|
|
|
233
233
|
const INDEX_REL = 'docs/ai/index.md';
|
|
234
234
|
// The docs checker is the docs-size module's one deployed entry: bundled, it is the generator; deployed,
|
|
235
235
|
// the kept probe. A flat scripts/check-docs-size.mjs is no deployed checker (story S4 reads it).
|
|
236
|
-
const
|
|
236
|
+
const readChecker = () => readDeployedScripts().find(({ module }) => module === 'docs-size');
|
|
237
237
|
const ENSURE_INDEX_OUTCOME = /^ensure-index: (regenerated|already-current)\b/m;
|
|
238
238
|
const ENSURE_INDEX_REFUSAL = /^ensure-index: (write-refused|probe-failed)\b/m;
|
|
239
239
|
// The probe has no machine line, so its two ANSWERS are matched against the canonical sentences it
|
|
@@ -249,21 +249,21 @@ const describeExit = (result) => (result.signal ? `on signal ${result.signal}` :
|
|
|
249
249
|
const bothStreams = (result) => `${String(result.stdout ?? '')}${String(result.stderr ?? '')}`.trim();
|
|
250
250
|
const describeExitWithOutput = (result, subject = 'it') => `${subject} exited ${describeExit(result)}${bothStreams(result) ? `: ${bothStreams(result)}` : ''}`;
|
|
251
251
|
|
|
252
|
-
const
|
|
253
|
-
const
|
|
252
|
+
const describeKeptJudge = () => `the project's own checker (${readChecker().deployed} --check-index)`;
|
|
253
|
+
const describeKeptFits = () => `in sync under ${describeKeptJudge()} and within the maxLines it stamps`;
|
|
254
254
|
const KEPT_ROUTE = "the spec layer's write of the bundled modules the project's hook loads, then this step again";
|
|
255
255
|
const KEPT_PROBE_TIMEOUT_MS = 30_000;
|
|
256
256
|
const countLines = (text) => text.split('\n').length - (text.endsWith('\n') ? 1 : 0);
|
|
257
257
|
const readStampedCap = (text) => { const value = parseFrontmatter(text)?.maxLines; const cap = value ? Number(value) : NaN; return Number.isNaN(cap) ? undefined : cap; };
|
|
258
258
|
|
|
259
|
-
const
|
|
259
|
+
const readDeployedByPath = () => new Map(readDeployedScripts().map((entry) => [entry.path, entry]));
|
|
260
260
|
const RELATIVE_IMPORT = /(?:\bfrom\s*|\bimport\s*\(?\s*)['"](\.{1,2}\/[^'"]+)['"]/g;
|
|
261
261
|
const pathIn = (root, rel) => join(root, ...rel.split('/'));
|
|
262
262
|
|
|
263
263
|
// The one reading of the family's bundled imports, shared by the index, scripts and specs ops: the deployed
|
|
264
264
|
// manifest paths `bundle` (the bytes at manifest path `path`) imports by a relative specifier.
|
|
265
265
|
export const bundledImportsOf = (path, bundle) => [...String(bundle).matchAll(RELATIVE_IMPORT)]
|
|
266
|
-
.map(([, spec]) => posix.join(posix.dirname(path), spec)).filter((dep) =>
|
|
266
|
+
.map(([, spec]) => posix.join(posix.dirname(path), spec)).filter((dep) => readDeployedByPath().has(dep));
|
|
267
267
|
// Each of `files` ({ path, imports }) after every one of them it imports, by manifest path in code-unit order
|
|
268
268
|
// otherwise, so each file a run leaves loads. A cycle is a broken bundle, never a silent order.
|
|
269
269
|
export const dependenciesFirst = (files) => {
|
|
@@ -281,10 +281,10 @@ export const dependenciesFirst = (files) => {
|
|
|
281
281
|
// The modules the project's hook loads, the checker first: the deployed files of the docs-size and
|
|
282
282
|
// spec-schema modules, and the shared files the checker reaches through its bundled relative imports.
|
|
283
283
|
const hookModulesOf = (bundleOf) => {
|
|
284
|
-
const reached = new Set([
|
|
285
|
-
for (const path of reached) for (const dep of bundledImportsOf(path, bundleOf(
|
|
284
|
+
const reached = new Set([readChecker().path]);
|
|
285
|
+
for (const path of reached) for (const dep of bundledImportsOf(path, bundleOf(readDeployedByPath().get(path)).bytes ?? '')) reached.add(dep);
|
|
286
286
|
const loaded = ({ module, path }) => module === 'docs-size' || module === 'spec-schema' || (module === 'shared' && reached.has(path));
|
|
287
|
-
return [
|
|
287
|
+
return [readChecker(), ...readDeployedScripts().filter((entry) => entry !== readChecker() && loaded(entry))];
|
|
288
288
|
};
|
|
289
289
|
|
|
290
290
|
// A regular file where a folder on the way belongs (ENOTDIR) holds no module.
|
|
@@ -293,12 +293,12 @@ const probeHookModule = (cwd, entry, lstat) => { try { return probeSeedTarget(pa
|
|
|
293
293
|
// → one { rel, state } per hook module: absent, wrong-kind, bundle-unreadable or the classifier's word.
|
|
294
294
|
// No deployed checker → that one entry, absent; every kind is probed before any project file is read.
|
|
295
295
|
const surveyHook = (cwd, kitRoot, read, lstat) => {
|
|
296
|
-
const checker = probeHookModule(cwd,
|
|
297
|
-
if (checker.wrongKind || !checker.present) return [{ rel:
|
|
296
|
+
const checker = probeHookModule(cwd, readChecker(), lstat);
|
|
297
|
+
if (checker.wrongKind || !checker.present) return [{ rel: readChecker().deployed, state: checker.wrongKind ? 'wrong-kind' : 'absent', wrongKind: checker.wrongKind }];
|
|
298
298
|
const bundles = new Map();
|
|
299
299
|
const readBundle = (entry) => { try { return { bytes: read(pathIn(kitRoot, entry.bundled)) }; } catch (err) { return { error: causeOf(err) }; } };
|
|
300
300
|
const bundleOf = (entry) => (bundles.has(entry.path) ? bundles : bundles.set(entry.path, readBundle(entry))).get(entry.path);
|
|
301
|
-
const probes = hookModulesOf(bundleOf).map((entry) => ({ entry, rel: entry.deployed, probe: entry ===
|
|
301
|
+
const probes = hookModulesOf(bundleOf).map((entry) => ({ entry, rel: entry.deployed, probe: entry === readChecker() ? checker : probeHookModule(cwd, entry, lstat) }));
|
|
302
302
|
const wrong = probes.find(({ probe }) => probe.wrongKind);
|
|
303
303
|
if (wrong) return [{ rel: wrong.rel, state: 'wrong-kind', wrongKind: wrong.probe.wrongKind }];
|
|
304
304
|
return probes.map(({ entry, rel, probe }) => {
|
|
@@ -310,7 +310,7 @@ const surveyHook = (cwd, kitRoot, read, lstat) => {
|
|
|
310
310
|
};
|
|
311
311
|
|
|
312
312
|
const judgeKept = ({ cwd, spawn, read, lstat, deps }) => {
|
|
313
|
-
const result = spawn(process.execPath, [pathIn(cwd,
|
|
313
|
+
const result = spawn(process.execPath, [pathIn(cwd, readChecker().deployed), '--check-index'], { cwd, encoding: 'utf8', timeout: deps.keptProbeTimeoutMs ?? KEPT_PROBE_TIMEOUT_MS, killSignal: 'SIGKILL' });
|
|
314
314
|
if (result.error) return { error: `${causeOf(result.error)}${result.signal ? `, killed on signal ${result.signal}` : ''}` };
|
|
315
315
|
if (result.status !== 0) return { accepted: false, said: describeExitWithOutput(result), half: 'its index check' };
|
|
316
316
|
const text = lstatNoFollow(join(cwd, INDEX_REL), lstat)?.isFile() ? String(read(join(cwd, INDEX_REL), 'utf8')) : null;
|
|
@@ -340,15 +340,15 @@ const putBackIndex = (cwd, found, deps) => {
|
|
|
340
340
|
|
|
341
341
|
const ensureKeptIndex = ({ cwd, drive, spawn, read, lstat, deps }) => {
|
|
342
342
|
const judge = () => judgeKept({ cwd, spawn, read, lstat, deps });
|
|
343
|
-
const reportUnanswered = (verdict, after) => loud('index', 'index-probe-failed', `${INDEX_REL}: ${
|
|
343
|
+
const reportUnanswered = (verdict, after) => loud('index', 'index-probe-failed', `${INDEX_REL}: ${describeKeptJudge()} could not be launched or did not answer in time (${verdict.error}) — ${after}`);
|
|
344
344
|
const first = judge();
|
|
345
345
|
if (first.error) return reportUnanswered(first, 'nothing was written');
|
|
346
|
-
if (first.accepted) return ok('index', 'already-current', `${INDEX_REL}: ${
|
|
346
|
+
if (first.accepted) return ok('index', 'already-current', `${INDEX_REL}: ${describeKeptFits()} — nothing written`);
|
|
347
347
|
const found = lstatNoFollow(join(cwd, INDEX_REL), lstat) === null ? null : read(join(cwd, INDEX_REL));
|
|
348
348
|
const restored = found === null ? 'the navigator was put back: found absent, it was removed again' : 'the navigator was put back byte for byte';
|
|
349
349
|
const restoreThen = (failure, compose) => {
|
|
350
350
|
const refused = putBackIndex(cwd, found, deps);
|
|
351
|
-
return refused === null ? compose() : loud('index', 'write-refused', `${INDEX_REL}: putting the navigator back failed (${refused})${failure ? ` after ${failure}` : ''} — a navigator ${
|
|
351
|
+
return refused === null ? compose() : loud('index', 'write-refused', `${INDEX_REL}: putting the navigator back failed (${refused})${failure ? ` after ${failure}` : ''} — a navigator ${describeKeptJudge()} rejects may stand; re-read it before re-running`);
|
|
352
352
|
};
|
|
353
353
|
const run = drive('--ensure-index');
|
|
354
354
|
const refusal = String(run.stderr ?? '').match(ENSURE_INDEX_REFUSAL);
|
|
@@ -359,19 +359,19 @@ const ensureKeptIndex = ({ cwd, drive, spawn, read, lstat, deps }) => {
|
|
|
359
359
|
}
|
|
360
360
|
let second;
|
|
361
361
|
try { second = judge(); } catch (err) { return restoreThen(`the navigator could not be read back (${causeOf(err)})`, () => loud('index', 'unexpected-error', `${INDEX_REL}: the navigator could not be read back after the bundled write (${causeOf(err)}) — ${restored}`)); }
|
|
362
|
-
if (second.error) return restoreThen(`${
|
|
363
|
-
if (second.accepted) return ok('index', 'regenerated', `${INDEX_REL}: written by the bundled generator — ${
|
|
364
|
-
return restoreThen(null, () => ok('index', 'customized-preserved', `${INDEX_REL}: ${
|
|
362
|
+
if (second.error) return restoreThen(`${describeKeptJudge()} could not answer (${second.error})`, () => reportUnanswered(second, restored));
|
|
363
|
+
if (second.accepted) return ok('index', 'regenerated', `${INDEX_REL}: written by the bundled generator — ${describeKeptFits()}`);
|
|
364
|
+
return restoreThen(null, () => ok('index', 'customized-preserved', `${INDEX_REL}: ${describeKeptJudge()} rejected the bundled render on ${second.half} (${second.said}), and the navigator as found did not pass it either (${first.half}) — ${restored}. The route: ${KEPT_ROUTE}`));
|
|
365
365
|
};
|
|
366
366
|
|
|
367
367
|
const buildKeptDryRunNote = (hook) =>
|
|
368
|
-
`a module the project's hook loads (${hook.filter((entry) => entry.state !== 'current').map((entry) => entry.rel).join(', ')}) is not the bundled one: unless the spec-layer step of this run first refreshes every such module, the real run judges the navigator by ${
|
|
368
|
+
`a module the project's hook loads (${hook.filter((entry) => entry.state !== 'current').map((entry) => entry.rel).join(', ')}) is not the bundled one: unless the spec-layer step of this run first refreshes every such module, the real run judges the navigator by ${describeKeptJudge()} and puts back a write it rejects`;
|
|
369
369
|
|
|
370
370
|
export const ensureIndex = ({ cwd, kitRoot, dryRun = false, deps = {} }) => {
|
|
371
371
|
const lstat = deps.lstat ?? lstatSync;
|
|
372
372
|
const read = deps.readFile ?? readFileSync;
|
|
373
373
|
const spawn = deps.spawnSync ?? spawnSync;
|
|
374
|
-
const generator = pathIn(kitRoot,
|
|
374
|
+
const generator = pathIn(kitRoot, readChecker().bundled);
|
|
375
375
|
const drive = (mode) => spawn(process.execPath, [generator, mode, `--root=${cwd}`], { encoding: 'utf8' });
|
|
376
376
|
const unlaunchable = (result) =>
|
|
377
377
|
loud('index', 'generator-unlaunchable', `${INDEX_REL}: the bundled generator could not be started, so nothing was probed or written — reinstall the kit. ${causeOf(result.error)}`);
|