feat: opencode plugin that warns on restated figures (#14)
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.
This commit is contained in:
@@ -119,3 +119,39 @@ func Unsourced(findings []Finding) []Finding {
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Scored is a finding with the verdict for a specific evidence window.
|
||||
type Scored struct {
|
||||
Finding
|
||||
Status Status
|
||||
}
|
||||
|
||||
// Classify tags findings against this turn's tool output and the claims this
|
||||
// session already made in earlier turns. It is the single place that decides
|
||||
// sourced/stale/unsupported, so the CLI and the live plugin cannot disagree.
|
||||
//
|
||||
// Staleness is measured against *earlier prose*, not earlier tool output, and
|
||||
// that distinction matters: a tool printed "6884 deletions" while the prose
|
||||
// said "6,884 lines", so matching tool output by number+unit called the real
|
||||
// incident "unsupported" — silent. Comparing prose to prose catches the actual
|
||||
// failure, which is restating a figure the session already asserted.
|
||||
func Classify(findings []Finding, turnOutputs []string, priorProse string) []Scored {
|
||||
prior := make(map[claimKey]struct{})
|
||||
for _, c := range Extract(priorProse) {
|
||||
prior[claimKey{c.Value, normUnit(c.Unit)}] = struct{}{}
|
||||
}
|
||||
|
||||
out := make([]Scored, 0, len(findings))
|
||||
for _, orig := range findings {
|
||||
f := Mark([]Finding{orig}, turnOutputs)[0]
|
||||
status := Sourced
|
||||
if !f.Sourced {
|
||||
status = Unsupported
|
||||
if _, repeated := prior[claimKey{f.Value, normUnit(f.Unit)}]; repeated {
|
||||
status = Stale
|
||||
}
|
||||
}
|
||||
out = append(out, Scored{Finding: f, Status: status})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user