Skip to content

実装: AGENTS.md を repository index 化し native worktree isolation の混入を防止する #1737

Open

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: none
goal_ref: "AGENTS.md を20〜50行程度の repository instruction index として整備し、CLAUDE.md から import する。また、native worktree isolation を利用せず独自 issue worktree binding を正本とする方針を static validator で強制する。"
change_kind: mixed

Parent Issue

なし(単独改善)

Parent Goal Ref

  • Goal: AGENTS.md を repository instruction index として整備し、native worktree isolation の混入を static validator で防止する
  • Desired Destination: N/A(単独改善 Issue のため)

Current Validated Scope

  • AGENTS.md を20〜50行程度の index に再構成する
  • CLAUDE.md から @AGENTS.md を import する
  • native worktree isolation の混入を検出する static validator を追加する
  • worktree binding manifest(WORKTREE_SCOPE_BINDING_V1)の仕様を docs へ記載する

Remaining Parent Gaps

なし(単独改善 Issue のため)

Outcome

AGENTS.md が20〜50行程度の repository instruction index として整備され、CLAUDE.md が @AGENTS.md を import した状態になっている。加えて、native worktree isolation(isolation: worktree frontmatter・EnterWorktree 呼び出し・cwd basename や vendor-specific agent ID からの Issue 推測など)の混入を検出する static validator が追加され、独自 issue worktree binding manifest(WORKTREE_SCOPE_BINDING_V1)と live Git state の照合による正規 binding 解決が test で保証されている状態。

In Scope

概要

AGENTS.md を20~50行程度の repository instruction index として整備し、CLAUDE.md から import する。

同時に、Claude Code/Codex CLI の native worktree isolation を利用せず、独自 issue worktree binding を正本とするプロジェクト方針を static validator で強制する。

背景

現在の AGENTS.md と CLAUDE.md は短い pointer に留まっている。

一方、すべての build/test command や Skill/Agent/Hook の詳細責務を常時 context に入れると、異なる作業文脈で不要な instructions が増え、context bloat や conflicting instructions を招く。

Repository-level instruction は索引に限定し、作業固有の手順は対応する Skill と SSOT document へ委譲する。

また、このリポジトリでは vendor-native isolation ではなく、独自 issue worktree binding を正本とする。Agent の cwd や vendor-specific agent ID から Issue を推測してはならない。

対象

  • AGENTS.md
  • CLAUDE.md
  • repository instruction checker
  • Agent/Skill frontmatter validator
  • worktree binding documentation
  • tests

実装要件

CLAUDE.md

AGENTS.md を import し、Claude Code 固有の差分だけを保持する。

@AGENTS.md

AGENTS.md

20~50行程度を目安とし、次を含める。

  • repository の短い概要
  • 1 Issue = 1 PR
  • 独自 issue worktree binding が SSOT であること
  • 主要ディレクトリから対応する運用 SSOT への索引
  • 重要 docs への索引
  • 逸脱時に参照する Skill
  • repository mutation 前に binding validator を通すこと

次は記載しない。

  • 全文脈に共通しない pnpm typecheck / lint / test / build
  • Python/TypeScript/AI Agent 全体へ一律適用できない command
  • Skill/Agent/Hook の詳細責務
  • 長大 schema
  • generic coding conventions
  • GitHub branch protection と重複する長文
  • repository 固有でない一般論

native isolation validator

次を禁止対象として検出する。

Claude agent frontmatter: isolation: worktree
EnterWorktree 呼び出し
Codex native isolation/worktree option
agent-* 命名 worktree を issue binding とみなす処理
cwd basename だけに依存した issue 解決
vendor-specific agent ID からの issue 推測

正規 binding は明示的 manifest と live Git state の照合で解決する。

例:

WORKTREE_SCOPE_BINDING_V1:
  repo: squne121/loop-protocol
  issue_number: 123
  worktree_path: /absolute/path
  branch: worktree-issue-123-slug
  bootstrap_head_sha: ...
  binding_digest: ...

GitHub branch protection はローカル working tree の編集を防止しないため、repository mutation の禁止は Skill/executor/binding validator 側で強制する。

Out of Scope

  • AGENTS.md を workflow manual にすること
  • すべての test command を常時読み込ませること
  • GitHub ruleset だけでローカル main checkout の変更を防げると仮定すること
  • native isolation と独自 issue binding を併用すること

Acceptance Criteria

  • AC1: AGENTS.md が20~50行程度の index になっている
  • AC2: CLAUDE.md が @AGENTS.md を import している
  • AC3: Claude Code 固有情報は CLAUDE.md に分離されている
  • AC4: 主要ディレクトリから運用 SSOT を発見できる
  • AC5: 文脈固有の build/test command が常時 instruction から除外されている
  • AC6: native worktree isolation の混入を検出する validator がある
  • AC7: isolation: worktree と EnterWorktree の fixture が拒否される
  • AC8: cwd basename/agent ID だけによる Issue 推測が拒否される
  • AC9: manifest と live Git state の不一致が拒否される
  • AC10: repository mutation 前の binding validation が test されている
  • AC11: Claude Code と Codex CLI の双方で index discovery の smoke test が成功する

Verification Commands

# AC1
$ wc -l AGENTS.md

# AC2
$ rg -n "^@AGENTS.md$" CLAUDE.md

# AC3
$ rg -c "Claude Code" CLAUDE.md

# AC4
$ rg -n "docs/" AGENTS.md

# AC5
$ rg -c -e "pnpm typecheck" -e "pnpm lint" -e "pnpm test" -e "pnpm build" AGENTS.md

# AC6
$ test -f scripts/agent-ops/native_isolation_guard.py

# AC7
$ uv run --locked python3 -m pytest scripts/agent-ops/tests/test_native_isolation_guard.py -k isolation_worktree_frontmatter_rejected

# AC8
$ uv run --locked python3 -m pytest scripts/agent-ops/tests/test_native_isolation_guard.py -k cwd_or_agent_id_inference_rejected

# AC9
$ uv run --locked python3 -m pytest scripts/agent-ops/tests/test_native_isolation_guard.py -k manifest_live_git_state_mismatch_rejected

# AC10
$ uv run --locked python3 -m pytest scripts/agent-ops/tests/test_native_isolation_guard.py -k mutation_precondition_validated

# AC11
$ uv run --locked python3 -m pytest scripts/agent-ops/tests/test_native_isolation_guard.py -k index_discovery_smoke

Allowed Paths

  • AGENTS.md
  • CLAUDE.md
  • scripts/agent-ops/native_isolation_guard.py
  • scripts/agent-ops/tests/test_native_isolation_guard.py
  • docs/dev/worktree-issue-binding.md

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合

Required Skills

  • Python
  • Markdown / repository instruction authoring

Required Design References

  • docs/dev/workflow.md
  • docs/dev/secret-policy.md

Scope Delta(該当時のみ記載)

N/A

Delivery Rule

  • 1 Issue = 1 PR
  • 作業は専用 worktree(worktree-issue-<番号>-<slug>)で行う
  • PR は Draft PR を既定とする

Notes for Reviewer

Activity

  1. added
    enhancement
    phase/implementation
    triage-required
    agent/implementer
    on Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/implementerenhancementphase/implementationtriage-required

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions