Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(cli): prefer exact agent names for squads and autopilots (#10215)

Bohan Jiangea619f7f78e7
diff --git a/server/cmd/multica/cmd_autopilot.go b/server/cmd/multica/cmd_autopilot.go
index aeab37911f..555f51a777 100644
--- a/server/cmd/multica/cmd_autopilot.go
+++ b/server/cmd/multica/cmd_autopilot.go
@@ -1015,8 +1015,8 @@ func resolveAutopilotSubscriberInputs(ctx context.Context, client *cli.APIClient
// uuidRegexp matches a canonical UUID (8-4-4-4-12 hex).
var uuidRegexp = regexp.MustCompile(`^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$`)
-// resolveAgent accepts either a UUID or an agent name (case-insensitive substring)
-// and returns the agent's UUID. Errors on no match or ambiguous match.
+// resolveAgent passes UUIDs through and otherwise resolves workspace agents
+// using the shared ID, exact-name, and substring matching rules.
func resolveAgent(ctx context.Context, client *cli.APIClient, nameOrID string) (string, error) {
if uuidRegexp.MatchString(nameOrID) {
return nameOrID, nil
@@ -1031,26 +1031,13 @@ func resolveAgent(ctx context.Context, client *cli.APIClient, nameOrID string) (
return "", fmt.Errorf("fetch agents: %w", err)
}
- nameLower := strings.ToLower(nameOrID)
- type match struct{ ID, Name string }
- var matches []match
+ candidates := make([]assigneeCandidate, 0, len(agents))
for _, a := range agents {
- aName := strVal(a, "name")
- if strings.Contains(strings.ToLower(aName), nameLower) {
- matches = append(matches, match{ID: strVal(a, "id"), Name: aName})
- }
+ candidates = append(candidates, assigneeCandidate{assigneeMatch: assigneeMatch{
+ Type: "agent", ID: strVal(a, "id"), Name: strVal(a, "name"),
+ }})
}
- switch len(matches) {
- case 0:
- return "", fmt.Errorf("no agent found matching %q", nameOrID)
- case 1:
- return matches[0].ID, nil
- default:
- var parts []string
- for _, m := range matches {
- parts = append(parts, fmt.Sprintf(" %q (%s)", m.Name, truncateID(m.ID)))
- }
- return "", fmt.Errorf("ambiguous agent %q; matches:\n%s", nameOrID, strings.Join(parts, "\n"))
- }
+ _, agentID, err := matchAssignee(nameOrID, assigneeKinds{agent: true}, candidates)
+ return agentID, err
}
diff --git a/server/cmd/multica/cmd_autopilot_test.go b/server/cmd/multica/cmd_autopilot_test.go
index 53cb0ad6b4..b9960ea038 100644
--- a/server/cmd/multica/cmd_autopilot_test.go
+++ b/server/cmd/multica/cmd_autopilot_test.go
@@ -450,6 +450,115 @@ func TestResolveAgent(t *testing.T) {
})
}
+func TestResolveAgentOverlappingNames(t *testing.T) {
+ const (
+ reviewerID = "f656eab8-1111-1111-1111-111111111111"
+ claudeID = "9b0ff9a2-2222-2222-2222-222222222222"
+ )
+
+ tests := []struct {
+ name string
+ input string
+ wantID string
+ reverse bool
+ duplicate bool
+ wantAmbiguous bool
+ }{
+ {
+ name: "exact shorter name wins",
+ input: "Reviewer",
+ wantID: reviewerID,
+ },
+ {
+ name: "exact match ignores case",
+ input: "rEvIeWeR",
+ wantID: reviewerID,
+ },
+ {
+ name: "exact match is independent of directory order",
+ input: "reviewer",
+ wantID: reviewerID,
+ reverse: true,
+ },
+ {
+ name: "surrounding whitespace is normalized",
+ input: " Reviewer ",
+ wantID: reviewerID,
+ },
+ {
+ name: "at-prefixed name is normalized",
+ input: "@reviewer",
+ wantID: reviewerID,
+ },
+ {
+ name: "short ID uses shared assignee matching",
+ input: "f656eab8",
+ wantID: reviewerID,
+ },
+ {
+ name: "agent mention uses shared assignee matching",
+ input: "[Reviewer](mention://agent/" + reviewerID + ")",
+ wantID: reviewerID,
+ },
+ {
+ name: "unique substring still resolves",
+ input: "claude",
+ wantID: claudeID,
+ },
+ {
+ name: "substring without exact match remains ambiguous",
+ input: "review",
+ wantAmbiguous: true,
+ },
+ {
+ name: "duplicate full names remain ambiguous",
+ input: "Reviewer",
+ duplicate: true,
+ wantAmbiguous: true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ agents := []map[string]any{
+ {"id": reviewerID, "name": "Reviewer"},
+ {"id": claudeID, "name": "Claude Reviewer"},
+ }
+ if tt.reverse {
+ agents[0], agents[1] = agents[1], agents[0]
+ }
+ if tt.duplicate {
+ agents = append(agents, map[string]any{
+ "id": "33333333-3333-3333-3333-333333333333", "name": "reviewer",
+ })
+ }
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if r.Method != http.MethodGet || r.URL.Path != "/api/agents" || r.URL.Query().Get("workspace_id") != "ws-1" {
+ t.Errorf("unexpected request: %s %s", r.Method, r.URL.String())
+ http.NotFound(w, r)
+ return
+ }
+ json.NewEncoder(w).Encode(agents)
+ }))
+ defer srv.Close()
+
+ client := cli.NewAPIClient(srv.URL, "ws-1", "test-token")
+ got, err := resolveAgent(context.Background(), client, tt.input)
+ if tt.wantAmbiguous {
+ if err == nil || !strings.Contains(err.Error(), "ambiguous") {
+ t.Fatalf("got (%q, %v), want ambiguity error", got, err)
+ }
+ if tt.duplicate && strings.Contains(err.Error(), "Claude Reviewer") {
+ t.Fatalf("duplicate full-name error includes substring-only match: %v", err)
+ }
+ return
+ }
+ if err != nil || got != tt.wantID {
+ t.Fatalf("got (%q, %v), want (%q, nil)", got, err, tt.wantID)
+ }
+ })
+ }
+}
+
func TestRunAutopilotCreateSendsProjectID(t *testing.T) {
const (
agentID = "11111111-1111-1111-1111-111111111111"