Repository navigation
fix(hooks): ask for zsh's $=name and $~name expansions - #152
Conversation
shfmt reads `$=name` and `$~name` as a dollar sign and literal text, so the guard took them for static words, though zsh splits or globs the value at run time. They now ask in every shell. ADR-0015 records that unquoted run-time variables ask everywhere and why a zsh one-word reading was dropped. Closes #151 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
@codex review |
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
| unquoted = "".join(part.get("Value", "") for part in parts if part.get("Type") == "Lit") | ||
| if any(part.get("Type") in SPLIT_PARTS for part in parts) or GLOB.search(unquoted) or BRACES & set(unquoted): | ||
| return True | ||
| if ZSH_EXPANSION_FLAG.search(unquoted): |
There was a problem hiding this comment.
P2 — This check looks only at top-level Lit parts, so $= inside double quotes isn't covered. Example: gh run view 1 --job "$=J" --log. shfmt reads "$=J" as a DblQuoted containing the literal $=J, so literal_word decodes it as the static string $=J and the guard allows the command. The zsh manual says ${=spec} splits words "regardless of whether the parameter appears in double quotes". If that holds for "$=J" too, the value can still become several words or options, which is the case #151 is about. (Inside quotes, "$~J" doesn't glob, but the guard still treats it as the literal $~J.) I couldn't run zsh here to confirm. Consider also scanning DblQuoted inner Lit values for an unescaped $=, and adding a test case for "$=J".
There was a problem hiding this comment.
指摘のとおりです.二重引用符の中のリテラルも検査するようにし,"$=J" / "$~J" / "a$^J" のテストを足しました.
|
Review summary (read-only)
The fix works for the unquoted forms in #151, including |
`$=J` and `$~J` still decoded to the static text, so a rule or the program position saw a literal. The word is now flagged dynamic as well as spreading. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
| LINE_CONTINUATION = "\\\n" | ||
| # shfmt reads `$=name` and `$~name` as a `$` and literal text, but zsh splits or globs the value; a dollar | ||
| # sign after an even run of backslashes (each pair is one literal backslash) is not escaped. | ||
| ZSH_EXPANSION_FLAG = re.compile(r"(?<!\\)(?:\\\\)*\$[=~]") |
There was a problem hiding this comment.
P2: zsh also has an unbraced $^name (RC_EXPAND_PARAM; e.g. the common $^fpath/*). shfmt likely reads it the same way as $= / $~: a $ followed by literal text. ^ isn't in GLOB or BRACES, so gh run view 1 --job $^J --log would still count as a static word. zsh would expand J at run time, and with an array it would distribute over the surrounding text. This is the same "static form slips through" class as #151. Consider [=~^] here, plus a test row for $^J. I couldn't run the guard in this sandbox to confirm the decision, so please check it with a quick test.
There was a problem hiding this comment.
指摘のとおりです.zsh が $ の直後に受け付けるフラグは =,~,^ に限られるため,3 つとも検査対象にし,$^J のテストを足しました.
|
Review summary (read-only):
Everything else checks out. The escaped-backslash handling ( |
`=`, `~` and `^` are the only characters zsh accepts after a `$` as an expansion flag, in or out of double quotes, so the check names all three and also reads the literal text inside double quotes. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
レビュー結果ブロッキングとなる指摘はありません(P0: 0,P1: 0,P2: 0,P3: 0).
なお,この環境ではテストを実行できなかったため,静的なレビューのみです. |
🤖 I have created a release *beep* *boop* --- ## [0.1.1](v0.1.0...v0.1.1) (2026-11-11) ### Features * **hooks:** judge session changes with jev-lint model rules at Stop ([#150](#150)) ([946e976](946e976)) ### Bug Fixes * **hooks:** ask for zsh's $=name and $~name expansions ([#152](#152)) ([9255c87](9255c87)) * **hooks:** judge a ~user path by the secret-path rules of the own home ([#129](#129)) ([64221f6](64221f6)) * **hooks:** match static words by their single-quoted form in precise command rules ([#147](#147)) ([c432a20](c432a20)) * **hooks:** run verification tools through the flake dev shell ([#132](#132)) ([63dd2f5](63dd2f5)) * **hooks:** start trusted model-rule programs and send only in-repository regular files ([#156](#156)) ([183496b](183496b)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: furedea-release[bot] <353651101+furedea-release[bot]@users.noreply.github.com>
概要
zsh の
$=name(語分割)と$~name(グロブ)は,shfmt が$とリテラルに分けて読むため,ガードで静的な語として通っていた.どちらも実行時に語数や中身が変わるので,どのシェルでも ask にする.Closes #151
変更
agents/hooks/lib/shell_words.py:spreadsが,エスケープされていない$=/$~(偶数個のバックスラッシュの後を含む)を広がる語として扱うtests/hooks/test_zsh_expansion_flags.py:Issue の表の 2 行を ask で固定.エスケープされたバックスラッシュの後の$=,ほかの判定が変わらないこと(単一引用符,エスケープされた$=J,クォート付きの変数は allow)も固定確認
uv run pytest:4646 passed.test_model_rules_process.pyの 2 件(git ls-filesが tmp で失敗)はこの sandbox 内だけの失敗で,この変更とは無関係(CI で確認する)ruff check,ruff format --check,ty check,dprint check通過🤖 Generated with Claude Code