@sabaiway/agent-workflow-kit 14.0.0 → 14.1.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 +38 -0
- package/README.md +1 -1
- package/SKILL.md +1 -1
- package/capability.json +1 -1
- package/package.json +1 -1
- package/references/modes/dispatch.md +3 -3
- package/references/modes/review-state.md +1 -1
- package/tools/dispatch-record.mjs +8 -2
- package/tools/dispatch-store-read.mjs +35 -1
- package/tools/dispatch-store.mjs +8 -1
- package/tools/dispatch.mjs +25 -4
- package/tools/held-session.mjs +57 -18
- package/tools/task-thread.mjs +70 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,44 @@ Semantically versioned ([semver](https://semver.org)), newest first. The `versio
|
|
|
4
4
|
is the current release. `upgrade` mode reads a project's `docs/ai/.workflow-version` and applies
|
|
5
5
|
every `migrations/<version>-<slug>.md` newer than it, in semver order.
|
|
6
6
|
|
|
7
|
+
## 14.1.0 — a dispatch names its task: `dispatch open --task <brief>` records the brief and its files, the ledger refuses overlapping and mixed task threads (`files-overlap`, `mixed-open`), and the held-session judge holds one session per task instead of one per commit (AD-145)
|
|
8
|
+
|
|
9
|
+
**A held session now belongs to a task.** Until 14.0.0 the held-session judge kept ONE held session per commit, so a
|
|
10
|
+
planned fresh session for the next task read as a forbidden substitution. From 14.1.0 a delegation thread can name the
|
|
11
|
+
task it carries out, and each task's threads form their own chain with their own held session. Every ledger a 14.x kit
|
|
12
|
+
wrote reads unchanged; a ledger holding a task record needs this kit to read it. Story S8 of the epic
|
|
13
|
+
`EPICS-STORIES-TASKS-AS-THE-UNIT-OF-WORK`; the contract is the draft `docs/ai/specs/kit/task-thread/` (S1–S4 and S6
|
|
14
|
+
bound), the live `docs/ai/specs/kit/held-session.md` revised. Parallel task threads are NOT part of this release: a
|
|
15
|
+
task thread is still measured over the whole tree, so D10's one-dispatch-at-a-time bar still binds every thread.
|
|
16
|
+
|
|
17
|
+
- **The task key (`tools/task-thread.mjs`, new, 70 lines).** A `dispatch` record may carry `task: { brief, files }`,
|
|
18
|
+
the dispatch kind's second optional key at schema 1: `brief` is `docs/plans/TASK-<stem>-T<n>.md`, `files` a
|
|
19
|
+
non-empty list of distinct normalized repo-relative paths in UTF-8 byte order, none a path prefix of another. Three
|
|
20
|
+
refusals by name — `task-brief`, `task-files`, `task-base` (a task on a head base) — beside the closed nested keys.
|
|
21
|
+
The pure leaf also exports `readsTask` (a record minted before the field reads `null`), `readsInsideEpoch` (moved
|
|
22
|
+
from `held-session.mjs`), `claimedPaths`, `epochClaims` and `byteOrder`; it imports nothing from the ledger modules.
|
|
23
|
+
- **`dispatch open --checkpoint <oid> --task <brief>`.** Reads the brief at the git top-level through the no-follow
|
|
24
|
+
reader, parses it with `task-brief`'s own parser and records its `Files:` paths in byte order. `--task` without
|
|
25
|
+
`--checkpoint` refuses `task-base`; a brief the parser refuses keeps the parser's name; nothing is written on a
|
|
26
|
+
refusal. A retry must record its origin's task. An open without `--task` on a ledger with no task record is unchanged.
|
|
27
|
+
- **Two refusals at append time (`tools/dispatch-store-read.mjs`, `tools/dispatch-store.mjs`).** Since the last
|
|
28
|
+
commit, `files-overlap` refuses a task thread whose files overlap by path prefix an open task thread's or a folded
|
|
29
|
+
thread's of another brief; `mixed-open` refuses an untasked open beside an open task thread, an untasked `code` open
|
|
30
|
+
of backend `codex` after a task fold, and a task open beside an open untasked thread. Both are judged under the store
|
|
31
|
+
lock against a HEAD read taken there, and the read audit never replays them, so moving HEAD back keeps the ledger
|
|
32
|
+
readable. An open without `--task` on a ledger with no task record takes no extra git read.
|
|
33
|
+
- **One held session per task chain (`tools/held-session.mjs`).** The chain key is the brief; threads without a task
|
|
34
|
+
keep the one commit-epoch chain. With a task `code` thread of backend `codex` in the epoch the judge reports `chains`
|
|
35
|
+
and a per-thread `chainKey`, keeps `heldId`, `folds` and `open` on the untasked chain while `substitution` and
|
|
36
|
+
`threads` span every chain; `review-state` prints `held sessions: <k> chain(s) — <label>: <id> (<n>) · …`,
|
|
37
|
+
`commit-guard --check` inherits its refusal verbatim, and `procedures plan-execution` prints one fold run line or
|
|
38
|
+
caveat per chain, a task chain's marked `(task <brief>)`. Without a task thread
|
|
39
|
+
the report, the line and the fold lane are byte-identical to 14.0.0.
|
|
40
|
+
- **Copy.** The dispatch mode doc and the README name `--task` and both refusals; the review-state mode doc names the
|
|
41
|
+
chain line; D10 stays a bar for every thread, the two refusals adding to it.
|
|
42
|
+
- **Tests.** Five new suites — `task-thread.test.mjs`, `dispatch.test/task.test.mjs`, `dispatch.test/task-overlap.test.mjs`,
|
|
43
|
+
`held-session-chain.test.mjs`, `review-state-task-chain.test.mjs` — and the record and tarball pins (313 files).
|
|
44
|
+
|
|
7
45
|
## 14.0.0 — the placed executor's body is derived from `docs/ai/vehicles.json`: the agents writer and a new eighth config ensure, `executor`, re-derive it instead of preserving a hand edit, the readiness survey reports an unreadable setting as an unusable vehicle, and the advisor reads the posture (AD-143)
|
|
8
46
|
|
|
9
47
|
**MAJOR: the never-clobber rule for the placed executor is withdrawn.** Until 13.3.0 the agents writer reported a
|
package/README.md
CHANGED
|
@@ -245,7 +245,7 @@ file), or run the guarded `/agent-workflow-kit uninstall`.
|
|
|
245
245
|
| `/agent-workflow-kit commit-guard` | any time | **the read-only pre-commit guard** (D10) — makes the commit capture the whole current working tree, so «verified» and «about to be committed» are the same bytes (the receipt itself has a stated residual — see the mode doc). FIRST it refuses an **INDEX that lags the verified working tree** (the gates and the fingerprint describe the WORKING tree while `git commit` takes the INDEX alone, and the fingerprint cannot tell them apart — so a lagging index used to ship a strict subset of what was verified): unstaged tracked paths or reviewable untracked-not-ignored paths, named up to a bounded cap with the remainder stated, a dirty tracked **submodule** named separately with its own recovery, and fail-closed on an undecidable probe. This deliberately blocks a partial commit. Then it binds the LATEST completed `run-gates --final` receipt to the EXACT current tree: refuses on a missing/red/stale receipt, fingerprint drift under the run, a dangling later attempt, declaration content drift, evidence-hash or lcov drift, or unsatisfied review obligations (the same review-state decision, recomputed over a sanitized env — forged out-of-repo stores never satisfy). Re-runs NO gate or test. Wire it into `.git/hooks/pre-commit` (the installer writes the RESOLVED invocation). `git commit --no-verify` stays the stated residual. |
|
|
246
246
|
| `/agent-workflow-kit recommendations` | any time (every `upgrade` ends with it) | **read-only deployment advisor** (AD-044) — computes what in THIS deployment is configured sub-optimally (allowlist not seeded, autonomy render drifted, OS sandbox unavailable, gates undeclared, bridge friction, sandbox-mask clutter, an unacknowledged sandbox recipe, a feature-spec layer never adopted) and renders **verdict-first**: one composed verdict line (does anything need attention?), then each item as **{severity · what · one-line benefit · an optional `recipe:` line (the sandbox-lane live recipe, the worktrees-dir hand-apply-first grant advice, the agents hidden-mode reconcile follow-up, or the spec-adoption decline preview) · the exact consent-gated apply one-liner}**. The agent PRESENTS the section in the user's conversational language — every fact and count, nothing added or dropped; commands, paths, hosts and rule strings byte-exact; raw tool block on request — and runs EXACTLY the rendered one-liners only on your yes, surfacing each item's posture note first. Renders **present-even-when-empty** (`no recommendations — flow optimal.`); a failed probe degrades to a stated skip line. Registry strings are fact-true frozen one-line data (posture/risk notes live in the mode doc at the consent moment); the kit never seeds `sandbox.network.allowedDomains` / `filesystem.allowWrite` (**HAND-APPLY** territory), and the sandbox-lane item's convergence is a neutral fingerprint acknowledgement recorded by a consent-gated ack writer into `docs/ai/acks.json` — never a security key (the recipe is documented per bridge in `capability.json` `networkHosts` + `writableDirs`). `--cwd` is required (the target project is explicit); never writes, never commits, never runs a subscription CLI. |
|
|
247
247
|
| `/agent-workflow-kit doc-parity` | any time | **read-only doc-parity lint** (AD-049) — kills the doc-drift class where a mode-contract doc silently lags a code constant (a `--check` doc still reading `300` after the diff cap moved to `400`): a **closed, exported registry** binds each live constant (review caps, schema versions, the ledger's own class/scope vocabulary, and the autonomy-doctor EXIT/status/trusted-dir contract) to the exact token its `references/modes/*.md` contract must carry, and asserts the CURRENT value renders into every bound file — a drifted doc, an unreadable file, or an absent token **fails closed**. The values are sourced from the live imports (never re-typed), so the lint can't itself go stale; adding a binding is adding a checked entry (closed-world, edit-safe). `--check` is a gate exit code for `docs/ai/gates.json`. Never writes, never commits, never runs a subscription CLI. |
|
|
248
|
-
| `/agent-workflow-kit dispatch` | any time | **the delegation engine** — makes "how much does delegating a sub-task actually buy?" a measured number instead of a feeling. `check <file>` validates a sub-task brief's contract block and exits 0/1 naming the first violated field — **form only**: whether the task is genuinely bounded, its design decided and its acceptance adequate stays your judgment, and a well-formed absurdity passes here by construction. `advise --step-class <c>` answers the question that comes BEFORE that one — which vehicle should carry this kind of sub-task, whether it is even present on this machine, and what the ledger has already recorded for threads of that class (finished, failed, closed without a fold, and still open — counted separately) — and it decides nothing: it refuses no dispatch, gates no verb, and a choice that diverges from the advice is noted rather than blocked. It reads the filesystem only: nothing is launched to find out what is installed, an absent ledger prints "no recorded history", an unreadable one prints the store's own words, and either way the advice still prints. The same block appears as a footer under a form-valid `check` — never under a refusal, so it can never hide one. `register` pre-registers an acceptance wave (step classes, pairing key, minimum observations per class, the mean and first-pass thresholds) so the bar can never be chosen after the results it judges — immutable per wave. `observe` records ONE hand-written observation (`solo-construction`, the baseline whose ratio is 1 by construction — except over a scope measuring zero bytes, which has no ratio at all and is recorded ineligible by name — or `self-reported`) — delegated numbers are never hand-written, they are derived. The writer verbs are where that derivation happens: `open` puts a delegated thread on the record with every mint-time field copied from the brief's own header, refusing a deadline the wrapper's cap plus its kill grace would not fit inside, and recording whether the tree it started from was clean against the thread's base — HEAD by default, or the tree `--checkpoint <oid>` names, so the second task of a story is measured over the first one's uncommitted work instead of opening dirty (a dirty one makes the result honestly unmeasurable rather than quietly counted); `await` waits for that one dispatch to answer and writes nothing — only the finished receipt satisfies it, a run still holding the nonce means keep waiting, and a wait that runs out says so with its own exit code, names whether the deadline or your own timeout ended it, and authorizes nothing: a wait that ended without an answer is a question for you, never permission to dispatch again; `return` absorbs the receipt the wrapper minted — only a finished one, checked against the contract it actually ran, its deadline and its own report, and refused outright when the tree hides changes from git or moves while the return is being computed — and derives the bytes from git rather than from anyone's claim; `fold` is the acceptance, and it refuses if the tree moved since the return — precisely, it re-confirms **equality of the visible canonical payload**, which is a change detector rather than a cryptographic identity of the tree: under the default head base that payload's untracked section is unframed and carries no file mode, so a content or symlink target that imitates the marker opening the next entry can alias two trees, and making an untracked file executable moves nothing (both named as residuals in the mode doc, with the fix queued); under a checkpoint base it is one indexed diff that carries modes. A change set carrying a binary, a non-regular path, a submodule, or a symlink whose target is not valid UTF-8 is **refused** at `return` and `fold` — CONSERVATIVELY, rather than promise what the default head payload may not be able to follow — and the same refusals hold for a checkpoint thread. `degrade` closes a thread that never earned a fold, on the record and with its reason. `aggregate` prints one wave: the registered thresholds, every observation as context, and per step class the finished threads — a folded success with git-provable bytes contributes its ratio, one whose bytes are unprovable is excluded from the mean but still counts in the first-pass rate, and a failed thread, a degrade-closed one, or one folded after failing acceptance each count as a real zero. Below the registered minimum nothing is computed (insufficient); at or above it is computed and labeled PILOT evidence. It REFUSES rather than guessing: no pre-registration, an unfinished thread in scope, a recorded refusal-to-delegate that never opened a thread, or an ambiguous wave each stop the computation by name. `handoff-return --slug <s>` closes the worktree loop after `land --prepare`: it re-attests that main still holds exactly the prepared tree under the same HEAD (both recorded in the handoff at prepare time), prints the satellite handoff's user-owned content byte for byte with its boundaries, byte lengths and the main-owned destinations each part folds into, prints the handoff digest and both OIDs as its proof, states the after-the-fold order (a fold landed after the gates leaves them stale), and records ONE self-reported worktree-stream observation only when the whole prepared change set is measurable — a deletion, a rename, a symlink, a submodule or a mode-only change ends with a named NOT RECORDED instead, never a partial number. Appends only to its own ledger inside the git dir (never committable); it also writes `handoff-return`'s `write-tree` tree object and, for a checkpoint measurement, the leaf's OWN temporary index file and the blobs its forced adds store — never a ref, never the real index; never commits, never runs a subscription CLI. |
|
|
248
|
+
| `/agent-workflow-kit dispatch` | any time | **the delegation engine** — makes "how much does delegating a sub-task actually buy?" a measured number instead of a feeling. `check <file>` validates a sub-task brief's contract block and exits 0/1 naming the first violated field — **form only**: whether the task is genuinely bounded, its design decided and its acceptance adequate stays your judgment, and a well-formed absurdity passes here by construction. `advise --step-class <c>` answers the question that comes BEFORE that one — which vehicle should carry this kind of sub-task, whether it is even present on this machine, and what the ledger has already recorded for threads of that class (finished, failed, closed without a fold, and still open — counted separately) — and it decides nothing: it refuses no dispatch, gates no verb, and a choice that diverges from the advice is noted rather than blocked. It reads the filesystem only: nothing is launched to find out what is installed, an absent ledger prints "no recorded history", an unreadable one prints the store's own words, and either way the advice still prints. The same block appears as a footer under a form-valid `check` — never under a refusal, so it can never hide one. `register` pre-registers an acceptance wave (step classes, pairing key, minimum observations per class, the mean and first-pass thresholds) so the bar can never be chosen after the results it judges — immutable per wave. `observe` records ONE hand-written observation (`solo-construction`, the baseline whose ratio is 1 by construction — except over a scope measuring zero bytes, which has no ratio at all and is recorded ineligible by name — or `self-reported`) — delegated numbers are never hand-written, they are derived. The writer verbs are where that derivation happens: `open` puts a delegated thread on the record with every mint-time field copied from the brief's own header, refusing a deadline the wrapper's cap plus its kill grace would not fit inside, and recording whether the tree it started from was clean against the thread's base — HEAD by default, or the tree `--checkpoint <oid>` names, so the second task of a story is measured over the first one's uncommitted work instead of opening dirty (a dirty one makes the result honestly unmeasurable rather than quietly counted), while `--task <brief>` also records which task brief the thread carries out and the files that brief lists, refusing, since the last commit, a task thread whose files overlap by path prefix those of an open task thread or of a folded thread of another brief (`files-overlap`), and a mix of the two kinds — an untasked open beside an open task thread or, for a `code` open of backend `codex`, after a task fold, and a task open beside an open untasked thread (`mixed-open`); `await` waits for that one dispatch to answer and writes nothing — only the finished receipt satisfies it, a run still holding the nonce means keep waiting, and a wait that runs out says so with its own exit code, names whether the deadline or your own timeout ended it, and authorizes nothing: a wait that ended without an answer is a question for you, never permission to dispatch again; `return` absorbs the receipt the wrapper minted — only a finished one, checked against the contract it actually ran, its deadline and its own report, and refused outright when the tree hides changes from git or moves while the return is being computed — and derives the bytes from git rather than from anyone's claim; `fold` is the acceptance, and it refuses if the tree moved since the return — precisely, it re-confirms **equality of the visible canonical payload**, which is a change detector rather than a cryptographic identity of the tree: under the default head base that payload's untracked section is unframed and carries no file mode, so a content or symlink target that imitates the marker opening the next entry can alias two trees, and making an untracked file executable moves nothing (both named as residuals in the mode doc, with the fix queued); under a checkpoint base it is one indexed diff that carries modes. A change set carrying a binary, a non-regular path, a submodule, or a symlink whose target is not valid UTF-8 is **refused** at `return` and `fold` — CONSERVATIVELY, rather than promise what the default head payload may not be able to follow — and the same refusals hold for a checkpoint thread. `degrade` closes a thread that never earned a fold, on the record and with its reason. `aggregate` prints one wave: the registered thresholds, every observation as context, and per step class the finished threads — a folded success with git-provable bytes contributes its ratio, one whose bytes are unprovable is excluded from the mean but still counts in the first-pass rate, and a failed thread, a degrade-closed one, or one folded after failing acceptance each count as a real zero. Below the registered minimum nothing is computed (insufficient); at or above it is computed and labeled PILOT evidence. It REFUSES rather than guessing: no pre-registration, an unfinished thread in scope, a recorded refusal-to-delegate that never opened a thread, or an ambiguous wave each stop the computation by name. `handoff-return --slug <s>` closes the worktree loop after `land --prepare`: it re-attests that main still holds exactly the prepared tree under the same HEAD (both recorded in the handoff at prepare time), prints the satellite handoff's user-owned content byte for byte with its boundaries, byte lengths and the main-owned destinations each part folds into, prints the handoff digest and both OIDs as its proof, states the after-the-fold order (a fold landed after the gates leaves them stale), and records ONE self-reported worktree-stream observation only when the whole prepared change set is measurable — a deletion, a rename, a symlink, a submodule or a mode-only change ends with a named NOT RECORDED instead, never a partial number. Appends only to its own ledger inside the git dir (never committable); it also writes `handoff-return`'s `write-tree` tree object and, for a checkpoint measurement, the leaf's OWN temporary index file and the blobs its forced adds store — never a ref, never the real index; never commits, never runs a subscription CLI. |
|
|
249
249
|
| `/agent-workflow-kit worktrees` | any time | **parallel feature worktrees** — run several features in DIFFERENT agent sessions on one repo, zero interference on working-tree files (the ONE exception is the dependency cache, below): `provision <slug> --plan <file>` creates a sibling git worktree on branch `aw/<slug>` and populates it (registry-derived footprint copy-if-missing — a tracked file is never overwritten; EXACTLY ONE seeded feature plan; the `handoff-<slug>.md` record from minute zero; `node_modules` symlinked where the link stays ignored — a shared MUTABLE dependency cache: writes through it hit MAIN's node_modules; for isolation run the printed isolated-install command (`--install` only PRINTS it; on `--resume` run the printed unlink-first recovery first — printed only for a link whose RAW TARGET is MAIN's `node_modules`, since a foreign or unreadable link is reported as such with no removal advised); absolute root-pinned gate commands rebased on untracked copies only, and only while their bytes equal the MAIN source or its rebased form — user-modified copies stay untouched); `list` is read-only (slug, branch, base, dirty, handoff); `prompt <slug>` is read-only too and re-prints the satellite's cold-start prompt — the same text `provision` ends its report with: where the worktree is, its ONE seeded plan, the handoff as the one channel back, MAIN's orientation (shared series index, landing) and, under its own heading because it is probed on the satellite, that checkout's install posture — every value derived LIVE rather than replayed from the frozen provision record, a recorded value that no longer matches NAMED as a divergence (with the cause its source makes likely) instead of printed as the runnable one, every offered command marked with WHO runs it (`MAIN $ …` for the landing, `HERE $ …` for this checkout's own install, a posture with nothing to run staying prose), and a control character in any rendered value a typed STOP rather than a forged prompt line; `land <slug> --prepare` locks the common git dir, fail-closes on divergence or incomplete satellite state, transfers the complete accepted satellite diff onto a CLEAN main, runs sync plus the declared gates, and reports HEAD/TRANSFER/PREPARED OIDs — the commit ALWAYS stays a dialogue ask; `cleanup <slug>` takes the same lock and removes a LANDED worktree only after live landed-verification against main HEAD, while `--abandon` is the ONE destructive arm (destroys unlanded work; **no preview step** on any writer). The parent dir is the `docs/ai/worktrees.json` `parentDir` setting (default: the repo's sibling parent); an unwritable parent degrades to printed maintainer-pasted commands, and the one-time host consent that makes it promptless surfaces via `recommendations`. Never commits, never pushes, never runs a subscription CLI. |
|
|
250
250
|
| `/agent-workflow-kit uninstall` | opt-in, any time | **guarded teardown** — the inverse of `init` / `setup`. Removes only what's **provably ours** (managed skill dirs + bridge wrappers; in a project, the hidden-mode git-ignore block it added + the pre-commit hook it installed); **never deletes** your `docs/ai` / `AGENTS.md` (prints the exact `rm` to run by hand) or your `.claude/settings.json` (prints an **edit** — remove the attribution key, review any velocity `permissions.*` — never an `rm`). Always `--dry-run` first; preflight-then-mutate; never commits. |
|
|
251
251
|
| `/agent-workflow-kit velocity` | Claude Code · opt-in | **onboarding velocity profile** — seeds a fixed, audited **read-only** allowlist into `.claude/settings.json` so routine read-only commands stop idling on approval prompts while you're away; opt-in `acceptEdits`; plus a **read-only advisory** of likely project gate commands to add by hand. Writes **only** `.claude/settings.json` — **never** allowlists commit/push/publish, never writes `settings.local.json`, never commits. A seeded entry is a **trust posture, not a sandbox** (a runtime residual remains at the settings level — its guard ships as the opt-in `hook` command); a direct commit/push/publish still asks. `--dry-run` first. |
|
package/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: agent-workflow-kit
|
|
|
3
3
|
description: Deploy or upgrade a portable AI-agent memory-and-workflow system in any project. Use when the user wants to bootstrap `docs/ai/` + an entry-point `AGENTS.md` (+ `CLAUDE.md` alias) + cap/archive/index enforcement in a new or existing repo, set up the Memory Map and session protocols, install the docs-rotation pre-commit hook, or run `/agent-workflow-kit` / `/agent-workflow-kit upgrade`. Triggers on phrases like "set up the memory system", "deploy the AI workflow here", "bootstrap docs/ai", "upgrade the workflow".
|
|
4
4
|
disable-model-invocation: true
|
|
5
5
|
metadata:
|
|
6
|
-
version: '14.
|
|
6
|
+
version: '14.1.0'
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
# agent-workflow-kit
|
package/capability.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sabaiway/agent-workflow-kit",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.1.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",
|
|
@@ -30,7 +30,7 @@ Run **`node ${CLAUDE_SKILL_DIR}/tools/dispatch.mjs <check|advise|register|observ
|
|
|
30
30
|
|
|
31
31
|
3. **`register`** — appends the wave's **pre-registration** record (`--wave --step-classes --pairing-key --min-per-class --mean-l-threshold --first-pass-num --first-pass-den`). Acceptance is pre-registered so thresholds can never be chosen after the observations that will be judged against them; a registration is **immutable per wave** and a second one refuses. `--pairing-key` accepts only a key the aggregator actually implements (today `stepClass`) — a wave registered under any other key would record a contract the computation never follows, and the aggregator re-checks the registration independently, since a store can be hand-written.
|
|
32
32
|
4. **`observe`** — appends ONE **observation** (`--wave --step-class --scope --plan --phase --provenance [--denominator-bytes]`). Provenance is `solo-construction` or `self-reported` **only**: delegated accounting is DERIVED from nonce threads and is never hand-appended. The numerator is the post-image bytes of the objects the scope names; a **solo** observation takes that same number as its denominator — `L = 1` by construction, so `--denominator-bytes` is refused — while a self-reported one states its own. One stated exception: a solo scope that measures **zero** bytes has no ratio at all, and is recorded INELIGIBLE by name (`zero-denominator`) rather than as `L = 1` — `0/0` is undefined before it is one, and a named ineligibility is what this family records instead of a silent number. **`--scope` is repeatable**, one repo-relative path per occurrence: no separator is safe inside a POSIX path, so a split list could not express `docs/my file.md` and would silently measure the wrong set wherever its fragments happened to exist. Paths are anchored at the **git top-level**, never at the caller's cwd, and the record carries a **JSON-encoded array of canonical repo-relative paths, carried in the schema's string field** (the record's `scope` is a string by D3, so the array travels encoded). An object's identity IS its canonical path, so two files with identical bytes are two objects and count twice, while one path reached twice (a repeated listing, an in-repo ancestor symlink) is one object and counts once. The run refuses by name outside a git work tree, for an absent or non-regular path, and for a path whose **real** location leaves the repository (an ancestor symlink is not a way out).
|
|
33
|
-
5. **`open`** — appends the **dispatch** record that opens a thread (`--contract <dispatch-file> --wave --backend --rationale --wrapper-cap-s --kill-grace-s [--checkpoint <oid>] [--retry-of <nonce>]`). Every mint-time field — `nonce`, `stepClass`, `vehicle`, `deadlineS`, `retry.index`, `retry.cap` — is **COPIED from the contract header** and bound by `contractDigest`, so a dispatch can never disagree with the header it claims to carry. It fingerprints the tree (`preTreeDigest`) and probes it for a CLEAN baseline; a **dirty** one is recorded as such, and the eventual return is then metric-INELIGIBLE by the name `dirty-baseline` — the uncommitted-state fingerprint is blind to the index↔worktree split, so a dirty baseline cannot attribute bytes to a dispatch. It **refuses a `deadlineS` below `--wrapper-cap-s` + `--kill-grace-s`** (both explicit operands: the kit never reads another package's default), because a dispatch that cannot be capped inside its own deadline could never honour the terminal-exit rule. Every retry rule — one successor per thread, the cap read off the chain's ORIGIN, wave and class equality, a changed contract after a `contract-refusal` — is the **store's**, and `open` surfaces its refusals verbatim. `--checkpoint <oid>` records the checkpoint base: the operand must be a git object id of exactly 40 or 64 lowercase hex characters that resolves to a TREE (a commit, a blob, a tag and an unknown id each refuse by name, nothing written), and every measurement of that thread — the clean probe, `preTreeDigest`, the return's bracketing fingerprint and diff, the fold's fingerprint and enumeration — is computed against that tree over the snapshot scope — every work-tree path not ignored by git's standard excludes judged without the real index, plus every present kit-own path, plus every path HEAD's tree or the base tree names, minus `docs/plans/`, `.claude/settings.json`, `.claude/settings.local.json`, `.mcp.json`, every known foreign-tool footprint and `node_modules`; the base tree's non-excluded paths deleted since the snapshot are measured as deletions; without the flag the base is `head` and every byte of the MEASUREMENT is today's (the writer always mints the `baseline` key, so the record itself is not byte-identical to 13.0.0's). The CLEAN line of a checkpoint open names the base.
|
|
33
|
+
5. **`open`** — appends the **dispatch** record that opens a thread (`--contract <dispatch-file> --wave --backend --rationale --wrapper-cap-s --kill-grace-s [--checkpoint <oid>] [--task <brief>] [--retry-of <nonce>]`). Every mint-time field — `nonce`, `stepClass`, `vehicle`, `deadlineS`, `retry.index`, `retry.cap` — is **COPIED from the contract header** and bound by `contractDigest`, so a dispatch can never disagree with the header it claims to carry. It fingerprints the tree (`preTreeDigest`) and probes it for a CLEAN baseline; a **dirty** one is recorded as such, and the eventual return is then metric-INELIGIBLE by the name `dirty-baseline` — the uncommitted-state fingerprint is blind to the index↔worktree split, so a dirty baseline cannot attribute bytes to a dispatch. It **refuses a `deadlineS` below `--wrapper-cap-s` + `--kill-grace-s`** (both explicit operands: the kit never reads another package's default), because a dispatch that cannot be capped inside its own deadline could never honour the terminal-exit rule. Every retry rule — one successor per thread, the cap read off the chain's ORIGIN, wave and class equality, a changed contract after a `contract-refusal` — is the **store's**, and `open` surfaces its refusals verbatim. `--checkpoint <oid>` records the checkpoint base: the operand must be a git object id of exactly 40 or 64 lowercase hex characters that resolves to a TREE (a commit, a blob, a tag and an unknown id each refuse by name, nothing written), and every measurement of that thread — the clean probe, `preTreeDigest`, the return's bracketing fingerprint and diff, the fold's fingerprint and enumeration — is computed against that tree over the snapshot scope — every work-tree path not ignored by git's standard excludes judged without the real index, plus every present kit-own path, plus every path HEAD's tree or the base tree names, minus `docs/plans/`, `.claude/settings.json`, `.claude/settings.local.json`, `.mcp.json`, every known foreign-tool footprint and `node_modules`; the base tree's non-excluded paths deleted since the snapshot are measured as deletions; without the flag the base is `head` and every byte of the MEASUREMENT is today's (the writer always mints the `baseline` key, so the record itself is not byte-identical to 13.0.0's). The CLEAN line of a checkpoint open names the base. `--task <brief>` records the brief's path and its byte-ordered Files, requires `--checkpoint` (`task-base`), refuses a brief the parser refuses by the parser's name, and the store refuses `files-overlap` and `mixed-open` at append time.
|
|
34
34
|
6. **`await`** — watches for ONE dispatch to **answer**, and writes nothing at all (`--nonce [--timeout <s>]`). Satisfaction is the arrival of the **TERMINAL** exec receipt for the dispatch's own `{backend, nonce}`: a `reserved` artifact means the run holds the nonce and has published nothing about how it ended, so the wait continues — the same artifact that is a **supervision refusal** at `return`, because absorbing it would record an outcome nobody observed. Satisfaction is decided **positively**, by the exec-receipt reader itself, so an artifact of a neighbouring family standing at that path — a review receipt, a delegation ledger line, a finding manifest — **refuses** rather than satisfies: only an exec receipt answers an exec dispatch, which is the D10 rule the review waiter states from its own side. The bound is the **ABSOLUTE** deadline, measured from the DISPATCH record's timestamp rather than from whenever this wait began: `--timeout` defaults to the time **remaining**, and one reaching past the deadline is **refused** rather than silently clamped (a shortened wait would let a caller believe they waited longer than they did). An already-expired dispatch is **answered immediately**, never waited on. **Arrival is read first, before EVERY bound** — the two wait bounds and the `--timeout` admissibility check alike, so a receipt already on disk answers `ARRIVED` even when the supplied `--timeout` is inadmissible, and the check runs only once there genuinely IS a wait to bound. A receipt already on disk is a fact this verb reports; whether a *late* one may be absorbed is the absorb door's question, refused there by name — **lateness has exactly one decision site, and it is `return`**. The review waiter checks its deadline first for the opposite reason: a receipt *line* carries no dispatch-bound timestamp at all, so there the clock is the only evidence there is. Each pass consults the clock over the poll that has already happened, then sleeps and polls again, so a receipt landing during the last sleep is reported rather than lost to a cutoff a moment later. An unanswered wait exits **`3`** — its own status so a caller that **branches** on the code can tell it from a refusal, never a defence against one that discards failure wholesale — names whether the **deadline** or the `--timeout` ended it, and states that **no writer slot was released**: a wait that ended without an answer never authorizes the next dispatch. Every artifact read rides the store's own no-follow reader, so a symlinked, FIFO, unreadable or malformed artifact refuses **by class** instead of standing in for an answer.
|
|
35
35
|
7. **`return`** — absorbs the wrapper's exec receipt and appends the **return** record (`--nonce [--outcome <o>] [--no-receipt --exit-status <n>]`). The receipt and its report live **beside the ledger**, in the store's own directory. It reads the **TERMINAL** receipt — a `reserved` one is a **supervision question**, not a timeout, and refuses by saying so — then checks the receipt's independently computed `contractDigest` against the dispatch's (a run that executed a *different* contract would otherwise correlate cleanly), its `{backend, nonce}` body against the dispatch it answers (the filename alone is composed by this side), its `capS + killGraceS` against the recorded `deadlineS`, and its timestamp against the **ABSOLUTE** deadline (`dispatch.timestamp + deadlineS`) — a late return refuses by name. It re-verifies the report's digest and length against the receipt, refuses a change set **hidden from the plain `git diff`** the head-base metric is computed over (assume-unchanged, skip-worktree, `diff.ignoreSubmodules`), and then enumerates the returned objects and frames the canonical integration bundle, **bracketed by the tree fingerprint**: a tree that moves mid-computation refuses rather than mixing two change sets. `--outcome` records an orchestrator judgment under the **closed override form** — a wrapper outcome either stays itself or moves to `contract-refusal | partial-edit | acceptance-failure | stale-return | store-failure`, and `success` is recordable only from a receipt that already says success; the record vocabulary's own cross-field rules cut the remaining incompatible pairs. **`--no-receipt`** means "no TERMINAL receipt", never "no evidence": it absorbs a **reservation ONLY** — over a `terminal` artifact it refuses, because a hand-stated outcome there would discard an exit status, a session id and a report digest the run actually proved, and skip the report check that guards them. It builds the return from that reservation (`wrapperVersion` and `posture`, never hand-typed), requires `--exit-status` and an `--outcome` from `transport-failure | contract-refusal | store-failure | missing-identity` (so `partial-edit` and `stale-return` are inexpressible there by name), and reads the report **if present** — an absent one records length 0 and the metric is then ineligible **by name**: `empty-report` where there IS a diff, and `no-op-diff` where the tree is unchanged too, since the eligibility rule names the diff first. That keeps a failed REPORT write and a failed TERMINAL write two separately named lanes. With **no artifact at all** there is no honest return — `--no-receipt` reads the same path and would refuse the same way — so close the thread with `degrade`.
|
|
36
36
|
8. **`fold`** — appends the integration re-confirmation and CLOSES the thread (`--nonce --verdict <text>`). It runs the **same hidden-path guard** as `return`, and here for a sharper reason: `treeDigestAtFold` is computed from the very payload that is blind to those paths, so under a HEAD base a change made behind an `assume-unchanged` / `skip-worktree` bit between the return and the fold leaves the digest **equal** and the fold would accept bytes nobody returned — the digest cannot catch what the payload cannot see. It then computes the **current** tree digest, which the store binds to the folded return's `postTreeDigest`: a tree that moved between the return and the fold refuses in the store's own words, and the recovery it names is a fresh dispatch, never a fold. Under a HEAD base, staging usually moves the tree too — every change set carrying an untracked path does — so the order is `return` → review (own eyes + the configured review recipe) → a plain gate run → `fold` → `git add`. **The one shape staging does not move** is a tracked-only change passing from the worktree into a **clean** index: the payload concatenates the staged and unstaged diffs, so those bytes are identical either side of `git add` (the uncommitted-state fingerprint's stated blindness to the index↔worktree split). The fold is still honest there — identical payload bytes mean the folded content IS the returned content — so the rule is "**the fold precedes staging**", never "staging refuses the fold by construction". A checkpoint measurement never reads the real index, so staging moves nothing there, while the fold still precedes `git add` by the same rule. `fold` refuses a checkpoint `code` thread the held-session judge names SUBSTITUTED in its own verdict, naming the ledger degrade and retry as recovery, and fails closed on an error epoch or an unreadable ledger.
|
|
@@ -46,6 +46,6 @@ Run **`node ${CLAUDE_SKILL_DIR}/tools/dispatch.mjs <check|advise|register|observ
|
|
|
46
46
|
|
|
47
47
|
**Which ledger the tree-binding verbs use.** For `open`, `return` and `fold` the resolved store must be the **canonical** one, exactly — `<git common dir>/agent-workflow-delegation.jsonl` — and every other store refuses. Three failures collapse into that one equality: a store placed inside the work tree is carried by the payload *and enumerated as an object*, so the metric would count its own bookkeeping as delegated work while the append that follows `postTreeDigest` moves the tree every later fold binds; a store belonging to another repository would measure this tree against a foreign thread, the frozen record schema binding no worktree identity; and a **second** ledger in the same git dir would share artifact names with the first, since those are a function of `{backend, nonce}` alone — so a return could absorb the neighbouring ledger's receipt. One repository, one delegation ledger, which is what resolving to the git *common* dir already meant. `register`, `observe`, `await` and `aggregate` keep the unrestricted override — they bind no tree. Path comparison canonicalizes through symlinks and **fails closed** on any error but `ENOENT` (a path this kit cannot resolve is not one it may approve); the check is repeated immediately before every append, which *narrows* the replacement window rather than closing it — a check-then-write pair is not atomic, and this module defends against a buggy or interrupted producer, never a racing adversary. `open` additionally refuses **pre-spend** when either exec artifact name for its `{backend, nonce}` is already taken: one nonce, one artifact pair. **Stated residual:** two *linked worktrees* of one repository share a common dir by design (the ledger is worktree-shared), so this rule cannot separate them — opening in one linked worktree and returning or folding in another measures the wrong tree, is **forbidden** under the D10 one-writer bar, and is named here rather than mechanized, because the frozen record schema carries no worktree identity to bind it with.
|
|
48
48
|
|
|
49
|
-
**What the fold's binding IS, and its stated residuals.** The binding is **equality of the visible payload** between the return and the fold — never an identity of the tree, and the difference is not academic. Under a HEAD base the payload is an unframed concatenation, so **two different trees can produce the same bytes**: probed live, a single file containing the line `untracked:two.txt` yields the same fingerprint as a tree of two files, and a symlink's target can imitate the marker that opens the next untracked entry. Its UNTRACKED section carries **no git-relevant mode**, so `chmod 0644 → 0755` on an untracked file moves neither the fingerprint nor the enumeration — a blind attribute, not a fourth unsupported content class (a TRACKED file's mode flip rides the diff as `old mode` / `new mode` and does move it). Regular-file content and symlink targets are deliberately **not** subtracted: they are present in the payload, only ambiguously framed, and refusing them would refuse `new` and `symlink`, which is every delegated change set there is. The real fix — a framed payload carrying mode bits — is queued against that frozen surface, since it revalues every stored head-base fingerprint in the family. Under a checkpoint base the payload is one indexed diff: a mode change moves it and no untracked marker line exists. A **receipt is forgeable**, exactly like every record in this family, so what the absorb door defends against is a buggy or interrupted producer, not a hostile one; under a head base the numerator **over-counts a rename** (a delegate's rename arrives as a deletion plus a creation, and no identity matching is done — that machinery was built and deliberately subtracted), so the metric reads optimistic, except in the rename-then-recreate case, which is indeterminate and named in the producer's own header; under a checkpoint base git's own rename detection applies inside the one base-relative layer and a detected rename is counted once as `renamed`; and **D10 is a bar, not a mechanism** — at most ONE in-tree exec dispatch runs at a time, and nothing here refuses a second one.
|
|
49
|
+
**What the fold's binding IS, and its stated residuals.** The binding is **equality of the visible payload** between the return and the fold — never an identity of the tree, and the difference is not academic. Under a HEAD base the payload is an unframed concatenation, so **two different trees can produce the same bytes**: probed live, a single file containing the line `untracked:two.txt` yields the same fingerprint as a tree of two files, and a symlink's target can imitate the marker that opens the next untracked entry. Its UNTRACKED section carries **no git-relevant mode**, so `chmod 0644 → 0755` on an untracked file moves neither the fingerprint nor the enumeration — a blind attribute, not a fourth unsupported content class (a TRACKED file's mode flip rides the diff as `old mode` / `new mode` and does move it). Regular-file content and symlink targets are deliberately **not** subtracted: they are present in the payload, only ambiguously framed, and refusing them would refuse `new` and `symlink`, which is every delegated change set there is. The real fix — a framed payload carrying mode bits — is queued against that frozen surface, since it revalues every stored head-base fingerprint in the family. Under a checkpoint base the payload is one indexed diff: a mode change moves it and no untracked marker line exists. A **receipt is forgeable**, exactly like every record in this family, so what the absorb door defends against is a buggy or interrupted producer, not a hostile one; under a head base the numerator **over-counts a rename** (a delegate's rename arrives as a deletion plus a creation, and no identity matching is done — that machinery was built and deliberately subtracted), so the metric reads optimistic, except in the rename-then-recreate case, which is indeterminate and named in the producer's own header; under a checkpoint base git's own rename detection applies inside the one base-relative layer and a detected rename is counted once as `renamed`; and **D10 is a bar, not a mechanism** — at most ONE in-tree exec dispatch runs at a time, and nothing here refuses a second one, task threads included; `files-overlap` and `mixed-open` additionally refuse conflicting task threads at append time.
|
|
50
50
|
|
|
51
|
-
**Invariants:** writer — appends only to the delegation ledger, `<git common dir>/agent-workflow-delegation.jsonl` (`AW_DELEGATION_STORE` overrides, absolute only), through the store's own lock-serialized append; the store's preflight is the single legality door and this mode adds no second validator · every verb that DERIVES anything from the ledger (`return`, `fold`, `degrade`, `aggregate`) replays the store's preflight over the whole file first and refuses at the first record the append path would have refused, naming its physical line — a verb never computes over a "legal prefix" · **never commits**, never runs a subscription CLI, spawns nothing but git READS — with TWO stated exceptions: `handoff-return` attests MAIN's index with `git write-tree`, which may write a tree OBJECT into the odb (the same probe `land --prepare` itself uses), and checkpoint measurement writes the leaf's OWN temporary index file and forced-add blob objects — never a ref, never the real index; the ledger stays the only thing this mode APPENDS to · the ledger is separate from the review receipts and the flow store, and a line of one family never satisfies a reader of another.
|
|
51
|
+
**Invariants:** writer — appends only to the delegation ledger, `<git common dir>/agent-workflow-delegation.jsonl` (`AW_DELEGATION_STORE` overrides, absolute only), through the store's own lock-serialized append; the store's preflight is the single legality door and this mode adds no second validator · every verb that DERIVES anything from the ledger (`return`, `fold`, `degrade`, `aggregate`) replays the store's preflight over the whole file first and refuses at the first record the append path would have refused, except `files-overlap` and `mixed-open`, which are judged at append time only, naming its physical line — a verb never computes over a "legal prefix" · **never commits**, never runs a subscription CLI, spawns nothing but git READS — with TWO stated exceptions: `handoff-return` attests MAIN's index with `git write-tree`, which may write a tree OBJECT into the odb (the same probe `land --prepare` itself uses), and checkpoint measurement writes the leaf's OWN temporary index file and forced-add blob objects — never a ref, never the real index; the ledger stays the only thing this mode APPENDS to · the ledger is separate from the review receipts and the flow store, and a line of one family never satisfies a reader of another.
|
|
@@ -6,7 +6,7 @@ Read-only **review-receipt checker** (AD-038) — it makes *"reviewed ≠ shippe
|
|
|
6
6
|
|
|
7
7
|
Run `node ${CLAUDE_SKILL_DIR}/tools/review-state.mjs [--check] [--json]`:
|
|
8
8
|
|
|
9
|
-
1. Plain run → the human report: resolved recipe + source, plan-in-flight, tree fingerprint, the `held session: <id> — <n> fold(s) rode it` / `none` / substitution line when configured delegated execution arms it, and per-backend receipt state (current / stale / ungrounded / probe / rejected / missing) with verdict + grounding + timestamp.
|
|
9
|
+
1. Plain run → the human report: resolved recipe + source, plan-in-flight, tree fingerprint, the `held session: <id> — <n> fold(s) rode it` / `none` / substitution line when configured delegated execution arms it (with a task `code` thread of backend `codex` in the commit epoch and no unresolved substitution, `held sessions: <k> chain(s) — <label>: <id> (<n>) · …` is printed instead, one entry per chain, labelled by its brief or `untasked`, with `none` for a chain with no held session), and per-backend receipt state (current / stale / ungrounded / probe / rejected / missing) with verdict + grounding + timestamp.
|
|
10
10
|
2. **`--check`** → the gate exit code. Before the review-recipe early return, a configured `plan-execution.execute = delegated` with a plan in flight and a dirty, fingerprintable tree audits the delegation ledger and refuses a substituted held session; an absent ledger is inert, while an unreadable, malformed, foreign, audit-refused ledger or failed HEAD read fails closed with its own reason. For a head-base thread, the accepted-replacement escape is a `codex-exec` degrade at the substituted return's tree, standing after every later fold, never the review receipt id `codex`. A checkpoint-based thread's substitution closes only by its own ledger `degrade` (which also withdraws the expectation, so the next fold establishes HELD) — no core-evidence degrade lifts it, and the report's recovery hint says so. The remaining **normative exit contract lives in the tool header** (the single home — do not re-enumerate it elsewhere): exit 0 for a CONFIGURED solo recipe (after the held-session arm above) (a computed readiness-degrade NEVER silently becomes solo — it needs the explicit degrade record below), no plan in flight (the `docs/plans` naming convention: `queue.md` and `EXECUTE-`/`FEEDBACK-`/`TASK-`-prefixed or `PROMPT`/`prompt`/`handoff`-carrying names are scratch), a clean tree, a cwd where git ITSELF answers not-a-repository under both discoveries (the ONLY non-work-tree location that passes — `error`, `redirected`, `no-work-tree` and `env-only` refuse by their state name once a receipt could be required), or every recipe-named backend SATISFIED for the current tree. **A clean-tree PASS under a NON-SOLO review obligation is never silent about a latent arm:** when a `reviewed` or `council` recipe is configured, it NAMES every plan in flight and states that this gate arms as soon as the tree is dirty — the condition is discoverable BEFORE it blocks, instead of surfacing at the worst moment (a pending commit, or the landing of a feature worktree when main first turns dirty). Nothing is announced under a configured `solo` recipe or a not-a-repository cwd, where the gate can never arm. **Satisfaction is ship-class-only on the LATEST NORMAL receipt (D3(b)):** per backend, the latest probe-free current-fingerprint receipt is selected FIRST and THEN verdict-checked — only the recognized ship-class vocabulary (`ship` / `ship with nits`) satisfies; a recognized NEGATIVE (`revise` / `rethink` / `rework`) is an authoritative VETO (an earlier ship never survives a later revise); an UNRECOGNIZED verdict (e.g. `unknown` from a dead run) fails CLOSED unconditionally — a later `unknown` never lets an earlier SHIP stand, and a fresh normal re-run supersedes it. **The ONLY review-backend escape is an explicit degrade RECORD** (`core-evidence.mjs degrade --backend <name> --reason "…"`, fingerprint-bound to the current tree) — and never all backends: ≥1 non-degraded ship-class receipt is required whenever ≥1 backend is configured; a malformed evidence store denies the escape fail-closed but never fails an independently-satisfied tree. Exit 1 otherwise — missing, **stale** (every edit the payload can see moves the fingerprint, and no more), ungrounded, vetoed, or unrecognized. Plan/diff receipts and continuations (`agy-review --continue`) are **informational-only**: after a fold, only a **fresh grounded re-run** (`codex-review code`; `agy-review code --facts @f`) restores green. **Probe receipts never attest either:** a `CODEX_PROBE=1` / `AGY_PROBE=1` review runs with the frontier-model/max-effort guard OFF, so the wrapper stamps `probe:true` and this checker excludes it — per receipt, so a real review at the same fingerprint still satisfies. **Silence is not a declaration:** a malformed *or* absent probe marker is rejected fail-closed and stated in the check line. Honest bound: receipts are **not authenticated** (a forger could write `probe:false` as easily as any other field) — like the rest of the receipt this is a self-discipline mechanism, not a security boundary.
|
|
11
11
|
3. **Wire it as a gate by hand OR via the explicit-consent init preview — never without consent (AD-021/D9).** The candidate line for your own `docs/ai/gates.json`: `{ "id": "review-state", "title": "Review receipts current for the uncommitted tree", "cmd": "node <path-to-this-skill>/tools/review-state.mjs --check" }` — with the path your project actually reaches the kit by, QUOTED so a path with spaces survives, executable from the project root. The consent-gated gates-init preview — `node ${CLAUDE_SKILL_DIR}/tools/gates-init.mjs --cwd <project>` (dry-run: it prints the derived entries and writes NOTHING; `--apply --only review-state` writes exactly this one on your explicit yes) — offers exactly this entry, path resolved and quoted, ONLY when your `docs/ai/orchestration.json` declares `reviewed`/`council` on `plan-execution.review` (the slot this checker enforces). The full consent-fill contract is in `${CLAUDE_SKILL_DIR}/references/modes/gates.md`. Once declared, the opt-in `${CLAUDE_SKILL_DIR}/references/modes/hook.md` auto-approves it like any other declared gate — and `run-gates --final` requires this check among its canonical core gates.
|
|
12
12
|
4. **`--await [--timeout <s>]`** (BUGFREE-3 / AD-049) → BLOCK until every recipe-named backend is SATISFIED for the current tree (i.e. until `--check` would PASS), or the bounded timeout elapses (a loud exit 1; default 900s). Run it after dispatching the review bridges to WAIT for their receipts to land instead of hand-polling a pid: the durable completion signal is the **receipt**, never a process event (a harness "completed" notification fires early; a bridge's output late-flushes). It inherits the `--check` decision whole — a backend with a current-tree degrade RECORD stops being waited on (the shared decideCheck), so you never hand-`--await` around a known degrade. A held-session refusal and an **AUTHORITATIVE veto terminate the wait loudly BEFORE the deadline**: neither can be moved by waiting; only the held-session retry/degrade lane or a fresh review can move its corresponding refusal. Still read-only (it re-reads the receipts + the evidence store); solo / no-plan / clean-tree resolve instantly. For waiting on **one dispatch's arrival** (never obligation satisfaction) use the receipt-arrival deadline runner, `${CLAUDE_SKILL_DIR}/references/modes/receipt-deadline.md`.
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
|
|
77
77
|
import { createHash } from 'node:crypto';
|
|
78
78
|
import { SAFE_NONCE_RE, flowCanonicalSerialization } from './flow-record.mjs';
|
|
79
|
+
import { validateTask } from './task-thread.mjs';
|
|
79
80
|
|
|
80
81
|
const deepFreeze = (value) => {
|
|
81
82
|
if (value !== null && typeof value === 'object') {
|
|
@@ -133,7 +134,7 @@ const short = (v) => {
|
|
|
133
134
|
export const DELEGATION_SCHEMA_VERSION = 1;
|
|
134
135
|
export const BASELINE_KINDS = deepFreeze(['head', 'checkpoint']);
|
|
135
136
|
export const HEAD_BASELINE = deepFreeze({ kind: 'head', treeOid: null });
|
|
136
|
-
export const OPTIONAL_FIELDS = deepFreeze({ dispatch: ['baseline'] });
|
|
137
|
+
export const OPTIONAL_FIELDS = deepFreeze({ dispatch: ['baseline', 'task'] });
|
|
137
138
|
const TREE_OID_RE = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
|
|
138
139
|
export const isTreeOid = (v) => typeof v === 'string' && TREE_OID_RE.test(v);
|
|
139
140
|
export const readsBaseline = (dispatch) => Object.hasOwn(dispatch, 'baseline')
|
|
@@ -145,7 +146,7 @@ export const DELEGATION_KINDS = deepFreeze(['pre-registration', 'dispatch', 'ret
|
|
|
145
146
|
// The closed key set per kind (schema + kind are implicit on every record).
|
|
146
147
|
export const DELEGATION_KEY_SETS = deepFreeze({
|
|
147
148
|
'pre-registration': ['waveId', 'stepClasses', 'pairingKey', 'minPerClass', 'meanLThreshold', 'firstPassNum', 'firstPassDen', 'timestamp'],
|
|
148
|
-
dispatch: ['waveId', 'nonce', 'stepClass', 'vehicle', 'backend', 'contractDigest', 'preTreeDigest', 'baselineClean', 'deadlineS', 'retryOf', 'retryIndex', 'retryCap', 'rationale', 'timestamp', 'baseline'],
|
|
149
|
+
dispatch: ['waveId', 'nonce', 'stepClass', 'vehicle', 'backend', 'contractDigest', 'preTreeDigest', 'baselineClean', 'deadlineS', 'retryOf', 'retryIndex', 'retryCap', 'rationale', 'timestamp', 'baseline', 'task'],
|
|
149
150
|
return: ['role', 'backend', 'nonce', 'contractDigest', 'preTreeDigest', 'postTreeDigest', 'diffDigest', 'diffLength', 'reportDigest', 'reportLength', 'bundleDigest', 'bundleLength', 'metric', 'outcome', 'exitStatus', 'sessionId', 'wrapperVersion', 'posture', 'timestamp'],
|
|
150
151
|
fold: ['nonce', 'returnDigest', 'treeDigestAtFold', 'verdict', 'timestamp'],
|
|
151
152
|
observation: ['waveId', 'stepClass', 'scope', 'metric', 'planId', 'phase', 'timestamp'],
|
|
@@ -346,6 +347,7 @@ const FIELD_CHECKS = {
|
|
|
346
347
|
firstPassDen: { ok: (v) => Number.isSafeInteger(v) && v >= 1, want: 'a positive integer first-pass denominator' },
|
|
347
348
|
vehicle: { ok: isPlainObject, want: 'the closed vehicle pair {requested, selected}' },
|
|
348
349
|
baseline: { ok: isPlainObject, want: 'the closed baseline pair {kind, treeOid}' },
|
|
350
|
+
task: { ok: isPlainObject, want: 'the closed task object {brief, files}' },
|
|
349
351
|
// The safe token grammar, not merely non-empty: the backend NAMES an artifact beside the store
|
|
350
352
|
// (the exec receipt and its report), so a name outside this grammar records a dispatch whose own
|
|
351
353
|
// receipt could never be written. One grammar on both sides, or the ledger accepts what the
|
|
@@ -519,6 +521,10 @@ export const validateDelegationRecord = (record) => {
|
|
|
519
521
|
const baseline = validateBaseline('dispatch: baseline', record.baseline);
|
|
520
522
|
if (!baseline.ok) return baseline;
|
|
521
523
|
}
|
|
524
|
+
if (Object.hasOwn(record, 'task')) {
|
|
525
|
+
const closed = checkClosedKeys('dispatch: task', record.task, ['brief', 'files']); if (!closed.ok) return closed;
|
|
526
|
+
const task = validateTask(record.task, readsBaseline(record).kind); if (!task.ok) return refuse(`dispatch: task: ${task.reason}`);
|
|
527
|
+
}
|
|
522
528
|
return vehicle.ok ? validateDispatchCrossFields(record) : vehicle;
|
|
523
529
|
}
|
|
524
530
|
if (record.kind === 'return') return validateReturnCrossFields(record);
|
|
@@ -7,6 +7,9 @@ import {
|
|
|
7
7
|
} from './dispatch-record.mjs';
|
|
8
8
|
import { readRegularFileNoFollow } from './fs-read-nofollow.mjs';
|
|
9
9
|
import { GIT_MAX_BUFFER } from './git-env.mjs';
|
|
10
|
+
import { readsTask, readsInsideEpoch, epochClaims } from './task-thread.mjs';
|
|
11
|
+
import { hasPathOverlap } from './claim-relation.mjs';
|
|
12
|
+
import { HELD_RECEIPT_BACKEND } from './held-session.mjs';
|
|
10
13
|
|
|
11
14
|
export const DELEGATION_STORE_STOP = 'DELEGATION_STORE_STOP';
|
|
12
15
|
export const delegationStoreStop = (message) => Object.assign(new Error(`[agent-workflow-kit] ${message}`), { name: 'DelegationStoreStop', code: DELEGATION_STORE_STOP });
|
|
@@ -127,7 +130,34 @@ const describeClosure = (last) =>
|
|
|
127
130
|
|
|
128
131
|
const WAVE_SCOPED_KINDS = ['dispatch', 'observation', 'degrade'];
|
|
129
132
|
|
|
130
|
-
|
|
133
|
+
const checkTaskClaims = (records, snapshot, head) => {
|
|
134
|
+
if (head.state === 'error') throw stop(`${head.reason}; nothing was written`);
|
|
135
|
+
const task = readsTask(snapshot);
|
|
136
|
+
const claims = epochClaims(records, head, isThreadTerminalRecord);
|
|
137
|
+
if (task === null) {
|
|
138
|
+
const collision = claims.find((claim) => claim.state === 'open'
|
|
139
|
+
|| (claim.state === 'folded' && snapshot.stepClass === 'code' && snapshot.backend === HELD_RECEIPT_BACKEND));
|
|
140
|
+
if (collision !== undefined) {
|
|
141
|
+
throw stop(`mixed-open: untasked dispatch collides with task thread "${collision.nonce}" (${collision.state}); nothing was written`);
|
|
142
|
+
}
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const untasked = records.find((record) => record.kind === 'dispatch' && readsTask(record) === null
|
|
146
|
+
&& readsInsideEpoch(record, head) && delegationThreadState(records, record.nonce).open);
|
|
147
|
+
if (untasked !== undefined) {
|
|
148
|
+
throw stop(`mixed-open: task dispatch collides with open untasked thread "${untasked.nonce}"; nothing was written`);
|
|
149
|
+
}
|
|
150
|
+
for (const claim of claims) {
|
|
151
|
+
if (claim.state === 'folded' && claim.brief === task.brief) continue;
|
|
152
|
+
const shared = [...new Set(task.files.flatMap((path) => claim.files.flatMap((other) =>
|
|
153
|
+
hasPathOverlap(path, other) ? [path, other] : [])))].sort();
|
|
154
|
+
if (shared.length > 0) {
|
|
155
|
+
throw stop(`files-overlap: task dispatch overlaps thread "${claim.nonce}" on ${shared.join(', ')}; nothing was written`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export const delegationSemanticPreflight = ({ records, snapshot, storePath, head = null }) => {
|
|
131
161
|
const digest = canonicalDelegationDigest(snapshot);
|
|
132
162
|
if (records.some((record) => canonicalDelegationDigest(record) === digest)) {
|
|
133
163
|
throw stop(`refusing a canonical duplicate: ${storePath} already carries this exact record (${digest.slice(0, 12)}…), however its keys are ordered — a genuine new record carries new content or a new timestamp; nothing was written`);
|
|
@@ -180,6 +210,9 @@ export const delegationSemanticPreflight = ({ records, snapshot, storePath }) =>
|
|
|
180
210
|
if (base.kind !== priorBase.kind || base.treeOid !== priorBase.treeOid) {
|
|
181
211
|
throw stop(`refusing a retry: its base {kind "${base.kind}", treeOid ${base.treeOid}} differs from its retry origin "${snapshot.retryOf}"'s {kind "${priorBase.kind}", treeOid ${priorBase.treeOid}} — a retry chain is measured against ONE base; nothing was written`);
|
|
182
212
|
}
|
|
213
|
+
if (JSON.stringify(readsTask(snapshot)) !== JSON.stringify(readsTask(prior.dispatch))) {
|
|
214
|
+
throw stop(`refusing a retry: its task differs from its retry origin "${snapshot.retryOf}" in brief or files — a retry keeps the same task; nothing was written`);
|
|
215
|
+
}
|
|
183
216
|
const origin = findRetryChainOrigin(records, prior.dispatch);
|
|
184
217
|
if (snapshot.retryIndex > origin.retryCap) {
|
|
185
218
|
throw stop(`refusing a retry: retryIndex ${snapshot.retryIndex} exceeds the retryCap ${origin.retryCap} recorded on the thread's ORIGIN dispatch ("${origin.nonce}") — a fresh contract never manufactures a fresh retry budget; nothing was written`);
|
|
@@ -188,6 +221,7 @@ export const delegationSemanticPreflight = ({ records, snapshot, storePath }) =>
|
|
|
188
221
|
throw stop(`refusing a retry: it retries a contract-refusal thread and must carry a DIFFERENT contractDigest — an unchanged contract would only be refused again, and a retry loop on one contract is exactly what the cap exists to prevent; nothing was written`);
|
|
189
222
|
}
|
|
190
223
|
}
|
|
224
|
+
if (head !== null) checkTaskClaims(records, snapshot, head);
|
|
191
225
|
return;
|
|
192
226
|
}
|
|
193
227
|
if (state.dispatch === null) {
|
package/tools/dispatch-store.mjs
CHANGED
|
@@ -9,8 +9,10 @@ import {
|
|
|
9
9
|
resolveDelegationStorePath,
|
|
10
10
|
parseDelegationStoreText,
|
|
11
11
|
delegationSemanticPreflight,
|
|
12
|
+
readHeadInstant,
|
|
12
13
|
} from './dispatch-store-read.mjs';
|
|
13
14
|
import { createStoreAppendLane } from './store-append.mjs';
|
|
15
|
+
import { readsTask } from './task-thread.mjs';
|
|
14
16
|
|
|
15
17
|
export {
|
|
16
18
|
DELEGATION_STORE_STOP,
|
|
@@ -52,6 +54,11 @@ const delegationAppendLane = createStoreAppendLane({
|
|
|
52
54
|
export const appendDelegationRecord = ({ cwd = process.cwd(), record, env = process.env, deps = {} } = {}) => {
|
|
53
55
|
const { line, snapshot } = delegationAppendLane.captureRecordSnapshot(record);
|
|
54
56
|
return delegationAppendLane.appendResolvedRecord({
|
|
55
|
-
cwd, env, deps,
|
|
57
|
+
cwd, env, deps, makeRecord: () => ({ line, snapshot }),
|
|
58
|
+
preflight: ({ records, snapshot, line, storePath }) => delegationSemanticPreflight({
|
|
59
|
+
records, snapshot, line, storePath, cwd,
|
|
60
|
+
head: snapshot.kind === 'dispatch' && (readsTask(snapshot) !== null || records.some((record) => readsTask(record) !== null))
|
|
61
|
+
? readHeadInstant(cwd) : null,
|
|
62
|
+
}),
|
|
56
63
|
});
|
|
57
64
|
};
|
package/tools/dispatch.mjs
CHANGED
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
// • a receipt is FORGEABLE, exactly like every record in this family. What the absorb door defends
|
|
55
55
|
// against is a buggy or interrupted producer, not a hostile one.
|
|
56
56
|
// • D10 stands as a bar, not a mechanism: at most ONE in-tree exec dispatch runs at a time, and
|
|
57
|
-
// nothing here refuses a second one.
|
|
57
|
+
// nothing here refuses a second one, task threads included; files-overlap and mixed-open additionally refuse conflicting task threads at append time.
|
|
58
58
|
// • `await` observes ARRIVAL and nothing else: an expiry never authorizes the next writer, and the
|
|
59
59
|
// verb releases no slot it never held. Whether the run may be ABSORBED stays `return`'s question. A parallel-write story is not this plan's.
|
|
60
60
|
//
|
|
@@ -99,6 +99,8 @@ import {
|
|
|
99
99
|
resolveRepoRoot, measureScope, ratio, formatRatio, buildObservationRecord,
|
|
100
100
|
} from './observation-builder.mjs';
|
|
101
101
|
import { handoffReturn, HANDOFF_SLUG_RE } from './worktree-handoff-return.mjs';
|
|
102
|
+
import { parseBrief } from './task-brief.mjs';
|
|
103
|
+
import { byteOrder, validateTask } from './task-thread.mjs';
|
|
102
104
|
|
|
103
105
|
const usageFail = (message) => Object.assign(new Error(message), { exitCode: 2 });
|
|
104
106
|
|
|
@@ -145,6 +147,7 @@ export const OPEN_FLAG_FIELDS = Object.freeze({
|
|
|
145
147
|
'--rationale': 'rationale',
|
|
146
148
|
'--retry-of': 'retryOf',
|
|
147
149
|
'--checkpoint': 'baseline.treeOid',
|
|
150
|
+
'--task': 'task',
|
|
148
151
|
});
|
|
149
152
|
// COPIED from the contract header at mint and bound by contractDigest (D3): a dispatch that
|
|
150
153
|
// disagreed with the header it claims to carry is refused by checkDispatchMintConsistency.
|
|
@@ -476,7 +479,7 @@ const runObserve = ({ baseCwd, env, argv, now }) => {
|
|
|
476
479
|
// some other producer wrote — and a verb computing over such a ledger inherits its lie. So every
|
|
477
480
|
// verb that DERIVES anything from the store (`return`, `fold`, `degrade`, `aggregate`) reads it
|
|
478
481
|
// through this one door, which replays the store's own preflight in file order and stops at the
|
|
479
|
-
// first record the append path would have refused, naming its physical line.
|
|
482
|
+
// first record the append path would have refused, except files-overlap and mixed-open, which are judged at append time only, naming its physical line.
|
|
480
483
|
//
|
|
481
484
|
// `open` deliberately has no read-side audit: it derives nothing from the ledger. Its retry and wave
|
|
482
485
|
// rules are evaluated by the store, on the snapshot under the lock, which is the only place they can
|
|
@@ -539,6 +542,22 @@ const runOpen = ({ baseCwd, env, argv, now }) => {
|
|
|
539
542
|
if (!resolved.ok) return refusal('open', resolved.reason);
|
|
540
543
|
}
|
|
541
544
|
const base = oid === undefined ? HEAD_BASELINE : { kind: 'checkpoint', treeOid: oid };
|
|
545
|
+
const brief = values['--task'];
|
|
546
|
+
let task = null;
|
|
547
|
+
if (brief !== undefined) {
|
|
548
|
+
if (oid === undefined) return refusal('open', 'task-base: --task requires --checkpoint; nothing was written');
|
|
549
|
+
const root = resolveRepoRoot(cwd);
|
|
550
|
+
if (root === null) return refusal('open', 'not inside a git work tree — a dispatch is opened against a repository (fail closed); nothing was written');
|
|
551
|
+
const read = readRegularFileNoFollow(resolve(root, brief));
|
|
552
|
+
if (read.outcome !== 'ok') {
|
|
553
|
+
return refusal('open', `cannot read ${brief} (${read.code ?? read.className ?? read.outcome}); nothing was written`);
|
|
554
|
+
}
|
|
555
|
+
const parsed = parseBrief(read.content);
|
|
556
|
+
if (!parsed.ok) return refusal('open', parsed.reason);
|
|
557
|
+
task = { brief, files: [...new Set(parsed.files.map(({ path }) => path))].sort(byteOrder) };
|
|
558
|
+
const checked = validateTask(task, base.kind);
|
|
559
|
+
if (!checked.ok) return refusal('open', checked.reason);
|
|
560
|
+
}
|
|
542
561
|
const baselineClean = isCleanAgainstBase(cwd, base);
|
|
543
562
|
if (baselineClean === null) {
|
|
544
563
|
return refusal('open', 'the working state could not be probed, so the baseline is undecidable — a dispatch never records a guessed baseline, and outside a git work tree there is no tree to fingerprint either (fail closed); nothing was written');
|
|
@@ -571,6 +590,7 @@ const runOpen = ({ baseCwd, env, argv, now }) => {
|
|
|
571
590
|
preTreeDigest,
|
|
572
591
|
baselineClean,
|
|
573
592
|
baseline: { kind: base.kind, treeOid: base.treeOid },
|
|
593
|
+
...(task === null ? {} : { task }),
|
|
574
594
|
deadlineS: contract.deadlineS,
|
|
575
595
|
retryOf: values['--retry-of'] ?? null,
|
|
576
596
|
retryIndex: contract.retry.index,
|
|
@@ -1600,7 +1620,7 @@ Usage:
|
|
|
1600
1620
|
[--denominator-bytes <n>] [--cwd <dir>]
|
|
1601
1621
|
node dispatch.mjs open --contract <dispatch-file> --wave <id> --backend <name>
|
|
1602
1622
|
--rationale <text> --wrapper-cap-s <n> --kill-grace-s <n>
|
|
1603
|
-
[--checkpoint <oid>] [--retry-of <nonce>] [--cwd <dir>]
|
|
1623
|
+
[--checkpoint <oid>] [--task <brief>] [--retry-of <nonce>] [--cwd <dir>]
|
|
1604
1624
|
node dispatch.mjs await --nonce <n> [--timeout <s>] [--cwd <dir>]
|
|
1605
1625
|
node dispatch.mjs return --nonce <n> [--outcome <o>]
|
|
1606
1626
|
[--no-receipt --exit-status <n>] [--cwd <dir>]
|
|
@@ -1652,6 +1672,7 @@ refusal from the store verbatim.
|
|
|
1652
1672
|
--checkpoint <oid> records a resolvable TREE object of exactly 40 or 64 lowercase hex characters
|
|
1653
1673
|
(a commit, blob, tag or unknown id refuses by name); the base rides the record and return/fold read
|
|
1654
1674
|
it there, while a checkpoint CLEAN line names the base.
|
|
1675
|
+
--task records the brief's path and its byte-ordered Files, requires --checkpoint (task-base), refuses a brief the parser refuses by the parser's name, and the store refuses files-overlap and mixed-open at append time.
|
|
1655
1676
|
|
|
1656
1677
|
THE LEDGER a tree-binding verb uses is the CANONICAL one, exactly: <git common dir>/
|
|
1657
1678
|
agent-workflow-delegation.jsonl. A store inside the work tree is measured as part of the change set
|
|
@@ -1780,7 +1801,7 @@ arrives as a deletion plus a creation, over-counting a plain rename; under a che
|
|
|
1780
1801
|
rename detection applies inside the one base-relative layer and a detected rename is counted once.
|
|
1781
1802
|
A receipt is forgeable exactly like every record here;
|
|
1782
1803
|
and D10 stands as a BAR, not a mechanism — at most one in-tree exec dispatch at a time, and nothing
|
|
1783
|
-
refuses a second.
|
|
1804
|
+
refuses a second, task threads included; files-overlap and mixed-open additionally refuse conflicting task threads at append time.
|
|
1784
1805
|
|
|
1785
1806
|
Never commits, never runs a subscription CLI, spawns nothing but git READS — with TWO stated exceptions: handoff-return,
|
|
1786
1807
|
which attests MAIN's index with git write-tree: that may write a tree OBJECT into the odb and moves
|
package/tools/held-session.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { escapeForDisplay, isRenderableLine, shellQuoteArg } from './repo-lex.mj
|
|
|
2
2
|
import { wrapperCmdFor } from './detect-backends.mjs';
|
|
3
3
|
import { DISPLAY_ALIASES } from './recipes.mjs';
|
|
4
4
|
import { readsBaseline, TERMINAL_RETURN_OUTCOMES } from './dispatch-record.mjs';
|
|
5
|
+
import { readsInsideEpoch, readsTask } from './task-thread.mjs';
|
|
5
6
|
|
|
6
7
|
const CODE_STEP = 'code';
|
|
7
8
|
const FOLD_KIND = 'fold';
|
|
@@ -13,12 +14,6 @@ const UNPOPULATED_HELD_ID = '<held id>';
|
|
|
13
14
|
export const HELD_RECEIPT_BACKEND = DISPLAY_ALIASES[EXECUTE_BACKEND];
|
|
14
15
|
export const HELD_EXECUTE_WRAPPER = wrapperCmdFor(EXECUTE_BACKEND, 'execute');
|
|
15
16
|
|
|
16
|
-
const readsInsideEpoch = (dispatch, head) => {
|
|
17
|
-
if (head.state === 'unborn') return true;
|
|
18
|
-
const instant = Date.parse(dispatch.timestamp);
|
|
19
|
-
return Number.isFinite(instant) && Math.floor(instant / 1000) > head.seconds;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
17
|
const updatesThread = (threads, nonce, update) =>
|
|
23
18
|
threads.map((thread) => (thread.nonce === nonce ? { ...thread, ...update } : thread));
|
|
24
19
|
|
|
@@ -101,15 +96,7 @@ const countsHeldFolds = (records, epochNonces, heldId) => {
|
|
|
101
96
|
}).length;
|
|
102
97
|
};
|
|
103
98
|
|
|
104
|
-
|
|
105
|
-
if (head.state === 'error') {
|
|
106
|
-
return { state: 'error', cause: 'head', reason: head.reason, heldId: null, folds: 0, substitution: null, threads: [], open: [] };
|
|
107
|
-
}
|
|
108
|
-
const dispatches = records.filter((record) =>
|
|
109
|
-
record.kind === 'dispatch'
|
|
110
|
-
&& record.stepClass === CODE_STEP
|
|
111
|
-
&& record.backend === backend
|
|
112
|
-
&& readsInsideEpoch(record, head));
|
|
99
|
+
const judgeChain = (records, dispatches, degrades) => {
|
|
113
100
|
const epochNonces = new Set(dispatches.map((dispatch) => dispatch.nonce));
|
|
114
101
|
const initial = { epochNonces, dispatches: [], returns: [], heldId: null, substitutions: [], threads: [], open: [] };
|
|
115
102
|
const accumulated = records.reduce(accumulatesFacts(degrades), initial);
|
|
@@ -125,6 +112,44 @@ export const judgeHeldSession = (records, { head, backend, degrades = [] }) => {
|
|
|
125
112
|
};
|
|
126
113
|
};
|
|
127
114
|
|
|
115
|
+
export const judgeHeldSession = (records, { head, backend, degrades = [] }) => {
|
|
116
|
+
if (head.state === 'error') {
|
|
117
|
+
return { state: 'error', cause: 'head', reason: head.reason, heldId: null, folds: 0, substitution: null, threads: [], open: [] };
|
|
118
|
+
}
|
|
119
|
+
const dispatches = records.filter((record) =>
|
|
120
|
+
record.kind === 'dispatch'
|
|
121
|
+
&& record.stepClass === CODE_STEP
|
|
122
|
+
&& record.backend === backend
|
|
123
|
+
&& readsInsideEpoch(record, head));
|
|
124
|
+
if (!dispatches.some((dispatch) => readsTask(dispatch) !== null)) return judgeChain(records, dispatches, degrades);
|
|
125
|
+
const groups = new Map();
|
|
126
|
+
for (const dispatch of dispatches) {
|
|
127
|
+
const key = readsTask(dispatch)?.brief ?? null;
|
|
128
|
+
if (!groups.has(key)) groups.set(key, []);
|
|
129
|
+
groups.get(key).push(dispatch);
|
|
130
|
+
}
|
|
131
|
+
const reports = new Map([...groups].map(([key, entries]) => {
|
|
132
|
+
const nonces = new Set(entries.map((dispatch) => dispatch.nonce));
|
|
133
|
+
return [key, judgeChain(records.filter((record) => nonces.has(record.nonce)), entries, degrades)];
|
|
134
|
+
}));
|
|
135
|
+
const untasked = reports.get(null);
|
|
136
|
+
const threads = new Map([...reports].flatMap(([chainKey, report]) =>
|
|
137
|
+
report.threads.map((thread) => [thread.nonce, { ...thread, chainKey }])));
|
|
138
|
+
const substitutions = new Map([...reports.values()]
|
|
139
|
+
.filter((report) => report.substitution !== null)
|
|
140
|
+
.map((report) => [report.substitution.nonce, report.substitution]));
|
|
141
|
+
const firstReturn = records.find((record) => record.kind === RETURN_KIND && substitutions.has(record.nonce));
|
|
142
|
+
return {
|
|
143
|
+
state: 'ok',
|
|
144
|
+
heldId: untasked?.heldId ?? null,
|
|
145
|
+
folds: untasked?.folds ?? 0,
|
|
146
|
+
substitution: firstReturn === undefined ? null : substitutions.get(firstReturn.nonce),
|
|
147
|
+
threads: dispatches.map((dispatch) => threads.get(dispatch.nonce)),
|
|
148
|
+
open: untasked?.open ?? [],
|
|
149
|
+
chains: [...reports].map(([key, { heldId, folds, open }]) => ({ key, heldId, folds, open })),
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
|
|
128
153
|
export const threadVerdict = (facts, nonce) => facts.threads.find((thread) => thread.nonce === nonce) ?? null;
|
|
129
154
|
|
|
130
155
|
export const judgeLedger = (ledger, { backend, degrades = [] }) => {
|
|
@@ -150,6 +175,11 @@ export const decideHeldSession = (facts) => {
|
|
|
150
175
|
const reason = `delegated code thread "${nonce}" substituted held session "${escapeForDisplay(expectedId)}" with "${escapeForDisplay(actualId)}"`;
|
|
151
176
|
return { code: 1, reason, line: `held session: SUBSTITUTED — ${reason}` };
|
|
152
177
|
}
|
|
178
|
+
if (facts.chains !== undefined) {
|
|
179
|
+
const entries = facts.chains.map(({ key, heldId, folds }) =>
|
|
180
|
+
`${key === null ? 'untasked' : escapeForDisplay(key)}: ${heldId === null ? 'none' : escapeForDisplay(heldId)} (${folds})`);
|
|
181
|
+
return { code: 0, reason: 'task chains have no unresolved substitution', line: `held sessions: ${facts.chains.length} chain(s) — ${entries.join(' · ')}` };
|
|
182
|
+
}
|
|
153
183
|
if (facts.heldId === null) return { code: 0, reason: 'no held session stands: no folded code thread established one in this commit epoch, or the last one was withdrawn by a checkpoint thread\'s ledger degrade', line: 'held session: none' };
|
|
154
184
|
const heldId = escapeForDisplay(facts.heldId);
|
|
155
185
|
return { code: 0, reason: `held session "${heldId}" is continuous`, line: `held session: ${heldId} — ${facts.folds} fold(s) rode it` };
|
|
@@ -164,15 +194,24 @@ const describesLaneCaveat = (facts) => {
|
|
|
164
194
|
return null;
|
|
165
195
|
};
|
|
166
196
|
|
|
197
|
+
const chainLaneLines = (facts, chain) => {
|
|
198
|
+
const substitution = facts.threads.find((thread) => thread.chainKey === chain.key && thread.substituted) ?? null;
|
|
199
|
+
const caveat = describesLaneCaveat({ state: facts.state, heldId: chain.heldId, substitution });
|
|
200
|
+
const task = chain.key === null ? '' : ` (task ${escapeForDisplay(chain.key)})`;
|
|
201
|
+
if (caveat !== null) return [` caveat: ${caveat}${task}`];
|
|
202
|
+
return [` run: ${HELD_EXECUTE_WRAPPER} --resume ${shellQuoteArg(chain.heldId)} --nonce <nonce> <fold-brief>${task}`];
|
|
203
|
+
};
|
|
204
|
+
|
|
167
205
|
export const foldLaneLines = (facts) => {
|
|
168
|
-
const caveat = describesLaneCaveat(facts);
|
|
169
|
-
const heldId = caveat === null ? shellQuoteArg(facts.heldId) : UNPOPULATED_HELD_ID;
|
|
170
206
|
const lines = [
|
|
171
207
|
'Fold lane (execute = delegated) — a fold rides the delegate\'s HELD session:',
|
|
172
|
-
` run: ${HELD_EXECUTE_WRAPPER} --resume ${heldId} --nonce <nonce> <fold-brief>`,
|
|
173
208
|
' the fold brief is a dispatch file carrying the finding and the accepted fold; dispatch open precedes the run, then dispatch return and fold follow it',
|
|
174
209
|
' the orchestrator runs the suites, verifies the returned diff, re-mints the red-proofs and owns the commit',
|
|
175
210
|
' a fresh session is a forbidden substitution; a retry of a failed thread or, for a head base, a recorded execute degrade is the exception (a checkpoint thread\'s substitution closes by its ledger degrade); the wrapper sidecar is never read',
|
|
176
211
|
];
|
|
212
|
+
if (facts.chains !== undefined) return [...lines, ...facts.chains.flatMap((chain) => chainLaneLines(facts, chain))];
|
|
213
|
+
const caveat = describesLaneCaveat(facts);
|
|
214
|
+
const heldId = caveat === null ? shellQuoteArg(facts.heldId) : UNPOPULATED_HELD_ID;
|
|
215
|
+
lines.splice(1, 0, ` run: ${HELD_EXECUTE_WRAPPER} --resume ${heldId} --nonce <nonce> <fold-brief>`);
|
|
177
216
|
return caveat === null ? lines : [...lines, ` caveat: ${caveat}`];
|
|
178
217
|
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { hasPathOverlap } from './claim-relation.mjs';
|
|
2
|
+
|
|
3
|
+
const TASK_BRIEF = /^docs\/plans\/TASK-[^/]+-T[1-9][0-9]*\.md$/u;
|
|
4
|
+
const INVALID_SEGMENTS = Object.freeze(['', '.', '..', '.git']);
|
|
5
|
+
const HEAD_BASELINE = Object.freeze({ kind: 'head', treeOid: null });
|
|
6
|
+
|
|
7
|
+
export const byteOrder = (a, b) => Buffer.compare(Buffer.from(a), Buffer.from(b));
|
|
8
|
+
|
|
9
|
+
export const readsTask = (dispatch) => Object.hasOwn(dispatch, 'task')
|
|
10
|
+
? { brief: dispatch.task.brief, files: [...dispatch.task.files] }
|
|
11
|
+
: null;
|
|
12
|
+
|
|
13
|
+
export const validateTask = (task, baseKind) => {
|
|
14
|
+
if (typeof task.brief !== 'string' || !TASK_BRIEF.test(task.brief)) {
|
|
15
|
+
return { ok: false, reason: 'task-brief: expected docs/plans/TASK-<stem>-T<n>.md with a positive task number' };
|
|
16
|
+
}
|
|
17
|
+
if (!Array.isArray(task.files) || task.files.length === 0) {
|
|
18
|
+
return { ok: false, reason: 'task-files: expected a non-empty array of paths' };
|
|
19
|
+
}
|
|
20
|
+
for (let index = 0; index < task.files.length; index += 1) {
|
|
21
|
+
const path = task.files[index];
|
|
22
|
+
if (typeof path !== 'string' || path.split('/').some((segment) => INVALID_SEGMENTS.includes(segment))) {
|
|
23
|
+
return { ok: false, reason: 'task-files: expected normalized repo-relative paths without empty, dot or .git segments' };
|
|
24
|
+
}
|
|
25
|
+
if (index > 0 && byteOrder(task.files[index - 1], path) >= 0) {
|
|
26
|
+
return { ok: false, reason: 'task-files: paths must be distinct and in byte order' };
|
|
27
|
+
}
|
|
28
|
+
if (task.files.slice(0, index).some((earlier) => hasPathOverlap(earlier, path))) {
|
|
29
|
+
return { ok: false, reason: 'task-files: one path is a prefix of another' };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (baseKind === 'head') {
|
|
33
|
+
return { ok: false, reason: 'task-base: a task requires a checkpoint baseline' };
|
|
34
|
+
}
|
|
35
|
+
return { ok: true };
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const readsInsideEpoch = (dispatch, head) => {
|
|
39
|
+
if (head.state === 'unborn') return true;
|
|
40
|
+
const instant = Date.parse(dispatch.timestamp);
|
|
41
|
+
return Number.isFinite(instant) && Math.floor(instant / 1000) > head.seconds;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const collectClaims = (records, head, isTerminal) => {
|
|
45
|
+
const claims = [];
|
|
46
|
+
records.forEach((dispatch, index) => {
|
|
47
|
+
if (dispatch.kind !== 'dispatch' || !readsInsideEpoch(dispatch, head)) return;
|
|
48
|
+
const task = readsTask(dispatch);
|
|
49
|
+
if (task === null) return;
|
|
50
|
+
const later = records.slice(index + 1).filter((record) => record.nonce === dispatch.nonce);
|
|
51
|
+
const folded = later.some((record) => record.kind === 'fold');
|
|
52
|
+
if (!folded && later.some(isTerminal)) return;
|
|
53
|
+
// Keep the baseline reader local to preserve the acyclic ledger boundary.
|
|
54
|
+
const baseline = Object.hasOwn(dispatch, 'baseline') ? dispatch.baseline : HEAD_BASELINE;
|
|
55
|
+
claims.push({
|
|
56
|
+
nonce: dispatch.nonce, brief: task.brief, files: task.files,
|
|
57
|
+
state: folded ? 'folded' : 'open', treeOid: baseline.treeOid,
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
return claims;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const claimedPaths = (records, treeOid, head, isTerminal) => [...new Set(
|
|
64
|
+
collectClaims(records, head, isTerminal)
|
|
65
|
+
.filter((claim) => claim.treeOid === treeOid)
|
|
66
|
+
.flatMap((claim) => claim.files),
|
|
67
|
+
)].sort(byteOrder);
|
|
68
|
+
|
|
69
|
+
export const epochClaims = (records, head, isTerminal) => collectClaims(records, head, isTerminal)
|
|
70
|
+
.map(({ nonce, brief, files, state }) => ({ nonce, brief, files, state }));
|