Repository navigation
fix(guardrails): plugin を v1 形で export し、loader を通ることを検査する - #329
Merged
Merged
Conversation
#328 は gate-fires.test.ts をもって発火検証済みと読める書き方をしたが、 実 opencode run では guardrail.ts / team.ts とも loader で落ちており、 chat.params の block は全期間で 0 件だった。gate() は本番で一度も呼ばれていない。 根因は export の形。default が関数だと readV1Plugin (detect) に v1 と認識されず legacy 経路に落ち、module の全 named export を server(input, options) で呼ぶ。 ensureLocalOpencodeIgnored(worktree: string) に input オブジェクトが渡って path.join で落ち、team.ts は非関数の const export で "not a function"。 変更: guardrail.ts / team.ts default を { id, server } の v1 形へ(判定内容は不変。 guardrail.ts の非コメント差分は rename 1 行 + default 1 行) plugin-loads.test.ts 新規。loader の判定を複製し v1 認識 / legacy 再現 / chat.params 到達 / ソースとの pair を検査 gate-fires.test.ts ヘッダを「loader を迂回した単体検査」と明記 実測: 修正前 (dev) に新テストをかけると 5 pass / 4 fail、修正後 9 pass / 0 fail。 実 CLI で failed to load plugin が 2 -> 0。harness 45 pass、lint 5131/1 (不変)、typecheck 30/30。 未解決: 実在 preview モデルでの実セッションは init 後にストールし session.created に 到達しないため、chat.params の実発火はまだ観測できていない (別の起動時問題)。 Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01Et1J3J3Zi3V6zEzAod8QPD
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
PR #329 の 93f28f4 で guardrail.ts / team.ts の default export を v1 形 `{ id, server }` に変えたが、packages/opencode/test/plugin/ の 6 ファイルが default を関数として呼んでいたため typecheck が TS2349 で落ちた。 修正前の grep が packages/guardrails しか見ておらず、import 元を取り逃した。 - guardrail.ts / team.ts: `export { guardrailServer as guardrail }` / `export { teamServer as team }` を追加(named export で旧 API を維持) - 6 テストの import を `import { guardrail }` / `import { team }` 形へ 実測: bun turbo typecheck --force 30/30(cache 0) bun run lint 5131 warnings / 1 error(変化なし) bun test profile/plugins 45 pass 0 fail bun test test/plugin/{6 files} 96 pass 0 fail Agent-Lane: claude-code Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01Et1J3J3Zi3V6zEzAod8QPD
This was referenced Sep 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
何が壊れていたか — guardrail は実 CLI で一度もロードされていなかった
#328はgate-fires.test.ts(6 pass)をもって発火検証済みと読める書き方をした。過大だった。Codex による実環境貫通と監督の独立再現で、実
opencode runはを出し、
.opencode/guardrails/events.jsonlのchat.paramsblock は全期間で 0 件、state.jsonはlast_block='' / llm_call_count=0だった。gate()は本番で一度も呼ばれていない。gate-fires.test.tsはcreateContextを直接 import してgate()を呼ぶので loader を通らず、この状態でも緑だった。テストが緑のまま本番の強制経路が死んでいた。
根因 — export の形
loader(
packages/opencode/src/plugin/index.tsapplyPlugin)はreadV1Plugin(mod, spec, "server", "detect")で default が object かつ id/server/tui を持つかを見る。持たなければ legacy 経路
getLegacyPluginsに落ち、module の全 export を plugin と見なしてserver(input, options)で呼ぶ。export default async function guardrail(...)は関数なので v1 と認識されず legacy に落ち、named export の
ensureLocalOpencodeIgnored(worktree: string)にinputオブジェクトが渡ってpath.join(object, ...)で落ちた。team.tsは非関数の const を named export しているのでPlugin export is not a function。workspace:*の依存解決失敗(2026-05-20 から)も並行して出るが、致命なのは export 形である(依存解決は WARN で続行するが、load 失敗は hooks が登録されない)。
変更(判定内容は 1 バイトも変えていない)
guardrail.tsexport default async function guardrail→async function guardrailServer+export default { id: "aidd-guardrail", server: guardrailServer }team.tsaidd-team)plugin-loads.test.tschat.params到達性 / ソースとの pair を検査gate-fires.test.tsguardrail.tsの非コメント差分は rename 1 行 + default 1 行のみ(git diff --cachedで確認)。なぜ loader を直接 import せず判定を複製したか
shared.ts/index.tsは@/util/*と@opencode-ai/core/npmに依存し、guardrails の bun test から解決できない。複製だけだと「テストは緑だが loader は変わっていた」を通すので、
ソースの決定的な 2 条件を文字列で照合する pair 検査を付けた。ずれたら落ちる。
実測
反証(修正前の code に新テストをかける)
落ちた 4 本は v1 形に依存する assertion だけで、legacy 再現(F2)と pair は両方で通る = 変異は局所的。
実 CLI(修正後)
スイート / lint / typecheck
解けていないもの(ふりをしない)
chat.paramsが実セッションで発火することは、まだ観測できていない。実在する preview モデル(
deepseek/deepseek-v4-flash-vision-exp、whitelist 内かつ preview 正規表現に一致)で実 CLI を起動すると、
initログの直後でストールしsession.createdに到達しない(90s / 300s とも rc=124、events.jsonl 増分 0)。plugin ロードとは別の起動時問題(
models.devの fetch 失敗が先行して出ている)。gate は
session.createdの後で動くので、この経路では生死を判定できない。本 PR が保証するのは **「plugin が loader を通り、
chat.paramsを含む hooks が返される」**まで。「実セッションで gate が throw する」は次の観測課題として残す。
監督の誤りの記録
#328本文の「@opencode-ai/pluginは version bump のみ・API 変更なし」は package.json の版数差分だけを見て挙動を断定した表面形一致だった
gate-fires.test.tsの当初ヘッダ「The guardrail must actually BLOCK」は発火検証と読めたが、loader を迂回しており本番経路を何も保証していなかった
H5-guard: yes
H5-NEGATIVE:
dev(修正前)にplugin-loads.test.tsをコピーして実行 → 5 pass / 4 fail(F1 ×2・F3 ×2 が落ち、legacy 再現 F2 と PAIR は通る = 変異は局所的)。修正後 9 pass / 0 fail。加えて実 CLI でfailed to load pluginが 2 → 0。H5-LEDGER: 本 PR は export の形だけを変え、guardrail の発火経路(
chat.params→ctx.mark→.opencode/guardrails/events.jsonl/state.json)は不変。plugin がロードされなかった期間は台帳にchat.paramsが 0 件だったこと自体が「配線はあるが到達していなかった」証跡である。H5-RETIRE:
plugin-loads.test.tsの PAIR 節が参照するreadV1Plugin/getLegacyPluginsの文字列が upstream で書き換えられたら PAIR が落ちるので、その時点で複製を追随させるか loader を直接 import できる形へ移す。実セッションでのchat.params発火が 1 度観測されたら、本 PR の「未観測」節を閉じる。H5-SUBTRACTION: N/A
H5-PAIR:
packages/opencode/src/plugin/shared.tsのreadV1Plugindetect 条件 ↔plugin-loads.test.tsの複製; mutation=devの関数 default を持つ module に対して v1 判定が undefined を返し legacy 経路で throw する(F2 で再現)。H5-E2E: bun run local:check-offline && opencode run --print-logs -m "zai/glm-4.7-preview" "echo hi"
H5-E2E-OUT:
45 pass, 0 fail/ rc=0 / 実 CLI のfailed to load plugin0 件(修正前 2 件)。実セッションでの gate throw は未観測(init後ストール、上記)。Evidence:
bun test profile/plugins/plugin-loads.test.ts(修正前 worktree 5/4、修正後 9/0)/opencode run --print-logs ...(load error 2→0)/bun run local:check-offline/bun run lint/bun turbo typecheck| 45 pass、lint 5131/1、typecheck 30/30、実 gate はinit後ストールで未観測 | 2026-09-04 JST🤖 Generated with Claude Code