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:
@@ -11,7 +11,11 @@ import (
|
||||
"git.a-wan.net/alan/pipelines/internal/stage"
|
||||
)
|
||||
|
||||
func TestRuntimeLimitAndSelectedMemory(t *testing.T) {
|
||||
// TestRuntimeLimitAndReviewLoop exercises the runner-owned visit limit on a
|
||||
// worker -> review loop. Model stages now read turn files rather than selected
|
||||
// memory fields, so the fake stage hands its result forward through the previous
|
||||
// output map and the loop is bounded by limits alone.
|
||||
func TestRuntimeLimitAndReviewLoop(t *testing.T) {
|
||||
for _, approveLast := range []bool{false, true} {
|
||||
t.Run(map[bool]string{false: "exhaustion", true: "last review approves"}[approveLast], func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
@@ -21,8 +25,7 @@ func TestRuntimeLimitAndSelectedMemory(t *testing.T) {
|
||||
}
|
||||
defer store.Close()
|
||||
source := pipeline.Template([]string{"planner", "worker", "review"}, true)
|
||||
source = strings.Replace(source, "# stage worker", "# stage worker\n\n```memory\n{\"task\":\"input.prompt\",\"plan\":\"planner.plan\",\"findings\":\"review.findings?\"}\n```", 1)
|
||||
source = strings.Replace(source, "# stage review", "# stage review\n\n```limits\n{\"max_visits\":3,\"on\":[\"rejected\"]}\n```\n\n```memory\n{\"task\":\"input.prompt\",\"checks\":\"planner.checks\"}\n```", 1)
|
||||
source = strings.Replace(source, "# stage review", "# stage review\n\n```limits\n{\"max_visits\":3,\"on\":[\"rejected\"]}\n```", 1)
|
||||
source = strings.Replace(source, "success -> #success", "success -> #success\nrejected -> worker", 1)
|
||||
if _, err := store.Submit(ctx, "bounded", source); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -33,7 +36,7 @@ func TestRuntimeLimitAndSelectedMemory(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
calls := map[string]int{}
|
||||
runner.execute = func(_ context.Context, def stage.Definition, input stage.Values) (stage.Result, error) {
|
||||
runner.execute = func(_ context.Context, def stage.Definition, _ stage.Values) (stage.Result, error) {
|
||||
calls[def.Key]++
|
||||
if _, ok := def.Blocks["limits"]; ok {
|
||||
t.Fatal("policy exposed to model")
|
||||
@@ -42,17 +45,8 @@ func TestRuntimeLimitAndSelectedMemory(t *testing.T) {
|
||||
case "planner":
|
||||
return stage.Result{Outcome: "success", Output: stage.Values{"plan": "do task", "checks": "inspect actual files"}}, nil
|
||||
case "worker":
|
||||
if input["task"] != "task" || input["plan"] != "do task" {
|
||||
t.Error("lost shared task context", input)
|
||||
}
|
||||
if calls["worker"] > 1 && input["findings"] != "fix layout" {
|
||||
t.Error("missing revision feedback", input)
|
||||
}
|
||||
return stage.Result{Outcome: "success", Output: stage.Values{"ui_revision": 0, "previous_verdict": "rejected"}}, nil
|
||||
default:
|
||||
if len(input) != 2 || input["checks"] != "inspect actual files" {
|
||||
t.Error("review context contaminated", input)
|
||||
}
|
||||
if approveLast && calls["review"] == 3 {
|
||||
return stage.Result{Outcome: "success", Output: stage.Values{"summary": "approved"}}, nil
|
||||
}
|
||||
@@ -68,8 +62,8 @@ func TestRuntimeLimitAndSelectedMemory(t *testing.T) {
|
||||
t.Fatal("model evaded runtime limit", calls, len(retained.Steps))
|
||||
}
|
||||
last := retained.Steps[6]
|
||||
if last.Control == nil || last.Control.Visit != 3 || last.Control.Memory["checks"].Sequence != 1 {
|
||||
t.Fatal("missing retained control evidence", last)
|
||||
if last.Control == nil || last.Control.Visit != 3 {
|
||||
t.Fatalf("missing retained control evidence: %+v", last)
|
||||
}
|
||||
if approveLast {
|
||||
if retained.Status != "succeeded" || last.Control.LimitReached {
|
||||
|
||||
Reference in New Issue
Block a user