Files
pipelines/internal/server/chat_slash_commands.go
T
alan d1390994cc Chat: offer the session's Claude Code skills and slash commands in the palette
The server reads the commands Claude Code's initialize response lists (bundled,
user, project, plugin and claude.ai-synced skills plus CLI commands, with
descriptions and argument hints), drops terminal-only ones, and serves them per
chat over a new chat_commands request without waiting for a CLI start. The
composer palette lists them after the recorded commands; choosing one inserts
"/<name> " and sending passes it to the harness as an ordinary prompt.
Codex, OpenCode and Pi chats reply with an empty list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 20:53:57 +00:00

47 lines
1.6 KiB
Go

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 "/<name> 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})
}