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
+23 -16
View File
@@ -205,24 +205,31 @@ file diffs: current capture is server-owned. Do not promise full files/rollback.
## Retained stage artifacts
Every agent visit gets a per-run/step artifacts directory under the data
directory (`<data>/artifacts/<run>/<step>/`); the root is configurable and
defaults next to the database. The directory is passed as
`PIPELINES_ARTIFACTS_DIR` to a locally spawned Pi process and exported to the
OpenCode CLI where controllable, and it is stated in the agent prompt next to
`Run directory:` for every harness. OpenCode V2 tools run inside the shared serve
process, so there the prompt line, not the environment, is the reliable carrier.
The instruction is general: save images, screenshots, reports and logs there.
Every model visit gets a file-based turn under the data directory
(`<data>/artifacts/<run>/stages/<seq>-<stage>/`) with `input.md`, `memory.md`,
`output.md` and `private/`; `public/` is run-level and shared by every stage.
The root is configurable and defaults next to the database. The writable
`private/` and shared `public/` directories are stated in the agent prompt for
every harness, and `PIPELINES_ARTIFACTS_DIR` points at the turn directory for a
locally spawned Pi process. OpenCode V2 tools run inside the shared serve
process, so there the prompt, not the environment, is the reliable carrier.
Turn-local files belong in `private/`; reports, logs and screenshots for later
stages belong in `public/`. The server owns `input.md`, `memory.md` and
`output.md` and never asks the model to write them directly.
After the visit the server makes one bounded inventory and records each file's
name, size, content type (extension, sniff fallback) and a relative url; these
appear under each step's `artifacts` in `inspect RUN_ID --json` and the TUI's
`A` artifacts view, which groups them by stage and visit, marks images and shows
the recorded count, capture-pending/not-recorded wording and partial-capture
notes.
After the visit the server makes one bounded inventory of the turn and public
directories and records each file's name, size, content type (extension, sniff
fallback) and a relative url; these appear under each step's `artifacts` in
`inspect RUN_ID --json` and the TUI's `A` artifacts view, which groups them by
stage and visit, marks images and shows the recorded count,
capture-pending/not-recorded wording and partial-capture notes. Public entries
carry a `public/` prefix. `input.md`, `memory.md` and `output.md` are the primary
artifacts of every model visit.
`GET /artifacts/<run>/<step>/<name>` serves the bytes (correct Content-Type and
Content-Length, HEAD, and Range/206/416 via `http.ServeContent`), refusing
traversal, absolute paths, symlink escapes and unknown runs/steps.
traversal, absolute paths, symlink escapes and unknown runs/steps. A pre-turn
`<run>/<step>/` path stays readable for runs recorded before the file protocol
landed.
- Limits: 200 files, 8 MiB/file, 64 MiB total per visit; over-cap files are
skipped and counted; symlinks and non-regular files are excluded.
@@ -236,7 +243,7 @@ traversal, absolute paths, symlink escapes and unknown runs/steps.
- When an OpenCode-harness model stage finishes, the server exports its real
session read-only (v1 `opencode export <id>`, v2 `opencode session export <id>`)
and writes exactly one file, `session.html`, into the same `<run>/<step>` artifacts
and writes exactly one file, `session.html`, into the same turn artifacts
directory; it lists and serves like any other artifact.
- The `session.md` export is retired: nothing writes it any more and it is never
presented. A run recorded before the HTML-only change still lists `session.md`