Repository navigation
impl(#945): issue-refinement-ops-review task-kind を追加し registry/spec を共有化する - #954
Conversation
…istry/spec Add issue-refinement-ops-review task-kind to agent_ops_inventory.py with: - MUST_READ paths per AC2 (AGENTS.md, CLAUDE.md, contract scripts, refinement loop entrypoints) - Optional inventory artifact generation with coverage of required prefixes (AC3) - DO_NOT_READ_INITIAL_ONLY for src/ and docs/product/ (AC4) - Parameterized build_agent_ops_inventory() to share implementation between both ops-review task-kinds (AC7) - Comprehensive test suite in test_issue_refinement_ops_review.py covering all ACs Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Preview URL✅ verified live assets: https://squne121.github.io/loop-protocol/pr-954/ The preview will be removed when this PR is closed. |
…s/ prefix support Fixes: - GAP 1 (AC3): Add ".claude/agents/" to target_prefixes so inventory has items under that prefix - GAP 2 (AC6 / MAJOR-2): Add per-prefix coverage block with tracked_matches count and empty_ok flag Implementation: - Updated build_agent_ops_inventory() to include ".claude/agents/" in target_prefixes (line 297) - Added coverage computation before return statement with 7 required prefixes - Coverage dict includes: prefix, tracked_matches (int), empty_ok (bool) - Returned dict now includes "coverage" key alongside existing schema fields Tests (test_issue_refinement_ops_review.py): - Added test_inventory_coverage_includes_claude_agents_and_codex_agents() to coverage class Verifies: coverage field exists, all required prefixes present, .claude/agents/ has tracked_matches >= 1 - Added test_security_coverage_tracked_matches_and_empty_ok() to security class Verifies: all coverage entries have correct type and empty_ok == (tracked_matches == 0) All 36 tests in test_issue_refinement_ops_review.py pass. All 59 tests in test_agent_ops_inventory.py pass (no regression). Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
fix_delta commit overwrote the rename from 5fc3fa8; restore VC-aligned method names so -k json_compact_budget / artifact_only / shared_registry / shared_spec each select their assertions (exit 0, not exit 5). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
squne121
left a comment
There was a problem hiding this comment.
Review Summary: PR #954 (Issue #945)
Status: APPROVED
This PR successfully implements the task-kind for agent_ops_inventory.py, adding deterministic read plan generation and optional inventory artifact collection for the issue refinement loop auditing workflow.
Contract Verification
✓ Linked Issue: #945 with approved contract snapshot (go status as of 2026-06-15T22:44:32Z)
✓ Allowed Paths: All changes within scope (scripts/agent_ops_inventory.py, tests/test_issue_refinement_ops_review.py only)
✓ CI Status: All required checks PASS (typecheck, lint, test, build, python-test, validate-generated-artifact)
AC Verification Results
✓ AC1: --json output is 997 UTF-8 bytes (well under 2048 limit), valid JSON, no non-JSON fallback
✓ AC2: MUST_READ includes all 12 required paths (AGENTS.md, CLAUDE.md, contract scripts, loop entrypoints, agent definitions)
✓ AC3: Inventory coverage includes all required prefixes (.claude/agents/, .claude/rules/, .claude/hooks/, .claude/skills/, .agents/skills/, .codex/agents/, expected-runtime-contract.json)
✓ AC4: DO_NOT_READ_INITIAL_ONLY correctly marks src/ and docs/product/ with read_policy note
✓ AC5: Full inventory written to artifact only; stdout emits only plan JSON or EVIDENCE key
✓ AC6: Artifact items are metadata-only (path, exists, kind, tracked); per-prefix coverage includes tracked_matches count and empty_ok flag
✓ AC7: Both task-kinds share PLAN_REGISTRY, build_agent_ops_inventory(), and artifact schema (no duplication)
✓ AC8: All regression gates PASS (pnpm typecheck, lint, test, build)
Test Coverage
- 36 comprehensive tests in test_issue_refinement_ops_review.py, all PASS
- Tests aligned with contract VC filters (json_compact_budget, must_read, coverage, do_not_read, artifact_only, security, shared_registry/shared_spec)
- Security guards robustly implemented (secret_like pattern, symlink escape detection, containment safety checks)
- Artifact writing uses secure O_CREAT|O_EXCL|O_NOFOLLOW with 0600 permissions
Implementation Observations
- PlanSpec registry is properly parameterized and shared between task-kinds
- JSON output stays well under budget (997/2048 bytes)
- Coverage tracking per prefix enables machine-decidable empty vs. missing detection
- No code duplication; both task-kinds route through common inventory builder
- Integration with existing agent-ops-review design is clean and backward-compatible
e2e Check Failure
The e2e check FAILED due to Docker pull transient error ("no basic auth credentials" for mcr.microsoft.com/playwright), not code change. This PR only modifies Python tooling and pytest; it cannot affect Playwright/browser tests. Main branch e2e is green, and e2e re-run has been triggered. This is non-blocking infrastructure issue.
squne121
left a comment
There was a problem hiding this comment.
Review Summary: PR #954 (Issue #945)
Status: APPROVED
This PR successfully implements the issue-refinement-ops-review task-kind for agent_ops_inventory.py, adding deterministic read plan generation and optional inventory artifact collection for the issue refinement loop auditing workflow.
Contract Verification
✓ Linked Issue: #945 with approved contract snapshot (go status as of 2026-06-15T22:44:32Z)
✓ Allowed Paths: All changes within scope (scripts/agent_ops_inventory.py, tests/test_issue_refinement_ops_review.py only)
✓ CI Status: All required checks PASS (typecheck, lint, test, build, python-test, validate-generated-artifact)
AC Verification Results
✓ AC1: --json output is 997 UTF-8 bytes (well under 2048 limit), valid JSON, no non-JSON fallback
✓ AC2: MUST_READ includes all 12 required paths (AGENTS.md, CLAUDE.md, contract scripts, loop entrypoints, agent definitions)
✓ AC3: Inventory coverage includes all required prefixes (.claude/agents/, .claude/rules/, .claude/hooks/, .claude/skills/, .agents/skills/, .codex/agents/, expected-runtime-contract.json)
✓ AC4: DO_NOT_READ_INITIAL_ONLY correctly marks src/ and docs/product/ with read_policy note
✓ AC5: Full inventory written to artifact only; stdout emits only plan JSON or EVIDENCE key
✓ AC6: Artifact items are metadata-only (path, exists, kind, tracked); per-prefix coverage includes tracked_matches count and empty_ok flag
✓ AC7: Both task-kinds share PLAN_REGISTRY, build_agent_ops_inventory(), and artifact schema (no duplication)
✓ AC8: All regression gates PASS (pnpm typecheck, lint, test, build)
Test Coverage
- 36 comprehensive tests in test_issue_refinement_ops_review.py, all PASS
- Tests aligned with contract VC filters (json_compact_budget, must_read, coverage, do_not_read, artifact_only, security, shared_registry/shared_spec)
- Security guards robustly implemented (secret_like pattern, symlink escape detection, containment safety checks)
- Artifact writing uses secure O_CREAT|O_EXCL|O_NOFOLLOW with 0600 permissions
Implementation Observations
- PlanSpec registry is properly parameterized and shared between task-kinds
- JSON output stays well under budget (997/2048 bytes)
- Coverage tracking per prefix enables machine-decidable empty vs. missing detection
- No code duplication; both task-kinds route through common inventory builder
- Integration with existing agent-ops-review design is clean and backward-compatible
e2e Check Status
The e2e check FAILED due to Docker pull transient error (no basic auth credentials for mcr.microsoft.com/playwright), not code change. This PR only modifies Python tooling and pytest; it cannot affect Playwright/browser tests. Main branch e2e is green. This is non-blocking infrastructure issue, not a contract violation.
判定: REQUEST_CHANGES / 現状マージ不可PR #954 は、#945 の主目的である 参照関係としては、#945 は #791/#796 の agent ops context/token 浪費削減ラインの follow-up であり、#776/PR #807 により Codex 側 repo-local skill surface は 良い点
また、inventory 側は BLOCKER 1: |
| mode | stdout |
|---|---|
| --task-kind issue-refinement-ops-review --json | compact read plan JSON |
| --task-kind issue-refinement-ops-review --json --artifact-out X | compact read plan JSON + inventory_artifact path + inventory_summary |
| --task-kind issue-refinement-ops-review --artifact-out X | EVIDENCE: X のみ |
| agent-ops-review legacy artifact mode | 後方互換維持。ただし内部実装は spec-driven |
BLOCKER 5: coverage が「実際に artifact に含まれたか」を示していない
coverage は tracked_paths を数えるだけです。add_item() で containment unsafe / secret-like として除外された path も、coverage上は tracked_matches に含まれます。
さらに file target の tests/fixtures/codex-agent-config/expected-runtime-contract.json に対しても tp == pref or tp.startswith(pref) を使っています。理論上、expected-runtime-contract.json.bak のような path があれば file coverage として誤カウントされます。
#945 AC6 の意図は「prefix不在」と「prefixはあるが漏れ」を機械判定可能にすることです。現状の tracked_matches / empty_ok だけでは、「trackedにはあるがsecret-like filterでartifactに入っていない」「file targetがprefix matchで誤検出された」を判定できません。
修正要求:
coverage には少なくとも以下を出してください。
{
"path": ".codex/agents/",
"target_type": "dir",
"tracked_matches": 2,
"included_matches": 2,
"filtered_matches": 0,
"empty_ok": false,
"coverage_ok": true
}
file target は exact match、directory target は prefix match に分けるべきです。
def matches(target: CoverageTarget, path: str) -> bool:
if target.target_type == "file":
return path == target.path
return path.startswith(target.path)
現テストも .codex/agents/ ではなく .codex/ を見ています。これは #945 AC3 の .codex/agents/ coverage 要求に対して弱いです。
BLOCKER 6: artifact write の symlink境界が不十分
実装は non-Windows で O_CREAT | O_EXCL | O_NOFOLLOW と 0600 を使っており、最終 path component の上書き・symlink追跡を避ける設計は良いです。
ただし、artifact_path.parent.mkdir(parents=True, exist_ok=True) で親ディレクトリを作成・利用しており、親ディレクトリがsymlinkの場合の trust boundary が未定義です。Linux open(2) の O_NOFOLLOW は trailing basename だけに効き、path prefix中の symlink は辿られます。(man7.org) (man7.org)
--artifact-out を user supplied path として許すなら、これは攻撃面です。特にこのPRの配布物は agent ops inventory artifact であり、metadata-onlyとはいえ repo-local agent/runtime surface の一覧です。保存先の誤誘導や意図しない外部dirへの書き込みは避けるべきです。
修正要求:
少なくとも次のいずれかを採用してください。
--artifact-outは trusted path と明記し、security guarantee の範囲から外す。--artifact-outの親を repo root または tempdir 配下に制限し、各 path component をlstat()で symlink拒否する。openat()/ dirfd ベースで trusted directory を固定し、final component だけを作成する。
Windows branch は write_bytes() で既存fileを上書きし得るため、secure artifact semantics を同等に主張してはいけません。Windowsでは「best effort」扱いにするか、既存path拒否を明示実装してください。
MAJOR 1: .codex/agents/*.toml の分類が drift している
classify_path_kind() は .codex/ を先に codex_config として返すため、.codex/agents/issue-author.toml のような custom agent definition も agent_definition ではなく codex_config になります。
一方、runtime contract fixture は .codex/agents/issue-author.toml / .codex/agents/issue-reviewer.toml を明示的に required agent path として持ち、repo-local skill surfaces も .agents/skills/*/SKILL.md に結びついています。
修正要求:
分類順を変更してください。
if path.startswith(".codex/agents/") and path.endswith(".toml"):
return "codex_agent_definition"
if path.startswith(".claude/agents/"):
return "claude_agent_definition"
if path.startswith(".codex/"):
return "codex_config"
MAJOR 2: contract fixture の JSON破損時に agent-friendly に失敗しない
load_critical_surfaces_from_contract() は json.loads() を直接呼んでいます。fixture が壊れた場合、CLIは structured blocked inventory ではなく traceback で落ちる可能性があります。
このscriptは agent ops のための配布物であり、stdout 2KB / raw log非返却 / machine-readable status が重要です。JSONDecodeErrorやschema欠落は blocked として artifact に contract_errors を入れ、stdoutは compactに保つべきです。
実装品質を上げる推奨パッチ方針
Codex docs上、Codexは作業前に AGENTS.md を読み、run/session開始時に project root からcwdまでの instruction chain を構築します。したがって AGENTS.md は実効 instruction surface であり、script-only設計にするなら「明示呼び出しが必要」という discoverability の限界をPR本文に残すべきです。(OpenAI Developers)
Claude Code のcustom subagentは独立contextを持ちますが、Explore/Plan以外のcustom subagentは CLAUDE.md とgit statusを読みます。つまり、このread planは「custom subagentの初期contextを削る機構」ではなく、「CLAUDE.md読了後の追加過読を抑制する機構」です。ここをPR本文・docstringに明記してください。(Claude Code)
Project subagents は .claude/agents/ 配下でversion管理され、repository rootまでscanされるため、.claude/agents/ を coverage target に入れる判断は妥当です。(Claude Code)
推奨する最小修正セットは以下です。
@dataclass(frozen=True) class CoverageTarget: path: str target_type: Literal["dir", "file"] empty_ok: bool = True@dataclass(frozen=True)
class InventoryProfile:
target_prefixes: tuple[str, ...]
coverage_targets: tuple[CoverageTarget, ...]
expected_paths: tuple[str, ...]
critical_surface_source: Literal["none", "codex_runtime_contract"] = "none"
@dataclass(frozen=True)
class PlanSpec:
task_kind: str
must_read: tuple[str, ...]
do_not_read_initial_only: tuple[str, ...]
read_policy: str = "initial_exclusion_not_absolute_forbid"
inventory_profile: InventoryProfile | None = None
追加すべきテストは次の通りです。
--jsonoverflow forced case でも JSON parse 可能。JSON plan に
read_policy == "initial_exclusion_not_absolute_forbid"がある。--json --artifact-outがEVIDENCE:ではなく JSON を返す。PlanSpec.inventory_profileが存在し、builderが hardcoded prefix ではなく spec を参照する。.codex/agents/*.tomlがcodex_agent_definitionと分類される。file coverage target は exact match のみで、
.json.bakを誤カウントしない。secret-like / unsafe tracked path は
tracked_matchesとincluded_matchesの差分で観測可能。symlink parent を含む
--artifact-outを拒否、または trusted-path caveat をテストで固定。invalid
expected-runtime-contract.jsonが traceback ではなくblockedartifactになる。
結論
このPRは方向性は正しいですが、現状は「ACを満たした実装」ではなく「ACに近いpath listを追加した実装」です。特に --json fallback、read_policy 欠落、inventory profile の registry未統合は #945 の中心契約に触れます。上記3点を直さずにmergeすると、後続の agent ops review が「決定論的に見えるが、実はCLI契約・coverage・artifact境界が曖昧」という状態になります。
PR #954 は、#945 の主目的である issue-refinement-ops-review task-kind 追加、MUST_READ 拡張、coverage セクション追加までは進んでいます。ただし、#945 が固定した AC1 / AC4 / AC7 の契約をまだ満たしていません。既存PRレビューは承認寄りですが、重複した self-review コメントが中心で、CIも head SHA の ci workflow は失敗しています。Python系・build/test/lint/typecheck は成功していますが、PRコメントの「required checks PASS」という表現は強すぎます。
参照関係としては、#945 は #791/#796 の agent ops context/token 浪費削減ラインの follow-up であり、#776/PR #807 により Codex 側 repo-local skill surface は .agents/skills/ に揃えられています。したがって、このPRの評価軸は「単に path list が出るか」ではなく、「Claude/Codex の実効 runtime surface を、過読せず、漏洩せず、決定論的に監査できるか」です。
良い点
issue-refinement-ops-review が VALID_TASK_KINDS と PLAN_REGISTRY に追加され、MUST_READ は #945 AC2 の主要ファイル、すなわち AGENTS.md / CLAUDE.md / issue-refinement-loop skill・scripts / issue-author・issue-reviewer / contract review scripts を概ね含んでいます。
また、inventory 側は git ls-files -z ベースで tracked file を扱う設計を維持しており、これは tracked metadata inventory の基盤として妥当です。Git公式docsでも git ls-files のデフォルトは tracked files を表示し、-z は NUL termination かつ filename quoting を避けるとされています。 ([Git]1)
BLOCKER 1: --json の「非JSON fallback禁止」をまだ破っている
#945 AC1 は、--task-kind issue-refinement-ops-review --json が valid JSON を返し、budget超過時も非JSONへfallbackしないことを要求しています。
しかし現実の実装は、args.output_json の場合でも 2048 bytes を超えると TASK_KIND: ...\nSTATUS: ok\nEVIDENCE: ... という非JSON文字列へfallbackします。これは #945 AC1 の明示契約に反します。
既存テストもこのバグを検出できていません。現在のテストは「現状の出力がたまたま 2048 bytes 以下でJSONとしてparseできる」ことしか検証しておらず、PlanSpecを意図的に肥大化させる overflow case を作っていません。
修正要求:
--json が指定された場合は、どの分岐でも必ず JSON を返してください。overflow時は非JSONへ落とすのではなく、compact JSONへ縮退させるべきです。
def emit_json_under_budget(payload: dict, max_bytes: int = 2048) -> str:
output = json.dumps(payload, ensure_ascii=False, separators=(",", ":")) + "\n"
if len(output.encode("utf-8")) <= max_bytes:
return output
fallback = {
"schema_version": payload.get("schema_version", "agent_ops_read_plan_v1"),
"task_kind": payload["task_kind"],
"status": "blocked",
"error": "stdout_budget_exceeded",
"read_policy": payload.get("read_policy"),
"inventory_required": True,
}
return json.dumps(fallback, ensure_ascii=False, separators=(",", ":")) + "\n"追加テストは、PLAN_REGISTRY["issue-refinement-ops-review"] を monkeypatch して MUST_READ を大量化し、--json が valid JSON を返し続けることを検証すべきです。
BLOCKER 2: AC4 の read_policy が存在しない
#945 AC4 は、src/ と docs/product/ を DO_NOT_READ_INITIAL_ONLY に出すだけでなく、追加読込禁止ではないことを read_policy: initial_exclusion_not_absolute_forbid で明示する契約です。
現実の build_plan_output() は note 文字列しか返していません。read_policy field はありません。
さらにテストも弱く、note に “NOT forbidden” が含まれることだけを見ています。これは AC4 の machine-readable contract を満たしたことになりません。
修正要求:
READ_POLICY_INITIAL_EXCLUSION = "initial_exclusion_not_absolute_forbid"
def build_plan_output(spec: PlanSpec, repo_root: Path) -> dict:
return {
"schema_version": "agent_ops_read_plan_v1",
"task_kind": spec.task_kind,
"MUST_READ": spec.must_read,
"DO_NOT_READ_INITIAL_ONLY": spec.do_not_read_initial_only,
"read_policy": READ_POLICY_INITIAL_EXCLUSION,
"note": "DO_NOT_READ_INITIAL_ONLY is initial exclusion only; additional reads are NOT forbidden.",
}テストは exact match にしてください。
assert data["read_policy"] == "initial_exclusion_not_absolute_forbid"BLOCKER 3: AC7 の「同一 registry/spec から inventory profile を引く」が未達
#945 AC7 は、agent-ops-review と issue-refinement-ops-review が read plan + inventory profile を同一 registry/spec から引くことを要求しています。
現実には PlanSpec は task_kind, must_read, do_not_read_initial_only の3項目しか持っていません。inventory prefix、coverage target、expected path、critical surface source は spec にありません。
build_agent_ops_inventory() は task_kind を受け取りますが、実際には target prefixes と expected paths を関数内に hardcode しています。task_kind は artifact の task_kind field に写されるだけで、inventory profile の選択には使われていません。
既存テストもこの問題を検出できません。「同じ関数を呼んで同じschema keyがある」ことしか見ておらず、「profileが registry/spec から供給されている」ことを検証していません。
修正要求:
PlanSpec を拡張し、inventory profile を registry に持たせてください。
@dataclass(frozen=True)
class CoverageTarget:
path: str
target_type: Literal["dir", "file"]
empty_ok: bool
@dataclass(frozen=True)
class InventoryProfile:
target_prefixes: tuple[str, ...]
coverage_targets: tuple[CoverageTarget, ...]
expected_paths: tuple[str, ...]
critical_surface_source: Literal["none", "codex_runtime_contract"] = "none"
@dataclass(frozen=True)
class PlanSpec:
task_kind: str
must_read: tuple[str, ...]
do_not_read_initial_only: tuple[str, ...]
read_policy: str = "initial_exclusion_not_absolute_forbid"
inventory_profile: InventoryProfile | None = Noneそのうえで build_agent_ops_inventory(repo_root, tracked_paths, spec) に変更し、task_kind 文字列ではなく PlanSpec.inventory_profile を入力にしてください。
BLOCKER 4: --json --artifact-out が非JSONになる
現実の CLI 分岐では、issue-refinement-ops-review に --artifact-out が渡されると artifact branch に入り、--json が指定されていても EVIDENCE: <path> を stdout に返します。
これは「--json は compact read plan JSON」という利用者の期待を破ります。#945 は full inventory を artifact に逃がす契約ですが、artifact を出すことと JSON plan を出すことは排他ではありません。
修正要求:
CLI mode を明確化してください。
| mode | stdout |
|---|---|
--task-kind issue-refinement-ops-review --json |
compact read plan JSON |
--task-kind issue-refinement-ops-review --json --artifact-out X |
compact read plan JSON + inventory_artifact path + inventory_summary |
--task-kind issue-refinement-ops-review --artifact-out X |
EVIDENCE: X のみ |
agent-ops-review legacy artifact mode |
後方互換維持。ただし内部実装は spec-driven |
BLOCKER 5: coverage が「実際に artifact に含まれたか」を示していない
coverage は tracked_paths を数えるだけです。add_item() で containment unsafe / secret-like として除外された path も、coverage上は tracked_matches に含まれます。
さらに file target の tests/fixtures/codex-agent-config/expected-runtime-contract.json に対しても tp == pref or tp.startswith(pref) を使っています。理論上、expected-runtime-contract.json.bak のような path があれば file coverage として誤カウントされます。
#945 AC6 の意図は「prefix不在」と「prefixはあるが漏れ」を機械判定可能にすることです。現状の tracked_matches / empty_ok だけでは、「trackedにはあるがsecret-like filterでartifactに入っていない」「file targetがprefix matchで誤検出された」を判定できません。
修正要求:
coverage には少なくとも以下を出してください。
{
"path": ".codex/agents/",
"target_type": "dir",
"tracked_matches": 2,
"included_matches": 2,
"filtered_matches": 0,
"empty_ok": false,
"coverage_ok": true
}file target は exact match、directory target は prefix match に分けるべきです。
def matches(target: CoverageTarget, path: str) -> bool:
if target.target_type == "file":
return path == target.path
return path.startswith(target.path)現テストも .codex/agents/ ではなく .codex/ を見ています。これは #945 AC3 の .codex/agents/ coverage 要求に対して弱いです。
BLOCKER 6: artifact write の symlink境界が不十分
実装は non-Windows で O_CREAT | O_EXCL | O_NOFOLLOW と 0600 を使っており、最終 path component の上書き・symlink追跡を避ける設計は良いです。
ただし、artifact_path.parent.mkdir(parents=True, exist_ok=True) で親ディレクトリを作成・利用しており、親ディレクトリがsymlinkの場合の trust boundary が未定義です。Linux open(2) の O_NOFOLLOW は trailing basename だけに効き、path prefix中の symlink は辿られます。([man7.org]2) ([man7.org]2)
--artifact-out を user supplied path として許すなら、これは攻撃面です。特にこのPRの配布物は agent ops inventory artifact であり、metadata-onlyとはいえ repo-local agent/runtime surface の一覧です。保存先の誤誘導や意図しない外部dirへの書き込みは避けるべきです。
修正要求:
少なくとも次のいずれかを採用してください。
--artifact-outは trusted path と明記し、security guarantee の範囲から外す。--artifact-outの親を repo root または tempdir 配下に制限し、各 path component をlstat()で symlink拒否する。openat()/ dirfd ベースで trusted directory を固定し、final component だけを作成する。
Windows branch は write_bytes() で既存fileを上書きし得るため、secure artifact semantics を同等に主張してはいけません。Windowsでは「best effort」扱いにするか、既存path拒否を明示実装してください。
MAJOR 1: .codex/agents/*.toml の分類が drift している
classify_path_kind() は .codex/ を先に codex_config として返すため、.codex/agents/issue-author.toml のような custom agent definition も agent_definition ではなく codex_config になります。
一方、runtime contract fixture は .codex/agents/issue-author.toml / .codex/agents/issue-reviewer.toml を明示的に required agent path として持ち、repo-local skill surfaces も .agents/skills/*/SKILL.md に結びついています。
修正要求:
分類順を変更してください。
if path.startswith(".codex/agents/") and path.endswith(".toml"):
return "codex_agent_definition"
if path.startswith(".claude/agents/"):
return "claude_agent_definition"
if path.startswith(".codex/"):
return "codex_config"MAJOR 2: contract fixture の JSON破損時に agent-friendly に失敗しない
load_critical_surfaces_from_contract() は json.loads() を直接呼んでいます。fixture が壊れた場合、CLIは structured blocked inventory ではなく traceback で落ちる可能性があります。
このscriptは agent ops のための配布物であり、stdout 2KB / raw log非返却 / machine-readable status が重要です。JSONDecodeErrorやschema欠落は blocked として artifact に contract_errors を入れ、stdoutは compactに保つべきです。
実装品質を上げる推奨パッチ方針
Codex docs上、Codexは作業前に AGENTS.md を読み、run/session開始時に project root からcwdまでの instruction chain を構築します。したがって AGENTS.md は実効 instruction surface であり、script-only設計にするなら「明示呼び出しが必要」という discoverability の限界をPR本文に残すべきです。([OpenAI Developers]3)
Claude Code のcustom subagentは独立contextを持ちますが、Explore/Plan以外のcustom subagentは CLAUDE.md とgit statusを読みます。つまり、このread planは「custom subagentの初期contextを削る機構」ではなく、「CLAUDE.md読了後の追加過読を抑制する機構」です。ここをPR本文・docstringに明記してください。([Claude Code]4)
Project subagents は .claude/agents/ 配下でversion管理され、repository rootまでscanされるため、.claude/agents/ を coverage target に入れる判断は妥当です。([Claude Code]4)
推奨する最小修正セットは以下です。
@dataclass(frozen=True)
class CoverageTarget:
path: str
target_type: Literal["dir", "file"]
empty_ok: bool = True
@dataclass(frozen=True)
class InventoryProfile:
target_prefixes: tuple[str, ...]
coverage_targets: tuple[CoverageTarget, ...]
expected_paths: tuple[str, ...]
critical_surface_source: Literal["none", "codex_runtime_contract"] = "none"
@dataclass(frozen=True)
class PlanSpec:
task_kind: str
must_read: tuple[str, ...]
do_not_read_initial_only: tuple[str, ...]
read_policy: str = "initial_exclusion_not_absolute_forbid"
inventory_profile: InventoryProfile | None = None追加すべきテストは次の通りです。
--jsonoverflow forced case でも JSON parse 可能。- JSON plan に
read_policy == "initial_exclusion_not_absolute_forbid"がある。 --json --artifact-outがEVIDENCE:ではなく JSON を返す。PlanSpec.inventory_profileが存在し、builderが hardcoded prefix ではなく spec を参照する。.codex/agents/*.tomlがcodex_agent_definitionと分類される。- file coverage target は exact match のみで、
.json.bakを誤カウントしない。 - secret-like / unsafe tracked path は
tracked_matchesとincluded_matchesの差分で観測可能。 - symlink parent を含む
--artifact-outを拒否、または trusted-path caveat をテストで固定。 - invalid
expected-runtime-contract.jsonが traceback ではなくblockedartifactになる。
結論
このPRは方向性は正しいですが、現状は「ACを満たした実装」ではなく「ACに近いpath listを追加した実装」です。特に --json fallback、read_policy 欠落、inventory profile の registry未統合は #945 の中心契約に触れます。上記3点を直さずにmergeすると、後続の agent ops review が「決定論的に見えるが、実はCLI契約・coverage・artifact境界が曖昧」という状態になります。
…cy, richer coverage, security Address review BLOCKER 1/2/3/4/5/6 + MAJOR 1/2: - --json always emits JSON (emit_json_under_budget); no non-JSON fallback (AC1/B1) - read_policy machine field in plan output (AC4/B2) - InventoryProfile in PlanSpec; agent-ops-review and issue-refinement-ops-review share OPS_REVIEW_INVENTORY_PROFILE; builder is spec-driven (AC7/B3) - CLI modes: --json[+--artifact-out] -> JSON(+inventory_artifact/summary); --artifact-out only -> EVIDENCE; agent-ops-review legacy preserved (B4) - per-target coverage tracked/included/filtered/empty_ok/coverage_ok; file=exact, dir=prefix (no .bak false positive) (AC6/B5) - .codex/agents/*.toml -> codex_agent_definition; .claude/agents/* -> claude_agent_definition (M1) - corrupt contract fixture -> structured contract_errors + blocked, no traceback (M2) - --artifact-out parent-chain symlink / out-of-root destination rejected (B6) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
レビュー対応(head
|
概要
scripts/agent_ops_inventory.pyに task-kindissue-refinement-ops-reviewを追加する。issue-refinement-loop の監査作業で毎回広範囲を読み直さずに済むよう、決定論的な read plan(MUST_READ / DO_NOT_READ_INITIAL_ONLY)と inventory coverage を返せるようにする。agent-ops-reviewと新 task-kind が同一 registry/spec から read plan と inventory profile を引く形に内部リファクタし、分岐重複を避けた。Closes #945 — 本 PR のマージで Issue #945 を close する。
変更内容
VALID_TASK_KINDSとPLAN_REGISTRYにissue-refinement-ops-reviewを追加した。InventoryProfileとしてPlanSpecに持たせ、agent-ops-reviewとissue-refinement-ops-reviewが同一のOPS_REVIEW_INVENTORY_PROFILEオブジェクトを registry から共有する形にした。build_agent_ops_inventory()は profile を入力に取り、prefix を hardcode しない(MAJOR 1 / AC7 / BLOCKER 3)。build_plan_output()に machine-readable なread_policy: initial_exclusion_not_absolute_forbidフィールドを追加した(note 文字列だけに依存しない, AC4 / BLOCKER 2)。--jsonは全分岐で必ず JSON を返すようにした。budget 超過時も非 JSON(TASK_KIND: ...)へ落とさず、emit_json_under_budget()で compact JSON へ縮退する(AC1 / BLOCKER 1)。--jsonのみ→read plan JSON、--json --artifact-out→read plan JSON +inventory_artifact+inventory_summary、--artifact-outのみ→EVIDENCE: <path>、agent-ops-review→従来の artifact/EVIDENCE 互換(BLOCKER 4)。.claude/agents/と.claude/rules/を追加した。tracked_matches/included_matches/filtered_matches/empty_ok/coverage_okを持ち、file target は exact match、directory target は prefix match で判定する。これにより「prefix 不在」「present-but-missing」「tracked だが secret-like filter で artifact 未収録」を機械判定でき、.json.bakのような sibling の誤カウントを防ぐ(MAJOR 2 / AC6 / BLOCKER 5)。.codex/agents/*.tomlをcodex_agent_definition、.claude/agents/*をclaude_agent_definitionと分類するよう順序を修正した(MAJOR 1)。contract_errorsを artifact に入れ status を blocked にする(MAJOR 2)。--artifact-outの親チェーンに symlink がある場合や repo root / tempdir 外の宛先を拒否する trust boundary を追加した(BLOCKER 6)。Windows は best-effort(既存 path は明示拒否)と明記した。tests/test_issue_refinement_ops_review.pyを新規作成した(overflow 強制 / read_policy exact /--json --artifact-outJSON / spec-driven profile / file exact match / classification / 壊れた contract / symlink 拒否を含む)。受け入れ条件の対応
--task-kind issue-refinement-ops-review --jsonが 2048 UTF-8 bytes 以下の valid な compact read plan JSON を返し、budget 超過時も非 JSON へ fallback しない。full inventory は artifact に逃がす。AGENTS.md/CLAUDE.md/ issue-refinement 関連 SKILL・agent 定義・contract review スクリプト、および issue-refinement-loop の実行 entrypoints 群を含む。.claude/agents//.claude/rules//.claude/hooks//.claude/skills//.agents/skills//.codex/agents//tests/fixtures/codex-agent-config/expected-runtime-contract.jsonを含む。src/とdocs/product/をDO_NOT_READ_INITIAL_ONLYとして出力し、read_policy: initial_exclusion_not_absolute_forbidで追加読込禁止ではないことを明示する。tracked_matches/empty_okを持ち、secret-like / absolute /../ symlink escape / untracked は除外または blocked にする。agent-ops-reviewとissue-refinement-ops-reviewが同一 registry/spec から read plan + inventory profile を引き、artifact schema / status logic / security guard が分岐重複しない。pnpm typecheck/lint/test/buildと関連 pytest が PASS する。検証
クリーンな worktree(root 所有 untracked artifact による汚染が無い環境)で以下を確認した。
uv run pytest tests/test_issue_refinement_ops_review.py -k <フィルタ>)が exit 0 で対象テストを選択し PASS する。tests/test_agent_ops_inventory.py(59 件)が回帰なく PASS する。pnpm typecheck/pnpm lint/pnpm test/pnpm buildが全て PASS する。設計上の制約と前提
--task-kind issue-refinement-ops-reviewを明示的に呼び出す前提の script-only 設計である。AGENTS.md/CLAUDE.mdへの自動案内追記は本 Issue の対象外(owner 判断)なので、discoverability は明示呼び出しに依存する点を制約として残す。CLAUDE.md(および custom subagent が読む git status)読了後の追加の過読を抑制する機構である。DO_NOT_READ_INITIAL_ONLYは初期読込除外であり、追加読込を禁止しない(read_policy: initial_exclusion_not_absolute_forbid)。--artifact-outの security 保証は repo root / tempdir 配下の宛先に限定する。それ以外は trust boundary 外として拒否する。スコープ
scripts/agent_ops_inventory.pyとtests/のみ。変更ファイルはこの 2 ファイルに収まっている。CLAUDE.md/AGENTS.mdへの read plan 例外追記は本 Issue では対象外(owner 判断により script-only に固定)。