Dismiss finished shell command cards with Undo

Finished command cards get a Dismiss button and the chat's More menu a
Dismiss all finished commands entry. Dismissal applies to every client of
the chat; a SnackBar (Material) or transient notice (Cupertino) offers Undo
for 5 s. Running commands cannot be dismissed until they end.
This commit is contained in:
2026-11-09 21:40:20 +00:00
parent 03123c23fd
commit bac21efc5b
11 changed files with 639 additions and 9 deletions
+52
View File
@@ -130,6 +130,58 @@ change, and `{session_id, run_id, output, offset, end}` for output chunks.
- The process group is killed on Stop, on server shutdown and after the
command exits, so a run cannot leave an orphan holding the server's pipe.
## Dismissing commands
- A finished card (exited, stopped, failed, interrupted) has a Dismiss
button: a close icon with the tooltip (Material) or semantics label
(Cupertino) "Dismiss". The card has no menu, so there is no menu entry.
- A running card has no Dismiss. Stop it first; once it ends, Dismiss
appears. This was chosen over "Stop and dismiss" because a command that
ignores SIGINT keeps running for the grace period, and hiding a live
process's card would be confusing.
- The chat's More menu has "Dismiss all finished commands" when at least one
run has finished. It dismisses every finished run and leaves running ones.
- Dismissal is per chat, for every client (not per device). The card goes at
once. A refusal brings the card back with the server's reason.
- Undo: a 5 s SnackBar (Material) or a transient notice over the
conversation (Cupertino, `ChatUndoBar` in the root overlay) offers Undo.
The Cupertino notice briefly covers the composer.
- Server design: dismiss-then-restore within a window, then purge.
`chat_shell_dismiss {session_id, run_ids}` sets `dismissed_at` on finished
runs and pushes `chat_shell_run_event {dismissed: true}` to every watcher.
`chat_shell_restore {session_id, run_ids}` clears it within
`ChatShellRunUndoWindow` (30 s, longer than the 5 s notice). The reply
carries the runs, and watchers get lifecycle frames. A client that held no
copy reads the list again for the output. After the window the server
purges the run's command, output, output text and error (an `AfterFunc`,
plus on every server start). Only a tombstone row remains.
- Readback: `chat_shell_runs` and `chat_shell_run_output` exclude dismissed
runs. `chat_shell_runs` lists tombstone ids in `chat_shell_dismissed`, so a
client that missed the event drops those cards on its next refresh.
Tombstones age out with the 50-run history prune.
- Files: `internal/protocol/chat_shell_dismiss.go`,
`internal/pipeline/chat_shell_dismiss.go`,
`internal/server/chat_shell_dismiss.go`,
`lib/features/chat/shell/chat_shell_dismiss.dart` (button, menu entry,
Undo notice) and `chat_shell_runs_dismissal.dart` (controller part).
- Tests: `internal/pipeline/chat_shell_dismiss_test.go` covers dismiss,
readback, restore, purge and tombstones.
`internal/server/chat_shell_dismiss_test.go` covers the websocket dismiss
to two watchers, refusing a running or empty request, readback with
tombstones, refusing output for a dismissed run, Undo, and purge after the
window and on restart. `test/features/chat/shell/chat_shell_dismiss_test.dart`
covers the button, Undo and notice expiry (both hosts), a refused dismiss,
the menu entry's absence and dismiss-all, another client's dismissal and
restore, and tombstone readback.
- Verification (2026-11-09): `go test ./internal/protocol ./internal/pipeline
./internal/server` all ok. `tool/memwatch/full.sh test/features/chat`
gives `PASS: 1146 passed, 0 failed`. `tool/analyze.sh` is clean. Real
Chrome captures (`tool/capture`, `chats=1&msgs=2&shell=1`) covered Material
light 880x1000 and Cupertino dark 560x1000: cards with Dismiss, the Undo
notice, the restored card, the More menu entry, dismiss-all with its
notice, and (Cupertino) the notice gone after 5 s. The PNGs were inspected.
A live server and browser session was not exercised end to end.
## Files
- Server: `internal/protocol/chat_shell_run.go`,