Skip to content

refactor!: remove the agent GitHub token - #264

Merged
furedea merged 4 commits into
mainfrom
refactor/remove-agent-github-token
Nov 27, 2026
Merged

furedea merged 4 commits into
mainfrom
refactor/remove-agent-github-token

Conversation

@furedea-agent

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

Copy link
Copy Markdown
Contributor

概要

  • Home Manager の programs.agent-harness.github.agentToken オプションと,その Claude,Codex,Antigravity の設定への合成(nix/agent_github_token.nix),GitHub App のトークンを更新する launchd / systemd のジョブ(nix/agent_github_app_token_module.nix)を削除した.
  • agent-harness github-app-token サブコマンド(src/github_app/)と,トークン専用だった FileMode::Private(0600 / 0700)を削除した.
  • 使わなくなった依存 ring,base64,ureq と,それらのためにライセンスの許可リストへ加えていた ISC,BSD-3-Clause,CDLA-Permissive-2.0 を削除した.開発シェルとチェックの入力から openssl も外した.
  • 旧オプションを設定すると,Home Manager の評価が移行の手順を示して失敗する(lib.mkRemovedOptionModule).
  • ソースの設定はそのまま生成されるようになり,ソースの gh * の除外を上書きしていた ADR-0018 の例外がなくなった.
  • ADR-0020〜0023 を ADR-0032 で superseded にし,ADR-0031 と ADR-0028(FileMode::Private と github_app の削除)に amended を追記した.README,DESIGN を更新した.

Refs #262(3 つの PR の 2 つ目.#263 のマージ後に origin/main へリベースした)

破壊的変更と利用側の移行

以下を利用側が先に用意しないと,旧オプションを消した時点でトークンの供給と隔離が黙って止まる.旧版が生成していた内容をそのまま書く(<configDir> は旧既定値 $HOME/.config/agent-harness/gh の絶対パス,<key> は App の秘密鍵の絶対パス).

dotfiles の Home Manager 設定から消すもの

  • programs.agent-harness.github.agentToken.enable,.configDir,.source,.app.id,.app.installationId,.app.privateKeyPath(programs.agent-harness.github の下はすべて)

agent-config(ソースの設定)に足すもの

