feat(hooks): add Factory Droid integration#2267
Open
krimvp wants to merge 2 commits into
Open
Conversation
Register RTK with Factory Droid so shell commands the agent runs are transparently rewritten to their token-saving `rtk` equivalents. - `rtk init --agent droid`: install a native PreToolUse hook into ~/.factory/settings.json (matcher "Execute"); supports global (-g) and project scope, the FACTORY_HOME override, idempotent install with backup + atomic write, and a clean uninstall round-trip. - `rtk hook droid`: process Droid's PreToolUse payload (BOM strip, stdin cap, JSON-parse fallback), mirroring the existing provider hooks. - Deny verdict steps aside (no output) so Droid's native deny handling fires, matching Claude/Cursor/Copilot and the PermissionVerdict::Deny contract. - Rewrites are auto-allowed: Droid only applies a hook's updatedInput when the decision is "allow", so we mirror run_cursor to avoid silently dropping the rewrite (and its savings) on the default verdict.
Droid 0.140.0 applies a PreToolUse hook's updatedInput regardless of the permission decision (verified empirically + via binary decompile), so the forced permissionDecision:"allow" was unnecessary. Worse, Droid resolves the decision as the first hook result carrying one (no deny-over-allow priority), so an unconditional allow could suppress another PreToolUse hook's deny/ask and bypass Droid's native prompt. Now omit permissionDecision by default and only assert allow on an explicit allow rule, mirroring process_claude_payload. The rewrite still lands via Droid's decision-independent "updated input result" path. Updated the inaccurate comment and the test that required allow.
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.
Closes #2099
Summary
Adds first-class Factory Droid support so shell commands the agent runs are transparently rewritten to their token-saving
rtkequivalents.rtk init --agent droid— installs a nativePreToolUsehook into~/.factory/settings.json(matcherExecute). Supports global (-g) and project scope, theFACTORY_HOMEoverride, idempotent install with.bakbackup + atomic write, and a clean uninstall round-trip (--uninstall).rtk hook droid— processes Droid'sPreToolUsepayload (BOM strip, stdin cap, JSON-parse fallback), mirroring the existing provider hooks.PermissionVerdict::Denycontract.updatedInputwhen the decision isallow, so we mirrorrun_cursorto avoid silently dropping the rewrite (and its savings) on the default verdict.Protocol verified against Factory's hooks reference:
Executematcher,tool_input.command,hookSpecificOutputwithpermissionDecision/updatedInput, hooks stored in~/.factory/settings.json.Demo
End-to-end: build from source → install → Droid runs commands (RTK rewrites them live) → uninstall.
Test plan
cargo fmt --allcleancargo clippy --all-targets— zero warningscargo test— 2021 passed (16 Droid-specific: install/uninstall round-trip, idempotency, matcher-group reuse, deny step-aside, auto-allow, legacyBashmatcher, passthrough)droidCLI (v0.140.0): hook fires onExecute, rewritesgit status/git log→rtk …, savings tracked inrtk gain~/.factory/settings.jsonrestored byte-identical after--uninstallDocs
README updated — Supported Agents list + integration table row.