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
@@ -20,6 +20,7 @@ import { fileURLToPath } from "node:url";
20
20
  import { promisify } from "node:util";
21
21
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
22
22
  import { appendSystemPromptOnce, type AppendableSystemPromptOptions } from "../lib/append-system-prompt.ts";
23
+ import { setPathConsentSkills } from "../lib/path-consent-fence.ts";
23
24
  import { isHomeOrBroadUserDirectory } from "../lib/bounded-writer-admission.ts";
24
25
  import { resolveSessionWorktree } from "../lib/session-worktree-registry.ts";
25
26
 
@@ -991,7 +992,10 @@ export default function (pi: ExtensionAPI) {
991
992
  pi.on("before_agent_start", async (event, ctx) => {
992
993
  const options = event.systemPromptOptions;
993
994
  clearEffectivePrompt(options);
995
+ setPathConsentSkills(ctx, "registry", []);
994
996
  if (shouldSkipSkillRegistryStartup(pi) || !options) return;
997
+ const manager = ctx.sessionManager, sessionId = manager?.getSessionId?.(), cwd = ctx.cwd;
998
+ const generation = startupGeneration;
995
999
  const skills = options.skills;
996
1000
  if (Array.isArray(skills) && skills.every(isResolvedSkill)) {
997
1001
  lastResolvedSkills = skills.map(trimResolvedSkill);
@@ -1002,7 +1006,11 @@ export default function (pi: ExtensionAPI) {
1002
1006
  .filter((entry): entry is SkillEntry => entry !== undefined);
1003
1007
  const effective = mergeResolvedWithLoose(resolved, entries, ctx.cwd, lastResolvedSkills.map((skill) => skill.filePath));
1004
1008
  const piListed = piRendersAvailableSkills(options as { selectedTools?: unknown });
1005
- appendEffectivePrompt(options, ctx.cwd, unlistedEntries(effective, piListed ? resolved : []), piListed);
1009
+ const advertised = unlistedEntries(effective, piListed ? resolved : []);
1010
+ appendEffectivePrompt(options, ctx.cwd, advertised, piListed);
1011
+ if (generation === startupGeneration && ctx.sessionManager === manager && manager?.getSessionId?.() === sessionId && ctx.cwd === cwd) {
1012
+ setPathConsentSkills(ctx, "registry", advertised.map(entry => entry.path));
1013
+ }
1006
1014
  } catch {
1007
1015
  // Preserve best-effort behavior without advertising a stale or incomplete view.
1008
1016
  }
@@ -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:
@@ -137,6 +137,12 @@ const firstLine = (s) => {
137
137
  };
138
138
 
139
139
  // Adds the complete lines in `text` to the feed. Bad lines are skipped, never thrown.
140
+ // A feed can describe a session this view cannot read: another agent publishes the same
141
+ // snapshot without a Pi session file. The chat then has no transcript, and falling back to the
142
+ // terminal's folder would read a different session's.
143
+ export const hasTranscript = (identity) =>
144
+ typeof identity?.sessionFile === "string" && identity.sessionFile.endsWith(".jsonl");
145
+
140
146
  export function ingest(feed, text) {
141
147
  for (const line of text.split("\n")) {
142
148
  if (!line.trim()) continue;
@@ -21,7 +21,7 @@ import { agents, props, layout, hc, run, setShared, shared, theme, watchFolder,
21
21
  import { readFile } from "fs/promises";
22
22
  import { sessionFileFor, readAfter, readTail, utf8 } from "./session.js";
23
23
  import { FeedSource, allSessions, targetSession, machineOf, liveState } from "./snapshot.js";
24
- import { createFeed, ingest, hideThinkingFrom } from "./feed.js";
24
+ import { createFeed, ingest, hideThinkingFrom, hasTranscript } from "./feed.js";
25
25
  import { palette, sans, R } from "./tokens.js";
26
26
  import { header, entries, entry, lane, stateLabel, askCard, askOptions, composer, icon, PERM, ELSEWHERE } from "./ui.js";
27
27
  import { sendAction, errorText, safeKeys, terminalFree, tuiCommand, showTerminal, confirm, confirmed, readSnapshot } from "./actions.js";
@@ -43,6 +43,7 @@ const REQUEST_MS = 10000; // a palette request older than this is ignored (share
43
43
  const NO_COMMANDS = "Open that session's terminal to run /commands.";
44
44
  const KEPT = 30; // sessions whose opened rows are remembered when another session shows
45
45
  const DOUBLE_MS = 300; // one ⌘O that reaches both the chat's key and the layout's key toggles once
46
+ const READ_FAILED = ["Cannot read this conversation", "Its session file could not be read. The chat tries again when the session updates."];
46
47
 
47
48
  // The composer's "/" menu: open while the draft is one "/word" (no space or line break yet).
48
49
  // Names that start with the word come first, then names and descriptions that contain it.
@@ -95,6 +96,10 @@ export default class GentleChat extends View {
95
96
  this.requesting = false;
96
97
  this.settingsDirs = new Set(); // the folders of the shown session's settings files, watched
97
98
  this.real = new Map(); // cwd -> real path, for sessionFileFor
99
+ // A session that publishes a feed without a Pi session file (another agent): there is no
100
+ // transcript this view can read, and falling back to the folder would show a different one.
101
+ this.foreign = false;
102
+ this.readFailed = false; // the last read of the session file failed (#3537): never shown as an empty conversation
98
103
  this.open = new Map(); // row id -> open, when flipped from its default (S11: per row, kept across reads)
99
104
  this.hunkAt = new Map(); // diff card id -> shown hunk
100
105
  this.kept = new Map(); // session file -> { open, hunkAt } of a session shown before
@@ -224,12 +229,30 @@ export default class GentleChat extends View {
224
229
  return targetSession(this.source.feeds, this.key);
225
230
  }
226
231
 
232
+ // The shown session follows the pick at once, before any await: Send, answers and actions go to
233
+ // it even while a refresh of the session shown before still reads.
227
234
  tick(cx) {
228
235
  this.want = this.pick();
229
236
  this.wantFeeds = this.source.feeds;
237
+ this.show(this.want, cx);
230
238
  cx.spawn(async (cx) => { await this.refreshNow(cx); });
231
239
  }
232
240
 
241
+ // Makes `s` the shown session: its key, its Herdr terminal and its snapshot (where actions go).
242
+ show(s, cx) {
243
+ const key = s?.key ?? null;
244
+ const address = s?.terminal?.address ?? null;
245
+ if (key !== this.key) {
246
+ this.key = key;
247
+ this.cwd = s?.terminal?.cwd ?? s?.feed?.identity?.cwd ?? null;
248
+ this.dir = null;
249
+ this.reset(null);
250
+ this.setSnap(s?.feed ?? null);
251
+ cx.notify();
252
+ }
253
+ if (address !== this.address) { this.address = address; cx.notify(); }
254
+ }
255
+
233
256
  // One refresh at a time; a call during one runs it again after, for the newest `want`.
234
257
  async refreshNow(cx) {
235
258
  if (this.refreshing) { this.reagain = true; return; }
@@ -254,28 +277,35 @@ export default class GentleChat extends View {
254
277
  const s = this.want;
255
278
  const key = s?.key ?? null;
256
279
  const address = s?.terminal?.address ?? null;
257
- if (key !== this.key) {
258
- this.key = key;
259
- this.cwd = s?.terminal?.cwd ?? s?.feed?.identity?.cwd ?? null;
260
- this.dir = null;
261
- this.reset(null);
262
- this.setSnap(null);
263
- cx.notify();
264
- }
265
- if (address !== this.address) { this.address = address; cx.notify(); }
280
+ this.show(s, cx);
281
+ if (!s && this.foreign) { this.foreign = false; cx.notify(); }
266
282
  if (!s) return;
267
283
  // S14: a terminal on another machine. Its session file and snapshot are on that machine and the
268
284
  // desktop feed reads this computer's, so nothing is read (a local file of the same folder would
269
285
  // be another session): the empty state says where it runs, the Terminal shows it.
270
- if (machineOf(address)) return;
286
+ // A remote terminal renders its own state, so a foreign flag from the previous session stops
287
+ // here; routine refreshes of the shown session must not clear it.
288
+ if (machineOf(address)) {
289
+ if (this.foreign) { this.foreign = false; this.dir = null; this.reset(null); cx.notify(); }
290
+ return;
291
+ }
271
292
  // The snapshot names the exact session file; a terminal without one falls back to its folder.
272
293
  const exact = s.feed?.identity?.sessionFile;
294
+ const foreign = Boolean(s.feed) && !hasTranscript(s.feed.identity);
295
+ if (foreign !== this.foreign) {
296
+ this.foreign = foreign;
297
+ // The same key can turn foreign (a feed that stops naming a Pi session file): drop the
298
+ // transcript read earlier, or it would sit beside the notice that we cannot read it.
299
+ if (foreign) { this.dir = null; this.reset(null); }
300
+ cx.notify();
301
+ }
273
302
  const where = typeof exact === "string" && exact.endsWith(".jsonl")
274
303
  ? { dir: exact.slice(0, Math.max(exact.lastIndexOf("/"), exact.lastIndexOf("\\"))), file: exact, feed: s.feed }
275
- : s.terminal ? await sessionFileFor(s.terminal, this.real, this.wantFeeds) : null;
304
+ : foreign ? null : s.terminal ? await sessionFileFor(s.terminal, this.real, this.wantFeeds) : null;
276
305
  if (this.key !== key) return;
277
306
  if (this.setSnap(where?.feed ?? s.feed ?? null)) cx.notify();
278
307
  if (this.settingsOf !== key) await this.readSettings(s, cx);
308
+ if (this.key !== key) return;
279
309
  if (!where) return;
280
310
  if (where.dir !== this.dir) { this.dir = where.dir; this.watch(where.dir, cx); }
281
311
  if (where.file !== this.file) { this.reset(where.file); cx.notify(); }
@@ -375,6 +405,7 @@ export default class GentleChat extends View {
375
405
  this.limit = PAGE;
376
406
  this.stick = true;
377
407
  this.error = null;
408
+ this.readFailed = false;
378
409
  }
379
410
 
380
411
  // Watches the session folder. With the snapshot's exact file, only a write to that file reads
@@ -389,6 +420,7 @@ export default class GentleChat extends View {
389
420
  const paths = await watchFolder(dir);
390
421
  if (this.watched !== dir) break;
391
422
  const file = this.file;
423
+ if (this.foreign) { this.watched = null; return; } // nothing to read: the empty state already says why
392
424
  if (!file || typeof this.snap?.identity?.sessionFile !== "string") { await this.refreshNow(cx); continue; }
393
425
  const name = file.slice(file.lastIndexOf("/") + 1);
394
426
  if (!Array.isArray(paths) || paths.some((p) => p === file || p === dir || String(p).endsWith(`/${name}`))) await this.load(cx);
@@ -420,7 +452,8 @@ export default class GentleChat extends View {
420
452
 
421
453
  // Reads only the complete lines added since `pos` (a long session: first its tail, readTail).
422
454
  // The file only grows; if it shrank, start over. A big file is read through `sh`, which gives
423
- // its size and only the new bytes; a small one is read whole and sliced (session.js).
455
+ // its size and only the new bytes; a small one is read whole and sliced (session.js). A read
456
+ // from the start that fails is shown as a failure; `pos` stays 0, so the next refresh reads again.
424
457
  async load(cx) {
425
458
  if (this.loading) { this.again = true; return; }
426
459
  this.loading = true;
@@ -434,7 +467,8 @@ export default class GentleChat extends View {
434
467
  const first = !this.feed.items.length;
435
468
  const t = await readTail(file, TAIL * this.back, LINES * this.back, TAIL_MAX * this.back);
436
469
  if (file !== this.file) return;
437
- if (!t) continue;
470
+ if (!t) { this.readFailed = true; cx.notify(); continue; }
471
+ this.readFailed = false;
438
472
  const feed = createFeed();
439
473
  ingest(feed, t.text);
440
474
  this.feed = feed;
@@ -450,8 +484,10 @@ export default class GentleChat extends View {
450
484
  if (Number.isFinite(size)) this.size = size;
451
485
  if (text === null) {
452
486
  if (this.pos > 0) { this.reset(file); this.again = true; }
487
+ else { this.readFailed = true; cx.notify(); }
453
488
  continue;
454
489
  }
490
+ if (this.readFailed) { this.readFailed = false; cx.notify(); }
455
491
  if (text) {
456
492
  ingest(this.feed, text);
457
493
  this.pos = end;
@@ -917,6 +953,13 @@ export default class GentleChat extends View {
917
953
  const busy = live && (live.status === "working" || live.status === "waiting");
918
954
  if (working || busy) rows.push(lane(stateLabel(p, "work", busy ? live.label : "Working")));
919
955
  }
956
+ // A foreign session or a failed read can still have a status row; the explanation has to appear anyway.
957
+ if ((this.foreign || this.readFailed) && rows.length > 0) {
958
+ const [title, about] = this.foreign ? this.foreignText() : READ_FAILED;
959
+ rows.push(lane(v_flex().id("foreign").flex_none().self_center().items_center().px(28).py(24).gap(4)
960
+ .child(div().text_size(14).font_semibold().text_color(p.text).child(title))
961
+ .child(div().text_size(12.5).text_color(p.muted).text_center().child(about))));
962
+ }
920
963
  const empty = !rows.length;
921
964
  // Pinned to the newest entry: new items pin it, scrolling up unpins it. scroll_to_item
922
965
  // reveals a child with the least scroll, so the target is a 1px sentinel after the last row,
@@ -950,15 +993,32 @@ export default class GentleChat extends View {
950
993
 
951
994
  // No conversation yet (the artboard has no such state): a calm block in the middle of the
952
995
  // log, in the design's type: the mark in faint, a 14px semibold line, a 12.5px muted line.
953
- empty(p) {
996
+ // The same words in the empty state and above any status row: a feed with no Pi session file
997
+ // cannot be read here, and where the session runs changes what the person can do about it.
998
+ foreignText() {
999
+ const where = this.address
1000
+ ? "This view can only show its Terminal (⌘J)."
1001
+ : "Open its terminal where it runs to follow the conversation.";
1002
+ return ["No transcript for this session", `It publishes a desktop feed but no Pi session file. ${where}`];
1003
+ }
1004
+
1005
+ emptyText() {
954
1006
  const machine = machineOf(this.address);
955
- const [title, about] = machine
1007
+ return machine
956
1008
  ? [`Runs on ${machine}`, `Herdr shows its state and its Terminal (⌘J). Its conversation and desktop feed stay on ${machine}: this window reads this computer's.`]
1009
+ : this.foreign
1010
+ ? this.foreignText()
957
1011
  : !this.key
958
1012
  ? ["No Gentle Shell session", "Start one with + in the tab bar, or run gentle-shell in a terminal."]
959
1013
  : !this.file
960
1014
  ? ["Waiting for the first message", "This session has not written its conversation yet."]
1015
+ : this.readFailed
1016
+ ? READ_FAILED
961
1017
  : ["No messages yet", this.address ? "Type below to start. ⌘J shows the Terminal." : "Type below to start."];
1018
+ }
1019
+
1020
+ empty(p) {
1021
+ const [title, about] = this.emptyText();
962
1022
  return v_flex().id("log").flex_1().min_h(0).items_center().justify_center().gap(6).px(28).pb(40)
963
1023
  .on_mouse_down("left", () => this.focus.focus())
964
1024
  .child(icon("mark", 26).text_color(p.faint).mb(4))
@@ -93,17 +93,24 @@ export function utf8(bytes) {
93
93
  // when the file shrank or vanished (start over). A half-written last line waits for the next read.
94
94
  // Only the new bytes are decoded and parsed. The runtime has no ranged read and no stat, so the
95
95
  // bytes are fetched whole and sliced; `viaExec` (a big file, S13) asks `sh` for the size and the
96
- // new bytes only instead: one process, no multi-megabyte copy per write.
96
+ // new bytes only instead: one process, no multi-megabyte copy per write. Where `sh` cannot start
97
+ // (native Windows, #3352) the file is fetched whole and sliced after all.
97
98
  // `max` caps one slice so a huge first read doesn't stall the UI thread (`more` = call again).
98
99
  export async function readAfter(file, pos, max = 2 * 1024 * 1024, viaExec = false) {
99
- if (viaExec) return readOutside(file, pos, max);
100
+ if (viaExec) {
101
+ const r = await readOutside(file, pos, max);
102
+ if (r) return r;
103
+ }
100
104
  let bytes;
101
105
  try {
102
106
  bytes = await readFile(file);
103
107
  } catch (e) {
104
108
  // Herdr grants mods read access to the home folder only; a session resumed from elsewhere
105
109
  // (`gentle-shell --session /tmp/x.jsonl`) is read through `exec` instead.
106
- if (OUTSIDE.test(String(e?.message ?? e))) return readOutside(file, pos, max);
110
+ if (OUTSIDE.test(String(e?.message ?? e))) {
111
+ const r = await readOutside(file, pos, max);
112
+ if (r) return r;
113
+ }
107
114
  return { text: null, end: 0, more: false, size: 0 };
108
115
  }
109
116
  const size = bytes.length;
@@ -168,14 +175,15 @@ export function utf8Length(s) {
168
175
  }
169
176
 
170
177
  // readAfter for a file outside the read roots: its size, then the bytes after `pos`, from one
171
- // `sh` (the path and numbers are positional arguments, never part of the script).
178
+ // `sh` (the path and numbers are positional arguments, never part of the script). Null when
179
+ // `exec` rejected (Herdr: `sh` could not start, or it timed out).
172
180
  async function readOutside(file, pos, max) {
173
181
  const cap = Math.max(1, Math.min(max * 3, EXEC_MAX));
174
182
  let r;
175
183
  try {
176
184
  r = await exec("sh", ["-c", 'wc -c < "$2" && tail -c +"$1" "$2" | head -c "$3"', "sh", String(pos + 1), file, String(cap)], { timeout: 15000 });
177
185
  } catch {
178
- return { text: null, end: 0, more: false };
186
+ return null;
179
187
  }
180
188
  const cut = r.stdout.indexOf("\n");
181
189
  const size = Number.parseInt(r.stdout.slice(0, cut), 10);
@@ -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:
@@ -86,6 +86,12 @@ function toolSay(v, call) {
86
86
 
87
87
  // ---------------------------------------------------------------- 4a header (l.259-270, 369-399)
88
88
 
89
+ // The feed carries the mode token ("gentleman"); the header shows it as a name, or null when unknown.
90
+ export function personaLabel(persona) {
91
+ const raw = typeof persona === "string" ? persona : persona?.name ?? null;
92
+ return raw ? raw.charAt(0).toUpperCase() + raw.slice(1) : null;
93
+ }
94
+
89
95
  export function header(v, p) {
90
96
  const s = v.snap;
91
97
  const f = v.feed;
@@ -207,7 +213,7 @@ function facts(v, p) {
207
213
  const modelFact = (compact) => profileMenu(v, p, fact("f-model", [k("Model"), ...(compact ? [] : [model ? div().child(model) : none()]), icon("down", 13).text_color(p.muted)],
208
214
  compact ? `Model · ${model || "—"} (switch profile)` : "Model · effort · profile (switch profile)").cursor_pointer().hover((st) => st.bg(p.selected))
209
215
  .when(v.busy === "profile", (el) => el.opacity(0.6)));
210
- const persona = typeof s?.persona === "string" ? s.persona : s?.persona?.name ?? null;
216
+ const persona = personaLabel(s?.persona);
211
217
  const personaFact = fact("f-persona", [icon("user", 13).text_color(p.muted), persona ? div().child(persona) : none("No persona")],
212
218
  "Persona (opens /gentle:persona in the Terminal)").cursor_pointer().hover((st) => st.bg(p.selected))
213
219
  .on_click((_e, cx) => v.command("persona", "/gentle:persona", cx));
@@ -483,6 +483,8 @@ export default class GentleInspector extends View {
483
483
  const c = tokens();
484
484
  // The shown session, wherever it runs (snapshot.js targetSession, T11).
485
485
  const shown = this.source.target(this.last);
486
+ // A refusal or notice belongs to the session it came from.
487
+ if ((shown?.key ?? null) !== this.last) { this.error = null; this.notice = null; }
486
488
  if (shown) this.last = shown.key;
487
489
  this.address = shown?.terminal?.address ?? null;
488
490
  const f = shown?.feed ?? null;
@@ -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:
@@ -4,7 +4,7 @@
4
4
  // 1px line-strong, radius 12, 6px padding, rows 7px 8px radius 6 with a hover fill), .eyebrow
5
5
  // group titles, kbd hints and the i-search / i-cmd symbols (l.305, l.314).
6
6
  //
7
- // What it lists, for the Gentle Shell session the window is about (snapshot.js targetTerminal):
7
+ // What it lists, for the Gentle Shell session the window is about (snapshot.js targetSession):
8
8
  // Needs you every session (any agent) waiting for the person → focuses it
9
9
  // Session Stop the agent (while it works), then pi's session commands (new, resume,
10
10
  // fork, compact, name, export, …) from the session's snapshot `commands`