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:
2026-10-19 22:27:44 +01:00
parent b2fd614ba4
commit e37b864c40
66 changed files with 2199 additions and 3028 deletions
+32 -68
View File
@@ -2,23 +2,19 @@
Definitions are Markdown made only of `# stage KEY` headings and fenced blocks.
An optional `# settings` section precedes all stages. No unrelated prose outside
blocks. The first stage receives `input.prompt` from the runtime user's task
and `input.pwd`, the resolved run directory recorded by the server;
later stages receive previous output unless `memory` explicitly selects fields
from run-local context. There are no stage `input` blocks. Read
`references/control.md` for selected memory and runner-enforced limits.
blocks. The first stage receives the run prompt in its `input.md`; later stages receive
the previous turn's output. Every visit also gets a `memory.md` of completed
turns. There are no stage `input`, `output`, or `memory` blocks: the model reads
the turn files and writes free-form markdown, and only the `# outcome` section is
interpreted. Read `references/control.md` for runner-enforced limits.
Each model stage requires nonempty `output`, `prompt`, `configs`, and `edges` blocks:
Each model stage requires nonempty `prompt`, `configs`, and `edges` blocks:
````markdown
# stage worker
```output
{ summary, evidence, artifacts }
```
```prompt
Perform the task supplied in input.prompt. Return evidence, not invented success.
Perform the task. Write the complete output.md markdown; only `# outcome` is required.
```
```configs
@@ -49,36 +45,30 @@ prompts/outputs. Read `references/control.md` for the exact format.
## Result format
A model or agent stage returns a line-oriented document: the first non-empty line
is the declared outcome (one of the stage's non-error `edges` keys), sections begin
with `# <heading>`, and the required `# output` section holds one JSON object — the
output map that later stages and `memory` select from. Every other heading becomes
an evidence field keyed by its normalised heading (lowercased, spaces to
underscores) and is retained verbatim, so prose, code fences, quotes and embedded
JSON need no escaping. Extra sections are best-effort and never fail the stage.
Each visit gets `input.md`, `memory.md`, `output.md` and `private/` in
`<run>/stages/<seq>-<stage>/`, plus the run-level shared `public/`. The model
reads input and memory and returns the complete `output.md` markdown. The only
required section is the outcome heading, followed by one of the stage's declared
edge words:
````markdown
# outcome
success
# output
{"task": "x", "changed_files": ["a.go"]}
# Result
# evidence
go test ./... — PASS (observed output)
Free-form markdown for the next stage and the operator.
````
The legacy single JSON envelope `{ "outcome": "...", "output": {...} }` is still
accepted unchanged. The parser chooses by precedence: a response whose first
non-empty character is `{` (after an optional surrounding fence) uses the JSON path;
a `# ` heading that appears before any `{` uses the line path. A missing outcome, an
undeclared outcome, or a missing/invalid `# output` fails the stage with
`FINAL RESULT VALIDATION`; salvageable sections are retained and the parse status is
recorded under the reserved key `result_parse` (`parsed`, `partial`, `failed`). The
full raw response is saved as `raw-output.md` in the stage's artifacts directory. Use
the line form when the evidence is prose, logs or code; never fabricate a result,
never flatten the output fields alongside the outcome, and save any reports, logs or
screenshots you produce into the artifacts directory the runtime names
(`references/delivery.md`).
`internal/turn.ParseOutput` matches the heading case-insensitively at any ATX
level and ignores headings or words inside fenced code blocks. A missing,
duplicate, empty or undeclared outcome fails the stage with
`FINAL RESULT VALIDATION`. Every other heading is uninterpreted and preserved
verbatim in the body. There is no JSON envelope, output schema, field selection
or format-repair pass: do not ask for JSON fields or invent server sections.
Keep turn-local files in `private/`; put reports, logs and screenshots for later
stages in `public/`. Never fabricate a result.
Model configs may set `harness=opencode` or `harness=pi`; omission preserves
historical OpenCode execution. Read `references/harnesses.md` for setup/limits.
@@ -94,7 +84,7 @@ timeouts; an explicit read-only stage may additionally retry a post-admission
deadline or transport failure, while a stage with `edit`/`shell` (or no tools
block) never replays admitted work. Optional `budget_usd=1.50` and
`budget_tokens=50000` independently cap reported usage.
They accumulate across attempts, format repair sessions, and repeated visits
They accumulate across attempts and repeated visits
to this stage in the same run. Omit either budget to leave that resource unlimited.
Both budgets must be positive; tokens include input, output, reasoning and cache
reads/writes. Accounting failures stop budget-limited stages. In-flight requests
@@ -151,10 +141,6 @@ not a choice. It validates, renders, exports and imports like every other type.
````markdown
# stage gate
```output
The operator's decision evidence.
```
```prompt
Review the screenshots and artifacts above, then choose where the run goes.
```
@@ -195,10 +181,6 @@ declared list:
Commit this run's change locally; never push.
```
```memory
{"changed_files":"implementer.changed_files","server_changed_files":"input.server_changed_files"}
```
```tools
read
glob
@@ -215,10 +197,9 @@ error -> #failure
State this pre-commit checklist in the prompt:
1. Stage the union of `input.server_changed_files` (the authoritative,
server-captured set) and the declared `changed_files`, restricted to paths that
still exist, keeping every exclusion. A declared list can be incomplete, and a
captured path it omitted is still this run's change (`references/control.md`).
1. Inspect `git status` and the full diff. Stage this run's change, including
inherited work, restricted to paths that still exist, and keep every
exclusion. Do not rely on a model-declared file list.
2. Inspect the staged diff before committing; never commit unrelated work, secrets
or generated artifacts.
3. Run the repository's required checks and record the exact commands and observed
@@ -244,27 +225,10 @@ stage returns success; do not run the post-landing ancestry check beforehand.
Without a delivery gate, the original workflow or manager completes the merge
and verifies ancestry. No separate merger pipeline is required (`references/queue.md`).
Malformed final JSON has bounded recovery even with `retries=0`; it never changes
verdict/evidence. Recovery tries a deterministic local pass first (append missing
closing delimiters, drop one trailing comma, or insert the single comma/colon the
parser expected), then at most one deny-all formatter request whose deadline is
derived from the payload size and the attempt's remaining budget rather than a
fixed short constant. Every path records `repaired`, `partial` or `unrecoverable`
in `format_repairs`; a partial or unrecoverable result is never returned as
complete, and an ambiguous payload (an unescaped quote/colon inside a string
value) is never guessed at. On an explicit read-only stage a rejected malformed
result may be re-emitted up to `retries`; a stage with `edit`/`shell` or no tools
block never replays stage tools or re-emits the result, though the deterministic
pass and the fresh deny-all, tool-free formatter session still apply. Compatible
native stable backends request schema output with schema retries disabled; a
retained deny-all, no-inference compatibility probe identifies known format
incompatibility. Incompatible native backends and V2 require strict local envelope
validation. Do not promise recovery of truncated strings, missing evidence or
invalid outcomes.
Return the line-oriented result format above, or the strict
`{ "outcome": "declared-edge-key", "output": { ... } }` envelope. Do not treat
tool-call/DSML markup, plain prose or flattened output as success, or rerun tool
work to fix a response's formatting.
A stage returns the markdown above, never the retired
`{ "outcome": ..., "output": ... }` envelope. Do not treat tool-call/DSML markup,
plain prose, or a missing outcome as success, and never rerun tool work merely to
fix a response's formatting.
## Scheduling