feat: integrate RTK (Rust Token Killer) for LLM token optimization (Copilot + OpenCode)#431
feat: integrate RTK (Rust Token Killer) for LLM token optimization (Copilot + OpenCode)#431
Conversation
Agent-Logs-Url: https://github.com/sparkfabrik/sparkdock/sessions/d7415780-54f0-4ab4-ac17-fb7ae46b16c2 Co-authored-by: francescoben <[email protected]>
Review feedback1.
|
francescoben
left a comment
There was a problem hiding this comment.
see comment #431 (comment)
…ed_when Agent-Logs-Url: https://github.com/sparkfabrik/sparkdock/sessions/d906b6ca-9dc7-4733-b545-194ec88e1441 Co-authored-by: francescoben <[email protected]>
All three points addressed in commit
|
Idempotency issue with backup/restore approachThe current backup/restore pattern has a duplication problem: running Proposed solution: temp dir + blockinfile with markersInstead of running Example for Copilot: - name: Initialize RTK for Copilot in temp directory
shell: |
TMPDIR=$(mktemp -d)
cd "$TMPDIR"
rtk init --copilot --auto-patch
echo "$TMPDIR"
register: rtk_tmpdir
become: false
- name: Copy RTK hooks to Copilot config
copy:
src: "{{ rtk_tmpdir.stdout }}/.github-copilot/hooks/"
dest: "{{ ansible_facts['env']['HOME'] }}/.github-copilot/hooks/"
remote_src: true
become: false
- name: Inject RTK instructions into Copilot custom-instructions.md
blockinfile:
path: "{{ ansible_facts['env']['HOME'] }}/.github-copilot/custom-instructions.md"
marker: "<!-- {mark} RTK MANAGED BLOCK -->"
block: "{{ lookup('file', rtk_tmpdir.stdout + '/.github-copilot/custom-instructions.md') }}"
create: yes
become: false
- name: Cleanup temp directory
file:
path: "{{ rtk_tmpdir.stdout }}"
state: absentKey points:
|
… for RTK init Agent-Logs-Url: https://github.com/sparkfabrik/sparkdock/sessions/6c79097f-5af8-4092-967a-572306583224 Co-authored-by: francescoben <[email protected]>
Addressed in commit The backup/restore pattern is replaced with the tmpdir +
Both tmpdirs are cleaned up after their respective inject steps. |
|
@copilot you can remove everything related to Claude code, we only need to support Copilot and Opencode |
…de only Agent-Logs-Url: https://github.com/sparkfabrik/sparkdock/sessions/49c6b307-5999-447b-8e85-729226169e42 Co-authored-by: francescoben <[email protected]>
Done in commit |
|
@copilot please add some test for the ansible playbook. We already have a github workflow for that |
…ook workflow Agent-Logs-Url: https://github.com/sparkfabrik/sparkdock/sessions/05bbeb5b-7a94-4691-83d6-0bba548f7ea6 Co-authored-by: francescoben <[email protected]>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
There was a problem hiding this comment.
Pull request overview
Adds RTK (Rust Token Killer) to the macOS provisioning flow so developer machines get token-optimization hooks configured for GitHub Copilot and OpenCode, and extends CI to validate first-run behavior plus idempotency of the Copilot instructions injection.
Changes:
- Add
rtkto the default Homebrew package list. - Add an Ansible
rtk-tagged block to initialize RTK for Copilot (hook copy + instructionsblockinfile) and OpenCode. - Extend the Ansible playbook workflow to validate RTK setup on first run and ensure the managed block is idempotent and preserves user content.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| config/packages/all-packages.yml | Adds rtk to default brew packages so it’s available during provisioning. |
| ansible/macos/macos/base.yml | Implements RTK initialization + Copilot hook/instructions installation and OpenCode init. |
| CHANGELOG.md | Documents the addition of RTK (currently mismatched with implementation). |
| .github/workflows/test-ansible-playbook.yml | Adds CI checks for RTK presence + Copilot instructions idempotency. |
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
… error Agent-Logs-Url: https://github.com/sparkfabrik/sparkdock/sessions/d29eade8-2b22-4c29-b3eb-7ecf9f2da086 Co-authored-by: francescoben <[email protected]>
…pilot init Agent-Logs-Url: https://github.com/sparkfabrik/sparkdock/sessions/8559fcf9-794d-416a-9292-31edbcfb5bbd Co-authored-by: francescoben <[email protected]>
|
@copilot resolve the merge conflicts in this pull request |
Co-authored-by: francescoben <[email protected]>
Done in commit |
Wrong path for Copilot CLI hooksTesting revealed that Copilot CLI does not read hooks from Copilot CLI reads hooks and instructions from Since we primarily use Copilot CLI (terminal), please update the Ansible tasks to copy the hooks and instructions to If we want to support both VS Code Copilot Chat and Copilot CLI, we need to write to both paths:
|
…~/.github/ (VS Code) Agent-Logs-Url: https://github.com/sparkfabrik/sparkdock/sessions/a7fea805-cf99-4d2f-b36b-dbe9a221e7db Co-authored-by: francescoben <[email protected]>
Done in commit
Both use the same tmpdir output (from a single |
|
@paolomainardi ready for your review. Here's a summary of the final implementation: Implementation overviewRTK is installed via Homebrew ( GitHub Copilotrtk init has a known upstream bug rtk-ai/rtk#1512: it overwrites existing instruction files instead of appending. This means any custom instructions the user has would be lost. We designed a workaround:
OpenCodeOpenCode uses a TypeScript plugin, so no instruction file is involved — rtk init -g --opencode runs directly without the temp directory workaround. IdempotencyThe whole flow is fully idempotent:
Paths
TestingBoth myself and @giuliobracci actively worked on this, from designing the workaround approach to testing the full flow on our machines:
|
|
|
||
| - name: Display RTK initialization status | ||
| debug: | ||
| msg: "✅ RTK initialized for GitHub Copilot and OpenCode. Restart your AI coding tools to activate." |
There was a problem hiding this comment.
@francescoben I want to move all that logic into a sjust task (the shared one) and a reusable install script, so that we can:
- Manual re-run from sjust
- Easy to integrate in the archlinux provisioner @Monska85
Adds RTK (Rust Token Killer) to the macOS provisioning flow to enable token-optimization hooks for GitHub Copilot and OpenCode, with idempotent instruction file injection and CI validation.
Changes Made
rtkto the default Homebrew package listansible/macos/macos/base.yml):rtk init --copilot --auto-patchin an isolated temp directoryblockinfileto both Copilot paths:~/.github/hooks/+~/.github/copilot-instructions.md→ VS Code Copilot Chat~/.copilot/hooks/+~/.copilot/copilot-instructions.md→ Copilot CLI (terminal)rtk init -g --opencode --auto-patchfor OpenCode (plugin-based, no instruction file merge needed)blockinfilewith<!-- BEGIN/END RTK MANAGED BLOCK -->markers ensures re-provisioning replaces only the RTK content — user instructions outside the markers are never touched.github/workflows/test-ansible-playbook.yml): Extended with RTK validation steps that assert both~/.github/and~/.copilot/paths are populated on first run and that neither file accumulates duplicate blocks across re-provisions (user content preservation verified)masterresolved, keeping both the RTK entry and the~/.local/binPATH entry