Embed rtk, fd, rg binaries and wrap bash with rtk#66
Conversation
- Add internal/embedded package to embed and extract tool binaries (gzip-compressed) to ANNA_HOME/bin/ on first use - Add scripts/download-tools.sh using mise to download fd, rg, rtk for the current platform - Wrap all bash tool commands with rtk for token-efficient output - Prepend ANNA_HOME/bin to PATH in bash tool so embedded tools are available to the LLM - Add mise task tools:download and goreleaser before hook
📊 Coverage ReportTotal coverage: 43.0% Per-package breakdown |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e7895593ff
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| before: | ||
| hooks: | ||
| - go mod download | ||
| - bash scripts/download-tools.sh |
There was a problem hiding this comment.
Build each target's embedded tools instead of the host set
I checked .github/workflows/release.yml:16-38: releases run GoReleaser once on a single Linux runner. This new global hook downloads fd/rg/rtk only for the current platform (scripts/download-tools.sh:4-23), but the same embedded payload is then compiled into every target in .goreleaser.yaml:16-22, including darwin, windows, and linux/arm64. As a result, every non-host artifact will ship the runner's binaries, and because envWithToolsBin prepends ANNA_HOME/bin to PATH, those releases will try to execute the wrong OS/arch tools at runtime.
Useful? React with 👍 / 👎.
| if _, err := os.Stat(destPath); err == nil { | ||
| continue // already extracted |
There was a problem hiding this comment.
Refresh embedded binaries when Anna upgrades
extractTools now treats an existing ANNA_HOME/bin/<name> as permanently valid and skips re-extracting it. Because the installed filenames are stable (fd, rg, rtk) while the embedded versions are expected to change over time, upgrading Anna will keep using the old on-disk binaries forever unless the user manually deletes ~/.anna/bin. That means future version bumps or fixes to these bundled tools will never reach existing installs.
Useful? React with 👍 / 👎.
| func wrapWithRTK(command string, _ []string) string { | ||
| if rtkPath() == "" { | ||
| return command | ||
| } | ||
| return rtkPath() + " " + command |
There was a problem hiding this comment.
Preserve shell env-prefix semantics when wrapping with rtk
Blindly concatenating rtkPath() + " " + command changes the meaning of valid bash commands that start with an environment assignment. For example, FOO=bar go test ./... currently sets a temporary env var, but after this change it becomes rtk FOO=bar go test ./..., so FOO=bar is passed as an argument instead of being applied to the command. Since the tool is documented for arbitrary shell commands, this is a real regression for any command that relies on standard shell prefixes.
Useful? React with 👍 / 👎.
- Re-extract embedded tools when anna upgrades by comparing a fingerprint (file names + sizes) stored in ANNA_HOME/bin/.embedded-version - Skip rtk wrapping for commands starting with env var assignments (e.g. FOO=bar go test) to preserve shell semantics
Goreleaser per-build hook now passes --goos/--goarch to the download script, which maps to MISE_OS/MISE_ARCH env vars. This ensures each build target embeds the correct platform's fd/rg/rtk binaries, all from a single CI runner.
Replace naive string prefix with `rtk rewrite` which correctly handles env var prefixes (FOO=bar cmd), pipes, and unsupported commands.
Guide the LLM to prefer fd/rg over find/grep since they are bundled as embedded tools.
- Remove unused env parameter from wrapWithRTK - Add 200MB size cap to extractGzip to guard against decompression bombs - Add unit tests for wrapWithRTK and envWithToolsBin
* ✨ feat: embed rtk, fd, rg binaries and wrap bash commands with rtk - Add internal/embedded package to embed and extract tool binaries (gzip-compressed) to ANNA_HOME/bin/ on first use - Add scripts/download-tools.sh using mise to download fd, rg, rtk for the current platform - Wrap all bash tool commands with rtk for token-efficient output - Prepend ANNA_HOME/bin to PATH in bash tool so embedded tools are available to the LLM - Add mise task tools:download and goreleaser before hook * 🐛 fix: address PR review — version-check extraction and rtk env-prefix - Re-extract embedded tools when anna upgrades by comparing a fingerprint (file names + sizes) stored in ANNA_HOME/bin/.embedded-version - Skip rtk wrapping for commands starting with env var assignments (e.g. FOO=bar go test) to preserve shell semantics * 🐛 fix: use mise with MISE_OS/MISE_ARCH for cross-platform tool downloads Goreleaser per-build hook now passes --goos/--goarch to the download script, which maps to MISE_OS/MISE_ARCH env vars. This ensures each build target embeds the correct platform's fd/rg/rtk binaries, all from a single CI runner. * ♻️ refactor: use rtk rewrite for smart command wrapping Replace naive string prefix with `rtk rewrite` which correctly handles env var prefixes (FOO=bar cmd), pipes, and unsupported commands. * 📝 docs: mention built-in fd and rg in system prompt Guide the LLM to prefer fd/rg over find/grep since they are bundled as embedded tools. * 🐛 fix: clean up embedded rtk integration - Remove unused env parameter from wrapWithRTK - Add 200MB size cap to extractGzip to guard against decompression bombs - Add unit tests for wrapWithRTK and envWithToolsBin
Summary
internal/embeddedpackage, extracted toANNA_HOME/bin/on first usertkfor 60-90% token reduction on command outputANNA_HOME/binprepended to PATH so embedded tools are available to the LLMmise install-into— no manual platform mapping neededHow it works
mise run tools:download→ downloads fd, rg, rtk for current platform via miseinternal/embedded/binaries/and embedded via//go:embedANNA_HOME/bin/rtk <command>Test plan
go build ./...compiles cleangolangci-lint run— 0 issuesgo test -v -race ./internal/embedded/— extraction + idempotency tests passrtkwrapping reduces token output for common commands (git status, ls, etc.)mise run tools:downloadbefore build