Model stages: outcome-first output shape and one in-session outcome repair

The prompt now says output.md must start with # outcome and the outcome
word alone on the next line, then # handoff, then detail. Runs 241/243
followed the old "start with # handoff" wording and dropped the outcome.

When a completed turn lacks a valid outcome, the OpenCode/agent and Pi
clients send one short follow-up in the same session asking only for the
outcome line. An outcome-only reply goes at the top of the original report;
a still-invalid reply fails with the same validation error as before. The
follow-up's tokens accrue to the session usage. No outcome is inferred.

Missing tools/evidence now name blocked when declared, else error. The
parser tolerates a trailing period on the outcome word.
This commit is contained in:
2026-11-04 17:20:58 +00:00
parent b5927505cc
commit 88dfc051e5
13 changed files with 457 additions and 16 deletions
+58 -1
View File
@@ -64,7 +64,8 @@ func ParseOutput(markdown string, allowedOutcomes []string) (Outcome string, Bod
if value == len(lines) {
return "", "", fmt.Errorf("%w: outcome heading has no value", ErrMissingOutcome)
}
word := strings.TrimSpace(lines[value].text)
// The value line is the word alone; a trailing period is tolerated.
word := strings.TrimSpace(strings.TrimSuffix(strings.TrimSpace(lines[value].text), "."))
canonical, ok := allowedOutcome(word, allowedOutcomes)
if !ok {
return "", "", fmt.Errorf("%w: %q", ErrOutcomeNotAllowed, word)
@@ -89,6 +90,62 @@ func allowedOutcome(word string, outcomes []string) (string, bool) {
return "", false
}
// WithOutcome returns markdown with a leading "# outcome" section holding the
// given word, replacing any outcome headings (and their value lines) already in
// it. The word is never derived from the text: callers pass an outcome the
// model stated explicitly, such as its reply to the outcome repair follow-up.
// Every other byte of the original document is kept in order.
func WithOutcome(markdown, outcome string) string {
lines := markdownLines(markdown)
drop := make(map[int]bool)
var fence fenceState
for i := 0; i < len(lines); i++ {
text := lines[i].text
if fence.open() {
if fence.closes(text) {
fence = fenceState{}
}
continue
}
if marker, ok := openingFence(text); ok {
fence = marker
continue
}
if !isOutcomeHeading(text) {
continue
}
drop[i] = true
value := i + 1
for value < len(lines) && strings.TrimSpace(lines[value].text) == "" {
value++
}
if value == len(lines) {
continue
}
_, _, heading := atxHeading(lines[value].text)
_, fenced := openingFence(lines[value].text)
if !heading && !fenced {
drop[value] = true
i = value
}
}
var b strings.Builder
b.WriteString("# outcome\n")
b.WriteString(outcome)
b.WriteString("\n\n")
for i, line := range lines {
if drop[i] {
continue
}
start := 0
if i > 0 {
start = lines[i-1].next
}
b.WriteString(markdown[start:line.next])
}
return b.String()
}
type markdownLine struct {
text string
next int