Repository navigation
feat(complete): add --install flag to source completions from a file - #751
Conversation
The script tab prints is static; commands resolve at TAB time through `cf complete -- <words…>`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`cf complete <shell> --install` writes the init script to ~/.config/cloudflare/completions/cf.<ext> so the shell rc can source it instead of spawning cf on every startup. TAB callbacks rewrite installed scripts whose content differs from the running cf's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
commit: |
--install flag to source completions from a file
|
LGTM |
|
| mean | stddev | min | max | |
|---|---|---|---|---|
| PR | 279.5 ms | 4.2 ms | 274.1 ms | 288.8 ms |
| base | 277.4 ms | 3.5 ms | 273.4 ms | 284.5 ms |
Δ (PR vs base): ↑ +2.1 ms (+0.8%)
Measured with hyperfine on ubuntu-latest (3 warmup runs, 20 timed runs). CI numbers carry ±a few ms of runner jitter; treat small deltas as noise.
The usage hint, splash, and first-run tip suggested commands that only print the script. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
LGTM |
|
LGTM |
There was a problem hiding this comment.
Superseded by the review of
c48bce88.
This review, of d35883cb
💬 Approved with comments — No blocking or warning-level issues; two INFO notes on Windows rc-line paths for bash/zsh and a possible leftover temp file when a write fails.
Findings: 2 info (2 are inline comments on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: 💬 2 info
Sound and well-tested change; two minor INFO notes in install.ts.
Recommendation: 💬 Optional Nits
- [INFO] getSourceLine prints a native Windows backslash path inside a POSIX
source '…'line for bash/zsh (packages/cli/src/commands/completions/install.ts:60) - [INFO] writeScript can leave a stray
.tmpfile behind when the write or rename fails (packages/cli/src/commands/completions/install.ts:69)
View full review
- Windows paths in the bash/zsh rc line (
packages/cli/src/commands/completions/install.ts:60): on Windows,getScriptPathreturns a backslash path. It is printed as is inside a POSIXsource '…'line, which may not resolve in every bash/zsh environment on Windows. The tests only cover POSIX-style paths for these shells. - Leftover temp file (
packages/cli/src/commands/completions/install.ts:69-70): ifrenameSync(or a partialwriteFileSync) fails,cf.<ext>.<pid>.tmpstays behind. On the TAB path the error is swallowed, and the PID is new on every press, so repeated failures can pile up orphan files.
✅ All other checks passed
🚀 Release: ✅ LGTM
Two changesets cover the new --install flag (minor) and the startup change (patch), which matches the repository's changeset rules. The new installer writes to the user's config directory, but the write is reversible: deleting the file uninstalls it, and TAB refresh never recreates a missing file.
🔒 Security: ✅ LGTM
The installed script content comes from tab's static output, the rc line is quoted for each shell, and writes go only to the user's own config directory. shell is limited to the SHELLS choices.
📖 AGENTS.md: ✅ LGTM
No issues found.
⚡ Performance: ✅ LGTM
No issues found.
📝 Documentation: ✅ LGTM
No issues found.
Reviewed commit: d35883cb
Each TAB callback runs under a new pid, so a target that keeps failing would otherwise collect a temp file per press. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bash and zsh on Windows run under MSYS2 or Cygwin, which accept C:/ paths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-6d4c50' into NuroDev/shell-completion-caching-6d4c50
|
LGTM! |
There was a problem hiding this comment.
Superseded by the review of
8c6daaac.
This review, of c48bce88
✅ Approved — Both earlier INFO notes (Windows path in the bash/zsh rc line, leftover temp file) are fixed and tested; no new issues.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🚀 Release: ✅ LGTM
Two changesets cover the change: a minor bump for the new --install flag and a patch bump for the startup improvement. The install is opt-in and reversible: deleting the file uninstalls it, and the TAB refresh never recreates a missing file.
🔒 Security: ✅ LGTM
The script content comes from tab's static output. shell is limited to the SHELLS choices, writes go only to the user's own config directory, and the rc line is quoted for each shell.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
- Windows rc line: for bash/zsh,
getSourceLinenow replacessepwith/(install.ts:68). This does nothing on POSIX, and a win32-only test covers it. - Temp file cleanup:
writeScriptcallsrmSync(tempPath, { force: true })before rethrowing (install.ts:80-84). A test forces the rename to fail and checks that no temp file is left.
⚡ Performance: ✅ LGTM
On TAB, the refresh only reads small files and rewrites a script when its content differs. Printing the init script no longer loads the command catalogue.
📝 Documentation: ✅ LGTM
No issues found.
Reviewed commit: c48bce88
jamesopstad
left a comment
There was a problem hiding this comment.
Note that these comments are mostly from an AI review.
…ions bash, zsh, and PowerShell rc lines now check the script exists, so a removed script does not print an error in every new shell. fish autoloads completions on first use, so its hint links the script into $__fish_config_dir/completions instead of sourcing it from config.fish. The bash and fish examples use --install too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
renderScript now throws when tab prints nothing, so a future tab that stops printing through a single console.log cannot blank every installed script. Tests check each shell's script registers its completions, independent of how the output is captured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
LGTM! |
There was a problem hiding this comment.
Superseded by the review of
4bd4f2e9.
This review, of 8c6daaac
💬 Approved with comments — The fixes from the discussion are in place and tested. The one remaining note is INFO only: the documented install path is Linux-specific.
Findings: 1 info (1 is an inline comment on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📝 Documentation: 💬 1 info
The documented install path applies to Linux only
Recommendation: 💬 Optional Nits
- [INFO] architecture.md hard-codes the Linux config path for installed completion scripts; macOS uses ~/Library/Preferences/cloudflare. (
docs/architecture.md:199)
View full review
docs/architecture.md:199 gives the install path as ~/.config/cloudflare/completions/cf.<ext>. The code builds the path from getCfConfigPath(), which is ~/Library/Preferences/cloudflare on macOS. The changeset's example is framed as "the printed line, e.g.", so it is less of a problem there.
✅ All other checks passed
🚀 Release: ✅ LGTM
Two changesets cover the change: a minor bump for the new --install flag and a patch bump for the faster init-script output. The install is opt-in and reversible: deleting the file uninstalls it, and the TAB refresh never recreates a missing file.
🔒 Security: ✅ LGTM
No issues found. The script content is tab's static output, shell is limited to the SHELLS choices, files are written only to the user's own config directory, and the printed commands are quoted for each shell.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
The changes since the last review are correct:
- rc lines now check that the file exists.
- The fish hint now creates a symlink.
renderScriptthrows on an empty render (install.ts:53-56).getScriptPathnow runs inside the refreshtry(install.ts:129).- Telemetry now records
--installthroughsafeFlags.
The Windows forward-slash fix and the temp-file cleanup still hold.
⚡ Performance: ✅ LGTM
No issues found.
Reviewed commit: 8c6daaac
cf's config directory is ~/Library/Preferences/cloudflare on macOS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
LGTM |
There was a problem hiding this comment.
✅ Approved — The last note, the Linux-only install path in architecture.md, is fixed. There are no open findings, and the code still holds.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🚀 Release: ✅ LGTM
There is a minor changeset for the new --install flag and a patch changeset for the faster init-script output. The install is opt-in and reversible.
🔒 Security: ✅ LGTM
No issues found. The script content is tab's static output, shell is limited to the SHELLS choices, files are written only to the user's own config directory, and the printed commands are quoted for each shell.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
Still correct:
renderScriptrestoresconsole.logand throws on an empty render.writeScriptwrites a temp file and renames it into place, and removes the temp file on failure.refreshInstalledScriptsnever creates a missing file and swallows its own errors.- The tests cover rc-line quoting for each shell, including the Windows forward-slash case.
⚡ Performance: ✅ LGTM
The TAB-time refresh only does a few small reads and renders only for shells whose script exists. It writes only when the content differs. Skipping the catalogue load for init scripts cuts startup work.
📝 Documentation: ✅ LGTM
docs/architecture.md now describes the install location as completions/cf.<ext> under cf's config directory (getCfConfigPath()). The changeset example names the macOS path.
Reviewed commit: 4bd4f2e9
Summary
Putting
eval "$(cf complete zsh)"in a shell rc cost ~250ms per new shell. This removes that cost in two ways:perf(complete):cf complete <shell>no longer loads the command catalogue before printing the init script. tab's init scripts are static (commands are resolved at TAB time throughcf complete -- <words…>), so the load was wasted work. ~380ms → ~110ms on a local build.feat(complete): newcf complete <shell> --installwrites the script tocompletions/cf.<ext>(bash, zsh, fish, ps1) under cf's config directory:~/.config/cloudflareon Linux,~/Library/Preferences/cloudflareon macOS. The path goes to stdout, and how to load it goes to stderr: an rc line that skips a missing file for bash, zsh and PowerShell, or a symlink into fish's autoloaded completions directory. Shell startup then never spawns cf.Design notes
renderScriptbriefly swapsconsole.logaround the synchronoust.setup()call. It throws on an empty render, so a tab change there can't make the refresh blank installed scripts.'\'', fish\'/\\, PowerShell''). On Windows, bash/zsh lines use forward slashes.node:fsplus modules it already loaded. The install branch importsoutput.jsandlog.jsdynamically.Testing
pnpm checkpasses.completions-install.test.tscovers rendering parity witht.setup, install path, refresh of stale vs. missing files, rc-line quoting, andcf completewith and without--install, plus TAB-time refresh._cfregistered,complete -p cf, fishcomplete -c cf). PowerShell was not run.telemetry/dispatcher.test.tsthat come from the agent env vars set in the local shell (AI_AGENT,CLAUDECODE). They pass with those unset and are unrelated to this change.🤖 Generated with Claude Code