Commit Graph

494 Commits

Author SHA1 Message Date
alan 66a12207b9 Unattended test: build the subscription the current way
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 01:08:01 +00:00
alan dd86454657 Merge branch 'worktree-agent-a717651aa412e3b7c'
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 01:00:02 +00:00
alan 8384c229a6 Merge branch 'worktree-agent-ae57d5ca18be911ad' 2026-12-03 00:51:08 +00:00
alan 878012ad4c Runner: gofmt
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 00:42:27 +00:00
alan 2ea7eb9db0 Runner: no I/O under the runner lock; retry run settlement
- Run worktree creation happens outside r.mu; the source tree is protected
  from storage maintenance meanwhile and the reservation is re-checked under
  the lock before the run is recorded (a refused tree is discarded).
- getRun/listRuns read the store without r.mu; listRuns finds failed runs
  with an active cleanup agent in one query (partial index) instead of a
  detail read per failed run.
- finishRunState writes the deliverable and walks the run size without the
  lock; FinishRun retries transient failures with backoff (a refused
  transition is final).
- Launch teardown retries a failed read with backoff instead of keeping the
  reservation forever; a kept run that cannot be read at reattach is retried
  and then marked interrupted (stopping its adopted session first).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 00:42:25 +00:00
alan c7e0b8b84e Chat tests: accept text deltas joined in a subscriber's queue
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 00:41:48 +00:00
alan 8bd219e636 Chat: find in chat (Ctrl+F / Cmd+F)
A find bar over the transcript: query, Match case, n of N (counted from
the newest), Enter for an older match and Shift+Enter for a newer one.
Matches are painted over the rendered text, code blocks included, without
restyling it; the current match is scrolled into view. Matches in history
not loaded yet come from the server's chat:<id>-scoped search and are
reached by loading older pages. Esc closes and returns to the composer.
The key is the pane's, so a focused terminal keeps Ctrl+F. Fixture answers
scoped searches for captures; cheatsheet lists the key. The scoped search
matches the query as typed, spaces included, like the client.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 00:41:39 +00:00
alan c316bc9bc8 Chat and runs: tell a slow client to resync instead of dropping it silently; join queued deltas
A chat subscriber whose queue fills is detached and its writer ends the
stream with a resync frame (the app re-attaches and re-reads history); a run
subscriber gets a final runs_resync and the app subscribes again and
re-reads the Runs list and open detail. Consecutive text/reasoning deltas of
one part are joined in a chat subscriber's queue; joined numbered frames carry
seq_from and delta_lens so the app trims exactly the prefix a history page
already holds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 00:39:38 +00:00
alan ab6b2bb632 Scheduler: skip unreadable schedules, admit claimed runs asynchronously
A schedule that cannot be parsed or claimed is logged and skipped instead
of aborting the tick for every schedule. Claimed runs are admitted on their
own goroutines, so a slow start (worktree creation) no longer makes the
next due schedule look missed; lateness is measured at claim time. An
invalid interval no longer divides by zero.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 00:37:50 +00:00
alan fbc09528ec Chat list: order chat_session_changed pushes by a registry revision
operator_sessions gains a revision bumped by a trigger on every update; the
wire row carries it, and the app ignores a push (or a list read) older than
the row it holds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 00:34:16 +00:00
alan b95ec83918 Merge branch 'worktree-agent-a96b82d1c1cee18ca' 2026-12-03 00:33:07 +00:00
alan 2e535951cf Keep run --wait's 'run ended STATUS' error prefix
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 00:30:31 +00:00
alan 64e51ee751 Claude tasks: stop listing finished subagent/foreground calls as running
The host counted any tool_result containing "running in background with ID"
as a launch acknowledgement, so a subagent's foreground `sed` of
fake-claude.py (or translate.go) became a background task that never ends.
A subagent's background command whose completion notification preceded its
launch result was also revived. Both stayed "Running" in the chat for days.

