Commit Graph
8 Commits
Author SHA1 Message Date
yetone 0d70f335ec agent: the disconnect preview of a plugin's agent shows what it puts back, not nothing (plugins#799)
Purfeather found that disconnecting MiniMax Design (an agent a plugin adds)
showed the dialog's generic sentence: /api/agents/.../disconnect-preview
returned changes: []. The preview runs Disconnect in a process whose HOME
(and APPDATA, LOCALAPPDATA, XDG_*) is a temporary copy, but a plugin agent's
stash key is "plugin:<id>:" + the file's whole path, so the copied
stash.json named the file under the real home. The dry run found no stash,
read the agent as not on magpie, and changed nothing.

The same holds for every built-in whose stash key carries its file's path
(Droid, AtomCode, Cline, Qwen, Kimi, Zed, Hermes, Muse, Snow, ...): their
previews found the file wired but not what to put back, and showed magpie's
lines taken out instead of the user's model going back.

The fix is in one place, DisconnectPreview: after copying magpie's files it
rewrites the copy's stash so each key naming a path under home names it
under the copy's home (moveStashKeys/movedKey; a separator must follow
home, and Windows compares without case, since %APPDATA% can spell the
home folder otherwise). The real stash, its key format and the real
connect/disconnect are unchanged, so stashes users already have keep
working and nothing is migrated. A stash that is missing or doesn't parse
is left as it is.

Run at this head (30a0bfe88 + this commit; origin/main had not moved):
- mote: go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows
  go vet ./...: clean. gofmt -l: nothing.
- mote: go test -tags nogui -timeout 45m ./...: 87 packages ok, exit 0
  (internal/agent 381s).
- xiaomi-gpu (Windows): go test -tags nogui -run
  'TestDisconnectPreview|TestMovedKey' ./internal/agent: ok, the four new
  tests PASS (the case-insensitive branch runs there only).
- mote GUI files that show the preview (agent-changes-before-now,
  agent-disconnect-preview, agent-leave-magpie, agent-own-direct,
  aside-native, mask-actions): Chromium 60/60, WebKit 34/34.

