chat: add the Codex backend

Store a chat's harness with its operator session, expose chat_backends and a
backend choice in New chat, and route each session through a manager. The Codex
adapter uses the App Server's Unix WebSocket for threads, turns, history,
questions and interrupt; OpenCode remains the default and Claude is not
advertised until its sidecar and login are wired.
This commit is contained in:
2026-10-20 12:10:39 +01:00
parent 74b74adee7
commit f7a3a49f94
25 changed files with 1287 additions and 32 deletions
+14
View File
@@ -4,6 +4,7 @@ import (
"context"
"crypto/rand"
"encoding/hex"
"regexp"
"strconv"
"sync/atomic"
@@ -92,6 +93,16 @@ type operatorRegistry interface {
ReopenOperatorSession(ctx context.Context, sessionID string) error
SetOperatorSessionStar(ctx context.Context, sessionID string, starred bool) error
SetOperatorSessionTitle(ctx context.Context, sessionID, title string) error
SetOperatorSessionBackend(ctx context.Context, sessionID, backend string) error
}
// validChatSessionID accepts the opaque id shapes of the supported harnesses
// (OpenCode ses_…, Codex/Claude UUIDs). The owning adapter still validates the
// exact shape before any provider call; this only rejects clearly unsafe ids.
var chatSessionIDPattern = regexp.MustCompile(`^(?:ses_[A-Za-z0-9_]+|[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$`)
func validChatSessionID(id string) bool {
return len(id) <= 200 && chatSessionIDPattern.MatchString(id)
}
var chatTokenSequence atomic.Uint64
@@ -157,6 +168,9 @@ func handleChat(ctx context.Context, request protocol.Message, broker chatBroker
case protocol.ChatRename:
handleChatRename(ctx, request, registry, write)
return true
case protocol.ChatBackends:
handleChatBackends(request, broker, write)
return true
case protocol.ChatShells:
handleChatShells(ctx, request, broker, registry, write)
return true