Skip to content

fix(copilot): support IDE terminal hooks - #3093

Merged
KuSh merged 2 commits into
rtk-ai:developfrom
lntutor:fix/2443-copilot-ide-terminal
Jul 26, 2026
Merged

KuSh merged 2 commits into
rtk-ai:developfrom
lntutor:fix/2443-copilot-ide-terminal

Conversation

@lntutor

@lntutor lntutor commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • recognize JetBrains Copilot's camelCase run_in_terminal payload separately from Copilot CLI bash
  • return top-level deny-with-suggestion responses because the IDE host ignores modifiedArgs
  • enforce explicit permission denials through the same host-supported response
  • stay silent for deferred, unsupported, already-RTK, and non-terminal tool calls
  • preserve existing Copilot CLI transparent rewrite behavior

Testing

  • focused IDE detection, rewrite, deny, and defer tests
  • full existing Copilot CLI regression suite
  • cargo fmt --all -- --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test --all-features (2,499 passed, 8 ignored)

Closes #2443

@CLAassistant

CLAassistant commented Jul 20, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

KuSh added a commit that referenced this pull request Jul 26, 2026
…ot generated

The doc comments described the camelCase toolName/toolArgs schema as "GitHub
Copilot CLI"'s format, which was accurate when rtk init --copilot registered
it. Now that only the PascalCase schema is generated, this path is reachable
only via not-yet-upgraded installs' leftover registration, or hosts that use
this schema under a different toolName value on their own (JetBrains/
IntelliJ's Copilot plugin sends "run_in_terminal", tracked in #2443/#3093).
Note both call sites accordingly so the code isn't mistaken for dead weight.
@KuSh

KuSh commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

Heads-up on some overlapping context from #3212 (in review), which also touches detect_format/HookFormat::CopilotCli in src/hooks/hook_cmd.rs:

  • We found the handle_vscode/PascalCase path had never had its literal permissionDecision: "ask" fixed (that's the root cause of rtk hook copilot emits permissionDecision "ask", forcing a permission prompt on every command in Copilot CLI >= 1.0.66 #3037 — 84aa4d6/0df6929 only patched the camelCase native path). fix(hooks): stop Copilot from silently deciding permission on unconfigured commands #3212 makes both schemas only assert permissionDecision: allow for an explicit user Allow rule, mirroring process_claude_payload.
  • We also found rtk init --copilot's dual PreToolUse/preToolUse registration causes Copilot CLI to run both hooks sequentially per tool call (confirmed live, order-independent) — the camelCase one does the real rewrite, the PascalCase one then defers on the already-rewritten command. fix(hooks): stop Copilot from silently deciding permission on unconfigured commands #3212 drops the camelCase registration since Copilot CLI honors the PascalCase-only schema fine on its own; existing installs upgrade on next rtk init --copilot re-run.
  • Practically for this PR: the camelCase toolName/toolArgs schema is no longer what rtk init --copilot generates, but it's still very much alive — both for installs that haven't re-run init yet, and as the schema JetBrains/IntelliJ's plugin already uses under toolName: "run_in_terminal" (distinct from Copilot CLI's "bash"). So this PR's approach (recognizing run_in_terminal in the camelCase branch, deny-with-suggestion for the IDE host) still stands on its own — no conflict, just flagging the shared code area so the rebase/review has context.

Happy to coordinate further if useful.

@KuSh KuSh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @lntutor,
Thanks for your contribution!

It LGTM apart from a missing test (minor).
You'll also have to sign the CLA before we could merge your work.

Comment thread src/hooks/hook_cmd.rs Resolved
@lntutor
lntutor force-pushed the fix/2443-copilot-ide-terminal branch from fde0058 to d0f004f Compare July 26, 2026 04:58
@lntutor

lntutor commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

@KuSh both review points are addressed:

  • Missing test — added test_copilot_ide_allow_rewrite_returns_deny_with_suggestion (in d0f004f), driving copilot_ide_response_from_decision with HookDecision::AllowRewrite(...) and asserting a deny decision, the rewritten command in the reason, and no modifiedArgs. This pins the "Allow also becomes deny" behavior explicitly rather than leaving it implicit in the AllowRewrite | AskRewrite arm. Local gate green: cargo fmt --all -- --check, cargo clippy --all-targets --all-features -- -D warnings, cargo test --all-features (2442 passed).
  • CLA — signed; license/cla is passing.

Re-requesting review when you have a moment.

@KuSh KuSh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@KuSh KuSh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few clippy lints that need addressing before merging

Resolve a semantic (non-textual) merge conflict: develop's 0df6929
changed HookDecision::AskRewrite from a tuple variant AskRewrite(String)
to a struct variant AskRewrite { rewritten, explicit }. The auto-merge
left two copilot-IDE usages in the old tuple form, breaking the build:

- copilot_ide_response_from_decision match arm: bind `rewritten` from
  the struct variant via `AskRewrite { rewritten, .. }`.
- test_copilot_ide_rewrite_returns_deny_with_suggestion: construct the
  struct variant with `explicit: false` (a default, non-user-configured
  rewrite; the IDE path ignores the field).

Gate green: cargo fmt --all --check, cargo clippy --all-targets
--all-features -D warnings, cargo test --all-features (2497 passed).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01G8b9dEaJtpvydzz4ttM7JH
@lntutor

lntutor commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

@KuSh pushed b434fd2 — the CI failure wasn't clippy lints but a semantic merge conflict: develop's 0df6929 changed HookDecision::AskRewrite from a tuple variant AskRewrite(String) to a struct variant AskRewrite { rewritten, explicit }. My branch still had the old tuple form, so it compiled/tested green locally but broke once merged against develop (that's exactly the shared hook_cmd.rs area you flagged from #3212/0df6929).

Fixed by merging develop and updating the two surviving tuple-form usages:

  • copilot_ide_response_from_decision match arm → AskRewrite { rewritten, .. }
  • test_copilot_ide_rewrite_returns_deny_with_suggestion constructor → AskRewrite { rewritten: ..., explicit: false } (default, non-user-configured rewrite; the IDE path ignores the field)

Resolution is folded into the merge commit so it compiles bisect-clean. Local gate green: cargo fmt --all -- --check, cargo clippy --all-targets --all-features -- -D warnings (no warnings), cargo test --all-features (2497 passed).

The new run is stuck at action_required — mind approving the CI run and taking another look when you have a moment? Thanks!

@KuSh
KuSh merged commit 1d6798d into rtk-ai:develop Jul 26, 2026
10 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 26, 2026
@pszymkowiak

Copy link
Copy Markdown
Collaborator

Quick status check since the last review round: the clippy lints flagged between the LGTM 🚀 and the follow-up CHANGES_REQUESTED look resolved already. The merge commit b434fd2 fixed the semantic conflict with develop's 0df6929 (AskRewrite tuple → struct variant), and building the branch locally confirms it's green:

  • cargo clippy --all-targets — no issues
  • cargo fmt --all --check — clean
  • cargo test --all — 2561 passed, 8 ignored

Might be worth a re-review to clear the stale CHANGES_REQUESTED — the blocking issue itself looks fixed.

Separate, non-blocking observation while reading through: copilot_ide_response_from_decision's AllowRewrite/AskRewrite arm calls audit_log("rewrite", cmd, &rewritten) — the same action label used elsewhere for rewrites that actually get applied transparently. Here the response is a deny-with-suggestion (the user has to manually re-type the command), so it's a different kind of event even though the label is identical. Not asking for a change here, just flagging in case it's worth a distinct label (e.g. "suggest") later, since hook_audit_cmd.rs counts action == "rewrite" for its stats and this would blend two different outcomes into one number.

KuSh added a commit that referenced this pull request Jul 26, 2026
…ot generated

The doc comments described the camelCase toolName/toolArgs schema as "GitHub
Copilot CLI"'s format, which was accurate when rtk init --copilot registered
it. Now that only the PascalCase schema is generated, this path is reachable
only via not-yet-upgraded installs' leftover registration, or hosts that use
this schema under a different toolName value on their own (JetBrains/
IntelliJ's Copilot plugin sends "run_in_terminal", tracked in #2443/#3093).
Note both call sites accordingly so the code isn't mistaken for dead weight.
KuSh added a commit that referenced this pull request Jul 27, 2026
…ot generated

The doc comments described the camelCase toolName/toolArgs schema as "GitHub
Copilot CLI"'s format, which was accurate when rtk init --copilot registered
it. Now that only the PascalCase schema is generated, this path is reachable
only via not-yet-upgraded installs' leftover registration, or hosts that use
this schema under a different toolName value on their own (JetBrains/
IntelliJ's Copilot plugin sends "run_in_terminal", tracked in #2443/#3093).
Note both call sites accordingly so the code isn't mistaken for dead weight.
KuSh added a commit that referenced this pull request Jul 27, 2026
…owershell

Contributor testing on Windows 11 with Copilot CLI 1.0.73 (#3179) confirmed
Copilot CLI remaps its native bash/powershell shell tool to tool_name: "Bash"
under the PascalCase PreToolUse schema, and that its updatedInput is honored
end-to-end there. Since rtk init --copilot now only registers that schema,
Windows already works standalone through it — the camelCase toolName
"powershell" case (#3178/#3179) becomes legacy-only, relevant solely to
un-upgraded installs. Document that on both HookFormat variants.

Also fixes a HookDecision::AskRewrite struct-pattern leftover in
copilot_ide_response_from_decision (added by #3093, merged into develop
after this branch's own struct-to-tuple AskRewrite refactor), surfaced as a
compile error by rebasing onto develop to pick up #3179.
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.

rtk hook copilot no-op in JetBrains/IntelliJ Copilot plugin — camelCase run_in_terminal not matched, and IDE host only honors permissionDecision: deny

4 participants