diff --git a/docs/cli.md b/docs/cli.md index a61ef1a5..e2c5978e 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -662,8 +662,9 @@ files as that step's artifacts: //public/ ``` -`input.md` is the run prompt on the first visit and the previous visit's output -body (without its outcome section) afterwards. `memory.md` is the accumulated markdown of completed turns plus the +`input.md` is the run prompt on the first visit; later visits carry the run +prompt under `# Run task` followed by the previous visit's output body (without +its outcome section) under `# Previous turn output`. `memory.md` is the accumulated markdown of completed turns plus the files each turn added to the shared `public/` directory. A text-only stage (an explicit empty `tools` block) receives both files' contents in its prompt instead, because it has no file-reading tool. The model returns the complete diff --git a/docs/model-results.md b/docs/model-results.md index 7d1c90a8..b157249f 100644 --- a/docs/model-results.md +++ b/docs/model-results.md @@ -16,8 +16,10 @@ Every model visit gets its own directory under the run's artifact root: //public/ ``` -- `input.md` is the run prompt on the first visit and the previous visit's body - after that, under a `# Previous turn output` heading. +- `input.md` is the run prompt on the first visit. Later visits keep the run + prompt under a `# Run task` heading (its own headings demoted two levels) and + add the previous visit's body under a `# Previous turn output` heading, so + every stage sees what the run is for even when an earlier stage summarised. - `memory.md` is one `## · visit ` section per completed turn: the turn body followed by a system-written, sorted list of the files that turn added to `public/`. diff --git a/docs/notes/stage-turns.md b/docs/notes/stage-turns.md index 0f6cf678..f46aa29d 100644 --- a/docs/notes/stage-turns.md +++ b/docs/notes/stage-turns.md @@ -15,9 +15,11 @@ the run's artifact root: zero-padded to two digits). `Paths.Ensure` creates the turn, private and public directories idempotently; it never deletes or rewrites existing files. -`input.md` is the run prompt on the first visit and the previous visit's output -body (without the outcome section) under a `# Previous turn output` heading -afterwards. `memory.md` is plain +`input.md` is the run prompt on the first visit. Afterwards it is the run +prompt under a `# Run task` heading (headings demoted two levels) followed by +the previous visit's output body (without the outcome section) under a +`# Previous turn output` heading. Carrying the task forward means a stage that +only summarised its own work is never the sole carrier of what the run is for. `memory.md` is plain markdown: one `## · visit ` section per completed turn, with that turn's body — its own ATX headings demoted two levels, so the turn heading stays the structural one — followed by a system-written list of files it added to diff --git a/internal/author/skill/SKILL.md b/internal/author/skill/SKILL.md index 8f4de2ff..b87bf8f1 100644 --- a/internal/author/skill/SKILL.md +++ b/internal/author/skill/SKILL.md @@ -57,7 +57,7 @@ explicitly asks to manage a schedule; scheduling alone is not workflow authoring ## Turns and artifacts -Each visit has `input.md` (the run prompt or previous body), `memory.md` +Each visit has `input.md` (the run prompt; later visits add the previous body), `memory.md` (completed turns), `output.md`, and `private/`. Every run also has one shared `public/` directory, addressed by its absolute path; files there are visible to later stages and are the stage's real artifacts. `input.md`, `memory.md`, diff --git a/internal/server/turn_test.go b/internal/server/turn_test.go index c6b82aae..30904b6f 100644 --- a/internal/server/turn_test.go +++ b/internal/server/turn_test.go @@ -89,8 +89,8 @@ func TestTurnsAccumulateMemoryAndListFilesAsArtifacts(t *testing.T) { if detail.Status != "succeeded" || len(detail.Steps) != 2 { t.Fatalf("run = %q steps=%d: %+v", detail.Status, len(detail.Steps), detail.RunSummary) } - if secondInput != "# Previous turn output\n\nfirst body\n" { - t.Fatalf("second input.md = %q, want the previous turn's output", secondInput) + if secondInput != "# Run task\n\noriginal task\n\n# Previous turn output\n\nfirst body\n" { + t.Fatalf("second input.md = %q, want the run task and the previous turn's output", secondInput) } for _, want := range []string{"## first · visit 1", "first body", "Files added to public/:\n- public/shared.txt"} { if !strings.Contains(secondMemory, want) { diff --git a/internal/server/turns.go b/internal/server/turns.go index 4931b3a4..be33dab1 100644 --- a/internal/server/turns.go +++ b/internal/server/turns.go @@ -89,16 +89,16 @@ func turnInputWithRetry(base string, retryInput stage.Values) string { return base + "\n# Retry input\n\nThis retry was given this complete input:\n\n```json\n" + string(encoded) + "\n```\n" } -// turnInput is the run prompt on the first visit and the previous visit's -// output afterwards. +// turnInput is the run prompt on the first visit; later visits carry the run +// prompt and the previous visit's output. func (s *runState) turnInput() string { if len(s.turns) == 0 && strings.TrimSpace(s.lastOutput) == "" { return s.prompt } if strings.TrimSpace(s.lastOutput) == "" { - return "# Previous turn output\n\n_(no output)_\n" + return turn.RenderInput(s.prompt, "_(no output)_\n") } - return turn.RenderInput("", s.lastOutput) + return turn.RenderInput(s.prompt, s.lastOutput) } // turnOutput renders a completed step for later memory. Model stages store their diff --git a/internal/turn/render.go b/internal/turn/render.go index 6aca5eaf..a7e6955e 100644 --- a/internal/turn/render.go +++ b/internal/turn/render.go @@ -6,14 +6,20 @@ import ( "strings" ) -// RenderInput renders the markdown a turn receives. The first turn receives the -// run prompt as-is. Later turns receive the previous turn's output verbatim -// under a heading; prompt is not repeated. +// RenderInput is a visit's input.md: the run prompt on the first visit, and on +// later visits the run prompt under "# Run task" followed by the previous +// visit's body under "# Previous turn output". Every stage keeps the operator's +// task: a stage that summarised its own work must not be the only carrier of +// what the run is for. func RenderInput(prompt string, previousOutput string) string { if strings.TrimSpace(previousOutput) == "" { return prompt } - return "# Previous turn output\n\n" + previousOutput + if strings.TrimSpace(prompt) == "" { + return "# Previous turn output\n\n" + previousOutput + } + task := strings.TrimRight(prompt, "\n") + return "# Run task\n\n" + demoteHeadings(task) + "\n\n# Previous turn output\n\n" + previousOutput } // MemoryEntry is one completed turn in a later turn's memory file. Output is diff --git a/internal/turn/render_test.go b/internal/turn/render_test.go index 6c035ab9..d0399085 100644 --- a/internal/turn/render_test.go +++ b/internal/turn/render_test.go @@ -15,15 +15,16 @@ func TestRenderInputFirstTurnIsTheRunPrompt(t *testing.T) { } } -func TestRenderInputLaterTurnShowsOnlyPreviousOutput(t *testing.T) { +func TestRenderInputLaterTurnKeepsTheTaskAndThePreviousOutput(t *testing.T) { previous := "## Result\n\n- changed `internal/turn`\n\n```diff\n+new line\n```\n" - got := RenderInput("the original prompt", previous) - want := "# Previous turn output\n\n" + previous + got := RenderInput("# Goal\n\nThe original prompt.\n", previous) + want := "# Run task\n\n### Goal\n\nThe original prompt.\n\n# Previous turn output\n\n" + previous if got != want { t.Fatalf("later turn input = %q, want %q", got, want) } - if strings.Contains(got, "the original prompt") { - t.Fatal("later turn input repeated the run prompt") + // Without a recorded prompt the previous output stands alone. + if got := RenderInput("", previous); got != "# Previous turn output\n\n"+previous { + t.Fatalf("promptless later input = %q", got) } }