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
+7 -1
View File
@@ -23,6 +23,7 @@ type chatShellRunStore interface {
ChatShellRuns(ctx context.Context, sessionID string) ([]protocol.ChatShellRunRecord, error)
ChatShellRun(ctx context.Context, sessionID, id string) (protocol.ChatShellRunRecord, bool, error)
InterruptChatShellRuns(ctx context.Context, endedAt int64, reason string) (int64, error)
chatShellDismissStore
}
const (
@@ -48,6 +49,8 @@ type chatShellRunner struct {
grace time.Duration
flush time.Duration
persist time.Duration
// undo is how long a dismissed run stays restorable before its purge.
undo time.Duration
mu sync.Mutex
active map[string]*chatShellProcess
@@ -74,6 +77,7 @@ func newChatShellRunner(base context.Context, store chatShellRunStore, publish f
return &chatShellRunner{
base: base, store: store, publish: publish, now: time.Now, shell: chatShellProgram,
grace: 3 * time.Second, flush: 100 * time.Millisecond, persist: 2 * time.Second,
undo: protocol.ChatShellRunUndoWindow * time.Millisecond,
active: map[string]*chatShellProcess{},
}
}
@@ -89,12 +93,14 @@ func chatShellProgram() string {
}
// recover marks runs a previous server process left running as interrupted:
// their processes died with it (or are no longer owned by anyone).
// their processes died with it (or are no longer owned by anyone). It also
// purges dismissals whose undo window passed while no server was running.
func (r *chatShellRunner) recover(ctx context.Context) {
if r.store == nil {
return
}
_, _ = r.store.InterruptChatShellRuns(ctx, r.now().UnixMilli(), chatShellInterruptedReason)
r.purgeDismissed(ctx)
}
// resolveChatShellDirectory requires the chat's recorded directory to still be