gentle-pi 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/README.md +1 -1
  2. package/assets/agents/gentle-ai-explore.md +3 -6
  3. package/assets/agents/gentle-ai-verify.md +1 -1
  4. package/assets/agents/gentle-ai-worker.md +9 -9
  5. package/assets/agents/jd-fix-agent.md +1 -1
  6. package/assets/agents/jd-judge-a.md +0 -1
  7. package/assets/agents/jd-judge-b.md +0 -1
  8. package/assets/migrations/agent-body-history.json +6 -0
  9. package/assets/orchestrator-full-delegation.md +1 -1
  10. package/assets/orchestrator-maintenance.md +11 -0
  11. package/assets/orchestrator-quota-recovery.md +1 -1
  12. package/assets/orchestrator-skills.md +10 -0
  13. package/assets/orchestrator-verification.md +9 -7
  14. package/assets/orchestrator.md +1 -1
  15. package/bin/gentle-shell.mjs +67 -15
  16. package/contracts/review-provider-contract-mirror/provider-contract.lock.json +10 -10
  17. package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/manifest.json +5 -5
  18. package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/orchestration/pi.md +5 -3
  19. package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/routing/pi.md +1 -1
  20. package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/schemas/lens.schema.json +3 -3
  21. package/contracts/review-provider-contract-mirror/v1.7.0/bundle/vectors/lens.json +1 -0
  22. package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/generated/provider-capabilities.baseline.json +3 -3
  23. package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/generated/provider-roles.baseline.json +3 -3
  24. package/docs/bundled-install.md +2 -2
  25. package/docs/delegated-verification.md +8 -4
  26. package/docs/desktop-feed.md +15 -6
  27. package/docs/desktop-rpc.md +44 -20
  28. package/docs/gentle-shell-desktop.md +10 -3
  29. package/docs/gentle-shell.md +17 -13
  30. package/docs/install-wizard.md +2 -2
  31. package/docs/odd-preparation-continuity.md +2 -2
  32. package/docs/permission-modes.md +10 -2
  33. package/docs/readme-reference.md +46 -11
  34. package/docs/session-profile-format.md +33 -7
  35. package/docs/work-continuity.md +7 -7
  36. package/docs/yolo-mode.md +1 -1
  37. package/extensions/child-context.ts +2 -11
  38. package/extensions/gentle-agents.ts +47 -28
  39. package/extensions/gentle-ai.ts +573 -353
  40. package/extensions/gentle-desktop-feed.ts +13 -3
  41. package/extensions/gentle-fast.ts +9 -2
  42. package/extensions/gentle-shell.ts +142 -55
  43. package/extensions/gentle-tps.ts +5 -0
  44. package/extensions/quiet-tools.ts +13 -22
  45. package/extensions/skill-registry.ts +9 -1
  46. package/herdr/mods/gentle-agents/snapshot.js +30 -23
  47. package/herdr/mods/gentle-chat/feed.js +6 -0
  48. package/herdr/mods/gentle-chat/main.js +76 -16
  49. package/herdr/mods/gentle-chat/session.js +13 -5
  50. package/herdr/mods/gentle-chat/snapshot.js +30 -23
  51. package/herdr/mods/gentle-chat/ui.js +7 -1
  52. package/herdr/mods/gentle-inspector/main.js +2 -0
  53. package/herdr/mods/gentle-inspector/snapshot.js +30 -23
  54. package/herdr/mods/gentle-palette/main.js +1 -1
  55. package/herdr/mods/gentle-palette/snapshot.js +30 -23
  56. package/herdr/mods/gentle-pane/snapshot.js +30 -23
  57. package/herdr/mods/gentle-sidebar/snapshot.js +30 -23
  58. package/herdr/mods/gentle-spaces/snapshot.js +30 -23
  59. package/herdr/mods/gentle-status/snapshot.js +30 -23
  60. package/herdr/mods/gentle-tabs/main.js +3 -2
  61. package/herdr/mods/gentle-tabs/new-tab.js +9 -0
  62. package/herdr/mods/gentle-tabs/snapshot.js +30 -23
  63. package/herdr/mods/gentle-tokens/snapshot.js +30 -23
  64. package/lib/agent-profiles.ts +50 -10
  65. package/lib/agents-config.ts +59 -4
  66. package/lib/agents-runner.ts +34 -1
  67. package/lib/auto-permission-runtime.ts +2 -1
  68. package/lib/background-jobs-tools.ts +24 -16
  69. package/lib/claude-bridge-config.ts +41 -0
  70. package/lib/desktop-agent-definitions-service.ts +10 -6
  71. package/lib/desktop-command-rpc.ts +71 -0
  72. package/lib/desktop-feed-sources.ts +44 -1
  73. package/lib/desktop-feed.ts +41 -29
  74. package/lib/desktop-rpc-agent-definitions.ts +7 -3
  75. package/lib/desktop-rpc-changes.ts +13 -4
  76. package/lib/desktop-rpc-config.ts +106 -3
  77. package/lib/exploration-budget.ts +3 -7
  78. package/lib/gentle-design.ts +23 -4
  79. package/lib/gentle-shell-desktop.ts +85 -0
  80. package/lib/gentle-shell-launcher.ts +106 -3
  81. package/lib/mcp-config.ts +214 -0
  82. package/lib/native-review-cli.ts +78 -34
  83. package/lib/odd-phase-inference.ts +1 -1
  84. package/lib/orchestrator-mode-policy.ts +25 -12
  85. package/lib/path-consent-fence.ts +113 -0
  86. package/lib/pi-settings.ts +157 -0
  87. package/lib/review-continuation-registry.ts +7 -20
  88. package/lib/review-coordinator.ts +5 -0
  89. package/lib/review-host-relay.ts +2 -35
  90. package/lib/review-integration-v2.ts +31 -12
  91. package/lib/sensitive-paths.ts +22 -2
  92. package/lib/session-profile-freeze.ts +11 -4
  93. package/lib/session-worktree-registry.ts +11 -5
  94. package/lib/shell-card.ts +27 -1
  95. package/lib/shell-changes-view.ts +6 -2
  96. package/lib/shell-changes.ts +94 -37
  97. package/lib/shell-git-worker.ts +158 -0
  98. package/lib/shell-idle-changes.ts +88 -0
  99. package/lib/shell-untracked-cache.ts +142 -0
  100. package/lib/shell-untracked-lines.ts +178 -0
  101. package/lib/tps-policy.ts +85 -0
  102. package/lib/vim-editor-adapter.ts +3 -2
  103. package/lib/voice-artifacts.ts +8 -1
  104. package/lib/voice-install.ts +7 -3
  105. package/lib/yolo-session-policy.ts +2 -2
  106. package/package.json +1 -1
  107. package/runtime/gentle-shell-desktop.mjs +85 -0
  108. package/runtime/gentle-shell-launcher.mjs +106 -3
  109. package/runtime/native-review-cli.mjs +77 -33
  110. package/runtime/review-integration-v2.mjs +31 -12
  111. package/runtime/sensitive-paths.mjs +22 -2
  112. package/scripts/gentle-ai-installer.mjs +10 -10
  113. package/scripts/main-channel.mjs +27 -7
  114. package/scripts/verify-package-files.mjs +13 -12
  115. package/skills/rdd-defect-workflow/SKILL.md +2 -2
  116. package/tests/agent-profiles-workflow.test.ts +102 -0
  117. package/tests/agents-config.test.ts +1 -2
  118. package/tests/agents-protocol.test.ts +1 -1
  119. package/tests/agents-runner.test.ts +94 -2
  120. package/tests/append-system-prompt-route.test.ts +16 -11
  121. package/tests/auto-permission-runtime.test.ts +4 -4
  122. package/tests/bounded-stop-contract.test.ts +50 -62
  123. package/tests/child-context-files.test.ts +6 -6
  124. package/tests/child-web-package.test.ts +1 -1
  125. package/tests/controlled-engineering-editor.test.ts +192 -0
  126. package/tests/controlled-engineering-launch.test.ts +136 -0
  127. package/tests/controlled-engineering.test.ts +244 -0
  128. package/tests/delivery-b-rendered-surfaces.test.ts +1 -1
  129. package/tests/desktop-feed-tool-summaries.test.ts +1 -1
  130. package/tests/desktop-feed-transcript.test.ts +17 -0
  131. package/tests/desktop-feed.test.ts +141 -7
  132. package/tests/desktop-liveness.test.ts +125 -0
  133. package/tests/desktop-persona.test.ts +17 -0
  134. package/tests/desktop-rpc-agent-definitions.test.ts +23 -2
  135. package/tests/desktop-rpc-changes.test.ts +80 -3
  136. package/tests/desktop-rpc-config-mcp-fidelity.test.ts +106 -0
  137. package/tests/desktop-rpc-config-readonly-stores.test.ts +458 -0
  138. package/tests/desktop-rpc-config.test.ts +5 -2
  139. package/tests/desktop-rpc-design.test.ts +21 -0
  140. package/tests/desktop-rpc-session-snapshot-commands.test.ts +50 -0
  141. package/tests/desktop-session-switch.test.ts +237 -0
  142. package/tests/desktop-target-session.test.ts +104 -0
  143. package/tests/destructive-command-guard.test.ts +187 -0
  144. package/tests/devbinary/pi-host-relay.devtest.ts +73 -9
  145. package/tests/exploration-budget.test.ts +2 -26
  146. package/tests/fixtures/primary-session-prompt/gentleman.golden.md +14 -10
  147. package/tests/full-delegation-closure.test.ts +19 -9
  148. package/tests/generic-agent-tools.test.ts +3 -3
  149. package/tests/gentle-agents.test.ts +214 -9
  150. package/tests/gentle-ai-exploration-budget.test.ts +3 -2
  151. package/tests/gentle-ai-installer.test.ts +52 -51
  152. package/tests/gentle-ai.test.ts +29 -5
  153. package/tests/gentle-chat-read-failure.test.ts +74 -0
  154. package/tests/gentle-chat-session-read.test.ts +127 -0
  155. package/tests/gentle-design.test.ts +39 -0
  156. package/tests/gentle-shell-desktop.test.ts +108 -0
  157. package/tests/gentle-shell-launcher-auto-provision.test.ts +152 -0
  158. package/tests/gentle-shell-launcher-machine-output.test.ts +356 -0
  159. package/tests/gentle-shell.test.ts +93 -12
  160. package/tests/gentle-tps.test.ts +57 -0
  161. package/tests/independent-recovery-delivery.test.ts +15 -13
  162. package/tests/installer-preflight.test.ts +3 -2
  163. package/tests/job-turn-end-texts.test.ts +57 -0
  164. package/tests/lazy-module-contradictions-contract.test.ts +1 -2
  165. package/tests/main-channel.test.ts +12 -1
  166. package/tests/maintainer/desktop-rpc.maintest.ts +2 -2
  167. package/tests/native-review-capability-contract.test.ts +7 -1
  168. package/tests/native-review-cli.test.ts +113 -1
  169. package/tests/no-self-pause-contract.test.ts +8 -7
  170. package/tests/odd-phase-inference.test.ts +2 -2
  171. package/tests/odd-routing-canonical-ratchet.test.ts +1 -1
  172. package/tests/odd-routing-contract.test.ts +1 -1
  173. package/tests/orchestrator-budget.test.ts +7 -2
  174. package/tests/orchestrator-prompt-diet-contract.test.ts +5 -5
  175. package/tests/orchestrator-skills-inline-contract.test.ts +26 -0
  176. package/tests/package-manifest.test.ts +11 -16
  177. package/tests/packaged-agent-codemode.test.ts +79 -0
  178. package/tests/path-consent-fence.test.ts +326 -0
  179. package/tests/pi-update-launcher.test.ts +1 -1
  180. package/tests/primary-session-prompt.test.ts +9 -7
  181. package/tests/profile-fast-tier.test.ts +79 -4
  182. package/tests/progress-rule-contract.test.ts +54 -0
  183. package/tests/rdd-delivery-warning.test.ts +42 -4
  184. package/tests/review-actor-tool-deny.test.ts +1 -2
  185. package/tests/review-continuation-registry.test.ts +17 -17
  186. package/tests/review-controller-native-recovery.test.ts +100 -0
  187. package/tests/review-controller-native-routing.test.ts +129 -24
  188. package/tests/review-coordinator.test.ts +14 -0
  189. package/tests/review-host-relay-restart-parity.test.ts +2 -52
  190. package/tests/review-host-relay-routing.test.ts +57 -297
  191. package/tests/review-host-relay.test.ts +0 -46
  192. package/tests/review-integration-v2-forward.test.ts +39 -2
  193. package/tests/review-json-arguments.test.ts +30 -9
  194. package/tests/review-one-call-findings.test.ts +1 -0
  195. package/tests/review-untracked-inventory-replay.test.ts +181 -0
  196. package/tests/runtime-harness.mjs +27 -1
  197. package/tests/sensitive-path-tools.test.ts +155 -4
  198. package/tests/session-profile-extension.test.ts +90 -11
  199. package/tests/session-profile-freeze.test.ts +49 -2
  200. package/tests/session-profile-v1-compat.test.ts +11 -3
  201. package/tests/session-worktree-registry.test.ts +23 -0
  202. package/tests/shell-changes-idle-start.test.ts +510 -0
  203. package/tests/shell-changes-untracked-bound.test.ts +230 -0
  204. package/tests/shell-changes-view.test.ts +8 -2
  205. package/tests/shell-changes.test.ts +134 -0
  206. package/tests/shell-git-runner-stall.test.ts +74 -0
  207. package/tests/shell-git-worker-fallback.test.ts +140 -0
  208. package/tests/shell-git-worker-lifetime.test.ts +91 -0
  209. package/tests/shell-render-cache-runtime.test.ts +256 -3
  210. package/tests/shell-untracked-cache.test.ts +213 -0
  211. package/tests/short-check-routing-contract.test.ts +11 -7
  212. package/tests/skill-registry.test.ts +3 -3
  213. package/tests/support/chat-ui.ts +39 -0
  214. package/tests/t7-recovery-preservation.test.ts +68 -0
  215. package/tests/tps-policy.test.ts +96 -0
  216. package/tests/turn-end-rule-contract.test.ts +155 -0
  217. package/tests/turn-end-scope.test.ts +39 -0
  218. package/tests/verification-scoped-stop-contract.test.ts +1 -1
  219. package/tests/verification-tiers-contract.test.ts +4 -3
  220. package/tests/verify-first-launch-contract.test.ts +19 -7
  221. package/tests/vim-editor-adapter.test.ts +4 -4
  222. package/tests/voice-install.test.ts +97 -11
  223. package/tests/windows-hidden-processes.test.ts +11 -44
  224. package/tests/work-continuity-contract.test.ts +48 -55
  225. package/tests/yolo-session-policy.test.ts +2 -0
  226. package/contracts/review-provider-contract-mirror/v1.6.0/bundle/vectors/lens.json +0 -1
  227. package/extensions/codegraph-tools.ts +0 -437
  228. package/tests/child-codegraph-bootstrap.test.ts +0 -74
  229. package/tests/codegraph-tools.test.ts +0 -554
  230. /package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/README.md +0 -0
  231. /package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/schemas/refuter.schema.json +0 -0
  232. /package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/schemas/targeted-validator.schema.json +0 -0
  233. /package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/vectors/refuter.json +0 -0
  234. /package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/vectors/targeted-validator.json +0 -0
