Dismiss and restore operator shell commands per chat

chat_shell_dismiss hides finished runs from every readback and pushes a
dismissal frame to every watcher; chat_shell_restore undoes it within a
30 s window, after which the command, output and error are purged and only
a tombstone remains, reported by chat_shell_runs for clients that missed
the event.
This commit is contained in:
2026-11-09 21:22:07 +00:00
parent 8f06f12d49
commit 03123c23fd
11 changed files with 513 additions and 9 deletions
+26
View File
@@ -0,0 +1,26 @@
package protocol
// Dismissing operator shell commands. Dismissal is per chat, for every client:
// a dismissed run leaves every chat_shell_runs readback and every watcher
// receives a chat_shell_run_event with Dismissed set. A running command cannot
// be dismissed. For ChatShellRunUndoWindow after a dismissal the run can be
// restored (chat_shell_restore); after that the server purges its command,
// output and error, keeping only a tombstone whose id chat_shell_runs reports
// in ChatShellDismissed so a client that missed the event drops the card.
const (
// ChatShellDismiss dismisses the finished runs named in
// ChatShellRunRequest.RunIDs; the reply lists those it dismissed in
// ChatShellDismissed (running, unknown and already dismissed runs are
// skipped).
ChatShellDismiss = "chat_shell_dismiss"
// ChatShellRestore undoes a dismissal still inside its undo window; the
// reply carries the restored runs (with their list output tail) in
// ChatShellRuns, and every watcher receives their lifecycle frames.
ChatShellRestore = "chat_shell_restore"
// ChatShellRunUndoWindow is how long, in milliseconds, a dismissed run is
// kept restorable before its output is purged. It is longer than the
// clients' Undo notice so a late Undo still succeeds.
ChatShellRunUndoWindow = 30_000
// ChatShellDismissLimit bounds the run ids of one request.
ChatShellDismissLimit = 200
)
+4 -1
View File
@@ -76,6 +76,8 @@ type ChatShellRunRequest struct {
Rows int `json:"rows,omitempty"`
Data string `json:"data,omitempty"`
After int64 `json:"after,omitempty"`
// RunIDs names the runs of chat_shell_dismiss and chat_shell_restore.
RunIDs []string `json:"run_ids,omitempty"`
}
// ChatShellRunRecord is one operator command and what it produced. Output is
@@ -116,7 +118,7 @@ type ChatShellRunRecord struct {
// ChatShellRunEventFrame is one live change to a run. A lifecycle frame sets
// Run (without output); an output frame sets Output covering absolute bytes
// [Offset, End). A client whose own copy ends before Offset missed output and
// [Offset, End); a dismissal frame sets Dismissed (the card goes away). A client whose own copy ends before Offset missed output and
// shows that gap rather than joining unrelated text.
type ChatShellRunEventFrame struct {
SessionID string `json:"session_id"`
@@ -125,4 +127,5 @@ type ChatShellRunEventFrame struct {
Output string `json:"output,omitempty"`
Offset int64 `json:"offset,omitempty"`
End int64 `json:"end,omitempty"`
Dismissed bool `json:"dismissed,omitempty"`
}
+3
View File
@@ -280,6 +280,9 @@ type Message struct {
ChatShellRun *ChatShellRunRecord `json:"chat_shell_run,omitempty"`
ChatShellRuns []ChatShellRunRecord `json:"chat_shell_runs,omitempty"`
ChatShellRunEvent *ChatShellRunEventFrame `json:"chat_shell_run_event,omitempty"`
// ChatShellDismissed lists dismissed run ids (chat_shell_dismiss's reply
// and chat_shell_runs' tombstones; chat_shell_dismiss.go).
ChatShellDismissed []string `json:"chat_shell_dismissed,omitempty"`
// ListDirectory is the list_directory body and DirectoryListing its reply:
// the home-restricted folder picker listing (see directories.go).
ListDirectory *DirectoryListRequest `json:"list_directory,omitempty"`