Record and serve per-stage artifacts

Every agent stage now writes into a per-run/step artifacts directory under
the data dir (<data>/artifacts/<run>/<step>), passed to Pi as
PIPELINES_ARTIFACTS_DIR, exposed on the OpenCode client env seam, and stated
in the agent prompt boilerplate so agents save images, screenshots, reports
and logs there.

After each step the server scans that directory with a bounded, symlink- and
traversal-safe inventory (os.OpenRoot + Lstat + O_NOFOLLOW) recording name,
size_bytes, content type (extension then 512-byte sniff fallback) and URL,
enforcing max files, per-file bytes and total bytes while counting skipped
and truncated entries. A missing, unreadable or oversized directory yields
only a best-effort diagnostic and never changes the step outcome.

The list is carried on protocol.RunStep as Artifacts []StageArtifact plus
skipped/truncated counters (omitempty, backwards compatible), persisted in a
new step_artifacts table keyed (run_id, sequence) alongside the
notifications/file-changes tables and loaded by GetRun.

GET /artifacts/{run}/{step}/{name} on the existing handler serves the bytes
with http.ServeContent, so Content-Type, Content-Length, HEAD and Range
(206/416) come from the stdlib; unknown runs/steps, absolute paths,
traversal, symlink escapes and non-regular files are refused.

The TUI lists each selected step's artifacts (name + human size) in the
retained-evidence section and adds an artifacts summary in the style of the
file-changes summary. Adds docs/stage-artifacts.md linked from README and an
artifacts subsection to the packaged operations skill reference.

Tests cover the scan records and caps, missing/oversized directories,
HTTP HEAD/Range/traversal/symlink/unknown refusals and protocol round-trips.
This commit is contained in:
2026-10-15 17:51:18 +01:00
parent 370eaaed1f
commit 0f5a188c6a
19 changed files with 905 additions and 49 deletions
+3 -1
View File
@@ -11,7 +11,9 @@ disposable repository, review edits and command evidence, and expect rough edges
See the [tester walkthrough and known limits](docs/first-version-testing.md).
Stage results include [retained, highlighted workspace diffs](docs/stage-file-diffs.md)
for newly executed visits, alongside their reports and audit evidence.
for newly executed visits, alongside their reports and audit evidence. Stages can
also [record and serve their own artifacts](docs/stage-artifacts.md) - images,
screenshots, reports and logs - per step.
Use `:export` / `:import` to [select and transfer pipeline definitions](docs/pipeline-transfer.md)
between servers as portable ZIP bundles.