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.
- package/README.md +1 -1
- package/assets/agents/gentle-ai-explore.md +3 -6
- package/assets/agents/gentle-ai-verify.md +1 -1
- package/assets/agents/gentle-ai-worker.md +9 -9
- package/assets/agents/jd-fix-agent.md +1 -1
- package/assets/agents/jd-judge-a.md +0 -1
- package/assets/agents/jd-judge-b.md +0 -1
- package/assets/migrations/agent-body-history.json +6 -0
- package/assets/orchestrator-full-delegation.md +1 -1
- package/assets/orchestrator-maintenance.md +11 -0
- package/assets/orchestrator-quota-recovery.md +1 -1
- package/assets/orchestrator-skills.md +10 -0
- package/assets/orchestrator-verification.md +9 -7
- package/assets/orchestrator.md +1 -1
- package/bin/gentle-shell.mjs +67 -15
- package/contracts/review-provider-contract-mirror/provider-contract.lock.json +10 -10
- package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/manifest.json +5 -5
- package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/orchestration/pi.md +5 -3
- package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/routing/pi.md +1 -1
- package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/schemas/lens.schema.json +3 -3
- package/contracts/review-provider-contract-mirror/v1.7.0/bundle/vectors/lens.json +1 -0
- package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/generated/provider-capabilities.baseline.json +3 -3
- package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/generated/provider-roles.baseline.json +3 -3
- package/docs/bundled-install.md +2 -2
- package/docs/delegated-verification.md +8 -4
- package/docs/desktop-feed.md +15 -6
- package/docs/desktop-rpc.md +44 -20
- package/docs/gentle-shell-desktop.md +10 -3
- package/docs/gentle-shell.md +17 -13
- package/docs/install-wizard.md +2 -2
- package/docs/odd-preparation-continuity.md +2 -2
- package/docs/permission-modes.md +10 -2
- package/docs/readme-reference.md +46 -11
- package/docs/session-profile-format.md +33 -7
- package/docs/work-continuity.md +7 -7
- package/docs/yolo-mode.md +1 -1
- package/extensions/child-context.ts +2 -11
- package/extensions/gentle-agents.ts +47 -28
- package/extensions/gentle-ai.ts +573 -353
- package/extensions/gentle-desktop-feed.ts +13 -3
- package/extensions/gentle-fast.ts +9 -2
- package/extensions/gentle-shell.ts +142 -55
- package/extensions/gentle-tps.ts +5 -0
- package/extensions/quiet-tools.ts +13 -22
- package/extensions/skill-registry.ts +9 -1
- package/herdr/mods/gentle-agents/snapshot.js +30 -23
- package/herdr/mods/gentle-chat/feed.js +6 -0
- package/herdr/mods/gentle-chat/main.js +76 -16
- package/herdr/mods/gentle-chat/session.js +13 -5
- package/herdr/mods/gentle-chat/snapshot.js +30 -23
- package/herdr/mods/gentle-chat/ui.js +7 -1
- package/herdr/mods/gentle-inspector/main.js +2 -0
- package/herdr/mods/gentle-inspector/snapshot.js +30 -23
- package/herdr/mods/gentle-palette/main.js +1 -1
- package/herdr/mods/gentle-palette/snapshot.js +30 -23
- package/herdr/mods/gentle-pane/snapshot.js +30 -23
- package/herdr/mods/gentle-sidebar/snapshot.js +30 -23
- package/herdr/mods/gentle-spaces/snapshot.js +30 -23
- package/herdr/mods/gentle-status/snapshot.js +30 -23
- package/herdr/mods/gentle-tabs/main.js +3 -2
- package/herdr/mods/gentle-tabs/new-tab.js +9 -0
- package/herdr/mods/gentle-tabs/snapshot.js +30 -23
- package/herdr/mods/gentle-tokens/snapshot.js +30 -23
- package/lib/agent-profiles.ts +50 -10
- package/lib/agents-config.ts +59 -4
- package/lib/agents-runner.ts +34 -1
- package/lib/auto-permission-runtime.ts +2 -1
- package/lib/background-jobs-tools.ts +24 -16
- package/lib/claude-bridge-config.ts +41 -0
- package/lib/desktop-agent-definitions-service.ts +10 -6
- package/lib/desktop-command-rpc.ts +71 -0
- package/lib/desktop-feed-sources.ts +44 -1
- package/lib/desktop-feed.ts +41 -29
- package/lib/desktop-rpc-agent-definitions.ts +7 -3
- package/lib/desktop-rpc-changes.ts +13 -4
- package/lib/desktop-rpc-config.ts +106 -3
- package/lib/exploration-budget.ts +3 -7
- package/lib/gentle-design.ts +23 -4
- package/lib/gentle-shell-desktop.ts +85 -0
- package/lib/gentle-shell-launcher.ts +106 -3
- package/lib/mcp-config.ts +214 -0
- package/lib/native-review-cli.ts +78 -34
- package/lib/odd-phase-inference.ts +1 -1
- package/lib/orchestrator-mode-policy.ts +25 -12
- package/lib/path-consent-fence.ts +113 -0
- package/lib/pi-settings.ts +157 -0
- package/lib/review-continuation-registry.ts +7 -20
- package/lib/review-coordinator.ts +5 -0
- package/lib/review-host-relay.ts +2 -35
- package/lib/review-integration-v2.ts +31 -12
- package/lib/sensitive-paths.ts +22 -2
- package/lib/session-profile-freeze.ts +11 -4
- package/lib/session-worktree-registry.ts +11 -5
- package/lib/shell-card.ts +27 -1
- package/lib/shell-changes-view.ts +6 -2
- package/lib/shell-changes.ts +94 -37
- package/lib/shell-git-worker.ts +158 -0
- package/lib/shell-idle-changes.ts +88 -0
- package/lib/shell-untracked-cache.ts +142 -0
- package/lib/shell-untracked-lines.ts +178 -0
- package/lib/tps-policy.ts +85 -0
- package/lib/vim-editor-adapter.ts +3 -2
- package/lib/voice-artifacts.ts +8 -1
- package/lib/voice-install.ts +7 -3
- package/lib/yolo-session-policy.ts +2 -2
- package/package.json +1 -1
- package/runtime/gentle-shell-desktop.mjs +85 -0
- package/runtime/gentle-shell-launcher.mjs +106 -3
- package/runtime/native-review-cli.mjs +77 -33
- package/runtime/review-integration-v2.mjs +31 -12
- package/runtime/sensitive-paths.mjs +22 -2
- package/scripts/gentle-ai-installer.mjs +10 -10
- package/scripts/main-channel.mjs +27 -7
- package/scripts/verify-package-files.mjs +13 -12
- package/skills/rdd-defect-workflow/SKILL.md +2 -2
- package/tests/agent-profiles-workflow.test.ts +102 -0
- package/tests/agents-config.test.ts +1 -2
- package/tests/agents-protocol.test.ts +1 -1
- package/tests/agents-runner.test.ts +94 -2
- package/tests/append-system-prompt-route.test.ts +16 -11
- package/tests/auto-permission-runtime.test.ts +4 -4
- package/tests/bounded-stop-contract.test.ts +50 -62
- package/tests/child-context-files.test.ts +6 -6
- package/tests/child-web-package.test.ts +1 -1
- package/tests/controlled-engineering-editor.test.ts +192 -0
- package/tests/controlled-engineering-launch.test.ts +136 -0
- package/tests/controlled-engineering.test.ts +244 -0
- package/tests/delivery-b-rendered-surfaces.test.ts +1 -1
- package/tests/desktop-feed-tool-summaries.test.ts +1 -1
- package/tests/desktop-feed-transcript.test.ts +17 -0
- package/tests/desktop-feed.test.ts +141 -7
- package/tests/desktop-liveness.test.ts +125 -0
- package/tests/desktop-persona.test.ts +17 -0
- package/tests/desktop-rpc-agent-definitions.test.ts +23 -2
- package/tests/desktop-rpc-changes.test.ts +80 -3
- package/tests/desktop-rpc-config-mcp-fidelity.test.ts +106 -0
- package/tests/desktop-rpc-config-readonly-stores.test.ts +458 -0
- package/tests/desktop-rpc-config.test.ts +5 -2
- package/tests/desktop-rpc-design.test.ts +21 -0
- package/tests/desktop-rpc-session-snapshot-commands.test.ts +50 -0
- package/tests/desktop-session-switch.test.ts +237 -0
- package/tests/desktop-target-session.test.ts +104 -0
- package/tests/destructive-command-guard.test.ts +187 -0
- package/tests/devbinary/pi-host-relay.devtest.ts +73 -9
- package/tests/exploration-budget.test.ts +2 -26
- package/tests/fixtures/primary-session-prompt/gentleman.golden.md +14 -10
- package/tests/full-delegation-closure.test.ts +19 -9
- package/tests/generic-agent-tools.test.ts +3 -3
- package/tests/gentle-agents.test.ts +214 -9
- package/tests/gentle-ai-exploration-budget.test.ts +3 -2
- package/tests/gentle-ai-installer.test.ts +52 -51
- package/tests/gentle-ai.test.ts +29 -5
- package/tests/gentle-chat-read-failure.test.ts +74 -0
- package/tests/gentle-chat-session-read.test.ts +127 -0
- package/tests/gentle-design.test.ts +39 -0
- package/tests/gentle-shell-desktop.test.ts +108 -0
- package/tests/gentle-shell-launcher-auto-provision.test.ts +152 -0
- package/tests/gentle-shell-launcher-machine-output.test.ts +356 -0
- package/tests/gentle-shell.test.ts +93 -12
- package/tests/gentle-tps.test.ts +57 -0
- package/tests/independent-recovery-delivery.test.ts +15 -13
- package/tests/installer-preflight.test.ts +3 -2
- package/tests/job-turn-end-texts.test.ts +57 -0
- package/tests/lazy-module-contradictions-contract.test.ts +1 -2
- package/tests/main-channel.test.ts +12 -1
- package/tests/maintainer/desktop-rpc.maintest.ts +2 -2
- package/tests/native-review-capability-contract.test.ts +7 -1
- package/tests/native-review-cli.test.ts +113 -1
- package/tests/no-self-pause-contract.test.ts +8 -7
- package/tests/odd-phase-inference.test.ts +2 -2
- package/tests/odd-routing-canonical-ratchet.test.ts +1 -1
- package/tests/odd-routing-contract.test.ts +1 -1
- package/tests/orchestrator-budget.test.ts +7 -2
- package/tests/orchestrator-prompt-diet-contract.test.ts +5 -5
- package/tests/orchestrator-skills-inline-contract.test.ts +26 -0
- package/tests/package-manifest.test.ts +11 -16
- package/tests/packaged-agent-codemode.test.ts +79 -0
- package/tests/path-consent-fence.test.ts +326 -0
- package/tests/pi-update-launcher.test.ts +1 -1
- package/tests/primary-session-prompt.test.ts +9 -7
- package/tests/profile-fast-tier.test.ts +79 -4
- package/tests/progress-rule-contract.test.ts +54 -0
- package/tests/rdd-delivery-warning.test.ts +42 -4
- package/tests/review-actor-tool-deny.test.ts +1 -2
- package/tests/review-continuation-registry.test.ts +17 -17
- package/tests/review-controller-native-recovery.test.ts +100 -0
- package/tests/review-controller-native-routing.test.ts +129 -24
- package/tests/review-coordinator.test.ts +14 -0
- package/tests/review-host-relay-restart-parity.test.ts +2 -52
- package/tests/review-host-relay-routing.test.ts +57 -297
- package/tests/review-host-relay.test.ts +0 -46
- package/tests/review-integration-v2-forward.test.ts +39 -2
- package/tests/review-json-arguments.test.ts +30 -9
- package/tests/review-one-call-findings.test.ts +1 -0
- package/tests/review-untracked-inventory-replay.test.ts +181 -0
- package/tests/runtime-harness.mjs +27 -1
- package/tests/sensitive-path-tools.test.ts +155 -4
- package/tests/session-profile-extension.test.ts +90 -11
- package/tests/session-profile-freeze.test.ts +49 -2
- package/tests/session-profile-v1-compat.test.ts +11 -3
- package/tests/session-worktree-registry.test.ts +23 -0
- package/tests/shell-changes-idle-start.test.ts +510 -0
- package/tests/shell-changes-untracked-bound.test.ts +230 -0
- package/tests/shell-changes-view.test.ts +8 -2
- package/tests/shell-changes.test.ts +134 -0
- package/tests/shell-git-runner-stall.test.ts +74 -0
- package/tests/shell-git-worker-fallback.test.ts +140 -0
- package/tests/shell-git-worker-lifetime.test.ts +91 -0
- package/tests/shell-render-cache-runtime.test.ts +256 -3
- package/tests/shell-untracked-cache.test.ts +213 -0
- package/tests/short-check-routing-contract.test.ts +11 -7
- package/tests/skill-registry.test.ts +3 -3
- package/tests/support/chat-ui.ts +39 -0
- package/tests/t7-recovery-preservation.test.ts +68 -0
- package/tests/tps-policy.test.ts +96 -0
- package/tests/turn-end-rule-contract.test.ts +155 -0
- package/tests/turn-end-scope.test.ts +39 -0
- package/tests/verification-scoped-stop-contract.test.ts +1 -1
- package/tests/verification-tiers-contract.test.ts +4 -3
- package/tests/verify-first-launch-contract.test.ts +19 -7
- package/tests/vim-editor-adapter.test.ts +4 -4
- package/tests/voice-install.test.ts +97 -11
- package/tests/windows-hidden-processes.test.ts +11 -44
- package/tests/work-continuity-contract.test.ts +48 -55
- package/tests/yolo-session-policy.test.ts +2 -0
- package/contracts/review-provider-contract-mirror/v1.6.0/bundle/vectors/lens.json +0 -1
- package/extensions/codegraph-tools.ts +0 -437
- package/tests/child-codegraph-bootstrap.test.ts +0 -74
- package/tests/codegraph-tools.test.ts +0 -554
- /package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/README.md +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/schemas/refuter.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/schemas/targeted-validator.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/vectors/refuter.json +0 -0
- /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
|
-
// `
|
|
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).
|
|
95
|
-
//
|
|
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
|
-
//
|
|
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
|
|
309
|
-
//
|
|
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
|
-
|
|
319
|
-
|
|
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
|
-
// `
|
|
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).
|
|
95
|
-
//
|
|
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
|
-
//
|
|
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
|
|
309
|
-
//
|
|
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
|
-
|
|
319
|
-
|
|
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
|
-
// `
|
|
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).
|
|
95
|
-
//
|
|
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
|
-
//
|
|
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
|
|
309
|
-
//
|
|
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
|
-
|
|
319
|
-
|
|
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
|
-
// `
|
|
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).
|
|
95
|
-
//
|
|
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
|
-
//
|
|
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
|
|
309
|
-
//
|
|
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
|
-
|
|
319
|
-
|
|
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
|
-
// `
|
|
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).
|
|
95
|
-
//
|
|
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
|
-
//
|
|
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
|
|
309
|
-
//
|
|
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
|
-
|
|
319
|
-
|
|
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
|
|
164
|
-
.on_click(() => run("tab.new",
|
|
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
|
-
// `
|
|
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).
|
|
95
|
-
//
|
|
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
|
-
//
|
|
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
|
|
309
|
-
//
|
|
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
|
-
|
|
319
|
-
|
|
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:
|