Repository navigation
Conversation
📊 Automated PR Analysis
SummaryIntroduces Review Checklist
Analyzed automatically by wshm · This is an automated analysis, not a human review. |
KuSh
force-pushed
the
fix/host-rules-loaded-once
branch
2 times, most recently
from
October 16, 2026 20:41
c257fd4 to
dad7edc
Compare
KuSh
force-pushed
the
fix/host-rules-loaded-once
branch
from
October 21, 2026 00:20
dad7edc to
fb49507
Compare
KuSh
force-pushed
the
fix/host-rules-loaded-once
branch
from
October 29, 2026 06:52
fb49507 to
9a271f2
Compare
4 tasks done
KuSh
force-pushed
the
fix/host-rules-loaded-once
branch
from
November 1, 2026 10:45
9a271f2 to
e14f503
Compare
This was referenced Nov 1, 2026
Closed
6 tasks done
KuSh
force-pushed
the
fix/host-rules-loaded-once
branch
from
November 2, 2026 11:46
e14f503 to
1583424
Compare
4 tasks done
Aftaritet1990
approved these changes
Nov 2, 2026
2 tasks
KuSh
force-pushed
the
fix/host-rules-loaded-once
branch
4 times, most recently
from
November 7, 2026 13:31
aebbb7b to
8bde78c
Compare
This was referenced Nov 16, 2026
`HostRules` holds a host's rules, either deny/ask/allow lists (with the
configured transparent prefixes) or OpenCode's ordered last-match-wins list,
read from disk once. Every `rtk hook <agent>` processor and `rtk hook check`
decide through `decide_for_host`: the verdict of the typed command, the
shared decision, and, on a host that judges the command its hook hands back
(OpenCode), no rewrite whose verdict differs, and none at all when rtk cannot
read the rules the way OpenCode does. This replaces `load_rules_for` and the
OpenCode branch in `check_command_for_agent`. Claude Code's own hook
loads them with `HostRules::claude_hook`, in place of
`check_claude_hook_command`, which repeated `check_command_for_agent`'s
load: the walk of the settings that reads the rules also says whether a
fish script may be wrapped.
One load serves the whole `rtk hook claude` run: the engine pipeline's swap
gate decides against it too, from the payload's working directory. In a
managed worktree it swaps no command whose replacement contains `git`:
Claude Code refuses an `rtk` command there whenever its text contains
`git`, and the replacement hands the typed command to `sh`, so git reaches
Claude Code as typed, as the hook leaves it.
`rtk hook check --agent claude` gives that answer too, from the directory
it runs in.
`rtk rewrite`, which the hermes, omp, pi and OpenClaw hooks run, answers
through the same path as `rtk hook check` for those agents
(`AgentPath::answer`) instead of computing its verdict and decision itself;
only `hook check` then drops a rewrite that changes nothing.
`check_command` and `check_command_for` had no other caller and are gone.
The configured `exclude_commands` and transparent prefixes are read and
compiled once with the rules and held by `HostRules`, so the verdict and
the rewrite of one decision use the same settings, instead of the rewrite
reading the config again and recompiling the exclusions on every call.
`rtk hook check --agent opencode` now gives the answer of the plugin run
without an agent: it reported a rewrite the plugin skips, e.g. `git
status` under `{"*": "deny", "git status": "allow"}`, or any command under
a config with a legacy key only one OpenCode generation applies.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
`rtk discover` kept its own deny/ask/allow struct for Claude Code's rules. It now holds the same `HostRules` the hooks load, still read once per run, and `load_permission_rules` is private to `permissions` again. Its rewrite estimate uses the `exclude_commands` and transparent prefixes those rules were read beside, rather than a second copy of them, so `config::hook_rewrite_params` loses its last caller and is gone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude Code's loader and `read_json`, which Cursor, Gemini and Droid read
through, each decided what a settings file holds, and only the first knew
that a path under a regular file or a file holding only a BOM holds no
rule. OpenCode read its configs with a third copy. All four now read
through `read_json`: no file, a path under a regular file, or a BOM and
whitespace hold nothing; anything else RTK cannot read or parse is an
error. What an error costs stays each host's own: Claude Code and Gemini
ask for every command, Cursor and Droid deny it.
Gemini and OpenCode read on as if such a file were not there, so a file
RTK cannot parse (a commented one, which both hosts accept) let a rewrite
or another file's allow silence the ask it holds. Gemini now asks for
every command, and OpenCode's rules are unjudgeable: `rtk hook opencode`
answers `{}` and OpenCode judges the command as typed. Like the other
hosts, it now warns on stderr about a config it cannot read or parse.
`rtk hook cursor` and `rtk hook droid` no longer step aside for every
command when `~/.cursor` or `~/.factory` is a regular file, or when the
settings file holds only a BOM.
Refs #4651
Co-Authored-By: Claude Opus 5.5 <[email protected]>
`HookDecision::AllowRewrite` and `AskRewrite(_, AskOwner)` described one
thing, a rewrite, under two variants and a second enum. They become
`HookDecision::Rewrite { command, approval }`, where `Approval` is `Allow`
(an allow rule matched, RTK allows), `Ask` (RTK asks itself: the fish wrap)
or `Host` (left to whoever judges next). Each host renders the three as
before: only `rtk hook claude` tells `Ask` from `Host`, `ApprovalOwner`
relaxes only a `Host` rewrite under a default verdict, and
`suppress_identity` drops only an `Allow` or `Host` rewrite that changed
nothing.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ini does Gemini CLI now turns folder trust on unless the global settings set `security.folderTrust.enabled` to false, and applies a project's `.gemini/settings.json` only in a folder it trusts. RTK assumed trust was off by default: with no global file, or one that leaves the setting out, it trusted every folder, so it auto-approved a command the project file allowed where Gemini asks first. It also only read `GEMINI_CLI_TRUST_WORKSPACE=true`, while `GEMINI_CLI_TRUST_WORKSPACE=false` and `GEMINI_RESTRICTED_MODE=true` distrust the folder even with folder trust off. RTK now reads the project file when the environment trusts the folder or the global file turns folder trust off, together with the global file's confirmations, which Gemini still applies there; and the global file alone when the environment distrusts it. Otherwise the user may have trusted the folder in Gemini's dialog, which RTK does not read, so it allows no more than either file would: it asks wherever one file asks, and allows only what both allow. Measured with Gemini CLI 0.70.0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
KuSh
force-pushed
the
fix/host-rules-loaded-once
branch
from
November 23, 2026 01:33
8bde78c to
3d86ec3
Compare
This was referenced Nov 25, 2026
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.
Follow-up to #4349. Refs #4651.
Summary
permissions::HostRulesholds a host's rules, read from disk once: deny/ask/allow lists, or OpenCode's ordered last-match-wins list, or a marker that rtk cannot read OpenCode's rules the way OpenCode does (an agent markdown file declaring rules, a legacy key only one generation applies, a config rtk cannot read or parse). It also holds the configuredexclude_commandsand transparent prefixes, compiled once, so the verdict, the hook's rewrite andrtk discover's estimate use one copy instead of each reading the config (the hooks recompiled the exclusions on every decision).HostRules::load(host, agent)replacesload_rules_forand the OpenCode branch incheck_command_for_agent. Whether a host judges the command its hook hands back is stated per host inpermissions::judges_final_command.rtk hook <agent>processor andrtk hook checkdecide throughdecision::decide_for_host: the verdict of the typed command, the shared decision, and, on a host that judges the final command (OpenCode), no rewrite whose verdict differs, and none at all when the rules are unreadable.rtk rewrite, which the hermes, omp, pi and OpenClaw hooks run, answers through the same path asrtk hook checkfor those agents instead of computing its verdict and decision itself; only the hooks drop a rewrite that changes nothing.HostRules::claude_hook(), in place ofcheck_claude_hook_command, which repeatedcheck_command_for_agent's load: the walk of the settings that reads the rules also says whether a fish script may be wrapped. One load serves the wholertk hook clauderun: the engine pipeline's swap gate decides against it too, including whether anaskrule is what makes a command ask. In a managed worktree it swaps no command whose replacement containsgit: Claude Code refuses anrtkcommand there whenever its text containsgit, even inside another word, and the replacement hands the typed command tosh(on develop it swappedgit statustoo).rtk hook cursorandrtk hook droidno longer step aside for every command when~/.cursoror~/.factoryis a regular file or the settings file holds only a BOM. Gemini and OpenCode used to read a file rtk cannot parse (a commented one, which both accept) as absent, so a rewrite or another file's allow could silence the ask it holds: Gemini now asks for every command, andrtk hook opencodeanswers{}; like every hook, it still counts a read of a tee file the rules do not deny..gemini/settings.jsonis read under folder trust the way Gemini CLI decides it. Gemini now turns folder trust on unless the global settings turn it off, and rtk assumed it was off, so it auto-approved a command a project file allowed in a folder Gemini does not trust. rtk now reads the project file underGEMINI_CLI_TRUST_WORKSPACE=trueor when the global file setssecurity.folderTrust.enabledto false, together with the global file's confirmations, which Gemini still applies there, and the global file alone underGEMINI_CLI_TRUST_WORKSPACE=falseorGEMINI_RESTRICTED_MODE=true. Otherwise the user may have trusted the folder in Gemini's dialog, which rtk does not read, so it asks wherever either file asks and allows only what both allow.rtk hook checknow gives the hook's answer: for--agent opencodethe plugin's when it runs without an agent (it printedrtk git statuswherertk hook opencodeanswers{}, e.g.git statusunder{"*": "deny", "git status": "allow"}), and for--agent claudefrom the directory it runs in.HookDecision::Rewrite { command, approval }replacesAllowRewriteandAskRewrite(_, AskOwner).ApprovalisAllow(an allow rule matched, RTK allows),Ask(RTK asks itself: the fish wrap) orHost(left to whoever judges next); every host renders the three as before.rtk discoverjudges transcript commands through the sameHostRules(Claude Code's, still read once per run) instead of its own deny/ask/allow struct.When the skip applies,
hook checkprints the genericNo rewrite for: <cmd>; saying that the rewrite would change the verdict could be a follow-up.Test plan
cargo fmt --all && cargo clippy --all-targets && cargo test --all, with and without default features (5841 and 5623 passed); clippy and the unit tests also pass on each commitcwd, a project one and a managed worktree),rtk rewritewith and withoutRTK_REWRITE_HOST=openclaw,rtk hook opencodeandrtk hook checkfor all 18 agents from the same three directories, over 19 settings layouts × 12 commands (15542 runs per side).rtk rewriteis byte-identical. The other differences are the ones above: Cursor and Droid rewriting beside a regular file or a BOM-only file, OpenCode answering{}under a config rtk cannot read,hook check --agent opencodeunder the [OpenCode] RTK rewrite breaks existing Bash permission allowlists by addingrtkbefore permission evaluation #4195 policy, a"*": "ask"policy and a legacy key,hook check --agent claudeand the pipeline swap leaving git alone in a managed worktree, Gemini's decisions are unchanged where its file cannot be read (it already asks when no rule matches), and parse warnings are no longer printed for files that hold nothing.hook checkand the hook agree on all 636 pairs compared (develop: 75 disagree).git; nothing else differs.hook checkvs the plugin over 7 policies × 6 commands in both directions, each host reading its own rule file and no other, every host reading a settings file the same way, a commented OpenCode config, OpenCode counting a tee read under rules rtk cannot judge but not under a deny, a trusted Gemini project file rtk cannot parse, Gemini's project file under each folder-trust setting, the per-hostjudges_final_commandtable, the rewrite looking past the prefixes the verdict was judged with and leaving the rules' own excluded commands alone, a declined pipeline swap reading the settings no more often than no pipeline, the swap gate declining any command containinggitin a managed worktree,hook check --agent claudethere, and test homes that never read settings aboveTMPDIR-wworktree session against a mock API (7 runs): plaingit statusruns, and so do the hook's ownrtk cargo build && git statusandrtk read .gitignore;rtk git statusis refused, and so is a swappedrtk <task> -- sh -c '…'whose script containsgit(git status && cargo build,xargs -n1 git add,find -exec git,echo digit,echo GIT), as isrtk git-digest -- sh -c 'cargo build'; a swapped command without it runsrun_shell_commandconfirmation beats a global allow;GEMINI_CLI_TRUST_WORKSPACE=falseandGEMINI_RESTRICTED_MODE=trueignore the project file and keep the global allow, even with folder trust off; in a trusted folder a global barerun_shell_commandconfirmation still applies when the project file allows the command; a confirmation naming a command (run_shell_command(git push)) has no effect in Gemini, so rtk asking on it is stricteraskrules or the prefixes they hold, the unreadable-rules early return, the legacy-key mapping, the shared reader's handling of a path under a regular file or a BOM, the unreadable OpenCode or Gemini config, Gemini's unknown folder trust, each input to Gemini's folder trust (either environment variable, the default, an undecided folder read as trusted or as untrusted), the allows both Gemini files must share or the asks either one holds, the global confirmations a trusted folder keeps, the swap gate's worktree check (removed, narrowed to a word, or reading the typed command), or any reader of the transparent prefixes orexclude_commandsgoing back to the config each fails a test🤖 Generated with Claude Code