diff --git a/docs/design.md b/docs/design.md index 38990f2..1226746 100644 --- a/docs/design.md +++ b/docs/design.md @@ -118,7 +118,37 @@ The open unit is `.sisi/contract.json`. New fields are optional unless the profi and the risk table, so every unit says which policies were in force [11.6]. - `sisi unit pause ""` records a wait and lets the turn end with no demands. The pause also ends when the tree changes or `sisi verify` runs. Wait time is - telemetry [6.1]. + telemetry [6.1]. A pause defers checks that wait on something and the retro, never the + contract: it is refused when no unit is open, the unit is not the session's own, or it is + missing what is required before building (below). It silences the gate only for the session + that holds the unit, and only while the unit is valid. +- A unit is **bound to the session that works on it** [10.1]. A session opened it + (`sisi contract init`) or said it continues it (`sisi unit continue`, which prints the goal, + age and owed checks); the binding is kept in the session record, never in the contract. A + unit with no activity (a verification run, an allowed edit, a continue) for `unit.stale_hours` + (12) needs `continue` again. `sisi unit park ""` sets the open unit aside, kept under + `.sisi/parked/` and listed by `status` and `unit list`; `sisi unit resume ID` brings it back + when no unit is open. `contract init` on an open unit names the three ways on: continue, + park, or close it as abandoned. +- **The contract comes before the work** (rule 3). `sisi/unitguard.py`, called from the + before-tool hook (`sisi watch`) on a main thread, works out the risk floor of the path a + file-changing call (or a shell write the classifier recognises) is about to change, together + with the paths this session already changed since its last valid unit. Above `trivial` the + call is refused (a short message, at most 12 lines, naming each missing item and the command + that supplies it) unless the session holds a valid unit: bound, not stale, passing + `sisi contract check` with no placeholder check left, and carrying what the profile needs + *before building* from canon/risk.json (the requirement list, risk note and approach for + integration and above; independent evidence and the retro come at the end). Writes under + `.sisi/` and outside the project, worker and subagent sessions, and every error inside the + hook are let through. A shell command the classifier does not recognise is caught by the + after-tool snapshot, and the next counted call is refused the same way. Delegating a build + needs the unit too (the contract is where the brief's acceptance comes from). Word lists + live in canon/guard.json. Every refusal is stored (what, when) and kept in the unit record + (`guard_refusals`); `sisi status` counts them. +- Nobody is their own independent evidence [13.3]: a check marked `independent` counts only + if `by` names something other than the author (not empty, not the session's own model, not + a self-reference such as "me" or "my own review"), and a review counts only from a worker + other than the author's model, judged with a check stronger than `none`. - `sisi unit show [ID]` prints a record. Nothing is ever overwritten or lost. - Delivery status is one of `delivered`, `delivered-with-deferred`, `deviation` (a check was waived), `unverified` (the gate released after its send-backs ran out), `abandoned`. @@ -187,7 +217,13 @@ At the end of a turn in which the session changed something: evidence), say which. 4. If everything is green and the unit is not closed, offer the two ways on: record the retro (`sisi retro`), which closes the unit; or `sisi unit pause ""`. -5. A paused or closed unit with no new change passes silently. +5. A paused or closed unit with no new change passes silently. A pause silences only the session + that holds the unit, and only while it is valid. + +The gate judges a session's changes only against a unit the session holds. When the open unit +is another session's, or stale, a non-trivial change is sent back with the three ways on +(continue, park, or init) and none of that unit's checks are run; if the send-backs run out the +turn ends as unverified and the other unit is left as it was. In this build the retro is offered once for each state of the tree and a trivial change is asked nothing (unless the unit shows an anomaly); a recorded retro closes the unit. A session is judged only on diff --git a/docs/developing.md b/docs/developing.md index 0648a8f..eda7956 100644 --- a/docs/developing.md +++ b/docs/developing.md @@ -36,6 +36,15 @@ afterwards so the tools point at the stable copy (release tells you if they do n Switches `current` to the release before it and rebuilds the rulebook. +## Check the contract guard against a real agent + +`tools/live_contract_check.py` runs the host's command-line tool headless in a temporary +git project, with the hooks of THIS clone and temporary sisi data and state folders, and asserts +that a leftover open contract from other work cannot be built on, skipped or paused away. It +needs a login and costs a few cents, so it is not part of the unit suite. Run it +(`python3 tools/live_contract_check.py`) after changing sisi/unitguard.py, sisi/watch.py, the +gate's unit logic or the refusal wording, and whenever the host's hook interface changes. + ## Promote a personal addition Rules, verifiers and recipes you added live in your personal overlay. Run from the clone: diff --git a/docs/records.md b/docs/records.md index 308740a..e0653bc 100644 --- a/docs/records.md +++ b/docs/records.md @@ -28,6 +28,12 @@ with a failing check cannot close as delivered. A mandatory check that never ran whose `when_changed` glob matches no file, makes the unit `delivered-with-deferred`, never plainly `delivered`. `sisi contract waive` records a deviation; it turns nothing green. +The record also carries `guard_refusals`: every building step the before-tool guard refused for +this unit, with what, when, the tool and the unit's state (see docs/design.md, section 4). Units +set aside with `sisi unit park` are kept whole under `.sisi/parked/.json` with the reason, the +time and what each still owes. The guard's own state (which session continues which unit, a unit's +last activity, remembered floors) lives in the state folder and is scratch. + A pause records what the unit waits for. While nothing in the tree changes the gate asks nothing; a change ends the wait, and so does running `sisi verify`. Waiting time is telemetry. A contract must declare `risk.profile`; see [docs/design.md](design.md). diff --git a/sisi/helptext.py b/sisi/helptext.py index 58568b2..53790ba 100644 --- a/sisi/helptext.py +++ b/sisi/helptext.py @@ -6,7 +6,7 @@ command is printed by `sisi help COMMAND` and `sisi COMMAND --help`. LONG = { 'contract': ' sisi contract init [--goal TEXT] start a work unit: create .sisi/contract.json here (refuses while one is open)\n sisi contract check validate the contract (vacuous checks are refused)\n sisi contract waive [--check ID] ""\n record a deviation: a waived check does not pass; the unit closes as a deviation and the report must say so\n sisi contract trust | untrust allow / stop allowing this project\'s contract to run commands', - 'unit': ' sisi unit close [--abandon ""]\n archive the unit to .sisi/units/.json with its scorecard; --abandon records why it stopped\n sisi unit pause ""\n record a wait; the turn may end with no demands\n sisi unit show [ID] | list print the open unit or an archived record; list this project\'s units', + 'unit': ' sisi unit close [--abandon ""]\n archive the unit to .sisi/units/.json with its scorecard; --abandon records why it stopped\n sisi unit pause ""\n record a wait (checks waiting on something, and the retro; never the contract: refused without a valid unit this session holds)\n sisi unit continue\n say this session continues the open unit: prints its goal, age and owed checks; needed again after unit.stale_hours idle\n sisi unit park "" | resume ID\n set the open unit aside, kept under .sisi/parked/ (listed by status and unit list), or bring a parked one back\n sisi unit show [ID] | list print the open unit or an archived record; list this project\'s units', 'verify': ' sisi verify [--json] run the selected fast checks (five statuses; nothing unrun passes); exit 0 ok, 1 failure, 2 no contract, 3 untrusted\n sisi verify --deep [--background] run the deep (long) checks; --background detaches and returns at once\n sisi verify --all | --state run every check in both tiers; print only the deep-check state (with --json)', 'gate': " sisi gate [--tool NAME] end-of-turn hook (reads hook JSON on stdin; NAME selects the tool's hook shape)", 'tick': ' sisi tick [--tool NAME] session-start hook', @@ -58,7 +58,7 @@ GROUPS = ( )), ("For the agent at work", ( (("contract",), "contract init|check|waive|trust|untrust", "start, validate and bend the unit's contract"), - (("unit",), "unit close|pause|show|list", "close a unit with its scorecard, record a wait, look back"), + (("unit",), "unit close|pause|continue|park|resume|show|list", "close a unit with its scorecard, record a wait, say it is yours, set it aside, look back"), (("risk",), "risk [--json]", "the risk floor of the working-tree change; what it requires"), (("verify",), "verify [--deep|--all|--state] [--json]", "run the contract's checks; nothing unrun passes"), (("retro",), "retro [--finding F ...|--adopt ID]", "the unit's record; record a finding, with its cause and fix"),