feat: live guardrail for restated figures (opencode plugin) (#15)
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>
This commit was merged in pull request #15.
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
|
||||
}
|
||||
|
||||
@@ -205,10 +205,10 @@ type LintRun struct {
|
||||
// quoted from an earlier turn count as unsourced.
|
||||
func Lint(s *Session) []LintRun {
|
||||
var out []LintRun
|
||||
var turnOutputs, earlierOutputs []string
|
||||
var turnOutputs []string
|
||||
var priorProse strings.Builder
|
||||
for _, m := range s.Messages {
|
||||
if m.Role == "user" {
|
||||
earlierOutputs = append(earlierOutputs, turnOutputs...)
|
||||
turnOutputs = nil
|
||||
continue
|
||||
}
|
||||
@@ -217,16 +217,11 @@ func Lint(s *Session) []LintRun {
|
||||
continue
|
||||
}
|
||||
prose := strings.Join(m.Text, "\n")
|
||||
for _, f := range Mark(Extract(prose), turnOutputs) {
|
||||
run := LintRun{MessageID: m.ID, Seq: m.Seq, Finding: f, Status: Sourced}
|
||||
if !f.Sourced {
|
||||
run.Status = Unsupported
|
||||
if len(Mark([]Finding{f}, earlierOutputs)) == 1 && Mark([]Finding{f}, earlierOutputs)[0].Sourced {
|
||||
run.Status = Stale
|
||||
}
|
||||
}
|
||||
out = append(out, run)
|
||||
for _, sc := range Classify(Extract(prose), turnOutputs, priorProse.String()) {
|
||||
out = append(out, LintRun{MessageID: m.ID, Seq: m.Seq, Finding: sc.Finding, Status: sc.Status})
|
||||
}
|
||||
priorProse.WriteString(prose)
|
||||
priorProse.WriteString("\n")
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user