Run operator shell commands in a chat's directory on the server

chat_shell_run starts $SHELL -lc in the chat session's directory in its own
process group, streams merged output to every watcher of the session, keeps a
1 MiB tail and persists each run; chat_shell_stop interrupts the group and
kills it after a grace period. chat_shell_share queues an ordinary prompt
with the command and a bounded output tail.
This commit is contained in:
2026-11-09 15:55:14 +00:00
parent 57679d9591
commit e6bc57c901
16 changed files with 1367 additions and 1 deletions
+12 -1
View File
@@ -22,6 +22,13 @@ const chatPermissionPollInterval = 2 * time.Second
// every other client, attributed to the sending device's label, and the turn's
// output is fanned out to all of them.
func handleChatPrompt(ctx context.Context, request protocol.Message, broker chatBroker, hub *chatHub, registry operatorRegistry, clientID string, write func(protocol.Message) error) {
admitChatPrompt(ctx, request, broker, hub, registry, clientID, write, false)
}
// admitChatPrompt is handleChatPrompt; echoSender also publishes the user turn
// to the sending client, for a prompt the server composed (chat_shell_share)
// that the sender has no local copy of.
func admitChatPrompt(ctx context.Context, request protocol.Message, broker chatBroker, hub *chatHub, registry operatorRegistry, clientID string, write func(protocol.Message) error, echoSender bool) {
if broker == nil {
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "chat is not configured on this server"})
return
@@ -128,7 +135,11 @@ func handleChatPrompt(ctx context.Context, request protocol.Message, broker chat
accepted = true
queued := admission == chatAdmitQueued
// Publish the user turn to every other client; the sender already has it.
hub.broadcastUser(userFrame, clientID)
exceptClientID := clientID
if echoSender {
exceptClientID = ""
}
hub.broadcastUser(userFrame, exceptClientID)
if admission == chatAdmitSteered {
hub.markOpSteered(sessionID, operationID)
// The harness took the message into its running turn: it is not queued,