Repository navigation
fix(hooks): treat OpenCode 1.x default verdict as allow when rule sources are readable (#4638) - #4926
feliperm17 wants to merge 3 commits into
Conversation
`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`, whose single walk of the
settings also says whether a fish script may be wrapped, so the fish wrap
no longer reads them a second time.
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, so it
leaves git as typed in a managed worktree just as the hook does.
`rtk hook check --agent claude` gives that answer too, from the directory
it runs in.
`rtk hook check --agent opencode` now gives the plugin's answer: 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. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rces are readable (rtk-ai#4638)
📊 Automated PR Analysis
SummaryMaps OpenCode 1.x's default PermissionVerdict::Default to Allow in HostRules::verdict so rtk's allow-rewrites of kubectl/oc/npm/gcloud/git/aws actually apply, while failing closed to Unjudgeable when a selected config source exists but can't be read or parsed. Also refactors the Claude Code discover coverage path to use the shared HostRules abstraction instead of a bespoke PermissionRules struct, and adds extensive unit/integration tests. Review Checklist
Linked issues: #4638 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
|
Hi @KuSh! I'd like to share an update on #4638 and ask for your guidance before making further changes to this PR. During independent validation, I found that the The current implementation inherits some limitations from the historical #4458 base, particularly:
In certain valid configurations, these limitations can cause the hook to return a rewrite even when OpenCode would evaluate the original command as I've developed a local experimental solution combining the configuration discovery work from #4932 with additional permission-handling improvements. The previously identified 16 permission-mismatch cases now pass independent validation, along with 5,377 Rust tests and additional regression scenarios. However, the experimental patch has grown considerably, and I haven't pushed it or ported it to the latest #4458 implementation. There are also limitations involving remote/managed configurations and session-resolved permissions that aren't fully addressed. Before making this PR significantly larger, I'd appreciate your opinion on the best approach: Would you prefer that we first reconcile #4458 and #4932, then keep #4926 focused on the remaining I'm happy to adapt the implementation to whichever approach fits the project's architecture and review process best. Thanks for your time! |
Closes #4638
Summary
PermissionVerdict::DefaulttoPermissionVerdict::AllowinHostRules::verdictfor OpenCode (Rules::Ordered), matching OpenCode 1.x's built-in* -> allowrule sortk-prefixed allow policies (e.g.,"rtk *": "allow"or selective bare allows) rewritekubectl,oc,npm,gcloud,git, andawsinstead of returning{}.Rules::Unjudgeable({}) inload_judgeable_opencode_ruleswhenever a selected config source (OPENCODE_CONFIG, global config, nearest project config, or inspected agent markdown file) exists on disk but fails to be read or parsed as JSON, preventing an unreadable file from falling back to the built-in allow.src/hooks/*andtests/hook_decision_protocol_test.rscovering the 16-case(before, after)transition matrix,#4195(* -> deny), explicitask/denyrules, compound commands, unattestable constructs, and unreadable/malformed config sources.Test plan
cargo fmt --all && cargo clippy --all-targets && cargo test(5,302 passed, 0 failed, 8 ignored; zero clippy warnings or fmt diffs)rtk <command>output inspected (rtk hook opencode -- kubectl get pods,oc get pods,npm run build,gcloud compute instances list,git status, andaws sts get-caller-identityverified across default,"rtk *": "allow", and selective"rtk *": "allow" + "git *": "allow" + "aws *": "allow"configs)