diff --git a/pkg/commands/cmd_acp.go b/pkg/commands/cmd_acp.go index 9e9260ff9..22657dd39 100644 --- a/pkg/commands/cmd_acp.go +++ b/pkg/commands/cmd_acp.go @@ -10,57 +10,54 @@ import ( func acpCommand() Definition { return Definition{ - Prefix: "acp", + Name: "acp", Description: "Agent Client Protocol capabilities (e.g. acp spawn, status, close)", - Category: "System", Usage: "/acp [args...]", - Handler: func(ctx context.Context, args string, rt Runtime) error { - parts := strings.Fields(args) - if len(parts) == 0 { - return fmt.Errorf("missing acp action (spawn, status, close)") + Handler: func(ctx context.Context, req Request, rt *Runtime) error { + parts := strings.Fields(req.Text) + if len(parts) < 2 { + return req.Reply("Usage: /acp [args...]") } - action := parts[0] + action := parts[1] switch action { case "spawn": - if len(parts) < 2 { - return fmt.Errorf("usage: /acp spawn ") + if len(parts) < 3 { + return req.Reply("usage: /acp spawn ") } - harness := parts[1] + harness := parts[2] session, err := acp.GetManager().Spawn(harness, "session", harness, "", "cli-spawned", []string{}) if err != nil { - return fmt.Errorf("failed to spawn ACP session: %v", err) + return req.Reply(fmt.Sprintf("failed to spawn ACP session: %v", err)) } - rt.PrintSysMessage(fmt.Sprintf("✓ Spawned ACP harness '%s'. Session Key: %s", harness, session.Key)) + return req.Reply(fmt.Sprintf("✓ Spawned ACP harness '%s'. Session Key: %s", harness, session.Key)) case "status": sessions := acp.GetManager().ListSessions() if len(sessions) == 0 { - rt.PrintSysMessage("No active ACP sessions.") - return nil + return req.Reply("No active ACP sessions.") } var b strings.Builder b.WriteString("Active ACP Sessions:\n") for _, s := range sessions { b.WriteString(fmt.Sprintf("- Key: %s | Harness: %s | Status: %s\n", s.Key, s.AgentID, s.Status())) } - rt.PrintSysMessage(b.String()) + return req.Reply(b.String()) case "close": - if len(parts) < 2 { - return fmt.Errorf("usage: /acp close ") + if len(parts) < 3 { + return req.Reply("usage: /acp close ") } - key := parts[1] + key := parts[2] err := acp.GetManager().CloseSession(key) if err != nil { - return fmt.Errorf("failed to close session: %v", err) + return req.Reply(fmt.Sprintf("failed to close session: %v", err)) } - rt.PrintSysMessage(fmt.Sprintf("✓ Closed ACP session %s", key)) + return req.Reply(fmt.Sprintf("✓ Closed ACP session %s", key)) default: - return fmt.Errorf("unknown acp action: %s", action) + return req.Reply(fmt.Sprintf("unknown acp action: %s", action)) } - return nil }, } } diff --git a/pkg/commands/cmd_system.go b/pkg/commands/cmd_system.go index dce896a9e..d92806921 100644 --- a/pkg/commands/cmd_system.go +++ b/pkg/commands/cmd_system.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "strings" + + "github.com/sipeed/picoclaw/pkg/auth" ) func versionCommand() Definition { diff --git a/pkg/commands/cmd_whatsapp.go b/pkg/commands/cmd_whatsapp.go index 72096d1f1..7b9b4b51d 100644 --- a/pkg/commands/cmd_whatsapp.go +++ b/pkg/commands/cmd_whatsapp.go @@ -13,40 +13,27 @@ func whatsappCommand() Definition { return Definition{ Name: "whatsapp", Description: "WhatsApp management commands", - Subcommands: []Definition{ + SubCommands: []SubCommand{ { Name: "qr", Description: "Get the latest WhatsApp pairing QR code", - Handler: func(ctx context.Context, req Request, rt Runtime) ExecuteResult { + Handler: func(ctx context.Context, req Request, rt *Runtime) error { ch, ok := rt.GetChannel("whatsapp_native") if !ok { - return ExecuteResult{ - Outcome: OutcomeHandled, - Err: fmt.Errorf("whatsapp_native channel is not enabled"), - } + return req.Reply("whatsapp_native channel is not enabled") } qp, ok := ch.(qrProvider) if !ok { - return ExecuteResult{ - Outcome: OutcomeHandled, - Err: fmt.Errorf("whatsapp_native channel does not support QR retrieval"), - } + return req.Reply("whatsapp_native channel does not support QR retrieval") } qr := qp.GetLastQR() if qr == "" { - return ExecuteResult{ - Outcome: OutcomeHandled, - Err: fmt.Errorf("no QR code available yet. please wait for the channel to initialize"), - } + return req.Reply("no QR code available yet. please wait for the channel to initialize") } - // For now, return the QR code string. - // Optimization: In the future, we can return an image reference. - _ = req.Reply(fmt.Sprintf("Scan this QR code string (or wait for image support): %s", qr)) - - return ExecuteResult{Outcome: OutcomeHandled} + return req.Reply(fmt.Sprintf("Scan this QR code string (or wait for image support): %s", qr)) }, }, }, diff --git a/pkg/providers/builtin_resolvers.go b/pkg/providers/builtin_resolvers.go index 7386af7da..cf440069c 100644 --- a/pkg/providers/builtin_resolvers.go +++ b/pkg/providers/builtin_resolvers.go @@ -1,7 +1,6 @@ package providers import ( - "strings" "github.com/sipeed/picoclaw/pkg/config" )