Skip to content

Send a block's long output to a file with out=file - #340

Merged
gdey merged 1 commit into
mainfrom
claude/project-thread-wszv0g
Nov 23, 2026
Merged

gdey merged 1 commit into
mainfrom
claude/project-thread-wszv0g

Conversation

@gdey

@gdey gdey commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Requested by j · project thread

This is steps 4 and 5 of docs/spilled-output/design.md, and it builds on #339 (include windows).

What changes

  • out=file[:path] writes stdout to <doc>.assets/<id>.log, or to the path given, under the usual root rules. The file is written whether the block passed or failed, and only when its bytes changed. Output past 16 MB (docroot.MaxRead) is cut at a line boundary and the fence gets truncated.
  • The output fence is an include of the file, for example output {for=build exit=2 at=… <include file=res://build.log match="^FAIL" before=3 lines=20}.
    • mdsh rewrites for=, exit=, exited, truncated, at= and <include file= on every run.
    • It keeps the author's window attributes: from, to, match, before, lines, until and number_on. They are checked at parse time, just as on an include block.
    • With no window attributes, the fence shows the first fold_output lines, or the whole file when fold_output: 0.
  • Copies (output {for=build} elsewhere) are refilled the same way, and each keeps its own window.
  • Ordering (step 5): when an out=file block ends, the session re-reads every include block that names its file, wherever it is in the document. An include above the block therefore shows this run's log.
  • history=N: earlier logs are renamed as build.<time>.log, as images are, and their history fences point at the renamed file. Logs that write-back drops are tidied away.
  • Naming an unnamed block renames its default log and rewrites res://<old>. in its output fence and copies.
  • Rules: secret, tty and http blocks can't have out=file (a parse error that names the attributes). nosave writes no file at all; the window is shown from memory.
  • Docs: README (new "Long output in a file" section), spec, cheatsheet, site docs, and CHANGELOG with a screenshot.

One change from the design: the design said a nosave block writes its log to a session temp directory. Nothing reads that file yet, so this PR doesn't write it. That can come with step 6's "open the log" link.

Still to come in later PRs: the line count and link to the file in mdsh-gui's output bar, and --html/--pdf linking the file (step 6); Chroma-based symbol= for other languages (step 7).

Screenshot

mdsh-gui (--serve) after Run all. The block's own fence shows the first 25 lines of test.log. The copy under "The first failure" sets match="^--- FAIL" before=1 lines=4.

out=file in mdsh-gui

Testing

  • go test ./... passes.
  • New tests:
    • run.TestSpill: the file is written, the default window, author windows kept on write-back, a copy's own window, an include above the block refilled, number_on in printing, an unchanged file not rewritten.
    • TestSpillPathCapNoSave: an explicit path, a failing block, the 16 MB cap with truncated, nosave.
    • TestSpillParse and TestSpillHistory, for parse errors and log rotation.
    • TestSpillNameBlocks, for auto-naming.
  • The cmd/mdsh-gui vendor copy and the bundle are regenerated. There are no TypeScript changes.

Generated by Claude Code

A build log or test run swamped the document: its lines were all in
the file, and every run's diff was the whole log. Step 4 and 5 of
docs/spilled-output/design.md:

- out=file[:path] writes stdout to <doc>.assets/<id>.log, or the path
  given, whether the block passed or failed, and only when the bytes
  changed. Output past docroot.MaxRead is cut at a line and the fence
  marked truncated.
- The output fence becomes an include of the file. mdsh writes for=,
  exit=, exited, truncated, at= and <include file= on every run, and
  keeps the fence's window attributes (from, to, match, before, lines,
  until, number_on), checked at parse time like an include's. With
  none, the fence shows the first fold_output lines.
- Copies are refilled the same way, each keeping its own window.
- When the block ends, include blocks that name its file are read
  again, wherever they are, so one above the block shows this run.
- history=N renames earlier logs as it does images and points their
  fences at them; naming an unnamed block renames its log and rewrites
  res://<old>. in its fences.
- nosave writes no file and shows the window from memory; secret, tty
  and http blocks can't have out=file.

The GUI's line count and link to the file, and Chroma-based symbol=,
are later steps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W9mexoiqFA4n1PYQWSzMDS
@gdey gdey self-assigned this Nov 23, 2026
@gdey
gdey merged commit 7eeabd3 into main Nov 23, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants