Northes (Discord #feedback, 11-04): WorkBuddy's Agents row kept "重启
WorkBuddy 后生效" after they quit and reopened it, and its Restart quit
WorkBuddy and never opened it again. #3700 (Raters0) is the second half on
WorkBuddy AI.
Cause, from WorkBuddy 5.5.6's app.asar (read only) and its processes on the
Windows box: WorkBuddy starts a sidecar as `<its own executable>
.../app.asar/main/sidecar-entry.js --token ...` (ELECTRON_RUN_AS_NODE,
detached). The sidecar outlives the app's quit and the next start reuses
it, and its prewarm and `--serve` CLIs run as `<executable>
.../cli/bin/codebuddy ...`. The daemon is `WorkBuddy.exe ...
daemon-app-server-entry.js --stdio`. All of them match the running check's
`Contents/MacOS/<exe>` pattern (and WorkBuddy.exe's image on Windows), so:
- (a) findRestartable took the oldest match, the sidecar, as the app's
start, so magpie's change was always "after" it and the row never
cleared, however often the app restarted. On Windows the earliest start
was used too.
- (b) reopenBundle waited for every process under Contents/ to end; the
sidecar never does, so after 30s it said "still open" and never ran
`open`.
Fix: runsScript(cmd, exe) tells a script run on the app's executable (a
.js/.cjs/.mjs argument, or a first non-flag argument that is an absolute
path) from the app itself and its helpers (--type=..., /prefetch:,
-psn_, a deep link). The macOS running check and the reopen's wait skip
such processes (appProcs), and the Windows check reads each process's
command line (proc.CommandLine, new) and skips them too. The reopen still
waits for real helpers (renderer, GPU). This is shared by every restartable
app: Claude desktop, WorkBuddy, WorkBuddy AI and the Codex app.
Tests (red on the old code: a copy of the base with runsScript returning
false failed all three, since = the sidecar's 2h, the Windows since the
sidecar's, and 6 RunsScript rows):
- TestWorkBuddySidecarOutlivesQuitOnMac (WorkBuddy and WorkBuddy AI, a
space in the bundle): a 2h-old sidecar and prewarm beside the app; the
row is behind by the app's start, a manual reopen clears it, the
sidecar alone is not "running", Restart quits then opens.
- TestWorkBuddySidecarOutlivesQuitOnWindows: same, and Restart closes and
ends only the app's tree, then opens it.
- TestRunsScript: real Windows command lines from WorkBuddy on the box,
macOS ones, and #3700's `codebuddy --serve` line.
Run at this head (rebased on d6d3e6cc8):
- mote: gofmt -l clean; GOOS=windows, linux and darwin go vet
./internal/agent ./internal/proc; go test -count=1 ./internal/agent
./internal/proc ok.
- xiaomi-gpu (win-run): go test ./internal/agent ./internal/proc -run
'Restart|Sidecar|RunsScript|WorkBuddy|List': the new tests pass; red are
TestWorkBuddyRestartOnMac and TestWorkBuddyOwnSaveAfterStartIsNoChange/
darwin (red the same at origin/main d6d3e6cc8, #4115) and
TestWithViaKeepsTheJoinedList (#4786). The new mac test skips on Windows
for #4115's reason.
- Real processes, uncommitted tests: on mote a fake "WorkBuddy AI.app"
(Go sleeper as Electron) with a sidecar started first, through real
pgrep and sysctl: since is the app's (0.66s), the sidecar alone is not
running. On xiaomi-gpu a fake WorkBuddy.exe sidecar and app:
readWinProc's command lines are the real ones and runsScript tells
them apart.
Not tried: the real WorkBuddy or WorkBuddy AI (not run, ~/.workbuddy not
touched); a real Restart end to end through osascript/open or on Windows
(the quit/open steps are faked); Linux (no restartable app there).
Refs #3700