4a3e671aa1
feat: live guardrail for restated figures (opencode plugin) (#15) Co-authored-by: David Gwilliam <dhgwilliam@gmail.com> Co-committed-by: David Gwilliam <dhgwilliam@gmail.com>
59 lines
1.9 KiB
Markdown
59 lines
1.9 KiB
Markdown
# knox.claims — OpenCode plugin
|
|
|
|
Warns when a request restates a figure that an earlier turn measured but the
|
|
current turn did not.
|
|
|
|
## Why
|
|
|
|
The failure mode is drift, not ignorance: a number is derived once — sometimes
|
|
against the wrong reference — then quoted in later turns, and each restatement
|
|
makes it feel more established. In this repo that produced "6,884 lines behind
|
|
main" from a diff measured against `bb852fa`, repeated across five turns, which
|
|
drove a branch decision that had to be undone.
|
|
|
|
## How it works
|
|
|
|
The `context` session hook runs immediately before a request is dispatched,
|
|
including tool-driven continuations. It gets the assembled messages, splits them
|
|
at the last user message, and passes:
|
|
|
|
```json
|
|
{ "prose": "<last assistant text>", "outputs": ["<this turn's tool output>"], "earlier": ["<previous turns'>"] }
|
|
```
|
|
|
|
to `knox claims check`, which replies with each numeric claim tagged
|
|
`sourced` / `stale` / `unsupported`. Only `stale` claims produce a warning, which
|
|
is appended as a system part for that request.
|
|
|
|
All classification lives in the Go binary, so the plugin cannot drift from the
|
|
tested implementation.
|
|
|
|
## Enable
|
|
|
|
```jsonc
|
|
// ~/.config/opencode/opencode.json
|
|
{
|
|
"plugins": ["/home/david/assistant/knox/plugins/claims"]
|
|
}
|
|
```
|
|
|
|
Takes effect on the next `opencode service restart`.
|
|
|
|
## Configure
|
|
|
|
| Env | Default | Meaning |
|
|
|---|---|---|
|
|
| `KNOX_BIN` | `knox` (on `PATH`) | Binary to invoke. Set an absolute path when the daemon's PATH does not include it. |
|
|
|
|
## Failure behaviour
|
|
|
|
Every failure path is swallowed: a missing binary, a timeout (2 s), or malformed
|
|
JSON results in no warning and an unmodified request. A guardrail must never
|
|
break the thing it guards.
|
|
|
|
## Not implemented
|
|
|
|
- It cannot *force* a re-check; it appears in the system prompt as guidance.
|
|
- It only sees numeric claims in prose, not comparatives ("the trees are
|
|
identical") — those need a different signal and would be far noisier.
|