Commit Graph
4 Commits
Author SHA1 Message Date
yetone 5be581a1c3 gui: a magpie folder the user can't write gets a one-click Repair (YouWhat)
YouWhat on Discord (macOS): adding a custom provider failed with
"mkdir ~/.config/magpie: permission denied". ~/.config wasn't the user's
(a command run under sudo makes it root's), so magpie couldn't make its
folder. The app still ran because reads of a missing file mean "none",
but every save failed. The GUI saves showed the raw error; the
background writes (usage, quotas, caches) dropped theirs.

Now:
- appdir.Blocked() names the folder that keeps magpie from writing its
  config or cache folder: the folder itself, or the first one above it
  when it doesn't exist yet. Only folders inside the home folder are
  named. Unix only; on Windows it is "".
- /api/state carries configBlocked. A failed save whose error is a
  permission refusal comes back with code config_blocked. The window asks
  once a load, and again over the editor whose save failed. "Not now"
  returns to that editor as it was left. The tray panel doesn't ask.
- Repair (POST /api/config/repair): a folder the user owns gets u+rwx with
  no prompt. Another user's folder is chowned to the user, through the
  system's password prompt (update.AsAdmin, the updater's: osascript on a
  Mac, pkexec on Linux). That chown is not recursive for ~/.config, so the
  other apps' folders inside it stay as they are; magpie's own folder is
  chowned -R, since everything in it is magpie's. magpie web shows no
  prompt; it names the sudo command instead. Data never moves: every
  reader keeps the one path, so nothing splits.
- Words in en, zh, zh-TW, ja and de.
- The core-script budget goes up by 1,112 bytes (app.js stays under its
  own), with no room added.

Run (on mote via mote-run, at this tree, based on 17114b505):
- gofmt -l: empty. go vet ./... (darwin), GOOS=linux go vet -tags nogui
  ./..., GOOS=windows go vet ./...: clean.
