Skip to content

fix(hooks): ask for zsh's $=name and $~name expansions - #152

Merged
furedea merged 3 commits into
mainfrom
fix/ask-for-zsh-expansion-flags
Nov 11, 2026
Merged

furedea merged 3 commits into
mainfrom
fix/ask-for-zsh-expansion-flags

Conversation

@furedea-agent

@furedea-agent furedea-agent Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

概要

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)も固定
  • ADR-0015:クォートなしの実行時の変数はどのシェルでも ask のままで,zsh の 1 語としての読み方は fix(hooks): judge unquoted variables as zsh runs them #148 / fix(hooks): judge unquoted variables as zsh runs them #149 で試して取りやめた旨を既知の制約として追記

確認

  • 追加テストは先に失敗(2 件)してから通ることを確認
  • 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

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]>
@furedea

furedea commented Nov 11, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-11T09:03:53.218568Z
We couldn’t complete this review. Comment @codex review to try again.
6a64c3c Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Comment thread agents/hooks/lib/shell_words.py Outdated
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):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

指摘のとおりです.二重引用符の中のリテラルも検査するようにし,"$=J" / "$~J" / "a$^J" のテストを足しました.

@github-actions

Copy link
Copy Markdown

Review summary (read-only)

  • P2 (inline, shell_words.py:129): the new $= / $~ check only scans unquoted Lit parts, so "$=J" is still decoded as the literal $=J and allowed. The zsh manual says = splits even inside double quotes. Not confirmed against a real zsh, since none was available here.

The fix works for the unquoted forms in #151, including $ after an even run of backslashes. The tests cover the changed behavior and the existing allow cases. No blocking findings.

`$=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]>
@furedea

furedea commented Nov 11, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Comment thread agents/hooks/lib/shell_words.py Outdated
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"(?<!\\)(?:\\\\)*\$[=~]")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

指摘のとおりです.zsh が $ の直後に受け付けるフラグは =,~,^ に限られるため,3 つとも検査対象にし,$^J のテストを足しました.

@github-actions

Copy link
Copy Markdown

Review summary (read-only):

  • P2: zsh's unbraced $^name (RC_EXPAND_PARAM) seems to slip through the same way $= and $~ did. ^ isn't caught by ZSH_EXPANSION_FLAG, GLOB, or BRACES. Details are in the inline comment.

Everything else checks out. The escaped-backslash handling ((?<!\\\\)(?:\\\\\\\\)*) is correct. Joining Lit parts across quoted segments can only cause extra asks, which is the safe direction, never missed ones. The tests cover the allow and ask cases on both the guard path and the parser path. The ADR change is documentation plus list re-indentation. No blocking issues.

`=`, `~` 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]>
@furedea

furedea commented Nov 11, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions

Copy link
Copy Markdown

レビュー結果

ブロッキングとなる指摘はありません(P0: 0,P1: 0,P2: 0,P3: 0).

  • ZSH_EXPANSION_FLAG の後読みと偶数個のバックスラッシュの扱いを確認しました.\\$=J は一致し,\$=J と \\\$=J は一致しません.
  • _expandable_text は Lit と DblQuoted の Lit だけを連結します.単一引用符の部分や展開を飛ばしても,奇数個のバックスラッシュが部分の境目をまたいで $ をエスケープしたように見える形は作れないため,連結による誤判定は見つかりませんでした.$"…" と $'…' は従来どおり dollar-quote として拒否されます.
  • literal_word 側でも動的と判定するため,リダイレクト先など spreads を通らない語でも $~name が静的なパスとして扱われることはありません.
  • テストは ask と allow の両方向と dynamic フラグを押さえており,変更された挙動に対して十分です.

なお,この環境ではテストを実行できなかったため,静的なレビューのみです.

@furedea
furedea merged commit 9255c87 into main Nov 11, 2026
22 of 24 checks passed
@furedea
furedea deleted the fix/ask-for-zsh-expansion-flags branch November 11, 2026 09:12
furedea pushed a commit that referenced this pull request Nov 11, 2026
🤖 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(hooks): ask for zsh $= and $~ expansions

1 participant