diff --git a/config/process-host-direct-import-baseline.txt b/config/process-host-direct-import-baseline.txt index 85d6225d4a7..89669f71704 100644 --- a/config/process-host-direct-import-baseline.txt +++ b/config/process-host-direct-import-baseline.txt @@ -1,38 +1,28 @@ -# Existing production source files importing child_process outside @orca/process-host. +# Existing production source files importing child_process at runtime outside @orca/process-host. # Migration debt: this list may only shrink; new callers use the package public API. src/cli/handlers/core.ts src/cli/handlers/interactive-login-interruption.ts src/cli/runtime/launch.ts src/main/agent-hooks/installation/locking/managed-hook-owner-identity.ts -src/main/agent-hooks/wsl-relay/wsl-hook-relay-link.ts -src/main/agent-hooks/wsl-relay/wsl-hook-relay-manager.ts -src/main/agent-hooks/wsl-relay/wsl-hook-relay-sentinel.ts -src/main/ai-vault/scan-service/session-scanner-service-client-state.ts -src/main/ai-vault/scan-service/session-scanner-service-client.ts src/main/ai-vault/scan-service/session-scanner-service-spawn.ts src/main/window/desktop-integration/app-icon.ts src/main/automations/precheck-runner.ts src/main/browser/agent-browser/helper-process/agent-browser-bridge-execution.ts src/main/browser/agent-browser/helper-process/agent-browser-bridge-raw-process.ts -src/main/browser/agent-browser/session-routing/agent-browser-bridge-state.ts -src/main/browser/agent-browser/session-lifecycle/agent-browser-session-state.ts src/main/browser/network/egress/browser-route-egress-electron-launch.ts src/main/codex-accounts/legacy-wsl-runtime-auth-drain-recovery-script-harness.ts src/main/codex-accounts/legacy-wsl-runtime-auth-drain-script-harness.ts src/main/codex-accounts/service.ts -src/main/codex/app-server/codex-app-server-session.ts src/main/computer/desktop-script-provider-bridge.ts src/main/computer/macos-computer-use-permission-status.ts src/main/computer/macos-computer-use-permissions.ts src/main/computer/macos-native-provider-transport.ts src/main/computer/sidecar-client.ts -src/main/daemon/launch/daemon-launched-child.ts src/main/daemon/endpoint/identity/daemon-process-identity-query.ts src/main/daemon/endpoint/identity/daemon-process-inspection.ts src/main/daemon/endpoint/identity/daemon-process-start-time.ts src/main/emulator/android/android-avd-boot.ts -src/main/emulator/android/scrcpy-stream-session.ts src/main/emulator/serve-sim-helper-processes.ts src/main/emulator/serve-sim-runtime-materializer.ts src/main/emulator/simctl-simulator-devices.ts @@ -49,33 +39,18 @@ src/main/git/wsl-git-read-environment.ts src/main/github/gh-utils.ts src/main/workspace-hooks/hooks.ts src/main/ipc/developer-permissions.ts -src/main/ipc/filesystem/filesystem-handler-context.ts -src/main/ipc/filesystem/watcher-process/parcel-watcher-cancellation-restart.ts -src/main/ipc/filesystem/watcher-process/parcel-watcher-cancellation-tracker.ts src/main/ipc/filesystem/watcher-process/parcel-watcher-child-launch.ts -src/main/ipc/filesystem/watcher-process/parcel-watcher-child-messaging.ts -src/main/ipc/filesystem/watcher-process/parcel-watcher-child-recovery.ts -src/main/ipc/filesystem/watcher-process/parcel-watcher-child-termination.ts -src/main/ipc/filesystem/watcher-process/parcel-watcher-host-subscriptions.ts -src/main/ipc/filesystem/watcher-process/parcel-watcher-pending-cancellation.ts -src/main/ipc/filesystem/watcher-process/parcel-watcher-process-supervisor.ts -src/main/ipc/filesystem/watcher-process/parcel-watcher-supervisor-disposal.ts -src/main/ipc/filesystem/watcher-process/parcel-watcher-supervisor-message.ts -src/main/ipc/filesystem/watcher-process/parcel-watcher-supervisor-subscribe.ts -src/main/ipc/filesystem/watchers/wsl-watcher-process-exit.ts src/main/ipc/local-network-connection-test.ts src/main/ipc/macos-keyboard-input-source.ts src/main/ipc/macos-keyboard-layout-snapshot.ts src/main/ipc/notification-authorization-status.ts src/main/ipc/preflight-command-exec.ts -src/main/ipc/repos/repo-clone-lifecycle.ts src/main/ipc/worktree-apfs-clone.ts src/main/local-builds/local-build-candidate.ts src/main/macos-keychain/generic-password.ts src/main/power/macos-system-sleep-assertion.ts src/main/macos-permissions/macos-tcc-prompt-watch.ts src/main/memory/collector.ts -src/main/native-chat/wsl-transcript-fs-process-slot.ts src/main/native-chat/wsl-transcript-fs-process-spawn.ts src/main/network/macos-system-resolver-health.ts src/main/network/macos-tailscale-dns-diagnostic.ts @@ -85,21 +60,17 @@ src/main/ports/port-scan-command-execution.ts src/main/providers/macos-login-session-pty-probe.ts src/main/providers/process-cwd.ts src/main/pty/process-retirement/pty-descendant-fresh-table.ts -src/main/pty/environment/windows-environment-path.ts src/main/rate-limits/providers/gemini/gemini-cli-oauth-extractor.ts src/main/runtime/rpc/server/pairing/network/windows-default-route-interfaces.ts src/main/runtime/rpc/server/pairing/network/windows-mobile-firewall.ts -src/main/ssh/connection/ssh-connection.ts src/main/ssh/system-transport/ssh-proxy-command.ts src/main/ssh/system-transport/system-ssh-command.ts src/main/ssh/system-transport/forwarding/system-ssh-dynamic-forward-process.ts src/main/ssh/system-transport/file-transfer/system-ssh-file-transfer.ts -src/main/ssh/system-transport/system-ssh-operation-lifecycle.ts src/main/startup/ensure-virtual-display.ts src/main/pty/process-retirement/windows-process-tree-kill.ts src/main/pty/shell-startup/zsh-startup-hook-pty-harness.ts src/shared/ephemeral-vm-recipe-process.ts -src/shared/ephemeral-vm-recipe-runner.ts src/shared/fish-binary-requirement.ts src/shared/process-table-ps-capture.ts src/shared/terminal/pty/native-process/pty-slave-line-discipline-echo.ts diff --git a/config/scripts/static-analysis/module-requests/static-module-specifiers.mjs b/config/scripts/static-analysis/module-requests/static-module-specifiers.mjs index 961b899301a..408f9cc232c 100644 --- a/config/scripts/static-analysis/module-requests/static-module-specifiers.mjs +++ b/config/scripts/static-analysis/module-requests/static-module-specifiers.mjs @@ -100,7 +100,7 @@ function collectBindings(source) { // Resolve file-wide static import/re-export/import()/require/module.require/createRequire aliases and getBuiltinModule; literals/const strings and literal property keys only. // No scope tracking, computed values/specifiers, imported parameters, object/argument loaders or eval/Function resolution. -export function collectModuleSpecifiers(file, contents) { +export function collectModuleSpecifiers(file, contents, { runtimeOnly = false } = {}) { const source = ts.createSourceFile(file, contents, ts.ScriptTarget.Latest, false) if (source.parseDiagnostics.length > 0) { throw new Error(`Cannot parse ${file}; the process-host import check must not skip it.`) @@ -226,6 +226,14 @@ export function collectModuleSpecifiers(file, contents) { } } for (const node of modules) { + if ( + runtimeOnly && + (ts.isImportTypeNode(node) || + node.isTypeOnly || + (ts.isImportDeclaration(node) && node.importClause?.isTypeOnly)) + ) { + continue + } if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) { add(node.moduleSpecifier) } else if ( diff --git a/config/scripts/static-analysis/process-boundaries/check-process-host-imports.mjs b/config/scripts/static-analysis/process-boundaries/check-process-host-imports.mjs index b69c39fe070..3ac5874b986 100644 --- a/config/scripts/static-analysis/process-boundaries/check-process-host-imports.mjs +++ b/config/scripts/static-analysis/process-boundaries/check-process-host-imports.mjs @@ -59,6 +59,7 @@ export function assessProcessHostImports( ]) for (const [file, contents] of sources) { const ownSource = file.startsWith(PACKAGE_SOURCE) + let runtimeSpecifiers for (const sourceSpecifier of specifiersFor(file, contents)) { const specifier = normalized(sourceSpecifier) const local = packageRelativeImport(file, specifier) @@ -103,7 +104,12 @@ export function assessProcessHostImports( !isTestOnlySourcePath(file) && (specifier === 'child_process' || specifier === 'node:child_process') ) { - direct.add(file) + runtimeSpecifiers ??= new Set( + collectModuleSpecifiers(file, contents, { runtimeOnly: true }) + ) + if (runtimeSpecifiers.has(specifier)) { + direct.add(file) + } } } } diff --git a/config/scripts/static-analysis/process-boundaries/check-process-host-imports.test.mjs b/config/scripts/static-analysis/process-boundaries/check-process-host-imports.test.mjs new file mode 100644 index 00000000000..6c5cf811520 --- /dev/null +++ b/config/scripts/static-analysis/process-boundaries/check-process-host-imports.test.mjs @@ -0,0 +1,48 @@ +import { describe, expect, it } from 'vitest' +import { assessProcessHostImports } from './check-process-host-imports.mjs' + +const file = 'src/main/process-consumer.ts' +const manifest = { exports: { '.': './dist/index.js' } } +const assess = (source) => assessProcessHostImports(new Map([[file, source]]), manifest, new Set()) + +describe('process-host runtime import boundary', () => { + it.each([ + "import type { ChildProcess } from 'node:child_process'", + "import type * as ChildProcess from 'child_process'", + "import type ChildProcess = require('node:child_process')", + "export type { ChildProcess } from 'node:child_process'", + "type Child = import('node:child_process').ChildProcess" + ])('allows erased Node type ownership: %s', (source) => { + expect(assess(source)).toMatchObject({ direct: [], added: [], violations: [] }) + }) + + it.each([ + "import { spawn } from 'node:child_process'", + "import 'child_process'", + "import { type ChildProcess } from 'node:child_process'", + "export { spawn } from 'node:child_process'", + "const child = require('node:child_process')", + "const child = import('node:child_process')", + "import type { ChildProcess } from 'node:child_process'; require('node:child_process')", + "import { createRequire } from 'node:module'; const load = createRequire(import.meta.url); load('node:child_process')", + "process.getBuiltinModule('child_process')" + ])('still rejects runtime access: %s', (source) => { + expect(assess(source)).toMatchObject({ direct: [file], added: [file] }) + }) + + it('keeps package export restrictions for type-only imports', () => { + expect(assess("import type { Private } from '@orca/process-host/private'").violations).toEqual([ + `${file}: @orca/process-host/private is not a public process-host export` + ]) + }) + + it('requires the WSL allowlist only for runtime child-process imports', () => { + const wsl = "const program = 'wsl.exe'" + expect( + assess(`import type { ChildProcess } from 'node:child_process'; ${wsl}`).violations + ).toEqual([]) + expect(assess(`import { spawn } from 'node:child_process'; ${wsl}`).violations).toEqual([ + `${file}: direct wsl.exe exec must call assertWslDistroAllowed` + ]) + }) +}) diff --git a/config/scripts/test-runtime/node-worker/vitest-node-runtime-pool.test.ts b/config/scripts/test-runtime/node-worker/vitest-node-runtime-pool.test.ts index 0a37c94dae4..1d1d44efe69 100644 --- a/config/scripts/test-runtime/node-worker/vitest-node-runtime-pool.test.ts +++ b/config/scripts/test-runtime/node-worker/vitest-node-runtime-pool.test.ts @@ -6,11 +6,11 @@ import { PassThrough } from 'node:stream' import { afterAll, afterEach, beforeAll, expect, it, onTestFinished, vi } from 'vitest' import { createVitest, type PoolOptions, type Vitest } from 'vitest/node' import * as processes from '@orca/process-host' -import type { ChildProcessHandle } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import { nodeRuntimePool } from './vitest-node-runtime-pool' let context: Vitest -const children: ChildProcessHandle[] = [] +const children: ChildProcess[] = [] const spawn = processes.spawnProcess beforeAll(async () => { diff --git a/config/scripts/test-runtime/node-worker/vitest-node-runtime-pool.ts b/config/scripts/test-runtime/node-worker/vitest-node-runtime-pool.ts index b6914b161f0..16d79a56062 100644 --- a/config/scripts/test-runtime/node-worker/vitest-node-runtime-pool.ts +++ b/config/scripts/test-runtime/node-worker/vitest-node-runtime-pool.ts @@ -1,7 +1,7 @@ import { isAbsolute, resolve } from 'node:path' import type { PoolOptions, PoolWorker, WorkerRequest } from 'vitest/node' import { spawnProcess } from '@orca/process-host' -import type { ChildProcessHandle } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import { decodeNodeRuntimeMessage, encodeNodeRuntimeMessage @@ -10,7 +10,7 @@ import { class NodeRuntimeWorker implements PoolWorker { readonly name = 'node-runtime' readonly cacheFs = true - private child: ChildProcessHandle | undefined + private child: ChildProcess | undefined constructor(private readonly options: PoolOptions) {} @@ -125,7 +125,7 @@ class NodeRuntimeWorker implements PoolWorker { } } - private get worker(): ChildProcessHandle { + private get worker(): ChildProcess { if (!this.child) { throw new Error('Node Vitest worker is not running') } diff --git a/src/cli/handlers/opencode-account-login-command.ts b/src/cli/handlers/opencode-account-login-command.ts index eb9a88f9113..52eeac1cdd2 100644 --- a/src/cli/handlers/opencode-account-login-command.ts +++ b/src/cli/handlers/opencode-account-login-command.ts @@ -1,4 +1,4 @@ -import type { ChildProcessHandle } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import { spawnProcess } from '@orca/process-host' import { forceTerminateProcessTree, @@ -212,7 +212,7 @@ async function waitForProbe(promise: Promise, ms: number): Promise clearTimeout(timer)) } -function killProbeRoot(child: ChildProcessHandle, signal?: NodeJS.Signals): void { +function killProbeRoot(child: ChildProcess, signal?: NodeJS.Signals): void { try { child.kill(signal) } catch { diff --git a/src/cli/runtime/serve-recipe-json.ts b/src/cli/runtime/serve-recipe-json.ts index c2aae3397c3..45eec9683e9 100644 --- a/src/cli/runtime/serve-recipe-json.ts +++ b/src/cli/runtime/serve-recipe-json.ts @@ -1,4 +1,4 @@ -import type { ChildProcessHandle } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import { StringDecoder } from 'node:string_decoder' import { getEphemeralVmRecipeResultConnection, @@ -8,7 +8,7 @@ import { RuntimeClientError } from './types' const IGNORED_NON_RECIPE_STDOUT = '[serve] ignored non-recipe stdout' -export function waitForRecipeJson(child: ChildProcessHandle): Promise { +export function waitForRecipeJson(child: ChildProcess): Promise { return new Promise((resolve, reject) => { let output = '' let settled = false diff --git a/src/cli/runtime/serve-update-supervisor.ts b/src/cli/runtime/serve-update-supervisor.ts index 40924bd8023..41bf2b9c335 100644 --- a/src/cli/runtime/serve-update-supervisor.ts +++ b/src/cli/runtime/serve-update-supervisor.ts @@ -1,4 +1,5 @@ -import type { ChildProcessHandle, ProcessSpec } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' +import type { ProcessSpec } from '@orca/process-host/process-spec' import { readFileSync } from 'node:fs' import { readFile, rename, unlink, writeFile } from 'node:fs/promises' import { @@ -34,7 +35,7 @@ export const SERVE_CHILD_FORCE_KILL_GRACE_MS = type ServeSupervisorArgs = { /** Respawned on update; `program` is also the bundle whose installed version a handoff awaits. */ spec: ProcessSpec - spawnChild: (spec: ProcessSpec) => ChildProcessHandle + spawnChild: (spec: ProcessSpec) => ChildProcess handoffPath: string | null } @@ -76,7 +77,7 @@ async function awaitInstalledHandoff( export async function superviseForegroundServe( args: ServeSupervisorArgs & { - child: ChildProcessHandle + child: ChildProcess expectedHandoff: InstallRequestedHandoff | null } ): Promise { @@ -129,7 +130,7 @@ export async function superviseForegroundServe( } function waitForForegroundChild( - child: ChildProcessHandle, + child: ChildProcess, expected: { handoffPath: string; handoff: InstallRequestedHandoff } | null ): Promise<{ code: number | null diff --git a/src/main/agent-hooks/wsl-relay/wsl-hook-relay-launch.ts b/src/main/agent-hooks/wsl-relay/wsl-hook-relay-launch.ts index 47458275181..e36305bd325 100644 --- a/src/main/agent-hooks/wsl-relay/wsl-hook-relay-launch.ts +++ b/src/main/agent-hooks/wsl-relay/wsl-hook-relay-launch.ts @@ -1,4 +1,4 @@ -import type { PipedChildProcess } from '@orca/process-host/process-spec' +import type { ChildProcessWithoutNullStreams } from 'node:child_process' import { existsSync, readFileSync } from 'node:fs' import { join } from 'node:path' import { spawnProcess } from '@orca/process-host' @@ -102,7 +102,7 @@ export function spawnWslRelayProcess( distro: string, env: NodeJS.ProcessEnv, version: string -): PipedChildProcess { +): ChildProcessWithoutNullStreams { // --exec bypasses login-shell rewriting and passes $HOME verbatim for guest-side expansion. const command = `exec sh "${guestRelayDirExpr(version)}/launch.sh"` return spawnProcess({ @@ -153,10 +153,10 @@ export async function launchWslRelayWithInstall(options: { version: string io: WslRelayLaunchIo isDisposed: () => boolean - onChild: (child: PipedChildProcess) => void + onChild: (child: ChildProcessWithoutNullStreams) => void onNoNode: () => void onFailure: (message: string) => void - connect: (transport: MultiplexerTransport, child: PipedChildProcess) => Promise + connect: (transport: MultiplexerTransport, child: ChildProcessWithoutNullStreams) => Promise }): Promise { const { distro, env, bundleJsPath, version, io } = options let installTried = false diff --git a/src/main/browser/extensions/native-messaging/browser-extension-native-host-process-backpressure.test.ts b/src/main/browser/extensions/native-messaging/browser-extension-native-host-process-backpressure.test.ts index 64e93895c0c..590d100b79a 100644 --- a/src/main/browser/extensions/native-messaging/browser-extension-native-host-process-backpressure.test.ts +++ b/src/main/browser/extensions/native-messaging/browser-extension-native-host-process-backpressure.test.ts @@ -2,13 +2,13 @@ import { once } from 'node:events' import { PassThrough, Writable } from 'node:stream' import { spawnProcess } from '@orca/process-host' -import type { PipedChildProcess } from '@orca/process-host/process-spec' +import type { ChildProcessWithoutNullStreams } from 'node:child_process' import { afterEach, describe, expect, it, vi } from 'vitest' import { NATIVE_HOST_ERRORS } from './browser-extension-native-host-errors' import { startNativeHost, type NativeHostConnection } from './browser-extension-native-host-process' const owned: { - child: PipedChildProcess + child: ChildProcessWithoutNullStreams connection: NativeHostConnection closed: Promise }[] = [] @@ -23,7 +23,7 @@ async function controlledHost(script = 'setInterval(() => {}, 1000);', bufferStd } }) const write = vi.spyOn(stdin, 'write') - const children: PipedChildProcess[] = [] + const children: ChildProcessWithoutNullStreams[] = [] const closes: string[] = [] const messages: string[] = [] let closed: Promise = Promise.resolve() diff --git a/src/main/browser/extensions/native-messaging/browser-extension-native-host-process.test.ts b/src/main/browser/extensions/native-messaging/browser-extension-native-host-process.test.ts index 0ed456a0c07..8b69a504ca6 100644 --- a/src/main/browser/extensions/native-messaging/browser-extension-native-host-process.test.ts +++ b/src/main/browser/extensions/native-messaging/browser-extension-native-host-process.test.ts @@ -4,7 +4,7 @@ import { join } from 'node:path' import { once } from 'node:events' import { build } from 'esbuild' import { spawnProcess } from '@orca/process-host' -import type { PipedChildProcess } from '@orca/process-host/process-spec' +import type { ChildProcessWithoutNullStreams } from 'node:child_process' import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest' import { killAllNativeHosts, @@ -160,7 +160,7 @@ describe('native host process', () => { it('waits for the Windows supervisor to start the host before exposing its connection', async () => { const originalPlatform = Object.getOwnPropertyDescriptor(process, 'platform') Object.defineProperty(process, 'platform', { value: 'win32', configurable: true }) - const children: PipedChildProcess[] = [] + const children: ChildProcessWithoutNullStreams[] = [] const messages: string[] = [] let resolved = false try { diff --git a/src/main/browser/extensions/native-messaging/browser-extension-native-host-process.ts b/src/main/browser/extensions/native-messaging/browser-extension-native-host-process.ts index e48be3b1ba6..bb72af2747f 100644 --- a/src/main/browser/extensions/native-messaging/browser-extension-native-host-process.ts +++ b/src/main/browser/extensions/native-messaging/browser-extension-native-host-process.ts @@ -1,6 +1,7 @@ import { dirname } from 'node:path' import { spawnProcess } from '@orca/process-host' -import type { PipedChildProcess, PipedProcessSpec } from '@orca/process-host/process-spec' +import type { ChildProcessWithoutNullStreams } from 'node:child_process' +import type { PipedProcessSpec } from '@orca/process-host/process-spec' import { childProcessHasExited, forceTerminateProcessTree, @@ -38,9 +39,9 @@ export type NativeHostConnection = { close: () => void } -export type NativeHostSpawner = (spec: PipedProcessSpec) => PipedChildProcess +export type NativeHostSpawner = (spec: PipedProcessSpec) => ChildProcessWithoutNullStreams -const liveHosts = new Map void>() +const liveHosts = new Map void>() /** Quit: kill every host now; a pending grace timer would never fire. */ export function killAllNativeHosts(): void { @@ -55,7 +56,7 @@ export function killAllNativeHosts(): void { liveHosts.clear() } -function forwardStderr(name: string, child: PipedChildProcess): void { +function forwardStderr(name: string, child: ChildProcessWithoutNullStreams): void { let budget = STDERR_LOG_BUDGET_BYTES child.stderr.on('data', (chunk: Buffer) => { if (budget <= 0) { @@ -77,7 +78,7 @@ export function startNativeHost( spawn: NativeHostSpawner = spawnProcess ): Promise { return new Promise((resolve, reject) => { - let child: PipedChildProcess + let child: ChildProcessWithoutNullStreams const supervised = process.platform === 'win32' try { child = spawn( diff --git a/src/main/claude-accounts/claude-login-process-termination.ts b/src/main/claude-accounts/claude-login-process-termination.ts index f0a9195b84b..633ebc34236 100644 --- a/src/main/claude-accounts/claude-login-process-termination.ts +++ b/src/main/claude-accounts/claude-login-process-termination.ts @@ -1,5 +1,5 @@ import { spawnProcess } from '@orca/process-host' -import type { ChildProcessHandle } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import type { WindowsHostInteractiveLoginSpawn } from '../../shared/windows-interactive-login-spawn' import { recordSelfInitiatedTreeKill } from '../crash-reporting/self-initiated-tree-kill-log' import { admitSelfInitiatedTreeKill } from '../pty/process-retirement/own-chromium-tree-kill-guard' @@ -7,7 +7,7 @@ import { admitSelfInitiatedTreeKill } from '../pty/process-retirement/own-chromi const WINDOWS_TASKKILL_TIMEOUT_MS = 5_000 export function terminateClaudeProcess( - child: ChildProcessHandle, + child: ChildProcess, interactiveLogin: WindowsHostInteractiveLoginSpawn | null, afterKill: () => void ): void { diff --git a/src/main/claude/claude-agent-sdk-exit-proof.test.ts b/src/main/claude/claude-agent-sdk-exit-proof.test.ts index f2da6be21cf..c71e8743aa6 100644 --- a/src/main/claude/claude-agent-sdk-exit-proof.test.ts +++ b/src/main/claude/claude-agent-sdk-exit-proof.test.ts @@ -1,5 +1,4 @@ -import type { PipedChildProcess } from '@orca/process-host/process-spec' -import { execFileSync } from 'node:child_process' +import { execFileSync, type ChildProcessWithoutNullStreams } from 'node:child_process' import { describe, expect, it } from 'vitest' import { spawnProcess } from '@orca/process-host' import { proveClaudeChildExit } from './claude-agent-sdk-exit-proof' @@ -71,7 +70,7 @@ async function proveExitWithRetries( return proveClaudeChildExit(input) } -function spawnScript(script: string): PipedChildProcess { +function spawnScript(script: string): ChildProcessWithoutNullStreams { const child = spawnProcess({ program: process.execPath, args: ['-e', script], @@ -81,7 +80,7 @@ function spawnScript(script: string): PipedChildProcess { return child } -function firstStdoutLine(child: PipedChildProcess): Promise { +function firstStdoutLine(child: ChildProcessWithoutNullStreams): Promise { return new Promise((resolve) => { child.stdout.setEncoding('utf8').once('data', (chunk: string) => resolve(chunk.trim())) }) diff --git a/src/main/claude/claude-agent-sdk-exit-proof.ts b/src/main/claude/claude-agent-sdk-exit-proof.ts index a279ab00e26..7587f8798fa 100644 --- a/src/main/claude/claude-agent-sdk-exit-proof.ts +++ b/src/main/claude/claude-agent-sdk-exit-proof.ts @@ -1,4 +1,4 @@ -import type { SpawnedProcess } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import { terminateDescendantSnapshotWithVerdict, type DescendantTreeVerdict @@ -23,7 +23,7 @@ const TREE_VERDICT_TRUST: Record = { exited: 2 } -type ReapableChild = Pick +type ReapableChild = Pick // A missing or exited root may have reparented descendants; its walk cannot prove an empty tree. function admissibleTree( diff --git a/src/main/claude/claude-agent-sdk-process-spawn.ts b/src/main/claude/claude-agent-sdk-process-spawn.ts index d04cd9e2551..a5eb7f49e55 100644 --- a/src/main/claude/claude-agent-sdk-process-spawn.ts +++ b/src/main/claude/claude-agent-sdk-process-spawn.ts @@ -1,4 +1,5 @@ -import type { PipedChildProcess, PipedProcessSpawner } from '@orca/process-host/process-spec' +import type { ChildProcessWithoutNullStreams } from 'node:child_process' +import type { PipedProcessSpawner } from '@orca/process-host/process-spec' import type { SpawnOptions as ClaudeAgentSdkSpawnOptions } from '@anthropic-ai/claude-agent-sdk' import { spawnProcess } from '@orca/process-host' import { @@ -9,8 +10,8 @@ import { claudeChildClosePolicy, claudeChildCloseProven } from './claude-child-e export type ClaudeCodeProcessSpawn = { /** SDK spawn hook; Orca retains process ownership. */ - spawn: (options: ClaudeAgentSdkSpawnOptions) => PipedChildProcess - readonly child: PipedChildProcess | null + spawn: (options: ClaudeAgentSdkSpawnOptions) => ChildProcessWithoutNullStreams + readonly child: ChildProcessWithoutNullStreams | null readonly managed: ManagedProviderProcess | null /** Supervisor pid on POSIX; lease ownership also requires start time and spawn token. */ readonly pid: number | undefined @@ -30,7 +31,7 @@ function definedEnv(env: Record): Record void ): void { const onSubscribe = (event: string | symbol): void => { diff --git a/src/main/claude/claude-agent-sdk-root-kill-fallback.test.ts b/src/main/claude/claude-agent-sdk-root-kill-fallback.test.ts index 91e65460a52..d8417965fd4 100644 --- a/src/main/claude/claude-agent-sdk-root-kill-fallback.test.ts +++ b/src/main/claude/claude-agent-sdk-root-kill-fallback.test.ts @@ -2,7 +2,7 @@ import { EventEmitter } from 'node:events' import { PassThrough } from 'node:stream' import { describe, expect, it, vi } from 'vitest' -import type { SpawnedProcess } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import type { DescendantSnapshot } from '../pty/process-retirement/pty-descendant-termination' import { createClaudeChildTreeReaper } from './claude-agent-sdk-exit-proof' @@ -11,7 +11,7 @@ const ROOT_STARTED_AT = 'Mon Jan 1 00:00:00 2026' const ROOT_FORK_MS = Date.parse(ROOT_STARTED_AT) function mockChild(): EventEmitter & - Pick & { kill: ReturnType } { + Pick & { kill: ReturnType } { return Object.assign(new EventEmitter(), { pid: ROOT_PID, stdin: new PassThrough(), diff --git a/src/main/claude/claude-child-exit-proof-fixture.ts b/src/main/claude/claude-child-exit-proof-fixture.ts index b5330be0577..f157807d036 100644 --- a/src/main/claude/claude-child-exit-proof-fixture.ts +++ b/src/main/claude/claude-child-exit-proof-fixture.ts @@ -1,4 +1,4 @@ -import type { PipedChildProcess } from '@orca/process-host/process-spec' +import type { ChildProcessWithoutNullStreams } from 'node:child_process' import { spawnManagedProviderProcess, type ManagedProviderProcess @@ -9,7 +9,7 @@ const managedChildren = new WeakMap() /** `closePlatform` picks the close rules; the spawn itself always skips the POSIX supervisor. */ export function managedChild( - child: PipedChildProcess, + child: ChildProcessWithoutNullStreams, closePlatform: NodeJS.Platform = 'linux' ): ManagedProviderProcess { const existing = managedChildren.get(child) diff --git a/src/main/claude/claude-child-root-termination.ts b/src/main/claude/claude-child-root-termination.ts index 7633d42838f..1a8b431e4c9 100644 --- a/src/main/claude/claude-child-root-termination.ts +++ b/src/main/claude/claude-child-root-termination.ts @@ -1,7 +1,7 @@ -import type { SpawnedProcess } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' type RootTerminationInput = { - child: Pick + child: Pick exited: () => boolean } diff --git a/src/main/claude/claude-stream-json-connection.test.ts b/src/main/claude/claude-stream-json-connection.test.ts index 1cc57ba3545..17b63de60f7 100644 --- a/src/main/claude/claude-stream-json-connection.test.ts +++ b/src/main/claude/claude-stream-json-connection.test.ts @@ -1,11 +1,11 @@ -import { execFileSync } from 'node:child_process' +import { execFileSync, type ChildProcess } from 'node:child_process' import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path' import { providerDiagnosticOf } from '../../shared/agent-session/failures/agent-session-failure' import { afterEach, describe, expect, it, vi } from 'vitest' import { spawnProcess } from '@orca/process-host' -import type { SpawnedProcess, ProcessSpec } from '@orca/process-host/process-spec' +import type { ProcessSpec } from '@orca/process-host/process-spec' import type { query, CanUseTool } from '@anthropic-ai/claude-agent-sdk' import { @@ -89,7 +89,7 @@ function launchFor( } const spawned: ProcessSpec[] = [] -const spawnedChildren: SpawnedProcess[] = [] +const spawnedChildren: ChildProcess[] = [] async function open( launch: ClaudeStreamJsonLaunch, diff --git a/src/main/claude/windows-native-hook-registration.test.ts b/src/main/claude/windows-native-hook-registration.test.ts index c62b41fcc4a..bf01e0fe34f 100644 --- a/src/main/claude/windows-native-hook-registration.test.ts +++ b/src/main/claude/windows-native-hook-registration.test.ts @@ -1,6 +1,6 @@ import { afterEach, describe, expect, it, vi } from 'vitest' import { spawnProcess } from '@orca/process-host' -import type { PipedChildProcess } from '@orca/process-host/process-spec' +import type { ChildProcessWithoutNullStreams } from 'node:child_process' import { once } from 'node:events' import { existsSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs' import { tmpdir } from 'node:os' @@ -85,7 +85,7 @@ describe.skipIf(process.platform !== 'win32')('ClaudeHookService native hook ins `${join(hooksDir, EXE).replaceAll('\\', '/')} claude` // Holding stdin open keeps the hook image mapped to exercise locked-executable replacement. - function startHeldHook(program: string): PipedChildProcess { + function startHeldHook(program: string): ChildProcessWithoutNullStreams { return spawnProcess({ program, args: ['claude'], diff --git a/src/main/codex/app-server/codex-app-server-client.ts b/src/main/codex/app-server/codex-app-server-client.ts index 837aa52c124..484e164fde0 100644 --- a/src/main/codex/app-server/codex-app-server-client.ts +++ b/src/main/codex/app-server/codex-app-server-client.ts @@ -1,4 +1,5 @@ -import type { ChildProcessHandle, ProcessSpec } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' +import type { ProcessSpec } from '@orca/process-host/process-spec' import { spawnProcess } from '@orca/process-host' import '../trust/toml/config-toml-trust' import { normalizeCodexHookTrustLookupKey as normalizeHookTrustKeyForLookup } from '../trust/identity/codex-trust-identity' @@ -95,12 +96,11 @@ function collectHookListings(result: unknown): CodexHookListing[] { export async function runCodexHookTrustGrantSession( request: CodexHookTrustGrantRequest, - spawnImpl: ( - program: string, - args: string[], - options: Record - ) => ChildProcessHandle = (program, args, options) => - spawnProcess({ program, args, ...options } as ProcessSpec) + spawnImpl: (program: string, args: string[], options: Record) => ChildProcess = ( + program, + args, + options + ) => spawnProcess({ program, args, ...options } as ProcessSpec) ): Promise { return runCodexAppServerSession( request.invocation, diff --git a/src/main/codex/app-server/codex-app-server-process-tree-kill.ts b/src/main/codex/app-server/codex-app-server-process-tree-kill.ts index 80c8b5e1bd1..1e914eb7ff2 100644 --- a/src/main/codex/app-server/codex-app-server-process-tree-kill.ts +++ b/src/main/codex/app-server/codex-app-server-process-tree-kill.ts @@ -1,5 +1,6 @@ import { spawnProcess } from '@orca/process-host' -import type { ChildProcessHandle, ProcessSpec } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' +import type { ProcessSpec } from '@orca/process-host/process-spec' import { admitProcessTreeKill } from '@orca/process-host/process-tree-kill-gate' /** Spawn seam for tests; production always goes through the hardened spawnProcess wrapper. */ @@ -7,13 +8,13 @@ export type CodexAppServerSpawn = ( program: string, args: string[], options: Record -) => ChildProcessHandle +) => ChildProcess export const spawnCodexAppServerProcess: CodexAppServerSpawn = (program, args, options) => spawnProcess({ program, args, ...options } as ProcessSpec) export function killCodexAppServerProcessTree( - child: Pick, + child: Pick, options: { platform?: NodeJS.Platform; spawnImpl?: CodexAppServerSpawn } = {} ): void { const platform = options.platform ?? process.platform diff --git a/src/main/codex/history/index/codex-state-db-backfill-recovery-process.ts b/src/main/codex/history/index/codex-state-db-backfill-recovery-process.ts index 793bff15c01..270d1f4d972 100644 --- a/src/main/codex/history/index/codex-state-db-backfill-recovery-process.ts +++ b/src/main/codex/history/index/codex-state-db-backfill-recovery-process.ts @@ -1,4 +1,4 @@ -import type { ChildProcessHandle } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import { withCliRuntimeOnPath } from '../../../../shared/node-cli-command-resolution' import { parseWslUncPath } from '../../../../shared/wsl-paths' import { buildWslCodexAppServerArgs } from '../../../codex-accounts/wsl-codex-command' @@ -18,7 +18,7 @@ const BACKFILL_RECOVERY_KILL_SITE = 'codex-state-db-backfill-recovery' const BACKFILL_RECOVERY_CLOSE_REQUEST: ProviderCloseRequest = 'stdin-end' export type CodexBackfillRecoveryProcess = { - child: ChildProcessHandle + child: ChildProcess supervised: boolean } @@ -71,7 +71,7 @@ export function spawnCodexBackfillRecoveryProcess( } export async function stopCodexBackfillRecoveryProcess( - child: ChildProcessHandle, + child: ChildProcess, supervised: boolean ): Promise { if (supervised) { diff --git a/src/main/codex/history/index/codex-state-db-backfill-recovery.ts b/src/main/codex/history/index/codex-state-db-backfill-recovery.ts index 6f8dd5a232f..322ffe03649 100644 --- a/src/main/codex/history/index/codex-state-db-backfill-recovery.ts +++ b/src/main/codex/history/index/codex-state-db-backfill-recovery.ts @@ -6,7 +6,7 @@ import { parseWslUncPath } from '../../../../shared/wsl-paths' import { withManagedHookInstallLock } from '../../../agent-hooks/installation/locking/managed-hook-install-lock' import { readManagedHookHostIdentity } from '../../../agent-hooks/installation/locking/managed-hook-owner-identity' import { resolveCodexCommand } from '../../../codex-cli/command' -import type { ChildProcessHandle } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import { spawnCodexAppServerProcess, type CodexAppServerSpawn @@ -43,7 +43,7 @@ type RecoveryDependencies = { countSessions: (sessionsRoot: string, limit: number) => number now: () => number sleep: (ms: number, signal: AbortSignal) => Promise - terminate: (child: ChildProcessHandle, supervised: boolean) => Promise + terminate: (child: ChildProcess, supervised: boolean) => Promise } const defaultDependencies: RecoveryDependencies = { diff --git a/src/main/computer/desktop-script-runtime-host.test.ts b/src/main/computer/desktop-script-runtime-host.test.ts index 7a49bf08d44..90a7a13dc48 100644 --- a/src/main/computer/desktop-script-runtime-host.test.ts +++ b/src/main/computer/desktop-script-runtime-host.test.ts @@ -1,7 +1,7 @@ import { EventEmitter } from 'node:events' import { afterEach, describe, expect, it, vi } from 'vitest' import type { ProcessSpec } from '@orca/process-host/process-spec' -import type { RuntimeChildProcess } from './desktop-script-serve-channel' +import type { ChildProcessWithoutNullStreams } from 'node:child_process' import { DesktopScriptRuntimeHost, isRuntimeHostUnavailable } from './desktop-script-runtime-host' class FakeRuntimeChild extends EventEmitter { @@ -96,7 +96,8 @@ function createHost( const child = new FakeRuntimeChild() child.deferWrites = options.deferWrites === true children.push(child) - return child as unknown as RuntimeChildProcess + // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: this fixture implements the piped streams and events used by the runtime host. + return child as unknown as ChildProcessWithoutNullStreams } }) return { host, children, specs, warnings } diff --git a/src/main/computer/desktop-script-runtime-host.ts b/src/main/computer/desktop-script-runtime-host.ts index 7f4a49cc237..b9a12a9e467 100644 --- a/src/main/computer/desktop-script-runtime-host.ts +++ b/src/main/computer/desktop-script-runtime-host.ts @@ -4,11 +4,8 @@ import { reportComputerDiagnostic } from './computer-sidecar-diagnostics' import { isReplayableTool } from './desktop-script-action' import type { BridgeRequest, BridgeResponse } from './desktop-script-provider-types' import { DesktopScriptRequestQueue } from './desktop-script-request-queue' -import { - startServeChannel, - type DesktopScriptServeChannel, - type RuntimeProcessSpawn -} from './desktop-script-serve-channel' +import type { PipedProcessSpawner } from '@orca/process-host/process-spec' +import { startServeChannel, type DesktopScriptServeChannel } from './desktop-script-serve-channel' import { MAX_START_ATTEMPTS, RuntimeHostAvailability, @@ -27,7 +24,7 @@ const IDLE_SHUTDOWN_MS = 120_000 export const RUNTIME_HOST_UNAVAILABLE = 'runtime_host_unavailable' export type DesktopScriptRuntimeHostOptions = { - spawn?: RuntimeProcessSpawn + spawn?: PipedProcessSpawner powerShellPath?: () => string requestTimeoutMs?: number idleShutdownMs?: number diff --git a/src/main/computer/desktop-script-serve-channel.test.ts b/src/main/computer/desktop-script-serve-channel.test.ts index 6f2cf443eaa..a86a028a7b6 100644 --- a/src/main/computer/desktop-script-serve-channel.test.ts +++ b/src/main/computer/desktop-script-serve-channel.test.ts @@ -1,6 +1,7 @@ import { EventEmitter } from 'node:events' import { describe, expect, it, vi } from 'vitest' -import { DesktopScriptServeChannel, type RuntimeChildProcess } from './desktop-script-serve-channel' +import type { ChildProcessWithoutNullStreams } from 'node:child_process' +import { DesktopScriptServeChannel } from './desktop-script-serve-channel' class FakeChild extends EventEmitter { readonly stdout = new EventEmitter() @@ -36,7 +37,11 @@ class FakeChild extends EventEmitter { function createChannel() { const child = new FakeChild() const handlers = { onLine: vi.fn(), onGone: vi.fn(), onOverflow: vi.fn() } - const channel = new DesktopScriptServeChannel(child as unknown as RuntimeChildProcess, handlers) + const channel = new DesktopScriptServeChannel( + // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: this fixture implements the piped streams and events consumed by the channel. + child as unknown as ChildProcessWithoutNullStreams, + handlers + ) return { channel, child, handlers } } @@ -86,11 +91,15 @@ describe('DesktopScriptServeChannel', () => { const tails: string[] = [] const feed = (index: number): void => { const child = new FakeChild() - const channel = new DesktopScriptServeChannel(child as unknown as RuntimeChildProcess, { - onLine: () => {}, - onGone: () => {}, - onOverflow: () => {} - }) + const channel = new DesktopScriptServeChannel( + // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: this fixture implements the piped streams and events consumed by the channel. + child as unknown as ChildProcessWithoutNullStreams, + { + onLine: () => {}, + onGone: () => {}, + onOverflow: () => {} + } + ) const line = String.fromCharCode(65 + (index % 26)).repeat(1024 * 1024) child.stdout.emit('data', `${line}\n{"partial":${index}`) tails.push((channel as unknown as { buffer: string }).buffer) diff --git a/src/main/computer/desktop-script-serve-channel.ts b/src/main/computer/desktop-script-serve-channel.ts index 53eb8d90b81..816bbf76c07 100644 --- a/src/main/computer/desktop-script-serve-channel.ts +++ b/src/main/computer/desktop-script-serve-channel.ts @@ -1,15 +1,8 @@ import { StringDecoder } from 'node:string_decoder' -import type { - PipedChildProcess, - PipedProcessSpawner, - PipedProcessSpec -} from '@orca/process-host/process-spec' +import type { ChildProcessWithoutNullStreams } from 'node:child_process' +import type { PipedProcessSpawner, PipedProcessSpec } from '@orca/process-host/process-spec' import { ownRetainedString } from '../../shared/own-retained-string' -export type RuntimeChildProcess = PipedChildProcess - -export type RuntimeProcessSpawn = PipedProcessSpawner - /** UTF-16 units, not bytes — this bounds the buffer, it is not a payload contract. */ const MAX_RESPONSE_CHARS = 20 * 1024 * 1024 const MAX_STDERR_CHARS = 4096 @@ -30,7 +23,7 @@ export class DesktopScriptServeChannel { private closed = false constructor( - private readonly child: RuntimeChildProcess, + private readonly child: ChildProcessWithoutNullStreams, private readonly handlers: ServeChannelHandlers ) { const onStdout = (chunk: Buffer | string): void => this.readStdout(chunk) @@ -135,7 +128,7 @@ export class DesktopScriptServeChannel { export function startServeChannel( spec: PipedProcessSpec, - spawn: RuntimeProcessSpawn, + spawn: PipedProcessSpawner, handlers: ServeChannelHandlers ): DesktopScriptServeChannel { return new DesktopScriptServeChannel(spawn(spec), handlers) diff --git a/src/main/computer/macos-computer-use-permission-status-cleanup.integration.test.ts b/src/main/computer/macos-computer-use-permission-status-cleanup.integration.test.ts index 4a78022c95b..a01de3fdffb 100644 --- a/src/main/computer/macos-computer-use-permission-status-cleanup.integration.test.ts +++ b/src/main/computer/macos-computer-use-permission-status-cleanup.integration.test.ts @@ -3,12 +3,12 @@ import { mkdtemp, rm } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { spawnProcess } from '@orca/process-host' -import type { ChildProcessHandle } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import { afterEach, describe, expect, it } from 'vitest' import { stopMacOSPermissionStatusHelper } from './macos-computer-use-permission-status-cleanup' describe.skipIf(process.platform !== 'darwin')('real permission status helper cleanup', () => { - const children: ChildProcessHandle[] = [] + const children: ChildProcess[] = [] const directories: string[] = [] afterEach(async () => { @@ -27,7 +27,7 @@ describe.skipIf(process.platform !== 'darwin')('real permission status helper cl ) }) - async function startFixture(executablePath: string, args: string[]): Promise { + async function startFixture(executablePath: string, args: string[]): Promise { const child = spawnProcess({ program: process.execPath, args: [ diff --git a/src/main/computer/macos-native-provider-process-reaping.ts b/src/main/computer/macos-native-provider-process-reaping.ts index e0e28d196a3..e9a4cf4dba1 100644 --- a/src/main/computer/macos-native-provider-process-reaping.ts +++ b/src/main/computer/macos-native-provider-process-reaping.ts @@ -1,4 +1,4 @@ -import type { ChildProcessHandle as ChildProcess } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' export const PROVIDER_SIGKILL_GRACE_MS = 2_000 diff --git a/src/main/computer/macos-native-provider-reaping.integration.test.ts b/src/main/computer/macos-native-provider-reaping.integration.test.ts index 2ba3fe2c502..291415219fe 100644 --- a/src/main/computer/macos-native-provider-reaping.integration.test.ts +++ b/src/main/computer/macos-native-provider-reaping.integration.test.ts @@ -1,11 +1,11 @@ import { once } from 'node:events' import { afterEach, describe, expect, it } from 'vitest' import { spawnProcess } from '@orca/process-host' -import type { ChildProcessHandle } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import { reapMacOSProviderProcess } from './macos-native-provider-process-reaping' describe.skipIf(process.platform === 'win32')('real macOS provider process reaping', () => { - const children: ChildProcessHandle[] = [] + const children: ChildProcess[] = [] afterEach(async () => { await Promise.all( diff --git a/src/main/daemon/launch/daemon-launched-child-spawn.ts b/src/main/daemon/launch/daemon-launched-child-spawn.ts index 4a2f49cf937..a4c103b1e6c 100644 --- a/src/main/daemon/launch/daemon-launched-child-spawn.ts +++ b/src/main/daemon/launch/daemon-launched-child-spawn.ts @@ -1,6 +1,6 @@ import { forkProcess, type ForkSpec } from '@orca/process-host/fork-process' import { spawnProcess } from '@orca/process-host' -import type { SpawnedProcess } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import { getAppEnvironment } from '../../../shared/app-environment' import { removeChromiumDisabledSessionBus } from '../../pty/shell-startup/chromium-session-bus-env' import { hostMallocTunablesDaemonEnv } from '../../memory/host-malloc-tunables' @@ -79,7 +79,7 @@ export function buildDaemonScriptArgs( export function spawnDaemonChildProcess( options: DaemonChildSpawnOptions, useDurableScope: boolean -): SpawnedProcess { +): ChildProcess { const { forkEntryPath, relocatedExecPath, diff --git a/src/main/daemon/process-scopes/daemon-scope-death-watch.ts b/src/main/daemon/process-scopes/daemon-scope-death-watch.ts index 7dbc81f8454..c95f9b3a8bb 100644 --- a/src/main/daemon/process-scopes/daemon-scope-death-watch.ts +++ b/src/main/daemon/process-scopes/daemon-scope-death-watch.ts @@ -1,5 +1,6 @@ import { spawnProcess } from '@orca/process-host' -import type { ProcessSpec, SpawnedProcess } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' +import type { ProcessSpec } from '@orca/process-host/process-spec' // The pipe closes even on SIGKILL; a live/reused owner PID always vetoes cleanup. const SCOPE_DEATH_WATCH_SCRIPT = ` @@ -24,10 +25,10 @@ type ScopeDeathWatchOptions = { /** Stopping the owned daemon scope also reaps its bound terminal slice. */ daemonScope: string | null log: (event: string, details?: Record) => void - spawn?: (spec: ProcessSpec) => SpawnedProcess + spawn?: (spec: ProcessSpec) => ChildProcess } -export function startDaemonScopeDeathWatch(options: ScopeDeathWatchOptions): SpawnedProcess | null { +export function startDaemonScopeDeathWatch(options: ScopeDeathWatchOptions): ChildProcess | null { const { daemonScope: unit, log } = options if (!unit) { return null diff --git a/src/main/ipc/filesystem/filesystem-listing-process-cleanup.ts b/src/main/ipc/filesystem/filesystem-listing-process-cleanup.ts index c752933a5bc..39e40eb1fbf 100644 --- a/src/main/ipc/filesystem/filesystem-listing-process-cleanup.ts +++ b/src/main/ipc/filesystem/filesystem-listing-process-cleanup.ts @@ -1,8 +1,8 @@ -import type { ChildProcessHandle } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import { killSpawnedRipgrepProcess } from '../../../shared/ripgrep/ripgrep-process-availability' export type FilesystemListingProcess = { - child: ChildProcessHandle + child: ChildProcess isDone: () => boolean finish: (error?: Error) => void } diff --git a/src/main/ipc/filesystem/watcher-process/parcel-watcher-child-slot.ts b/src/main/ipc/filesystem/watcher-process/parcel-watcher-child-slot.ts index c88c0797a94..bb1108690bc 100644 --- a/src/main/ipc/filesystem/watcher-process/parcel-watcher-child-slot.ts +++ b/src/main/ipc/filesystem/watcher-process/parcel-watcher-child-slot.ts @@ -1,16 +1,16 @@ -import type { ChildProcessHandle } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import { removeWatcherCanaryDirectory } from './parcel-watcher-canary-directory' export class WatcherChildSlot { - child: ChildProcessHandle | null = null - terminating: ChildProcessHandle | null = null + child: ChildProcess | null = null + terminating: ChildProcess | null = null canaryDir: string | null = null removeCanary(): void { this.canaryDir = removeWatcherCanaryDirectory(this.canaryDir) } - beginTermination(proc: ChildProcessHandle): void { + beginTermination(proc: ChildProcess): void { this.terminating = proc this.removeCanary() } diff --git a/src/main/ipc/filesystem/watcher-process/parcel-watcher-owned-children.ts b/src/main/ipc/filesystem/watcher-process/parcel-watcher-owned-children.ts index 1d1c33e7a66..550cda225de 100644 --- a/src/main/ipc/filesystem/watcher-process/parcel-watcher-owned-children.ts +++ b/src/main/ipc/filesystem/watcher-process/parcel-watcher-owned-children.ts @@ -1,14 +1,14 @@ -import type { ChildProcessHandle } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import { watcherChildPhysicalExit, requireWatcherChildTermination } from './parcel-watcher-child-termination' export class WatcherOwnedChildren { - private readonly children = new Set() + private readonly children = new Set() private disposal: Promise | null = null - track(child: ChildProcessHandle): ChildProcessHandle { + track(child: ChildProcess): ChildProcess { this.children.add(child) // Reuse launch-owned physical-exit evidence, including close without exit after spawn failure. void watcherChildPhysicalExit(child).then(() => { diff --git a/src/main/ipc/filesystem/watchers/filesystem-watcher-wsl.ts b/src/main/ipc/filesystem/watchers/filesystem-watcher-wsl.ts index db7dd96a81c..3c499f85538 100644 --- a/src/main/ipc/filesystem/watchers/filesystem-watcher-wsl.ts +++ b/src/main/ipc/filesystem/watchers/filesystem-watcher-wsl.ts @@ -1,5 +1,5 @@ /** Poll inside WSL so distro shutdown kills the watcher instead of Windows UNC polling repeatedly waking it. */ -import type { PipedChildProcess } from '@orca/process-host/process-spec' +import type { ChildProcessWithoutNullStreams } from 'node:child_process' import { StringDecoder } from 'node:string_decoder' import type { WebContents } from 'electron' import type { Event as WatcherEvent } from '@parcel/watcher' @@ -234,7 +234,7 @@ export async function createWslWatcher( } } - let child: PipedChildProcess + let child: ChildProcessWithoutNullStreams const releaseChildReservation = watcherChildRegistry.reserveWatcherChild() if (!releaseChildReservation) { throw new watcherChildRegistry.WatcherChildCapacityError() diff --git a/src/main/ipc/filesystem/watchers/wsl-watcher-spawn.ts b/src/main/ipc/filesystem/watchers/wsl-watcher-spawn.ts index 88db2150c2f..dd5c599ad03 100644 --- a/src/main/ipc/filesystem/watchers/wsl-watcher-spawn.ts +++ b/src/main/ipc/filesystem/watchers/wsl-watcher-spawn.ts @@ -1,9 +1,12 @@ import { spawnProcess } from '@orca/process-host' -import type { PipedChildProcess } from '@orca/process-host/process-spec' +import type { ChildProcessWithoutNullStreams } from 'node:child_process' import { resolveWslInteropSpawnCwd } from '../../../wsl/execution/wsl-interop-spawn-directory' /** Start the in-distro poll script; process-host applies the internal distro allowlist. */ -export function spawnWslWatcherProcess(distro: string, linuxPath: string): PipedChildProcess { +export function spawnWslWatcherProcess( + distro: string, + linuxPath: string +): ChildProcessWithoutNullStreams { return spawnProcess({ program: 'wsl.exe', args: ['-d', distro, '--exec', 'sh', '-s', '--', linuxPath], diff --git a/src/main/managed-server/lifecycle/orcad-bash-stdio-bridge.test.ts b/src/main/managed-server/lifecycle/orcad-bash-stdio-bridge.test.ts index 918193203a8..dda2f33008f 100644 --- a/src/main/managed-server/lifecycle/orcad-bash-stdio-bridge.test.ts +++ b/src/main/managed-server/lifecycle/orcad-bash-stdio-bridge.test.ts @@ -1,11 +1,10 @@ import { existsSync, mkdirSync, mkdtempSync, readdirSync, rmSync, writeFileSync } from 'node:fs' -import { spawnSync } from 'node:child_process' +import { spawnSync, type ChildProcessWithoutNullStreams } from 'node:child_process' import { createServer, type Server, type Socket } from 'node:net' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterAll, beforeAll, describe, expect, it } from 'vitest' import { spawnProcess } from '@orca/process-host' -import type { PipedChildProcess as Bridge } from '@orca/process-host/process-spec' import { OrcadStdioBridgeUnavailableError } from '../../orcad/orcad-host-unavailable' import { checkOrcadStdioBridge, type OrcadStdioBridge } from './orcad-stdio-bridge' import { orcadBashStdioBridgeCommand } from './orcad-stdio-bridge-script' @@ -39,7 +38,10 @@ afterAll(() => { rmSync(scratch, { recursive: true, force: true }) }) -function spawnBridge(port: number, env: Partial = {}): Bridge { +function spawnBridge( + port: number, + env: Partial = {} +): ChildProcessWithoutNullStreams { return spawnProcess({ program: '/bin/sh', args: ['-c', orcadBashStdioBridgeCommand(port)], @@ -51,7 +53,7 @@ function realCat(): string { return spawnSync('sh', ['-c', 'command -v cat'], { encoding: 'utf8' }).stdout.trim() } -function exitOf(child: Bridge): Promise { +function exitOf(child: ChildProcessWithoutNullStreams): Promise { return new Promise((resolve) => child.once('exit', (code) => resolve(code))) } diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-start-telemetry.test.ts b/src/main/native-chat/agent-session-wire/host/testing/structured-agent-session-start-telemetry.test.ts similarity index 68% rename from src/main/native-chat/agent-session-wire/structured-agent-session-start-telemetry.test.ts rename to src/main/native-chat/agent-session-wire/host/testing/structured-agent-session-start-telemetry.test.ts index 31d95661f38..91decedd1c8 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-start-telemetry.test.ts +++ b/src/main/native-chat/agent-session-wire/host/testing/structured-agent-session-start-telemetry.test.ts @@ -1,13 +1,9 @@ import { beforeEach, expect, it, vi } from 'vitest' -import { track } from '../../telemetry/client' -import { - CALLER, - attachParams, - hostTestState -} from './host/testing/structured-agent-session-host-test-harness' -import './host/testing/structured-agent-session-create-test-fixture' +import { track } from '../../../../telemetry/client' +import { CALLER, attachParams, hostTestState } from './structured-agent-session-host-test-harness' +import './structured-agent-session-create-test-fixture' -vi.mock('../../telemetry/client', () => ({ track: vi.fn() })) +vi.mock('../../../../telemetry/client', () => ({ track: vi.fn() })) beforeEach(() => vi.mocked(track).mockClear()) it('keeps a proved process live when telemetry capture fails', async () => { diff --git a/src/main/opencode/opencode-launch-model-context.ts b/src/main/opencode/opencode-launch-model-context.ts index 08d2dc8854e..2d46321dc10 100644 --- a/src/main/opencode/opencode-launch-model-context.ts +++ b/src/main/opencode/opencode-launch-model-context.ts @@ -10,7 +10,7 @@ import { withTimeout } from '../../shared/promise-timeout-fallback' import { createOutputSink } from '@orca/process-host/bounded-output-sink' import { readFetchResponseJsonWithinLimit } from '../../shared/fetch-response-body' import { cancelUnreadResponseBody } from '../lib/unread-response-body' -import type { ChildProcessHandle } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import { createProviderSpawnSpec } from '../provider-process/provider-process-supervisor' import { stopSupervisedChildProcess } from '../provider-process/supervised-child-process-stop' import { guardSupervisedProviderGroup } from '../provider-process/provider-group-orphan-guard' @@ -172,7 +172,7 @@ export async function probeOpenCodeLaunchModelContext(options: { /** Only the supervisor’s normal stop/relayed exit proves its detached server group is gone. * Forced supervisor teardown and failed group reap (exit 1) prove nothing. */ async function stopSupervisedPreflight( - child: ChildProcessHandle, + child: ChildProcess, closed: Promise ): Promise { if (!child.pid) { diff --git a/src/main/provider-process/managed-provider-process.ts b/src/main/provider-process/managed-provider-process.ts index 3abd330609f..27ea3fadc04 100644 --- a/src/main/provider-process/managed-provider-process.ts +++ b/src/main/provider-process/managed-provider-process.ts @@ -1,4 +1,5 @@ -import type { PipedChildProcess, PipedProcessSpawner } from '@orca/process-host/process-spec' +import type { ChildProcessWithoutNullStreams } from 'node:child_process' +import type { PipedProcessSpawner } from '@orca/process-host/process-spec' import { spawnProcess } from '@orca/process-host' import { RetryableProcessExitProof } from '@orca/process-host/retryable-process-exit-proof' import type { ProviderProcessLaunch } from './provider-process-launch' @@ -53,7 +54,7 @@ type ManagedProviderProcessOptions = { } export type ManagedProviderProcess = { - child: PipedChildProcess + child: ChildProcessWithoutNullStreams supervised: boolean /** The spawn failed before a process existed: absence is proven, but no exit was observed. */ readonly processless: boolean diff --git a/src/main/provider-process/provider-process-close.ts b/src/main/provider-process/provider-process-close.ts index f8f2dd21b8d..580ea37cbde 100644 --- a/src/main/provider-process/provider-process-close.ts +++ b/src/main/provider-process/provider-process-close.ts @@ -1,4 +1,4 @@ -import type { SpawnedProcess } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import type { DescendantTreeVerdict } from '../pty/process-retirement/pty-descendant-exit-verification' import { waitForProcessExitUntil } from './provider-process-exit-deadline' import { @@ -26,7 +26,7 @@ export type ProviderProcessClosePolicy = { } export type ProviderProcessCloseInput = { - child: Pick + child: Pick exitPromise: Promise rootVerdict: () => DescendantTreeVerdict supervised?: boolean diff --git a/src/main/provider-process/provider-process-teardown.ts b/src/main/provider-process/provider-process-teardown.ts index 259ea48963a..c751abeea98 100644 --- a/src/main/provider-process/provider-process-teardown.ts +++ b/src/main/provider-process/provider-process-teardown.ts @@ -1,4 +1,4 @@ -import type { ChildProcessHandle } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import { captureDescendantSnapshot, type DescendantSnapshot @@ -19,7 +19,7 @@ export type ProviderProcessTeardownVerdict = const activeTeardowns = new WeakMap>() -type TeardownChild = Pick +type TeardownChild = Pick export type ProviderProcessTeardownDeps = { site: string diff --git a/src/main/provider-process/supervised-child-process-stop.ts b/src/main/provider-process/supervised-child-process-stop.ts index 308776f760b..d24d1353bef 100644 --- a/src/main/provider-process/supervised-child-process-stop.ts +++ b/src/main/provider-process/supervised-child-process-stop.ts @@ -1,4 +1,4 @@ -import type { ChildProcessHandle } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import { closeProviderProcess, rootOnlyProviderClosePolicy, @@ -8,7 +8,7 @@ import type { ProviderCloseRequest } from './provider-process-supervisor' import { terminateProviderProcessTree } from './provider-process-teardown' type SupervisedChild = Pick< - ChildProcessHandle, + ChildProcess, 'pid' | 'kill' | 'stdin' | 'exitCode' | 'signalCode' | 'once' > diff --git a/src/main/providers/windows-console-attached-processes.ts b/src/main/providers/windows-console-attached-processes.ts index d6c7ef3c827..e74bcc32226 100644 --- a/src/main/providers/windows-console-attached-processes.ts +++ b/src/main/providers/windows-console-attached-processes.ts @@ -1,5 +1,5 @@ import { forkProcess } from '@orca/process-host/fork-process' -import type { SpawnedProcess } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' const CONPTY_PROCESS_LIST_TIMEOUT_MS = 3_000 @@ -9,7 +9,7 @@ type ForkConsoleListAgent = ( modulePath: string, args: string[], options: { silent: true } -) => SpawnedProcess +) => ChildProcess const forkConsoleListAgent: ForkConsoleListAgent = (modulePath, args) => forkProcess({ modulePath, args, stdio: ['pipe', 'pipe', 'pipe', 'ipc'] }) @@ -33,7 +33,7 @@ export function readWindowsConsoleAttachedProcessIds( if (!Number.isSafeInteger(rootPid) || rootPid <= 0) { return Promise.resolve(null) } - let child: SpawnedProcess + let child: ChildProcess try { child = (deps.forkProcess ?? forkConsoleListAgent)( (deps.resolveAgentPath ?? resolveNodePtyConsoleListAgent)(), diff --git a/src/main/ripgrep/bundled-ripgrep-stop.ts b/src/main/ripgrep/bundled-ripgrep-stop.ts index 1f1166c7d74..ceaac0ff1c5 100644 --- a/src/main/ripgrep/bundled-ripgrep-stop.ts +++ b/src/main/ripgrep/bundled-ripgrep-stop.ts @@ -1,10 +1,10 @@ import { signalProcessTree } from '@orca/process-host/process-tree-termination' import { killSpawnedRipgrepProcess } from '../../shared/ripgrep/ripgrep-process-availability' -import type { ChildProcessHandle } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' -const stoppingChildren = new WeakSet() +const stoppingChildren = new WeakSet() -export function stopBundledRipgrep(child: ChildProcessHandle, wsl = false): void { +export function stopBundledRipgrep(child: ChildProcess, wsl = false): void { if (stoppingChildren.has(child)) { return } diff --git a/src/main/ripgrep/bundled-ripgrep-text-search.ts b/src/main/ripgrep/bundled-ripgrep-text-search.ts index b4cd60b9809..7fca8a88f3b 100644 --- a/src/main/ripgrep/bundled-ripgrep-text-search.ts +++ b/src/main/ripgrep/bundled-ripgrep-text-search.ts @@ -1,4 +1,4 @@ -import type { ChildProcessHandle } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import type { SearchOptions, SearchResult } from '../../shared/file-search/code-search-types' import { RipgrepSearchDiagnostics } from '../../shared/ripgrep/ripgrep-search-diagnostics' import { SearchSubprocessLineAccumulator } from '../../shared/search-subprocess-lines' @@ -45,7 +45,7 @@ export function runBundledRipgrepTextSearch({ wslDistro?: string wslDistroForOutput?: string signal?: AbortSignal - onSpawn: (child: ChildProcessHandle) => () => void + onSpawn: (child: ChildProcess) => () => void }): Promise { throwIfSignalAborted(signal) const maxResults = Math.max( @@ -65,7 +65,7 @@ export function runBundledRipgrepTextSearch({ let resolved = false let processErrorObserved = false let unavailableExitObserved = false - let child: ChildProcessHandle | null = null + let child: ChildProcess | null = null let killTimeout: ReturnType | undefined let releaseChild: (() => void) | undefined diff --git a/src/main/ssh/system-transport/forwarding/system-ssh-forward-process.ts b/src/main/ssh/system-transport/forwarding/system-ssh-forward-process.ts index 00873182918..207fc8eb1fb 100644 --- a/src/main/ssh/system-transport/forwarding/system-ssh-forward-process.ts +++ b/src/main/ssh/system-transport/forwarding/system-ssh-forward-process.ts @@ -1,4 +1,4 @@ -import type { ChildProcessHandle as ChildProcess } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import { spawnProcess } from '@orca/process-host' import { connect } from 'node:net' import { createSshOperationAbortError } from '../../connection/ssh-exec-options' diff --git a/src/main/ssh/system-transport/forwarding/system-ssh-loopback-route.ts b/src/main/ssh/system-transport/forwarding/system-ssh-loopback-route.ts index 3beed7c4017..ed9baf9fc0d 100644 --- a/src/main/ssh/system-transport/forwarding/system-ssh-loopback-route.ts +++ b/src/main/ssh/system-transport/forwarding/system-ssh-loopback-route.ts @@ -1,5 +1,5 @@ /** On Windows, hold a proxied ssh -N -L once; route later execs through loopback to avoid repeated proxy handshakes without ControlMaster. */ -import type { ChildProcessHandle as ChildProcess } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import { childProcessHasExited, signalProcessTree diff --git a/src/main/startup/hydrate-shell-path.ts b/src/main/startup/hydrate-shell-path.ts index 6ef5377c07a..95f1e25ef1c 100644 --- a/src/main/startup/hydrate-shell-path.ts +++ b/src/main/startup/hydrate-shell-path.ts @@ -1,4 +1,4 @@ -import type { SpawnedProcess } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import { delimiter, win32 as pathWin32 } from 'node:path' import { spawnProcess } from '@orca/process-host' import { stripAnsiEscapeSequences } from '../../shared/ansi-escape-sequences' @@ -154,7 +154,7 @@ function spawnShellAndReadPath(shell: string): Promise { let stdout = '' let timer: ReturnType | null = null - let child: SpawnedProcess + let child: ChildProcess try { child = spawnProcess({ program: shell, diff --git a/src/main/startup/shell-probe-lifetime.ts b/src/main/startup/shell-probe-lifetime.ts index 133a4f661ee..4480edc8250 100644 --- a/src/main/startup/shell-probe-lifetime.ts +++ b/src/main/startup/shell-probe-lifetime.ts @@ -1,5 +1,5 @@ /** A detached login-shell probe gets no terminal signals, so its owner ends it: on timeout and when the owner exits. */ -import type { SpawnedProcess } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import { signalProcessTree } from '@orca/process-host/process-tree-termination' export type ShellProbeLifetime = { @@ -10,7 +10,7 @@ export type ShellProbeLifetime = { } // No signal listeners: one would replace Electron's graceful signal quit, and every owner turns INT/TERM into an exit. -export function bindShellProbeLifetime(child: SpawnedProcess): ShellProbeLifetime { +export function bindShellProbeLifetime(child: ChildProcess): ShellProbeLifetime { const kill = (): void => { if (process.platform === 'win32') { // Windows probes stay attached, and a tree kill would spawn taskkill from an exit hook. diff --git a/src/main/worker-thread-child-process/worker-thread-child-process-server.ts b/src/main/worker-thread-child-process/worker-thread-child-process-server.ts index 94ed6e9a95c..99d57da2fae 100644 --- a/src/main/worker-thread-child-process/worker-thread-child-process-server.ts +++ b/src/main/worker-thread-child-process/worker-thread-child-process-server.ts @@ -1,4 +1,4 @@ -import type { PipedChildProcess } from '@orca/process-host/process-spec' +import type { ChildProcessWithoutNullStreams } from 'node:child_process' import { spawnProcess } from '@orca/process-host' import type { WorkerThreadChildErrorPayload, @@ -24,10 +24,13 @@ function toErrorPayload(error: unknown): WorkerThreadChildErrorPayload { } export function serveWorkerThreadChildProcesses(port: WorkerThreadChildPort): void { - const children = new Map() + const children = new Map< + number, + { child: ChildProcessWithoutNullStreams; pendingOutputBytes: number } + >() const spawnChild = ({ id, spec }: Extract): void => { - let child: PipedChildProcess + let child: ChildProcessWithoutNullStreams try { child = spawnProcess({ ...spec, stdio: ['pipe', 'pipe', 'pipe'] }) } catch (error) { diff --git a/src/main/wsl/execution/wsl-command-channel.test.ts b/src/main/wsl/execution/wsl-command-channel.test.ts index cc4dc186f19..2e0d8ec0ade 100644 --- a/src/main/wsl/execution/wsl-command-channel.test.ts +++ b/src/main/wsl/execution/wsl-command-channel.test.ts @@ -1,7 +1,7 @@ import { EventEmitter } from 'node:events' import { PassThrough } from 'node:stream' import { afterEach, beforeEach, expect, it, vi } from 'vitest' -import type { PipedChildProcess } from '@orca/process-host/process-spec' +import type { ChildProcessWithoutNullStreams } from 'node:child_process' import { killWslChannelsInCloseGrace, WSL_CHANNEL_CLOSE_GRACE_MS, @@ -25,7 +25,7 @@ function fakeChild() { child.emit('exit', code, null) } // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the channel reads only these members. - return { child: child as unknown as PipedChildProcess, fake: child, exit } + return { child: child as unknown as ChildProcessWithoutNullStreams, fake: child, exit } } beforeEach(() => { diff --git a/src/main/wsl/execution/wsl-command-channel.ts b/src/main/wsl/execution/wsl-command-channel.ts index a677ca506ac..db67ffa2fa5 100644 --- a/src/main/wsl/execution/wsl-command-channel.ts +++ b/src/main/wsl/execution/wsl-command-channel.ts @@ -1,12 +1,12 @@ import { Duplex } from 'node:stream' -import type { PipedChildProcess } from '@orca/process-host/process-spec' +import type { ChildProcessWithoutNullStreams } from 'node:child_process' import type { RemoteCommandChannel } from '../../managed-server/install/remote-install-transport' /** How long a closed channel's guest gets to exit on stdin EOF before wsl.exe is killed. */ export const WSL_CHANNEL_CLOSE_GRACE_MS = 2_000 // wsl.exe children inside their close grace; quit kills them so none outlives Orca. -const closingChildren = new Set() +const closingChildren = new Set() /** App quit: no grace left, so a guest still running after close must not keep wsl.exe up. */ export function killWslChannelsInCloseGrace(): void { @@ -19,7 +19,7 @@ export function killWslChannelsInCloseGrace(): void { } /** Expose wsl.exe stdio as an SSH-style channel; exit reports status and close follows stdio teardown. */ -export function wrapWslCommandProcess(child: PipedChildProcess): RemoteCommandChannel { +export function wrapWslCommandProcess(child: ChildProcessWithoutNullStreams): RemoteCommandChannel { // Only the child emits close, once after exit status, like ssh2. const duplex = new Duplex({ emitClose: false, diff --git a/src/main/wsl/execution/wsl-command-loop-pool.ts b/src/main/wsl/execution/wsl-command-loop-pool.ts index 68b67d17ffd..066883d9768 100644 --- a/src/main/wsl/execution/wsl-command-loop-pool.ts +++ b/src/main/wsl/execution/wsl-command-loop-pool.ts @@ -1,4 +1,4 @@ -import type { PipedChildProcess } from '@orca/process-host/process-spec' +import type { ChildProcessWithoutNullStreams } from 'node:child_process' import type { RemoteCommandChannel } from '../../managed-server/install/remote-install-transport' import { createSshOperationAbortError } from '../../ssh/connection/ssh-exec-options' import { startWslCommandLoop, wslCommandLoopMarker, type WslCommandLoop } from './wsl-command-loop' @@ -11,7 +11,7 @@ export type WslCommandLoopPool = { type WslCommandLoopPoolOptions = { /** Starts `wsl.exe --exec sh -c `. */ - spawnLoop: (marker: string) => PipedChildProcess + spawnLoop: (marker: string) => ChildProcessWithoutNullStreams /** Concurrent commands beyond this run on their own wsl.exe, as before. */ maxLoops?: number idleMs?: number diff --git a/src/main/wsl/execution/wsl-command-loop.test.ts b/src/main/wsl/execution/wsl-command-loop.test.ts index 10756004375..ac746c861f9 100644 --- a/src/main/wsl/execution/wsl-command-loop.test.ts +++ b/src/main/wsl/execution/wsl-command-loop.test.ts @@ -3,14 +3,14 @@ import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, describe, expect, it } from 'vitest' import { spawnProcess } from '@orca/process-host' -import type { PipedChildProcess } from '@orca/process-host/process-spec' +import type { ChildProcessWithoutNullStreams } from 'node:child_process' import { execCommand } from '../../ssh/remote-exec/remote-exec-command' import { WSL_COMMAND_LOOP_ARGV0, WSL_COMMAND_LOOP_SCRIPT } from './wsl-command-loop' import { createWslCommandLoopPool, type WslCommandLoopPool } from './wsl-command-loop-pool' // The guest side is plain POSIX sh, so a local sh stands in for `wsl.exe --exec sh`. const posix = process.platform !== 'win32' -const spawned: PipedChildProcess[] = [] +const spawned: ChildProcessWithoutNullStreams[] = [] const pools: WslCommandLoopPool[] = [] function pool(options: { maxLoops?: number; script?: string } = {}) { diff --git a/src/main/wsl/execution/wsl-command-loop.ts b/src/main/wsl/execution/wsl-command-loop.ts index 15c580b60ad..8265657feca 100644 --- a/src/main/wsl/execution/wsl-command-loop.ts +++ b/src/main/wsl/execution/wsl-command-loop.ts @@ -1,7 +1,7 @@ /** Reuse one wsl.exe for sequential stdin-free probes (~180ms startup each on win-lowspec). Isolate each sh command in its own session with /dev/null stdin; base64-frame output/status with per-loop markers. */ import { randomUUID } from 'node:crypto' import { Duplex, PassThrough, Writable } from 'node:stream' -import type { PipedChildProcess } from '@orca/process-host/process-spec' +import type { ChildProcessWithoutNullStreams } from 'node:child_process' import type { RemoteCommandChannel } from '../../managed-server/install/remote-install-transport' // setsid preserves per-command process-group isolation. Fresh output files keep background writers attached to old inodes, never the next command. @@ -53,7 +53,10 @@ export function wslCommandLoopMarker(): string { return `__ORCA_WSL_EXEC_${randomUUID().replaceAll('-', '')}__` } -export function startWslCommandLoop(child: PipedChildProcess, marker: string): WslCommandLoop { +export function startWslCommandLoop( + child: ChildProcessWithoutNullStreams, + marker: string +): WslCommandLoop { let pending: PendingCommand | null = null let alive = true let buffered = '' diff --git a/src/main/wsl/filesystem/wsl-directory-upload.test.ts b/src/main/wsl/filesystem/wsl-directory-upload.test.ts index 4713614a565..6524ed13059 100644 --- a/src/main/wsl/filesystem/wsl-directory-upload.test.ts +++ b/src/main/wsl/filesystem/wsl-directory-upload.test.ts @@ -1,4 +1,4 @@ -import { execFileSync } from 'node:child_process' +import { execFileSync, type ChildProcessWithoutNullStreams } from 'node:child_process' import { chmodSync, existsSync, @@ -14,7 +14,6 @@ import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it } from 'vitest' import { spawnProcess } from '@orca/process-host' -import type { PipedChildProcess } from '@orca/process-host/process-spec' import { uploadDirectoryIntoWsl } from './wsl-directory-upload' import { createWslOrcadHostTransport, @@ -37,7 +36,7 @@ describe.skipIf(process.platform === 'win32' || !hasSha256sum())('uploadDirector let dest: string let commands: string[] const transports: WslOrcadHostTransport[] = [] - const children: PipedChildProcess[] = [] + const children: ChildProcessWithoutNullStreams[] = [] const getTransport = (): WslOrcadHostTransport => { const transport = transports.at(-1) diff --git a/src/main/wsl/orcad/__tests__/wsl-orcad-bridge-test-child.ts b/src/main/wsl/orcad/__tests__/wsl-orcad-bridge-test-child.ts index 441ab6a6ca4..7cc6a162c56 100644 --- a/src/main/wsl/orcad/__tests__/wsl-orcad-bridge-test-child.ts +++ b/src/main/wsl/orcad/__tests__/wsl-orcad-bridge-test-child.ts @@ -2,7 +2,8 @@ import { EventEmitter } from 'node:events' import { connect } from 'node:net' import { PassThrough } from 'node:stream' -import type { PipedChildProcess, PipedProcessSpawner } from '@orca/process-host/process-spec' +import type { ChildProcessWithoutNullStreams } from 'node:child_process' +import type { PipedProcessSpawner } from '@orca/process-host/process-spec' import { ORCAD_STDIO_BRIDGE_READY, ORCAD_STDIO_BRIDGE_REFUSED, @@ -78,7 +79,7 @@ export function fakeWslBridgeChildren(): FakeWslBridgeChildren { socket.on('close', () => finish(0)) process.nextTick(() => child.emit('spawn')) // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the WSL channel reads only the streams, exit state, kill and events assigned above. - return child as unknown as PipedChildProcess + return child as unknown as ChildProcessWithoutNullStreams } return { spawn, commands, live: () => live, maxLive: () => maxLive } } diff --git a/src/main/wsl/orcad/wsl-orcad-host-transport-loops.test.ts b/src/main/wsl/orcad/wsl-orcad-host-transport-loops.test.ts index ecf40e11877..615893291f7 100644 --- a/src/main/wsl/orcad/wsl-orcad-host-transport-loops.test.ts +++ b/src/main/wsl/orcad/wsl-orcad-host-transport-loops.test.ts @@ -1,12 +1,13 @@ import { Readable } from 'node:stream' import { afterEach, describe, expect, it } from 'vitest' import { spawnProcess } from '@orca/process-host' -import type { PipedChildProcess, PipedProcessSpec } from '@orca/process-host/process-spec' +import type { ChildProcessWithoutNullStreams } from 'node:child_process' +import type { PipedProcessSpec } from '@orca/process-host/process-spec' import { execCommand } from '../../ssh/remote-exec/remote-exec-command' import { createWslOrcadHostTransport, type WslOrcadHostTransport } from './wsl-orcad-host-transport' const posix = process.platform !== 'win32' -const children: PipedChildProcess[] = [] +const children: ChildProcessWithoutNullStreams[] = [] const transports: WslOrcadHostTransport[] = [] /** Runs what follows `--exec` with the local sh, as wsl.exe would inside the distro. */ diff --git a/src/main/wsl/orcad/wsl-orcad-host-transport.test.ts b/src/main/wsl/orcad/wsl-orcad-host-transport.test.ts index 79af2088e4b..9d79590ff15 100644 --- a/src/main/wsl/orcad/wsl-orcad-host-transport.test.ts +++ b/src/main/wsl/orcad/wsl-orcad-host-transport.test.ts @@ -1,7 +1,8 @@ import { EventEmitter } from 'node:events' import { PassThrough, Readable } from 'node:stream' import { describe, expect, it, vi } from 'vitest' -import type { PipedChildProcess, PipedProcessSpec } from '@orca/process-host/process-spec' +import type { ChildProcessWithoutNullStreams } from 'node:child_process' +import type { PipedProcessSpec } from '@orca/process-host/process-spec' import { execCommand } from '../../ssh/remote-exec/remote-exec-command' import { WSL_CHANNEL_CLOSE_GRACE_MS } from '../execution/wsl-command-channel' @@ -61,7 +62,7 @@ function transportWith(children: FakeChild[]) { throw new Error('no fake child left') } // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the channel reads only the streams, exit state, kill and events the fake provides. - return next as unknown as PipedChildProcess + return next as unknown as ChildProcessWithoutNullStreams } }) return { transport, specs } @@ -172,7 +173,7 @@ describe('a transport with an abort signal', () => { commandLoops: false, signal: controller.signal, // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the channel reads only the streams, exit state, kill and events the fake provides. - spawn: () => child as unknown as PipedChildProcess + spawn: () => child as unknown as ChildProcessWithoutNullStreams }) const channel = await transport.exec('sleep 60') channel.on('error', () => {}) diff --git a/src/packages/process-host/src/fork-process.ts b/src/packages/process-host/src/fork-process.ts index 804b8d4aeb6..0a53bc2448d 100644 --- a/src/packages/process-host/src/fork-process.ts +++ b/src/packages/process-host/src/fork-process.ts @@ -2,9 +2,9 @@ import { fork as nodeFork, type ForkOptions, - type SpawnOptions as NodeSpawnOptions + type SpawnOptions as NodeSpawnOptions, + type ChildProcess } from 'node:child_process' -import type { SpawnedProcess } from './process-spec' // Preserve fork semantics for module resolution, execPath overrides, and inherited execArgv. export type ForkSpec = { @@ -23,7 +23,7 @@ export type ForkSpec = { serialization?: ForkOptions['serialization'] } -export function forkProcess(spec: ForkSpec): SpawnedProcess { +export function forkProcess(spec: ForkSpec): ChildProcess { const options: ForkOptions = { cwd: spec.cwd, env: spec.env, diff --git a/src/packages/process-host/src/process-spec.ts b/src/packages/process-host/src/process-spec.ts index 1137d5f3a55..34e4c1a1b61 100644 --- a/src/packages/process-host/src/process-spec.ts +++ b/src/packages/process-host/src/process-spec.ts @@ -5,10 +5,6 @@ import type { StdioOptions } from 'node:child_process' -export type ChildProcessHandle = ChildProcess - -export type SpawnedProcess = ChildProcess - export type ProcessSpec = { /** Prefer an absolute Windows path; stripped Electron PATHs may not resolve bare names. */ program: string @@ -42,13 +38,11 @@ export type ProcessSpec = { onStderr?: (chunk: Buffer | string) => void } -export type PipedChildProcess = ChildProcessWithoutNullStreams - export type PipedProcessSpec = Omit & { stdio?: 'pipe' | ['pipe', 'pipe', 'pipe', ...Exclude] } -export type PipedProcessSpawner = (spec: PipedProcessSpec) => PipedChildProcess +export type PipedProcessSpawner = (spec: PipedProcessSpec) => ChildProcessWithoutNullStreams export type ProcessTerminationBarrier = { observeStderr?: (chunk: Buffer | string) => void diff --git a/src/packages/process-host/src/run-process.ts b/src/packages/process-host/src/run-process.ts index 6e634fb5d46..c8b699fa62e 100644 --- a/src/packages/process-host/src/run-process.ts +++ b/src/packages/process-host/src/run-process.ts @@ -1,7 +1,8 @@ import { spawn as nodeSpawn, spawnSync as nodeSpawnSync, - type ChildProcess + type ChildProcess, + type ChildProcessWithoutNullStreams } from 'node:child_process' import { resolveSpawn, type ResolvedSpawn } from './spawn-resolution' import { forceTerminateProcessTree, signalProcessTree } from './process-tree-termination' @@ -13,12 +14,7 @@ import { createChildTerminationReporter } from './child-termination-reporter' export { WindowsCmdLineBreakError } from './windows-command-line' -import type { - PipedChildProcess, - PipedProcessSpec, - ProcessSpec, - ProcessResult -} from './process-spec' +import type { PipedProcessSpec, ProcessSpec, ProcessResult } from './process-spec' import { DEFAULT_PROCESS_TIMEOUT_MS, DEFAULT_MAX_OUTPUT_BYTES } from './process-spec' // Bound waits for children that ignore termination and never emit close. const PROCESS_EXIT_GRACE_MS = 2_000 @@ -26,7 +22,7 @@ const PROCESS_EXIT_GRACE_MS = 2_000 const BARRIER_UNVERIFIED_EXIT_GRACE_MS = 10_000 /** Callers own stream error handling; unhandled stream errors can crash the host process. */ -export function spawnProcess(spec: PipedProcessSpec): PipedChildProcess +export function spawnProcess(spec: PipedProcessSpec): ChildProcessWithoutNullStreams export function spawnProcess(spec: ProcessSpec): ChildProcess export function spawnProcess(spec: ProcessSpec): ChildProcess { const resolved = resolveSpawn(spec, process.platform) diff --git a/src/packages/process-host/src/spawn-process-stdio.test.ts b/src/packages/process-host/src/spawn-process-stdio.test.ts index cfa9613e4aa..501e0c5d63c 100644 --- a/src/packages/process-host/src/spawn-process-stdio.test.ts +++ b/src/packages/process-host/src/spawn-process-stdio.test.ts @@ -1,9 +1,10 @@ import { once } from 'node:events' import { describe, expect, expectTypeOf, it } from 'vitest' import { spawnProcess } from '@orca/process-host' -import type { ChildProcessHandle, PipedChildProcess, ProcessSpec } from './process-spec' +import type { ChildProcess, ChildProcessWithoutNullStreams } from 'node:child_process' +import type { ProcessSpec } from './process-spec' -async function waitForClose(child: ChildProcessHandle): Promise { +async function waitForClose(child: ChildProcess): Promise { try { await once(child, 'close', { signal: AbortSignal.timeout(5_000) }) } finally { @@ -18,7 +19,7 @@ async function waitForClose(child: ChildProcessHandle): Promise { describe('public spawn stream contracts', () => { it('returns three pipes by default', async () => { const child = spawnProcess({ program: process.execPath, args: ['-e', ''] }) - expectTypeOf(child).toEqualTypeOf() + expectTypeOf(child).toEqualTypeOf() await waitForClose(child) expect(child.stdin).not.toBeNull() expect(child.stdout).not.toBeNull() @@ -27,7 +28,7 @@ describe('public spawn stream contracts', () => { it('returns three pipes for an explicit pipe mode', async () => { const child = spawnProcess({ program: process.execPath, args: ['-e', ''], stdio: 'pipe' }) - expectTypeOf(child).toEqualTypeOf() + expectTypeOf(child).toEqualTypeOf() await waitForClose(child) expect(child.stdin).not.toBeNull() expect(child.stdout).not.toBeNull() @@ -40,7 +41,7 @@ describe('public spawn stream contracts', () => { args: ['-e', ''], stdio: ['pipe', 'pipe', 'pipe'] }) - expectTypeOf(child).toEqualTypeOf() + expectTypeOf(child).toEqualTypeOf() await waitForClose(child) expect(child.stdin).not.toBeNull() expect(child.stdout).not.toBeNull() @@ -53,7 +54,7 @@ describe('public spawn stream contracts', () => { args: ['-e', 'process.disconnect()'], stdio: ['pipe', 'pipe', 'pipe', 'ipc'] }) - expectTypeOf(child).toEqualTypeOf() + expectTypeOf(child).toEqualTypeOf() await waitForClose(child) expect(child.stdin).not.toBeNull() expect(child.stdout).not.toBeNull() @@ -62,7 +63,7 @@ describe('public spawn stream contracts', () => { it.each(['ignore', 'inherit'] as const)('returns nullable streams for %s', async (stdio) => { const child = spawnProcess({ program: process.execPath, args: ['-e', ''], stdio }) - expectTypeOf(child).toEqualTypeOf() + expectTypeOf(child).toEqualTypeOf() await waitForClose(child) expect(child.stdin).toBeNull() expect(child.stdout).toBeNull() @@ -75,7 +76,7 @@ describe('public spawn stream contracts', () => { args: ['-e', ''], stdio: ['ignore', 'pipe', 'pipe'] }) - expectTypeOf(child).toEqualTypeOf() + expectTypeOf(child).toEqualTypeOf() await waitForClose(child) expect(child.stdin).toBeNull() expect(child.stdout).not.toBeNull() @@ -85,7 +86,7 @@ describe('public spawn stream contracts', () => { it('keeps the general contract when the specification does not guarantee pipes', async () => { const spec: ProcessSpec = { program: process.execPath, args: ['-e', ''] } const child = spawnProcess(spec) - expectTypeOf(child).toEqualTypeOf() + expectTypeOf(child).toEqualTypeOf() await waitForClose(child) }) }) diff --git a/src/shared/__fixtures__/fake-spawned-child.ts b/src/shared/__fixtures__/fake-spawned-child.ts index edeb24870e6..9897a16de1c 100644 --- a/src/shared/__fixtures__/fake-spawned-child.ts +++ b/src/shared/__fixtures__/fake-spawned-child.ts @@ -1,6 +1,6 @@ import type * as ChildProcessModule from 'node:child_process' import { PassThrough } from 'node:stream' -import type { PipedChildProcess } from '@orca/process-host/process-spec' +import type { ChildProcessWithoutNullStreams } from 'node:child_process' import { vi } from 'vitest' // Consumers may mock spawn without exporting the ChildProcess constructor. @@ -11,7 +11,13 @@ class FakeSpawnedChild extends NodeChildProcess { override stdin = new PassThrough() override stdout = new PassThrough() override stderr = new PassThrough() - override stdio: PipedChildProcess['stdio'] = [this.stdin, this.stdout, this.stderr, null, null] + override stdio: ChildProcessWithoutNullStreams['stdio'] = [ + this.stdin, + this.stdout, + this.stderr, + null, + null + ] override kill = vi.fn((_signal?: NodeJS.Signals | number) => true) override unref = vi.fn<() => void>() diff --git a/src/shared/file-listing/node-markdown-document-listing.ts b/src/shared/file-listing/node-markdown-document-listing.ts index 26e14e7ecc3..e8d99216006 100644 --- a/src/shared/file-listing/node-markdown-document-listing.ts +++ b/src/shared/file-listing/node-markdown-document-listing.ts @@ -1,4 +1,4 @@ -import type { ChildProcessHandle } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' import type { MarkdownDocument } from './file-document' import { RipgrepFilenameDecoder } from '../ripgrep/ripgrep-filename-decoder' import { @@ -38,7 +38,7 @@ export const MARKDOWN_DOCUMENT_LISTING_ARGS = [ ] export function collectMarkdownDocuments( - child: ChildProcessHandle, + child: ChildProcess, rootPath: string, windowsOutput = false, signal?: AbortSignal, diff --git a/src/shared/ripgrep/ripgrep-process-availability.ts b/src/shared/ripgrep/ripgrep-process-availability.ts index 2b7f1f9ecb3..47d5c131936 100644 --- a/src/shared/ripgrep/ripgrep-process-availability.ts +++ b/src/shared/ripgrep/ripgrep-process-availability.ts @@ -1,6 +1,6 @@ import { constants } from 'node:fs' import { access, stat } from 'node:fs/promises' -import type { ChildProcessHandle } from '@orca/process-host/process-spec' +import type { ChildProcess } from 'node:child_process' const RIPGREP_CWD_CHECK_TIMEOUT_MS = 1000 @@ -35,7 +35,7 @@ export function isTransientRipgrepSpawnError(error: unknown): boolean { function ignoreRipgrepSpawnError(): void {} -export function killSpawnedRipgrepProcess(child: ChildProcessHandle): boolean { +export function killSpawnedRipgrepProcess(child: ChildProcess): boolean { // Why: killing a failed-spawn handle can signal the relay's own process group. if (Object.hasOwn(child, 'pid') && child.pid === undefined) { return false @@ -44,7 +44,7 @@ export function killSpawnedRipgrepProcess(child: ChildProcessHandle): boolean { } export function absorbPendingRipgrepSpawnError( - child: ChildProcessHandle, + child: ChildProcess, state: { errorObserved: boolean; unavailableExitObserved: boolean } ): void { if ( @@ -107,7 +107,7 @@ export async function classifySynchronousRipgrepSpawnFailure( } export function isRipgrepUnavailableExit( - child: ChildProcessHandle, + child: ChildProcess, code: number | null, signal: NodeJS.Signals | null, options: { classifyNativeLauncherExit?: boolean } = {}