Skip to content

fix: stop refusing interpreter identifiers and gh and mkcert arguments as file reads - #64

Merged
liby merged 5 commits into
mainfrom
fix/inline-mentions-and-option-roles
Nov 19, 2026
Merged

liby merged 5 commits into
mainfrom
fix/inline-mentions-and-option-roles

Conversation

@liby

@liby liby commented Nov 19, 2026

Copy link
Copy Markdown
Member

Agents were refused for code that never touches a credential: a Python here-document building a command with .env("A", "1"), a JavaScript template such as `${at()} keydown ${e.key}`, gh search code --filename .env.local, and mkcert -cert-file .certs/local.pem -key-file .certs/local-key.pem x.local. There were two causes. Interpreter source went through the tokenizer used for shell text the guard cannot parse, and every candidate became a read. gh and mkcert were unmodelled, so every operand was read as a local file.

Interpreter source is now scanned in its own language, with code, string and interpolation states. A name with a slash counts anywhere. A name without one counts only inside a string or a comment, and not when it is called as name(. Interpolated code is scanned again, so f"{name}.pem" is still refused. Uncertain shell fragments keep the previous rules. open(".env"), os.system("cat ~/.ssh/id_rsa"), glob(".env*") and Path.home()/".npmrc" are still refused. A protected directory mentioned in prose, such as "no ~/.claude here", also stays refused. Allowing a lone store directory inside a multiword string would also allow os.system("cp -R ~/.claude /tmp/x"), so that case is listed under known limits instead.

gh search code|commits|issues|prs|repos and gh api now have complete option grammars taken from the gh 2.105 manual. Queries, endpoints, filters and -f key=@FILE values are names. --input FILE and -F key=@FILE send a local file and are refused as credential_upload when that file is protected. Other gh commands are unchanged. mkcert options follow Go's flag package, which the new Syntax::Go binds. -cert-file, -key-file and -p12-file are writes, -csr is a read, and operands are host names, including words after the first host name, as mkcert reads them.

Writes into an .ssh directory get a new reason ID, ssh_private_write, instead of ssh_private or credential_file. The new message suggests writing under a project or temporary directory and asking the user to install the file. Tooling that matches the old IDs for these writes needs updating.

Interpreter source piped into an interpreter is now checked: cat <<'EOF' | python3 with open('.env') in it is refused like python3 - <<'EOF' already was. This applies only when the interpreter takes its program from standard input. Data piped into python3 script.py, python3 -m json.tool or -c code is still that program's input. This is the only tightening, so it has its own commit.

The last commit moves release notes into pull requests. A change that readers of the notes need adds or updates its entry in docs/releases/unreleased.md, and the release commit renames that file to docs/releases/<version>.md, which publish.yml already reads. This branch's entry is included.

make check passes. The 133 commands from the design were run through release builds of 0.8.17 and this branch. Every verdict that changed is listed in docs/releases/unreleased.md, and every command that had to stay refused or allowed kept its verdict. Weakening each new decision toward the weaker verdict fails a named fixture row: 14 for interpreter scanning, 12 for the gh and mkcert grammars, and 7 for piped source. Median latency through bin/agent-guard was 12.33 ms against 12.74 ms for 0.8.17, over 30 paired rounds of seven events, with load between 5.89 and 6.60.

liby added 5 commits November 19, 2026 15:46
Interpreter source given with `-c` or `-e` or as a here-document went
through the tokenizer for shell text no parser can read, which takes
any word that starts with a dot, contains a slash or touches a quote as
a mention. A Rust builder chain `.env("A", "1")` quoted in a Python
here-document, or a JavaScript member such as `e.key`, was refused as
naming `.env` or `.key`.

The source now keeps its interpreter's language until it is scanned. A
word containing a slash is a mention anywhere; a bare name is one only
as a word of string content or a comment, unless it is escaped or
directly followed by `(`. The scanner follows each language's string
forms: Python triple-quoted strings and f-strings, JavaScript templates
and comments, Ruby `%` literals and heredocs, Perl quote-like operators
and regular expressions, PHP heredocs, Lua long brackets and
AppleScript comments. Interpolated code is read as code whose strings
are read again, so `${fs.readFileSync(".env")}` and `f"{name}.pem"`
stay refused. A word with a wildcard is checked as a pattern. Comments
are read like string content, as the contract for `# cat .env` in a
here-document requires.

Shell text no parser can read, such as `bash -c "$CODE"`, keeps the
broader rule.
`gh` was an unknown program, so every operand was read as a path:
`gh search code --filename .env.local` and
`gh api repos/o/r/contents/.env` were refused for names that only
select what GitHub searches or returns, while `gh api --input .env` was
refused as an ordinary read rather than as sending the file. The
`search` verbs and `gh api` are now read from their documented options:
queries, endpoints, `-f` fields and option values are names, and the
files `--input` and `-F key=@FILE` send, other than standard input, are
refused as `credential_upload`. Other gh commands and undocumented
options keep the unknown-program roles.

`mkcert` was unknown as well, so a host name such as `server.key` was
refused and `-key-file ~/.ssh/id_rsa` was reported as a read. Its
options follow Go's flag package, which the new `Syntax::Go` binds: one
dash or two, a value glued with `=` or in the next word, a boolean that
takes a value only when glued, and no options after the first operand.
`-cert-file`, `-key-file` and `-p12-file` are writes, `-csr` is a read,
and operands are host names.

A write into an `.ssh` directory was refused with the message for
reading private keys. It now has its own marker, `ssh_private_write`,
whose alternative is to write under a project or temporary directory
and ask the user to install the file.
`python3 - <<'EOF'` was checked as interpreter source, but the same
here-document piped as `cat <<'EOF' | python3` was not: only a direct
here-document or here-string became inline code, so moving the source
into a pipeline let `open('.env')` through.

When an interpreter's standard input is a pipe whose text the shell
evaluator models, the known text is now recorded on the command, and
target inference reads it with the interpreter's scanner when the
interpreter takes its program from standard input: no code option, and
no operand other than `-`. Text piped to a script, a module or a code
option stays that program's data, and pipes into other programs are not
read as code.
Release notes were written in the release commit by reconstructing them
from the commit range, so each release had to review every change
again. A pull request whose change readers of the notes need now adds
or updates its entry in `docs/releases/unreleased.md`, and a later pull
request that changes the same behavior updates that entry. The release
commit renames the file to `docs/releases/<version>.md` with the version
heading and repins its `main` links to the tag, so the publish workflow,
which reads that file, is unchanged.

AGENTS.md carries the pull-request rule because it loads before any
change is made; the release skill keeps how entries are written and
the rename at release.

Add this branch's entry: interpreter identifiers, piped interpreter
source, gh search and api roles, mkcert roles, and the
`ssh_private_write` reason ID.
Drop doc comments that only repeat a name, a signature or the control
flow beside them, and move the two rationales worth keeping (a mention
is judged as a read; a pflag boolean takes a value only when glued) onto
the items that own them.

Remove inline-mention fixture rows that another row already catches on
the same scanner path and partition, and file the piped builder chain
under piped source, since `python3` runs that text as its program.

The release note keeps the affected `-c`, `-e` and here-document scope
without the old implementation detail. The scanner loop no longer
matches an empty stack, whose bottom frame is never popped, and the
Perl quote-like check rejects a preceding character before reading the
operator name.
@liby
liby merged commit e260868 into main Nov 19, 2026
5 checks passed
@liby
liby deleted the fix/inline-mentions-and-option-roles branch November 19, 2026 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant