Skip to content

feat(init): complete Copilot lifecycle - uninstall, idempotency, show_config#728

Open
jeziellopes wants to merge 1 commit intortk-ai:developfrom
jeziellopes:feat/copilot-init-agent
Open

feat(init): complete Copilot lifecycle - uninstall, idempotency, show_config#728
jeziellopes wants to merge 1 commit intortk-ai:developfrom
jeziellopes:feat/copilot-init-agent

Conversation

@jeziellopes
Copy link
Copy Markdown
Contributor

@jeziellopes jeziellopes commented Mar 19, 2026

Context

PR #859 (merged) shipped a basic --copilot flag from PR #824. This PR completes what was shipped — adding the full agent lifecycle that every other agent in rtk has.

Upstream's current run_copilot() installs files and exits. No idempotency. No uninstall. rtk init --show is blind to Copilot files. This PR fills all of those gaps.

What this adds on top of what shipped

Feature --copilot (upstream, merged) --agent copilot (this PR)
Installs .github/ files
Enum pattern (--agent copilot) ❌ standalone --copilot: bool ✅ consistent with --agent cline/windsurf/cursor
Idempotency ❌ always re-runs ✅ early-return with clear status message
PATH check for rtk binary ❌ none utils::tool_exists() — cross-platform, no false positives on Windows
--uninstall --agent copilot ❌ no uninstall path exists ✅ strips RTK section, preserves pre-existing user content
rtk init --show Copilot status show_config() has no Copilot awareness [ok]/[--] for both .github/ files
Unit tests 0 6 new tests

Also fixes #836 / supersedes #837

Issue #836 reports that users who ran rtk init --copilot early on got .github/hooks/rtk-rewrite.json with "command": "rtk hook" (missing subcommand), causing a parse_failure entry on every Bash tool call.

Changes

File Change
src/main.rs AgentTarget::Copilot enum variant; "hook" added to RTK_META_COMMANDS; routing to run_copilot_mode()
src/hooks/init.rs run_copilot_mode() (idempotent install), full uninstall branch (content-safe), show_config() checks, 6 unit tests
.github/hooks/rtk-rewrite.json "rtk hook""rtk hook copilot" (embedded via include_str!, single source of truth)
CHANGELOG.md [Unreleased] entries
# Install (project-scoped, idempotent)
rtk init --agent copilot
# → .github/hooks/rtk-rewrite.json  (PreToolUse hook)
# → .github/copilot-instructions.md (RTK usage rules)

# Uninstall (strips RTK section, preserves pre-existing user content)
rtk init --uninstall --agent copilot

# Check status
rtk init --show

Testing

✅ cargo fmt --all
✅ cargo clippy --all-targets (0 warnings)
✅ 1129 tests passed (6 new Copilot tests)
✅ Manual: install → idempotent re-run → uninstall → content preserved — all verified

@jeziellopes jeziellopes force-pushed the feat/copilot-init-agent branch from ed8bc50 to 83e2f8d Compare March 19, 2026 13:36
dgehriger added a commit to dgehriger/rtk that referenced this pull request Mar 20, 2026
Implements PR rtk-ai#728 functionality with improvements:
- rtk init --agent copilot installs both the hook JSON AND lean instructions
- The hook (.github/hooks/rtk-rewrite.json) does the heavy lifting
- Instructions file is minimal (~15 lines) to avoid context pollution
- Uninstall removes instructions but preserves shared hook JSON
- Idempotent: re-running is safe

Unlike upstream PR rtk-ai#728 which only reports hook status, this version
actually installs the hook JSON, making it a one-command setup.

Signed-off-by: Daniel Gehriger <dgehriger@globusmedical.com>
@jeziellopes jeziellopes force-pushed the feat/copilot-init-agent branch 2 times, most recently from df22aac to e59e5a8 Compare March 20, 2026 14:15
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 20, 2026

CLA assistant check
All committers have signed the CLA.

@jeziellopes jeziellopes force-pushed the feat/copilot-init-agent branch from e59e5a8 to d11c613 Compare March 25, 2026 22:59
@jeziellopes
Copy link
Copy Markdown
Contributor Author

jeziellopes commented Mar 25, 2026

Updated PR to address review gaps and align with issue #823:

