Expand description
Offload the dropped head of an over-long PTY output to a scratch file.
When a command’s output grows past the in-memory cap the PTY keeps only the
tail and drops the oldest bytes (see the truncation paths in pty.rs). That
dropped head is the part the agent can no longer see. Instead of losing it,
we append it to a file under <workspace>/.winx/scratch/ so the agent can
recover it with ReadFiles (or grep via BashCommand). The file lives inside the workspace on
purpose: those read tools are workspace-confined and pipe through the
redaction layer, so a leaked secret in the log is still scrubbed on the way
back out.
Everything here is best-effort: any IO error is logged at debug and swallowed
so output offload can never crash the server (release builds are
panic = "abort").
Functions§
- append_
scratch - Append
bytesto the scratch file, creating it if absent. - new_
scratch_ path - A fresh, unique scratch-file path under the workspace, creating the directory
if needed and pruning stale files first so the dir does not grow without
bound. Returns
Noneon any IO error (offload is best-effort). - prune_
scratch_ dir - Remove scratch files whose mtime is older than
max_age. Best-effort: per-entry failures are logged at debug and skipped, and a missing dir is a no-op.