Claude(claude/settings.json):

  • env.GH_CONFIG_DIR = "<configDir>"(絶対パス)
  • sandbox.enableWeakerNetworkIsolation = true(gh が TLS を検証するため)
  • sandbox.network.allowedDomains に github.com と api.github.com
  • sandbox.excludedCommands から gh * を外す(旧版はソースに書いてあっても生成時に取り除いていた).git push * などほかの除外はソースのとおり
  • permissions.deny に Read(/<key>)(絶対パスなので先頭は //),sandbox.filesystem.denyRead に <key>
  • <configDir> を隠す Read(...),denyRead,読み取り禁止の秘密パスルールを置かない(旧版は評価時に検査していた)

Codex(codex/config.toml):

  • shell_environment_policy.set.GH_CONFIG_DIR = "<configDir>"
  • default_permissions = "guarded"
  • [permissions.guarded.filesystem]:":root" = "read",":tmpdir" = "write",":slash_tmp" = "write","~/.config/gh/hosts.yml" = "deny","<key>" = "deny",Claude の sandbox.filesystem.allowWrite のうち絶対パスと ~/ のパスそれぞれに "write"
  • [permissions.guarded.filesystem.":workspace_roots"]:"." = "write"
  • [permissions.guarded.network]:enabled = true

Antigravity(antigravity/settings.json):

  • permissions.deny に read_file(~/.config/gh/hosts.yml) と read_file(<key>).GH_CONFIG_DIR は旧版も設定しておらず,起動環境から渡す

dotfiles に足すもの(トークンの発行と更新)

  • 旧ジョブ:launchd エージェント agent-harness-github-app-token(RunAtLoad,StartInterval = 300,ログは ~/Library/Logs/agent-harness-github-app-token.log)が agent-harness github-app-token refresh --app-id <id> [--installation-id <id>] --private-key <key> --config-dir <configDir> を実行していた.残り 20 分未満のときだけ 1 時間のインストールトークンを発行していた.

  • 置き換えるスクリプトは <configDir>/hosts.yml を一時ファイルからの rename で 0600 で書く.旧版が書いていた形は次のとおり(ユーザー名は x-access-token).<configDir>/config.yml がなければ version: "1" を書くと,gh の複数アカウントへの移行(GET /user が要る)を飛ばせる.

    github.com:
        users:
            x-access-token:
                oauth_token: <token>
        git_protocol: https
        oauth_token: <token>
        user: x-access-token
  • 旧版の状態ファイル <configDir>/agent_harness_token.json は不要になるので消してよい.

そのほか

  • pre-major の互換性方針(ADR-0009,ADR-0010)に従い,タイトルの ! で破壊的変更として記録する.リリースはしない.

検証

  • ローカル:cargo fmt --check,cargo clippy --all-targets -- -D warnings,cargo test,nix flake check がすべて成功
  • Red:credentials_are_not_a_harness_command と Nix のチェック removed-github-options が削除前の実装で失敗することを確認した
  • tests/agent_github_token.nix と tests/agent_github_app_token.nix は対象の機能ごと削除した
  • CI:push のたびに確認(最新の結果は PR のチェック欄)

レビュー対応

  • DESIGN にトークンだけがソースを上書きするという記述が残っていた(codex-review P2):決定 5 を「ソースの設定を上書きするものはない」に直し,ADR の一覧と使われなくなったリンク定義を整理した.
  • ADR-0028 が削除した FileMode::Private と github_app を記述したままだった(codex-review P2):amended を追記した.

計画からの逸脱

  • Codex の設定同期の formerly_managed: ["GH_CONFIG_DIR"](ADR-0024,sidecar がない古いインストールからの移行用)は汎用の仕組みのデータなので残した.
  • FileMode::Private はトークン専用だったので,あわせて削除した.

🤖 Generated with Claude Code

@furedea

furedea commented Nov 27, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

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

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-27T04:55:15.490396Z 54fa95e 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.

@github-actions

Copy link
Copy Markdown
Contributor

Automated review: no findings.

Checked:

  • Home Manager module: settings are now rendered straight from claudeSourceSettings, codexSourceSettings and antigravitySourceSettings. Nothing in nix/, src/ or tests/ still refers to composedSettings, cfg.github or the deleted agent_github_*.nix files.
  • lib.mkRemovedOptionModule [ "programs" "agent-harness" "github" ] adds an assertion. Home Manager checks assertions when config is read, so the tryEval config.home.username check in tests/removed_github_options.nix does catch a removed option being set. The test without the option makes sure evaluation does not fail for some other reason.
  • Rust: removing github_app and FileMode::Private leaves no references behind. The create_parents, open_file and create_temporary_file signature changes match across io.rs, executor.rs and the in-memory test filesystem. The mode behaviour for Standard and Bits is unchanged.
  • Dependencies: the remaining Cargo.lock packages fit the smaller license allow-list (Apache-2.0, MIT, Unicode-3.0).
  • The breaking change (gh * is no longer removed from excludedCommands, and the token refresh job is gone) is intentional and the PR description covers the migration.

🤖 Generated with Claude Code

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 64f2f00ed3

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docs/DESIGN.md Resolved
@furedea

furedea commented Nov 27, 2026

Copy link
Copy Markdown
Owner

@codex review

1 similar comment
@furedea

furedea commented Nov 27, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown
Contributor

Review summary (read-only)

No blocking or non-blocking findings.

Checked:

  • nix/home_manager_module.nix: settings now render straight from *SourceSettings. Nothing else references composedSettings, agentToken, or agent_github_token.nix. lib.mkRemovedOptionModule on programs.agent-harness.github catches every old sub-option, because defining any of them defines the subtree.
  • tests/removed_github_options.nix: Home Manager runs the assertion checks when config is accessed, so tryEval config.home.username does catch the removed-option assertion. The negative case and the launchd check look right.
  • src/shell/io.rs / executor.rs: removing FileMode::Private doesn't change the behaviour of Standard or Bits. DirBuilderExt is still used for the 0700 staging directory. Nothing else in the tree refers to FileMode::Private or github_app.
  • Dropping ring/base64/ureq and the ISC/BSD-3/CDLA license allowances matches the removed code. openssl was only used by the deleted tests.
  • I kept formerly_managed: ["GH_CONFIG_DIR"] in the Codex sync, as the PR describes. If a user declares GH_CONFIG_DIR in the source settings, the sync manages it, so the migration path still works.

Blocking findings (P0/P1): 0

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: d4f3c1e87c

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Base automatically changed from refactor/limit-to-rendering to main November 27, 2026 04:28
furedea
furedea previously approved these changes Nov 27, 2026
furedea and others added 3 commits November 27, 2026 13:29
Drop the github.agentToken Home Manager option, its Claude, Codex,
and Antigravity compositions, the github-app-token subcommand with
its launchd and systemd jobs, and the ring, base64, and ureq
dependencies. Setting a removed option now fails evaluation with
migration instructions; the source settings carry the wiring and the
token is minted outside the harness (ADR-0032).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@furedea-agent
furedea-agent Bot dismissed furedea’s stale review November 27, 2026 04:31

The merge-base changed after approval.

@furedea-agent
furedea-agent Bot force-pushed the refactor/remove-agent-github-token branch from d4f3c1e to e64ea2c Compare November 27, 2026 04:31
@furedea

furedea commented Nov 27, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown
Contributor

Review summary

No findings. The removal looks clean:

  • No references to composedSettings, github.agentToken, github_app, FileMode::Private, or the dropped crates remain outside the ADRs.
  • The Home Manager module now generates the source settings directly. lib.mkRemovedOptionModule on programs.agent-harness.github covers every old sub-option, including agentToken.source and agentToken.app.*.
  • tests/removed_github_options.nix really tests the rejection. Home Manager runs its module checks before it returns config, so builtins.tryEval config.home.username catches the removed-option assertion.
  • The FileMode / create_parents signature changes are mechanical, and the remaining Standard / Bits paths behave as before.

Blocking findings (P0/P1): 0

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e64ea2c440

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/file_op.rs Resolved
@furedea

furedea commented Nov 27, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown
Contributor

Review summary

No findings (0 P0, 0 P1, 0 P2, 0 P3).

What I checked:

  • No references to the removed code are left anywhere: composedSettings, agentToken, github_app, FileMode::Private, the agent_github_* Nix files, and openssl in the Nix, Rust, TOML and workflow files.
  • The Claude, Codex and Antigravity settings are now generated straight from *SourceSettings. This matches what the old pipeline produced when the token was disabled.
  • lib.mkRemovedOptionModule on programs.agent-harness.github fails evaluation when any old option is set. The removed-github-options check covers both the rejected and the accepted case. Home Manager throws on failed assertions, so builtins.tryEval catches it.
  • In src/shell/io.rs, the DirBuilderExt import is still needed by create_staging_directory, which sets 0700. After the removal of FileMode::Private, the create_parents, open_file and create_temporary_file signatures line up across the trait, RealFileSystem and the memory test double.
  • The tests that were deleted only covered behaviour that was also deleted. The new tests (credentials_are_not_a_harness_command, a_new_file_gets_the_default_mode, and the Nix check) cover what this PR changes.

The breaking-change migration notes in the PR body look complete for anyone using the old options.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 54fa95e159

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@furedea
furedea merged commit ea5741d into main Nov 27, 2026
23 checks passed
@furedea
furedea deleted the refactor/remove-agent-github-token branch November 27, 2026 06:52
furedea added a commit that referenced this pull request Nov 27, 2026
## 概要

- インストールしたファイルの一覧から保護パスを導出する仕組み(`generation/protection`,ADR-0008)を削除した.
- Claude:インストールしたファイルへの `Edit(...)` の拒否と `sandbox.filesystem.denyWrite`
の追加をやめた.`denyWrite` はソースの値をそのまま出す.
- Codex:`[permissions.guarded.filesystem]` へのインストールしたファイルの `"read"`
エントリをやめた.秘密パスポリシーの `"none"` エントリと `glob_scan_max_depth`
は引き続き生成する(`generation/guarded_filesystem` に改名).
- Antigravity(ADR-0031 の保護部分):インストールしたファイルと
`~/.gemini/config`,`~/.gemini/antigravity-cli/settings.json` への
`write_file(...)` の拒否,`read_file(/nix)` と `read_file(/run)` の許可,`/run`
配下の秘密のマウントの `read_file(...)` の拒否,`agentMode = ""` と
`enableTerminalSandbox = true` の固定をやめた.秘密パスとコマンド権限の変換,使えないパスルールの拒否は残した.
    - 実行時のフック向けの `~/.claude/hooks/rules/protected_paths.json` を生成しなくなった.
- 保護パスのためだけにあった `install
--dsh-profile`,`GenerationContext.dsh_profile`,`SyncTarget`,`InstalledLayout::generated_files_for`
などを削除した.Home Manager モジュールは `--dsh-profile` を渡さなくなった(`dsh.profile`
オプションは同期先として残る).
- ADR-0008 を ADR-0032 で superseded,ADR-0031 を partly-superseded にして
amended を追記した.README,DESIGN,構成図を更新した.

Refs #262(3 つの PR の 3 つ目.#263,#264 のマージ後に `origin/main` へ載せ替えた)

## 破壊的変更と利用側の移行


以下を利用側が先に用意しないと,アップグレードした時点で保護が黙って外れる.旧版が生成していた内容と,置き換えの方針(書き込みの許可リスト+ハーネスのルートごとの拒否,Issue
の方針の更新 1)を併記する.

### 最優先:保護パスのポリシーを読むフック

- 旧版は `~/.claude/hooks/rules/protected_paths.json`(`{"version": 1,
"paths": [...]}`)を書き,ソースのフック(agent-config の `hooks/`)が読んでいた.このファイルは次の
install で消える(`~/.claude/hooks/` は丸ごと置き換える管理ディレクトリ).
- ADR-0008
のとおりフックがファイルの欠落で拒否側に倒れる実装なら,アップグレード後にすべての対象呼び出しが止まる.agent-config
のフックからこのファイルを読む処理を先に外す.守りたいパスはフック自身の規則(たとえばハーネスのルート)で持つ.

### agent-config(ソースの設定)に足すもの


旧版が拒否していた範囲は,次のハーネスのルートの中にすべて収まる:`~/.claude`,`~/.codex`,`~/.devin`,`~/.config/devin/config.json`,`~/.hermes`,`~/.pi`,`~/.dsh`,`~/.gemini/config`,`~/.gemini/antigravity-cli/settings.json`.プロジェクト内インストール(`--runtime-root`)では,これらは実行時ルートの下の絶対パスだった.スキル(`skills/`)は旧版も保護していなかった.

Claude(`claude/settings.json`):

- `permissions.deny`:旧版はファイルごとに `Edit(<path>)` を足していた.置き換えはルートごとに 1
つ,たとえば `Edit(~/.claude/**)`,`Edit(~/.codex/**)` など上の各ルート.Claude Code
自身が書く場所(`~/.claude.json` や `~/.claude/` 配下の状態)との兼ね合いは agent-config
で確かめる.
- `sandbox.filesystem.denyWrite`:旧版は同じパスを足していた.Claude の sandbox の書き込みは
`allowWrite` と作業ディレクトリだけの許可リストなので,`allowWrite`
が上のルートを含まない限り追加は不要.含む場合はそのルートを `denyWrite` に書く.

Codex(`codex/config.toml`):

- 旧版は `[permissions.guarded.filesystem]` にインストールしたファイルごとに `"<path>" =
"read"` を足していた(guarded プロファイルを使うときだけ効く).#264 の移行で guarded を `":root" =
"read"`
と作業ディレクトリ・一時領域・キャッシュだけの書き込みにすれば,ルートは書けない.書き込みを許すエントリがルートを覆うときは,`"~/.codex"
= "read"` のようにルートを書く.

Antigravity(`antigravity/settings.json`):

- `"agentMode": ""` と `"enableTerminalSandbox":
true`(旧版はソースの値を上書きして固定していた)
- `permissions.allow`:`read_file(/nix)`,`read_file(/run)`
-
`permissions.deny`:`read_file(/run/credentials)`,`read_file(/run/secrets)`,`read_file(/run/secrets.d)`,`read_file(/run/secrets-for-users)`,`read_file(/run/agenix)`,`read_file(/run/agenix.d)`,`read_file(/run/keys)`,`read_file(/run/user)`,`write_file(~/.gemini/config)`,`write_file(~/.gemini/antigravity-cli/settings.json)`,および上の各ルートの
`write_file(...)`(`agy` はグロブを受け付けないのでディレクトリをそのまま書く.先頭の `~` は同期が展開する)

### 既存インストールで残る値

- Claude の設定でソースが `sandbox` を宣言しないとき,旧版が生成した `sandbox`(`denyWrite`
の保護パスを含む)は同期で残る.Antigravity でソースが `agentMode`/`enableTerminalSandbox`
を宣言しないときも,旧版の `""`/`true` が残る(ADR-0029 の
`WhenAbsent::Keep`).残るのは厳しい側の値で,ソースが宣言すれば次の同期で置き換わる.上の移行でソースに書けば,新規と既存のインストールは一致する.
- 手作業の後始末:ソースに `sandbox` を書かない利用者は,アップグレード後の最初の同期のあとで
`~/.claude/settings.json` の `sandbox.filesystem.denyWrite`
から旧版が足したハーネスのパス(上の各ルートの配下)を消すか,`sandbox` を丸ごと消す.消さないと,README
の「`denyWrite` はソースの値をそのまま出す」に反して,それらのパスへの sandbox
内の書き込みが拒否され続ける.Antigravity の `agentMode`/`enableTerminalSandbox`
も,ソースに書かずに既定へ戻したいときは `~/.gemini/antigravity-cli/settings.json` から消す.

### dotfiles

- Home Manager 経由なら変更不要.`agent-harness install --dsh-profile ...`
を直接呼んでいるスクリプトがあれば,フラグを外す.

### そのほか

- `generate-codex-config-fragment` の出力は秘密パスのエントリと `glob_scan_max_depth`
だけになる.
- pre-major の互換性方針(ADR-0009,ADR-0010)に従い,タイトルの `!`
で破壊的変更として記録する.リリースはしない.

## 検証

- ローカル:`cargo fmt --check`,`cargo clippy --all-targets -- -D
warnings`,`cargo test`,`nix flake check` がすべて成功
-
Red:`path_rules_come_only_from_the_source_secret_policy`,`the_source_mode_and_sandbox_settings_pass_through`,`build_settings_merges_hooks_command_permissions_and_secret_paths`,`write_config_source_adds_no_guarded_entry_for_installed_files`,`every_provider_declares_how_it_enforces_command_rules`
が削除前の実装で失敗することを確認した
- golden は再生成し,差分が保護エントリ,Antigravity の固定値と許可・拒否,`protected_paths.json`
の削除だけであることを確認した
- CI:push のたびに確認(最新の結果は PR のチェック欄)

## レビュー対応

- 旧版が生成した Claude の `sandbox` と Antigravity の
`agentMode`/`enableTerminalSandbox` が既存インストールに残る(codex-review P2
×2):変更せず,上の「既存インストールで残る値」に明記した.所有範囲から外れたキーは,harness
が書いた値かユーザーが書いた値かを区別できず,消すとユーザーの設定を落としうる.残るのは厳しい側の値で,ソースが宣言すれば置き換わる.
- 同じ点の README との食い違い(codex-review
P3):コードは変えず,「既存インストールで残る値」に手作業の後始末を追記した.

## 計画からの逸脱

- Antigravity の `agentMode`/`enableTerminalSandbox` の固定と `/nix`・`/run`
の許可・拒否も,ソースが宣言していない方針なので,ADR-0031 の保護部分として外した.
- `--dsh-profile` は保護パスにしか使われていなかったので削除した.

🤖 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 to furedea/agent-config that referenced this pull request Nov 28, 2026
…policy (#286)

## 概要

agent-harness が描画と配置だけを担うようになり(furedea/agent-harness#262),これまで harness
が合成していた保護とエージェント用 GitHub トークンの配線が消えた.その代わりをこのリポジトリのソース設定とフックで持つ.

- 保護は「書き込みの許可リスト+ハーネスのルートごとの拒否」にした.ルートは
`agents/hooks/rules/harness_roots.json` に 1 か所で宣言し,Claude と Antigravity
のネイティブの拒否,および全 provider 共通の `guard_file.py harness`
がそれに従う.テストが各設定と宣言の一致を確かめる.
- フックは生成ファイル `protected_paths.json` を読まなくなった.`harness_roots.json`
を読み,対象が(`.` と `..` を畳んだうえで)いずれかのルートの中なら拒否する.
- GitHub:`gh` を Claude の sandbox の中で動かし,`github.com` と `api.github.com`
への通信を許す.Codex は guarded プロファイルで動く.`GH_CONFIG_DIR` の値はホストごとの絶対パスで,Claude
の `env` も Codex の `shell_environment_policy.set` も `~`
を展開しないため,ソースには書かずホスト(dotfiles,サーバーでは `bootstrap_server.sh`)が渡す(ユーザーの決定).
- App の鍵は,`~/.ssh` 全体の読み取り拒否として各 provider
のネイティブ設定に明示した.ソースには鍵のファイル名を書かない.
- ADR-0031 を追加し,ADR-0013 を partly-superseded にした.

Closes #285

## 移行項目の対応表

### furedea/agent-harness#265(保護)

- [x] フックの `protected_paths.json` 依存を外す →
`agents/hooks/guard_file.py`,`agents/hooks/rules/harness_roots.json`(Codex,Devin,Hermes,Pi,dsh,Antigravity
のアダプターも同じフックを通る)
- [x] Claude `permissions.deny` にルートごとの `Edit(...)` →
`agents/claude/settings.json`(`~/.claude/**`,`~/.codex/**`,`~/.devin/**`,`~/.config/devin/config.json`,`~/.hermes/**`,`~/.pi/**`,`~/.dsh/**`,`~/.gemini/config/**`,`~/.gemini/antigravity-cli/settings.json`)
- [x] Claude `sandbox.filesystem.denyWrite` → 追加不要.`allowWrite`
はどのルートも含まない(テストで固定)
- [x] Codex:ルートを書けない guarded プロファイル →
`agents/codex/config.toml`(`":root" = "read"`,書き込みは作業ディレクトリ,一時領域,Claude
の `allowWrite` と同じキャッシュだけ.テストで Claude と一致を固定)
- [x] Antigravity `agentMode = ""`,`enableTerminalSandbox = true` →
`agents/antigravity/settings.json`(新規)
- [x] Antigravity `read_file(/nix)`,`read_file(/run)` の許可,`/run`
の秘密のマウント 8 つの `read_file(...)` の拒否 → 同上
- [x] Antigravity の各ルートの `write_file(...)` 拒否 → 同上
- [x] Devin,Hermes,Pi,dsh → ネイティブの規則の面がないので,フック(`harness_roots.json`)で拒否
- [x] dotfiles の `--dsh-profile` → このリポジトリは使っていない(対応なし)

### furedea/agent-harness#264(GitHub トークン)

- [x] Claude `sandbox.enableWeakerNetworkIsolation = true` → 既にソースにある
- [x] Claude `sandbox.network.allowedDomains` に
`github.com`,`api.github.com` → `agents/claude/settings.json`
- [x] Claude `sandbox.excludedCommands` から `gh *` を外す → 同上
- [x] Claude の鍵の拒否(`permissions.deny` と `sandbox.filesystem.denyRead`
の両方)→ `Read(~/.ssh/**)` と `~/.ssh`(鍵のパスを含む `~/.ssh`
全体.`secret_path_policy.json` の `~/.ssh/**`,`**/*.pem` でも生成される)
- [x] `<configDir>` を隠す規則を置かない → テスト
`test_agents_can_read_the_agent_gh_config_the_host_mints`
- [x] Codex `default_permissions =
"guarded"`,`":root"`,`":tmpdir"`,`":slash_tmp"`,`":workspace_roots"."."`,キャッシュの
`"write"`,`[permissions.guarded.network] enabled = true` →
`agents/codex/config.toml`
- [x] Codex の鍵の拒否 → `"~/.ssh" = "deny"`(加えて harness が `"~/.ssh/**" =
"none"` を生成)
- [x] Codex `"~/.config/gh/hosts.yml" = "deny"` →
`secret_path_policy.json` から harness が `"none"` を生成(従来どおり)
- [x] Antigravity `read_file(~/.config/gh/hosts.yml)` →
`secret_path_policy.json` から生成(従来どおり)
- [x] Antigravity の鍵の拒否 → `read_file(~/.ssh)`(ソースに明示,生成とも重複は畳まれる)
- [ ] Claude `env.GH_CONFIG_DIR`,Codex
`shell_environment_policy.set.GH_CONFIG_DIR` → **dotfiles
が渡す**(下記).ソースには書かない
- [ ] トークンの発行と更新 → dotfiles(furedea/dotfiles のトークン lane).サーバーは下記のフォローアップ

### furedea/agent-harness#263(Pi の srt 拡張)

- [x] `manifest.json` の `runtime_commands` に `srt` はない,Pi のためだけの sandbox
エントリもない → 対応なし

## 旧版との意図した違い

- ルート単位の拒否になったため,ファイルツールは `~/.claude/plans`(plan mode の計画ファイル)や
`~/.claude/keybindings.json`
など,ルート配下のすべてを書けない.旧版はインストールしたファイルだけを拒否していた.現在 `~/.claude/plans` は空で,plan
mode は使われていない.
- スキル(`~/.claude/skills` など)も保護される.旧版は保護していなかった.
- Codex は main checkout で `.git/worktrees` 全体を書けない(Codex がグロブのエントリに
`deny` しか受け付けず,`config.worktree` は git が読むため).Claude は `config.worktree`
だけを拒否する.Codex の lane は worktree で動き,共通の `.git` は元々作業領域の外なので影響しない.
- Codex の guarded プロファイルで,フックだけが書く状態と作業領域の `.git/hooks`,`.git/config`
を書けなくなった(旧版は書けた).
- 鍵の拒否は鍵のファイル単体ではなく `~/.ssh` 全体(従来から秘密パスのポリシーで拒否していた範囲と同じ).
- App の鍵がないホストでも,GitHub への通信が sandbox で開き,`gh` は sandbox の中で未認証で動く.旧版は
`gh` を sandbox の外でユーザー自身のログインで動かしていた.

## dotfiles が用意するもの

- `GH_CONFIG_DIR = <home>/.config/agent-harness/gh`(旧既定値と同じ絶対パス)を,Home
Manager の `programs.agent-harness.claude.settings.env` と
`programs.agent-harness.codex.settings.shell_environment_policy.set`
に足す(`NVIM_LOG_FILE` と同じ形).
- トークンを `<home>/.config/agent-harness/gh/hosts.yml`(0600,一時ファイルからの
rename)に書くスクリプトと,その定期実行.
- 鍵は `~/.ssh/` の下に置いたままにする(ここに置く限り,上の拒否が効く).

## マージ後にユーザーが確かめること

- dotfiles を新しい agent-harness に上げて切り替えたあと,Codex
のセッションで作業領域への書き込みができ,`.git/hooks` と `~/.claude` への書き込みが拒否されること.このレーンの
sandbox の中では `codex sandbox` が入れ子の seatbelt を作れず,設定の読み込みまでしか確かめられなかった.
- Claude のセッションで `gh auth status` がエージェントの身元を示すこと(トークンは表示しない).

## 必要な agent-harness のリビジョン

- この PR のソースは,ロック中の 0.9.15(c5b1303)と,#263〜#265 を含む main の 2008c43 の両方で
`install` と `verify` が成功し,描画結果に保護,GitHub の配線,鍵の拒否が入ることを確かめた.
- dotfiles は 2008c43 以降へ上げてよい(この PR のマージ後).

## フォローアップ

- agent-config:`scripts/bootstrap_server.sh` は `agent-harness
github-app-token refresh` でトークンを発行している.固定中のリリースでは動くが,#264
を含むリリースへ上げるとこのサブコマンドがなくなるので,その前に dotfiles と同じ形の発行スクリプトへ置き換える.
- agent-config:`docs/DESIGN.md` の「`denyWrite`
はまだ効いていない(agent-harness#213)」は,両方のリビジョンの描画で `denyWrite`
がソースのまま出ていたので,記述の見直しが要る.

## レビュー対応

- 相対パスとシンボリックリンクでルートの判定をすり抜ける(claude-review P2):payload の `cwd`
から解決し,字句上のパスと解決後のパスの両方で判定するよう修正した(dabd8070).
- GitHub への通信路(claude-review P3):旧版と同じ構成なのでコードは変えず,ADR-0031
に追記した(caf37603).
- Codex の guarded プロファイルが Claude の
`denyWrite`(フックだけが書く状態,`.git/hooks`,`.git/config`,`config.worktree`)を写していない(claude-review
P1):`"read"` で写し,テストで Claude
と一致を固定した(45257d64).旧版が合成していたプロファイルにも同じ欠落があった.
- codex-review は「レビューを完了できなかった」で失敗した(使用量制限など).

## 検証

- Red:`tests/hooks/test_guard_file.py` の新しい契約(28 件)と
`tests/test_harness_protection.py`(宣言ファイルがない,鍵の拒否がない)が実装前に失敗することを確認した
- `uv run pytest`:6662 passed,2 skipped
- `bats tests/bootstrap_server.bats`:81 件成功
- `ruff check`,`ruff format --check`,変更ファイルの `dprint check`,`nix run
.#adr-check -- docs/adr`:成功
- 新旧 2 つの agent-harness で一時ディレクトリへ `install` と `verify`,配置した
`guard_file.py harness` がルート配下を拒否し,作業ディレクトリのファイルを許すことを確認した

🤖 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 pushed a commit that referenced this pull request Dec 1, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.10.0](agent-harness-v0.9.16...agent-harness-v0.10.0)
(2026-11-29)


