@sabaiway/agent-workflow-kit 23.10.0 → 23.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- package/README.md +1 -1
- package/SKILL.md +1 -1
- package/bridges/codex-cli-bridge/SKILL.md +5 -5
- package/bridges/codex-cli-bridge/bin/codex-exec-jev.test.mjs +3 -2
- package/bridges/codex-cli-bridge/bin/codex-exec.sh +6 -6
- package/bridges/codex-cli-bridge/bin/codex-exec.test.mjs +5 -5
- package/bridges/codex-cli-bridge/bin/codex-model-posture.test.mjs +29 -29
- package/bridges/codex-cli-bridge/bin/codex-review-jev.test.mjs +3 -2
- package/bridges/codex-cli-bridge/bin/codex-review.sh +6 -6
- package/bridges/codex-cli-bridge/bin/codex-review.test.mjs +6 -6
- package/bridges/codex-cli-bridge/capability.json +4 -4
- package/bridges/codex-cli-bridge/references/driving-codex.md +1 -1
- package/bridges/codex-cli-bridge/references/sandbox-and-flags.md +2 -2
- package/bridges/codex-cli-bridge/setup/README.md +1 -1
- package/capability.json +1 -1
- package/package.json +1 -1
- package/references/modes/bridge-settings.md +2 -2
- package/references/modes/control-bytes.md +38 -32
- package/references/modes/recommendations.md +1 -1
- package/tools/advisor-matrix.mjs +2 -1
- package/tools/advisor-skip/index.mjs +73 -0
- package/tools/control-bytes.mjs +43 -20
- package/tools/doc-parity/index.mjs +46 -0
- package/tools/doc-parity.mjs +27 -47
- package/tools/recommendations.mjs +6 -6
- package/tools/release-scan/index.mjs +30 -0
- package/tools/release-scan.mjs +46 -25
- package/tools/sandbox-masks.mjs +6 -4
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
"schema": 1,
|
|
4
4
|
"name": "codex-cli-bridge",
|
|
5
5
|
"kind": "execution-backend",
|
|
6
|
-
"version": "6.0
|
|
7
|
-
"posture": { "model": "gpt-6.
|
|
6
|
+
"version": "6.1.0",
|
|
7
|
+
"posture": { "model": "gpt-6.2-sol", "effort": "high", "tier": null },
|
|
8
8
|
"provides": ["execute", "review"],
|
|
9
9
|
"roles": {
|
|
10
10
|
"execute": {
|
|
@@ -190,7 +190,7 @@
|
|
|
190
190
|
{
|
|
191
191
|
"key": "CODEX_MODEL",
|
|
192
192
|
"kind": "posture",
|
|
193
|
-
"default": "gpt-6.
|
|
193
|
+
"default": "gpt-6.2-sol",
|
|
194
194
|
"appliesTo": ["codex-exec", "codex-review"],
|
|
195
195
|
"effect": "the codex model every run uses (the host posture); a set value is checked against the installed codex's catalog first. /agent-workflow-kit bridge-settings shows the models offered."
|
|
196
196
|
},
|
|
@@ -207,7 +207,7 @@
|
|
|
207
207
|
"values": ["priority"],
|
|
208
208
|
"default": null,
|
|
209
209
|
"appliesTo": ["codex-exec", "codex-review"],
|
|
210
|
-
"effect": "codex service tier; 'priority' (catalog display name Fast) = \"2x speed, increased usage\" in the codex catalog's own words for gpt-6.
|
|
210
|
+
"effect": "codex service tier; 'priority' (catalog display name Fast) = \"2x speed, increased usage\" in the codex catalog's own words for gpt-6.2-sol (cache fetched 2026-11-18); it states no credit-rate figure — quality-neutral (same model). Unset/empty ⇒ no service_tier flag (standard tier). SPEND KNOB: enabling it is a consented per-host act, never a default. codex itself accepts any -c service_tier string silently, so the wrapper validates the value."
|
|
211
211
|
},
|
|
212
212
|
{
|
|
213
213
|
"key": "CODEX_HARD_TIMEOUT",
|
|
@@ -21,7 +21,7 @@ judgment.
|
|
|
21
21
|
## Model & effort: the host posture
|
|
22
22
|
|
|
23
23
|
Delegated codex work runs on the host posture: `CODEX_MODEL` / `CODEX_EFFORT` from the bridge settings
|
|
24
|
-
file, else the built-in default `gpt-6.
|
|
24
|
+
file, else the built-in default `gpt-6.2-sol` / `high`, checked against the installed CLI's catalog
|
|
25
25
|
before any spend. `/agent-workflow-kit bridge-settings` shows the models the installed codex offers and
|
|
26
26
|
sets the host posture. An environment value off the host posture is a one-off and is **refused** (exit 2)
|
|
27
27
|
with the settings-file remedy unless `CODEX_PROBE=1` — do not "tune down" the model or effort per call;
|
|
@@ -78,7 +78,7 @@ failure is proven.
|
|
|
78
78
|
## Host posture (model & effort)
|
|
79
79
|
|
|
80
80
|
The wrappers run on the host posture: `CODEX_MODEL` / `CODEX_EFFORT` from the bridge settings file, else
|
|
81
|
-
the built-in default `gpt-6.
|
|
81
|
+
the built-in default `gpt-6.2-sol` / `high`, checked pre-spend against the installed CLI's catalog
|
|
82
82
|
(`codex debug models`); `/agent-workflow-kit bridge-settings` shows the models offered and sets one. A model or effort the catalog does not offer, and an environment value off the
|
|
83
83
|
host posture (a one-off), are **refused** (exit 2, loud) with the settings-file remedy; a weaker model
|
|
84
84
|
is the user's choice in the setting, never a per-call downgrade. (Whether the default is the strongest
|
|
@@ -240,7 +240,7 @@ exec` over the precomputed diff instead, keeping every invariant intact.
|
|
|
240
240
|
| `-o, --output-last-message <f>` | write ONLY the final message (clean capture) |
|
|
241
241
|
| `--json` | structured event stream (`thread.started` ⇒ session id) |
|
|
242
242
|
| `--output-schema <f>` | constrain output to a JSON schema (`CODEX_REVIEW_SCHEMA=1`) |
|
|
243
|
-
| `-m <model>` | model (the host posture: the `CODEX_MODEL` setting, else `gpt-6.
|
|
243
|
+
| `-m <model>` | model (the host posture: the `CODEX_MODEL` setting, else `gpt-6.2-sol`) |
|
|
244
244
|
| `-c model_reasoning_effort=<effort>` | reasoning effort (the host posture: the `CODEX_EFFORT` setting, else `high`) |
|
|
245
245
|
| `codex debug models` | the model catalog as JSON `models[]` (`slug`, `visibility`, `priority`, `supported_reasoning_levels`, `default_reasoning_level`) — the wrappers' pre-spend check; reads no stdin (probed on 0.160.0) |
|
|
246
246
|
| `--ignore-user-config` | do NOT load `$CODEX_HOME/config.toml`; auth still uses `CODEX_HOME` |
|
|
@@ -74,7 +74,7 @@ if it reports a missing git work tree or root `AGENTS.md`, run it from a project
|
|
|
74
74
|
0.160.0 or newer, off a codex version and profile digest recorded as refused and, for `codex-exec`, from
|
|
75
75
|
a repository outside every temp root, both carry the permissions profile `jev`, whose network reaches the run hosts its service-facts.txt
|
|
76
76
|
lists; elsewhere the network stays off. They also run on the host posture — `CODEX_MODEL` / `CODEX_EFFORT` from the
|
|
77
|
-
bridge settings file, else `gpt-6.
|
|
77
|
+
bridge settings file, else `gpt-6.2-sol` / `high` — checked against the installed CLI's catalog,
|
|
78
78
|
and refuse a one-off model or effort unless `CODEX_PROBE=1` (see `../SKILL.md`), enforce a hard
|
|
79
79
|
timeout, capture only codex's final message, and block codex from writing git via a shim — see
|
|
80
80
|
[`../references/sandbox-and-flags.md`](../references/sandbox-and-flags.md) and the knob table in
|
package/capability.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sabaiway/agent-workflow-kit",
|
|
3
|
-
"version": "23.
|
|
3
|
+
"version": "23.12.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",
|
|
@@ -8,11 +8,11 @@ The reader + consent-gated **writer** for the **host-level** bridge settings fil
|
|
|
8
8
|
|
|
9
9
|
| key | bridge | values | note |
|
|
10
10
|
|---|---|---|---|
|
|
11
|
-
| `CODEX_MODEL` | codex | a model the installed codex offers | the host posture's model; default `gpt-6.
|
|
11
|
+
| `CODEX_MODEL` | codex | a model the installed codex offers | the host posture's model; default `gpt-6.2-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
14
|
| `JEV_MODEL` | the judge | a version its manifest offers | the judge's model; default the manifest's `posture.model`. |
|
|
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.
|
|
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.2-sol (cache fetched 2026-11-18); it states no credit-rate figure; quality-neutral (same model). Default unset ⇒ standard tier. |
|
|
16
16
|
| `CODEX_HARD_TIMEOUT` | codex | integer `1..86400` | hard wall-clock cap (seconds) via `timeout(1)`. |
|
|
17
17
|
| `CODEX_REVIEW_MAX_TOTAL_BYTES` | codex | integer `1..100000000` | codex-review payload size above which the diff rides a temp file (never truncated). |
|
|
18
18
|
| `AGY_HARD_TIMEOUT` | agy | duration `5m`/`30m`/`90s` (unit required, nonzero) | hard wall-clock cap via `timeout(1)`. |
|
|
@@ -19,8 +19,9 @@ any byte in 0x00–0x08, 0x0B, 0x0C, 0x0E–0x1F or 0x7F refuses; TAB, LF and CR
|
|
|
19
19
|
bytes; bytes at or above 0x80 are not judged (UTF-8 validity and C1 controls are not this tool's
|
|
20
20
|
business). A finding names the path, the surface, the byte offset and the byte in hex; the render is
|
|
21
21
|
injective — bytes decode as UTF-8 where valid, a control or line-separator code point (and a valid
|
|
22
|
-
U+FFFD) renders as `\u{XXXX}`, an invalid byte as `\xNN`, a backslash as `\\` — so no
|
|
23
|
-
byte or U+FFFD
|
|
22
|
+
U+FFFD) renders as `\u{XXXX}`, an invalid byte as `\xNN`, a backslash as `\\` — so no line `main` returns carries a
|
|
23
|
+
raw control byte or U+FFFD (the guard's error block keeps the error's first line and stack as they are) and two
|
|
24
|
+
names differing only in an unrenderable byte render differently.
|
|
24
25
|
|
|
25
26
|
**Binary by KIND, never by guess.** A path whose git attribute says `binary` or `-diff` has its
|
|
26
27
|
CONTENT skipped by kind and is NAMED in the summary (one `git check-attr --stdin -z binary diff`
|
|
@@ -36,35 +37,40 @@ kind and counted — name judged, no content surface. On a host that materialise
|
|
|
36
37
|
Run `node ${CLAUDE_SKILL_DIR}/tools/control-bytes.mjs [--check] [--cwd <dir>]` (`--cwd` anchors at
|
|
37
38
|
that directory's work-tree root):
|
|
38
39
|
|
|
39
|
-
1. Plain run → the
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
`
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
40
|
+
1. Plain run → clean: the report (the work-tree root; paths judged · skipped by attribute · skipped by
|
|
41
|
+
kind · findings; one `skipped by attribute: <path>` line per such path). Red: ONE block on standard
|
|
42
|
+
output, nothing on standard error, under the SAME exit table as `--check` (never a silent 0): the
|
|
43
|
+
verdict line `control-bytes: FAIL —` naming each class present, with counts for control-byte findings
|
|
44
|
+
and paths not judged, each finding `<path>: <surface> offset <n>: 0x<hex>` (`(+N more)` for more), each
|
|
45
|
+
path not judged `<path>: <why>`, one `control-bytes: REMEDY —` line per class, then the report; the work
|
|
46
|
+
tree not judged stands alone (step 2: no count, nothing after its remedy). A path that is no plain place
|
|
47
|
+
(escaped, holding a colon, opening with a space, with an empty, `.` or `..` segment, equal to `control-bytes`, or matching the text before `: ` on a report line) stands at `.`, the path leading its text.
|
|
48
|
+
2. **`--check`** → the gate spelling: the same output, then the gate exit code. **Exit 0** clean.
|
|
49
|
+
**Exit 1** on a finding OR on a refusal — refusals never pass and never skip silently, each with its
|
|
50
|
+
own message; a failed git query, an unmerged index, an empty domain or a location that is no work
|
|
51
|
+
tree is the work tree not judged: one finding at `.` carrying the message, one remedy line, nothing
|
|
52
|
+
after. The refusals: an UNREADABLE path (EACCES, EIO, a descriptor whose kind disagrees with the
|
|
53
|
+
named kind — distinct from an ABSENT path git named that vanished before the read; a TRACKED absent
|
|
54
|
+
path with the skip-worktree bit is a sparse checkout, skipped by kind and counted); a git command
|
|
55
|
+
that fails, is killed by a signal or is not on PATH; an UNMERGED index; an EMPTY domain; a file over
|
|
56
|
+
the read cap (16 MiB — read as at most cap+1 bytes on the descriptor, never trusting the fstat size,
|
|
57
|
+
so a file that grows after the fstat still refuses; the message names the cap and the path); a git
|
|
58
|
+
LOCATION that is not a work tree. The location is a closed table of six states shared with the
|
|
59
|
+
fingerprint and index consumers through the kit's git-location leaf, judged on the REALPATH identity
|
|
60
|
+
of the git dir, the common dir and the work-tree top under the ambient env against the discovery
|
|
61
|
+
from cwd with every variable whose upper-cased name starts with `GIT_` removed (a case-insensitive
|
|
62
|
+
host honours `git_dir` too): `work-tree` (all three agree) proceeds; `not-a-repository` (git itself
|
|
63
|
+
answers not-a-git-repository, exit 128); `error` (ENOENT, a synchronous throw, a signal, a realpath
|
|
64
|
+
that cannot resolve, any other non-zero or unparsable answer); `redirected` (any of the three
|
|
65
|
+
differs — `GIT_WORK_TREE` at a second tree with the same git dir, or `GIT_COMMON_DIR` at a second
|
|
66
|
+
repository); `no-work-tree` (the git dir agrees but `--show-toplevel` fails: bare, or cwd inside
|
|
67
|
+
`.git`); `env-only` (the ambient env reaches a repository the stripped discovery does not) — each
|
|
68
|
+
refuses by its own state name. A pre-commit hook's own env (`GIT_INDEX_FILE`, `GIT_PREFIX`,
|
|
69
|
+
`GIT_CONFIG_PARAMETERS`, `GIT_EXEC_PATH`) agrees and passes: the check is agreement, never a variable
|
|
70
|
+
ban. **Exit 2** usage — every operand is validated at parse; an unknown argument is usage: the verdict
|
|
71
|
+
line names what was wrong, then the usage text. An error the tool does not answer for prints the
|
|
72
|
+
guard's block (the verdict line naming the error, the remedy line, the stack), exit 1. Every content
|
|
73
|
+
read is descriptor-bound (open, fstat, read on the descriptor), never a path a symlink swap redirects.
|
|
68
74
|
3. **Declare it as a gate — never without consent (AD-021/D9).** `node
|
|
69
75
|
${CLAUDE_SKILL_DIR}/tools/checker-gates.mjs --cwd <project> --only control-bytes --apply` writes
|
|
70
76
|
this one entry while the kit offers it; without `--only control-bytes --apply` the same command
|
|
@@ -79,7 +85,7 @@ that directory's work-tree root):
|
|
|
79
85
|
**Honest bounds (stated, accepted):** the work tree is judged at the moment of the read — a byte
|
|
80
86
|
written after the run is caught on the next run, which is why the gate belongs in the pre-commit
|
|
81
87
|
matrix; the attribute is the only "binary" signal, so a binary file with no attribute refuses until
|
|
82
|
-
the project declares it; the tool reports and never edits
|
|
88
|
+
the project declares it; the tool reports and never edits; a
|
|
83
89
|
checkout PATH that is itself not valid UTF-8 is unreachable by any Node consumer (cwd is a string
|
|
84
90
|
before git ever answers) and a non-UTF-8 LINKED git dir or common dir path refuses as `error` — a
|
|
85
91
|
stated bound, not a case this tool judges; `O_NOFOLLOW` guards the
|
|
@@ -16,7 +16,7 @@ host/session facts* in `${CLAUDE_SKILL_DIR}/references/shared/report-footer.md`.
|
|
|
16
16
|
Run `node ${CLAUDE_SKILL_DIR}/tools/recommendations.mjs --cwd <project-root> [--json]`:
|
|
17
17
|
|
|
18
18
|
1. **`--cwd` is REQUIRED** — the target project is explicit, never inferred from the shell's current directory (a subdirectory invocation still advises on the named root).
|
|
19
|
-
2. **Verdict first (present-even-when-empty, opening at the `## Recommendations (agent-workflow)` header).** With everything optimal the body is exactly `no recommendations — flow optimal.` — the empty-state line ALONE is the verdict, zero added lines. Every other state opens the body with ONE verdict line composed from the frozen templates: `{K} item(s) need attention` leads when any item's severity is `attention` (a CONFIGURED declaration that is broken, drifted, degrading or invalid — the deployment needs review); `{N} optional recommendation(s), apply any you want` covers the `optional` class (offers to enable an unconfigured capability), led by `nothing is broken` ONLY when no item needs attention AND no probe check was skipped (a skipped probe could hide an attention-class problem — the claim never overreaches); `optimality NOT attested — {M} probe check(s) skipped` is appended last whenever probe checks were skipped. A kit item counts in neither class (applied with no pick): with only kit items and no skip the verdict is `nothing is broken` alone. (The `(s)` invariant form IS the pinned pluralization — no singular/plural branching.) Items render attention-first, each tagged `needs attention:` / `optional:`. A failed probe renders as a stated `⚠ skipped item …` line
|
|
19
|
+
2. **Verdict first (present-even-when-empty, opening at the `## Recommendations (agent-workflow)` header).** With everything optimal the body is exactly `no recommendations — flow optimal.` — the empty-state line ALONE is the verdict, zero added lines. Every other state opens the body with ONE verdict line composed from the frozen templates: `{K} item(s) need attention` leads when any item's severity is `attention` (a CONFIGURED declaration that is broken, drifted, degrading or invalid — the deployment needs review); `{N} optional recommendation(s), apply any you want` covers the `optional` class (offers to enable an unconfigured capability), led by `nothing is broken` ONLY when no item needs attention AND no probe check was skipped (a skipped probe could hide an attention-class problem — the claim never overreaches); `optimality NOT attested — {M} probe check(s) skipped` is appended last whenever probe checks were skipped. A kit item counts in neither class (applied with no pick): with only kit items and no skip the verdict is `nothing is broken` alone. (The `(s)` invariant form IS the pinned pluralization — no singular/plural branching.) Items render attention-first, each tagged `needs attention:` / `optional:`. A failed probe renders as a stated `⚠ skipped item …` line, never a crash or a fabricated item; if the line lost anything, its whole reason follows on `|` lines: relay all.
|
|
20
20
|
3. **The apply-through-agent lane — an explicit informed-consent checkpoint:** the agent applies chat and harness items on the chat yes, harness items by the consent route below, and kit items with no question by the kit route below. A chat item is never retried outside the sandbox and every failure of a chat step is a STOP. A user item is the user's own step, handed over as worded with its posture note (e.g. `source-size.id-squatter`). After presenting, OFFER to apply; the user selects items in plain language; for each selected item you **surface its posture note inline** where one exists (the per-item notes below cover exactly the risk-marked keys). For a chat item: the user **explicitly confirms**, and **only then** — **no command runs before confirmation** — do you run the rendered command. Do NOT infer safety from the presence or absence of an `--apply` flag: most chat items' rendered command IS the mutation and completes on that one run, **including a no-`--apply` mutation** such as `spec-adoption`'s `ensure-configs --reconcile --only specs` (it writes an edited spec-layer file with the bundled body with no question, its line naming where an edit meant to last goes). Some items instead render a **dry-run preview** that changes nothing and prints an explicit follow-up `--apply`/mutating command to run NEXT (e.g. the `gates-declaration` seeder): after the SAME confirmation you run that printed follow-up command — no second ask, no improvisation (each writer keeps its own consent semantics: previews, `--apply` flags, refusals) — except profile-gap, whose apply line runs with --apply appended only on a second yes over the relayed preview. For `worktrees-dir` you apply the grant on the chat yes after its check, like every harness item, with no hand step to wait for; its `recipe:` line's `ack-write` preview is the ack fallback, run only on the user's word that the host ignores the settings key, instead of the grant, and against a trusted host NO no ack renders.
|
|
21
21
|
4. Registry strings (benefits + item texts) are frozen tool data, fact-true, ONE line under the pinned shape cap — posture/risk detail lives in the notes below at the consent moment, never inline in the overview. The dual velocity+security wording (`safer — blast radius bounded by the OS sandbox, not human attention`) rides ONLY the items with a real security delta (the autonomy render, the sandbox provisioning); the bridge-wrappers item claims **velocity only**.
|
|
22
22
|
|
package/tools/advisor-matrix.mjs
CHANGED
|
@@ -32,7 +32,8 @@ export const ADVISOR_MATRIX_DOC = 'references/modes/dispatch.md';
|
|
|
32
32
|
export const ADVISOR_MATRIX_BEGIN = '<!-- advisor-matrix:begin -->';
|
|
33
33
|
export const ADVISOR_MATRIX_END = '<!-- advisor-matrix:end -->';
|
|
34
34
|
|
|
35
|
-
export const
|
|
35
|
+
export const resolveKitDoc = (rel) => resolve(KIT_ROOT, rel);
|
|
36
|
+
export const readKitDoc = (rel) => readFileSync(resolveKitDoc(rel), 'utf8');
|
|
36
37
|
|
|
37
38
|
// Both line endings are ordinary here. Splitting on '\n' alone leaves a trailing '\r' on every line
|
|
38
39
|
// of a CRLF-authored doc, and the marker match survives it (it trims) while the exact header match
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Contract: docs/ai/specs/kit/advisor-skip.md
|
|
2
|
+
import { isLineUnsafe, jsonForLine } from '../source-size-refusal.mjs';
|
|
3
|
+
|
|
4
|
+
export const SKIP_REASON_CAP = 200;
|
|
5
|
+
|
|
6
|
+
const EMPTY = '';
|
|
7
|
+
const SPACE = ' ';
|
|
8
|
+
const LINE_BREAK = /\r\n|\r|\n/u;
|
|
9
|
+
const UNPRINTABLE_REASON = 'unprintable error value';
|
|
10
|
+
const WHOLE_REASON_FOLLOWS = 'the whole reason follows';
|
|
11
|
+
const FOLD_NOTE = ` (${WHOLE_REASON_FOLLOWS})`;
|
|
12
|
+
const CUT_NOTE_START = '\u2026 (+';
|
|
13
|
+
const CUT_NOTE_END = ` more chars; ${WHOLE_REASON_FOLLOWS})`;
|
|
14
|
+
const SKIP_LEAD = ' \u26a0 skipped item ';
|
|
15
|
+
const PROBE_FAILED = ' \u2014 probe failed: ';
|
|
16
|
+
const CONTINUATION_LEAD = ' |';
|
|
17
|
+
const START_INDEX = 0;
|
|
18
|
+
const NEXT_INDEX_OFFSET = 1;
|
|
19
|
+
const LAST_INDEX = -1;
|
|
20
|
+
const NOT_FOUND = -1;
|
|
21
|
+
|
|
22
|
+
const readErrorText = (error) => {
|
|
23
|
+
try {
|
|
24
|
+
return String(error?.message ?? error);
|
|
25
|
+
} catch {
|
|
26
|
+
return UNPRINTABLE_REASON;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const escapeCodePoint = (codePoint) => isLineUnsafe(codePoint)
|
|
31
|
+
? jsonForLine(codePoint).slice(NEXT_INDEX_OFFSET, LAST_INDEX)
|
|
32
|
+
: codePoint;
|
|
33
|
+
|
|
34
|
+
const escapeLine = (line) => Array.from(line, escapeCodePoint).join(EMPTY);
|
|
35
|
+
const hasText = (line) => line.trim() !== EMPTY;
|
|
36
|
+
const formatCutNote = (droppedLength) => `${CUT_NOTE_START}${droppedLength}${CUT_NOTE_END}`;
|
|
37
|
+
|
|
38
|
+
const cutSummary = (summary, pieces) => {
|
|
39
|
+
const prefixLengths = [START_INDEX];
|
|
40
|
+
for (const piece of pieces.slice(START_INDEX, SKIP_REASON_CAP)) {
|
|
41
|
+
prefixLengths.push(prefixLengths.at(LAST_INDEX) + piece.length);
|
|
42
|
+
}
|
|
43
|
+
const prefixLength = prefixLengths.findLast((length) =>
|
|
44
|
+
length + formatCutNote(summary.length - length).length <= SKIP_REASON_CAP
|
|
45
|
+
) ?? START_INDEX;
|
|
46
|
+
return summary.slice(START_INDEX, prefixLength) + formatCutNote(summary.length - prefixLength);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const composeSkip = (key, error) => {
|
|
50
|
+
const lines = readErrorText(error).split(LINE_BREAK);
|
|
51
|
+
const firstLineIndex = lines.findIndex(hasText);
|
|
52
|
+
if (firstLineIndex === NOT_FOUND) return { key, reason: EMPTY };
|
|
53
|
+
|
|
54
|
+
const lastLineIndex = lines.findLastIndex(hasText);
|
|
55
|
+
const countingLines = lines.slice(firstLineIndex, lastLineIndex + NEXT_INDEX_OFFSET);
|
|
56
|
+
const trimmedLines = countingLines.map((line) => line.trim()).filter(Boolean);
|
|
57
|
+
const [, secondLine] = trimmedLines;
|
|
58
|
+
const isFolded = secondLine !== undefined;
|
|
59
|
+
const pieces = Array.from(trimmedLines.join(SPACE), escapeCodePoint);
|
|
60
|
+
const summary = pieces.join(EMPTY);
|
|
61
|
+
if (!isFolded && summary.length <= SKIP_REASON_CAP) return { key, reason: summary };
|
|
62
|
+
|
|
63
|
+
const reason = isFolded && summary.length + FOLD_NOTE.length <= SKIP_REASON_CAP
|
|
64
|
+
? summary + FOLD_NOTE
|
|
65
|
+
: cutSummary(summary, pieces);
|
|
66
|
+
const whole = countingLines.map((line) => hasText(line) ? escapeLine(line) : EMPTY);
|
|
67
|
+
return { key, reason, whole };
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const renderSkip = ({ key, reason, whole }) => [
|
|
71
|
+
`${SKIP_LEAD}${escapeLine(key)}${PROBE_FAILED}${reason}`,
|
|
72
|
+
...(whole?.map((entry) => entry === EMPTY ? CONTINUATION_LEAD : `${CONTINUATION_LEAD}${SPACE}${entry}`) ?? []),
|
|
73
|
+
];
|
package/tools/control-bytes.mjs
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
|
|
13
13
|
import { closeSync, constants as fsConstants, fstatSync, lstatSync, openSync, readSync, readlinkSync, realpathSync, statSync } from 'node:fs';
|
|
14
14
|
import { spawnSync } from 'node:child_process';
|
|
15
|
+
import { composeUsageRefusal } from '../references/scripts/shared/index.mjs';
|
|
16
|
+
import { composeCheckerBlock, runCheckerTail } from './checker-block/index.mjs';
|
|
15
17
|
import { isDirectRun } from './direct-run.mjs';
|
|
16
18
|
import { probeRegularFileNoFollow, readFileBytesNoFollowCapped } from './fs-read-nofollow.mjs';
|
|
17
19
|
import { GIT_MAX_BUFFER, parseIndexEntries, resolveGitLocation, withGitPath } from './git-env.mjs';
|
|
@@ -36,15 +38,25 @@ const USAGE = `usage: node control-bytes.mjs [--check] [--cwd <dir>]
|
|
|
36
38
|
--check the gate spelling; the plain run prints the same report and shares the exit table
|
|
37
39
|
exit 0 clean · 1 a finding or a refusal · 2 usage`;
|
|
38
40
|
|
|
41
|
+
const CHECKER_NAME = 'control-bytes';
|
|
42
|
+
const WORK_TREE_REMEDY = 'clear the cause the finding above names, then re-run';
|
|
43
|
+
const CONTROL_BYTE_REMEDY = 'rename each path whose name contains a refused byte, retarget each symlink whose target contains a refused byte, replace every refused byte in text content with an escape in source, and mark any affected binary file binary in .gitattributes, then re-run';
|
|
44
|
+
const PATH_REMEDY = 'settle each path above as its finding says, then re-run';
|
|
45
|
+
const UNEXPECTED_REMEDY = 'fix the cause the stack below names, then re-run';
|
|
46
|
+
|
|
39
47
|
const NUL = Buffer.from([0]);
|
|
40
48
|
const render = renderPathForDisplay;
|
|
41
49
|
// Every DYNAMIC diagnostic (a location cause, git stderr, an fs error code, a user argument) rides
|
|
42
50
|
// the same renderer as paths before it reaches a line — SAFE (never a raw byte or U+FFFD), while
|
|
43
51
|
// injectivity is promised for NAMES only: a string-originated diagnostic folds invalid bytes first.
|
|
44
52
|
const safe = (text) => render(Buffer.isBuffer(text) ? text : Buffer.from(String(text), 'utf8'));
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
53
|
+
const refuseWorkTree = (root, text) => ({ code: 1, lines: composeCheckerBlock({
|
|
54
|
+
name: CHECKER_NAME, root, failed: 'the work tree could not be judged',
|
|
55
|
+
findings: [{ path: '.', text }], remedies: [WORK_TREE_REMEDY],
|
|
56
|
+
}) });
|
|
57
|
+
const pathFinding = (path, text) => ({ path: render(path), text });
|
|
58
|
+
const absent = (path, tracked) => pathFinding(path, `absent (${tracked ? 'tracked but missing from the work tree — stage the deletion with git rm or git add -A, or it' : 'git named it, it'} vanished before the read)`);
|
|
59
|
+
const unreadable = (path, why) => pathFinding(path, `unreadable (${safe(why)})`);
|
|
48
60
|
const hexByte = (byte) => `0x${byte.toString(16).padStart(2, '0')}`;
|
|
49
61
|
const errorCode = (err) => err?.code ?? err?.message ?? String(err);
|
|
50
62
|
|
|
@@ -123,34 +135,34 @@ export const main = (argv, deps = {}) => {
|
|
|
123
135
|
const run = deps.spawn ?? spawnSync;
|
|
124
136
|
const env = deps.env ?? process.env;
|
|
125
137
|
const opts = parseArgs(argv, io);
|
|
126
|
-
if (opts.error) return { code: 2, lines:
|
|
138
|
+
if (opts.error) return { code: 2, lines: composeUsageRefusal({ name: CHECKER_NAME, failed: opts.error, usage: USAGE }) };
|
|
127
139
|
const cwd = opts.cwd ?? deps.cwd ?? process.cwd();
|
|
128
140
|
const location = resolveGitLocation(cwd, { spawn: run, env, realpath: io.realpath });
|
|
129
|
-
if (location.state !== 'work-tree') return
|
|
141
|
+
if (location.state !== 'work-tree') return refuseWorkTree(cwd, `the git location is ${location.state} — ${safe(location.cause)}`);
|
|
130
142
|
const top = location.top;
|
|
131
143
|
const git = (args, input, ok) => gitQuery(run, args, { cwd: top, env, input }, ok);
|
|
132
144
|
const tracked = git(TRACKED_ARGV);
|
|
133
|
-
if (tracked.failure) return
|
|
145
|
+
if (tracked.failure) return refuseWorkTree(top, tracked.failure);
|
|
134
146
|
const entries = parseIndexEntries(tracked.stdout);
|
|
135
147
|
const unmerged = entries.filter((e) => e.stage !== 0).length;
|
|
136
|
-
if (unmerged > 0) return
|
|
148
|
+
if (unmerged > 0) return refuseWorkTree(top, `the git index is UNMERGED (${unmerged} conflict-stage entr(ies)) — resolve the conflict, then re-run`);
|
|
137
149
|
const others = git(UNTRACKED_ARGV);
|
|
138
|
-
if (others.failure) return
|
|
150
|
+
if (others.failure) return refuseWorkTree(top, others.failure);
|
|
139
151
|
const domain = [...entries.map((e) => ({ path: e.path, mode: e.mode })), ...splitZ(others.stdout).map((path) => ({ path, mode: null }))]
|
|
140
152
|
.sort((a, b) => Buffer.compare(a.path, b.path));
|
|
141
|
-
if (domain.length === 0) return
|
|
153
|
+
if (domain.length === 0) return refuseWorkTree(top, `the domain is EMPTY — no tracked and no untracked-not-ignored path under ${render(Buffer.from(top))}`);
|
|
142
154
|
const attributes = git(ATTRIBUTES_ARGV, Buffer.concat(domain.flatMap((d) => [d.path, NUL])));
|
|
143
|
-
if (attributes.failure) return
|
|
155
|
+
if (attributes.failure) return refuseWorkTree(top, attributes.failure);
|
|
144
156
|
const skipByAttribute = attributeSkips(attributes.stdout);
|
|
145
157
|
// core.symlinks: exit 1 = unset = git's default (true); `false` = the host materialises a tracked
|
|
146
158
|
// symlink as a regular file holding the target bytes — refusing it there would refuse forever.
|
|
147
159
|
const symlinks = git(SYMLINKS_ARGV, undefined, [0, 1]);
|
|
148
|
-
if (symlinks.failure) return
|
|
160
|
+
if (symlinks.failure) return refuseWorkTree(top, symlinks.failure);
|
|
149
161
|
const symlinksMaterialised = symlinks.stdout.toString('utf8').trim() === 'false';
|
|
150
162
|
// Sparse checkouts: a tracked path whose skip-worktree bit is set (`ls-files -v`, a tag that
|
|
151
163
|
// uppercases to S — core-evidence's rule) may be ABSENT by design: a counted skip, never a refusal.
|
|
152
164
|
const sparse = git(SPARSE_ARGV);
|
|
153
|
-
if (sparse.failure) return
|
|
165
|
+
if (sparse.failure) return refuseWorkTree(top, sparse.failure);
|
|
154
166
|
const sparseSkip = new Set();
|
|
155
167
|
for (const record of splitZ(sparse.stdout)) {
|
|
156
168
|
if (record.length > 2 && String.fromCharCode(record[0]).toUpperCase() === 'S') sparseSkip.add(record.subarray(2).toString('hex'));
|
|
@@ -168,7 +180,7 @@ export const main = (argv, deps = {}) => {
|
|
|
168
180
|
if (first === -1) first = i;
|
|
169
181
|
count += 1;
|
|
170
182
|
}
|
|
171
|
-
if (first !== -1) findings.push(
|
|
183
|
+
if (first !== -1) findings.push(pathFinding(path, `${surface} offset ${first}: ${hexByte(bytes[first])}${count > 1 ? ` (+${count - 1} more)` : ''}`));
|
|
172
184
|
};
|
|
173
185
|
// An ABSENT path: a sparse (skip-worktree) tracked one is a counted skip; every other refuses.
|
|
174
186
|
const settleAbsent = (path, tracked) => {
|
|
@@ -181,7 +193,7 @@ export const main = (argv, deps = {}) => {
|
|
|
181
193
|
if (read.bytes) judge(read.bytes, surface, path);
|
|
182
194
|
return true;
|
|
183
195
|
}
|
|
184
|
-
if (read.outcome === 'over-cap') refusals.push(
|
|
196
|
+
if (read.outcome === 'over-cap') refusals.push(pathFinding(path, `over the read cap (${READ_CAP} bytes) — the gate read cap+1 bytes on the descriptor and stopped; ${surface === 'content' ? 'declare the path binary in .gitattributes or shrink it' : 'restore the link or shorten its target'}`));
|
|
185
197
|
else if (read.outcome === 'absent') settleAbsent(path, tracked);
|
|
186
198
|
else if (read.outcome === 'foreign') refusals.push(unreadable(path, `a ${read.className} where git named a ${named}`));
|
|
187
199
|
else refusals.push(unreadable(path, read.code));
|
|
@@ -251,14 +263,25 @@ export const main = (argv, deps = {}) => {
|
|
|
251
263
|
`control-bytes: work tree ${render(Buffer.from(top))}`,
|
|
252
264
|
`paths judged: ${domain.length} · skipped by attribute: ${skippedByAttribute.length} · skipped by kind: ${skippedByKind} · findings: ${findings.length}`,
|
|
253
265
|
...skippedByAttribute.map((path) => `skipped by attribute: ${render(path)}`),
|
|
254
|
-
...findings,
|
|
255
|
-
...refusals.map(refusalLine),
|
|
256
266
|
];
|
|
257
|
-
|
|
267
|
+
const classes = [];
|
|
268
|
+
const remedies = [];
|
|
269
|
+
if (findings.length) {
|
|
270
|
+
classes.push(`${findings.length} control-byte finding(s)`);
|
|
271
|
+
remedies.push(CONTROL_BYTE_REMEDY);
|
|
272
|
+
}
|
|
273
|
+
if (refusals.length) {
|
|
274
|
+
classes.push(`${refusals.length} path(s) not judged`);
|
|
275
|
+
remedies.push(PATH_REMEDY);
|
|
276
|
+
}
|
|
277
|
+
if (!classes.length) return { code: 0, lines };
|
|
278
|
+
return { code: 1, lines: composeCheckerBlock({
|
|
279
|
+
name: CHECKER_NAME, root: top, failed: classes.join('; '),
|
|
280
|
+
findings: [...findings, ...refusals], remedies, after: lines,
|
|
281
|
+
}) };
|
|
258
282
|
};
|
|
259
283
|
|
|
260
284
|
if (isDirectRun(import.meta.url)) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
process.exitCode = result.code;
|
|
285
|
+
runCheckerTail({ name: CHECKER_NAME, exitCode: 1, remedy: UNEXPECTED_REMEDY },
|
|
286
|
+
() => main(process.argv.slice(2)), process);
|
|
264
287
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { composeCheckerBlock } from '../checker-block/index.mjs';
|
|
2
|
+
import { resolveKitDoc } from '../advisor-matrix.mjs';
|
|
3
|
+
|
|
4
|
+
export const CHECKER_NAME = 'doc-parity';
|
|
5
|
+
const DRIFT_REMEDY = 'update each doc above in the same edit as the code it binds, then re-run';
|
|
6
|
+
|
|
7
|
+
const structureLine = (structure) =>
|
|
8
|
+
` ${structure.ok ? '✓' : '✗'} ${structure.constant} → ${structure.files[0].rel}${structure.ok ? '' : ` — ${structure.files[0].reason}`}`;
|
|
9
|
+
|
|
10
|
+
export const formatHuman = (results, structure) => {
|
|
11
|
+
const lines = ['doc-parity — code constants ⟷ references/modes/*.md contract (read-only, BUGFREE-3)'];
|
|
12
|
+
for (const r of results) {
|
|
13
|
+
for (const f of r.files) {
|
|
14
|
+
lines.push(` ${f.ok ? '✓' : '✗'} ${r.constant} → ${f.rel}${f.ok ? '' : ` — ${f.reason}`}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
lines.push(structureLine(structure));
|
|
18
|
+
const failed = results.flatMap((r) => r.files.filter((f) => !f.ok).map((f) => `${r.constant} @ ${f.rel}`));
|
|
19
|
+
// The summary verdict derives from BOTH halves. A PASS token computed from the bindings alone read
|
|
20
|
+
// as a green report while the structure check below it said FAIL — the one surface that lied.
|
|
21
|
+
const green = failed.length === 0 && structure.ok;
|
|
22
|
+
lines.push(` check: ${green ? 'PASS' : 'FAIL'} — ${failed.length === 0 ? `${results.length} binding(s) consistent` : `${failed.length} drifted binding(s): ${failed.join('; ')}`}, structure ${structure.ok ? 'PASS' : 'FAIL'}`);
|
|
23
|
+
return lines.join('\n');
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const formatCheckPass = (results) =>
|
|
27
|
+
`doc-parity check: PASS — ${results.length} binding(s) consistent; the advisor matrix structure corresponds`;
|
|
28
|
+
|
|
29
|
+
const driftFinding = (constant, { rel, reason }) => ({
|
|
30
|
+
path: resolveKitDoc(rel), text: `${constant} — ${reason}`,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export const composeDriftBlock = ({ results, structure, cwd }) => {
|
|
34
|
+
const drifted = results.filter(({ ok }) => !ok);
|
|
35
|
+
const classes = [];
|
|
36
|
+
if (drifted.length) classes.push(`${drifted.length} drifted binding(s)`);
|
|
37
|
+
const findings = drifted.flatMap(({ constant, files }) =>
|
|
38
|
+
files.filter(({ ok }) => !ok).map((file) => driftFinding(constant, file)));
|
|
39
|
+
if (!structure.ok) {
|
|
40
|
+
classes.push('the advisor matrix structure drifted');
|
|
41
|
+
findings.push(driftFinding(structure.constant, structure.files[0]));
|
|
42
|
+
}
|
|
43
|
+
return composeCheckerBlock({
|
|
44
|
+
name: CHECKER_NAME, root: cwd, failed: classes.join('; '), findings, remedies: [DRIFT_REMEDY],
|
|
45
|
+
});
|
|
46
|
+
};
|
package/tools/doc-parity.mjs
CHANGED
|
@@ -19,7 +19,11 @@
|
|
|
19
19
|
// Read-only: never writes, never commits, never runs a subscription CLI, spawns nothing. Dependency-
|
|
20
20
|
// free, Node >= 22. No side effects on import (the isDirectRun idiom).
|
|
21
21
|
|
|
22
|
+
import { resolve } from 'node:path';
|
|
23
|
+
import { composeUsageRefusal } from '../references/scripts/shared/index.mjs';
|
|
22
24
|
import { EXIT as DOCTOR_EXIT, STATUS as DOCTOR_STATUS, TRUSTED_DIRS as DOCTOR_TRUSTED_DIRS } from './autonomy-doctor.mjs';
|
|
25
|
+
import { runCheckerTail } from './checker-block/index.mjs';
|
|
26
|
+
import { CHECKER_NAME, formatHuman, formatCheckPass, composeDriftBlock } from './doc-parity/index.mjs';
|
|
23
27
|
import {
|
|
24
28
|
RECOMMENDATIONS_SECTION_HEADER,
|
|
25
29
|
RECOMMENDATIONS_EMPTY_LINE,
|
|
@@ -96,9 +100,6 @@ const STATUS_DOC = 'references/modes/status.md';
|
|
|
96
100
|
// its table in, and a second copy here is exactly the drift this lint exists to catch.
|
|
97
101
|
const DISPATCH_DOC = ADVISOR_MATRIX_DOC;
|
|
98
102
|
|
|
99
|
-
// A typed usage failure (exit 2) for the CLI parser — the codebase's typed-error idiom (no classes).
|
|
100
|
-
const usageFail = (message) => Object.assign(new Error(message), { exitCode: 2 });
|
|
101
|
-
|
|
102
103
|
// ── the closed binding registry ──────────────────────────────────────────────────────
|
|
103
104
|
// Each binding: { constant, value (live), token (value rendered into the doc's exact phrasing),
|
|
104
105
|
// files[] (the contract docs that MUST carry the token) }. The token phrasings match the current
|
|
@@ -281,30 +282,12 @@ export { ADVISOR_MATRIX_DOC, ADVISOR_MATRIX_BEGIN, ADVISOR_MATRIX_END, parseAdvi
|
|
|
281
282
|
// relative to the kit root.
|
|
282
283
|
export const checkParity = (bindings = BINDINGS, readText = defaultReadText) => bindings.map((b) => checkBinding(b, readText));
|
|
283
284
|
|
|
284
|
-
|
|
285
|
-
const
|
|
286
|
-
` ${structure.ok ? '✓' : '✗'} ${structure.constant} → ${structure.files[0].rel}${structure.ok ? '' : ` — ${structure.files[0].reason}`}`;
|
|
287
|
-
|
|
288
|
-
const formatHuman = (results, structure) => {
|
|
289
|
-
const lines = ['doc-parity — code constants ⟷ references/modes/*.md contract (read-only, BUGFREE-3)'];
|
|
290
|
-
for (const r of results) {
|
|
291
|
-
for (const f of r.files) {
|
|
292
|
-
lines.push(` ${f.ok ? '✓' : '✗'} ${r.constant} → ${f.rel}${f.ok ? '' : ` — ${f.reason}`}`);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
lines.push(structureLine(structure));
|
|
296
|
-
const failed = results.flatMap((r) => r.files.filter((f) => !f.ok).map((f) => `${r.constant} @ ${f.rel}`));
|
|
297
|
-
// The summary verdict derives from BOTH halves. A PASS token computed from the bindings alone read
|
|
298
|
-
// as a green report while the structure check below it said FAIL — the one surface that lied.
|
|
299
|
-
const green = failed.length === 0 && structure.ok;
|
|
300
|
-
lines.push(` check: ${green ? 'PASS' : 'FAIL'} — ${failed.length === 0 ? `${results.length} binding(s) consistent` : `${failed.length} drifted binding(s): ${failed.join('; ')}`}, structure ${structure.ok ? 'PASS' : 'FAIL'}`);
|
|
301
|
-
return lines.join('\n');
|
|
302
|
-
};
|
|
285
|
+
const UNEXPECTED_REMEDY = 'fix the cause the stack below names, then re-run';
|
|
286
|
+
const USAGE = 'Usage:\n node doc-parity.mjs [--check | --json]';
|
|
303
287
|
|
|
304
288
|
const HELP = `doc-parity — deterministic doc-drift lint for the agent-workflow family (BUGFREE-3 / AD-049).
|
|
305
289
|
|
|
306
|
-
|
|
307
|
-
node doc-parity.mjs [--check | --json]
|
|
290
|
+
${USAGE}
|
|
308
291
|
|
|
309
292
|
A CLOSED, exported registry binds each live code constant — the autonomy-doctor contract (the EXIT
|
|
310
293
|
table, the status tokens, the trusted-dir allowlist), the recommendations/upgrade presentation
|
|
@@ -346,32 +329,29 @@ Read-only: never writes, never commits, spawns nothing. Exit codes: 0 pass (or p
|
|
|
346
329
|
const KNOWN_ARGS = new Set(['--help', '-h', '--check', '--json']);
|
|
347
330
|
|
|
348
331
|
export const main = (argv, ctx = {}) => {
|
|
332
|
+
if (argv.includes('--help') || argv.includes('-h')) return { code: 0, stdout: HELP, stderr: '' };
|
|
333
|
+
const unknown = argv.find((argument) => !KNOWN_ARGS.has(argument));
|
|
334
|
+
if (unknown !== undefined) {
|
|
335
|
+
const lines = composeUsageRefusal({ name: CHECKER_NAME, failed: `unknown argument: ${JSON.stringify(unknown)}`, usage: USAGE });
|
|
336
|
+
return { code: 2, stdout: lines.join('\n'), stderr: '' };
|
|
337
|
+
}
|
|
349
338
|
const readText = ctx.readText ?? defaultReadText;
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
if (
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
if (argv.includes('--check')) {
|
|
362
|
-
const bindingReason = failed.length === 0 ? `${results.length} binding(s) consistent` : `${failed.length} drifted binding(s): ${failed.map((r) => r.constant).join(', ')} — update the contract doc(s) in the SAME edit as the code`;
|
|
363
|
-
const structureReason = structure.ok ? 'the advisor matrix structure corresponds' : `the advisor matrix structure DRIFTED — ${structure.files[0].reason}`;
|
|
364
|
-
return { code: green ? 0 : 1, stdout: `doc-parity check: ${green ? 'PASS' : 'FAIL'} — ${bindingReason}; ${structureReason}`, stderr: '' };
|
|
365
|
-
}
|
|
366
|
-
return { code: 0, stdout: formatHuman(results, structure), stderr: '' };
|
|
367
|
-
} catch (err) {
|
|
368
|
-
return { code: err.exitCode ?? 1, stdout: '', stderr: `doc-parity: ${err.message}` };
|
|
339
|
+
const results = checkParity(BINDINGS, readText);
|
|
340
|
+
const structure = checkMatrixStructure(readText);
|
|
341
|
+
const green = results.every(({ ok }) => ok) && structure.ok;
|
|
342
|
+
const check = argv.includes('--check');
|
|
343
|
+
if (argv.includes('--json')) {
|
|
344
|
+
return { code: check && !green ? 1 : 0, stdout: JSON.stringify({ results, structure, ok: green }, null, 2), stderr: '' };
|
|
345
|
+
}
|
|
346
|
+
if (check) {
|
|
347
|
+
if (green) return { code: 0, stdout: formatCheckPass(results), stderr: '' };
|
|
348
|
+
const lines = composeDriftBlock({ results, structure, cwd: resolve(ctx.cwd ?? process.cwd()) });
|
|
349
|
+
return { code: 1, stdout: lines.join('\n'), stderr: '' };
|
|
369
350
|
}
|
|
351
|
+
return { code: 0, stdout: formatHuman(results, structure), stderr: '' };
|
|
370
352
|
};
|
|
371
353
|
|
|
372
354
|
if (isDirectRun(import.meta.url)) {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
if (r.stderr) process.stderr.write(r.stderr.endsWith('\n') ? r.stderr : `${r.stderr}\n`);
|
|
376
|
-
process.exitCode = r.code;
|
|
355
|
+
runCheckerTail({ name: CHECKER_NAME, exitCode: 1, remedy: UNEXPECTED_REMEDY },
|
|
356
|
+
() => main(process.argv.slice(2)), process);
|
|
377
357
|
}
|