Skip to content

fix(hooks): find GNU grep on PATH instead of the first grep - #193

Merged
furedea merged 1 commit into
mainfrom
fix/hooks-use-gnu-grep
Oct 17, 2026
Merged

furedea merged 1 commit into
mainfrom
fix/hooks-use-gnu-grep

Conversation

@furedea-agent

@furedea-agent furedea-agent Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Sessions started by Herdr put /usr/bin ahead of the Nix profile on PATH. BSD grep ignores --null-data record boundaries and matches each line of a quoted argument on its own. In the #186 lane session, three multi-line policy tests failed for this reason. They pass in other sessions.

  • command_policy.gnu_grep() walks PATH and returns the first grep whose --version reports GNU grep. The result is cached per hook process.
  • Without GNU grep the policy fails closed with an explicit reason. It does not judge commands line by line.
  • Test helpers. The process-count contracts count grep by basename and ignore the one-time version probe.

Closes #192

Verification

  • uv run --frozen pytest tests: 1516 passed. The Hermes gateway errors are gone too, now that Nix runs inside the sandbox.
  • New contracts cover two cases:
    • a fake BSD grep earlier on PATH still yields multi-line matching;
    • a PATH with only BSD grep raises.
  • ruff and ty passed.

🤖 Generated with Claude Code

Sessions started by Herdr put macOS grep ahead of the Nix profile, and
BSD grep matches each line of a quoted argument on its own, so anchored
rules judged multi-line commands differently there. The policy now uses
the first GNU grep on PATH and fails closed when there is none.

Closes #192

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@furedea
furedea merged commit a84cb2e into main Oct 17, 2026
11 checks passed
@furedea
furedea deleted the fix/hooks-use-gnu-grep branch October 17, 2026 11:35
furedea added a commit that referenced this pull request Oct 17, 2026
Hotfix for #193. Sessions started by Herdr have no GNU grep on PATH at
all, not merely later on PATH. Failing closed there refused every Bash
command, so lane sessions could not run even `git status`.

- `gnu_grep()` still prefers the first GNU grep on PATH.
- With no GNU grep, it falls back to the first `grep`, which is the
behavior before #193.

Giving every session GNU grep explicitly is the real fix. It will follow
separately.

Refs #192

## Verification

- `uv run --frozen pytest tests/agents`: 1410 passed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: furedea <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
furedea added a commit that referenced this pull request Oct 17, 2026
The real fix for #192, replacing the GNU grep lookup from #193 and #195.

- **Before matching, line breaks become spaces.** Every grep then sees
one line. Anchors span the whole command, and a newline inside a quoted
argument can no longer hide a later line from an anchored rule. For
example, `gh api 'repos/x↵' --method DELETE` used to pass as a read
under macOS grep.
- **Plain `grep` without `--null-data`.** GNU and BSD grep behave the
same here, so the GNU grep lookup is removed.

Closes #192

## Verification

- `uv run --frozen pytest tests`: 1516 passed.
- `PATH=/usr/bin:$PATH uv run --frozen pytest tests/agents/hooks` (macOS
grep first): 963 passed.
- The new contract runs under both greps. It checks that `^…$` matches
the whole multi-line command and never a single line of it.
- ruff and ty passed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: furedea <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
furedea added a commit that referenced this pull request Nov 16, 2026
agent-config の PostToolUse フックが ADR 編集後に実行する `adr-check` を PATH
に置く.`jev-lint` と同じ方法で `home.packages` に追加し,`agent-config` 入力を #225
を含むリビジョンに更新する.

Refs furedea/agent-config#169

## 変更内容

- `nix/home/default.nix`: `adrCheckPackage =
agent-config.packages.${system}.adr-check;` を `jevLintPackage`
の隣に追加し,`home.packages` に加えた(furedea/agent-config#225).
- `flake.lock`: `agent-config` を `2ab23eb` → `138c542` に更新した(`nix flake
update agent-config`).

## agent-config の更新内容(2ab23eb → 138c542,23 コミット)

- lint: go-style / rust-style / python-style / TypeScript / bash-style /
github-actions-style / agents/AGENTS.md のルールを ast-grep・jev-lint・model
rules へ移行(#190, #191, #192, #193, #194, #195),Go の `util`・`common`
パッケージ検出(#202),ブロッキング ast-grep ルールの欠落修正(#216)
- hooks: 静的ルールエラーでの編集ブロックと ast-grep-ignore の保護(#203),ask
プレフィックスの限定(#199),リポジトリフック回避オプションの拒否(#212),コードセルの判定修正(#224)
- skills: issue / git / setup ワークフローを `development-cycle`
に統合(#211),agent 実行の verify ステップ削除(#213),範囲外指摘への回答と all-green 待機(#223)
- docs/ADR: MADR の採用(#215),スキル責務の配置(#208),コマンド判定の方針(#198),ast-grep
のブロック方針(#214),AGENTS.md の整理(#205)
- build/ci: マイナーバージョン上げの設定(#217),jev-lint モデルルールテストを CI で実行(#218)
- feat: `adr-check` コマンドの追加(#225)

## 検証

- `nix build '.#homeConfigurations."kaito@mbp".activationPackage'`:
成功.生成物の `home-path/bin` に `adr-check` が含まれることを確認した.
- `darwin-rebuild switch` は実行していない.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: furedea <[email protected]>
Co-authored-by: Claude Sonnet 5.5 <[email protected]>
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.

子セッションで BSD grep が使われ,フックの判定がずれる

1 participant