fix(hooks): detach fish hook from the tty - #297
Merged
Conversation
The fish hook ran `shelltime gc` and both `shelltime track` calls with the terminal still attached as stdin, and redirected stdout only. fish 4.1+ probes the terminal with OSC 11 / CPR / DA1 (the `query-term` feature) at startup and on prompt redraw; the terminal answers by writing into the tty input queue. A hook child holding that queue can leave those replies unconsumed, after which they are read as keystrokes and appear as literal escape text at the prompt. Redirect stdin from /dev/null so the hook can never sit on terminal input, and fold stderr into /dev/null to match the bash and zsh hooks, which already use `&> /dev/null`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Codecov Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Escape text like
^[]11;rgb:1010/1010/1010^[\^[[32;1R^[[?62;22;52cintermittentlyappears on the fish command line after Ctrl-C'ing a long-running foreground job.
Those bytes are not corruption — they are the terminal's replies to queries fish
sends. fish 4.1+ probes the terminal (the
query-termfeature, on by default) with:ESC]11;?ESC\ESC]11;rgb:1010/1010/1010ESC\ESC[6nESC[32;1RESC[0cESC[?62;22;52cfish emits these at startup and on prompt redraw. The terminal answers by writing into
the tty input queue. A hook child that holds that queue can leave the replies
unconsumed, after which they are read back as ordinary keystrokes and rendered as
literal text at the prompt.
Change
model/hooks/fish.fishwas the least protected of the three hooks:shelltime trackcalls used> /dev/null— stdout only, whilehooks/bash.bashandhooks/zsh.zshboth use&> /dev/nullshelltime gcruns during config load, i.e. inside fish's startup query windowAll three now use
< /dev/nullso the hook can never sit on terminal input, and thetwo
trackcalls fold stderr away for parity with bash/zsh.Kept in the foreground deliberately: backgrounding with
&makes fish emit job-statusnotifications, which is noisier than the problem being fixed.
Notes
ensureHookFile()(model/shell.go:24) returns early when the hook file alreadyexists, so existing installs keep their old
~/.shelltime/hooks/fish.fishuntil it isupdated by hand or removed and reinstalled.
the interrupted process tree) is still outstanding, and fish's own documented escape
hatch remains
set -Ua fish_features no-query-term.Testing
go build ./...,go test ./model/...passfish --no-execute model/hooks/fish.fishpassesgo test ./commands/...has 10 failures, all pre-existing atmain(daemonunix-socket tests plus one requiring the
openbinary) — verified by re-running at HEAD🤖 Generated with Claude Code