### ⚠ BREAKING CHANGES

* remove the generated protection of installed files
([#265](#265))
* remove the agent GitHub token
([#264](#264))
* **pi:** remove the srt sandbox extension
([#263](#263))

### Features

* render MCP servers declared once in the source
([#268](#268))
([2eb9fe7](2eb9fe7))


### Code Refactoring

* **pi:** remove the srt sandbox extension
([#263](#263))
([d1f8a11](d1f8a11))
* remove the agent GitHub token
([#264](#264))
([ea5741d](ea5741d))
* remove the generated protection of installed files
([#265](#265))
([2008c43](2008c43))

---
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>
furedea added a commit to furedea/dotfiles that referenced this pull request Dec 1, 2026
## 概要

furedea/agent-harness#264 でエージェント用 GitHub トークンの発行機能が agent-harness
から削除されたため,発行を dotfiles に移した.

- `scripts/github-app-token/mint_github_app_token.sh`(新規):
`openssl`,`curl`,`jq` でトークンを発行する.`jq` は既存の依存.
  - App の鍵で RS256 の JWT に署名する.
- `GET /app/installations` で App のインストールが 1 つだけであることを確かめ,`POST
/app/installations/{id}/access_tokens` でトークンを発行する.
- `<設定ディレクトリ>/hosts.yml` を一時ファイルからの rename で mode 0600 で書く.設定ディレクトリは
0700.`config.yml` がなければ `version: "1"` を書く.
  - 失敗したときは今の `hosts.yml` をそのまま残す.
  - JWT とトークンは標準入力で curl に渡すので,argv にも出力にも出ない.
- **2 回前のトークンの失効**: 置き換える `hosts.yml` を同じディレクトリの
`hosts.previous.yml`(mode 0600,一時ファイルからの rename)に残す.新しい `hosts.yml`
に置き換えた後,`hosts.previous.yml` にあったトークン(2 回前の実行で発行したもの)を,そのトークン自身で `DELETE
/installation/token` して失効させる.
- 有効なトークンは最大 2 つになる.実行の直前に始まった `gh run watch` のような長い `gh`
も,その次の実行まで(少なくとも 15 分)動き続ける.
  - 漏れたトークンは最大 30 分で失効する(もともと 1 時間で期限切れ).
  - 1 回目と 2 回目の実行は何も失効させない.
  - 発行に失敗したときは `hosts.yml` も `hosts.previous.yml` も変えず,何も失効させない.
  - 401 は期限切れなので何も出さない.
  - ほかの失敗はトークンを含めずにログへ出し,実行は成功として終える.
- **権限の絞り込み**: 権限の指定を必須にし,指定がなければ usage で失敗する.App の全権限を持つトークンは発行されない.
- `nix/home/default.nix`:
  - `programs.agent-harness.github.agentToken` を削除した.
- launchd エージェント `agent-github-token` を両ホストに追加した(`RunAtLoad`,15
分ごとに実行,ログは `~/Library/Logs/agent-github-token.log`).
  - App ID,鍵のパス,設定ディレクトリ `~/.config/agent-harness/gh` は旧版と同じ.
- Claude の `env` と Codex の `shell_environment_policy.set` に
`GH_CONFIG_DIR` を設定した.source の設定は `~` を展開しないので,dotfiles が絶対パスで渡す.
- `flake.lock`: agent-harness を 249aeac(0.10.0,furedea/agent-harness#268
を含む)に,agent-config を 4ea2075(0.6.0,furedea/agent-config#286
を含む)に一緒に更新した.
- furedea/agent-harness#268 は,ソースの `mcp_servers.json` と Home Manager の
`mcpServers` に宣言した MCP サーバーを,各プロバイダーの設定に生成する.
- dotfiles と agent-config は MCP
サーバーを宣言していないので,生成されるのはサーバーを含まない空のファイルだけ.`darwin-rebuild` 後に Mac に現れるのは次の
2 つ.
- `~/.gemini/config/mcp_config.json`: 新しい activation
`agentHarnessAntigravityMcpServers` が,なければ作る.
- `~/.gemini/config/.agent-harness-managed.json`:
そのサイドカー(`{"mcpServers": []}`).
- 既存の `~/.codex/.agent-harness-managed.json` に空の `mcp_servers`
が加わる.Codex の `config.toml` に `[mcp_servers]` は増えず,Claude の skills
ツリーのファイル構成も変わらない.Devin は有効にしていないので `~/.config/devin` には何も書かれない.
  - agent-config 側の差分は 0.6.0 のリリースと依存の更新(hypothesis,ruff).
- `nix/checks.nix`:
- 新しい agent-harness は `composedSettings` を公開しないので,モジュールと同じ評価(source の設定に
Home Manager の `settings` を `recursiveUpdate` で重ねる)で生成後の設定を組み立てるようにした.
  - 契約を追加した.
    - 旧 `github` オプションが削除済みであること
    - 両ホストのジョブの引数(App ID,鍵,設定ディレクトリ,権限)
    - 実行間隔が 1 時間の有効期限の 1/3 未満であること
    - Claude と Codex の `GH_CONFIG_DIR`
    - 組み込んだスクリプトが実行できること(darwinOnly)
  - Claude,Codex,Antigravity のそれぞれで鍵が読み取り拒否されていることを確かめる契約を追加した.
    - **Claude**: `Read(...)` と `denyRead` の両方
    - **Codex**: `default_permissions` のプロファイルの filesystem に `"deny"`
    - **Antigravity**: `read_file(...)`
    - 鍵そのものに加え,`~/.ssh` などの親ディレクトリの拒否も鍵を含むものとして扱う.
    - 設定を生成するプロバイダーが増えたら失敗する契約もある.
- ADR-0055 を追加し,README を更新した.

Closes #531

## 権限の選び方

`GET /apps/furedea-agent` で調べた App の権限は
`actions:read`,`contents:write`,`issues:write`,`metadata:read`,`pull_requests:write`
だった.エージェントはどれも使うので,5 つすべてを明示して要求する.

| 権限 | 使い道 |
| --- | --- |
| `actions:read` | CI の確認 |
| `contents:write` | push |
| `issues:write` | Issue |
| `pull_requests:write` | PR |
| `metadata:read` | 常に必要 |

絞り込みの効果は,後から App に権限を足しても,dotfiles
に書き足すまでエージェントには渡らないこと.リポジトリは絞らなかった.インストールが所有者の全リポジトリを対象にしていて,エージェントは複数のリポジトリにまたがって作業するため.

## マージ後の手順(各 Mac で)

トークンは表示しない.

1. `sudo darwin-rebuild switch --flake
~/ghq/github.com/furedea/dotfiles#<host>` で反映する.
2. launchd エージェントが動いたことを確かめる.
- `launchctl print gui/$(id
-u)/org.nix-community.home.agent-github-token | grep -E 'state|last exit
code'` で `last exit code = 0` になっている.
   - `~/Library/Logs/agent-github-token.log` にエラーがない.
3. エージェントの身元で gh が動くことを確かめる.
- `GH_CONFIG_DIR=~/.config/agent-harness/gh gh api
/installation/repositories --jq .total_count` が数を返す.
   - `stat -f %Lp ~/.config/agent-harness/gh/hosts.yml` が `600` を返す.
4. 新しく起動した Claude Code または Codex のセッションで `gh pr list --repo
furedea/dotfiles` が動く.
5. 旧版の状態ファイル `~/.config/agent-harness/gh/agent_harness_token.json`
は不要なので消してよい.

## 検証

- `bats tests/github-app-token`: 22 件すべて成功.スクリプトを作る前,失効と権限を足す前,2
回前の失効に変える前の各段階で,テストが先に失敗することを確認した.
- `nix flake check`: 成功(`all checks passed!`).
  - lock 更新前は次の 4 件が失敗し,更新後に通ることを確認した.
- `agent-harness-github-option-removed`(旧
`agent-harness-has-no-github-option`)
    - `github-app-key-unreadable-by-claude`,`-codex`,`-antigravity`
  - `GH_CONFIG_DIR` の 2 件は,dotfiles で設定した時点で通った.
- `bats --recursive tests`(137 件): 今回の変更による失敗はなし.ローカルのサンドボックスで zsh の
ssh-agent の 8 件と nvim の lspmux の 1 件が失敗したが,原因は Unix ソケットの listen と
`~/.local/state/nvim` への書き込みの拒否で,今回の変更とは関係ない.
- shellcheck,shfmt,lefthook,commitlint: 成功.
- Nix のチェック `agent-github-token-script`(darwinOnly): bats の仕様を,launchd
ジョブと同じ固定ツール(`nix/agent_github_token.nix`,curl のみ偽物)で実行し,22 件すべて成功.
- CI: `codex-review` と,それに連動する `all-green` 以外はすべて成功.`codex-review`
は利用上限で実行されていない(Codex のコメントで確認).
- 実際の鍵とトークンは,読み取りも表示もしていない.テストは使い捨ての鍵と偽の curl を使う.

## レビュー対応

- **P1(Claude)**: launchd ジョブの `TOOLS_PATH` に `sed` がなく,2 回目以降の実行が exit
127 で失敗してトークンが更新されなくなる.
  - 29e11c7 で修正した.前のトークンは bash の正規表現で読むようにした.
- bats の仕様をジョブと同じ固定ツールで実行する Nix チェックを足した.修正前のスクリプトで,このチェックが `sed:
command not found` で失敗することを確認した.
- **P2(Claude)**: 前のトークンをすぐ失効させるため,次の実行より長く動く `gh`(`gh run watch` など)が
401 になる.
- 所有者の判断で,2 回前のトークンを失効させる方式に変えた(ae6e9e1).有効なトークンは最大 2 つ,漏れたトークンは最大 30
分で失効する.
  - ADR-0055 の Decision と Consequences を更新した(b4fecc3).
- **P3(Claude)**: Claude Code の `Read(/path)`
はプロジェクトからの相対パスとして読まれるので,鍵の契約が保護にならないエントリーを通しうる.
  - 398e377 で修正した.`Read(` の絶対パスは `//` で始まるものだけを数える.
- **P3(Claude,変更なし)**: revoke の対象が `hosts.yml`
の値をそのまま使う点.指摘自身が問題なしとしている.エージェントがそのディレクトリに書けても,送られるのはエージェントがすでに持つトークンだけ.
- **P3(Claude,変更なし)**: checks は agent-harness
の合成を再現していて,生成結果そのものは読んでいない.生成結果を読むには評価時のビルド(IFD)が要るので,今の形にとどめた.agent-harness
の合成方法が変わったときは見直す.
- 最終の再レビュー(Claude): P0〜P2 の指摘なし.未解決のスレッドなし.
- 2 回前の失効と lock 更新後の再レビュー(Claude): P0〜P2 の指摘なし.P3 として,PR 本文の失効方式と lock
のリビジョンが古いと指摘された.push 直後に本文を更新しており,どちらも反映済み.
- Codex: 利用上限のため 2 回とも実行されていない.
- CI の bats で,GNU の `stat -f` によって mode の確認がずれていた.テストの補助関数で `stat -c`
を先に試すように直した.

## 計画からの逸脱

- JSON の読み取りに既存の `jq` を使った.インストール一覧の応答には入れ子の `id` があり,sed では確実に読めないため.
- 期限を追跡せず,毎回発行する.状態は前の `hosts.yml` だけで済む代わりに,1 台あたり毎時 4
回の発行と失効になる(ADR-0055).
- `nix/checks.nix` で agent-harness の合成を再現した.新しい agent-harness が
`composedSettings` を公開しなくなったため.

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

---------

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

1 participant