Broken by hand: with the key rewrite skipped, TestDisconnectPreviewOfAPluginAgent
fails with "the preview doesn't take magpie's entry out: []" (the
reporter's exact empty list), TestDisconnectPreviewOfAPluginAgentsModel
and TestDisconnectPreviewOfDroidPutsItsModelBack fail with no "~" line
putting the user's model back. Restored: all pass.

Not tried: a real MiniMax Design on Windows, or the GUI dialog against a
real magpie; the tests run the real preview path (this test binary as the
dry run's process) with the plugin's agent module as plugins#799 has it.
Paths stored in stash values (not keys) are not rewritten; none of the
values read in a disconnect hold a whole path.

Reported-by: Purfeather
2026-11-07 04:55:56 +08:00
yetoneandFake Trader 0cabaaf243 agent: a portable VS Code on a Mac is wired in its code-portable-data folder (#4151)
faketrader runs VS Code portable on a Mac: /usr/local/bin/code links into
/Applications/Code/Visual Studio Code.app, and the build reads
/Applications/Code/code-portable-data/user-data/User. magpie detected it
but wrote ~/Library/Application Support/Code/User, which that build never
reads. Their patch on #4151 is the base; this takes its rule and makes it
VS Code's own (configurePortable in src/bootstrap-node.ts), on every OS:

- A build is portable when its product.json has no `target` (an
  installer's build has one) and its data folder exists: on a Mac
  product.json's `portable`, else `<applicationName>-portable-data`,
  beside the .app; on Windows and Linux `data` beside the install, also
  for a build that updates into `<install>/<version>/resources/app`.
- The build is the one the launcher on PATH is, through a Scoop shim and
  every symlink. A launcher whose product.json names another editor (a
  fork's `code`) isn't the build's. With no launcher of its own, a Mac
  reads the app folders and Spotlight and takes a portable bundle only
  when every bundle found is that one; beside an installed bundle, which
  one runs is unknown and nothing moves.
- VS Code, Insiders and VSCodium each go by their own bundle and launcher.
- User and extensions come from one place (vscodeDirs): connect, Sync,
  profiles and Disconnect use the portable User folder, and Zoo Code is
  found by its extension in <data>/extensions and writes its import file
  there. Windows' Zoo Code under Scoop looked in ~/.vscode/extensions.
- Disconnect's preview is refused for a file in a portable data folder:
  the preview's child keeps PATH, and its launcher would reach the build's
  real files, not the copy. That also covers Scoop under home on Windows,
  which main previewed.
- An installed build with no portable folder keeps the OS's folder and
  ~/.vscode/extensions, unchanged.

#3260 and #4009 (Windows): 509d8e7d1 (ggbdpq) already moved Scoop's
`current\data`; this adds the target check, the versioned layout, the
Windows Zoo Code folder and the preview refusal above.

Tests (fixtures under t.TempDir, never /Applications or ~/Library; app
folders and Spotlight stubbed): TestVSCodeMacPortableDirs (stable,
Insiders, product's `portable`, no data folder, Windows' `data` name,
another editor, another channel's folder, unreadable product, installer
target), TestVSCodeMacPortableLinkChain (three links, folders with
spaces), TestVSCodeMacPortableWiring, TestVSCodeMacPortableWithoutLauncher,
TestVSCodeMacPortableLauncherPicks, TestVSCodeMacPortableForkLauncher,
TestVSCodePortableProduct (Windows/Linux: target, fork product, versioned
install, Zoo Code, Scoop preview).

Broken by hand, each went red and was restored: main's rule on darwin
(6 Mac tests FAIL, standard folder used), target ignored (Dirs, Product),
no preview refusal (Wiring, Product), first bundle wins
(WithoutLauncher), fork launcher decides (ForkLauncher), Zoo Code on
home's extensions (3 FAIL). On origin/main the new tests don't compile
(vscodeDirs is new); break #1 is main's Mac behaviour.

Run:
- mote (macOS 27), full suite at this change on 479476784:
  go test -tags nogui -timeout 45m -count=1 ./... : 85 packages ok
  (internal/agent 405s, gateway 832s, provider 251s), internal/gui red on
  two filed tests this change doesn't reach: TestSettingsSaveKeepsWhat-
  ItDoesNotSend (SearchAll, #4514) and TestColdTurnsTaken (#4510).
  Rebased onto 90c02326b (gui takeover, sessions save, kiro min; nothing
  in internal/agent): go build, go vet of agent/gui/sessions/provider and
  go test of internal/agent, internal/sessions, internal/provider again
  at the pushed head: ok (agent 352s, sessions 110s, provider 228s).
- mote (macOS 27): go test -tags nogui ./internal/agent -run
  'TestVSCode|TestZooCode' ok; gofmt -l clean; go vet ./...,
  GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./..., GOOS=linux
  go build -tags nogui, GOOS=windows go build ok.
- win-run (Windows 11) and wsl-run (Ubuntu 24.04): the agent tests above
  plus Preview, ok.
- Real use on mote, sandbox HOME, PATH=$SB/bin:/usr/bin:/bin: VS Code
  1.144.0 darwin-arm64 from update.code.visualstudio.com unpacked to
  "$SB/Apps With Space/Code/Visual Studio Code.app", `code` linked
  bin/code -> "link one/code" -> the bundle's bin/code. Without
  code-portable-data, `magpie agents` lists ~/Library/Application
  Support/Code/User/settings.json; with it, ".../code-portable-data/
  user-data/User/settings.json". The real `code --install-extension
  zoocodeorganization.zoo-code` put Zoo Code 3.94.0 in
  code-portable-data/extensions (no ~/.vscode made), and magpie then
  listed Zoo Code at the portable User folder. `magpie vscode
  deepseek/deepseek-chat` wrote settings.json and chatLanguageModels.json
  there, `magpie vscode default` took magpie out of both, and Zoo Code's
  connect wrote its import file under the portable globalStorage and its
  disconnect removed the setting; ~/Library/Application Support/Code was
  never made.
- Real use on xiaomi-gpu (Windows 11), sandbox USERPROFILE/APPDATA,
  PATH=<install>\bin;System32: VS Code's win32-x64 ZIP (its versioned
  layout, <install>\2c33b50b16\resources\app) unpacked to "Apps With
  Space\VSCode". Without data, `magpie agents` lists ~\AppData\Roaming\
  Code\User\settings.json; with data, <install>\data\user-data\User\
  settings.json. The real code.cmd --install-extension put Zoo Code in
  data\extensions (no ~\.vscode), magpie then listed Zoo Code there,
  and connect/disconnect wrote and cleaned that User folder; %APPDATA%\Code
  was never made.

Not tried / not handled: VS Code's window wasn't opened to see the model
picker (headless ssh). VSCODE_PORTABLE isn't read: it is the editor's
environment, not magpie's. A Windows or Linux portable build with no
launcher on PATH isn't found (there is no standard place to look). A group
an older magpie wrote in the OS's folder for a portable build stays there;
connecting again writes the portable one. A Claude Code or Codex extension
in a portable build doesn't keep that CLI from showing as gone: #4672.

Co-authored-by: Fake Trader <9635792+faketrader@users.noreply.github.com>
2026-11-01 11:55:33 +08:00
vincent e50d73aa36 agent: disconnect previews sweep sandboxes a killed magpie left (#3136)
DisconnectPreview builds its dry-run sandbox with os.MkdirTemp and
cleans it with a bare `defer os.RemoveAll(tmp)` (internal/agent/preview.go).
Two consequences reported by OldSuns: when the removal fails (on Windows
the dry run's bun host still holds magpie-bun.exe after cmd.Run returns)
the error is dropped and the sandbox - each with an 86 MB bun re-downloaded
into it - stays in the temporary directory for good; 12 dirs / 985 MB in
the report, 99 dirs in ggggggggggz's. And nothing ever reclaims sandboxes
left by a killed magpie, unlike the cursor snapshots, whose
sweepCursorSnaps removes stale magpie-cursor-* copies.

The change: DisconnectPreview sweeps magpie-preview-* folders older than
an hour (a live preview lasts seconds; the dry run is bounded at 20 s)
before creating its own, the way the cursor snapshots do; cleanup goes
through removePreview, which retries while processes are still letting go
of files (5 tries, 0.1 s-0.5 s apart) and logs the error instead of
dropping it when it still cannot remove the folder. Only the reported
prefix is swept; the other magpie-* temp prefixes have their own
lifecycles (#2321, cursor_snapshot.go).

Each sandbox also holds a copy of magpie's config folder's files
(logins.json, providers.json and the rest, copyTop), so a sandbox the
removal left behind kept the user's sign-ins in the temporary folder for
good. The sweep takes those too.

Reported by OldSuns, ggggggggggz and track23; the fix is skygunner's
branch fix/3136-agent-magpie-preview-86-mb (98e5e7bc7), ported as it is
apart from the test: it now sweeps a temp dir of its own (TMPDIR, TMP and
TEMP set to t.TempDir()) instead of the machine's, where it could take
another magpie's stale sandboxes.

What was run (on the ported tree):

- TestDisconnectPreviewSweepsStaleSandboxes with sweepPreviews() taken
  out by hand: red ("a stale sandbox is still there after a preview").
- go vet ./internal/agent/ for linux, windows and darwin: ok.
- go test ./internal/agent/ on mote: ok 170.4s.
- Windows (xiaomi-gpu, win-run): go test -run
  'TestDisconnectPreview|TestRemovePreview|TestPreview' ./internal/agent/:
  ok 7.8s.
- On mote, the built binary's agent-disconnect-dry-run for opencode,
  claude and codex under an empty sandbox HOME, then with a plugins.json
  naming an OpenCode plugin: nothing downloaded, the sandbox stayed at
  8-12K.

Not reproduced: the 86 MB bun and the pnpm install inside a sandbox. The
reports are from v0.1.1223; on main the dry run started no plugin host in
the cases above, so nothing here changes where bun comes from. The
sandboxes it left are what this removes.

Refs #3136
2026-10-28 18:21:38 +08:00
Junjie Zhou 4a97acf12a refactor(agent): separate Aside provider connection from model settings (#827)
* refactor(agent): connect Aside as a native provider with verified settings

* fix(agent): offer explicit offline Aside model and disconnect actions

Offer Save for next start after an initial runtime read failure, using a
structured API error instead of saved runtime state. Keep refusals and
failed readbacks on the live error path.

Add a separate offline disconnect confirmation that restores the checked
file plan, clears restore records and removes the provider last. Bind the
confirmation to its preview revision and roll back ordinary write failures.

Cover offline API and browser flows, cancellation, stale plans, missing
CLI, restore metadata and native provider spelling. Keep state file-only.
2026-10-05 14:37:44 +08:00
Junjie Zhou c6875999b0 fix(agent): isolate Aside disconnect previews from the live daemon (#818)
* test(agent): reproduce Aside daemon calls during disconnect previews

* fix(agent): isolate Aside disconnect previews from the live daemon
2026-10-05 01:56:02 +08:00
Zhizhen He c744a097b6 agent: avoid panics in disconnect preview masking (#788)
Check for a key/value match before indexing its value boundary. Compact
JSON arrays and TOML table headers can contain secret-related words
without matching that pattern.

Cover both cases in TestMask.
2026-10-04 21:13:31 +08:00
yetone 661d27b560 agent: the disconnect preview right on Windows, and the Codex panel says what connecting does (owner: 去 Windows 测试机上测一下 / 是不是需要界面上解释一下现在的逻辑) — on the Windows test box Claude Code's and OpenCode's disconnect previews were empty though both were connected. Claude: the dry run's temporary home has no ~/.codex/auth.json, so a codex/… model wasn't magpie's there; the magpie asking now writes the providers it has on into that home and the dry run takes their models as magpie's (TestDryRunKnowsTheAskersProviders). OpenCode: magpie/codex/gpt-6.1-sol, a model its copy of magpie's list didn't have yet, read as not connected and Disconnect left it on magpie; a magpie/… value whose model magpie routes is magpie's (TestOpenCodeOnAModelNotInItsList). The preview pairs a line going back only with one as deep (Claude's model, not a modelPicker row) and doesn't mask …_TOKENS counts. The Codex panel, joined: 「重开 Codex 后,/model 里自己的模型照旧,magpie 的模型也在里面。」, and 新会话默认 says 「和 Codex 的 /model 是同一个选择,在哪边改都行」 rather than 「不设就用 Codex 自己上次的选择」 beside a value (/api/state: joined). On Windows (sandbox USERPROFILE/APPDATA, real accounts): previews for Claude, OpenCode, Codex and Gemini; disconnecting all four restored them (Claude back to opus, Gemini to Google sign-in, Codex keeps its [model_providers.magpie] by design), real ~/.claude untouched; real Claude Code requests via yylx/claude-opus-5-5 and codex/gpt-5.5 answered. The new tests fail on the old code. go vet, builds (darwin, GOOS=linux, GOOS=windows), go test -tags nogui -count=1 ./... under a temp HOME and the 34 agent GUI tests pass but cli-update, menu-scroll and old-webkit, which fail on main too. 2026-10-04 02:05:10 +08:00
yetone d0d098c69f agents: the 「接入」 boards filled in — the opened row as designed, real accounts tried
- The opened row follows the boards: what to do in the agent, running copies with the old list, Claude Code's tiers (each with its own effort beside its model again, #536), the model list by whose models they are with what's hidden, the model new sessions start on, what connecting costs (Gemini's Google sign-in), and the files put back on disconnect, shown line by line.
- Disconnecting asks first and shows the lines it puts back. Secrets are masked, and a config of tens of thousands of lines diffs in a fraction of a second.
- Connecting prefers the agent's own subscription when magpie serves it (Claude, Codex).
- The dry run goes through proc.
- Every model hidden still keeps the row connected, with the way back to the list (#356).
- Routing groups are named in Chinese.
- Phone widths: the pickers and squares wrap inside the opened row, and the name stays beside its logo.

GUI tests moved to the new rows: connected fixtures carry refs and open the row from its link. tier-effort and mobile-web each found a real gap and now guard the fix.

Tried in a sandbox HOME with the owner's real accounts:
- Claude Code: connected, a request answered, and disconnect restored the settings exactly.
- OpenCode: a request answered.
- Gemini CLI: connected.
- Codex: connected.
- Model list picks were saved.

go vet, builds (darwin, GOOS=windows, GOOS=linux -tags nogui) and go test -tags nogui ./... under a temp HOME pass. The agent GUI tests pass except cli-update's tight-row case, menu-scroll and old-webkit, which fail on main too.
2026-10-04 02:05:10 +08:00