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
fix: harden Windows TUI quoting and CI coverage (#4642)
Adam Eivye21e31c1ab14
diff --git a/scripts/ci-test-plan.js b/scripts/ci-test-plan.jsindex 1f052acd9e..15e58815df 100644--- a/scripts/ci-test-plan.js+++ b/scripts/ci-test-plan.js@@ -39,9 +39,11 @@ 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\/agentGuard\//,/^server\/cos-runner\//,/^server\/services\/(?:shell|pm2|appBuilder)\b/,+ /^server\/services\/agentTuiSpawning(?:\.test)?\.js$/,/^server\/services\/autonomousJobs\/execution\.shellSpawn/,/^server\/routes\/apps\//,/^server\/routes\/scaffoldVite\.js$/,@@ -74,6 +76,7 @@ export const WINDOWS_CONTRACT_TESTS = ['server/lib/processEnv.spawnOptions.test.js','server/lib/processEnv.test.js','server/lib/spawnCwd.test.js',+ 'server/lib/shellCd.test.js','server/routes/apps/crud.test.js','server/routes/apps/icons.test.js','server/routes/apps/issues.test.js',@@ -89,6 +92,7 @@ export const WINDOWS_CONTRACT_TESTS = ['server/services/pm2Standardizer.test.js','server/services/shell.test.js','server/services/shellImageDrop.test.js',+ 'server/services/agentTuiSpawning.test.js',];// Contract guards that run on EVERY plan, whatever the impact scope selects.diff --git a/scripts/ci-test-plan.test.js b/scripts/ci-test-plan.test.jsindex e730b2ee4a..9e575a520e 100644--- a/scripts/ci-test-plan.test.js+++ b/scripts/ci-test-plan.test.js@@ -15,6 +15,8 @@ const TRACKED = ['server/services/taskPromptDefaults.test.js','server/lib/bufferedSpawn.test.js','server/lib/platform.test.js',+ 'server/lib/shellCd.test.js',+ 'server/services/agentTuiSpawning.test.js','client/src/a11yConventions.test.js','client/src/hooks/mountedRefConventions.test.js','client/src/components/catalog/CatalogCard.jsx',@@ -307,8 +309,16 @@ describe('CI test impact planner', () => {expect(spawn.windowsFiles).toEqual(['server/lib/bufferedSpawn.test.js','server/lib/platform.test.js',+ 'server/lib/shellCd.test.js',+ 'server/services/agentTuiSpawning.test.js',]);+ const tuiShell = buildCiTestPlan([+ 'server/lib/shellCd.js',+ ], { trackedFiles: TRACKED });+ expect(tuiShell.windows).toBe(true);+ expect(tuiShell.windowsMode).toBe('related');+const winHelper = buildCiTestPlan(['scripts/fix-windows-console.js',], { trackedFiles: TRACKED });diff --git a/server/lib/README.md b/server/lib/README.mdindex 5044676a78..87aba95cf7 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -374,7 +374,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub| `objects.js` | Object utilities — `deepMerge` (recursive merge w/ array replacement), `isPlainObject` (non-null, non-array `object` guard for JSON / LLM payloads), `POLLUTING_KEYS` (shared `__proto__`/`constructor`/`prototype` denylist for sanitizers), `canonicalStringify` (recursive sorted-key JSON serialization for cross-machine content hashing), `isEmptyScalar` (true for null/undefined/whitespace-string/empty-array — merge gap-fill gate). || `openapiSpec.js` | `buildOpenApiSpec(settings, { baseUrl, version })` — builds an OpenAPI 3.1 document for the currently-exposed public APIs from `apiRegistry`, reusing route Zod schemas via `z.toJSONSchema`. Exposed+`requireAuth` operations get a `security` requirement; passwordless ones don't. Served by `routes/apiDocs.js`. || `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)` + `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` → 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. Renders the LINE only; the Enter byte that submits it is `SUBMIT_KEY` in `tuiHandshake.js`. |+| `shellCd.js` | `buildCdCommand(path, 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. 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. || `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. || `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/shellCd.js b/server/lib/shellCd.jsindex ccfad0ba8b..0c6728019a 100644--- a/server/lib/shellCd.js+++ b/server/lib/shellCd.js@@ -69,8 +69,9 @@ export function quoteForShell(value, flavor = 'posix', position = 'argument') {const text = String(value ?? '');switch (flavor) {case 'cmd':- // cmd.exe has no escape for an embedded double quote.- return `"${text.replace(/"/g, '')}"`;+ // cmd.exe has no escape for an embedded double quote. Double a trailing+ // backslash so the Windows argv parser does not consume the closing quote.+ return `"${text.replace(/"/g, '').replace(/\\+$/, run => `${run}${run}`)}"`;case 'powershell': {const quoted = `'${text.replace(/'/g, "''")}'`;return position === 'command' ? `& ${quoted}` : quoted;diff --git a/server/lib/shellCd.test.js b/server/lib/shellCd.test.jsindex c6256c0c84..7bf014a560 100644--- a/server/lib/shellCd.test.js+++ b/server/lib/shellCd.test.js@@ -82,4 +82,11 @@ describe('quoteForShell', () => {.toBe('"C:\\Program Files\\claude.cmd"');expect(quoteForShell('arg"with space', 'cmd', 'argument')).toBe('"argwith space"');});++ it('preserves a trailing backslash in cmd.exe tokens', () => {+ const slash = String.fromCharCode(92);+ const path = ['C:', 'work', ''].join(slash);+ expect(quoteForShell(path, 'cmd', 'argument'))+ .toBe(`"C:${slash}work${slash}${slash}"`);+ });});diff --git a/server/services/agentTuiSpawning.test.js b/server/services/agentTuiSpawning.test.jsindex 0ed7e6b2d0..92239d5ad8 100644--- a/server/services/agentTuiSpawning.test.js+++ b/server/services/agentTuiSpawning.test.js@@ -295,7 +295,7 @@ describe('agent TUI spawning', () => {type: 'tui',command: 'codex',args: []- }, 'codex-configured-default');+ }, 'codex-configured-default', { shell: '/bin/zsh' });expect(config.command).toBe('codex');expect(config.args).toEqual(['--dangerously-bypass-approvals-and-sandbox', '-c', 'check_for_update_on_startup=false']);@@ -341,7 +341,7 @@ describe('agent TUI spawning', () => {args: ['--dangerously-skip-permissions', '--add-dir', '/tmp/with space'],tuiPromptDelayMs: 1000,tuiMaxRuntimeMs: 7200000- }, 'claude-sonnet');+ }, 'claude-sonnet', { shell: '/bin/zsh' });expect(config.args).toEqual(['--dangerously-skip-permissions',@@ -415,7 +415,11 @@ describe('agent TUI spawning', () => {});it('omits the --model flag when model is null/empty', () => {- const config = buildTuiSpawnConfig({ id: 'codex-tui', command: 'codex', type: 'tui', args: [] }, null);+ const config = buildTuiSpawnConfig(+ { id: 'codex-tui', command: 'codex', type: 'tui', args: [] },+ null,+ { shell: '/bin/zsh' },+ );expect(config.args).toEqual(['--dangerously-bypass-approvals-and-sandbox', '-c', 'check_for_update_on_startup=false']);expect(config.commandLine).toBe('codex --dangerously-bypass-approvals-and-sandbox -c check_for_update_on_startup=false');});