@@ -3,7 +3,7 @@
3
3
  //
4
4
  // CANONICAL COPY, carried byte-identical as `./snapshot.js` by every gentle-* mod that shows
5
5
  // snapshot data, gentle-chat included (gpui-shell refuses imports outside a mod's folder).
6
- // `targetTerminal` mirrors GentleChat.target() so every region shows one session.
6
+ // `targetSession` names the one session every region shows.
7
7
  //
8
8
  // Gentle Shell runs bundled (agent dir ~/.gentle-shell/agent), as the npm / Pi extension
9
9
  // (~/.pi/agent) or with its own home (GENTLE_PI_AGENT_HOME / PI_CODING_AGENT_DIR). Snapshots are
@@ -91,24 +91,38 @@ export async function readFeeds(roots) {
91
91
  const positive = (n) => Number.isInteger(n) && n > 0;
92
92
 
93
93
  // Whether each publisher still runs: one `ps` for the pids not checked in the last ALIVE_MS (a
94
- // crashed session leaves its snapshot behind until the next session start sweeps it). Without
95
- // `ps` (Windows) every snapshot counts as live.
94
+ // crashed session leaves its snapshot behind until the next session start sweeps it). Where `ps`
95
+ // cannot start (native Windows) or does not answer, one `tasklist` lists the running pids instead.
96
+ // A listing that did not answer decides nothing: when neither answers, every snapshot counts as live.
96
97
  const ALIVE_MS = 5000;
97
98
  const alive = new Map(); // pid -> { ok, at }
99
+
100
+ // `tasklist /NH /FO CSV` rows: "Image Name","PID","Session Name","Session#","Mem Usage".
101
+ export const parseTasklistPids = (stdout) =>
102
+ new Set([...String(stdout).matchAll(/^"[^"]*","(\d+)"/gm)].map((m) => Number(m[1])));
103
+
98
104
  export async function liveFeeds(feeds) {
99
105
  const now = Date.now();
100
106
  const want = [...new Set(feeds.map((f) => f.identity?.pid).filter(positive))].filter((pid) => !(now - (alive.get(pid)?.at ?? 0) < ALIVE_MS));
101
107
  if (want.length) {
108
+ let running = null;
102
109
  try {
103
- // `ps -p` lists the pids that run; it exits 1 when one of them does not.
110
+ // `ps -p` lists the pids that run; it exits 1 when one of them does not. A `ps` that rejects
111
+ // its own flags (MSYS/Git `ps` on Windows) also exits 1, but writes why on stderr: no answer.
104
112
  const r = await exec("ps", ["-o", "pid=", "-p", want.join(",")], { timeout: 3000 });
105
- if (r.code === 0 || r.code === 1) {
106
- const running = new Set(String(r.stdout).split(/\s+/).map(Number).filter(positive));
107
- for (const pid of want) alive.set(pid, { ok: running.has(pid), at: now });
108
- }
113
+ if (r.code === 0 || (r.code === 1 && !r.stderr)) running = new Set(String(r.stdout).split(/\s+/).map(Number).filter(positive));
109
114
  } catch {
110
- // no ps: the publisher's own sweep is the only cleanup
115
+ // `ps` cannot start
111
116
  }
117
+ if (!running) {
118
+ try {
119
+ const r = await exec("tasklist", ["/NH", "/FO", "CSV"], { timeout: 3000 });
120
+ if (r.code === 0) running = parseTasklistPids(r.stdout);
121
+ } catch {
122
+ // neither: the publisher's own sweep is the only cleanup
123
+ }
124
+ }
125
+ if (running) for (const pid of want) alive.set(pid, { ok: running.has(pid), at: now });
112
126
  if (alive.size > 256) for (const [pid, v] of alive) if (now - v.at > 60000) alive.delete(pid);
113
127
  }
114
128
  return feeds.filter((f) => alive.get(f.identity?.pid)?.ok !== false);
@@ -305,8 +319,10 @@ export function pickedKey() {
305
319
  }
306
320
 
307
321
  // The session the window is about: the picked one (see selectSession), else the focused Gentle
308
- // Shell terminal's, else one in the shown tab, else the last one shown (`last`, a session key),
309
- // else a Herdr one, else the newest snapshot. Mirrors targetTerminal for Herdr terminals.
322
+ // Shell terminal's, else one in the shown tab. A shown Herdr tab with no Gentle Shell session shows
323
+ // none: a Herdr tab or space was chosen, so the window follows it instead of keeping another
324
+ // session. Only with no focused tab: the last one shown (`last`, a session key), else a Herdr one,
325
+ // else the newest snapshot.
310
326
  export function targetSession(feeds, last) {
311
327
  const all = allSessions(feeds);
312
328
  const picked = pickedKey();
@@ -315,18 +331,9 @@ export function targetSession(feeds, last) {
315
331
  const f = focused();
316
332
  const byAddr = (a) => (a ? all.find((s) => s.terminal?.address === a) : undefined);
317
333
  const inTab = agents().filter((a) => isGentle(a.app) && a.tab === f?.tab);
318
- return byAddr(f?.agent) ?? byAddr(f?.terminal) ?? byAddr(inTab[0]?.address)
319
- ?? (last ? all.find((s) => s.key === last) : undefined) ?? all.find((s) => s.terminal) ?? all[0] ?? null;
320
- }
321
-
322
- // The Gentle Shell terminal the window is about: the focused one, else one in the shown tab,
323
- // else the last one shown (`last`), else the first. Mirrors GentleChat.target().
324
- export function targetTerminal(last) {
325
- const all = gentleTerminals();
326
- const f = focused();
327
- const byAddr = (a) => (a ? all.find((t) => t.address === a) : undefined);
328
- const inTab = agents().filter((a) => isGentle(a.app) && a.tab === f?.tab);
329
- return byAddr(f?.agent) ?? byAddr(f?.terminal) ?? byAddr(inTab[0]?.address) ?? byAddr(last) ?? all[0] ?? null;
334
+ const here = byAddr(f?.agent) ?? byAddr(f?.terminal) ?? byAddr(inTab[0]?.address);
335
+ if (here || f?.tab) return here ?? null;
336
+ return (last ? all.find((s) => s.key === last) : undefined) ?? all.find((s) => s.terminal) ?? all[0] ?? null;
330
337
  }
331
338
 
332
339
  // The live snapshots as the leader published them ({ digest, at, feeds }), and their digest alone:
@@ -3,7 +3,7 @@
3
3
  //
4
4
  // CANONICAL COPY, carried byte-identical as `./snapshot.js` by every gentle-* mod that shows
5
5
  // snapshot data, gentle-chat included (gpui-shell refuses imports outside a mod's folder).
6
- // `targetTerminal` mirrors GentleChat.target() so every region shows one session.
6
+ // `targetSession` names the one session every region shows.
7
7
  //
8
8
  // Gentle Shell runs bundled (agent dir ~/.gentle-shell/agent), as the npm / Pi extension
9
9
  // (~/.pi/agent) or with its own home (GENTLE_PI_AGENT_HOME / PI_CODING_AGENT_DIR). Snapshots are
@@ -91,24 +91,38 @@ export async function readFeeds(roots) {
91
91
  const positive = (n) => Number.isInteger(n) && n > 0;
92
92
 
93
93
  // Whether each publisher still runs: one `ps` for the pids not checked in the last ALIVE_MS (a
94
- // crashed session leaves its snapshot behind until the next session start sweeps it). Without
95
- // `ps` (Windows) every snapshot counts as live.
94
+ // crashed session leaves its snapshot behind until the next session start sweeps it). Where `ps`
95
+ // cannot start (native Windows) or does not answer, one `tasklist` lists the running pids instead.
96
+ // A listing that did not answer decides nothing: when neither answers, every snapshot counts as live.
96
97
  const ALIVE_MS = 5000;
97
98
  const alive = new Map(); // pid -> { ok, at }
99
+
100
+ // `tasklist /NH /FO CSV` rows: "Image Name","PID","Session Name","Session#","Mem Usage".
101
+ export const parseTasklistPids = (stdout) =>
102
+ new Set([...String(stdout).matchAll(/^"[^"]*","(\d+)"/gm)].map((m) => Number(m[1])));
103
+
98
104
  export async function liveFeeds(feeds) {
99
105
  const now = Date.now();
100
106
  const want = [...new Set(feeds.map((f) => f.identity?.pid).filter(positive))].filter((pid) => !(now - (alive.get(pid)?.at ?? 0) < ALIVE_MS));
101
107
  if (want.length) {
108
+ let running = null;
102
109
  try {
103
- // `ps -p` lists the pids that run; it exits 1 when one of them does not.
110
+ // `ps -p` lists the pids that run; it exits 1 when one of them does not. A `ps` that rejects
111
+ // its own flags (MSYS/Git `ps` on Windows) also exits 1, but writes why on stderr: no answer.
104
112
  const r = await exec("ps", ["-o", "pid=", "-p", want.join(",")], { timeout: 3000 });
105
- if (r.code === 0 || r.code === 1) {
106
- const running = new Set(String(r.stdout).split(/\s+/).map(Number).filter(positive));
107
- for (const pid of want) alive.set(pid, { ok: running.has(pid), at: now });
108
- }
113
+ if (r.code === 0 || (r.code === 1 && !r.stderr)) running = new Set(String(r.stdout).split(/\s+/).map(Number).filter(positive));
109
114
  } catch {
110
- // no ps: the publisher's own sweep is the only cleanup
115
+ // `ps` cannot start
111
116
  }
117
+ if (!running) {
118
+ try {
119
+ const r = await exec("tasklist", ["/NH", "/FO", "CSV"], { timeout: 3000 });
120
+ if (r.code === 0) running = parseTasklistPids(r.stdout);
121
+ } catch {
122
+ // neither: the publisher's own sweep is the only cleanup
123
+ }
124
+ }
125
+ if (running) for (const pid of want) alive.set(pid, { ok: running.has(pid), at: now });
112
126
  if (alive.size > 256) for (const [pid, v] of alive) if (now - v.at > 60000) alive.delete(pid);
113
127
  }
114
128
  return feeds.filter((f) => alive.get(f.identity?.pid)?.ok !== false);
@@ -305,8 +319,10 @@ export function pickedKey() {
305
319
  }
306
320
 
307
321
  // The session the window is about: the picked one (see selectSession), else the focused Gentle
308
- // Shell terminal's, else one in the shown tab, else the last one shown (`last`, a session key),
309
- // else a Herdr one, else the newest snapshot. Mirrors targetTerminal for Herdr terminals.
322
+ // Shell terminal's, else one in the shown tab. A shown Herdr tab with no Gentle Shell session shows
323
+ // none: a Herdr tab or space was chosen, so the window follows it instead of keeping another
324
+ // session. Only with no focused tab: the last one shown (`last`, a session key), else a Herdr one,
325
+ // else the newest snapshot.
310
326
  export function targetSession(feeds, last) {
311
327
  const all = allSessions(feeds);
312
328
  const picked = pickedKey();
@@ -315,18 +331,9 @@ export function targetSession(feeds, last) {
315
331
  const f = focused();
316
332
  const byAddr = (a) => (a ? all.find((s) => s.terminal?.address === a) : undefined);
317
333
  const inTab = agents().filter((a) => isGentle(a.app) && a.tab === f?.tab);
318
- return byAddr(f?.agent) ?? byAddr(f?.terminal) ?? byAddr(inTab[0]?.address)
319
- ?? (last ? all.find((s) => s.key === last) : undefined) ?? all.find((s) => s.terminal) ?? all[0] ?? null;
320
- }
321
-
322
- // The Gentle Shell terminal the window is about: the focused one, else one in the shown tab,
323
- // else the last one shown (`last`), else the first. Mirrors GentleChat.target().
324
- export function targetTerminal(last) {
325
- const all = gentleTerminals();
326
- const f = focused();
327
- const byAddr = (a) => (a ? all.find((t) => t.address === a) : undefined);
328
- const inTab = agents().filter((a) => isGentle(a.app) && a.tab === f?.tab);
329
- return byAddr(f?.agent) ?? byAddr(f?.terminal) ?? byAddr(inTab[0]?.address) ?? byAddr(last) ?? all[0] ?? null;
334
+ const here = byAddr(f?.agent) ?? byAddr(f?.terminal) ?? byAddr(inTab[0]?.address);
335
+ if (here || f?.tab) return here ?? null;
336
+ return (last ? all.find((s) => s.key === last) : undefined) ?? all.find((s) => s.terminal) ?? all[0] ?? null;
330
337
  }
331
338
 
332
339
  // The live snapshots as the leader published them ({ digest, at, feeds }), and their digest alone:
@@ -3,7 +3,7 @@
3
3
  //
4
4
  // CANONICAL COPY, carried byte-identical as `./snapshot.js` by every gentle-* mod that shows
5
5
  // snapshot data, gentle-chat included (gpui-shell refuses imports outside a mod's folder).
6
- // `targetTerminal` mirrors GentleChat.target() so every region shows one session.
6
+ // `targetSession` names the one session every region shows.
7
7
  //
8
8
  // Gentle Shell runs bundled (agent dir ~/.gentle-shell/agent), as the npm / Pi extension
9
9
  // (~/.pi/agent) or with its own home (GENTLE_PI_AGENT_HOME / PI_CODING_AGENT_DIR). Snapshots are
@@ -91,24 +91,38 @@ export async function readFeeds(roots) {
91
91
  const positive = (n) => Number.isInteger(n) && n > 0;
92
92
 
93
93
  // Whether each publisher still runs: one `ps` for the pids not checked in the last ALIVE_MS (a
94
- // crashed session leaves its snapshot behind until the next session start sweeps it). Without
95
- // `ps` (Windows) every snapshot counts as live.
94
+ // crashed session leaves its snapshot behind until the next session start sweeps it). Where `ps`
95
+ // cannot start (native Windows) or does not answer, one `tasklist` lists the running pids instead.
96
+ // A listing that did not answer decides nothing: when neither answers, every snapshot counts as live.
96
97
  const ALIVE_MS = 5000;
97
98
  const alive = new Map(); // pid -> { ok, at }
99
+
100
+ // `tasklist /NH /FO CSV` rows: "Image Name","PID","Session Name","Session#","Mem Usage".
101
+ export const parseTasklistPids = (stdout) =>
102
+ new Set([...String(stdout).matchAll(/^"[^"]*","(\d+)"/gm)].map((m) => Number(m[1])));
103
+
98
104
  export async function liveFeeds(feeds) {
99
105
  const now = Date.now();
100
106
  const want = [...new Set(feeds.map((f) => f.identity?.pid).filter(positive))].filter((pid) => !(now - (alive.get(pid)?.at ?? 0) < ALIVE_MS));
101
107
  if (want.length) {
108
+ let running = null;
102
109
  try {
103
- // `ps -p` lists the pids that run; it exits 1 when one of them does not.
110
+ // `ps -p` lists the pids that run; it exits 1 when one of them does not. A `ps` that rejects
111
+ // its own flags (MSYS/Git `ps` on Windows) also exits 1, but writes why on stderr: no answer.
104
112
  const r = await exec("ps", ["-o", "pid=", "-p", want.join(",")], { timeout: 3000 });
105
- if (r.code === 0 || r.code === 1) {
106
- const running = new Set(String(r.stdout).split(/\s+/).map(Number).filter(positive));
107
- for (const pid of want) alive.set(pid, { ok: running.has(pid), at: now });
108
- }
113
+ if (r.code === 0 || (r.code === 1 && !r.stderr)) running = new Set(String(r.stdout).split(/\s+/).map(Number).filter(positive));
109
114
  } catch {
110
- // no ps: the publisher's own sweep is the only cleanup
115
+ // `ps` cannot start
111
116
  }
117
+ if (!running) {
118
+ try {
119
+ const r = await exec("tasklist", ["/NH", "/FO", "CSV"], { timeout: 3000 });
120
+ if (r.code === 0) running = parseTasklistPids(r.stdout);
121
+ } catch {
122
+ // neither: the publisher's own sweep is the only cleanup
123
+ }
124
+ }
125
+ if (running) for (const pid of want) alive.set(pid, { ok: running.has(pid), at: now });
112
126
  if (alive.size > 256) for (const [pid, v] of alive) if (now - v.at > 60000) alive.delete(pid);
113
127
  }
114
128
  return feeds.filter((f) => alive.get(f.identity?.pid)?.ok !== false);
@@ -305,8 +319,10 @@ export function pickedKey() {
305
319
  }
306
320
 
307
321
  // The session the window is about: the picked one (see selectSession), else the focused Gentle
308
- // Shell terminal's, else one in the shown tab, else the last one shown (`last`, a session key),
309
- // else a Herdr one, else the newest snapshot. Mirrors targetTerminal for Herdr terminals.
322
+ // Shell terminal's, else one in the shown tab. A shown Herdr tab with no Gentle Shell session shows
323
+ // none: a Herdr tab or space was chosen, so the window follows it instead of keeping another
324
+ // session. Only with no focused tab: the last one shown (`last`, a session key), else a Herdr one,
325
+ // else the newest snapshot.
310
326
  export function targetSession(feeds, last) {
311
327
  const all = allSessions(feeds);
312
328
  const picked = pickedKey();
@@ -315,18 +331,9 @@ export function targetSession(feeds, last) {
315
331
  const f = focused();
316
332
  const byAddr = (a) => (a ? all.find((s) => s.terminal?.address === a) : undefined);
317
333
  const inTab = agents().filter((a) => isGentle(a.app) && a.tab === f?.tab);
318
- return byAddr(f?.agent) ?? byAddr(f?.terminal) ?? byAddr(inTab[0]?.address)
319
- ?? (last ? all.find((s) => s.key === last) : undefined) ?? all.find((s) => s.terminal) ?? all[0] ?? null;
320
- }
321
-
322
- // The Gentle Shell terminal the window is about: the focused one, else one in the shown tab,
323
- // else the last one shown (`last`), else the first. Mirrors GentleChat.target().
324
- export function targetTerminal(last) {
325
- const all = gentleTerminals();
326
- const f = focused();
327
- const byAddr = (a) => (a ? all.find((t) => t.address === a) : undefined);
328
- const inTab = agents().filter((a) => isGentle(a.app) && a.tab === f?.tab);
329
- return byAddr(f?.agent) ?? byAddr(f?.terminal) ?? byAddr(inTab[0]?.address) ?? byAddr(last) ?? all[0] ?? null;
334
+ const here = byAddr(f?.agent) ?? byAddr(f?.terminal) ?? byAddr(inTab[0]?.address);
335
+ if (here || f?.tab) return here ?? null;
336
+ return (last ? all.find((s) => s.key === last) : undefined) ?? all.find((s) => s.terminal) ?? all[0] ?? null;
330
337
  }
331
338
 
332
339
  // The live snapshots as the leader published them ({ digest, at, feeds }), and their digest alone:
@@ -3,7 +3,7 @@
3
3
  //
4
4
  // CANONICAL COPY, carried byte-identical as `./snapshot.js` by every gentle-* mod that shows
5
5
  // snapshot data, gentle-chat included (gpui-shell refuses imports outside a mod's folder).
6
- // `targetTerminal` mirrors GentleChat.target() so every region shows one session.
6
+ // `targetSession` names the one session every region shows.
7
7
  //
8
8
  // Gentle Shell runs bundled (agent dir ~/.gentle-shell/agent), as the npm / Pi extension
9
9
  // (~/.pi/agent) or with its own home (GENTLE_PI_AGENT_HOME / PI_CODING_AGENT_DIR). Snapshots are
@@ -91,24 +91,38 @@ export async function readFeeds(roots) {
91
91
  const positive = (n) => Number.isInteger(n) && n > 0;
92
92
 
93
93
  // Whether each publisher still runs: one `ps` for the pids not checked in the last ALIVE_MS (a
94
- // crashed session leaves its snapshot behind until the next session start sweeps it). Without
95
- // `ps` (Windows) every snapshot counts as live.
94
+ // crashed session leaves its snapshot behind until the next session start sweeps it). Where `ps`
95
+ // cannot start (native Windows) or does not answer, one `tasklist` lists the running pids instead.
96
+ // A listing that did not answer decides nothing: when neither answers, every snapshot counts as live.
96
97
  const ALIVE_MS = 5000;
97
98
  const alive = new Map(); // pid -> { ok, at }
99
+
100
+ // `tasklist /NH /FO CSV` rows: "Image Name","PID","Session Name","Session#","Mem Usage".
101
+ export const parseTasklistPids = (stdout) =>
102
+ new Set([...String(stdout).matchAll(/^"[^"]*","(\d+)"/gm)].map((m) => Number(m[1])));
103
+
98
104
  export async function liveFeeds(feeds) {
99
105
  const now = Date.now();
100
106
  const want = [...new Set(feeds.map((f) => f.identity?.pid).filter(positive))].filter((pid) => !(now - (alive.get(pid)?.at ?? 0) < ALIVE_MS));
101
107
  if (want.length) {
108
+ let running = null;
102
109
  try {
103
- // `ps -p` lists the pids that run; it exits 1 when one of them does not.
110
+ // `ps -p` lists the pids that run; it exits 1 when one of them does not. A `ps` that rejects
111
+ // its own flags (MSYS/Git `ps` on Windows) also exits 1, but writes why on stderr: no answer.
104
112
  const r = await exec("ps", ["-o", "pid=", "-p", want.join(",")], { timeout: 3000 });
105
- if (r.code === 0 || r.code === 1) {
106
- const running = new Set(String(r.stdout).split(/\s+/).map(Number).filter(positive));
107
- for (const pid of want) alive.set(pid, { ok: running.has(pid), at: now });
108
- }
113
+ if (r.code === 0 || (r.code === 1 && !r.stderr)) running = new Set(String(r.stdout).split(/\s+/).map(Number).filter(positive));
109
114
  } catch {
110
- // no ps: the publisher's own sweep is the only cleanup
115
+ // `ps` cannot start
111
116
  }
117
+ if (!running) {
118
+ try {
119
+ const r = await exec("tasklist", ["/NH", "/FO", "CSV"], { timeout: 3000 });
120
+ if (r.code === 0) running = parseTasklistPids(r.stdout);
121
+ } catch {
122
+ // neither: the publisher's own sweep is the only cleanup
123
+ }
124
+ }
125
+ if (running) for (const pid of want) alive.set(pid, { ok: running.has(pid), at: now });
112
126
  if (alive.size > 256) for (const [pid, v] of alive) if (now - v.at > 60000) alive.delete(pid);
113
127
  }
114
128
  return feeds.filter((f) => alive.get(f.identity?.pid)?.ok !== false);
@@ -305,8 +319,10 @@ export function pickedKey() {
305
319
  }
306
320
 
307
321
  // The session the window is about: the picked one (see selectSession), else the focused Gentle
308
- // Shell terminal's, else one in the shown tab, else the last one shown (`last`, a session key),
309
- // else a Herdr one, else the newest snapshot. Mirrors targetTerminal for Herdr terminals.
322
+ // Shell terminal's, else one in the shown tab. A shown Herdr tab with no Gentle Shell session shows
323
+ // none: a Herdr tab or space was chosen, so the window follows it instead of keeping another
324
+ // session. Only with no focused tab: the last one shown (`last`, a session key), else a Herdr one,
325
+ // else the newest snapshot.
310
326
  export function targetSession(feeds, last) {
311
327
  const all = allSessions(feeds);
312
328
  const picked = pickedKey();
@@ -315,18 +331,9 @@ export function targetSession(feeds, last) {
315
331
  const f = focused();
316
332
  const byAddr = (a) => (a ? all.find((s) => s.terminal?.address === a) : undefined);
317
333
  const inTab = agents().filter((a) => isGentle(a.app) && a.tab === f?.tab);
318
- return byAddr(f?.agent) ?? byAddr(f?.terminal) ?? byAddr(inTab[0]?.address)
319
- ?? (last ? all.find((s) => s.key === last) : undefined) ?? all.find((s) => s.terminal) ?? all[0] ?? null;
320
- }
321
-
322
- // The Gentle Shell terminal the window is about: the focused one, else one in the shown tab,
323
- // else the last one shown (`last`), else the first. Mirrors GentleChat.target().
324
- export function targetTerminal(last) {
325
- const all = gentleTerminals();
326
- const f = focused();
327
- const byAddr = (a) => (a ? all.find((t) => t.address === a) : undefined);
328
- const inTab = agents().filter((a) => isGentle(a.app) && a.tab === f?.tab);
329
- return byAddr(f?.agent) ?? byAddr(f?.terminal) ?? byAddr(inTab[0]?.address) ?? byAddr(last) ?? all[0] ?? null;
334
+ const here = byAddr(f?.agent) ?? byAddr(f?.terminal) ?? byAddr(inTab[0]?.address);
335
+ if (here || f?.tab) return here ?? null;
336
+ return (last ? all.find((s) => s.key === last) : undefined) ?? all.find((s) => s.terminal) ?? all[0] ?? null;
330
337
  }
331
338
 
332
339
  // The live snapshots as the leader published them ({ digest, at, feeds }), and their digest alone:
@@ -3,7 +3,7 @@
3
3
  //
4
4
  // CANONICAL COPY, carried byte-identical as `./snapshot.js` by every gentle-* mod that shows
5
5
  // snapshot data, gentle-chat included (gpui-shell refuses imports outside a mod's folder).
6
- // `targetTerminal` mirrors GentleChat.target() so every region shows one session.
6
+ // `targetSession` names the one session every region shows.
7
7
  //
8
8
  // Gentle Shell runs bundled (agent dir ~/.gentle-shell/agent), as the npm / Pi extension
9
9
  // (~/.pi/agent) or with its own home (GENTLE_PI_AGENT_HOME / PI_CODING_AGENT_DIR). Snapshots are
@@ -91,24 +91,38 @@ export async function readFeeds(roots) {
91
91
  const positive = (n) => Number.isInteger(n) && n > 0;
92
92
 
93
93
  // Whether each publisher still runs: one `ps` for the pids not checked in the last ALIVE_MS (a
94
- // crashed session leaves its snapshot behind until the next session start sweeps it). Without
95
- // `ps` (Windows) every snapshot counts as live.
94
+ // crashed session leaves its snapshot behind until the next session start sweeps it). Where `ps`
95
+ // cannot start (native Windows) or does not answer, one `tasklist` lists the running pids instead.
96
+ // A listing that did not answer decides nothing: when neither answers, every snapshot counts as live.
96
97
  const ALIVE_MS = 5000;
97
98
  const alive = new Map(); // pid -> { ok, at }
99
+
100
+ // `tasklist /NH /FO CSV` rows: "Image Name","PID","Session Name","Session#","Mem Usage".
101
+ export const parseTasklistPids = (stdout) =>
102
+ new Set([...String(stdout).matchAll(/^"[^"]*","(\d+)"/gm)].map((m) => Number(m[1])));
103
+
98
104
  export async function liveFeeds(feeds) {
99
105
  const now = Date.now();
100
106
  const want = [...new Set(feeds.map((f) => f.identity?.pid).filter(positive))].filter((pid) => !(now - (alive.get(pid)?.at ?? 0) < ALIVE_MS));
101
107
  if (want.length) {
108
+ let running = null;
102
109
  try {
103
- // `ps -p` lists the pids that run; it exits 1 when one of them does not.
110
+ // `ps -p` lists the pids that run; it exits 1 when one of them does not. A `ps` that rejects
111
+ // its own flags (MSYS/Git `ps` on Windows) also exits 1, but writes why on stderr: no answer.
104
112
  const r = await exec("ps", ["-o", "pid=", "-p", want.join(",")], { timeout: 3000 });
105
- if (r.code === 0 || r.code === 1) {
106
- const running = new Set(String(r.stdout).split(/\s+/).map(Number).filter(positive));
107
- for (const pid of want) alive.set(pid, { ok: running.has(pid), at: now });
108
- }
113
+ if (r.code === 0 || (r.code === 1 && !r.stderr)) running = new Set(String(r.stdout).split(/\s+/).map(Number).filter(positive));
109
114
  } catch {
110
- // no ps: the publisher's own sweep is the only cleanup
115
+ // `ps` cannot start
111
116
  }
117
+ if (!running) {
118
+ try {
119
+ const r = await exec("tasklist", ["/NH", "/FO", "CSV"], { timeout: 3000 });
120
+ if (r.code === 0) running = parseTasklistPids(r.stdout);
121
+ } catch {
122
+ // neither: the publisher's own sweep is the only cleanup
123
+ }
124
+ }
125
+ if (running) for (const pid of want) alive.set(pid, { ok: running.has(pid), at: now });
112
126
  if (alive.size > 256) for (const [pid, v] of alive) if (now - v.at > 60000) alive.delete(pid);
113
127
  }
114
128
  return feeds.filter((f) => alive.get(f.identity?.pid)?.ok !== false);
@@ -305,8 +319,10 @@ export function pickedKey() {
305
319
  }
306
320
 
307
321
  // The session the window is about: the picked one (see selectSession), else the focused Gentle
308
- // Shell terminal's, else one in the shown tab, else the last one shown (`last`, a session key),
309
- // else a Herdr one, else the newest snapshot. Mirrors targetTerminal for Herdr terminals.
322
+ // Shell terminal's, else one in the shown tab. A shown Herdr tab with no Gentle Shell session shows
323
+ // none: a Herdr tab or space was chosen, so the window follows it instead of keeping another
324
+ // session. Only with no focused tab: the last one shown (`last`, a session key), else a Herdr one,
325
+ // else the newest snapshot.
310
326
  export function targetSession(feeds, last) {
311
327
  const all = allSessions(feeds);
312
328
  const picked = pickedKey();
@@ -315,18 +331,9 @@ export function targetSession(feeds, last) {
315
331
  const f = focused();
316
332
  const byAddr = (a) => (a ? all.find((s) => s.terminal?.address === a) : undefined);
317
333
  const inTab = agents().filter((a) => isGentle(a.app) && a.tab === f?.tab);
318
- return byAddr(f?.agent) ?? byAddr(f?.terminal) ?? byAddr(inTab[0]?.address)
319
- ?? (last ? all.find((s) => s.key === last) : undefined) ?? all.find((s) => s.terminal) ?? all[0] ?? null;
320
- }
321
-
322
- // The Gentle Shell terminal the window is about: the focused one, else one in the shown tab,
323
- // else the last one shown (`last`), else the first. Mirrors GentleChat.target().
324
- export function targetTerminal(last) {
325
- const all = gentleTerminals();
326
- const f = focused();
327
- const byAddr = (a) => (a ? all.find((t) => t.address === a) : undefined);
328
- const inTab = agents().filter((a) => isGentle(a.app) && a.tab === f?.tab);
329
- return byAddr(f?.agent) ?? byAddr(f?.terminal) ?? byAddr(inTab[0]?.address) ?? byAddr(last) ?? all[0] ?? null;
334
+ const here = byAddr(f?.agent) ?? byAddr(f?.terminal) ?? byAddr(inTab[0]?.address);
335
+ if (here || f?.tab) return here ?? null;
336
+ return (last ? all.find((s) => s.key === last) : undefined) ?? all.find((s) => s.terminal) ?? all[0] ?? null;
330
337
  }
331
338
 
332
339
  // The live snapshots as the leader published them ({ digest, at, feeds }), and their digest alone:
@@ -23,6 +23,7 @@ import { h_flex, ScrollHandle } from "gpui-base";
23
23
  import { spaces, agents, terminals, run, openOverlay, window, layout, settings } from "herdr";
24
24
  import { tokens, stateDot, sessionTitle, kindBadge } from "./tokens.js";
25
25
  import { FeedSource, isGentle, followHerdr, selectSession, projectOf, spaceFor, machineOf, liveState, SESSION_KINDS } from "./snapshot.js";
26
+ import { newTabArgs } from "./new-tab.js";
26
27
 
27
28
  const MOD = "gentle-tabs";
28
29
 
@@ -160,8 +161,8 @@ export default class GentleTabs extends View {
160
161
  .child(div().id("tab-new").size(32).ml(4).mb(4).flex_none().flex().items_center().justify_center().rounded(8).text_color(c.muted)
161
162
  .hover((s) => s.bg(c.selected).text_color(c.text)).tooltip("New Gentle Shell session")
162
163
  .on_mouse_down("left", stop)
163
- // A new Gentle Shell session in the shown project's folder (the space's own folder).
164
- .on_click(() => run("tab.new", { argv: ["gentle-shell"], ...(space?.id ? { space: space.id } : {}), ...(space?.folder ? { folder: space.folder } : project ? { folder: project } : {}) }))
164
+ // A new Gentle Shell session in the shown session's project folder, else the space's (new-tab.js).
165
+ .on_click(() => run("tab.new", newTabArgs(space, target?.feed ? projectOf(target.feed) : null)))
165
166
  .child(svg("mods/gentle-tabs/icons/plus.svg").size(13))))
166
167
  .when(Boolean(w?.buttons), (el) => el.child(h_flex().id("window-buttons").flex_none().items_end().gap(2).ml(6)
167
168
  .child(control("minimize", win ? svg("mods/gentle-tabs/icons/win-min.svg").size(16) : "−", "Minimise", "window.minimize"))
@@ -0,0 +1,9 @@
1
+ // The "+" after the tabs (#3453): the `tab.new` arguments of a new Gentle Shell session. Pure (no
2
+ // host calls): main.js passes the shown space and the shown session's project;
3
+ // tests/gentle-shell-desktop.test.ts imports it. The session starts in the project's folder, and in
4
+ // the space's own folder only when no project is known: a space's stored folder can be another
5
+ // project's, and Herdr cannot change it after creation.
6
+ export function newTabArgs(space, project) {
7
+ const folder = project || space?.folder;
8
+ return { argv: ["gentle-shell"], ...(space?.id ? { space: space.id } : {}), ...(folder ? { folder } : {}) };
9
+ }
@@ -3,7 +3,7 @@
3
3
  //
4
4
  // CANONICAL COPY, carried byte-identical as `./snapshot.js` by every gentle-* mod that shows
5
5
  // snapshot data, gentle-chat included (gpui-shell refuses imports outside a mod's folder).
6
- // `targetTerminal` mirrors GentleChat.target() so every region shows one session.
6
+ // `targetSession` names the one session every region shows.
7
7
  //
8
8
  // Gentle Shell runs bundled (agent dir ~/.gentle-shell/agent), as the npm / Pi extension
9
9
  // (~/.pi/agent) or with its own home (GENTLE_PI_AGENT_HOME / PI_CODING_AGENT_DIR). Snapshots are
@@ -91,24 +91,38 @@ export async function readFeeds(roots) {
91
91
  const positive = (n) => Number.isInteger(n) && n > 0;
92
92
 
93
93
  // Whether each publisher still runs: one `ps` for the pids not checked in the last ALIVE_MS (a
94
- // crashed session leaves its snapshot behind until the next session start sweeps it). Without
95
- // `ps` (Windows) every snapshot counts as live.
94
+ // crashed session leaves its snapshot behind until the next session start sweeps it). Where `ps`
95
+ // cannot start (native Windows) or does not answer, one `tasklist` lists the running pids instead.
96
+ // A listing that did not answer decides nothing: when neither answers, every snapshot counts as live.
96
97
  const ALIVE_MS = 5000;
97
98
  const alive = new Map(); // pid -> { ok, at }
99
+
100
+ // `tasklist /NH /FO CSV` rows: "Image Name","PID","Session Name","Session#","Mem Usage".
101
+ export const parseTasklistPids = (stdout) =>
102
+ new Set([...String(stdout).matchAll(/^"[^"]*","(\d+)"/gm)].map((m) => Number(m[1])));
103
+
98
104
  export async function liveFeeds(feeds) {
99
105
  const now = Date.now();
100
106
  const want = [...new Set(feeds.map((f) => f.identity?.pid).filter(positive))].filter((pid) => !(now - (alive.get(pid)?.at ?? 0) < ALIVE_MS));
101
107
  if (want.length) {
108
+ let running = null;
102
109
  try {
103
- // `ps -p` lists the pids that run; it exits 1 when one of them does not.
110
+ // `ps -p` lists the pids that run; it exits 1 when one of them does not. A `ps` that rejects
111
+ // its own flags (MSYS/Git `ps` on Windows) also exits 1, but writes why on stderr: no answer.
104
112
  const r = await exec("ps", ["-o", "pid=", "-p", want.join(",")], { timeout: 3000 });
105
- if (r.code === 0 || r.code === 1) {
106
- const running = new Set(String(r.stdout).split(/\s+/).map(Number).filter(positive));
107
- for (const pid of want) alive.set(pid, { ok: running.has(pid), at: now });
108
- }
113
+ if (r.code === 0 || (r.code === 1 && !r.stderr)) running = new Set(String(r.stdout).split(/\s+/).map(Number).filter(positive));
109
114
  } catch {
110
- // no ps: the publisher's own sweep is the only cleanup
115
+ // `ps` cannot start
111
116
  }
117
+ if (!running) {
118
+ try {
119
+ const r = await exec("tasklist", ["/NH", "/FO", "CSV"], { timeout: 3000 });
120
+ if (r.code === 0) running = parseTasklistPids(r.stdout);
121
+ } catch {
122
+ // neither: the publisher's own sweep is the only cleanup
123
+ }
124
+ }
125
+ if (running) for (const pid of want) alive.set(pid, { ok: running.has(pid), at: now });
112
126
  if (alive.size > 256) for (const [pid, v] of alive) if (now - v.at > 60000) alive.delete(pid);
113
127
  }
114
128
  return feeds.filter((f) => alive.get(f.identity?.pid)?.ok !== false);
@@ -305,8 +319,10 @@ export function pickedKey() {
305
319
  }
306
320
 
307
321
  // The session the window is about: the picked one (see selectSession), else the focused Gentle
308
- // Shell terminal's, else one in the shown tab, else the last one shown (`last`, a session key),
309
- // else a Herdr one, else the newest snapshot. Mirrors targetTerminal for Herdr terminals.
322
+ // Shell terminal's, else one in the shown tab. A shown Herdr tab with no Gentle Shell session shows
323
+ // none: a Herdr tab or space was chosen, so the window follows it instead of keeping another
324
+ // session. Only with no focused tab: the last one shown (`last`, a session key), else a Herdr one,
325
+ // else the newest snapshot.
310
326
  export function targetSession(feeds, last) {
311
327
  const all = allSessions(feeds);
312
328
  const picked = pickedKey();
@@ -315,18 +331,9 @@ export function targetSession(feeds, last) {
315
331
  const f = focused();
316
332
  const byAddr = (a) => (a ? all.find((s) => s.terminal?.address === a) : undefined);
317
333
  const inTab = agents().filter((a) => isGentle(a.app) && a.tab === f?.tab);
318
- return byAddr(f?.agent) ?? byAddr(f?.terminal) ?? byAddr(inTab[0]?.address)
319
- ?? (last ? all.find((s) => s.key === last) : undefined) ?? all.find((s) => s.terminal) ?? all[0] ?? null;
320
- }
321
-
322
- // The Gentle Shell terminal the window is about: the focused one, else one in the shown tab,
323
- // else the last one shown (`last`), else the first. Mirrors GentleChat.target().
324
- export function targetTerminal(last) {
325
- const all = gentleTerminals();
326
- const f = focused();
327
- const byAddr = (a) => (a ? all.find((t) => t.address === a) : undefined);
328
- const inTab = agents().filter((a) => isGentle(a.app) && a.tab === f?.tab);
329
- return byAddr(f?.agent) ?? byAddr(f?.terminal) ?? byAddr(inTab[0]?.address) ?? byAddr(last) ?? all[0] ?? null;
334
+ const here = byAddr(f?.agent) ?? byAddr(f?.terminal) ?? byAddr(inTab[0]?.address);
335
+ if (here || f?.tab) return here ?? null;
336
+ return (last ? all.find((s) => s.key === last) : undefined) ?? all.find((s) => s.terminal) ?? all[0] ?? null;
330
337
  }
331
338
 
332
339
  // The live snapshots as the leader published them ({ digest, at, feeds }), and their digest alone: