Skip to content

fix(hooks): explain gh asks caused by other commands on the line - #284

Merged
furedea merged 3 commits into
mainfrom
fix/explain-gh-line-asks
Nov 28, 2026
Merged

furedea merged 3 commits into
mainfrom
fix/explain-gh-line-asks

Conversation

@furedea-agent

@furedea-agent furedea-agent Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

概要

gh の読み取りを git fetch や nix eval,cd などと 1 行でつなぐと,ガードが「作業ディレクトリのリモートが github.com とは限らない」という理由で確認を求めていた.実際の原因は同じ行の別のコマンドで,理由が原因と合わなかった.

Closes #282

変更

  • gh_policy.py: ask の理由を原因ごとに分けた.同じ行の別のコマンドが原因なら,そう書き,gh を単独の Bash 呼び出しで実行する直し方を示す.リモートが原因の場合の文は変えていない.
  • 当初 delegation skill に足した「承認の要らない gh の書き方」は取り除いた.ガードの設計の問題を skill に押し付けない.

GH_HOST を固定すれば --repo の読み取りを許可できるか

できない.そのため許可は広げていない.

  • ホストの解決だけなら固定で足りる.go-gh の DefaultHost は GH_HOST を設定ファイルより先に読み,--repo OWNER/REPO は ghrepo.FromFullName から DefaultHost でホストを補う.GH_HOST=github.com なら,設定ファイルの既定ホストを書き換えてもリダイレクトできない.
  • しかし設定ファイルには http_unix_socket があり,go-gh のクライアントは設定からこれを読んで,ホストに関係なく HTTP 通信(トークンを含む)をローカルの unix socket に送る.環境変数による上書きはない.同じ行の nix eval などが hook の確認後にこのキーを書けるので,GH_HOST の固定だけでは通信の宛先を保証できない.
  • 必要な設計変更: gh の設定ディレクトリを,エージェントの Bash が書けない場所に置くこと(別レーンが追加中の GH_CONFIG_DIR を,sandbox の書き込み許可に入れない).ただし hook はユーザーの権限で動くため,書けるかどうかを hook は os.access で確かめられない.許可に使うには,sandbox の設定をガードが読む仕組みが要るので,この PR の範囲外にした(feat(agent-runtime): build persistent, isolated, provider-neutral agent infrastructure #181 の方向).

この判断は _read_host_problem の docstring と,GH_HOST を固定した場合も含むテストに残した.

テスト

  • tests/hooks/test_gh_line_asks.py: 3 つの行形で理由が行を原因として示すこと.--repo が literal でも,GH_HOST 固定の有無にかかわらず ask になり,gh 単独なら許可されること.
  • test_gh_joined_read_only_lines.py: リモートが原因の理由は行を責めないこと,何も書かないコマンドの隣では許可されること.
  • test_gh_effects.py: cd ../other && gh pr list の期待理由を更新.
  • uv run pytest tests/hooks,ruff check と format は通過.

🤖 Generated with Claude Code

furedea and others added 2 commits November 29, 2026 00:08
…d ask

Split the ask reason for a gh read: a line that holds another command able to write
a file or run a program now says so and tells the caller to run gh as its own Bash
call, instead of blaming the working directory's remotes. Keep asking when --repo
is literal, because it names no host and gh reads GH_HOST or its configured default
host, which such a command may rewrite after the hook reads them.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@furedea

furedea commented Nov 28, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 28, 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-28T15:28:52.213525Z
We couldn’t complete this review. Comment @codex review to try again.
86b574f 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.

@github-actions

Copy link
Copy Markdown

Review summary: no findings.

I read the diff and checked _read_host_problem against the previous inline condition. The ask/allow decision is unchanged: changes_directory still asks first, then the remotes check when --repo is absent. Only the reason text is split by cause, so this carries no behavioural or security regression. CommandLine.changes_directory is documented as 'another command on the line may write a file or run a program', which matches the new wording. The new tests cover the three line shapes from #282, the remote-caused reason not blaming the line, and the deliberate --repo + nix eval ask. The test_gh_effects.py expectation was updated to match. The delegation skill guidance is consistent with the hook.

I did not run the test suite myself; I relied on the PR's reported results.

furedea
furedea previously approved these changes Nov 28, 2026
The guard, not the delegation skill, owns the judgement. Pinning GH_HOST settles the
host but not http_unix_socket in gh's configuration, so a literal --repo read still
asks beside a command that may rewrite that configuration.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@furedea

furedea commented Nov 28, 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

Review summary: no blocking findings.

I checked that line.changes_directory means what the new reason says. gh_command_line.py:73 defines it as another command on the line that may write a file or run a program. The check order is the same as before, so the only behaviour change is which ask reason is shown. The new tests cover the three line shapes, the remotes-caused ask, and gh run alone.

Only a P3 remains, and I did not post it inline. When the line and the remotes are both at fault, the ask names only the line. After the caller splits the call, they get a second ask about the remotes. That is acceptable, since the first fix is still correct.

🤖 Generated with Claude Code

@furedea
furedea merged commit 16ecae8 into main Nov 28, 2026
27 of 29 checks passed
@furedea
furedea deleted the fix/explain-gh-line-asks branch November 28, 2026 17:54
furedea pushed a commit that referenced this pull request Dec 1, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.6.0](v0.5.1...v0.6.0)
(2026-12-01)


### ⚠ BREAKING CHANGES

* **settings:** declare the harness protection and the agent GitHub
policy ([#286](#286))

### Features

* **delegation:** offer herdr-core terminals as an alternative lane
transport ([#281](#281))
([e0488ef](e0488ef))
* **settings:** declare the harness protection and the agent GitHub
policy ([#286](#286))
([ac335be](ac335be))


### Bug Fixes

* **hooks:** explain gh asks caused by other commands on the line
([#284](#284))
([16ecae8](16ecae8))

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

gh guard: explain asks caused by other commands on the line, and teach lanes the prompt-free form

1 participant