Skip to content

feat(hooks): add Factory Droid integration#2267

Open
krimvp wants to merge 2 commits into
rtk-ai:developfrom
krimvp:feat/droid-integration
Open

feat(hooks): add Factory Droid integration#2267
krimvp wants to merge 2 commits into
rtk-ai:developfrom
krimvp:feat/droid-integration

Conversation

@krimvp
Copy link
Copy Markdown

@krimvp krimvp commented Jun 4, 2026

Closes #2099

Summary

Adds first-class Factory Droid support so shell commands the agent runs are transparently rewritten to their token-saving rtk equivalents.

  • rtk init --agent droid — installs a native PreToolUse hook into ~/.factory/settings.json (matcher Execute). Supports global (-g) and project scope, the FACTORY_HOME override, idempotent install with .bak backup + atomic write, and a clean uninstall round-trip (--uninstall).
  • rtk hook droid — processes 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.

Protocol verified against Factory's hooks reference: Execute matcher, tool_input.command, hookSpecificOutput with permissionDecision/updatedInput, hooks stored in ~/.factory/settings.json.

Demo

End-to-end: build from source → install → Droid runs commands (RTK rewrites them live) → uninstall.

RTK x Factory Droid demo

If the GIF doesn't load inline, it's here: https://gist.github.com/krimvp/de2c1f86db84982a4176839b45825920

Test plan

  • cargo fmt --all clean
  • cargo clippy --all-targets — zero warnings
  • cargo test — 2021 passed (16 Droid-specific: install/uninstall round-trip, idempotency, matcher-group reuse, deny step-aside, auto-allow, legacy Bash matcher, passthrough)
  • Verified live against the real droid CLI (v0.140.0): hook fires on Execute, rewrites git status/git logrtk …, savings tracked in rtk gain
  • ~/.factory/settings.json restored byte-identical after --uninstall

Docs

README updated — Supported Agents list + integration table row.

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.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jun 4, 2026

CLA assistant check
All committers have signed the CLA.

@krimvp krimvp marked this pull request as ready for review June 4, 2026 15:09
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Support for Factory Droid CLI

2 participants