- claudehost: only a Bash/Agent/Task call's own first-line acknowledgement
  starts a task; finished ids are never revived by late acks/progress;
  background_tasks_changed (the CLI's running set) ends unlisted tasks;
  tool output no longer counts as a task notification.
- claude: same strict acknowledgement; background_tasks_changed settles
  tracked tasks; on reattach, host tasks without a native id are checked
  against the main and subagent transcripts, so phantoms from hosts still
  running the old build disappear.
- Fake CLI "subagent" turn and regression tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 00:27:50 +00:00
alan ba50bef3ba Merge branches 'worktree-agent-a752b94716f8d18ba' and 'worktree-agent-a253f0d23f8cafea3' into worktree-agent-a96b82d1c1cee18ca 2026-12-03 00:27:14 +00:00
alan 2bde6b6344 CLI for agents: non-TTY safe run/confirmations, compact inspect, wait hints and exit codes
- Without a terminal, run behaves as --json, tui refuses and confirmations
  fail fast naming --yes instead of prompting.
- inspect prints a compact summary by default; --step N, --transcripts and
  --json give detail.
- wait names a failed run's stage and first diagnostic line, prints how to
  answer a run waiting on a person, and exits 2 when any run failed,
  was canceled or interrupted (1 stays for client errors).
- help describes the current # outcome / # handoff format.
- Task starter's Land stage drops edit to match format.md; skill docs
  document run --json --yes, retry --yes --json and the new behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 00:27:14 +00:00
alan 9f13c93be6 Chat reliability: durable ntfy outbox, queue recovery retries, unattended cap
- Chat phone pushes (attention items, auto-switch notices) go through a
  durable chat_notifications outbox with leases, bounded attempts and
  backoff, retried by a worker; pushes cleared in the app first are never
  published, and a publication racing a clear is cleared again.
- Queued/scheduled chat prompts are deleted on recovery only when they can
  never be rebuilt; transient failures keep the rows and retry with backoff.
- Unattended chats with live work always keep notifying; the idle cap rises
  from 16 to 64.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 00:26:46 +00:00
alan 32c9c6b1df Server: chat:<id>-scoped find-in-chat search returning every occurrence, paged
A kind=chat search with scope chat:<id> returns one hit per text-part
occurrence (message id, part, UTF-16 offset/length), newest message first,
paged by cursor (a reply's next_cursor or a chat_messages next_cursor), with
optional case-sensitive matching. Scoped and global chat searches no longer
cancel each other on one connection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 00:25:09 +00:00
alan ae4526d87c Retries: tell stages why the last attempt failed; resume interrupted runs
- turn.RenderPreviousAttempt: bounded "# Previous attempt" section (attempt
  number, failing stage, bounded diagnostic, partial-edits note).
- In-stage retries (stage/model_run.go) append it instead of resending an
  identical prompt; run retries (resume and restart) add it to the first
  model visit's input.md, numbering attempts along the retry chain.
- --input-file retry overrides render only the override keys in input.md,
  labelled "# Operator correction" (the step row keeps the merged input).
- Essential memory (memory.md) inlines a revisiting stage's own last handoff,
  bounded, besides the previous stage's handoff.
- Interrupted runs can be retried: resume reruns the interrupted visit, or
  starts the next stage after the last completed visit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 00:24:56 +00:00
alan d275ffe643 Chat tools: follow-up ids, cancel_followup, run-triggered follow-ups, show_html warnings
- schedule_followup returns the follow-up id and lists pending follow-ups;
  count-then-queue is serialised so the 3-pending bound holds under
  concurrent calls.
- cancel_followup {id} removes one of the chat's undelivered follow-ups.
- schedule_followup {run_id, on: finished|attention} queues a durable
  follow-up (7-day deadline) that is released with the run's state when the
  run ends or waits on a human; run must exist and not already meet the
  condition; watches are re-armed from the restored queue after a restart.
- show_html results warn about scripts, remote resources (blocked by the
  sandbox) and missing dark-mode support.
- The ambiguous-call error advice fits each tool instead of always
  suggesting a different title.
- references/chat.md and the SKILL.md chat paragraph document the above, and
  questions are no longer described as Claude-only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 00:24:12 +00:00
alan e649eced10 Runs: one uninterruptible stage session no longer disables the runner
Start-up recovery used to fail the whole runner when any previously active
stage session could not be confirmed stopped. That run alone is now marked
interrupted with a diagnostic naming the session and error. A Pi owner whose
process and process group are gone counts as stopped without its quiescence
receipt (it crashed), as the Claude stage path already did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 00:23:39 +00:00
alan 3e267d4863 Chat: never drop a Claude turn's lifecycle frames; end a runner turn whose end was lost
emit now waits (bounded) for a full watcher to accept step and resync
frames instead of dropping them. The turn runner also ends its turn once a
harness that tracks its turn state has reported idle for the settle period
and its probe confirms, asking clients to resync.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 00:21:44 +00:00
alan 59d2fdcb20 Merge branch 'worktree-agent-a785be85dc8fbff78' 2026-12-02 20:15:14 +00:00
alan 876336f6fd Merge branch 'worktree-agent-abc9e7b0a4e0a0f54'
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 20:05:02 +00:00
alan b1db6b9c50 Merge branch 'worktree-agent-a04a38e74fe1aef60' 2026-12-02 19:56:31 +00:00
alan b1fcdcf2c3 Chat: unnamed chats take the harness title, harness default per folder, word-safe tables, Send later
- New chat: a cleared Name creates the chat without an operator title; the
  list shows the harness's own title, or the default name until it has one.
  The server no longer records "New chat" for a blank title and OpenCode
  is created without a title so it names the session itself.
- New chat harness defaults to the one last used in the chosen folder,
  else anywhere, else OpenCode; remembered on the device per server.
- Markdown tables wrap at word boundaries and never go below a column's
  longest word (tokens over ~40 characters may break); a table whose words
  cannot fit scrolls sideways with the code block affordance.
- Composer: right-click, long-press, Shift+F10 or the context menu key on
  Send opens Send later... (30 min, 1 h, tomorrow 9:00, usage reset, pick a
  time), sent through the same path with send_at.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 19:55:40 +00:00
alan f02ff56dfe App: dark-aware HTML views, run cards, changed/missing file notes, one card width, dense diff rows
show_html documents that declare dark support follow the app theme; others
stay light. Tool description and skill docs say so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 19:54:58 +00:00
alan 633b5953bb Chat: the server continues a usage-refused Claude chat at the reset
When Claude Code refuses an operator chat's turn for a usage limit and the
server does not continue it on another account, the server now queues a
durable prompt (auto-continue-<refusal id>, sent as Pipelines (automatic))
for a minute after the reset: the refused operator message when the turn
did no work, else "continue". The reset comes from the refusal's text,
else the rejected rate_limit_event. Refusals of turns Claude Code started
itself are handled too, with no client attached; a restarted server or a
device scheduling the same refusal adds nothing. The choice is kept per
Claude home beside auto-switch (or by the server for chats without one),
read and set with chat_auto_continue, on by default.

The app's limit banner now finds the refusal as the latest turn, ignoring
notices, agent reports and activity rows after it, reads and writes the
server's choice, and only schedules its own prompt for older servers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 19:52:03 +00:00
alan b91ef04ab0 Notifications: agent notify reaches every device and clears everywhere
- Server: chat ntfy messages carry a sequence id derived from their app id;
  clearing a chat app notification also clears it in ntfy (PUT
  /<topic>/<seq>/clear, verified on ntfy v2.38.1).
- Server: a turn that sent an agent notify does not also send chat_reply.
- notify tool and MCP instructions: Pipelines already notifies at reply end
  and for questions/approvals; notify is for mid-turn or background news.
- Shown notify items carry channels (apps/phone); the transcript row says
  where it went.
- App: NotificationBridge.close(tag); web closes tracked Notifications and
  tells other tabs over a BroadcastChannel; native bridge cancels by tag and
  now supports macOS. AgentNotices closes on notifications_cleared and on
  resubscribe cleared ids, and a tap sends clear_notifications.
- Docs: skill, chat reference, ntfy/notifications docs, app note.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 19:49:31 +00:00
alan d204ce3187 Chat tools: argument validation, replace, file snapshots, server-fetched images, show_run, show_diff head/paths, schedule_followup
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 19:44:47 +00:00
alan c8541f29b7 Notify: an agent's notify reaches every connected app
The notify tool now records a chat_notify app notification with its own
id per call (no dedupe of repeated words) and the tool's priority, so
every subscribed client gets it and a reconnecting client replays it.
ntfy delivery is unchanged; the tool result names where it went.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 15:44:39 +00:00
alan 0c75ff1b0d Notify link=: review fixes
- ntfy uses the link only beside a web run view; otherwise it keeps the
  run click and the receipt says why (app click stays the link).
- The outbox retry of a hook's failed publication re-resolves the stage's
  link=, so the ntfy and app tap targets keep it.
- A valid link file is never the attached artifact.
- Notification artifacts are read through os.OpenRoot with O_NOFOLLOW.
- The link note is recorded once, on the first receipt, and never becomes
  the run-level failure reason.
- Android: a recents relaunch does not reopen the link, and a run thread of
  several entries opens the run rather than the latest external page.
- Docs and the protocol comment say "first non-empty line".
2026-12-02 12:29:46 +00:00
alan f5f31b7bcd Notify link=: a stage's public/ file sets the phone tap target
A stage's notify block may name `link=<pattern>` (validated like `open=`).
When the hook fires, the newest public/ match is read (at most 4 KiB); its
first non-empty line, if an absolute http(s) URL ntfy accepts as a click,
becomes the ntfy Click and the app notification click, with the run kept
as the app's run action and ntfy's browser view. A missing file or invalid
URL keeps today's tap target and is noted on the receipt diagnostic.

Android opens such an http(s) click in the browser (after clearing the
notification) instead of handing it to Flutter as a route.
2026-12-02 12:20:22 +00:00
alan 364e0cb3c9 Chat queue: wake the runner when a scheduled head is unqueued; end a stale observed turn once the harness is idle
A prompt queued behind a scheduled prompt (the app's auto-continue at a
usage limit's reset) stayed queued after that head was removed: unqueue
never woke the runner, which slept until the removed prompt's send_at.
unqueue now wakes it, and the runner re-checks a scheduled head at least
every 30 s.

Safety net: a due prompt held by a turn the room only observed (its end
lost, or a reattach watcher that gave up) is delivered once the harness
reports itself idle for a settle period and its probe confirms it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 00:58:51 +00:00
alan 18e0e565ca App: Claude account auto-switch setting; the limit banner leaves a refusal the server is continuing alone
The Claude account dialog shows 'Auto-switch account when usage runs out'
(claude_account_auto_switch) when the server reports it. The usage-limit
banner schedules no auto-continue while the server's auto-switch continue
prompt is queued. A chat refused after another chat already switched the
Claude home gets a fresh switch stamp, so its banner clears too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 00:31:31 +00:00
alan ed9072b79a Claude accounts: switch a chat refused for usage to another saved account and continue it
When Claude Code refuses an operator chat's turn for a usage limit, the
server marks the refused account until its reset and, if the chat's Claude
home allows it (claude_account_auto_switch / `pipelines claude-account auto
on|off`, on by default, kept in pipelines-accounts/settings.json), switches
the home to the saved account with the most usage left through the
claude_account_use path. Switches of one home are serialized, so chats
refused together switch once. Each refused chat gets one queued prompt,
marked as sent automatically, that asks the agent to check it is on track
before continuing; the app's auto-continue-at-reset prompt for the refusal is
removed (and refused if it arrives later), and the operator gets a
low-priority notification.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 00:23:43 +00:00
alan 0dc805ae0e Chat: show the active Claude account in the send tooltip, menu and limit banner
usage.account now carries the email and organization of the account
Claude Code is signed in to (from its initialize account, or the saved
account just switched to), sent at process start and after a switch.
The app shows it as the send tooltip's usage prefix, the Claude account
menu subtitle, the usage-limit banner's status line and the info sheet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 16:33:46 +00:00
alan e80f18969c Merge branch 'worktree-agent-a11776f2a9241a0c9' 2026-11-30 16:13:58 +00:00
alan 293474ac3c Chat usage limit: Claude Code-style banner with auto-continue; drop the approaching-limit banner
- The usage-limit banner now reads 'Out of usage credits' (or the refusal's
  own 'You've hit your 5-hour limit'), 'Auto-resuming at <time>', an
  'Auto-continue when limits reset' checkbox and Try again, keeping the
  account switcher's 'Switch to <account>'.
- Auto-continue (a shared, persisted preference, on by default) hands the
  server a durable scheduled prompt (send_at = reset + 1 min) with an
  idempotent auto-continue-<refusal id> operation id: the refused operator
  message again, or 'continue' when the refused turn had already worked.
  Unchecking unqueues it; Try again unqueues it and sends now.
- Remove the approaching-limit banner, its SnackBar announcements and their
  marks; the send-button usage ring replaces them.
- Claude Code's rate_limit_event overage fields (overageStatus,
  isUsingOverage/overageInUse, overageDisabledReason, overageResetsAt) reach
  clients as usage.account.extra_usage; the ring tooltip and the banner say
  'Extra usage available' or 'Using extra usage'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 16:13:33 +00:00
alan 2cdd524ecc Merge branch 'main' into worktree-agent-a3ec65b20dc3028b9 2026-11-30 15:41:57 +00:00
alan ea25cf504f Claude chat: a history read mid-reply carries the streaming block's beginning
Claude Code writes a content block to its session file only once the block
is complete. A client that read history while a block streamed (opening the
chat mid-reply, a reconnect, a resync) got only the deltas after its read,
and nothing re-sent the block's beginning, so the reply showed with its first
part cut off. Deltas are now numbered (seq) and their text retained for the
newest assistant messages; the newest history page adds every retained part
the transcript lacks and reports the last included seq (live_seq) and the
overlaid parts (live_parts).

History now numbers empty text/thinking blocks as the live stream does, so a
thinking block after an empty display-omitted one keeps one part id live and
in history. Text a content_block_start carries is published, not dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 15:41:57 +00:00
alan c490f71042 Claude account switcher: save and switch a chat's Claude login in place
Saved accounts live under <CLAUDE_CONFIG_DIR>/pipelines-accounts/<slug>/
(0700 dir, 0600 files). Switching changes what /login changes: the
claudeAiOauth entry of .credentials.json and oauthAccount of .claude.json
(atomic temp+rename, mode and other keys kept) and the org caches /login
drops, under Claude Code's own refresh, storage and config locks, so
running CLIs continue on the new account without a restart. The active
login's rotated tokens are written back to its slot first.

Server: claude_accounts / claude_account_save / _use / _remove, chat-scoped
and Claude-only; a switch moves the home's open chats to the new account's
quota (usage.account.switched_at), clearing a reached limit.
CLI: pipelines claude-account list|save|use|remove [--dir].
App: Claude account in the chat menu, and Switch to <account> on the
usage-limit and usage-warning banners, with a confirmation snack.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 15:10:08 +00:00
alan 1772100af2 Claude history: show the newest 64 MiB of an oversized transcript
A session file over 64 MiB made the whole chat history unavailable. The
history now reads only the file's newest 64 MiB (from a whole line) and
opens with a notice that earlier turns are left out and how to see them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 13:46:09 +00:00
alan 3d739c3bfc Copy and paste: the desktop's universal copy key works; Ctrl+C at the terminal login keeps the terminal
Omarchy's Super+C sends Ctrl+C by setting the modifier state with no Ctrl key
event while Super is held. Flutter's web engine only presses a modifier on its
own key event, so the app saw a plain "c": the chat selection was not copied
and the terminal typed the letter. A key modifier sync in front of the
framework's key handler now presses the modifiers the browser event's flags
hold (and outside Apple platforms lets go of a held Meta for Ctrl+C/V/X/A/
Insert), installed by the app's binding.

The terminal copies a selection on Ctrl+C without sending ^C, treats the
injected copy key as copy only, and pastes on Shift+Insert. A refused
clipboard write or read now shows a message instead of failing silently.

Server: before the login completes, Ctrl+C and Ctrl+\ erase the typed
password (Ctrl+U) and Ctrl+Z is dropped, so su is not killed and the terminal
no longer ends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 17:57:28 +00:00
alan 58041e06b7 Chat colours: add lime, cyan, indigo, brown and grey
Thirteen colours in hue order. Each has a light and a dark shade checked by
the existing contrast test; teal moves a shade deeper so it stays apart
from cyan on light surfaces.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 19:08:41 +00:00
alan 4eb9b2e934 Open chats: the server moves a restarted chat (/new) to its new session
The server-stored open-chat set kept a /new'd chat's old session unless the
restarting device's own write landed, so another device (the phone) came
back to the old conversation. chat_new_session now replaces the session in
the stored set in place (position and floating kept) and pushes the new
revision to every connection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 00:43:33 +00:00
alan daf290e39e Questions: agents write their findings before asking; an open question isn't 'Stopped'
An agent put its whole analysis in thinking (not shown) and asked a
question straight away, so the operator saw only the question form under
a 'Stopped after 2 tools' row. The Pipelines tool instructions now tell
agents to write what they found before asking, and an activity row with
an open question reads '... · waiting for your answer'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 14:08:38 +00:00
alan 4d86fe5a7f Runs: a hub folder no longer blocks runs in the separate repositories inside it
Retrying the Daily brief (workspace ~/caplens) was refused while a change
run worked in ~/caplens/repos/fix-d, with a message that read as if the
retry reused the next run number. Nested workspaces now overlap only
within one repository, and the refusal names the blocking run's own
workspace.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 09:38:19 +00:00
alan e13cb99ade Terminals: keep screen state on the server; snapshot on reload and gaps
A headless xterm-compatible emulator (internal/termstate) follows each
machine terminal's PTY output under the same lock as the 1 MiB tail. A
terminal_output from before the retained tail (new page, reload, gap)
now gets output_snapshot: an escape stream that resets the client and
restores scrollback (1000 lines), main screen, the alternate screen when
in use (via ?1049h so the program's exit brings the shell back), saved
cursors, tabs, scroll region, cursor incl. pending wrap, modes (mouse
tracking/encoding, bracketed paste, DECCKM, keypad, autowrap, origin,
focus, ...), charsets, pen and title, as of output_end; frames continue
there. Reads inside the tail stay raw.

No Go library was adequate: charmbracelet/x/vt and vito/midterm scroll at
0.2-4 MB/s and hide modes/pen/region; vt10x is unmaintained. termstate
runs at 160-200 MB/s.

The app treats a snapshot reply as a replay without the dropped-output
line, and every replay now starts with RIS so stale modes end.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 00:56:49 +00:00
alan aaed57e105 Merge main into the terminal flow-control branch
Conflicts resolved keeping both sides: main's active-client rules, input
lane, reply marking and key input, and this branch's flow control,
acknowledgements, subscriptions and sliced emulator feed. terminal_ack
joins the terminal lane; the feed marks each live slice it writes as
drawing, so the emulator's answers still go to onReply.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 00:03:20 +00:00
alan 0963a071d0 Terminals: flow-controlled output, immediate echo, sliced emulator writes
Machine terminals no longer skip output for live viewers. Each connection's
subscription is a cursor into the 1 MiB retained tail, drained by the
connection's writer as soon as the PTY reader writes (no 50 ms tick; a
streaming frame gathers for at most 2 ms). A subscription opened with
flow: true gets window (256 KiB) in its reply and acknowledges drawn output
with terminal_ack; while one is full the reader stops reading the PTY, so
the program waits. A subscription full for 3 s without acking stops holding
the terminal and later sees a gap; a gone connection drops its
subscriptions. Clients that never ask for flow keep the old pacing (newest
64 KiB per 50 ms). terminal_open/terminal_output replies precede the frames
that follow them, which start exactly at the reply's output_end.

Chat shell runs share the buffer code: output is pushed as it arrives,
oldest first, while the chat's watchers keep short queues; 256 KiB unpushed
stops the reader, and watchers behind for 3 s get the old pacing.

The app asks for flow, takes offsets from the server (frame end, reply
output_end) instead of re-encoded text length, acks per quarter window, and
writes replays and bursts into the emulator in slices that yield to the
event loop (ChatShellTerminalFeed, shared with chat shells).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 23:57:18 +00:00