Add line-oriented result format for model and agent stages
Introduce a short, markdown-ish result format whose first non-empty line is
the declared outcome and whose "# output" section carries the routing data,
so stage output stops carrying multi-kilobyte prose inside a JSON envelope.
- New internal/stage/line_result.go: resultFormat() gates legacy JSON ('{'
first) vs the new line format; decodeLineResult() parses outcome-from-first
line, requires a JSON-object "# output" section, stores extra sections
verbatim under normalised keys, and records a reserved result_parse status
(parsed/partial/failed). Failures return a salvage Result plus
ErrInvalidModelResult, and never route an undeclared outcome.
- internal/stage/model.go: write the raw response to raw-output.md (0600,
best-effort) before parsing, and route the line format through
decodeLineResult while leaving the JSON path (stageResultText ->
decodeModelResult -> repairModelResult) unchanged.
- internal/stage/agent.go: agentResultText returns line-format text verbatim
so the "# output" body is not stripped by the JSON-object extractor.
- internal/server/runner.go: merge a non-empty salvage Result into the error
envelope under "salvage" on failure (a no-op for the legacy JSON path).
- internal/stage/line_result_test.go: raw-text fixtures covering happy path,
missing/undeclared outcome, missing "# output", best-effort extras,
adversarial prose, legacy JSON unchanged, >=64KB responses, and
raw-output.md written before parsing.
This commit is contained in:
@@ -276,6 +276,11 @@ func completedAgentResult(data []byte) (string, error) {
|
||||
// Agents may emit a short explanation before their final result. Preserve the
|
||||
// full response in the audit, but pass only a complete final JSON object to the
|
||||
// same strict stage validator. Never infer outcomes from prose or tool output.
|
||||
// The line-oriented format is returned verbatim so its '# output' body is not
|
||||
// stripped by the JSON-object extractor.
|
||||
func agentResultText(text string) string {
|
||||
if resultFormat(text) == "line" {
|
||||
return text
|
||||
}
|
||||
return stageResultText(text)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user