feat: add Gemini CLI support via rtk init --gemini#174
feat: add Gemini CLI support via rtk init --gemini#174ousamabenyounes wants to merge 9 commits intortk-ai:developfrom
Conversation
| # 2. Initialize for Claude Code (RECOMMENDED: hook-first mode) | ||
| rtk init --global | ||
| # 2. Initialize (RECOMMENDED: hook-first mode) | ||
| rtk init --global # For Claude Code |
There was a problem hiding this comment.
To keep it understandable/simple in six months, I will have taken this approach:
rtk init --claudertk init --geminirtk init --global-> auto CLIs detection (search for ~/.gemini and ~/.claude)
(By the way, Hey Ousama, I hope you are doing well 😄)
There was a problem hiding this comment.
There is a PR in progress similar to this one.
#158
There was a problem hiding this comment.
Hey! I’m doing great, hope you are too 🙂
I’m aligned with your approach and implementing it in a lightweight way.
There was #131, but it was considered too large and needed splitting.
So I decided to move forward with a lighter, more focused version instead.
I’ve also applied the requested fixes:
feat: auto-detect CLIs with rtk init --global, add --claude flag
I’m against duplicate work… just like I’m against copy-paste code 😄
Happy to align if #158 already covers it.
6b2e23b to
c22f6d0
Compare
|
hey just a heads up I've had one version of gemini support available for a bit here: #158 |
|
Hi @ousamabenyounes, the integration design is thoughtful. The idempotent Before this can move forward, one issue to fix and one broader question:
|
c22f6d0 to
868467b
Compare
|
Thanks for the detailed review @FlorianBruniaux — both points were spot on. Why I initially went with shell: Why I pivoted to Rust:
Live testing on both CLIs:
Automated tests:
|
|
Will this work in antigravity? If so, how can I try it? Related to this discussion #233 |
|
I haven't used Antigravity yet so I can't test it directly. If someone with Antigravity access wants to test it, the setup is simply: If Antigravity uses a different tool name or hook protocol than Gemini CLI, we'd need to adapt — happy to do so if someone can share the hook input JSON format. |
|
Hi @ousamabenyounes, sorry — there have been a lot of changes on master since this PR was opened. Could you please rebase on latest master? Thanks! |
Introduce first-class support for Gemini CLI by adding a dedicated initialization mode. This allows Gemini users to benefit from RTK's token optimization with the same ease as Claude Code users. - Add --gemini flag to 'rtk init' command - Implement run_gemini_mode() in src/init.rs for global setup - Automated installation of the rewrite hook in ~/.gemini/hooks/ - Intelligent GEMINI.md patching using upsert_rtk_block (preserves user content) - Support for ~/.gemini/RTK.md slim instructions - Update 'rtk init --show' to display Gemini configuration status - Update 'rtk init -g --uninstall' to clean up Gemini artifacts - Add comprehensive automated test: scripts/test-gemini-init.sh - Update INSTALL.md and README.md with Gemini setup instructions Collaboration: - Vision & Prompt Architecture: Ousama Ben Younes - Technical Implementation: Gemini AI (Google) Co-authored-by: Gemini AI <assistant@google.com>
Introduce first-class support for Gemini CLI by adding a dedicated initialization mode. This allows Gemini users to benefit from RTK's token optimization with the same ease as Claude Code users. - Add --gemini flag to 'rtk init' command - Implement run_gemini_mode() in src/init.rs for global setup - Automated installation of the rewrite hook in ~/.gemini/hooks/ - Intelligent GEMINI.md patching using upsert_rtk_block (preserves user content) - Support for ~/.gemini/RTK.md slim instructions - Update 'rtk init --show' to display Gemini configuration status - Update 'rtk init -g --uninstall' to clean up Gemini artifacts - Add comprehensive automated test: scripts/test-gemini-init.sh - Update INSTALL.md and README.md with Gemini setup instructions Collaboration: - Vision & Prompt Architecture: Ousama Ben Younes - Technical Implementation: Gemini AI (Google) Co-authored-by: Gemini AI <assistant@google.com>
…ed functions - Convert all French comments in REWRITE_GEMINI_HOOK constant to English - Translate doc comments and inline comments in patch_gemini_settings_json - Maintain exact same functionality, only language changes
- Fix grep pattern for cargo test output (add 'passed' detection) - Replace skip with skip_test for pytest, ruff, pip, go, golangci-lint - Skip learn test when Claude Code not installed - Result: 0 failures, 87 passed, 6 skipped
Replace 95-line bash Gemini hook with a Rust binary approach: - New src/hook_cmd.rs: standalone Gemini BeforeTool hook processor with 49 unit tests covering all command families (git, cargo, docker, kubectl, Python, Go, npm, etc.) - Uses correct Gemini CLI protocol: hookSpecificOutput.tool_input (not updatedInput) for command rewriting - Zero dependency on jq for Gemini users - Gemini hook in init.rs reduced to 3-line wrapper: exec rtk hook gemini - hooks/rtk-rewrite.sh restored to upstream thin delegator (no regression) - Tested end-to-end on both Claude Code and Gemini CLI Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
e5c64e7 to
2ada408
Compare
|
Done! Rebased on latest master (0.28.2). Full test suite is green:
|
accfb4a to
2f74637
Compare
- Add 3 smoke tests for Gemini CLI hook: - rewrites git status to rtk git status - passes through non-rewritable commands (echo) - skips already-rewritten commands (no double-rewrite) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2f74637 to
e5c0f09
Compare
- Add `rtk hook gemini` command: native Rust hook processor for Gemini CLI BeforeTool hooks. Reads JSON from stdin, delegates to `rewrite_command()` (single source of truth), outputs Gemini-format JSON response. - Add `--gemini` flag to `rtk init`: installs hook wrapper script, GEMINI.md, and patches ~/.gemini/settings.json with BeforeTool hook entry. - Add `rtk init -g --gemini --uninstall`: clean removal of all Gemini artifacts. - 6 unit tests covering hook format, rewrite delegation, and exclusions. Replaces PR rtk-ai#174 which had too many conflicts after upstream restructuring. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Ousama Ben Younes <benyounes.ousama@gmail.com>
|
Closing in favor of #573 — clean reimplementation on latest Key improvements in the new PR:
|
Summary
Introduce first-class support for Gemini CLI by adding a dedicated initialization mode that provides token optimization with the same ease-of-use as Claude Code integration.
Key Features
Core Implementation
rtk init --global --geminifor one-command setup~/.gemini/settings.jsonrtk init -g --uninstallremoves all Gemini artifacts cleanlyHook Mechanism
run_shell_commandtool calls before executionUser Experience
GEMINI.mdupdates preserve user content (viaupsert_rtk_block)rtk init --showdisplays Gemini configuration state~/.gemini/RTK.mdprovides concise command documentationgemini /hooksconfirms hook registrationTechnical Details
Files Changed
Architecture Decisions
Separate hook implementation (
REWRITE_GEMINI_HOOK):BeforeToolmatcher)settings.jsonregistration (vs. auto-discovery)Reused core logic:
upsert_rtk_block(): Consistent update mechanism across AI toolsensure_hook_installed(): Parameterized for hook content injectionuninstall(): Extended to handle both Claude and Gemini artifactsRobust error handling:
Testing Strategy
Comprehensive test coverage via
scripts/test-gemini-init.sh:settings.jsonstructure and hook presenceAll tests use isolated
$HOMEto avoid pollution.Usage Example
Documentation Updates
Compatibility
jqfor JSON parsing in hook scriptMigration Path
Existing Gemini users can adopt RTK with zero config changes:
Checklist
cargo test)scripts/test-gemini-init.sh)Author: Ousama Ben Younes ([@ousamabenyounes](https://github.com/ousamabenyounes))
Implementation Notes:
This PR was developed using AI-assisted coding with Gemini AI. The architecture, testing strategy, and integration design were manually crafted; code generation was AI-assisted and manually reviewed.