feat: live guardrail for restated figures (opencode plugin) #15

Merged
david merged 1 commits from feat/claims-plugin into main 2026-11-05 02:50:51 +00:00
Owner

Closes #14. Follow-up to #13, which audits completed sessions.

opencode.db only holds messages once they are persisted, so the audit cannot see the session in progress — which is precisely when a figure gets restated. The context hook runs before every request is dispatched, including tool-driven continuations, with the assembled messages.

Design

context hook ──▶ split at last user message ──▶ {prose, outputs, prior_prose}
                                                        │
                                              knox claims check (JSON)
                                                        │
                                        stale? ──▶ append system part

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 said 6,884 lines, the units disagree, so the claim came out unsupported and the plugin stayed silent on the incident it was built for.

Measuring against what the session already asserted fixes that:

Case Verdict
6,884 lines repeated from an earlier turn, no fresh evidence stale → warn
6,884 lines asserted for the first time unsupported → silent
6884 lines with a tool printing 6884 lines this turn sourced → silent

Failure 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

{ "plugins": ["/home/david/assistant/knox/plugins/claims"] }

Takes effect on opencode service restart. KNOX_BIN overrides the binary path; the default prefers the checkout and falls back to knox on PATH.

Verification

  • go vet ./..., go test ./... green (claims tests cover all three verdicts)
  • plugin typechecked with tsc --strict against a shim for @opencode/plugin
  • knox claims check exercised end-to-end with the plugin's exact payload shape

Not 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.

Closes #14. Follow-up to #13, which audits *completed* sessions. `opencode.db` only holds messages once they are persisted, so the audit cannot see the session in progress — which is precisely when a figure gets restated. The `context` hook runs before every request is dispatched, including tool-driven continuations, with the assembled messages. ## Design ``` context hook ──▶ split at last user message ──▶ {prose, outputs, prior_prose} │ knox claims check (JSON) │ stale? ──▶ append system part ``` 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 said `6,884 lines`, the units disagree, so the claim came out `unsupported` and the plugin stayed **silent on the incident it was built for**. Measuring against what the session already asserted fixes that: | Case | Verdict | |---|---| | `6,884 lines` repeated from an earlier turn, no fresh evidence | **stale** → warn | | `6,884 lines` asserted for the first time | unsupported → silent | | `6884 lines` with a tool printing `6884 lines` this turn | sourced → silent | ## Failure 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 ```jsonc { "plugins": ["/home/david/assistant/knox/plugins/claims"] } ``` Takes effect on `opencode service restart`. `KNOX_BIN` overrides the binary path; the default prefers the checkout and falls back to `knox` on `PATH`. ## Verification - `go vet ./...`, `go test ./...` green (claims tests cover all three verdicts) - plugin typechecked with `tsc --strict` against a shim for `@opencode/plugin` - `knox claims check` exercised end-to-end with the plugin's exact payload shape **Not 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.
david added 1 commit 2026-11-05 02:50:29 +00:00
feat: opencode plugin that warns on restated figures (#14)
build / test (push) Has been cancelled
build / image (push) Has been cancelled
12fe148cd9
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.
david merged commit 4a3e671aa1 into main 2026-11-05 02:50:51 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: david/knox#15