perf(agent-manager): enrich only candidate PIDs ("node" in processNames enriches every Node process)
Problem
AgentManager.listAgents builds one shared process snapshot from the union of all adapters' processNames. The Gemini, Kiro and Pi adapters declare "node", so every Node.js process on the machine matches: editor helpers, dev servers, other CLIs.
captureProcessSnapshot then enriches all matched PIDs with lsof -a -d cwd -p <pids> and ps -o lstart= -p <pids> on every refresh, before any adapter's canHandle filters them out. On a typical developer machine, dozens of unrelated Node processes get enriched every 3 s (49 on a test machine), and the cost grows with unrelated software.
Proposed approach
Use two-phase capture in packages/agent-manager/src/utils/process.ts and AgentManager.listAgents:
- Run
ps -axo pid=,ppid=,tty=,command=once, as today. - Keep only processes that at least one adapter's
canHandleaccepts.canHandleis already on theAgentAdapterinterface and needs only the command and executable. - Run
lsofandps lstartfor that filtered PID set only.
Optionally, cache start times per PID, since they never change for a live PID; this lets ps lstart skip PIDs it has already seen.
Acceptance criteria
- [ ] Given a snapshot with 50 unrelated
nodeprocesses and 2 real agents,lsof/ps lstartreceive only the PIDs that pass some adapter'scanHandle(unit test with an injected exec). - [ ] Start times are fetched once per
(pid)while the process is alive, not on every refresh. - [ ] Detection results are unchanged for existing Gemini, Kiro and Pi tests, including wrapper-process handling.
- [ ] With no candidate agent processes, a refresh spawns only the base
ps(nolsof/ps lstart).