Orchestration enforced by the tool-use hooks: direct-work meter, delegation guard, automatic silent fallback, recorded delegations, repeated-failure refusal, all-tool hook registration; integrated with the contract guard
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
commit
7ff5a33462
42 files changed
+4444
-173
No files matched your search
@@ -341,6 +341,64 @@ worker).
|
||||
- `sisi delegate --brief FILE …` still runs a worker through its own CLI when the host has no
|
||||
delegation of its own.
|
||||
|
||||
**Enforcement** (`sisi/orchestration.py`, `sisi/fallback.py`; host tool names in `canon/orchestration-tools.json`).
|
||||
The before- and after-tool hooks run for every tool, not only the shell, and keep a per-session,
|
||||
per-turn meter in the scratch store (`sessions/<id>.meter.json`, under a file lock; every counted event is
|
||||
also appended to `orchestration.jsonl`). It meters main threads only: a session the host marks as a subagent,
|
||||
one whose first prompt opens with the brief template's first line, and one started by `sisi delegate` are
|
||||
workers and are never counted or refused; neither is anything refused when no usable worker other than the
|
||||
session's own model exists. Every entry point fails open.
|
||||
|
||||
- **Direct-work budget.** Every tool call that is not a delegation, the question dialog, a planning or to-do
|
||||
tool, a message or a `sisi` command counts, with the characters of its result. Past `orchestrate.direct_calls`
|
||||
(6) or `orchestrate.direct_chars` (30000) the next counted call is refused with at most 12 lines: the count,
|
||||
rule 6, the router's pick for reading and for building (taken from the routing code, with its mechanism
|
||||
line) and two ways on: delegate with a brief, or `sisi unit direct "<reason>"`. A specific reason (a generic
|
||||
one is refused) extends the turn by `orchestrate.extension` (10) calls and the matching share of characters;
|
||||
each extension and its reason is stored and shown by `sisi status`. The turn starts again at each prompt (a
|
||||
host's notice about a background worker is not a prompt) and when the gate lets the turn end.
|
||||
- **Delegation guard.** A delegation that names no model, or the session's own, is refused with the router's
|
||||
pick; an allowed one is checked with `brief.check` (advice only) and written to the ledger as a pending run
|
||||
(worker, project, session, start), completed with minutes and tokens when the result reports them, or, for an
|
||||
async launch, when the host's completion notice arrives as a prompt. The gate asks once per set of finished,
|
||||
unjudged runs for the judgements.
|
||||
- **The router is asked first.** `sisi route` writes a routing decision for the session (kind, difficulty
|
||||
guess, pick, time). The first delegation with no decision inside `orchestrate.route_window_min` (15) is
|
||||
refused once; afterwards the pending run carries the kind and difficulty, so `sisi delegate judge ID` needs
|
||||
only the outcome and the check. A worker other than the router's pick is allowed and recorded
|
||||
(`chosen_against_route`); `sisi workers` shows how often and how those turned out (too few under five).
|
||||
`sisi route --retry-of ID` keeps the same worker with an instruction to improve the brief after the first
|
||||
rejection and then moves to a worker whose evidence is strictly better (`routing.retry_choice`: the cheapest
|
||||
capable one with better evidence, else the strongest known usable one) after a second.
|
||||
- **One before-tool path, one refusal at a time.** `sisi/watch.py` runs, for every tool: workers and subagents
|
||||
are exempt from all of it; then the contract guard (a call that would change a project file, or delegate a
|
||||
build, with no valid unit: rule 3); then the delegation guard (a model is named and is not the main thread's
|
||||
own; a routing decision exists); then the direct-work budget. The agent sees only the first refusal in that
|
||||
order, so an agent told to delegate is never refused afterwards for a contract it was not told about. A
|
||||
refused call is not counted by the meter. Every stage fails open on its own.
|
||||
- **Repeat failure.** The fourth identical failing shell command (whitespace-normalised) with no file changed
|
||||
in between is refused once (rule 5).
|
||||
- **Unavailable workers.** A limit, quota, login or connection failure arriving as a delegation result or as a
|
||||
host notice is classified (`workers.classify_failure`), the worker's provider (or just the model) is marked
|
||||
down until the reset time the message names, its pending run is marked `superseded` (never asked to be
|
||||
judged), and the agent gets at most six lines: the router's next worker for the same kind of work, to fall
|
||||
back now with the same brief, not to ask and not to report it (worker availability is internal, SPEC 9.7 and
|
||||
17), and to cancel the failed task. A question-dialog call right after is refused once; ending the turn with
|
||||
no fallback started is sent back (twice at most); a final message naming the failed worker or the failure is
|
||||
sent back once. All state-based. The person hears of it only when nothing usable is left or the outcome or
|
||||
its timing changes for them.
|
||||
- **New workers.** A model discovery finds that the previous one did not have is named once at session start
|
||||
as unproven (low-stakes work first, checked more carefully); never one whose id marks a tier that trains on
|
||||
its prompts.
|
||||
- **The record.** The unit record gains an `orchestration` part, and the scorecard's parallelism dimension the
|
||||
same values, each class `measured`: direct calls and characters, refusals, extensions with reasons,
|
||||
delegations started, judged and unjudged, and the share of tool calls delegated. `sisi status` prints it for
|
||||
the unit in progress too. `sisi rule 6` lists what is enforced.
|
||||
- **Hosts.** Claude Code: the meter can refuse (observed live). Codex, Gemini and Cursor have before-tool
|
||||
events and are wired for every tool; the refusal is exit status 2 with the reason as the host documents it,
|
||||
not run live here. Copilot only counts. Hosts with no before-tool hook (Qwen, Pi, OpenCode and the
|
||||
rulebook-only tools) cannot run the meter; `sisi doctor` says which.
|
||||
|
||||
The owner's hand-written orchestrator (`orch.py`, its ledger, and the section of his Claude
|
||||
instructions) is replaced by this. Its ledger is merged into the user store with a row count
|
||||
check, then it is removed.
|
||||
|
||||
@@ -19,6 +19,27 @@ atomically, so a running tool never sees a half-written copy: a process that has
|
||||
keeps running the release it started with. `sisi doctor` shows which copy is live and
|
||||
whether the source folder is ahead of it.
|
||||
|
||||
## The live orchestration check
|
||||
|
||||
Before any release that touches the hooks or the rulebook, run
|
||||
|
||||
python3 tools/live_orchestration_check.py
|
||||
|
||||
It starts the host's command-line tool headless with its least expensive model in small temporary
|
||||
projects, with the hooks from this checkout and a temporary `SISI_DATA` and `SISI_STATE` (the real sisi data is
|
||||
never read or written; the script asserts that it did not change). Scenario 3 starts from a project with no
|
||||
open unit and a task that needs more than six calls, with a witness hook recording whether a valid unit stood
|
||||
behind each call: no file may change before one does, and the agent must meet the guards in the order the rules
|
||||
give (the contract before the budget), each refusal in at most twelve lines. `--model NAME` sets the main
|
||||
thread's model. Scenario 1 asserts that the meter refused a
|
||||
tool call with its message, that the session then ran `sisi route` and delegated with a named model or recorded
|
||||
a reason with `sisi unit direct`, and that the ledger or events hold the matching record. Scenario 2 uses a fake
|
||||
provider that always answers with a quota error and a reset time: the provider must be marked down until that
|
||||
time, the session must go on with another worker, never call the question dialog and never mention the
|
||||
failure in its final message. It costs a few cents and needs the host's login, so it is not part of the unit
|
||||
suite; synthetic hook input is what let an earlier release ship broken. If the agent ignores a refusal or the
|
||||
host does not honour it, that is a finding: fix the hook output, do not weaken the assertion.
|
||||
|
||||
## Make a release
|
||||
|
||||
Run from the clone (a release is made from the running launcher's folder):
|
||||
|
||||
+23
-3
@@ -29,13 +29,33 @@ between each tool's hook JSON and the gate lives in `sisi/hookio.py`; the adapte
|
||||
skills shipped under `canon/skills` into `~/.agents/skills`; `sisi doctor` reports the linked
|
||||
state. Hooks fail open: any error lets the agent finish. Where a tool's hook input has no transcript path, the gate falls back to its pre-attribution behaviour (tree-change based, with no per-session edit attribution). Shell commands are attributed by measurement, not by their text, wherever the tool has confirmed before/after tool events (`sisi watch` takes a stat-only tree snapshot before and after the command and attributes the paths that changed to the session; provably read-only commands skip the pair); tools without confirmed before/after tool events keep the command-text classifier described in [docs/design.md](design.md).
|
||||
|
||||
## The orchestration meter, per tool
|
||||
|
||||
The before- and after-tool hooks count the main thread's direct tool calls and refuse past a budget (rule 6,
|
||||
[design.md](design.md) section 9). `sisi doctor` prints what it can do in each tool:
|
||||
|
||||
| tool | meter | evidence |
|
||||
|---|---|---|
|
||||
| Claude Code | counts and refuses every tool (permission-deny output), delegation guard, fallback | observed live (`tools/live_orchestration_check.py`) |
|
||||
| Codex CLI | counts and can refuse every tool (exit status 2 with the reason) | the host's hook documentation; not run live here |
|
||||
| Gemini CLI | counts and can refuse every tool (exit status 2) | documentation; not run live |
|
||||
| Cursor | counts and can refuse every tool (exit status 2) | documentation; not run live |
|
||||
| GitHub Copilot CLI | only counts: its refusal contract is not confirmed | not run live |
|
||||
| Qwen, Pi, OpenCode, Muse, Grok, Crush and the rulebook-only tools | cannot run: no before-tool hook is wired | see each section |
|
||||
|
||||
Host tool names (delegation, question dialog, planning, messaging) are data in
|
||||
`canon/orchestration-tools.json`; a tool named nowhere there still counts. Only Claude Code's delegation tool is
|
||||
named for the guard and the fallback; elsewhere delegation goes through `sisi delegate`, which is exempt.
|
||||
|
||||
## Claude Code
|
||||
|
||||
Fully wired, as before: an `@import` line in `~/.claude/CLAUDE.md`, `SessionStart` → `sisi tick`,
|
||||
`UserPromptSubmit` → `sisi prompt` (the matching recipe and lessons for the human's request, as
|
||||
added context; silent when nothing strictly matches, and never able to block a turn),
|
||||
`Stop`/`SubagentStop` → `sisi gate` (blocking), and `PreToolUse`/`PostToolUse` with matcher `Bash` →
|
||||
`sisi watch` (before/after tree measurement) in `~/.claude/settings.json`. The gate also enforces
|
||||
`Stop`/`SubagentStop` → `sisi gate` (blocking), and `PreToolUse`/`PostToolUse`/`PostToolUseFailure` with no
|
||||
matcher (every tool) → `sisi watch` (the orchestration meter, and before/after tree measurement for shell
|
||||
commands) in `~/.claude/settings.json`. An installation from an earlier release (shell-only matchers) is
|
||||
changed by `sisi install` and by `sisi update`, span-preserving; `sisi uninstall` restores the original bytes. The gate also enforces
|
||||
the question-dialog rule here: `AskUserQuestion` exists and the transcript is readable, so ending a
|
||||
turn by asking in reply text without using the dialog is sent back once. Evidence: the hooks
|
||||
reference documents `UserPromptSubmit` and its added-context output. Nothing for you to do.
|
||||
@@ -54,7 +74,7 @@ Rulebook symlink at `~/.codex/AGENTS.md` (or `$CODEX_HOME/AGENTS.md`), plus hook
|
||||
`~/.codex/hooks.json`: `SessionStart` → tick, `UserPromptSubmit` → prompt (the hooks page documents
|
||||
the event and its added-context output; it needs the same one-time trust below),
|
||||
`Stop`/`SubagentStop` → gate,
|
||||
`PreToolUse`/`PostToolUse` (matcher `Bash`) → `sisi watch`, blocking with
|
||||
`PreToolUse`/`PostToolUse` (every tool) → `sisi watch`, blocking with
|
||||
`{"decision":"block","reason":...}`. One step is yours: Codex only runs hooks you have trusted, by exact
|
||||
definition hash. After `sisi install`, open Codex, run `/hooks`, and trust the sisi hooks; repeat after
|
||||
any change to the hook commands (for example after moving the sisi clone). `sisi doctor` cannot verify
|
||||
|
||||
@@ -92,6 +92,27 @@ through to the next choice, and quality is untouched. Poor work is a rejected ju
|
||||
never marks a worker down. No approval- or sandbox-switching flag is passed unless the config
|
||||
allows it per tool (`workers.allow_bypass`).
|
||||
|
||||
## Orchestration the hooks enforce
|
||||
|
||||
`sisi route` records the session's routing decision (kind, difficulty guess, pick). A delegation started with
|
||||
the host's own tool is written to the ledger by the hooks as a pending run with that kind and difficulty, and
|
||||
completed when it returns; `sisi delegate judge ID --outcome O --check C` then needs nothing else. A worker
|
||||
other than the router's pick is recorded as an override, and `sisi workers` ends with one line on how often
|
||||
and how they turned out. After a rejection `sisi delegate judge` prints `sisi route --retry-of ID`: the same
|
||||
worker with a better brief first, then a worker whose evidence is strictly better (`routing.retry_choice`, the
|
||||
same ladder the capability routing uses). `sisi route --kind K` takes only the ledger's kinds (`impl`, `impl-multi`,
|
||||
`edit`, `tests`, `debug` build; `read`, `search`, `research`, `review`, `docs` do not; the list is data in
|
||||
canon/guard.json) and names them when given another; the decision is kept in the session's orchestration meter,
|
||||
which is also where the contract guard reads it to tell a build delegation from a read.
|
||||
|
||||
When a worker fails for a reason that is not about its work (a quota, limit, login or connection failure,
|
||||
arriving as a delegation result or as a host notice), the hooks record it down until the reset time in the
|
||||
message, mark its pending run `superseded` and hand the agent the router's next worker. The agent is told to
|
||||
fall back at once with the same brief and neither ask the person nor report it. `sisi delegate` itself says
|
||||
the same when only host-native workers remain. Models discovery finds that it had not seen are named once at
|
||||
session start as unproven. Settings under `orchestrate`: `direct_calls`, `direct_chars`, `extension`,
|
||||
`route_window_min`. Mechanics: [design.md](design.md) section 9.
|
||||
|
||||
## Stored, and when facts go stale
|
||||
|
||||
In the user store: `workers.json` (discovery cache), `delegations.jsonl` (the ledger),
|
||||
|
||||
Reference in new issue
Block a user