- go test -timeout 45m ./internal/appdir ./internal/update
  ./internal/gui ./internal/proc: appdir, update and proc ok. gui fails
  only TestMainWindowCorners/macOS_26_SDK, which fails the same on
  origin/main 17114b505 on mote (open: #3949). TestCoreScriptBudget's
  first red led to the raise above, and it passes after.
- Red on old code: TestBlockedConfigIsRepairedInOneClick at 17114b505
  fails with "failed save = 400 {"error":"mkdir …/.config/magpie:
  permission denied"}; want code config_blocked". Its sandbox HOME has
  .config at chmod 555, which is the reporter's error. With the change it
  passes: the save names ~/.config, Repair returns 204, the same save goes
  through into ~/.config/magpie/providers.json, and state clears.
  TestRepairOfAnotherUsersFolderAsksAnAdmin fakes another owner and checks
  that the script is "chown <uid>:<gid> '<~/.config>' && chmod u+rwx",
  with no -R, that magpie's own folder gets -R, and that web shows no
  prompt.
- GUI: config-blocked.test.cjs, cli-behind.test.cjs and i18n-keys.test.cjs
  in Chromium and WebKit (en, zh), 12/12 ok. The new file checks the keys
  in zh, zh-TW, ja and de. It is red on the old assets (2/2 not ok in
  Chromium).

Not tried: a real root-owned ~/.config and the real osascript or pkexec
prompt (no sudo on the test boxes). The script runs through the updater's
AsAdmin, which already runs a privileged script. The TUI and CLI don't
offer the repair yet: #4287.
2026-10-29 22:10:21 +08:00
yetone 6876125a19 agent, library: an npm agent or winget's RTK under Program Files updates after Windows' administrator prompt, and says why when it can't (新v学员 on Discord)
On Windows the official Node.js installer leaves npm's global prefix at
C:\Program Files\nodejs, which only an administrator can change. magpie
runs as the user, and writable() on Windows always said true, so the
Agents page offered the update and npm failed with EPERM (mkdir
...\node_modules\@scope), with nothing saying why. The same user then
reported RTK and other actions needing elevation all failing, and asked
for a setting to run magpie as administrator. There is no such setting:
an elevated magpie would write the agents' configs as the administrator,
couldn't start with Windows without a UAC prompt at each login, and
widens what can go wrong. Instead each action that needs an administrator
asks Windows for one, alone.

- agent: writable() on Windows makes and removes a file in the folder
  (update.Writable) instead of always saying yes. An npm CLI in a folder
  the user can't write in is still offered on Windows, marked Admin, and
  its update runs through update.RunElevated, never as the user. Elsewhere
  (/usr/lib, would want sudo) nothing is offered, as before.
- update: RunElevated (Windows) runs the command through
  ShellExecuteEx "runas" on a .cmd script that sets the env that differs
  from an elevated process's own plus PATH, cds to the folder, and sends
  output to a log read back; the exit code comes from GetExitCodeProcess
  (a non-zero one is update.ExitError, for its code). A declined prompt is
  ErrCanceled; no prompt to be had is the new ErrNoAdmin. Other systems:
  CanRunElevated false.
- library: RTK installed by winget for every user (under Program Files)
  is upgraded through the same prompt when only an administrator can
  change rtk's folder; the card's Upgrade title says Windows asks first.
  Install, and an upgrade whose folder looked writable, run winget as the
  user and go through the prompt only when winget answers 0x8A150019
  (command requires admin). winget's codes from the elevated run are read
  as before (0x8A15002B: no newer RTK, no failure).
- A declined or impossible prompt is agent.AdminError (Via npm or
  winget); the GUI answers it with code needs_admin and says, in the
  reader's language, what needs an administrator and what to do: try
  again and allow it, or run the command in a terminal opened as
  administrator, and for npm also moving npm's prefix
  (npm config set prefix "%APPDATA%\npm") and reinstalling.
- Install another agent: its npm commands note when npm's prefix
  (npm prefix -g, memoized) is such a folder.
- Checked, not changed: autostart uses HKCU's Run key, no admin needed;
  magpie never runs npm uninstall; plugins install into magpie's own
  folder with bun; agent CLIs update only on a click; RTK's PATH fix
  writes HKCU's Environment and rtk init -g the user's own agent folders;
  the library's only other exec is the MCP server check.

Run:
- go test -tags nogui ./internal/agent ./internal/update ./internal/library
  (and the full ./... under the lock). TestNPMUpdateNeedsAdmin fails with
  the admin branch removed and with runAdmin bypassed;
  TestRTKUpgradeAsksForAdmin and TestRTKInstallRetriesAsAdmin fail with
  runRTKInstaller never elevating (checked by hand).
- gofmt -l; go vet (darwin), GOOS=linux and GOOS=windows go vet.
- GUI, Chromium and WebKit: cli-update-admin (en, zh), library-rtk-admin
  (en, zh exact; ja, de, zh-TW translated, no npm advice; fails with the
  old Upgrade title), library-rtk-upgrade/-path/-nohook/-gain, gui-ja,
  gui-de, gui-zh-tw, cli-update, i18n-keys.
- Windows box (10.0.0.132): TestWritableSeesDeniedFolder passes, and fails
  on the old writable(). A portable Node 22 with Program Files' ACL
  (Users RX, Administrators F): as a non-elevated token (runas
  /trustlevel:0x20000) npm install -g failed with the reporter's EPERM,
  Writable said false, and dsh's CLI() said Via npm, Admin true; elevated
  it said Admin false. RunElevated from the elevated ssh session installed
  @deepseek-ai/dsh into that folder for real, and a missing version came
  back as exit status 1 with npm's ETARGET output. The library's RTK tests
  ran there too (TestRTKInstallRetriesAsAdmin passes; the shell-fake ones
  skip on Windows).
- Not tried: the UAC prompt itself, allowing or declining it, as nobody
  sits at the box; the ErrNoAdmin path on a real system; a real
  machine-scope winget RTK (none is installed on the box).
2026-10-11 05:33:23 +08:00
yetone e8b3be572c windows: the desktop app no longer opens a console window for every command it runs (#54) — it is linked as a GUI program and has no console, so each console CLI it started (devin auth status and models list, devin acp for every Devin turn, claude, codex, cursor-agent and grok probes and runs, grok login) was given a new console by Windows, and a Windows Terminal window with it, some every few seconds while the app sat idle. Every command magpie runs is now made through internal/proc, which starts it with CREATE_NO_WINDOW when magpie has no console of its own: the child gets a console without a window, and its output, which magpie always pipes back, arrives as before. A magpie run in a terminal (magpie serve, the TUI, the desktop app started from one with a command) has one, and its children share it as they did, so Ctrl+C there still reaches them. The relaunch after an update keeps its DETACHED_PROCESS, added to rather than replacing the flags it was made with, and a test fails on any command made with os/exec directly, so a new one can't bring the windows back 2026-09-25 14:04:44 +08:00
yetone 90580ca7e1 update: Update updates magpie in place — a click downloads the new version and restarts into it, asking for the password when magpie can't replace itself, instead of opening the release page; only a magpie running from its disk image or a temporary copy is sent to the download page, with why 2026-09-25 01:35:24 +08:00