背景
ADR specs/ai-guardrails-anti-patterns.md(PR #283)で、5 リポジトリ横断調査から抽象化した 8 つの実装アンチパターンを OpenCode の仕組みで止める。epic #1 の「plugin- and command-based guardrails」workstream の具体化。
ゴール
packages/guardrails/profile/ に以下のガードを実装し、「ドキュメントではなく仕組み」で 8 パターンを防ぐ。全ガードは反証付き(無効化すると落ちる)で実装すること。
実装内容(Phase 1: 即効)
1. Plugin: 変更の影響範囲ガード(パターン A)
- ファイル:
packages/guardrails/profile/plugins/removal-guard.ts
tool.execute.before フック:
git rm / git add -A(削除含む)を検知 → 削除対象ファイルを抽出
- リポジトリ全体で逆被参照 grep → 参照があれば警告ログ + エージェントに確認を強制
- 反証: ガードを無効化すると、削除時に参照が検出されないことをテストで示す
2. Permission: 並列実行の権限整備(パターン B)
- ファイル:
packages/guardrails/profile/opencode.json の permission
- 読み取り系 git を allow:
git worktree list / git merge-base * / git status* / git log*
- 破壊系を ask/deny:
git worktree add *(ask)/ git branch -D *(ask)/ git push --force*(deny)
- 反証: subagent が
git worktree list を実行でき、git push --force を実行できないことをテストで示す
3. Plugin: セッション開始時の衛生警告(パターン E)
- ファイル:
packages/guardrails/profile/plugins/hygiene-warning.ts
event フックでセッション開始時に worktree 数・マージ済み放置ブランチ数をカウント
- 閾値(worktree > 8 / 放置ブランチ > 10)超えで警告
- 反証: 閾値以下のリポジトリでは警告が出ないことをテストで示す
4. Command: /plan-light(パターン C / G)
- ファイル:
packages/guardrails/profile/commands/plan-light.md
- 実装前に「最小の検証パス」(fake テスト → CI → PR)を 1 行で宣言させる
- 重厚なパイプライン(複数環境・重層レビュー)を提案したら「まず最小パスで」と誘導
- 反証: 重厚な計画を提示したときに /plan-light が最小パスに誘導することをテストで示す
5. Command: /env-check(パターン D)
- ファイル:
packages/guardrails/profile/commands/env-check.md
- 新環境を作る前に「既存環境(dev 等)で足りるか」を確認させる
- 新環境構築は最後の手段であることを明示
- 反証: 既存で足りるケースで新環境構築をブロックすることをテストで示す
6. Command: /repo-hygiene(パターン E)
- ファイル:
packages/guardrails/profile/commands/repo-hygiene.md
- 放置ブランチ/worktree/マージ済み残骸を列挙し、削除候補をドライラン提示
- 実際の削除は実行せず、エージェントの判断を求める
7. Skill: 4 本(パターン F / G / H / A)
packages/guardrails/profile/skills/falsifiable-change/SKILL.md(F): 修正は「外すと落ちる」を実測してから報告
packages/guardrails/profile/skills/lean-pipeline/SKILL.md(C / G): 最小検証パスをデフォルトに
packages/guardrails/profile/skills/self-check/SKILL.md(H): 外部エージェント非依存の客観性証明(結線テスト)
packages/guardrails/profile/skills/impact-analysis/SKILL.md(A): 変更前に逆被参照を列挙
受入条件
参照
背景
ADR
specs/ai-guardrails-anti-patterns.md(PR #283)で、5 リポジトリ横断調査から抽象化した 8 つの実装アンチパターンを OpenCode の仕組みで止める。epic #1 の「plugin- and command-based guardrails」workstream の具体化。ゴール
packages/guardrails/profile/に以下のガードを実装し、「ドキュメントではなく仕組み」で 8 パターンを防ぐ。全ガードは反証付き(無効化すると落ちる)で実装すること。実装内容(Phase 1: 即効)
1. Plugin: 変更の影響範囲ガード(パターン A)
packages/guardrails/profile/plugins/removal-guard.tstool.execute.beforeフック:git rm/git add -A(削除含む)を検知 → 削除対象ファイルを抽出2. Permission: 並列実行の権限整備(パターン B)
packages/guardrails/profile/opencode.jsonのpermissiongit worktree list/git merge-base */git status*/git log*git worktree add *(ask)/git branch -D *(ask)/git push --force*(deny)git worktree listを実行でき、git push --forceを実行できないことをテストで示す3. Plugin: セッション開始時の衛生警告(パターン E)
packages/guardrails/profile/plugins/hygiene-warning.tseventフックでセッション開始時に worktree 数・マージ済み放置ブランチ数をカウント4. Command:
/plan-light(パターン C / G)packages/guardrails/profile/commands/plan-light.md5. Command:
/env-check(パターン D)packages/guardrails/profile/commands/env-check.md6. Command:
/repo-hygiene(パターン E)packages/guardrails/profile/commands/repo-hygiene.md7. Skill: 4 本(パターン F / G / H / A)
packages/guardrails/profile/skills/falsifiable-change/SKILL.md(F): 修正は「外すと落ちる」を実測してから報告packages/guardrails/profile/skills/lean-pipeline/SKILL.md(C / G): 最小検証パスをデフォルトにpackages/guardrails/profile/skills/self-check/SKILL.md(H): 外部エージェント非依存の客観性証明(結線テスト)packages/guardrails/profile/skills/impact-analysis/SKILL.md(A): 変更前に逆被参照を列挙受入条件
packages/guardrails/profile/に存在するbun run local:check等)が green参照
specs/ai-guardrails-anti-patterns.md(PR docs(specs): guardrails ADR — agent-spanning anti-patterns as OpenCode mechanism #283)provider.anthropic.modelsanomalyco/opencode#1750(パターン A/F)/ Feature request: support claude opus 4 and 4.1 agent in github copilot anomalyco/opencode#1753(経路B ハンドオーバー)