stage turns: replace JSON results with file-based markdown turns
Each model visit now gets <run>/stages/<seq>-<stage>/ with input.md, memory.md, output.md, private/ and a shared run-level public/. The model reads the two input files, follows the stage's instructions verbatim and returns complete markdown; only the # outcome section is parsed. - add internal/turn layout, render and output parsing - write input.md/memory.md before a visit and output.md from the final message; inventory all turn files as stage artifacts - accumulate completed turns and system-written public file additions in memory, including across retries and resume - remove the JSON envelope, strict field validation, line format and the repair ladder for model stages - republish pipeline authoring prompts and docs in the new style Checks: go build ./..., go vet ./..., go test -count=1 ./..., gofmt -l .
This commit is contained in:
@@ -20,8 +20,10 @@ import (
|
||||
|
||||
func TestRetryInputOverrideRejectsReservedAndOversizedValues(t *testing.T) {
|
||||
base := map[string]any{"handoff": "retained"}
|
||||
if _, err := retryInputOverride(base, map[string]any{"workspace": "/escape"}); err == nil {
|
||||
t.Fatal("reserved retry input was accepted")
|
||||
for _, reserved := range []string{"workspace", "server_changed_files"} {
|
||||
if _, err := retryInputOverride(base, map[string]any{reserved: "/escape"}); err == nil {
|
||||
t.Fatalf("reserved retry input %s was accepted", reserved)
|
||||
}
|
||||
}
|
||||
if _, err := retryInputOverride(base, map[string]any{"large": strings.Repeat("x", maxRetryInputBytes)}); err == nil {
|
||||
t.Fatal("oversized retry input was accepted")
|
||||
@@ -69,7 +71,7 @@ case "$3" in
|
||||
/api/session/ses_fresh_1/interrupt) echo '{}' ;;
|
||||
/api/session/ses_fresh_1) echo '{"data":{"id":"ses_fresh_1"}}' ;;
|
||||
/api/session/ses_fresh_1/message*) echo '{"data":[{"error":{"message":"provider rejected generation","token":"private-token"}}]}' ;;
|
||||
/api/session/ses_fresh_2/generate) echo '{"data":{"text":"{\"outcome\":\"success\",\"output\":{\"summary\":\"done\"}}"}}' ;;
|
||||
/api/session/ses_fresh_2/generate) printf '%%s\n' '{"data":{"text":"# outcome\nsuccess\n"}}' ;;
|
||||
*) exit 99 ;;
|
||||
esac
|
||||
`, log, count, count, count)
|
||||
@@ -288,8 +290,7 @@ func TestRetryResumeReusesPrefixHandoffAndReplaysRequestAfterReopen(t *testing.T
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
source := "# stage a\n\n```output\nA\n```\n\n```prompt\nA\n```\n\n```edges\nsuccess -> b\nerror -> #failure\n```\n\n```configs\ntype=model\nprovider=test\nmodel=test\n```\n\n# stage b\n\n```output\nB\n```\n\n```prompt\nB\n```\n\n```edges\nsuccess -> c\nerror -> #failure\n```\n\n```configs\ntype=model\nprovider=test\nmodel=test\n```\n\n# stage c\n\n```output\nC\n```\n\n```prompt\nC\n```\n\n```edges\nsuccess -> #success\nerror -> #failure\n```\n\n```configs\ntype=model\nprovider=test\nmodel=test\n```\n"
|
||||
source = strings.Replace(source, "# stage b\n\n```output", "# stage b\n\n```memory\n{\"task\":\"input.prompt\",\"handoff\":\"a.handoff\"}\n```\n\n```output", 1)
|
||||
source := "# stage a\n\n```prompt\nDo A.\n```\n\n```tools\nread\nglob\ngrep\nshell\n```\n\n```edges\nsuccess -> b\nerror -> #failure\n```\n\n```configs\ntype=model\nprovider=opencode-go\nmodel=deepseek-v4.1-flash\nretries=0\n```\n\n# stage b\n\n```prompt\nDo B.\n```\n\n```tools\nread\nglob\ngrep\nshell\n```\n\n```edges\nsuccess -> c\nerror -> #failure\n```\n\n```configs\ntype=model\nprovider=opencode-go\nmodel=deepseek-v4.1-flash\nretries=0\n```\n\n# stage c\n\n```prompt\nDo C.\n```\n\n```tools\nread\nglob\ngrep\nshell\n```\n\n```edges\nsuccess -> #success\nerror -> #failure\n```\n\n```configs\ntype=model\nprovider=opencode-go\nmodel=deepseek-v4.1-flash\nretries=0\n```\n"
|
||||
if _, err := store.Submit(ctx, "resume", source); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -307,7 +308,7 @@ func TestRetryResumeReusesPrefixHandoffAndReplaysRequestAfterReopen(t *testing.T
|
||||
if input["prompt"] != "task" {
|
||||
t.Errorf("entry received altered input: %#v", input)
|
||||
}
|
||||
return stage.Result{Outcome: "success", Output: stage.Values{"handoff": "from-a"}}, nil
|
||||
return stage.Result{Outcome: "success", Output: stage.Values{"task": "task", "handoff": "from-a"}}, nil
|
||||
case "b":
|
||||
bCalls++
|
||||
if input["handoff"] != "from-a" {
|
||||
@@ -329,6 +330,21 @@ func TestRetryResumeReusesPrefixHandoffAndReplaysRequestAfterReopen(t *testing.T
|
||||
if bCalls == 3 && input["correction"] != "use-new-plan-again" {
|
||||
t.Errorf("transitive selected retry lost input override: %#v", input)
|
||||
}
|
||||
if bCalls >= 2 {
|
||||
// The model reads input.md, not the persisted step input. A retry
|
||||
// correction that lives only in the step row is invisible.
|
||||
data, err := os.ReadFile(def.Turn.Input)
|
||||
if err != nil {
|
||||
t.Fatalf("read retry input.md: %v", err)
|
||||
}
|
||||
want := "use-new-plan"
|
||||
if bCalls == 3 {
|
||||
want = "use-new-plan-again"
|
||||
}
|
||||
if !strings.Contains(string(data), want) {
|
||||
t.Errorf("retry input.md missing override %q:\n%s", want, data)
|
||||
}
|
||||
}
|
||||
if bCalls <= 2 {
|
||||
return stage.Result{}, fmt.Errorf("deliberate failure")
|
||||
}
|
||||
@@ -380,9 +396,6 @@ func TestRetryResumeReusesPrefixHandoffAndReplaysRequestAfterReopen(t *testing.T
|
||||
if transitive.Steps[0].Input["task"] != "corrected-again" || transitive.Steps[0].Input["correction"] != "use-new-plan-again" {
|
||||
t.Fatalf("retry persisted the wrong selected input: %#v", transitive.Steps[0].Input)
|
||||
}
|
||||
if transitive.Steps[0].Control == nil || transitive.Steps[0].Control.Memory["handoff"].Sequence != 1 {
|
||||
t.Fatalf("transitive retry lost prefix memory provenance: %#v", transitive.Steps[0].Control)
|
||||
}
|
||||
if err := store.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -418,10 +431,10 @@ case "$3" in
|
||||
*/wait) echo '{}' ;;
|
||||
*/message*)
|
||||
case "$3" in
|
||||
*/ses_native_2/*) echo '{"data":[{"finish":"stop","content":[{"type":"text","text":"{\\"outcome\\":\\"invalid\\",\\"output\\":{\\"wrong\\":\\"format\\"}}"}]}]}' ;;
|
||||
*/ses_native_2/*) printf '%s\n' '{"data":[{"finish":"stop","content":[{"type":"text","text":"# outcome\ninvalid\n"}]}]}' ;;
|
||||
*/ses_native_3/*) echo '{}' ;;
|
||||
*/ses_native_3/*) echo '{"data":[{"finish":"stop","content":[{"type":"text","text":"{\\"outcome\\":\\"success\\",\\"output\\":{\\"handoff\\":\\"from-b\\"}}"}]}]}' ;;
|
||||
*) echo '{"data":[{"finish":"stop","content":[{"type":"text","text":"{\\"outcome\\":\\"success\\",\\"output\\":{\\"handoff\\":\\"from-a\\",\\"summary\\":\\"done\\"}}"}]}]}' ;;
|
||||
*/ses_native_3/*) printf '%s\n' '{"data":[{"finish":"stop","content":[{"type":"text","text":"# outcome\nsuccess\n\n# Handoff\n\nfrom-b\n"}]}]}' ;;
|
||||
*) printf '%s\n' '{"data":[{"finish":"stop","content":[{"type":"text","text":"# outcome\nsuccess\n\n# Handoff\n\nfrom-a\n"}]}]}' ;;
|
||||
esac ;;
|
||||
*) echo '{}' ;;
|
||||
esac
|
||||
@@ -436,7 +449,6 @@ esac
|
||||
}
|
||||
defer store.Close()
|
||||
source := "# stage a\n\n```output\n{ handoff, summary }\n```\n\n```prompt\nDo A.\n```\n\n```tools\nread\nglob\ngrep\nshell\n```\n\n```edges\nsuccess -> b\nerror -> #failure\n```\n\n```configs\ntype=model\nprovider=opencode-go\nmodel=deepseek-v4.1-flash\nretries=0\n```\n\n# stage b\n\n```output\n{ handoff }\n```\n\n```prompt\nDo B.\n```\n\n```tools\nread\nglob\ngrep\nshell\n```\n\n```edges\nsuccess -> c\nerror -> #failure\n```\n\n```configs\ntype=model\nprovider=opencode-go\nmodel=deepseek-v4.1-flash\nretries=0\n```\n\n# stage c\n\n```output\n{ handoff, summary }\n```\n\n```prompt\nDo C.\n```\n\n```tools\nread\nglob\ngrep\nshell\n```\n\n```edges\nsuccess -> #success\nerror -> #failure\n```\n\n```configs\ntype=model\nprovider=opencode-go\nmodel=deepseek-v4.1-flash\nretries=0\n```\n"
|
||||
source = strings.Replace(source, "# stage b\n\n```output", "# stage b\n\n```memory\n{\"task\":\"input.prompt\",\"handoff\":\"a.handoff\"}\n```\n\n```output", 1)
|
||||
if _, err := store.Submit(ctx, "native-resume", source); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -489,9 +501,6 @@ esac
|
||||
if transitive.RunDetail.Steps[0].Input["task"] != "corrected-second" || transitive.RunDetail.Steps[0].Input["correction"] != "second" {
|
||||
t.Fatalf("transitive native resume persisted wrong selected input: %#v", transitive.RunDetail.Steps[0].Input)
|
||||
}
|
||||
if transitive.RunDetail.Steps[0].Control == nil || transitive.RunDetail.Steps[0].Control.Memory["handoff"].Sequence != 1 {
|
||||
t.Fatalf("transitive native resume lost prefix provenance: %#v", transitive.RunDetail.Steps[0].Control)
|
||||
}
|
||||
sessions, err := os.ReadFile(filepath.Join(dir, "sessions"))
|
||||
if err != nil || strings.TrimSpace(string(sessions)) != "5" {
|
||||
t.Fatalf("native stage execution count = %q, want 5 (A once, B three times, C once): %v", sessions, err)
|
||||
@@ -536,7 +545,7 @@ case "$3" in
|
||||
if [ "$r" = "1" ]; then
|
||||
echo '{"data":[{"finish":"stop","content":'
|
||||
else
|
||||
echo '{"data":[{"finish":"stop","content":[{"type":"text","text":"{\"outcome\":\"success\",\"output\":{\"summary\":\"done\"}}"}]}]}'
|
||||
printf '%s\n' '{"data":[{"finish":"stop","content":[{"type":"text","text":"# outcome\nsuccess\n"}]}]}'
|
||||
fi ;;
|
||||
*/interrupt) echo '{}' ;;
|
||||
*) exit 99 ;;
|
||||
|
||||
Reference in New Issue
Block a user