Repository navigation
Description
Capture: a witnessed frame of any running surface — driven, replayable, and the gate's own eyes
Standalone · three waves in one issue (cut children per wave if lanes want them) · surfaces: tools, engine, tui, e2e
Problem
A worker that changes what a person sees or what a program does has no way to show it, and the harness has no way to look. Today:
- A claim like "the picker now fits at 80 columns" is text. The auditor (
internal/session/task_checks.go) may only run checks the work declared or ran, and nothing on either belt can produce a frame of a running surface, so there is nothing to check against. Verification signal is the bottleneck, and this is one of its widest holes. - The person reviewing a landing gets prose and a diff. For surface work — our own tui3, a CLI a leaf built, a web page it served — the thing that would settle "is it right?" in two seconds is a picture at the sizes that matter, and it is exactly what never lands.
- tui3 has no visual regression net.
(*app).frame()(internal/tui3/view.go) already renders(width, height) → stringwith no terminal and 22 test files use it, but the golden sweep that used it (internal/tui2/golden, 4,400 width×height×theme frames,-update, structural ANSI checks) was deleted as collateral in the v2 removal (74e16993). Rows at 80/100 columns degrade by data hierarchy; nothing pins that any more. - The only screen capture in the tree is
tmux capture-panein the e2e rig (internal/e2e/tmux_test.go), behind-tags e2e, needing tmux, a key, and ten minutes.
Asking the model to "take a screenshot" in a prompt does not fix this. FAILSAFE.md rule 2: evidence comes from the world, not from the component being checked. A worker saying it looked is a claim; the harness taking the frame is evidence. The same law that produced ArtifactFact{Claimed, Observed} applies here.
Two facts make this cheap for terminals specifically:
- A tui3 frame is text + SGR by architectural law (
internal/tui3/imagepreview.goheader — the surface is a framebuffer; no image protocols are ever emitted). A captured frame is therefore natively legible to a blind model: it reads the frame as text, no vision, no pixel tokens. PNG is only for people. charmbracelet/ultravioletandcharmbracelet/x/ansiare already dependencies, so a virtual terminal for arbitrary commands is close to free;internal/sanitizestill exists for structural checks;tokens.Profilealready resolves every colour, so a PNG renderer has nothing to invent.
Decision
One primitive, capture: run a surface at a size, drive it with inputs, take frames, land them as witnessed proof. Nothing else is new — the auditor, the landing report and CI are consumers of the same primitive.
The tape (interaction is the point)
A capture is a tape: an ordered list of steps with frames taken between them. Steps are domain-neutral and terminal-neutral:
| step | meaning |
|---|---|
type "text" |
literal bytes, paste-safe |
key ctrl+p / key enter / key esc / key up … |
one named key; chords as ctrl+enter (CSI-u on the wire) |
click col,row / move col,row / scroll col,row,±n |
SGR mouse report, press+release |
resize WxH |
window size change mid-tape (tea.WindowSizeMsg / TIOCSWINSZ) |
wait 800ms |
fixed pause |
until "text" 10s |
block until the frame contains the text, or fail — the rig's waitFor, promoted |
frame name |
take a frame now, named |
Two ways to drive it, same tape underneath:
- Scripted. The whole tape is handed over; the run is deterministic and replayable — this is what a contract's proof clause and the gate use.
- Stepwise. The agent holds a live session (
start→ handle), sends one step, receives the resulting frame as text in the tool result, decides the next step. This is the agent clicking around, typing, changing the size, looking. The tape is recorded as it goes, so an exploration becomes a replayable proof with no extra effort. Files, env and the workspace can be changed with ordinary tools between steps; the session stays up.
Backends behind one interface
internal/capture: Source with two implementations, chosen by run.
- In-process tui3 —
tui3.Options{Width, Height, Input, Output}already exists for headless boots; inputs are delivered astea.Msg, frames come from(*app).frame(). Deterministic: pins the same knobsnewTestApp(internal/tui3/tui3_test.go) already enumerates (tmux,remote,railAway,chords,hopQuick, palette, welcome) plus a fixed clock and a calm flag for animated cells (the old golden package'sTheme{Calm}). - Any command — PTY + virtual terminal (ultraviolet) at W×H; inputs are bytes on the PTY; a frame is the emulator's screen as sanitized SGR rows. Works for a CLI a leaf just built, a
less, a REPL, a curses app, a browser-lesscurl | jq. tmux/vhs are explicitly not dependencies.
Both return the same Proof{Tape, Frames []Frame, Text}: Frame is sanitized ANSI rows (small, lossless, diffable, greppable). PNG/GIF rendering is a separate, lazy function over frames — people ask for pixels, models never need them.
Where proofs land, and what they are
- Files land by the existing landing law (owned →
work/proof/, borrowed → the session'sartifacts/), readable names (home-80x24.txt,home-80x24.png,picker-drive.tape), one row each in the deliverables index, one quiet OSC8 line each in the thread — the same lawgenerate_imagealready obeys. ArtifactFactgains a third provenance flag besideClaimed/Observed:Witnessed— the harness itself ran the surface and took the frame. Only Witnessed proofs count for the gate.JournalEntry.Callgainscapture, written before the run returns like every other call.
Consumers (no new machinery in any of them)
- Workers —
captureon both belts, so a worker can look at what it built and steer itself. Session belt:internal/session/tools_capture.go, appended inbelt(); leaf belt: adefineat the tail of stratum 3 inToolbox.Definitions(), inFamilyMediaso leaves that never look pay nothing per turn. - The gate — contracts for surface-changing work carry a proof clause: what must be witnessed, at which sizes, after which steps. The auditor runs the tape itself (Witnessed, not Claimed) and judges the text frame under
RoleJudge; a looking model gets the PNG only if the text is not enough. The contract writer's prompt gains one principle, not an example: for work a person would judge by looking or by using, say what they would need to see or do to believe it, and at what sizes. - The landing — the node's report lists its proofs; the person or the conversation puts them in the PR. Task workers still push nothing and open nothing (
taskoutside.gounchanged). - CI — the golden sweep returns as
internal/tui3/goldenoverframe(), fed bymake demo-home's fixture, at the breakpoints and a coarse grid; a PR that changes a frame gets the diff at those sizes posted as text. No model, no key, seconds.
Rejected
- Prompt-only ("please screenshot before you finish") — a claim, skipped by unattended leaves, unfalsifiable.
- Pixel-first capture (vhs/asciinema as the primitive) — models cannot read pixels cheaply; tapes + text frames are the ground truth, pixels are a view.
- Inline terminal image protocols in the thread — already rejected in
docs/MULTIMODAL.md. - A worker-opened PR carrying screenshots — the outward act stays the person's (
taskoutside.go).
Acceptance
Wave A — the primitive and the net (no belt change, no model)
internal/captureexists with theSourceinterface, the in-process tui3 backend and the PTY backend;Take(ctx, Spec) (Proof, error)and the stepwiseStart/Step/Stop.- A tape of
type,key,click,resize,until,framesteps runs against tui3 in-process and produces identical frames on two consecutive runs (determinism pinned: clock, animation phase, environment sniffing). - The same tape schema drives a PTY-backed command (test fixture: a small Go program that draws a box and reacts to a key and a click) and returns frames through the same
Proof. internal/tui3/golden: the sweep from74e16993^:internal/tui2/goldenadapted toframe(), with-update, running undergo test ./internal/tui3/...in seconds against the demo-home fixture; goldens for the rail breakpoints (80, 100 cols) and a coarse grid land in the same PR.- Structural tests: nothing outside
internal/captureopens a PTY or imports the VT emulator;captureimports no provider and draws nothing.
Wave B — the tool and the provenance
captureon both belts, manual page naming it exactly (TestTheManualMentionsEveryToolOnTheBeltgreen), absent-not-broken when the workspace cannot host proofs.- Stepwise driving from a scripted nest: an agent that calls
capture start,capture step {key ctrl+p}, reads the palette in the returned text frame, andcapture stopleaves a.tapeand named frames inwork/proof/, each with a deliverables row and an OSC8 line in the thread. ArtifactFact.Witnessedset only bycapture;JournalEntry.Call == "capture"written before return.- PNG rendering of a frame exists as a separate function and is only invoked on request (
as: png) or by the thread's viewer path.
Wave C — proof clauses and the gate
- A contract for surface-changing work carries a proof clause; the auditor executes it through
capture(Witnessed) and judges the text frame underRoleJudge. - A scripted nest where the worker claims the frame is right and the witnessed frame disagrees: the gate fails the node and the repair round receives the frame.
- Benched on the issue rig against the current do/chat numbers before merge; report the delta in the changelog entry.
Notes for the implementer
- Start from
newTestApp(internal/tui3/tui3_test.go) — it is already the authoritative list of whatnewAppsniffs and must pin. The in-process backend is that function, exported behind a build-tag-free seam, plus a clock. - Mouse on the wire: SGR
\x1b[<0;col;rowMpress then\x1b[<0;col;rowmrelease; the e2e rig'smouseToalready builds the motion form. Ctrl+Enter is CSI-u\x1b[13;5u. untilisrig.waitFor— keep its shape (deadline, needle list) sointernal/e2e/tuiwords_test.gocan keep proving every needle still exists in the surface.- Keep the
Sourceinterface framework-agnostic: the deleted golden package'sView func(width, height int, theme Theme) []stringwas right to depend on neither Bubble Tea nor a concrete UI package. - Landing goes through
Place/landing.goandhome.Join; neveros.UserHomeDir. - Every new file in
internal/lanemust open with its law (TestEveryFileOpensWithItsLaw); if a capture ever makes a model call it stampsprovider.WithRole, and a new role needs a call site. - Low cyclomatic complexity, one composer per concern: one tape parser, one step-to-input mapper per backend, one frame sanitizer.
Verification recipe
go test ./internal/capture/... ./internal/tui3/...— determinism (two runs, byte-equal frames), tape schema round-trip, PTY fixture reacts to key and click, golden sweep green.- Scripted nest (
session.Agentwith a fake model): stepwise drive of tui3's palette; assert.tape, frames, deliverables rows,Witnessed, journalcaptureentry. - Scripted nest: claimed-vs-witnessed disagreement fails the gate and the repair brief contains the frame text.
make check(vet, tests, packed manual,SIZE-BUDGETratchet) — the VT emulator is already a dependency; report the binary delta in the PR.- One real run on
dev: a task that widens a tui3 row lands withwork/proof/*-80x24.txtand*-160x48.txtin its report, and the PR body carries them.
Drafted with CodeAF · reviewed and owned by the author
Activity
santoshkumarradha commentedon Sep 1, 2026
Heads-up to avoid a false closure: PR #254 was opened from a run titled for this issue, but it implements a different feature (an ffmpeg assembly library and
edit_video), not the capture/proof primitive this issue specifies. #254's body now says so and closes #238 instead. This issue stays open; nothing in it is delivered yet.AbirAbbas commentedon Sep 16, 2026
Closing as not planned. The capture primitive, the tape grammar and the gate were never started, and the project verifies its surfaces another way: the tmux end-to-end suite drives the real binary in a real terminal against a real model (
make test-e2e-tui), andscripts/frame.shsaves design frames. Reopen if a replayable capture becomes something a test needs.