fix: compilation errors in commands and providers

This commit is contained in:
Bernardo 2026-03-10 19:24:27 +01:00
parent 81841df578
commit b068f6ae44
4 changed files with 27 additions and 42 deletions

View file

@ -10,57 +10,54 @@ import (
func acpCommand() Definition { func acpCommand() Definition {
return Definition{ return Definition{
Prefix: "acp", Name: "acp",
Description: "Agent Client Protocol capabilities (e.g. acp spawn, status, close)", Description: "Agent Client Protocol capabilities (e.g. acp spawn, status, close)",
Category: "System",
Usage: "/acp <action> [args...]", Usage: "/acp <action> [args...]",
Handler: func(ctx context.Context, args string, rt Runtime) error { Handler: func(ctx context.Context, req Request, rt *Runtime) error {
parts := strings.Fields(args) parts := strings.Fields(req.Text)
if len(parts) == 0 { if len(parts) < 2 {
return fmt.Errorf("missing acp action (spawn, status, close)") return req.Reply("Usage: /acp <action> [args...]")
} }
action := parts[0] action := parts[1]
switch action { switch action {
case "spawn": case "spawn":
if len(parts) < 2 { if len(parts) < 3 {
return fmt.Errorf("usage: /acp spawn <harness_id>") return req.Reply("usage: /acp spawn <harness_id>")
} }
harness := parts[1] harness := parts[2]
session, err := acp.GetManager().Spawn(harness, "session", harness, "", "cli-spawned", []string{}) session, err := acp.GetManager().Spawn(harness, "session", harness, "", "cli-spawned", []string{})
if err != nil { 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": case "status":
sessions := acp.GetManager().ListSessions() sessions := acp.GetManager().ListSessions()
if len(sessions) == 0 { if len(sessions) == 0 {
rt.PrintSysMessage("No active ACP sessions.") return req.Reply("No active ACP sessions.")
return nil
} }
var b strings.Builder var b strings.Builder
b.WriteString("Active ACP Sessions:\n") b.WriteString("Active ACP Sessions:\n")
for _, s := range sessions { for _, s := range sessions {
b.WriteString(fmt.Sprintf("- Key: %s | Harness: %s | Status: %s\n", s.Key, s.AgentID, s.Status())) 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": case "close":
if len(parts) < 2 { if len(parts) < 3 {
return fmt.Errorf("usage: /acp close <session_key>") return req.Reply("usage: /acp close <session_key>")
} }
key := parts[1] key := parts[2]
err := acp.GetManager().CloseSession(key) err := acp.GetManager().CloseSession(key)
if err != nil { 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: default:
return fmt.Errorf("unknown acp action: %s", action) return req.Reply(fmt.Sprintf("unknown acp action: %s", action))
} }
return nil
}, },
} }
} }

View file

@ -4,6 +4,8 @@ import (
"context" "context"
"fmt" "fmt"
"strings" "strings"
"github.com/sipeed/picoclaw/pkg/auth"
) )
func versionCommand() Definition { func versionCommand() Definition {

View file

@ -13,40 +13,27 @@ func whatsappCommand() Definition {
return Definition{ return Definition{
Name: "whatsapp", Name: "whatsapp",
Description: "WhatsApp management commands", Description: "WhatsApp management commands",
Subcommands: []Definition{ SubCommands: []SubCommand{
{ {
Name: "qr", Name: "qr",
Description: "Get the latest WhatsApp pairing QR code", 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") ch, ok := rt.GetChannel("whatsapp_native")
if !ok { if !ok {
return ExecuteResult{ return req.Reply("whatsapp_native channel is not enabled")
Outcome: OutcomeHandled,
Err: fmt.Errorf("whatsapp_native channel is not enabled"),
}
} }
qp, ok := ch.(qrProvider) qp, ok := ch.(qrProvider)
if !ok { if !ok {
return ExecuteResult{ return req.Reply("whatsapp_native channel does not support QR retrieval")
Outcome: OutcomeHandled,
Err: fmt.Errorf("whatsapp_native channel does not support QR retrieval"),
}
} }
qr := qp.GetLastQR() qr := qp.GetLastQR()
if qr == "" { if qr == "" {
return ExecuteResult{ return req.Reply("no QR code available yet. please wait for the channel to initialize")
Outcome: OutcomeHandled,
Err: fmt.Errorf("no QR code available yet. please wait for the channel to initialize"),
}
} }
// For now, return the QR code string. return req.Reply(fmt.Sprintf("Scan this QR code string (or wait for image support): %s", qr))
// 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}
}, },
}, },
}, },

View file

@ -1,7 +1,6 @@
package providers package providers
import ( import (
"strings"
"github.com/sipeed/picoclaw/pkg/config" "github.com/sipeed/picoclaw/pkg/config"
) )