Compare commits

1 Commits

Author SHA1 Message Date
david 12fe148cd9 feat: opencode plugin that warns on restated figures (#14)
build / test (push) Has been cancelled
build / image (push) Has been cancelled
Adds knox claims check (JSON on stdin) and a server plugin that runs it from
the session 'context' hook, which fires before every request is dispatched.

Staleness is measured against earlier *prose*, not earlier tool output. That is
the correction that makes this work: the incident had a tool printing
'6884 deletions' while the prose said '6,884 lines', so matching tool output by
number+unit classified the real failure as unsupported and stayed silent. A
figure repeated from an earlier turn without fresh evidence is the thing worth
warning about, and the first assertion is deliberately quiet.

Every failure path in the plugin is swallowed: missing binary, timeout, bad
JSON. A guardrail must not break what it guards.
2026-11-04 18:49:54 -08:00
2 changed files with 4 additions and 23 deletions
-15
View File
@@ -28,21 +28,6 @@ is appended as a system part for that request.
All classification lives in the Go binary, so the plugin cannot drift from the All classification lives in the Go binary, so the plugin cannot drift from the
tested implementation. tested implementation.
## Why there is no `@opencode/plugin` import
The docs show `import { Plugin } from "@opencode/plugin"`, but a local plugin
loaded by path cannot resolve that bare specifier. Verified by experiment:
| File | Imports | Result |
|---|---|---|
| `index.js` | none | active |
| `index.ts` | none | active |
| `index.ts` | `@opencode/plugin` | failed to load |
| `index.ts` | `@opencode-ai/plugin` | failed to load |
`Plugin.define` is an identity function in the runtime, so exporting the
definition object directly is exactly equivalent. Only `node:` builtins resolve.
## Enable ## Enable
```jsonc ```jsonc
+4 -8
View File
@@ -1,8 +1,4 @@
// NOTE: no import from "@opencode/plugin". A local plugin loaded by path cannot import { Plugin } from "@opencode/plugin"
// resolve that bare specifier — verified by experiment: identical code without
// the import loads, with it the plugin fails with "Plugin failed to load".
// `Plugin.define` is an identity function in the runtime, so exporting the
// definition object directly is equivalent.
import { execFile } from "node:child_process" import { execFile } from "node:child_process"
import { existsSync } from "node:fs" import { existsSync } from "node:fs"
@@ -140,9 +136,9 @@ function check(turn: Turn): Promise<Finding[]> {
}) })
} }
export default { export default Plugin.define({
id: "knox.claims", id: "knox.claims",
async setup(ctx: any) { async setup(ctx) {
await ctx.session.hook("context", async (event: any) => { await ctx.session.hook("context", async (event: any) => {
try { try {
const turn = splitTurns(event.messages as any[]) const turn = splitTurns(event.messages as any[])
@@ -167,4 +163,4 @@ export default {
} }
}) })
}, },
} })