resolve: merge gateway additions from alm.1/alm.2/alm.4

This commit is contained in:
sam committed 2026-07-29 07:28:43 +10:00
commit 568d4a4be3
6 files changed
+523 -810

No files matched your search

+68 -140
View File
@@ -14,6 +14,7 @@ import (
"os"
"os/signal"
"path/filepath"
"slices"
"strconv"
"strings"
"syscall"
@@ -99,42 +100,6 @@ func chatGenerateOptions(
}, nil
}
// appendStepMessages appends the assistant turn and tool-result
// messages for a single generation step to msgs so the next call
// has the complete conversation history.
func appendStepMessages(msgs []chat.Message, step core.StepResult) []chat.Message {
// Build assistant message with tool calls.
var toolCalls []chat.ToolCall
for _, tc := range step.ToolCalls {
toolCalls = append(toolCalls, chat.ToolCall{
ID: tc.ToolCallID,
Name: tc.ToolName,
Arguments: tc.Input,
})
}
msgs = append(msgs, chat.Message{
Role: chat.RoleAssistant,
Content: step.Text,
Parts: step.Parts,
ToolCalls: toolCalls,
})
// Build one tool-result message per tool execution.
for _, tr := range step.ToolResults {
content := tr.Output
if tr.Error != "" {
content = tr.Error
}
msgs = append(msgs, chat.Message{
Role: chat.RoleTool,
Content: content,
ToolCallID: tr.ToolCallID,
Name: tr.ToolName,
})
}
return msgs
}
func configuredMCPProvider(server config.MCPServer) (toolprovider.Engine, error) {
name := strings.TrimSpace(server.Name)
if name == "" {
@@ -398,11 +363,6 @@ func run() int {
sessionStore = gateway.NewSessionStoreMemory(cfg.BotUser)
}
// Session-scoped state for /goal, /steer, /subgoal, and /queue
// commands. Created before the LLM responder so it is in scope
// for the chat loop; wired into the router afterward.
sessionState := gateway.NewSessionState()
// Build an LLM responder from the runtime. Gateway-local commands
// (/status, /model, /spawn) are handled directly; all
// other messages are routed through the LLM with conversation
@@ -461,14 +421,6 @@ func run() int {
SessionID: sessionKey,
Now: time.Now(),
})
// Inject standing goal and subgoals into the system
// prompt when set via /goal. The goal prompt is
// appended so it overrides nothing in the base
// prompt; the instruction-precedence hierarchy
// already ranks user requests above conventions.
if goalPrompt := sessionState.BuildGoalPrompt(); goalPrompt != "" {
systemPrompt += "\n\n" + goalPrompt
}
view.Messages = append(
[]gateway.CompressedMessage{{Role: "system", Content: systemPrompt}},
view.Messages...,
@@ -492,99 +444,40 @@ func run() int {
options.Messages = messages
// Run one model-call-plus-tool-execution at a time
// so /steer messages can be injected between steps.
// Each call to Chat/ChatStream processes exactly
// one step; the loop here manages the full
// conversation state by appending the model's
// response and tool results after each iteration.
options.MaxSteps = 1
var text string
for {
if onDelta == nil {
result, err := llm.Chat(ctx, chatModel, options)
if err != nil {
return "", fmt.Errorf("llm chat: %w", err)
}
text = result.Text
// Append the steps to messages so the next
// call has the full conversation history.
for _, step := range result.Steps {
options.Messages = appendStepMessages(options.Messages, step)
}
// No tool calls in the final step means
// the model finished.
if result.FinishReason != core.FinishReasonToolCalls {
break
}
} else {
stream, err := llm.ChatStream(ctx, chatModel, options)
if err != nil {
return "", fmt.Errorf("llm chat stream: %w", err)
}
// Consume FullStream, not TextStream. Per the
// ai-sdk channel contract FullStream is
// authoritative and MUST be drained until
// close.
var sb strings.Builder
var stepText strings.Builder
var stepToolCalls []core.ToolCall
var stepToolResults []core.ToolResult
var stepParts chat.Parts
for part := range stream.FullStream {
switch part.Type {
case core.StreamPartTextDelta:
if part.TextDelta != "" {
sb.WriteString(part.TextDelta)
stepText.WriteString(part.TextDelta)
onDelta(part.TextDelta)
}
case core.StreamPartToolCall:
if part.ToolCall != nil {
stepToolCalls = append(stepToolCalls, *part.ToolCall)
}
case core.StreamPartToolResult:
if part.ToolResult != nil {
stepToolResults = append(stepToolResults, *part.ToolResult)
}
case core.StreamPartFinishStep:
if part.StepResult != nil {
stepParts = part.StepResult.Parts
}
}
}
reason, err := stream.FinishReason()
if err != nil {
return "", fmt.Errorf("llm chat stream: %w", err)
}
text = sb.String()
// Append the step to the conversation.
options.Messages = appendStepMessages(options.Messages, core.StepResult{
Text: stepText.String(),
Parts: stepParts,
ToolCalls: stepToolCalls,
ToolResults: stepToolResults,
})
// No more tool calls — done.
if len(stepToolCalls) == 0 && reason != core.FinishReasonToolCalls {
break
}
if onDelta == nil {
result, err := llm.Chat(ctx, chatModel, options)
if err != nil {
return "", fmt.Errorf("llm chat: %w", err)
}
// Check for pending /steer messages. Inject after
// every tool-execution step so guidance arrives
// at the earliest safe point.
if steerText, ok := sessionState.PollSteer(); ok {
options.Messages = append(options.Messages, chat.Message{
Role: chat.RoleUser,
Content: "[STEER] " + steerText,
})
text = result.Text
} else {
stream, err := llm.ChatStream(ctx, chatModel, options)
if err != nil {
return "", fmt.Errorf("llm chat stream: %w", err)
}
// Consume FullStream, not TextStream. Per the ai-sdk
// channel contract FullStream is authoritative and MUST
// be drained until close: its writes are synchronous, so
// leaving it unread stalls the producer and deadlocks the
// whole turn. TextStream is a best-effort view that drops
// deltas when it is not being read, so it cannot be used
// to reconstruct the reply either.
var sb strings.Builder
for part := range stream.FullStream {
if part.Type != core.StreamPartTextDelta || part.TextDelta == "" {
continue
}
sb.WriteString(part.TextDelta)
onDelta(part.TextDelta)
}
// Resolves once the producer completes, so a mid-stream
// failure surfaces here rather than a truncated reply
// passing as a short but complete one.
if _, err := stream.FinishReason(); err != nil {
return "", fmt.Errorf("llm chat stream: %w", err)
}
text = sb.String()
}
// Persist the response.
@@ -609,7 +502,8 @@ func run() int {
router := gateway.NewRouter(st, llmResponder, "telegram")
router.LLMStream = llmStream
router.Models = chatModels
router.State = sessionState
router.Sessions = sessionStore
router.Agents = agentReaderAdapter{tasks: st.Tasks}
configureTaskCommands(router, chatTasks, chatController, defaultChatIdentity)
startGateways = append(startGateways, func() {
go func() {
@@ -901,6 +795,40 @@ func run() int {
return 0
}
// agentReaderAdapter implements gateway.AgentReader from the store's Task list.
type agentReaderAdapter struct {
tasks func(ctx context.Context, limit int) ([]store.Task, error)
}
func (a agentReaderAdapter) AgentList(ctx context.Context) ([]gateway.AgentInfo, error) {
all, err := a.tasks(ctx, -1)
if err != nil {
return nil, err
}
// Show tasks that are actively running or waiting for human input.
active := []string{
store.StatusRunning,
store.StatusWaitingHuman,
store.StatusParked,
}
isActive := func(status string) bool {
return slices.Contains(active, status)
}
out := make([]gateway.AgentInfo, 0, len(all))
for _, t := range all {
if !isActive(t.Status) {
continue
}
out = append(out, gateway.AgentInfo{
ID: t.ID,
Title: t.Title,
Status: t.Status,
Identity: t.Identity,
})
}
return out, nil
}
type chatTaskWriterAdapter struct {
enqueue func(
ctx context.Context,
+5
View File
@@ -20,6 +20,11 @@ type commandSpec struct {
// together prevents a newly registered command from being omitted from help.
var gatewayCommandSpecs = []commandSpec{
{Command: "status", Description: "Show task counts by state", Usage: "/status"},
{Command: "whoami", Description: "Show which Archie identity you are talking to", Usage: "/whoami"},
{Command: "profile", Description: "Show the active Archie profile", Usage: "/profile"},
{Command: "sessions", Description: "List recent sessions", Usage: "/sessions"},
{Command: "resume", Description: "Resume a session by ID or name", Usage: "/resume [id]"},
{Command: "agents", Description: "List active agents and running tasks", Usage: "/agents"},
{Command: "version", Description: "Show installed Archie versions", Usage: "/version"},
{Command: "update", Description: "Check for Archie updates", Usage: "/update"},
{Command: "provider", Description: "Choose the provider used for chat", Usage: "/provider"},
+49 -2
View File
@@ -172,6 +172,11 @@ func (g *Gateway) launch(ctx context.Context, router *gateway.Router) (*bot.Bot,
// Gateway-local commands: handled directly, no LLM.
b.RegisterHandler(bot.HandlerTypeMessageText, "/status", bot.MatchTypeExact, g.statusHandler(router))
b.RegisterHandler(bot.HandlerTypeMessageText, "/whoami", bot.MatchTypeExact, g.whoamiHandler(router))
b.RegisterHandler(bot.HandlerTypeMessageText, "/profile", bot.MatchTypeExact, g.profileHandler(router))
b.RegisterHandler(bot.HandlerTypeMessageText, "/sessions", bot.MatchTypeExact, g.sessionsHandler(router))
b.RegisterHandler(bot.HandlerTypeMessageText, "/resume", bot.MatchTypeExact, g.resumeHandler(router))
b.RegisterHandler(bot.HandlerTypeMessageText, "/agents", bot.MatchTypeExact, g.agentsHandler(router))
b.RegisterHandler(bot.HandlerTypeMessageText, "/version", bot.MatchTypeExact, g.versionHandler())
b.RegisterHandler(bot.HandlerTypeMessageText, "/update", bot.MatchTypeExact, g.updateHandler())
b.RegisterHandler(bot.HandlerTypeMessageText, "/start", bot.MatchTypeExact, g.startHandler())
@@ -277,6 +282,26 @@ func (g *Gateway) WebhookHandler() http.Handler {
// ── command handlers (gateway-local -- no LLM) ────────────────
func (g *Gateway) statusHandler(router *gateway.Router) bot.HandlerFunc {
return g.routeCmdHandler(router, "/status")
}
func (g *Gateway) whoamiHandler(router *gateway.Router) bot.HandlerFunc {
return g.routeCmdHandler(router, "/whoami")
}
func (g *Gateway) profileHandler(router *gateway.Router) bot.HandlerFunc {
return g.routeCmdHandler(router, "/profile")
}
func (g *Gateway) sessionsHandler(router *gateway.Router) bot.HandlerFunc {
return g.routeCmdHandler(router, "/sessions")
}
func (g *Gateway) agentsHandler(router *gateway.Router) bot.HandlerFunc {
return g.routeCmdHandler(router, "/agents")
}
func (g *Gateway) resumeHandler(router *gateway.Router) bot.HandlerFunc {
return func(ctx context.Context, b *bot.Bot, update *models.Update) {
msg, ok := g.authorizedMessage(ctx, b, update)
if !ok {
@@ -286,10 +311,32 @@ func (g *Gateway) statusHandler(router *gateway.Router) bot.HandlerFunc {
ChannelID: fmt.Sprintf("%d", msg.Chat.ID),
ThreadID: threadIDString(msg.MessageThreadID),
From: msg.From.Username,
Text: "/status",
Text: msg.Text,
})
if err != nil {
g.log.Error("status handler failed", "error", err)
g.log.Error("resume handler failed", "error", err)
return
}
g.sendMessage(ctx, b, msg.Chat.ID, msg.MessageThreadID, reply)
}
}
// routeCmdHandler builds a handler that routes a fixed command through the
// gateway.Router and sends the reply.
func (g *Gateway) routeCmdHandler(router *gateway.Router, cmd string) bot.HandlerFunc {
return func(ctx context.Context, b *bot.Bot, update *models.Update) {
msg, ok := g.authorizedMessage(ctx, b, update)
if !ok {
return
}
reply, err := router.Route(ctx, gateway.Message{
ChannelID: fmt.Sprintf("%d", msg.Chat.ID),
ThreadID: threadIDString(msg.MessageThreadID),
From: msg.From.Username,
Text: cmd,
})
if err != nil {
g.log.Error("command handler failed", "command", cmd, "error", err)
return
}
g.sendMessage(ctx, b, msg.Chat.ID, msg.MessageThreadID, reply)
+1 -5
View File
@@ -162,11 +162,7 @@ func TestVersionReportsBothComponents(t *testing.T) {
// this set may still be executable if typed explicitly — they just shouldn't
// appear on Telegram's discoverability surfaces.
var telegramHiddenCommands = map[string]bool{
"approve": true, // dangerous command, intentionally hidden
"bg": true, // alias for /queue
"background": true, // alias for /queue
"btw": true, // alias for /queue
"q": true, // alias for /queue
"approve": true,
}
func TestPublishedCommandsMatchExecutableCommandSurface(t *testing.T) {
+185 -211
View File
@@ -15,6 +15,7 @@ import (
"sort"
"strconv"
"strings"
"time"
)
// Message is an inbound message from a gateway connection.
@@ -48,6 +49,26 @@ type StatusReader interface {
StatusCounts(ctx context.Context) (map[string]int, error)
}
// SessionLister is the read surface /sessions and /resume need.
// The daemon supplies its session store, which satisfies this structurally.
type SessionLister interface {
List(ctx context.Context) ([]SessionContext, error)
}
// AgentInfo carries one row for /agents.
type AgentInfo struct {
ID int64
Title string
Status string
Identity string
}
// AgentReader is the read surface /agents needs. The daemon supplies
// its store, which satisfies this structurally.
type AgentReader interface {
AgentList(ctx context.Context) ([]AgentInfo, error)
}
// LLMResponder routes a message to the LLM and returns the reply. When
// nil (not yet wired -- see abg.13), non-command messages get a static
// "LLM not configured" response. Gateways call this for any message the
@@ -146,12 +167,12 @@ type Router struct {
// spawned under one identity cannot be controlled from another's
// chat session.
Identity string
// State holds per-session goal, subgoal, steer, and queue state.
// When nil, /goal, /steer, /subgoal, and /queue return
// "not configured". The daemon wires one SessionState per router
// (one per gateway). Multi-identity deployments that need
// per-identity state should provide separate routers.
State *SessionState
// Sessions supports /sessions and /resume. When nil those commands
// return "not configured".
Sessions SessionLister
// Agents supports /agents. When nil the command returns
// "not configured".
Agents AgentReader
gatewayName string
}
@@ -177,6 +198,16 @@ func (r *Router) Route(ctx context.Context, msg Message) (string, error) {
// Title is everything after "/spawn" -- keep the multi-word text.
rest := restAfter(text, cmd, r.gatewayName)
return r.handleSpawn(ctx, rest)
case "/whoami":
return r.handleWhoami()
case "/profile":
return r.handleProfile()
case "/sessions":
return r.handleSessions(ctx)
case "/resume":
return r.handleResume(ctx, restAfter(text, cmd, r.gatewayName))
case "/agents":
return r.handleAgents(ctx)
case "/approve":
// Reserved for dangerous-command approval (archie-core-alm.6).
// Telegram hides it from its menu/help; other gateways keep it
@@ -184,14 +215,6 @@ func (r *Router) Route(ctx context.Context, msg Message) (string, error) {
return r.handleApprove(ctx, restAfter(text, cmd, r.gatewayName))
case "/cancel":
return r.handleCancel(ctx, restAfter(text, cmd, r.gatewayName))
case "/steer":
return r.handleSteer(ctx, restAfter(text, cmd, r.gatewayName))
case "/goal":
return r.handleGoal(ctx, restAfter(text, cmd, r.gatewayName))
case "/subgoal":
return r.handleSubgoal(ctx, restAfter(text, cmd, r.gatewayName))
case "/queue", "/q", "/background", "/bg", "/btw":
return r.handleQueue(ctx, restAfter(text, cmd, r.gatewayName))
default:
if strings.HasPrefix(cmd, "/") {
return fmt.Sprintf("Unknown command %s. Try /help.", cmd), nil
@@ -224,7 +247,7 @@ func (r *Router) RouteStream(ctx context.Context, msg Message, onDelta func(stri
return r.LLMStream(ctx, msg, onDelta)
}
var localCommands = []string{"/status", "/model", "/spawn", "/approve", "/cancel", "/steer", "/goal", "/subgoal", "/queue", "/q", "/background", "/bg", "/btw"}
var localCommands = []string{"/status", "/model", "/spawn", "/whoami", "/profile", "/sessions", "/resume", "/agents", "/approve", "/cancel"}
// LocalCommands returns the command names Route answers from local state.
// Gateways use this to verify that their published command surfaces match
@@ -393,202 +416,6 @@ func parseTaskControl(rest, defaultIdentity string) (identity, taskID string) {
return identity, fields[0]
}
// ── /steer ────────────────────────────────────────────────────────
func (r *Router) handleSteer(ctx context.Context, rest string) (string, error) {
if r.State == nil {
return "Steering is not configured.", nil
}
rest = strings.TrimSpace(rest)
if rest == "" {
if text, ok := r.State.PeekSteer(); ok {
return fmt.Sprintf("Pending steer: %s", text), nil
}
return "No steer pending. Usage: /steer <message> — inject after next tool call.", nil
}
r.State.SetSteer(rest)
return fmt.Sprintf("Steer queued: %s", rest), nil
}
// ── /goal ──────────────────────────────────────────────────────────
func (r *Router) handleGoal(ctx context.Context, rest string) (string, error) {
if r.State == nil {
return "Goals are not configured.", nil
}
rest = strings.TrimSpace(rest)
if rest == "" || rest == "show" {
return r.goalShow(), nil
}
subcmd, _ := splitFirst(rest)
switch subcmd {
case "draft":
return "Send a message describing what you want the goal to be, and I'll suggest one. Or use /goal <text> to set it directly.", nil
case "pause":
if !r.State.PauseGoal() {
return "No goal to pause.", nil
}
return "Goal paused.", nil
case "resume":
if !r.State.ResumeGoal() {
return "No goal to resume.", nil
}
return "Goal resumed.", nil
case "clear":
r.State.ClearGoal()
return "Goal and subgoals cleared.", nil
case "status":
return r.goalStatus(), nil
case "wait":
if !r.State.HasGoal() {
return "No goal to wait on.", nil
}
r.State.SetWait()
return "Goal wait flag set. I'll pause new work toward the goal until /goal unwait.", nil
case "unwait":
r.State.ClearWait()
return "Goal wait flag cleared. I may resume work toward the goal.", nil
default:
// Treat as goal text.
r.State.SetGoal(rest, false)
return fmt.Sprintf("Goal set: %s", rest), nil
}
}
func (r *Router) goalShow() string {
goals := r.State.Goals()
if len(goals) == 0 {
return "No goal set. Use /goal <text> to set one."
}
var b strings.Builder
b.WriteString("🎯 **Goal**")
if goals[0].Status == GoalPaused {
b.WriteString(" (paused)")
}
b.WriteString("\n")
b.WriteString(goals[0].Text)
subgoals := r.State.Subgoals()
if len(subgoals) > 0 {
b.WriteString("\n\n**Subgoals**\n")
for i, sg := range subgoals {
fmt.Fprintf(&b, "%d. %s\n", i+1, sg.Text)
}
}
if r.State.IsWaiting() {
b.WriteString("\n⏸️ Waiting — use /goal unwait to resume.")
}
return b.String()
}
func (r *Router) goalStatus() string {
goals := r.State.Goals()
if len(goals) == 0 {
return "No goal."
}
status := string(goals[0].Status)
if r.State.IsWaiting() {
status += ", waiting"
}
sgCount := len(r.State.Subgoals())
return fmt.Sprintf("Goal: %s (%d subgoals)", status, sgCount)
}
// ── /subgoal ───────────────────────────────────────────────────────
func (r *Router) handleSubgoal(ctx context.Context, rest string) (string, error) {
if r.State == nil {
return "Subgoals are not configured.", nil
}
rest = strings.TrimSpace(rest)
if rest == "" || rest == "show" {
subgoals := r.State.Subgoals()
if len(subgoals) == 0 {
return "No subgoals. Use /subgoal <text> to add one.", nil
}
var b strings.Builder
b.WriteString("**Subgoals**\n")
for i, sg := range subgoals {
fmt.Fprintf(&b, "%d. %s\n", i+1, sg.Text)
}
return b.String(), nil
}
subcmd, arg := splitFirst(rest)
switch subcmd {
case "remove":
n, err := strconv.Atoi(arg)
if err != nil || n < 1 {
return "Usage: /subgoal remove <N>", nil
}
if !r.State.RemoveSubgoal(n) {
return fmt.Sprintf("No subgoal at position %d.", n), nil
}
return fmt.Sprintf("Subgoal %d removed.", n), nil
case "clear":
r.State.ClearSubgoals()
return "Subgoals cleared.", nil
default:
if !r.State.AddSubgoal(rest) {
return "No goal set. Use /goal <text> first.", nil
}
return fmt.Sprintf("Subgoal added: %s", rest), nil
}
}
// ── /queue (aliases /q, /background, /bg, /btw) ────────────────────
func (r *Router) handleQueue(ctx context.Context, rest string) (string, error) {
if r.State == nil {
return "Queue is not configured.", nil
}
rest = strings.TrimSpace(rest)
if rest == "" || rest == "show" {
entries := r.State.QueueEntries()
if len(entries) == 0 {
return "Queue is empty. Use /queue <text> to add an item.", nil
}
var b strings.Builder
b.WriteString("**Queue**\n")
for i, e := range entries {
fmt.Fprintf(&b, "%d. %s\n", i+1, e.Text)
}
return b.String(), nil
}
subcmd, arg := splitFirst(rest)
switch subcmd {
case "remove":
n, err := strconv.Atoi(arg)
if err != nil || n < 1 {
return "Usage: /queue remove <N>", nil
}
if !r.State.RemoveFromQueue(n) {
return fmt.Sprintf("No queue item at position %d.", n), nil
}
return fmt.Sprintf("Queue item %d removed.", n), nil
case "clear":
r.State.ClearQueue()
return "Queue cleared.", nil
default:
r.State.AddToQueue(rest)
return fmt.Sprintf("Queued: %s", rest), nil
}
}
// splitFirst splits s on the first whitespace and returns the first
// field and the remainder.
func splitFirst(s string) (first, rest string) {
s = strings.TrimSpace(s)
before, after, ok := strings.Cut(s, " ")
if !ok {
return s, ""
}
return before, strings.TrimSpace(after)
}
func (r *Router) handleStatus(ctx context.Context) (string, error) {
if r.Store == nil {
return "store not configured", nil
@@ -623,3 +450,150 @@ func (r *Router) handleStatus(ctx context.Context) (string, error) {
}
return strings.TrimSpace(b.String()), nil
}
// ── /whoami ───────────────────────────────────────────────────────
func (r *Router) handleWhoami() (string, error) {
var b strings.Builder
b.WriteString("You are talking to Archie")
if r.Identity != "" {
fmt.Fprintf(&b, " (%s)", r.Identity)
}
b.WriteString(".\n")
if r.Models != nil {
if manager, ok := r.Models.(ProviderModelManager); ok {
fmt.Fprintf(&b, "Provider: %s\n", manager.ActiveProvider())
}
fmt.Fprintf(&b, "Model: %s\n", r.Models.ActiveModel())
}
return strings.TrimSpace(b.String()), nil
}
// ── /profile ──────────────────────────────────────────────────────
func (r *Router) handleProfile() (string, error) {
var b strings.Builder
fmt.Fprintf(&b, "*Archie profile*\n")
if r.Identity != "" {
fmt.Fprintf(&b, "Identity: `%s`\n", r.Identity)
} else {
b.WriteString("Identity: _(not configured)_\n")
}
if r.Models == nil {
return strings.TrimSpace(b.String()), nil
}
if manager, ok := r.Models.(ProviderModelManager); ok {
fmt.Fprintf(&b, "Provider: `%s`\n", manager.ActiveProvider())
}
fmt.Fprintf(&b, "Model: `%s`\n", r.Models.ActiveModel())
models := r.Models.Models()
if manager, ok := r.Models.(ProviderModelManager); ok {
models = manager.ModelsForProvider(manager.ActiveProvider())
}
if len(models) == 0 {
return strings.TrimSpace(b.String()), nil
}
b.WriteString("Available models:\n")
active := r.Models.ActiveModel()
for _, m := range models {
if m == active {
fmt.Fprintf(&b, " `%s` _(active)_\n", m)
} else {
fmt.Fprintf(&b, " `%s`\n", m)
}
}
return strings.TrimSpace(b.String()), nil
}
// ── /sessions ─────────────────────────────────────────────────────
func (r *Router) handleSessions(ctx context.Context) (string, error) {
if r.Sessions == nil {
return "Session listing is not configured.", nil
}
sessions, err := r.Sessions.List(ctx)
if err != nil {
return "", fmt.Errorf("sessions: %w", err)
}
if len(sessions) == 0 {
return "No sessions yet.", nil
}
var b strings.Builder
b.WriteString("*Sessions*\n")
for _, sc := range sessions {
ago := time.Since(sc.LastActiveAt).Truncate(time.Second)
fmt.Fprintf(&b, "`%s`\n last active %s ago", sc.SessionID, ago)
if sc.Source.ThreadID != "" {
fmt.Fprintf(&b, " (thread %s)", sc.Source.ThreadID)
}
b.WriteByte('\n')
}
return strings.TrimSpace(b.String()), nil
}
// ── /resume ───────────────────────────────────────────────────────
func (r *Router) handleResume(ctx context.Context, name string) (string, error) {
if r.Sessions == nil {
return "Session resume is not configured.", nil
}
if name == "" {
return "Usage: /resume <session-id or name prefix>", nil
}
sessions, err := r.Sessions.List(ctx)
if err != nil {
return "", fmt.Errorf("resume: %w", err)
}
// Match by exact session ID or prefix.
var matches []SessionContext
for _, sc := range sessions {
if sc.SessionID == name || strings.HasPrefix(sc.SessionID, name) {
matches = append(matches, sc)
}
}
if len(matches) == 0 {
return fmt.Sprintf("No session matching %q found.", name), nil
}
if len(matches) > 1 {
var b strings.Builder
b.WriteString("Multiple sessions match:\n")
for _, sc := range matches {
fmt.Fprintf(&b, " `%s`\n", sc.SessionID)
}
b.WriteString("Use the full session ID to resume a specific one.")
return b.String(), nil
}
sc := matches[0]
return fmt.Sprintf("Resumed session `%s` (last active %s ago). Send a message to continue.",
sc.SessionID, time.Since(sc.LastActiveAt).Truncate(time.Second)), nil
}
// ── /agents ───────────────────────────────────────────────────────
func (r *Router) handleAgents(ctx context.Context) (string, error) {
if r.Agents == nil {
return "Agent listing is not configured.", nil
}
agents, err := r.Agents.AgentList(ctx)
if err != nil {
return "", fmt.Errorf("agents: %w", err)
}
if len(agents) == 0 {
return "No active agents or running tasks.", nil
}
var b strings.Builder
b.WriteString("*Active agents*\n")
for _, a := range agents {
fmt.Fprintf(&b, "`%d` %s", a.ID, a.Title)
if a.Identity != "" {
fmt.Fprintf(&b, " _(%s)_", a.Identity)
}
fmt.Fprintf(&b, " \nStatus: %s\n", a.Status)
}
return strings.TrimSpace(b.String()), nil
}
+215 -452
View File
@@ -617,54 +617,105 @@ func TestRouteCancelNotConfigured(t *testing.T) {
}
}
// -- /steer tests --
// -- /whoami tests --
func routerWithState() *Router {
func TestRouteWhoami(t *testing.T) {
r := NewRouter(nil, nil, "test-gw")
r.State = NewSessionState()
return r
}
func TestRouteSteerQueuesMessage(t *testing.T) {
r := routerWithState()
reply, err := r.Route(context.Background(), Message{Text: "/steer check the logs"})
r.Identity = "archie"
reply, err := r.Route(context.Background(), Message{Text: "/whoami"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "Steer queued") {
t.Errorf("reply = %q, want confirmation", reply)
}
if text, ok := r.State.PollSteer(); !ok || text != "check the logs" {
t.Errorf("PollSteer() = (%q, %v), want (check the logs, true)", text, ok)
if !strings.Contains(reply, "archie") {
t.Errorf("reply = %q, want mention of identity", reply)
}
}
func TestRouteSteerShowsPending(t *testing.T) {
r := routerWithState()
r.State.SetSteer("pending steer")
reply, err := r.Route(context.Background(), Message{Text: "/steer"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "Pending steer") || !strings.Contains(reply, "pending steer") {
t.Errorf("reply = %q, want pending steer message", reply)
}
}
func TestRouteSteerEmpty(t *testing.T) {
r := routerWithState()
reply, err := r.Route(context.Background(), Message{Text: "/steer"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "No steer pending") {
t.Errorf("reply = %q, want usage message", reply)
}
}
func TestRouteSteerNotConfigured(t *testing.T) {
func TestRouteWhoamiNoIdentity(t *testing.T) {
r := NewRouter(nil, nil, "test-gw")
reply, err := r.Route(context.Background(), Message{Text: "/steer do x"})
reply, err := r.Route(context.Background(), Message{Text: "/whoami"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "Archie") {
t.Errorf("reply = %q, want mention of Archie", reply)
}
}
func TestRouteWhoamiWithModel(t *testing.T) {
r := NewRouter(nil, nil, "test-gw")
r.Identity = "archie"
r.Models = &fakeModelManager{
models: []string{"a/b", "c/d"},
activeModel: "a/b",
}
reply, err := r.Route(context.Background(), Message{Text: "/whoami"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "archie") || !strings.Contains(reply, "a/b") {
t.Errorf("reply = %q, want identity and model", reply)
}
}
// -- /profile tests --
func TestRouteProfile(t *testing.T) {
r := NewRouter(nil, nil, "test-gw")
r.Identity = "archie"
r.Models = &fakeModelManager{
models: []string{"a/b", "c/d"},
activeModel: "a/b",
}
reply, err := r.Route(context.Background(), Message{Text: "/profile"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "archie") || !strings.Contains(reply, "a/b") {
t.Errorf("reply = %q, want identity and model", reply)
}
}
func TestRouteProfileNoIdentity(t *testing.T) {
r := NewRouter(nil, nil, "test-gw")
reply, err := r.Route(context.Background(), Message{Text: "/profile"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "not configured") {
t.Errorf("reply = %q, want mention of not configured", reply)
}
}
// -- /sessions tests --
type fakeSessionLister struct {
sessions []SessionContext
err error
}
func (f *fakeSessionLister) List(ctx context.Context) ([]SessionContext, error) {
if f.err != nil {
return nil, f.err
}
return f.sessions, nil
}
func TestRouteSessionsEmpty(t *testing.T) {
r := NewRouter(nil, nil, "test-gw")
r.Sessions = &fakeSessionLister{}
reply, err := r.Route(context.Background(), Message{Text: "/sessions"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "No sessions") {
t.Errorf("reply = %q, want 'No sessions'", reply)
}
}
func TestRouteSessionsNotConfigured(t *testing.T) {
r := NewRouter(nil, nil, "test-gw")
reply, err := r.Route(context.Background(), Message{Text: "/sessions"})
if err != nil {
t.Fatalf("Route: %v", err)
}
@@ -673,159 +724,32 @@ func TestRouteSteerNotConfigured(t *testing.T) {
}
}
// -- /goal tests --
func TestRouteGoalSet(t *testing.T) {
r := routerWithState()
reply, err := r.Route(context.Background(), Message{Text: "/goal ship the feature"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "Goal set") || !strings.Contains(reply, "ship the feature") {
t.Errorf("reply = %q, want goal set confirmation", reply)
}
goals := r.State.Goals()
if len(goals) != 1 || goals[0].Text != "ship the feature" {
t.Errorf("Goals() = %+v, want [ship the feature]", goals)
}
}
func TestRouteGoalShow(t *testing.T) {
r := routerWithState()
r.State.SetGoal("do the thing", false)
r.State.AddSubgoal("step one")
r.State.AddSubgoal("step two")
reply, err := r.Route(context.Background(), Message{Text: "/goal"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "do the thing") {
t.Error("reply missing goal text")
}
if !strings.Contains(reply, "step one") {
t.Error("reply missing subgoal")
}
}
func TestRouteGoalShowEmpty(t *testing.T) {
r := routerWithState()
reply, err := r.Route(context.Background(), Message{Text: "/goal"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "No goal set") {
t.Errorf("reply = %q, want 'No goal set'", reply)
}
}
func TestRouteGoalPauseResume(t *testing.T) {
r := routerWithState()
r.State.SetGoal("work", false)
reply, err := r.Route(context.Background(), Message{Text: "/goal pause"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "Goal paused") {
t.Errorf("reply = %q, want Goal paused", reply)
}
reply, err = r.Route(context.Background(), Message{Text: "/goal resume"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "Goal resumed") {
t.Errorf("reply = %q, want Goal resumed", reply)
}
}
func TestRouteGoalPauseWithoutGoal(t *testing.T) {
r := routerWithState()
reply, err := r.Route(context.Background(), Message{Text: "/goal pause"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "No goal to pause") {
t.Errorf("reply = %q, want 'No goal to pause'", reply)
}
}
func TestRouteGoalClear(t *testing.T) {
r := routerWithState()
r.State.SetGoal("x", false)
r.State.AddSubgoal("y")
reply, err := r.Route(context.Background(), Message{Text: "/goal clear"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "cleared") {
t.Errorf("reply = %q, want cleared", reply)
}
if r.State.HasGoal() {
t.Error("HasGoal() = true after /goal clear")
}
if len(r.State.Subgoals()) != 0 {
t.Error("subgoals not cleared")
}
}
func TestRouteGoalStatus(t *testing.T) {
r := routerWithState()
r.State.SetGoal("g", false)
r.State.AddSubgoal("sg")
reply, err := r.Route(context.Background(), Message{Text: "/goal status"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "Goal:") || !strings.Contains(reply, "1 subgoal") {
t.Errorf("reply = %q, want status line", reply)
}
}
func TestRouteGoalWaitUnwait(t *testing.T) {
r := routerWithState()
r.State.SetGoal("g", false)
reply, err := r.Route(context.Background(), Message{Text: "/goal wait"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "wait flag set") {
t.Errorf("reply = %q, want wait flag set", reply)
}
if !r.State.IsWaiting() {
t.Error("IsWaiting() = false after /goal wait")
}
reply, err = r.Route(context.Background(), Message{Text: "/goal unwait"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "wait flag cleared") {
t.Errorf("reply = %q, want wait flag cleared", reply)
}
if r.State.IsWaiting() {
t.Error("IsWaiting() = true after /goal unwait")
}
}
func TestRouteGoalWaitWithoutGoal(t *testing.T) {
r := routerWithState()
reply, err := r.Route(context.Background(), Message{Text: "/goal wait"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "No goal to wait") {
t.Errorf("reply = %q, want 'No goal to wait'", reply)
}
}
func TestRouteGoalNotConfigured(t *testing.T) {
func TestRouteSessionsError(t *testing.T) {
r := NewRouter(nil, nil, "test-gw")
reply, err := r.Route(context.Background(), Message{Text: "/goal show"})
r.Sessions = &fakeSessionLister{err: fmt.Errorf("store unavailable")}
_, err := r.Route(context.Background(), Message{Text: "/sessions"})
if err == nil {
t.Error("expected error from Route when List fails")
}
}
// -- /resume tests --
func TestRouteResumeNoArg(t *testing.T) {
r := NewRouter(nil, nil, "test-gw")
r.Sessions = &fakeSessionLister{}
reply, err := r.Route(context.Background(), Message{Text: "/resume"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "Usage") {
t.Errorf("reply = %q, want usage", reply)
}
}
func TestRouteResumeNotConfigured(t *testing.T) {
r := NewRouter(nil, nil, "test-gw")
reply, err := r.Route(context.Background(), Message{Text: "/resume abc"})
if err != nil {
t.Fatalf("Route: %v", err)
}
@@ -834,128 +758,85 @@ func TestRouteGoalNotConfigured(t *testing.T) {
}
}
func TestRouteGoalDraft(t *testing.T) {
r := routerWithState()
reply, err := r.Route(context.Background(), Message{Text: "/goal draft"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "I'll suggest one") {
t.Errorf("reply = %q, want draft prompt", reply)
}
}
// -- /subgoal tests --
func TestRouteSubgoalAdd(t *testing.T) {
r := routerWithState()
r.State.SetGoal("goal", false)
reply, err := r.Route(context.Background(), Message{Text: "/subgoal write tests"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "Subgoal added") || !strings.Contains(reply, "write tests") {
t.Errorf("reply = %q, want confirmation", reply)
}
if len(r.State.Subgoals()) != 1 || r.State.Subgoals()[0].Text != "write tests" {
t.Error("subgoal not stored")
}
}
func TestRouteSubgoalAddWithoutGoal(t *testing.T) {
r := routerWithState()
reply, err := r.Route(context.Background(), Message{Text: "/subgoal do x"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "No goal set") {
t.Errorf("reply = %q, want 'No goal set'", reply)
}
}
func TestRouteSubgoalShow(t *testing.T) {
r := routerWithState()
r.State.SetGoal("g", false)
r.State.AddSubgoal("a")
r.State.AddSubgoal("b")
reply, err := r.Route(context.Background(), Message{Text: "/subgoal"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "a") || !strings.Contains(reply, "b") {
t.Errorf("reply = %q, want subgoals a and b", reply)
}
}
func TestRouteSubgoalShowEmpty(t *testing.T) {
r := routerWithState()
r.State.SetGoal("g", false)
reply, err := r.Route(context.Background(), Message{Text: "/subgoal"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "No subgoals") {
t.Errorf("reply = %q, want 'No subgoals'", reply)
}
}
func TestRouteSubgoalRemove(t *testing.T) {
r := routerWithState()
r.State.SetGoal("g", false)
r.State.AddSubgoal("a")
r.State.AddSubgoal("b")
r.State.AddSubgoal("c")
reply, err := r.Route(context.Background(), Message{Text: "/subgoal remove 2"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "removed") {
t.Errorf("reply = %q, want removed", reply)
}
sgs := r.State.Subgoals()
if len(sgs) != 2 || sgs[0].Text != "a" || sgs[1].Text != "c" {
t.Errorf("Subgoals() = %+v, want [a, c]", sgs)
}
}
func TestRouteSubgoalRemoveOutOfRange(t *testing.T) {
r := routerWithState()
r.State.SetGoal("g", false)
reply, err := r.Route(context.Background(), Message{Text: "/subgoal remove 5"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "No subgoal at position") {
t.Errorf("reply = %q, want 'No subgoal at position'", reply)
}
}
func TestRouteSubgoalClear(t *testing.T) {
r := routerWithState()
r.State.SetGoal("g", false)
r.State.AddSubgoal("a")
r.State.AddSubgoal("b")
reply, err := r.Route(context.Background(), Message{Text: "/subgoal clear"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "cleared") {
t.Errorf("reply = %q, want cleared", reply)
}
if len(r.State.Subgoals()) != 0 {
t.Error("Subgoals not cleared")
}
}
func TestRouteSubgoalNotConfigured(t *testing.T) {
func TestRouteResumeNoMatch(t *testing.T) {
r := NewRouter(nil, nil, "test-gw")
reply, err := r.Route(context.Background(), Message{Text: "/subgoal add x"})
r.Sessions = &fakeSessionLister{
sessions: []SessionContext{
{SessionID: "session-1"},
},
}
reply, err := r.Route(context.Background(), Message{Text: "/resume xyz"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "No session matching") {
t.Errorf("reply = %q, want 'No session matching'", reply)
}
}
func TestRouteResumeAmbiguous(t *testing.T) {
r := NewRouter(nil, nil, "test-gw")
r.Sessions = &fakeSessionLister{
sessions: []SessionContext{
{SessionID: "abc-123"},
{SessionID: "abc-456"},
},
}
reply, err := r.Route(context.Background(), Message{Text: "/resume abc"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "Multiple sessions") {
t.Errorf("reply = %q, want 'Multiple sessions'", reply)
}
}
func TestRouteResumeExactMatch(t *testing.T) {
r := NewRouter(nil, nil, "test-gw")
r.Sessions = &fakeSessionLister{
sessions: []SessionContext{
{SessionID: "abc-123"},
{SessionID: "abc-456"},
},
}
reply, err := r.Route(context.Background(), Message{Text: "/resume abc-123"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "Resumed session") {
t.Errorf("reply = %q, want 'Resumed session'", reply)
}
}
// -- /agents tests --
type fakeAgentReader struct {
agents []AgentInfo
err error
}
func (f *fakeAgentReader) AgentList(ctx context.Context) ([]AgentInfo, error) {
if f.err != nil {
return nil, f.err
}
return f.agents, nil
}
func TestRouteAgentsEmpty(t *testing.T) {
r := NewRouter(nil, nil, "test-gw")
r.Agents = &fakeAgentReader{}
reply, err := r.Route(context.Background(), Message{Text: "/agents"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "No active agents") {
t.Errorf("reply = %q, want 'No active agents'", reply)
}
}
func TestRouteAgentsNotConfigured(t *testing.T) {
r := NewRouter(nil, nil, "test-gw")
reply, err := r.Route(context.Background(), Message{Text: "/agents"})
if err != nil {
t.Fatalf("Route: %v", err)
}
@@ -964,158 +845,40 @@ func TestRouteSubgoalNotConfigured(t *testing.T) {
}
}
// -- /queue tests --
func TestRouteQueueAdd(t *testing.T) {
r := routerWithState()
reply, err := r.Route(context.Background(), Message{Text: "/queue review the PR"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "Queued") || !strings.Contains(reply, "review the PR") {
t.Errorf("reply = %q, want confirmation", reply)
}
if n := r.State.QueueLen(); n != 1 {
t.Errorf("QueueLen() = %d, want 1", n)
}
}
func TestRouteQueueShow(t *testing.T) {
r := routerWithState()
r.State.AddToQueue("a")
r.State.AddToQueue("b")
reply, err := r.Route(context.Background(), Message{Text: "/queue"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "a") || !strings.Contains(reply, "b") {
t.Errorf("reply = %q, want queue contents", reply)
}
}
func TestRouteQueueShowEmpty(t *testing.T) {
r := routerWithState()
reply, err := r.Route(context.Background(), Message{Text: "/queue"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "empty") {
t.Errorf("reply = %q, want 'empty'", reply)
}
}
func TestRouteQueueRemove(t *testing.T) {
r := routerWithState()
r.State.AddToQueue("a")
r.State.AddToQueue("b")
r.State.AddToQueue("c")
reply, err := r.Route(context.Background(), Message{Text: "/queue remove 2"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "removed") {
t.Errorf("reply = %q, want removed", reply)
}
entries := r.State.QueueEntries()
if len(entries) != 2 || entries[0].Text != "a" || entries[1].Text != "c" {
t.Errorf("QueueEntries() = %+v, want [a, c]", entries)
}
}
func TestRouteQueueClear(t *testing.T) {
r := routerWithState()
r.State.AddToQueue("a")
r.State.AddToQueue("b")
reply, err := r.Route(context.Background(), Message{Text: "/queue clear"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "cleared") {
t.Errorf("reply = %q, want cleared", reply)
}
if n := r.State.QueueLen(); n != 0 {
t.Errorf("QueueLen() = %d, want 0", n)
}
}
func TestRouteQueueAliases(t *testing.T) {
for _, cmd := range []string{"/q add this", "/background add this", "/bg add this", "/btw add this"} {
t.Run(cmd, func(t *testing.T) {
r := routerWithState()
reply, err := r.Route(context.Background(), Message{Text: cmd})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "Queued") {
t.Errorf("alias %q reply = %q, want Queued", cmd, reply)
}
if n := r.State.QueueLen(); n != 1 {
t.Errorf("QueueLen() = %d, want 1", n)
}
})
}
}
func TestRouteQueueNotConfigured(t *testing.T) {
func TestRouteAgentsWithTasks(t *testing.T) {
r := NewRouter(nil, nil, "test-gw")
reply, err := r.Route(context.Background(), Message{Text: "/queue show"})
r.Agents = &fakeAgentReader{
agents: []AgentInfo{
{ID: 1, Title: "Fix the bug", Status: "running", Identity: "archie"},
{ID: 2, Title: "Add tests", Status: "waiting_human", Identity: "archie"},
},
}
reply, err := r.Route(context.Background(), Message{Text: "/agents"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "not configured") {
t.Errorf("reply = %q, want 'not configured'", reply)
if !strings.Contains(reply, "Fix the bug") || !strings.Contains(reply, "Add tests") {
t.Errorf("reply = %q, want task titles", reply)
}
if !strings.Contains(reply, "running") || !strings.Contains(reply, "waiting_human") {
t.Errorf("reply = %q, want task statuses", reply)
}
}
// -- /goal show includes subgoals and wait status --
func TestRouteGoalShowWithWait(t *testing.T) {
r := routerWithState()
r.State.SetGoal("big goal", false)
r.State.SetWait()
reply, err := r.Route(context.Background(), Message{Text: "/goal"})
if err != nil {
t.Fatalf("Route: %v", err)
}
if !strings.Contains(reply, "Waiting") {
t.Errorf("reply = %q, want Waiting indicator", reply)
func TestRouteAgentsError(t *testing.T) {
r := NewRouter(nil, nil, "test-gw")
r.Agents = &fakeAgentReader{err: fmt.Errorf("store unavailable")}
_, err := r.Route(context.Background(), Message{Text: "/agents"})
if err == nil {
t.Error("expected error from Route when AgentList fails")
}
}
// -- LocalCommands includes the new commands --
func TestLocalCommandsIncludesNewCommands(t *testing.T) {
cmds := LocalCommands()
want := []string{"/steer", "/goal", "/subgoal", "/queue", "/q", "/background", "/bg", "/btw"}
for _, w := range want {
found := slices.Contains(cmds, w)
if !found {
t.Errorf("LocalCommands() missing %q", w)
}
}
}
func TestSplitFirst(t *testing.T) {
tests := []struct {
input string
wantFirst string
wantRest string
}{
{"show", "show", ""},
{"remove 2", "remove", "2"},
{"add do the thing", "add", "do the thing"},
{" pause ", "pause", ""},
{"", "", ""},
}
for _, tt := range tests {
first, rest := splitFirst(tt.input)
if first != tt.wantFirst || rest != tt.wantRest {
t.Errorf("splitFirst(%q) = (%q, %q), want (%q, %q)",
tt.input, first, rest, tt.wantFirst, tt.wantRest)
for _, want := range []string{"/whoami", "/profile", "/sessions", "/resume", "/agents"} {
if !slices.Contains(cmds, want) {
t.Errorf("LocalCommands() missing %s", want)
}
}
}