Add stage execution limits and result-first workflow views
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package protocol
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"sort"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
// OutputPreview quotes retained output, never infers accomplishments from a
|
||||
// successful process or invents a schema for technology-neutral workflows.
|
||||
func OutputPreview(output map[string]any) string {
|
||||
keys := []string{"summary", "result", "report", "message", "accomplished", "artifacts", "evidence", "reason", "error"}
|
||||
seen := map[string]bool{}
|
||||
remaining := make([]string, 0, len(output))
|
||||
for key := range output {
|
||||
remaining = append(remaining, key)
|
||||
}
|
||||
sort.Strings(remaining)
|
||||
keys = append(keys, remaining...)
|
||||
for _, key := range keys {
|
||||
if seen[key] || key == "input" {
|
||||
continue
|
||||
}
|
||||
seen[key] = true
|
||||
value, exists := output[key]
|
||||
if !exists || value == nil {
|
||||
continue
|
||||
}
|
||||
text, ok := value.(string)
|
||||
if !ok {
|
||||
encoded, err := json.Marshal(value)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
text = string(encoded)
|
||||
}
|
||||
text = strings.Map(func(r rune) rune {
|
||||
if unicode.IsControl(r) {
|
||||
return ' '
|
||||
}
|
||||
return r
|
||||
}, text)
|
||||
text = strings.Join(strings.Fields(text), " ")
|
||||
if text == "" || text == "[]" || text == "{}" {
|
||||
continue
|
||||
}
|
||||
if key != "summary" && key != "result" && key != "report" && key != "message" {
|
||||
text = key + ": " + text
|
||||
}
|
||||
runes := []rune(text)
|
||||
if len(runes) > 280 {
|
||||
text = string(runes[:279]) + "…"
|
||||
}
|
||||
return text
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package protocol
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOutputPreviewUsesRetainedValuesWithoutAssumingSchema(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
output map[string]any
|
||||
want string
|
||||
}{
|
||||
{map[string]any{"summary": "Fixed layout\nand added regression checks", "evidence": "details"}, "Fixed layout and added regression checks"},
|
||||
{map[string]any{"artifacts": []string{"report.md"}}, `artifacts: ["report.md"]`},
|
||||
{map[string]any{"z": true, "a": json.Number("9007199254740993")}, "a: 9007199254740993"},
|
||||
{map[string]any{"input": map[string]any{"prompt": "private task"}}, ""},
|
||||
{nil, ""},
|
||||
} {
|
||||
if got := OutputPreview(test.output); got != test.want {
|
||||
t.Fatal(got, test.want)
|
||||
}
|
||||
}
|
||||
preview := OutputPreview(map[string]any{"summary": strings.Repeat("宽", 500)})
|
||||
if len([]rune(preview)) != 280 || !strings.HasSuffix(preview, "…") {
|
||||
t.Fatal("preview is not bounded by characters")
|
||||
}
|
||||
}
|
||||
+14
-12
@@ -23,18 +23,20 @@ type SessionEvidence struct {
|
||||
}
|
||||
|
||||
type RunSummary struct {
|
||||
ID int64 `json:"id"`
|
||||
PipelineID int64 `json:"pipeline_id"`
|
||||
Name string `json:"name"`
|
||||
Version int `json:"version"`
|
||||
ContentHash string `json:"content_hash"`
|
||||
Status string `json:"status"`
|
||||
Executing bool `json:"executing"`
|
||||
Outcome string `json:"outcome"`
|
||||
CurrentStage string `json:"current_stage"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
FinishedAt string `json:"finished_at"`
|
||||
Diagnostic string `json:"diagnostic"`
|
||||
ID int64 `json:"id"`
|
||||
PipelineID int64 `json:"pipeline_id"`
|
||||
Name string `json:"name"`
|
||||
Version int `json:"version"`
|
||||
ContentHash string `json:"content_hash"`
|
||||
Status string `json:"status"`
|
||||
Executing bool `json:"executing"`
|
||||
Outcome string `json:"outcome"`
|
||||
CurrentStage string `json:"current_stage"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
FinishedAt string `json:"finished_at"`
|
||||
Diagnostic string `json:"diagnostic"`
|
||||
ResultPreview string `json:"result_preview,omitempty"`
|
||||
CompletedSteps int `json:"completed_steps"`
|
||||
}
|
||||
|
||||
type RunStep struct {
|
||||
|
||||
Reference in New Issue
Block a user