Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (claude): dispatch liveness probe command on host platform
[._.]/ Adam Eivy0e34fcc8ed01
diff --git a/scripts/ci-test-plan.js b/scripts/ci-test-plan.jsindex 15e58815df..82c340fa82 100644--- a/scripts/ci-test-plan.js+++ b/scripts/ci-test-plan.js@@ -39,7 +39,7 @@ const WINDOWS_RISK_RULES = [/^scripts\/fix-windows-console(?:\.test)?\.js$/,/^scripts\/ps1-bom\.test\.js$/,/^server\/lib\/(?:bufferedSpawn|detachedSpawn|childProcess|bashResolver|processEnv|platform|spawnCwd|cliProviderRun|grok)\b/,- /^server\/lib\/shellCd(?:\.test)?\.js$/,+ /^server\/lib\/shell(?:Cd|Exit|LivenessProbe|ReadinessProbe)(?:\.test)?\.js$/,/^server\/lib\/agentGuard\//,/^server\/cos-runner\//,/^server\/services\/(?:shell|pm2|appBuilder)\b/,diff --git a/server/lib/README.md b/server/lib/README.mdindex cac274f486..4f5e1e9847 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -386,7 +386,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub| `prDisposition.js` | `resolvePrCompletion(metadata)` resolves the explicit `review-then-merge` / `merge-on-green` / `leave-open` policy, with legacy `reviewLoop` fallback; `leavesPrForHuman(task)` + `PR_STAYS_OPEN_TASK_TYPES` keep JIRA hand-offs open. Shared by the agent prompt builder and `agentWorktreeCleanup` so both halves agree. `resolvePrCreation({taskOpenPR, agentOwnsPr, prClaimVerified})` → a `PR_CREATION` tri-state (`never` / `if-missing` / `always`) naming who opens the change request for a completing worktree agent, so the runner, TUI, and direct-CLI completion paths cannot drift into double-firing `gh pr create`. || `shellCd.js` | `buildCdCommand(path, shell)` + `formatShellCommandLine(command, args, shell)` + `detectShellFlavor(shell, platform?)` + `quoteForShell(value, flavor, position?)` — build `cd` and arbitrary command-token lines for the shell a PTY session is ACTUALLY running (`cmd.exe` → Windows-escaped double quotes, PowerShell → doubled single quotes with `&` for a quoted command token, everything else → POSIX `shellQuote`). The Shell page's "cd to app" picker used to hard-code the POSIX form, which on Windows both mis-quoted the path and silently refused to cross drives (a bare `cd` does not switch drive). Flavor comes from the shell binary name, not the platform, so git-bash on Windows still gets POSIX quoting. `formatShellCommandLine` joins a command + argv into one quoted line and is shared by `agentTuiSpawning.js#buildTuiSpawnConfig` and the AI Providers page's "Launch in Shell" deep link, so a hand-launched TUI provider is quoted exactly the way the CoS runner would quote it. Renders the LINE only; the Enter byte that submits it is `SUBMIT_KEY` in `tuiHandshake.js`. || `shellExit.js` | `buildRunThenExitCommand(commandLine, shell)` — "run this CLI, then close the shell with its status", in the dialect the session speaks. An agent TUI shell exists only to host one CLI and must die with it. The POSIX `cmd; exit $?` was applied everywhere and is actively wrong off-POSIX: in PowerShell `$?` is a BOOLEAN, so `exit $?` reports success as 1 and failure as 0 (inverted) — use `$LASTEXITCODE`, pre-seeded to 1 so a command that never ran still exits non-zero; in cmd.exe `;` is an argument separator, so the CLI is handed `;`/`exit`/`$?` as arguments — use `& exit`. Verified against node-pty on Windows 11 for pwsh 7, PowerShell 5.1 and cmd.exe. |-| `shellLivenessProbe.js` | `buildLivenessProbeCommand(shellPid, shell, platform?)` + `parseLivenessProbeOutput(stdout, shellPid, shell, platform?)` + `shellHasLiveChild(shellPid, opts?)` — dialect- and platform-aware process-liveness probe for a launched TUI command in a persistent PTY shell. POSIX (`ps -Ao ppid=`) / Windows (`Get-CimInstance Win32_Process -Filter "ParentProcessId = <pid>"` via PowerShell). Resolves true (assume alive) when the probe fails or cannot run. |+| `shellLivenessProbe.js` | `buildLivenessProbeCommand(shellPid, platform?)` + `parseLivenessProbeOutput(stdout, shellPid, platform?)` + `shellHasLiveChild(shellPid, opts?)` — platform-aware process-liveness probe for a launched TUI command in a persistent PTY shell. POSIX (`ps -Ao ppid=`) / Windows (`Get-CimInstance Win32_Process -Filter "ParentProcessId = <pid>"` via PowerShell). Resolves true (assume alive) when the probe fails or cannot run. || `shellQuote.js` | `shellQuote(value)` — POSIX single-quote escaping for values interpolated into shell command strings (display command lines, copy-paste blocks in agent prompts). Bare-safe tokens pass through; everything else is single-quoted. Canonical escaper — don't hand-roll. || `shellReadinessProbe.js` | `buildReadinessProbe(nonce, shell)` — the round-trip "can this shell actually run commands yet?" probe `createShellSession`'s `waitForPromptReady` sends and watches for, in the dialect the session speaks: POSIX `printf '%s\n' 'PORTOSRDY''<nonce>'` (unchanged), PowerShell `Write-Output ('PORTOSRDY' + '<nonce>')`, `cmd.exe` → `null` (no split-literal concatenation operator exists there, so the caller skips straight to the bounded fallback timer instead of risking an always-matching probe). The split-literal property is load-bearing in every dialect: the probe source never contains the assembled marker, so seeing it in the output can only mean the shell executed the probe. || `sidecarProcess.js` | `runSidecarProcess({bin,args,env,signal,onStage,onProcess})` + `parseSidecarResult(stdout)` — the shared Python-sidecar STAGE:/RESULT: wire-protocol runner (spawn, tail-capped stdout/stderr, per-STAGE-line callback, abort/SIGTERM → `canceled`, non-zero exit → stderr-tail reason). Used by `pipeline/musicGen.js` (all music backends) and `audioMidiTranscription.js` (MuScriptor). |diff --git a/server/lib/shellLivenessProbe.js b/server/lib/shellLivenessProbe.jsindex 91882956be..dbceaa5d95 100644--- a/server/lib/shellLivenessProbe.js+++ b/server/lib/shellLivenessProbe.js@@ -11,46 +11,40 @@* already died. In that case, the spawner skips pasting the prompt into the bare* shell prompt and finalizes failure early.*- * The probe is dialect- and platform-aware:- * • POSIX (macOS/Linux / bash): `ps -Ao ppid=` (lists parent PIDs)- * • Windows (cmd.exe / PowerShell): `powershell -NoProfile -NonInteractive -Command ...`+ * The probe is executed host-side via `execFile` from Node.js (not inside the PTY):+ * • POSIX host (macOS / Linux): `ps -Ao ppid=` (lists parent PIDs)+ * • Windows host: `powershell -NoProfile -NonInteractive -Command ...`* using `Get-CimInstance Win32_Process` filtered by ParentProcessId.** Resolves true (assume alive) if the probe fails or cannot run, so an environment* glitch never blocks an otherwise-healthy run.*/-import { detectShellFlavor } from './shellCd.js';import { execFile } from './childProcess.js';/*** Build the file + argv for probing children of `shellPid`.** @param {number} shellPid - PID of the hosting shell process- * @param {string} [shell] - the session's shell binary; see detectShellFlavor* @param {string} [platform=process.platform] - OS platform* @returns {{ file: string, args: string[] }}*/-export function buildLivenessProbeCommand(shellPid, shell, platform = process.platform) {- const flavor = detectShellFlavor(shell, platform);- switch (flavor) {- case 'cmd':- case 'powershell':- return {- file: 'powershell',- args: [- '-NoProfile',- '-NonInteractive',- '-Command',- `Get-CimInstance Win32_Process -Filter "ParentProcessId = ${shellPid}" | Select-Object -ExpandProperty ProcessId`,- ],- };- default:- return {- file: 'ps',- args: ['-Ao', 'ppid='],- };+export function buildLivenessProbeCommand(shellPid, platform = process.platform) {+ if (platform === 'win32') {+ return {+ file: 'powershell',+ args: [+ '-NoProfile',+ '-NonInteractive',+ '-Command',+ `Get-CimInstance Win32_Process -Filter "ParentProcessId = ${shellPid}" | Select-Object -ExpandProperty ProcessId`,+ ],+ };}+ return {+ file: 'ps',+ args: ['-Ao', 'ppid='],+ };}/**@@ -58,30 +52,25 @@ export function buildLivenessProbeCommand(shellPid, shell, platform = process.pl** @param {string} stdout - raw stdout from the probe command* @param {number} shellPid - PID of the hosting shell process- * @param {string} [shell] - the session's shell binary* @param {string} [platform=process.platform] - OS platform* @returns {boolean} true if child process(es) were found*/-export function parseLivenessProbeOutput(stdout, shellPid, shell, platform = process.platform) {+export function parseLivenessProbeOutput(stdout, shellPid, platform = process.platform) {if (!stdout) return false;- const flavor = detectShellFlavor(shell, platform);- switch (flavor) {- case 'cmd':- case 'powershell':- return String(stdout)- .split('\n')- .some((line) => {- const num = parseInt(line.trim(), 10);- return Number.isFinite(num) && num > 0;- });- default:- return String(stdout)- .split('\n')- .some((line) => {- const num = parseInt(line.trim(), 10);- return Number.isFinite(num) && num === shellPid;- });+ if (platform === 'win32') {+ return String(stdout)+ .split('\n')+ .some((line) => {+ const num = parseInt(line.trim(), 10);+ return Number.isFinite(num) && num > 0;+ });}+ return String(stdout)+ .split('\n')+ .some((line) => {+ const num = parseInt(line.trim(), 10);+ return Number.isFinite(num) && num === shellPid;+ });}/**@@ -89,19 +78,19 @@ export function parseLivenessProbeOutput(stdout, shellPid, shell, platform = pro* Resolves `true` (assume alive) on error or missing PID.** @param {number} shellPid- * @param {{ shell?: string, platform?: string, execFileFn?: typeof execFile }} [options]+ * @param {{ platform?: string, execFileFn?: typeof execFile }} [options]* @returns {Promise<boolean>}*/-export function shellHasLiveChild(shellPid, { shell, platform = process.platform, execFileFn = execFile } = {}) {+export function shellHasLiveChild(shellPid, { platform = process.platform, execFileFn = execFile } = {}) {if (!shellPid) return Promise.resolve(true);- const { file, args } = buildLivenessProbeCommand(shellPid, shell, platform);+ const { file, args } = buildLivenessProbeCommand(shellPid, platform);return new Promise((resolve) => {execFileFn(file, args, { timeout: 2000 }, (err, stdout) => {if (err) {resolve(true);return;}- resolve(parseLivenessProbeOutput(stdout, shellPid, shell, platform));+ resolve(parseLivenessProbeOutput(stdout, shellPid, platform));});});}diff --git a/server/lib/shellLivenessProbe.test.js b/server/lib/shellLivenessProbe.test.jsindex 6b5f7b4a04..202f01044a 100644--- a/server/lib/shellLivenessProbe.test.js+++ b/server/lib/shellLivenessProbe.test.js@@ -6,8 +6,8 @@ import {} from './shellLivenessProbe.js';describe('buildLivenessProbeCommand', () => {- it('builds a PowerShell Get-CimInstance query for cmd.exe', () => {- const probe = buildLivenessProbeCommand(1234, 'C:\\WINDOWS\\system32\\cmd.exe');+ it('builds a PowerShell Get-CimInstance query on Windows', () => {+ const probe = buildLivenessProbeCommand(1234, 'win32');expect(probe.file).toBe('powershell');expect(probe.args).toEqual(['-NoProfile',@@ -17,54 +17,45 @@ describe('buildLivenessProbeCommand', () => {]);});- it('builds a PowerShell Get-CimInstance query for powershell.exe / pwsh', () => {- const probe = buildLivenessProbeCommand(5678, 'pwsh.exe');- expect(probe.file).toBe('powershell');- expect(probe.args[3]).toContain('ParentProcessId = 5678');- });-- it('builds a POSIX ps command for POSIX shells', () => {- const probe = buildLivenessProbeCommand(1234, '/bin/zsh');- expect(probe).toEqual({+ it('builds a POSIX ps command on macOS / Linux', () => {+ expect(buildLivenessProbeCommand(1234, 'darwin')).toEqual({file: 'ps',args: ['-Ao', 'ppid='],});- });-- it('keeps POSIX ps command for git-bash on Windows', () => {- const probe = buildLivenessProbeCommand(1234, 'C:\\Program Files\\Git\\bin\\bash.exe', 'win32');- expect(probe).toEqual({+ expect(buildLivenessProbeCommand(1234, 'linux')).toEqual({file: 'ps',args: ['-Ao', 'ppid='],});});- it('falls back to platform default when no shell is recorded', () => {- const winProbe = buildLivenessProbeCommand(1234, undefined, 'win32');- expect(winProbe.file).toBe('powershell');-- const posixProbe = buildLivenessProbeCommand(1234, undefined, 'darwin');- expect(posixProbe.file).toBe('ps');+ it('defaults to process.platform when platform argument is omitted', () => {+ const probe = buildLivenessProbeCommand(1234);+ if (process.platform === 'win32') {+ expect(probe.file).toBe('powershell');+ } else {+ expect(probe.file).toBe('ps');+ }});});describe('parseLivenessProbeOutput', () => {it('parses POSIX ps output matching the shell pid', () => {- expect(parseLivenessProbeOutput('1\n1\n1234\n999', 1234, '/bin/zsh')).toBe(true);- expect(parseLivenessProbeOutput('1\n1\n999', 1234, '/bin/zsh')).toBe(false);+ expect(parseLivenessProbeOutput('1\n1\n1234\n999', 1234, 'darwin')).toBe(true);+ expect(parseLivenessProbeOutput('1\n1\n999', 1234, 'darwin')).toBe(false);});it('parses Windows powershell output returning child pids', () => {- expect(parseLivenessProbeOutput('5678\n', 1234, 'cmd.exe')).toBe(true);- expect(parseLivenessProbeOutput('5678\n9012\n', 1234, 'powershell.exe')).toBe(true);- expect(parseLivenessProbeOutput('', 1234, 'cmd.exe')).toBe(false);- expect(parseLivenessProbeOutput(' \n', 1234, 'cmd.exe')).toBe(false);+ expect(parseLivenessProbeOutput('5678\n', 1234, 'win32')).toBe(true);+ expect(parseLivenessProbeOutput('5678\n9012\n', 1234, 'win32')).toBe(true);+ expect(parseLivenessProbeOutput('', 1234, 'win32')).toBe(false);+ expect(parseLivenessProbeOutput(' \n', 1234, 'win32')).toBe(false);+ expect(parseLivenessProbeOutput('ProcessId\n---------\n', 1234, 'win32')).toBe(false);});- it('returns false for empty stdout on all flavors', () => {- expect(parseLivenessProbeOutput('', 1234, '/bin/zsh')).toBe(false);- expect(parseLivenessProbeOutput(null, 1234, '/bin/zsh')).toBe(false);- expect(parseLivenessProbeOutput('', 1234, 'cmd.exe')).toBe(false);+ it('returns false for empty stdout on all platforms', () => {+ expect(parseLivenessProbeOutput('', 1234, 'darwin')).toBe(false);+ expect(parseLivenessProbeOutput(null, 1234, 'darwin')).toBe(false);+ expect(parseLivenessProbeOutput('', 1234, 'win32')).toBe(false);});});@@ -78,7 +69,7 @@ describe('shellHasLiveChild', () => {it('resolves true (fails open) when the probe command errors', async () => {const mockExec = vi.fn((_file, _args, _opts, cb) => cb(new Error('command failed')));const result = await shellHasLiveChild(1234, {- shell: '/bin/zsh',+ platform: 'darwin',execFileFn: mockExec,});expect(result).toBe(true);@@ -87,7 +78,7 @@ describe('shellHasLiveChild', () => {it('resolves true when POSIX ps detects a live child process', async () => {const mockExec = vi.fn((_file, _args, _opts, cb) => cb(null, '1\n1234\n999\n'));const result = await shellHasLiveChild(1234, {- shell: '/bin/zsh',+ platform: 'darwin',execFileFn: mockExec,});expect(result).toBe(true);@@ -96,7 +87,7 @@ describe('shellHasLiveChild', () => {it('resolves false when POSIX ps detects no child process', async () => {const mockExec = vi.fn((_file, _args, _opts, cb) => cb(null, '1\n999\n'));const result = await shellHasLiveChild(1234, {- shell: '/bin/zsh',+ platform: 'darwin',execFileFn: mockExec,});expect(result).toBe(false);@@ -108,7 +99,7 @@ describe('shellHasLiveChild', () => {cb(null, '4567\n');});const result = await shellHasLiveChild(1234, {- shell: 'cmd.exe',+ platform: 'win32',execFileFn: mockExec,});expect(result).toBe(true);@@ -120,7 +111,7 @@ describe('shellHasLiveChild', () => {cb(null, '\n');});const result = await shellHasLiveChild(1234, {- shell: 'cmd.exe',+ platform: 'win32',execFileFn: mockExec,});expect(result).toBe(false);diff --git a/server/services/agentTuiSpawning.js b/server/services/agentTuiSpawning.jsindex 7ca3507f4b..2b2a808ef9 100644--- a/server/services/agentTuiSpawning.js+++ b/server/services/agentTuiSpawning.js@@ -323,7 +323,7 @@ function createPasteRetryController({// this pid have a live child?" is the wrong question (claude may have zero// children at paste time) and a TUI exit kills the PTY, firing onExit. Skip// the probe there.- if (!useDurableRunner && !(await shellHasLiveChild(pid, { shell: tuiConfig?.shell }))) {+ if (!useDurableRunner && !(await shellHasLiveChild(pid))) {if (isFinalized()) return; // a real onExit may have finalized during the probe awaitawait finishStartupFailure('tui-exited-early',