diff --git a/internal/gateway/desktop.go b/internal/gateway/desktop.go index 8a149e3c8..0cef47438 100644 --- a/internal/gateway/desktop.go +++ b/internal/gateway/desktop.go @@ -425,20 +425,7 @@ func desktopNames(entries []provider.Entry) []string { // or without Claude Code's "[1m]"; or Claude Science's, // claude-magpie-. func aliased(id string) (string, bool) { - id = strings.TrimSuffix(id, "[1m]") - var number string - if n, ok := strings.CutPrefix(id, desktopAlias); ok { - number = n - } else if n, ok := strings.CutPrefix(id, desktopEffortAlias); ok { - number = n - } else if n, ok := strings.CutPrefix(id, scienceAlias); ok { - // Claude Science's (science.go) - number = n - } else if rest, ok := strings.CutPrefix(id, "magpie-"); ok { - if i := strings.Index(rest, desktopClaudeInfix); i > 0 { - number = rest[:i] - } - } + number := aliasDigits(id) if len(number) != 10 { return "", false } @@ -462,20 +449,27 @@ func aliased(id string) (string, bool) { // old alias is served all the same, and a reply to it must not name the // alias either (#4667). func magpieAliasAsked(id string) bool { + n := aliasDigits(id) + return len(n) == 10 && strings.IndexFunc(n, func(r rune) bool { return r < '0' || r > '9' }) < 0 +} + +// aliasDigits is the number in one of magpie's alias ids (aliased's forms, +// with or without Claude Code's "[1m]"), "" when id has none of the forms. +func aliasDigits(id string) string { id = strings.TrimSuffix(id, "[1m]") - var n string - if rest, ok := strings.CutPrefix(id, desktopAlias); ok { - n = rest - } else if rest, ok := strings.CutPrefix(id, desktopEffortAlias); ok { - n = rest - } else if rest, ok := strings.CutPrefix(id, scienceAlias); ok { - n = rest + if n, ok := strings.CutPrefix(id, desktopAlias); ok { + return n + } else if n, ok := strings.CutPrefix(id, desktopEffortAlias); ok { + return n + } else if n, ok := strings.CutPrefix(id, scienceAlias); ok { + // Claude Science's (science.go) + return n } else if rest, ok := strings.CutPrefix(id, "magpie-"); ok { if i := strings.Index(rest, desktopClaudeInfix); i > 0 { - n = rest[:i] + return rest[:i] } } - return len(n) == 10 && strings.IndexFunc(n, func(r rune) bool { return r < '0' || r > '9' }) < 0 + return "" } // isClaudeDesktop is a request from Claude Desktop's own gateway client: its