feat: live guardrail for restated figures (opencode plugin) #15
Reference in New Issue
Block a user
Delete Branch "feat/claims-plugin"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #14. Follow-up to #13, which audits completed sessions.
opencode.dbonly holds messages once they are persisted, so the audit cannot see the session in progress — which is precisely when a figure gets restated. Thecontexthook runs before every request is dispatched, including tool-driven continuations, with the assembled messages.Design
The plugin is deliberately thin: it maps messages, spawns the binary, and injects a warning. All classification stays in Go, where it is tested, so the plugin cannot drift from the CLI.
The correction that made it work
Staleness compares prose to prose, not prose to tool output.
Matching by number+unit against tool output gave the wrong answer on the motivating case: the tool printed
6884 deletions(-), the prose said6,884 lines, the units disagree, so the claim came outunsupportedand the plugin stayed silent on the incident it was built for.Measuring against what the session already asserted fixes that:
6,884 linesrepeated from an earlier turn, no fresh evidence6,884 linesasserted for the first time6884 lineswith a tool printing6884 linesthis turnFailure behaviour
Every path is swallowed — missing binary, 2 s timeout, malformed JSON — and the request proceeds unmodified. A guardrail must never break what it guards.
Enable
Takes effect on
opencode service restart.KNOX_BINoverrides the binary path; the default prefers the checkout and falls back toknoxonPATH.Verification
go vet ./...,go test ./...green (claims tests cover all three verdicts)tsc --strictagainst a shim for@opencode/pluginknox claims checkexercised end-to-end with the plugin's exact payload shapeNot verified: the plugin running inside the server. Enabling it requires restarting the service, which would terminate the session that built it — first restart after merge is the real test.