Changes in this force-push:

  • Switched from hooks/copilot-rtk-rules.md (new file) to hooks/copilot-rtk-awareness.md (existing file, as specified in feat: rtk init --agent copilot (automated Copilot VS Code + CLI setup) #823)
  • Added PATH verification: warns if rtk binary not in $PATH
  • Added -g flag guard: warns that Copilot setup is always project-scoped
  • Improved idempotent messaging: single "RTK already configured for GitHub Copilot" + early return (matching Cline/Windsurf pattern)
  • Added show_config() status checks: [ok]/[--] for .github/hooks/rtk-rewrite.json and .github/copilot-instructions.md
  • Added rtk init --agent copilot to show_config() Usage block

Additional fixes (self-review, commit 37ebc24):

  • Fixed cross-platform PATH check: replaced which (Unix-only) with crate::utils::tool_exists() — no false-positive warnings on Windows
  • Fixed uninstall data loss: now strips only the RTK section from copilot-instructions.md instead of deleting the whole file; preserves pre-existing user content
  • Added test_uninstall_copilot_preserves_user_content to cover the data-loss scenario
  • All 1120 tests pass

Note on #824: PR #824 uses --copilot flag; this PR uses --agent copilot as specified in #823 (consistent with existing --agent cline/--agent windsurf pattern). Happy to align if you prefer one form.

@jeziellopes jeziellopes force-pushed the feat/copilot-init-agent branch 3 times, most recently from 4ff3257 to bd487d6 Compare March 25, 2026 23:24
@aeppling
Copy link
Copy Markdown
Contributor

Hey

We are cleaning up the codebase and improving the project structure for better onboarding. As part of this effort, PR #826 reorganizes src/ from a flat layout into subfolders.

No logic changes — only file moves and import path updates.

What you need to do

Rebase your branch on develop when receiving this comment:

git fetch origin && git rebase origin/develop

Git 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

@jeziellopes jeziellopes force-pushed the feat/copilot-init-agent branch 2 times, most recently from ad26930 to fe1cbf3 Compare March 26, 2026 20:17
@jeziellopes
Copy link
Copy Markdown
Contributor Author

Rebased onto develop after PR #826 (src/ reorganization).

Changes to accommodate the new folder structure:

  • src/init.rssrc/hooks/init.rs (auto-merged cleanly by git)
  • include_str! paths updated: ../hooks/copilot-rtk-awareness.md../../hooks/copilot/rtk-awareness.md, and similarly for the hook JSON
  • crate::utils::tool_existsuse crate::core::utils import added (utils moved to src/core/utils.rs)
  • All routing in src/main.rs already used hooks::init:: prefix — no changes needed there

1129 tests pass, 0 clippy errors.

@jeziellopes jeziellopes force-pushed the feat/copilot-init-agent branch from fe1cbf3 to ca69951 Compare March 26, 2026 20:21
@jeziellopes jeziellopes force-pushed the feat/copilot-init-agent branch 2 times, most recently from cf8e1c5 to 2f98d0a Compare April 3, 2026 21:41
@jeziellopes
Copy link
Copy Markdown
Contributor Author

Hi @aeppling, rebased and CI-clean after the #826 refactor. I'm actively using GitHub Copilot CLI day-to-day and this is a missing piece for me. Waiting for a review on it. Thanks!

@jeziellopes jeziellopes force-pushed the feat/copilot-init-agent branch 2 times, most recently from 6d791ed to 94cca62 Compare April 8, 2026 14:47
@jeziellopes jeziellopes changed the title feat(copilot): add rtk init --agent copilot support feat(init): complete Copilot lifecycle - uninstall, idempotency, show_config Apr 8, 2026
@jeziellopes
Copy link
Copy Markdown
Contributor Author

Re: #836 and #837

PR #837 (rolf-quadra) targets the orphaned .github/hooks/rtk-rewrite.json bug from #836"command": "rtk hook" (missing subcommand) causes a parse_failure on every Bash tool call.

This PR already covers that surface:

  • --uninstall --agent copilot removes .github/hooks/rtk-rewrite.json cleanly
  • rtk init --show will expose the Copilot files so users can inspect/verify state

Merging this PR resolves the scenario described in #836 and makes #837 redundant. Flagging in case it helps triage both together.

@jeziellopes
Copy link
Copy Markdown
Contributor Author

@aeppling — updated PR description to reflect the current landscape.

Since #859 shipped, the gap is clearer now: upstream has install but no lifecycle — no idempotency, no uninstall, no rtk init --show awareness for Copilot. This PR fills all of that, plus fixes the "rtk hook" bug that's causing spurious parse_failure entries in #836 (which #837 is also trying to fix).

Happy to discuss scope or split if preferred. Thanks!

Adds GitHub Copilot to the AgentTarget enum, following the existing
--agent cline/windsurf/cursor pattern. Closes rtk-ai#823.

- AgentTarget::Copilot in src/main.rs + routing
- run_copilot_mode(): creates .github/hooks/rtk-rewrite.json and
  .github/copilot-instructions.md; idempotent (skips if already set)
- PATH check via crate::utils::tool_exists() (cross-platform, no which)
- uninstall: strips only RTK section, preserves pre-existing user content
- show_config(): [ok]/[--] status for both .github files + usage line
- Fix rtk-rewrite.json: rtk hook -> rtk hook copilot (embedded via
  include_str! so the installed hook is always correct)
- Register hook in RTK_META_COMMANDS so rtk hook copilot routes
  correctly instead of falling through to passthrough mode

Signed-off-by: Jeziel Lopes <jeziel@example.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jeziellopes jeziellopes force-pushed the feat/copilot-init-agent branch from 94cca62 to bc7049a Compare April 9, 2026 18:43
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.

4 participants