package server import ( "context" "git.a-wan.net/alan/pipelines/internal/protocol" ) // chatCommander is the optional slash-command surface of a chat harness: // the skills and commands its session loaded, which the operator invokes by // sending "/ args" as an ordinary prompt. Claude Code implements it; a // harness without one offers an empty list rather than an error. type chatCommander interface { Commands(ctx context.Context, sessionID string) ([]protocol.ChatCommand, error) } // Commands lists the slash commands the session's harness offers. func (m *chatManager) Commands(ctx context.Context, sessionID string) ([]protocol.ChatCommand, error) { adapter, err := m.brokerFor(ctx, sessionID) if err != nil { return nil, err } commander, ok := adapter.(chatCommander) if !ok { return nil, nil } return commander.Commands(ctx, sessionID) } // handleChatCommands answers chat_commands with the session's slash commands. func handleChatCommands(ctx context.Context, request protocol.Message, broker chatBroker, write func(protocol.Message) error) { query := request.ChatQuery if query == nil || !validChatSessionID(query.SessionID) { _ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a valid chat session id is required"}) return } var commands []protocol.ChatCommand if commander, ok := broker.(chatCommander); ok { var err error if commands, err = commander.Commands(ctx, query.SessionID); err != nil { _ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: err.Error()}) return } } _ = write(protocol.Message{Type: protocol.ChatCommands, ID: request.ID, ChatCommands: commands}) }