Review of Leon Zhao's Lody import (the two commits before this):
- Detection: a bare ~/.lody or ~/.lody-oss another tool made counted as
Lody. Now the home folder counts only with an entry Lody makes there
(workspace-catalog.json, loro-repo, agent-binaries, code-collab-v2, all
in the owner's real ~/.lody). A Lody.app counts only with an ai.lody.
bundle id (the real /Applications/Lody.app is ai.lody.desktop, and
registers the lody scheme) or a plist that isn't XML. Electron's data
folder under os.UserConfigDir (Application Support / %APPDATA% /
~/.config, "Lody", "Lody OSS", "Lody Nightly") still counts as before.
A never-opened install on Windows or Linux has no folder and isn't
shown; said in agent-wiring.md.
- Security: TestLodyLinkCarriesNoSecret turns LAN sharing on and checks
the link holds magpie-lody and never the LAN key, every endpoint is
loopback http, and MAGPIE_ADDR pinned beyond loopback gives no link at
all (0.0.0.0, 127.0.0.1 and [::1] still give one).
- `magpie lody add` with no link (a LAN-pinned gateway) said it opened
Lody and opened ""; it now says why and opens nothing.
- Added *bool: every consumer re-read. The CLI and TUI use agent.Agent's
func (nil-safe), the GUI reads a.added == null, and Cindy's false is now
sent as "added":false. TestLodyImportHandoff also checks Cindy's row
says false and Lody's leaves added out; the handoff test's ~/.lody
holds a catalog file now and checks it is left byte for byte.
- The hint "Opens {name} to add magpie as a provider — confirm it there"
was already translated in zh, zh-TW, ja and de (the import button's
tooltip). import-row now runs in all five languages, asserts Lody's
exact translated line and that no added/not-added wording shows, and
checks both import rows fit a 420px window with no sideways scroll
(waiting for the header's segments to settle after the resize, which
overflow for ~300ms in WebKit en on main too).
Run (on origin/main 4a6bf80f4 + Leon's two; after rebasing onto
dcf292cc8, a routing-only CSS change, import-row, agent-layout,
group-editor-align and i18n-keys were run again in both engines, 47/47,
with the Lody/Cindy/Import Go tests in agent and gui, ok):
- go test -tags nogui -count=1 -timeout 45m ./... under a sandbox HOME
(scratchpad dir, XDG_* there too, Go caches pinned): 64 packages ok,
exit 0 (agent 607s, gateway 674s, gui 130s, provider 219s).
- gofmt -l .: clean. go vet: darwin ./..., GOOS=linux -tags nogui ./...,
GOOS=windows ./...: clean.
- GUI, playwright 1.62.0, Chromium and WebKit: import-row 20/20 (5
languages x added/not x 2 engines, 960/700/420px); i18n-keys, gui-de,
gui-ja, gui-zh-tw, agent-layout, agent-connect, plugin-agent,
agent-cli-missing, agent-connected-unfolded, agent-bulk-visibility,
agents-hidden-last: 116/116.
Broken by hand, each went red, then restored:
- a bare ~/.lody counting again: TestLodyDetectionAndRegistration;
- any Lody.app counting: TestLodyBundle (com.example.lody, ai.lodyx.);
- the loopback switch removed: TestLodyLinkCarriesNoSecret (LAN-pinned
addresses got a link);
- the key taken from agentKeyAt at a LAN address: the LAN key showed in
the link, red;
- Cindy's false left out of state(): TestLodyImportHandoff;
- app.js's unknown-status branch taken out: import-row red in every
language; the de translation removed: import-row de red.
Not tried: Lody opening the link for real (Leon ran Lody's parser), and
Windows or Linux Lody installs.
131 lines
4.1 KiB
Go
131 lines
4.1 KiB
Go
package agent
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"encoding/json"
|
|
"net/url"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/yetone/magpie/internal/gateway"
|
|
)
|
|
|
|
// LodyScheme opens Lody's local-machine provider confirmation dialog.
|
|
const LodyScheme = "lody://provider/import?"
|
|
|
|
// LodyLink offers all supported runtimes. Lody accepts only loopback HTTP
|
|
// and its public attribution token, never a LAN key or a vendor credential.
|
|
func LodyLink(base string) string {
|
|
u, err := url.Parse(base)
|
|
if err != nil || u.Scheme != "http" || u.User != nil || u.ForceQuery || u.RawQuery != "" || u.Fragment != "" || (u.Path != "" && u.Path != "/") {
|
|
return ""
|
|
}
|
|
switch u.Hostname() {
|
|
case "127.0.0.1", "localhost", "::1":
|
|
default:
|
|
return ""
|
|
}
|
|
if strings.HasSuffix(u.Host, ":") || (u.Hostname() == "::1" && !strings.HasPrefix(u.Host, "[::1]")) {
|
|
return ""
|
|
}
|
|
host := u.Hostname()
|
|
if host == "::1" {
|
|
host = "[::1]"
|
|
}
|
|
if port := u.Port(); port != "" {
|
|
n, err := strconv.Atoi(port)
|
|
if err != nil || n < 1 || n > 65535 {
|
|
return ""
|
|
}
|
|
if n != 80 {
|
|
host += ":" + strconv.Itoa(n)
|
|
}
|
|
}
|
|
base = "http://" + host
|
|
type endpoint struct {
|
|
Protocol string `json:"protocol"`
|
|
BaseURL string `json:"baseUrl"`
|
|
Targets []string `json:"targets"`
|
|
ModelsURL string `json:"modelsUrl"`
|
|
}
|
|
payload := struct {
|
|
Kind string `json:"kind"`
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Auth map[string]string `json:"auth"`
|
|
Endpoints []endpoint `json:"endpoints"`
|
|
}{
|
|
Kind: "custom", ID: "magpie", Name: "Magpie",
|
|
Auth: map[string]string{"method": "apiKey", "apiKey": gateway.TokenFor("lody")},
|
|
Endpoints: []endpoint{
|
|
{"anthropic-messages", base, []string{"claude-code"}, base + "/v1/models"},
|
|
{"openai-responses", base + "/v1", []string{"codex"}, base + "/v1/models"},
|
|
{"openai-chat", base + "/v1", []string{"pi", "dsh", "kimi-code", "grok", "bub"}, base + "/v1/models"},
|
|
},
|
|
}
|
|
b, _ := json.Marshal(payload)
|
|
return LodyScheme + "v=1&data=" + base64.RawURLEncoding.EncodeToString(b)
|
|
}
|
|
|
|
// lodyMarks are entries Lody makes in its home folder (~/.lody, or
|
|
// ~/.lody-oss for its OSS build) once it has run: a folder of that name
|
|
// another tool made, with none of them in it, isn't Lody.
|
|
var lodyMarks = []string{"workspace-catalog.json", "loro-repo", "agent-binaries", "code-collab-v2"}
|
|
|
|
// lodyNames are the names Lody's builds go by: its app bundle on a Mac and
|
|
// its data folder under the OS's config folder (Electron's userData:
|
|
// ~/Library/Application Support/Lody, %APPDATA%\Lody, ~/.config/Lody).
|
|
var lodyNames = []string{"Lody", "Lody OSS", "Lody Nightly"}
|
|
|
|
// lodyBundle reports whether an app bundle in folders is one of Lody's:
|
|
// ai.lody.desktop (or another ai.lody. build), or a plist that isn't XML,
|
|
// which says nothing either way. A Lody.app of another vendor's isn't.
|
|
func lodyBundle(folders []string) bool {
|
|
for _, dir := range folders {
|
|
for _, name := range lodyNames {
|
|
b, err := os.ReadFile(filepath.Join(dir, name+".app", "Contents", "Info.plist"))
|
|
if err != nil {
|
|
continue
|
|
}
|
|
if id := plistIDRe.FindSubmatch(b); id == nil || strings.HasPrefix(strings.TrimSpace(string(id[1])), "ai.lody.") {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func lody(home string) *Agent {
|
|
homes := []string{filepath.Join(home, ".lody"), filepath.Join(home, ".lody-oss")}
|
|
var dirs []string
|
|
if cfg, err := os.UserConfigDir(); err == nil {
|
|
for _, name := range lodyNames {
|
|
dirs = append(dirs, filepath.Join(cfg, name))
|
|
}
|
|
}
|
|
return &Agent{
|
|
ID: "lody", Name: "Lody", Icon: "lody", UA: []string{"lody"},
|
|
detect: func() bool {
|
|
for _, dir := range homes {
|
|
for _, m := range lodyMarks {
|
|
if _, err := os.Stat(filepath.Join(dir, m)); err == nil {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
for _, dir := range dirs {
|
|
if isDir(dir) {
|
|
return true
|
|
}
|
|
}
|
|
return runtime.GOOS == "darwin" && lodyBundle(macAppFolders(home))
|
|
},
|
|
Import: func() string { return LodyLink(gateway.URL()) },
|
|
// There is no public status API. Never infer import success from a
|
|
// click, generated runtime files, or Lody's private document store.
|
|
}
|
|
}
|