Skip to content

Command rules as data: Sonny runs Codex's Starlark rules files, the daemon applies what each bot is given - #577

Merged
lydakis merged 20 commits into
mainfrom
claude/project-thread-19d030
Nov 1, 2026
Merged

lydakis merged 20 commits into
mainfrom
claude/project-thread-19d030

Conversation

@lydakis

@lydakis lydakis commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

The last PR of the day-5 review: command rules at full Codex fidelity, with the language kept out of the daemon.

What changes

  • The daemon takes rules as data. A bot's rules setting holds Codex's execpolicy shape as JSON: prefix_rules, host_executables, or invalid with why the client couldn't read them. The daemon matches each shell call against them as Command rules: Codex-style allow, prompt and forbidden rules replace a bot's unsandboxed list #572 did, now with host_executable in effect: a command run by an absolute path is matched by its program's name when that path is listed for it, or none is.
  • A bot made by another always goes by its creator's rules. It takes them when it's made, whatever its own client sends, and follows them when they change, along with the bots it makes. Configuring rules on it is invalid_setting.
  • Sonny reads ~/.agent/rules as Codex does. The files are Starlark in its extended dialect with f-strings and the standard globals, so variables, loops and functions work. prefix_rule and host_executable are ported from Codex, and each rule's examples are checked once the file has run, as Codex checks them.
    • network_rule is refused: it needs a proxy that filters a sandbox's network by host, which is its own feature.
    • A file that doesn't read keeps the rules last read. If none have been read yet, every shell call is refused with where it went wrong.
    • A rules file that is a symlink or has another hard link is refused, since the sandbox keeps only the folder read-only.
  • Sonny gives the rules to every agent it makes, and its tool host keeps them current. This sits beside the config.toml follower from configure takes every setting create takes; Sonny's agents follow config.toml #574.
  • sonny rules check [--pretty] -- COMMAND... replaces agent rules check.
  • serve --protect-path PATH (repeatable) replaces serve --rules DIR. It keeps a path read-only in every sandbox and stops it being created there. The CLI passes ~/.agent/rules.
  • This is protocol 43. Daemon: limits from [daemon] formulas, and a load gate for new commands #575 has 42.

Sonny's Cargo.toml adds three crates: starlark (Meta's crate, which Codex uses), shlex and anyhow. The daemon's dependencies stay the same.

Tests

  • Sonny unit tests:
    • Codex-written rules files, including what "always allow" writes.
    • Starlark features (loops, functions, f-strings).
    • host_executable.
    • One-line errors that say where.
    • Folder rereads that keep good rules, and links refused.
    • sonny rules check.
    • The tool host gives the rules to root agents only.
  • Daemon and store tests:
    • Daemon unit tests: scripts are ruled per command, and invalid rules refuse every call.
    • Store contract: creator inheritance, the cascade to grandchildren, child configure refused, and reset.
  • Runtime tests:
    • test_command_rules_let_a_command_out_ask_about_it_or_forbid_it now passes rules as data. It adds rules_invalid and an invalid setting.
    • The workflow tests give "always allow" rules with configure.
    • The agent rules check CLI test moved to Sonny.
  • Ran locally:
    • cargo test --workspace and clippy -D warnings are clean.
    • The full runtime suite with AGENT_TEST_SANDBOX=1 passes.
    • The query-plan check counts the descendants CTE's step scan as structural, since each step uses bots_maker.

No screenshots: nothing on screen changes.

claude added 18 commits October 31, 2026 22:55
A SigV4 refusal is told as clock skew when the error names it, or when
the response's Date is more than four minutes from when the request was
signed, the AWS SDK for Java's rule. A machine that slept with a signed
request in flight now re-signs instead of failing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGGxFkGajbntA1atiYT
The `history` tool's view already dropped reasoning items' encrypted
content. It now also drops a thinking block's signature, a redacted
thinking block's data, and a web search result's encrypted content:
bytes the provider hands back only to be replayed, which no agent can
read. Thinking text stays; stored items, raw reads, forks and replay are
unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGGxFkGajbntA1atiYT
The history view's READING_ITEM now matches quoted JSON keys, and the
planner's constant pattern stopped at its first escaped quote.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGGxFkGajbntA1atiYT
…ent/rules replace a bot's unsandboxed list

The daemon reads every *.rules file in the folder it is started with
(`serve --rules DIR`; the CLI passes ~/.agent/rules) and decides each shell
call by the strictest rule its commands match, as Codex's execpolicy does:
allow runs outside the sandbox without asking, prompt waits on the gate even
when confined (or fails command_needs_approval with no gate), forbidden
fails command_forbidden with the justification. A turn pins its rules when
its rounds begin; the folder is read again when its files change, keeping
the last good rules, and a folder broken before any read fails every shell
call with rules_invalid. The folder is read-only in every sandbox.

