Files
magpie/internal/cli
yetone 4dfd88206e agent: Lody on Linux is run with its import link, which xdg-open turned away (Atlas on Discord)
Atlas (Discord #help, 10-25, Linux): Lody was running, and adding it
from magpie said "failed to open uri". magpie handed the
lody://provider/import link to xdg-open, as every OS's opener.

Cause, shown with the real Lody 0.108.1 AppImage in an amd64 Ubuntu
24.04 container (Xvfb, no update-desktop-database, as on many
desktops): Lody writes ~/.local/share/applications/ai.lody.desktop.desktop
with MimeType x-scheme-handler/ai.lody.stable and x-scheme-handler/lody,
but runs `xdg-mime default` for ai.lody.stable only. lody:// then rests
on the desktop database cache, which nothing built, so
`xdg-open lody://...` answers "gio: lody://...: Operation not supported"
(rc 4) while ai.lody.stable:// opens. With update-desktop-database run,
both open. The same on GNOME and XFCE with a fake handler at that entry.

Fix: on Linux agent.OpenLody runs what xdg-open would have run, the
Exec line of Lody's own desktop entry (ai.lody.desktop, then
ai.lody.desktop.nightly, then dev.loro.lody.oss; $XDG_DATA_HOME before
$XDG_DATA_DIRS, the first file of a name decides), with %U as the link.
An entry whose program is gone, no entry, or a start that fails falls
back to the opener as before. macOS (Info.plist claims lody:) and
Windows (Lody registers lody itself) are unchanged. The GUI's
/api/open and `magpie lody add` both go through it.

Tests: TestOpenLodyRunsItsDesktopEntry and TestDesktopExec
(internal/agent), TestLodyImportRunsLodyOnLinux (internal/gui, Linux
only). The GUI test is red on the old providers.go in golang:1.26.8
docker ("the link went to xdg-open: lody://..."), green on this one.
TestLodyImportHandoff now sets XDG_DATA_HOME/XDG_DATA_DIRS to its
sandbox, and XDG_DATA_DIRS is in TestFolderVarsAreListed's notAnAgent
(the system's data folders; the first run of internal/agent was red on
it until then).

Not covered, and Lody's to change: magpie on a machine Lody Desktop
reaches as a remote (Atlas's later detail: Lody on their own computer
connected to the host magpie runs on). Lody 0.108.1 imports only into
the desktop's own machine (the renderer writes the configs with
machineId = its local machine and needs __LODY_ELECTRON__), and the
link's payload takes only kind/id/name/auth/endpoints with a loopback
gateway, so no link names another machine. Lody Desktop opened on that
host shares the agent's ~/.lody/machine-id, so the import lands on the
same machine; docs/subsystems/agent-wiring.md says so.

Run:
- real Lody 0.108.1 AppImage in docker: agent.OpenLody reached a
  running Lody (its log: "handleDeepLink accepted deep link {protocol
  'lody:', host 'provider', pathname '/import'}", "sending deep link to
  renderer") and a stopped one ("pending deep link sent to renderer
  after did-finish-load"); xdg-open on the same link: rc 4.
- golang:1.26.8 docker, -tags nogui: agent and gui Lody tests ok.
- macOS: HOME=<sandbox> go test -timeout 45m -count=1 ./internal/agent
  ./internal/gui ./internal/cli: gui ok (124.9s), cli ok (48.6s), agent
  FAIL on TestFolderVarsAreListed (XDG_DATA_DIRS, fixed here); agent
  again after the fix: ok (213.5s).
- rebased on origin/main c6768f06f (5 commits, providers.go among them): the
  Lody, DesktopExec and FolderVars tests of agent, gui and cli ok again.
- gofmt -l clean; GOOS=linux go vet -tags nogui ./... ok;
  GOOS=windows go vet ./internal/agent ./internal/gui ./internal/cli ok.

Not tried: a real GNOME/KDE session with a signed-in user, the .deb
install (its postinst runs update-desktop-database when present),
Nightly and OSS builds, KDE's kde-open, the web-mode page (location.href
still opens it there). No GUI asset changed, so no Playwright run; no
budget raised.
2026-10-25 14:13:38 +08:00
..