Repository navigation
Hook: only the chief writes the logbook; agents run read commands only (T83) - #36
Merged
Merged
Conversation
…y (T83) An agent event (agent_id) may run the state tool only as one plain read command (status, merge-check, logbook, standing, config with no key=value), by an allow-list, from any command tool (Bash, Monitor, PowerShell, mcp__terminal__*). It never runs sage-pr.mjs, never writes under the sage root with a file tool, a link or a shell write, and never runs outside the sandbox. On an error the hook refuses such commands and agent file changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…T83 S1, S2) S1: each change of a build's pr= writes a decision row (PR <old> → <new>). The merge check counts every task that was ever on the PR: by its pr, by those rows, and by its verdicts on a commit with that --pr. A cleared pr= no longer takes a task out of the merge. S2: the hook refuses the chief's Write, Edit, MultiEdit and NotebookEdit under the sage root, and a shell write that names the sage root (or, in sage mode, a logbook file), unless the command is only node .../sage.mjs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…round 1) - File tools: compare canonical paths (realpath.native, lower case, NFC), so another case or Unicode form of the sage root is refused (S-CASE). - Agent shell: deny by default near the logbook. A write form with a logbook file, .claude, a pattern that can name them, a variable by the home folder, or a cd home is refused (F1, S-PWSH). Reads with 2>/dev/null or 2>&1 pass, and the write words count only as commands (F3). - Every agent check fails closed (F2); an empty agent_id or a sage role's agent_type is an agent's event (S-EMPTYID); an agent runs only the state tool that the hook loads (S-OWNCOPY). - The chief's rule reads case and patterns too (S-CHIEFCASE). - A PR number has no leading zero, in the hook and the state tool; an older 040 row counts for PR 40 (S-PRZERO). - README and SKILL: the sandbox (T80) is the full guard for shell writes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…CASE) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…he sage root are refused (T83 round 2) - COST-GLOB (owner decision): an agent's pattern or logbook-file name is refused only with cd, pushd, .., ~, $, a backtick or an absolute path, or when a word resolves into the sage root or a folder that holds it. - S-WTLINK: every word of an agent's shell write is resolved through the links on disk; ln/link to the root, or to a target that the hook cannot read, is refused. - S-FOLD: NFKC before lower case (ſ is s, st is st). - S-DOTDOT: a file tool's path keeps its .. for the system to resolve after each link. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…is home again (T83 round 3)
S-GLOBLINK: the hook does not expand a pattern, so it now refuses an agent's
shell write when a part before the first wildcard is a link, or when the first
pattern part names a link (also a dangling one) in its folder.
S-HOMEBRACE: wordsOf gives ${HOME} as $HOME again ("$$$1", not "$$1").
README and SKILL.md: deliberate shell forgery is the sandbox's job (T94-T99).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…oot variable set to a scratch folder passes (T83 C2, C3, C4) An agent's read, diff or commit message that names sage.mjs passes; running the state tool's write or the PR script stays refused (behind env, xargs, -exec, sh -c, eval, a pipe into node, or a variable). SAGE_HOME or CLAUDE_CONFIG_DIR set in the command to a plain path outside the real sage root no longer makes a write near the logbook, for agents and the chief. New test: a file tool's path to a sage root that does not exist yet is compared folded. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e check (T83 C4) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the chief's shell rule by mode (T83 C2, C3, C7) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflicts resolved: the hook keeps both agent rules (agentWriteProblem for the logbook, agentProblem for stash and the process list), one SHELL_TOOLS pattern, main's shell reader with redirection targets kept in redirects, and the state tool's exported PR rule. The README and the sage skill keep both sides' rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…); a prefix SAGE_HOME is not safe; reviewer reads pass (T83 N1, N2, N4)
- scriptRun reads the programs that run through main's programsRun (T100), so
for, while, if, {, !, case, sudo -u <user>, npx -p and the other wrappers no
longer hide a state-tool write. One way to find programs, not two.
- usesRootVar: only an assignment that is a command of its own (or export)
makes a later $SAGE_HOME safe; a prefix assignment does not.
- node --check, python code that imports only read modules, diff <(git show),
and reader pipes that redirect to a scratch file pass; runs stay refused.
- nearLogbook and partsOf check each word once, so 1 MB stays under 200 ms.
- R454-N5 checks the stash rule alone: the logbook rule refuses an agent
command that the hook cannot read (fail closed).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…a write is refused; uniq, less and sort -o write; $? is no pattern; refusals name the word - Remove pythonReads, READ_MODULES, the node --check skip and writeText (T83-S1-PATHLIBOS, T83-S2-UNIQ part): python or node code that names sage.mjs is refused again. - uniq and less always count as writes, sort -o / --output too (T83-S2-UNIQ, R667-READERS). - usesRootVar: every $SAGE_HOME or $CLAUDE_CONFIG_DIR is a use, whatever assignments come before it, for agents and the chief (T83-N2-PREFIXVAR). - wordsOf: $? $# $* $@ $$ $! $- $0 are variables, not patterns (T83-Q1-DOLLARQ). - nearLogbook, namesRoot, linksNear and shellWrite return the word, and each refusal names it (T83-Q2-GLOBLOOP). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ort --o… writes, no program through a pattern, every refusal names its word in its own case - wordsOf: remove round 5's special-parameter rewrite (T83-R5-DOLLARQUOTE): hom$''? passed as hom$. One unquote() drops the $ of an ANSI-C or locale quote and the quotes, in wordsOf, namesRoot, usesRootVar and scriptRun. echo exit=$? is refused and the refusal says to use || echo FAIL or ; echo done. - sort: any option that starts with --o writes (T83-R5-SORTABBR). - globRun: a pattern in a program's path, or in the script that node, python or a shell runs, is refused and the part is named (T83-PRE-GLOBRUN). - hidesTool: a hidden state-tool run names the keyword, wrapper, program, node option or non-plain text, and the plain way to read sage.mjs (T83-Q3-N1WORD). - partsOf keeps each word's own capitals; nearLogbook and namesRoot match on the folded form and name the original (T83-Q4-CASE). - Tests: Q1-DOLLARQ replaced by R5-DOLLARQUOTE; R5-SORTABBR, PRE-GLOBRUN, Q3-N1WORD, Q4-CASE added; Q2-WORD asserts the root in its own case. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…writes # Conflicts: # scripts/sage-hook.test.mjs
Owner
Author
|
Round 6 (head ef9d43a: round-6 commit 6a0b69b, then main merged at f1ffd8a, PR 52). Five items:
The five new tests fail on 2c543fc and pass on the new head. Full 🤖 Generated with Claude Code |
…names sage.mjs runs only plain readers, a bare redirect to the logbook is a write; the pattern rule is gone A. Drop globRun: [ -f x ], [[ ]], if [[ ]], [ -d d ] || mkdir and $(( )) pass again for an agent (T83-R6-BRACKET, T83-R6-ARITH). B. Name rule: a command that names sage.mjs or sage-pr.mjs may run only plain readers (cat, grep, rg, head, tail, wc, ls, diff, shasum, jq, awk and sed without -i, git show/log/diff/status/blame/grep/ls-files/add/commit); any other program is refused and named, whatever its options (T83-R6-OPTVALUE). The refusal gives the plain read form and the cat/git show way (T83-R6-HINTFIT). scriptRun, hidesTool, kind and INTERPRETERS are gone. C. A command of only redirections is a command to the shell reader, so '> ~/.claude/sage/<p>/ledger.tsv' with no command word, also after ; or |, is refused for an agent and the chief (T83-R6-BAREREDIRECT). Co-Authored-By: Claude Fable 5.1 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scope of the guard
The hook stops agents' mistakes and the common forgery forms. Deliberate shell forgery (scripts, variables, links made at run time) is the sandbox's job (tasks T94–T99); merges stay paused until the sandbox switch (T99) merges.
What
Only the chief writes the logbook, and the chief writes it only through
sage.mjs. This PR changes the hook (agents and the chief), the state toolsage.mjs, the hook matcher, the README and the sage skill.Who is an agent
An event is an agent's when it has an
agent_idfield (also an empty one), or when itsagent_typeis a sage role other thansage:chief-of-staff. Every other event is the main session (the chief). The agent rule holds in every mode, also out of sage mode.Agents (hook)
env,xargs,sudo,timeout, ...), and the word after-exec. It runssage.mjswhen it is the file; when it is an interpreter (node,python, ...) whose words up to its script, whose heredoc or whose piped input name the file; and when text thatsh -c,bash -corevalruns does. A variable or substitution in those places counts as a run when the text names the file. Socat,grep,git diffandgit commit -m "fix sage.mjs"pass, and so does a description that names it.sage.mjspasses only as one plain command:node <path ending in skills/sage/sage.mjs> <read> [--project <p>], with the copy that the hook loads, and no quote, variable,;,&&,||,|, backtick,$(,>,<, newline or... The reads are an allow-list:status,merge-check,logbook(notrepair),standing(notadd),configwith nokey=value.sage-pr.mjs(same program rule)...are resolved, in any case and Unicode form (NFKC and lower case, as APFS compares names).>,tee,cp,mv,rm,ln,sed -i, PowerShell writes, ...) is refused with the sage root's path,.claude(except a plain worktree path), a variable by the home folder, a path that leads into the sage root through a link or.., or a pattern with a link on its path. A pattern or a logbook file's name in a project passes (rm dist/*,jq ... > config.json); withcd,pushd,..,~,$, a backtick or an absolute path it is refused.SAGE_HOMEorCLAUDE_CONFIG_DIRset in the command to a plain path outside the real sage root (a scratch folder for tests) passes, and so does a later$SAGE_HOMEof it. A$SAGE_HOMEthat the command did not set so, an assignment of another value ($HOME/..., the real root), or a bare name in a command with a substitution or pipe is refused with a write.dangerouslyDisableSandboxis refused.mcp__terminal__*; the PreToolUse matcher inhooks/claude.jsonnow names them.The chief (hook)
.claude/sage, or a root variable as above. In sage mode, a logbook file's name (tasks.tsv,ledger.tsv,config.json, ...) counts too; out of sage mode a project's ownconfig.jsonstays free.node <path>/sage.mjs ...as a command of its own passes. The owner's own!commands are no hook events.gh pr merge 040 ...is refused).State tool (
sage.mjs)pr=(task set pr=,verdict --pr) writes a decision rowPR <old> → <new>. The merge check for PR n counts every task that is on n, was on n by a decision row, or has ledger rows with PR n on any commit. A cleared or changedpr=no longer takes a large task's verdicts out of the merge.pr=040and--pr 040are refused); an older row with040counts as PR 40.Why
The T77 re-check (R354) showed that a sandboxed agent could run
verdict,task set branch=main,initandconfig cycles.*=1through the state tool, after which the merge check said "may merge" on its own unreviewed commit. S1 and S2 showed that a changedpr=or a hand edit by the chief could do the same.Evidence
scripts/sage-hook.test.mjsandscripts/sage.test.mjscover each forgery step, the spellings, links,.., patterns, PowerShell, the chief's writes, the PR history and the leading zero.sage.mjspass;bash -c,eval,-exec,xargs, a pipe into node,node -eand a variable that run it are refused), C3 (scratchSAGE_HOMEandCLAUDE_CONFIG_DIRpass for an agent and the chief; the real root is refused), C4 (a file tool path to a root that does not exist yet, in upper case and in compatibility forms), and the ledger-history test insage.test.mjs.prHistory, and without the fold incanonical.npm run build,npm run checkpass;npm testtwice on 317da33, with a fake ps and kill first on PATH: 260 of 260 pass both times.Not verified
commandstring.sage.mjsfrom inside a script file, or a name built at run time, is not seen; that is the sandbox's job.d*/x/*whered1/xis a link) is not caught; the hook does not expand patterns.Risk flag: auth. The owner merges this pull request, before PR 34.
🤖 Generated with Claude Code