The files are read by a small reader of Codex's documented form (literal
prefix_rule and host_executable calls, comments), not a Starlark runtime.
`agent rules check -- COMMAND...` shows what the rules decide.

The unsandboxed bot setting is gone (schema 75 strips it from stored bots;
protocol 39). Sonny's "always allow" writes an allow rule to default.rules,
and an existing [sonny] unsandboxed list moves there once at start.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGGxFkGajbntA1atiYT
… the runtime thread, linked rules files refused

A planned call keeps what the rules made of it (tools.ruling, schema
75), and its run reads that, so a park, restart or edit between
announcement and run can't gate a call no request was made for. The
rules folder is read on a blocking thread. A rules file that is a
symlink or has another hard link is rules_invalid: the sandbox keeps
only the folder itself read-only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGGxFkGajbntA1atiYT
…nreadable rules file is refused

A fresh round runs by the rules the turn read, which its announcement
used, so it needs no store read; only a resumed park reads the rulings
its round recorded, in the resume's own store job. A rules file whose
metadata can't be read is refused rather than skipped, so the rules
last read stay.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGGxFkGajbntA1atiYT
…fig.toml

`configure` gains `settings`, a map with create's names: a value given
replaces the setting, null resets it to its default, and the rest stay.
Naming `sandbox` resets writable, network and unix_sockets unless they are
named too. `fallback`, `compaction_instructions` and `compaction_model`
take null to remove. The old top-level sandbox, writable, network,
unix_sockets, cache_ttl and speed fields are gone. `changed` names each
setting key, with the sandbox's four reported as `sandbox`. Protocol 41.

Sonny's tool host checks config.toml every five seconds and configures
its agents to a changed [fallbacks] entry or senders setting.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGGxFkGajbntA1atiYT
…ders only when the sandbox changes

A setting named with null was dropped before the names were checked, so a
misspelled reset passed silently. And every settings change resolved the
writable folders again, so one deleted since failed an unrelated change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGGxFkGajbntA1atiYT
# Conflicts:
#	client/src/lib.rs
…aemon applies what each bot is given

The daemon no longer reads rules files. A bot's `rules` setting holds its
command rules as Codex's execpolicy shape in JSON (prefix_rules,
host_executables, or invalid with why), and the daemon matches each
shell call against them as before. A bot made by another always goes by
its creator's rules and follows their changes; configuring rules on it
is invalid_setting.

Sonny reads ~/.agent/rules as Codex does: Starlark in its extended
dialect with f-strings, prefix_rule and host_executable (now with
effect), examples checked after the file runs. network_rule is refused
until a proxy can filter a sandbox's network by host. Sonny gives the
rules to every agent it makes and keeps them current from its tool host.
`sonny rules check` replaces `agent rules check`, and
`serve --protect-path` replaces `serve --rules`, so the folder stays
read-only in every sandbox.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGGxFkGajbntA1atiYT
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T05:26:06.190009Z b566b48 New commits
🔒 Security Review ✅ Completed 2026-11-01T05:09:43.993501Z ba3f781 PR opened

Security findings

Advisory findings (1)

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ba3f7812c9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/store/db.rs Resolved
Comment thread src/store/db.rs Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Codex Security Review · Automatically triggered

Here are some automated security review suggestions for this pull request.

Reviewed commit: ba3f7812c9

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread client/src/rules.rs Resolved
… bot whose creator is gone own its own

A create reply repeats the bot's settings, now with its command rules,
which admission reserves room for: what the command gives, or the cap
for a bot that takes its creator's. inspect and the create reply show
`rules` with the other settings. A bot whose creator is deleted keeps
the rules it had and may be given its own, as no creator's sandbox holds
it either; Sonny's tool host gives such an agent its rules as it gives a
root one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGGxFkGajbntA1atiYT
…st_executable names

Codex matches a program run by any absolute path by its name's rules
when no host_executable names it. For an allow rule, which runs the
command outside the sandbox, that lets a sandboxed bot write /tmp/rg and
run it unasked. Such a path is still asked about or refused by the
name's rules, but only a listed path is allowed by them. Examples still
match by pattern alone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGGxFkGajbntA1atiYT
@lydakis
lydakis merged commit 20a487a into main Nov 1, 2026
10 checks passed
lydakis pushed a commit that referenced this pull request Nov 1, 2026
#577 took 43, so this branch's protocol moves to 44. The turn test's
rules are a policy given as data, as Sonny now passes them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGF9fn2EXiBvzYrQtaA
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.

2 participants