Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
refactor(spawn): core services launch through src/core/spawn.ts (#4992)
garrytanbc097b44b5c0
diff --git a/src/core/binary-self-update.ts b/src/core/binary-self-update.tsindex 4b4fa72b92..4e1cd6e4eb 100644--- a/src/core/binary-self-update.ts+++ b/src/core/binary-self-update.ts@@ -44,7 +44,7 @@import { chmodSync, closeSync, fsyncSync, openSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';import { dirname, join } from 'node:path';-import { execFileSync } from 'node:child_process';+import { execFileSync } from './spawn.ts';import { createHash } from 'node:crypto';/**diff --git a/src/core/bun-floor.ts b/src/core/bun-floor.tsindex f6a4820f02..e44793e090 100644--- a/src/core/bun-floor.ts+++ b/src/core/bun-floor.ts@@ -20,7 +20,7 @@* No DB; readers return failure values instead of throwing.*/-import { execFileSync } from 'node:child_process';+import { execFileSync } from './spawn.ts';import { readFileSync } from 'node:fs';import { join } from 'node:path';import { VERSION } from '../version.ts';diff --git a/src/core/docker-postgres.ts b/src/core/docker-postgres.tsindex 749f763041..e547090be3 100644--- a/src/core/docker-postgres.ts+++ b/src/core/docker-postgres.ts@@ -12,7 +12,7 @@* not ours to recreate).*/-import { spawnSync } from 'node:child_process';+import { spawnSync } from './spawn.ts';export const GBRAIN_PG_CONTAINER = 'gbrain-postgres';export const GBRAIN_PG_IMAGE = 'pgvector/pgvector:pg16';diff --git a/src/core/embed-stale-images.ts b/src/core/embed-stale-images.tsindex 3bb5037f17..228f9bfad1 100644--- a/src/core/embed-stale-images.ts+++ b/src/core/embed-stale-images.ts@@ -24,7 +24,7 @@* (`runStaleImageSweepFirst`), inside the run's cost cap.*/-import { execFileSync } from 'child_process';+import { execFileSync } from './spawn.ts';import type { BrainEngine } from './engine.ts';import { importImageFile } from './import-file.ts';import { resolveRecordedImageFile, type DirectoryListings, type RecordedImageFile } from './image-asset-resolver.ts';diff --git a/src/core/git-first-commit.ts b/src/core/git-first-commit.tsindex e8debc3cee..db431ce80c 100644--- a/src/core/git-first-commit.ts+++ b/src/core/git-first-commit.ts@@ -10,7 +10,7 @@* stay the fallback.*/-import { execFileSync } from 'child_process';+import { execFileSync } from './spawn.ts';import { realpathSync } from 'fs';import { relative } from 'path';import { gitChildEnv } from './git-env.ts';diff --git a/src/core/git-head.ts b/src/core/git-head.tsindex 8c035bf03f..f5eefe2150 100644--- a/src/core/git-head.ts+++ b/src/core/git-head.ts@@ -22,7 +22,7 @@* gate. See plan note "v0.41.27.1+ TODOs" in* ~/.claude/plans/system-instruction-you-are-working-eager-bird.md.*/-import { execFileSync } from 'node:child_process';+import { execFileSync } from './spawn.ts';import { gitChildEnv } from './git-env.ts';export type GitHeadProbe = (localPath: string) => string | null;diff --git a/src/core/git-visible-files.ts b/src/core/git-visible-files.tsindex f1270bce88..e30618774d 100644--- a/src/core/git-visible-files.ts+++ b/src/core/git-visible-files.ts@@ -1,5 +1,5 @@import { AsyncLocalStorage } from 'node:async_hooks';-import { execFileSync } from 'child_process';+import { execFileSync } from './spawn.ts';import { lstatSync } from 'fs';import { join, resolve } from 'path';import { gitChildEnv } from './git-env.ts';diff --git a/src/core/pglite-lock.ts b/src/core/pglite-lock.tsindex e3341da8b7..8541b4ccc8 100644--- a/src/core/pglite-lock.ts+++ b/src/core/pglite-lock.ts@@ -2,7 +2,7 @@import { mkdirSync, existsSync, readFileSync, writeFileSync, rmSync, renameSync, realpathSync, readlinkSync } from 'node:fs';import { basename, dirname, join, resolve } from 'node:path';import { randomUUID } from 'node:crypto';-import { execFileSync } from 'node:child_process';+import { execFileSync } from './spawn.ts';import { readProcessCommand, type ProcessCommandProbeDeps } from './autopilot-lock.ts';import { setTimeout as delay } from 'node:timers/promises';import { parseGlobalFlags } from './cli-options.ts';diff --git a/src/core/repo-visibility.ts b/src/core/repo-visibility.tsindex e050f7a7c3..e4ecb78bc9 100644--- a/src/core/repo-visibility.ts+++ b/src/core/repo-visibility.ts@@ -40,6 +40,7 @@ import { ensureGbrainHome } from './gbrain-home.ts';import { durableSsrfFlags } from './git-remote.ts';import { isCredentialInjectingProxy } from './execution-env.ts';import { gitChildEnv } from './git-env.ts';+import { bunSpawn } from './spawn.ts';// ── Subprocess seam (canonical home; bootstrap/repo.ts re-exports) ─────────@@ -52,11 +53,11 @@ export interface ExecResult {/** Injectable subprocess seam. argv[0] is the binary; never a shell string. */export type ExecRunner = (argv: string[]) => Promise<ExecResult>;-/** Default runner: Bun.spawn, both streams piped, spawn failure → code 127.+/** Default runner: bunSpawn (src/core/spawn.ts), both streams piped, spawn failure → code 127.* GIT_TERMINAL_PROMPT=0 so an unauthenticated git can never hang on a prompt. */export const defaultRunner: ExecRunner = async (argv: string[]): Promise<ExecResult> => {try {- const proc = Bun.spawn(argv, {+ const proc = bunSpawn(argv, {stdout: 'pipe',stderr: 'pipe',stdin: 'ignore',diff --git a/src/core/skill-fix-gates.ts b/src/core/skill-fix-gates.tsindex 75ec2c18d7..0544949672 100644--- a/src/core/skill-fix-gates.ts+++ b/src/core/skill-fix-gates.ts@@ -26,7 +26,7 @@* appear in dry-fix's own argument surface.*/-import { execFileSync } from 'node:child_process';+import { execFileSync } from './spawn.ts';import { dirname } from 'node:path';import { gitChildEnv } from './git-env.ts';diff --git a/src/core/source-health.ts b/src/core/source-health.tsindex 8cb2500ecd..6199d73b07 100644--- a/src/core/source-health.ts+++ b/src/core/source-health.ts@@ -21,7 +21,7 @@* `newest_content_at` column instead — NO git subprocess on a DB-supplied* local_path (preserves the v0.41.27.0 trust boundary).*/-import { execFileSync } from 'child_process';+import { execFileSync } from './spawn.ts';import type { BrainEngine } from './engine.ts';import { parseSourceConfig, type SourceRow } from './sources-load.ts';import { isSourceUnchangedSinceSync } from './git-head.ts';diff --git a/src/core/sync-delta.ts b/src/core/sync-delta.tsindex 1e35695064..6377c0ce52 100644--- a/src/core/sync-delta.ts+++ b/src/core/sync-delta.ts@@ -31,7 +31,7 @@* require A to be an ancestor of B (unlike a rev-walk or `A...B` merge-base).* That is the #1970 property this module preserves.*/-import { execFileSync } from 'node:child_process';+import { execFileSync } from './spawn.ts';import { buildSyncManifest, type SyncManifest } from './sync.ts';import { gitChildEnv } from './git-env.ts';diff --git a/src/core/sync-git.ts b/src/core/sync-git.tsindex dd996df656..95837ae7fe 100644--- a/src/core/sync-git.ts+++ b/src/core/sync-git.ts@@ -4,7 +4,7 @@* src/commands/sync.ts (containment sprint C13-C14) as a pure move.*/import { realpathSync } from 'fs';-import { execFileSync } from 'child_process';+import { execFileSync } from './spawn.ts';import { isAbsolute, join, relative, sep } from 'path';import type { BrainEngine } from './engine.ts';import { resolveSlugForPath, DEFAULT_SOURCE_ID } from './sync.ts';diff --git a/src/core/sync-reconcile.ts b/src/core/sync-reconcile.tsindex 61266bedcb..bb429c4d56 100644--- a/src/core/sync-reconcile.ts+++ b/src/core/sync-reconcile.ts@@ -3,7 +3,7 @@* gate) + sync deadline/stall resolution (#1633, #1950). Peeled out of* src/commands/sync.ts (containment sprint C13-C14) as a pure move.*/-import { execFileSync } from 'child_process';+import { execFileSync } from './spawn.ts';import { parseDurationSeconds } from './sync-concurrency.ts';import { resolveStallAbortSecondsFromEnv } from './stall-env.ts';import { gitChildEnv } from './git-env.ts';diff --git a/src/core/sync-upstream.ts b/src/core/sync-upstream.tsindex f9d30fc09d..c58b25c7a3 100644--- a/src/core/sync-upstream.ts+++ b/src/core/sync-upstream.ts@@ -8,7 +8,7 @@* three `sources.upstream_*` columns, so a remote doctor needs no subprocess.* A missing or older-than-24 h observation is "upstream unknown", never fresh.*/-import { execFileSync } from 'node:child_process';+import { execFileSync } from './spawn.ts';import { statSync } from 'node:fs';import type { BrainEngine } from './engine.ts';import { ERROR_CATALOGUE } from './error-catalogue.ts';diff --git a/src/core/tailscale.ts b/src/core/tailscale.tsindex 7266e1a307..168e99f6bf 100644--- a/src/core/tailscale.ts+++ b/src/core/tailscale.ts@@ -47,6 +47,7 @@import { existsSync, realpathSync } from 'node:fs';import { shellQuote } from './mcp-registration.ts';+import { bunSpawn } from './spawn.ts';export const TAILSCALE_ADMIN_DNS_URL = 'https://login.tailscale.com/admin/dns';export const TAILSCALE_ADMIN_ACL_URL = 'https://login.tailscale.com/admin/acls';@@ -91,7 +92,7 @@ export const defaultCommandRunner: CommandRunner = async (argv, opts = {}) => {let timer: ReturnType<typeof setTimeout> | null = null;let killTimer: ReturnType<typeof setTimeout> | null = null;try {- const proc = Bun.spawn(argv, {+ const proc = bunSpawn(argv, {stdin: opts.inherit ? 'inherit' : 'ignore',stdout: opts.inherit ? (opts.stdoutToStderr ? 2 : 'inherit') : 'pipe',stderr: opts.inherit ? 'inherit' : 'pipe',diff --git a/src/core/thin-client-upgrade-prompt.ts b/src/core/thin-client-upgrade-prompt.tsindex ced55b9b2a..984a470ed9 100644--- a/src/core/thin-client-upgrade-prompt.ts+++ b/src/core/thin-client-upgrade-prompt.ts@@ -21,7 +21,7 @@import { existsSync, readFileSync, writeFileSync, renameSync, openSync, closeSync, unlinkSync, statSync, mkdirSync } from 'fs';import { dirname } from 'path';-import { execSync, execFileSync } from 'child_process';+import { execSync, execFileSync } from './spawn.ts';import { compareVersions } from './migration-ledger.ts';import { gbrainPath } from './config.ts';import type { GBrainConfig } from './config.ts';diff --git a/src/core/transcription.ts b/src/core/transcription.tsindex 24cf4e3c96..22642b653f 100644--- a/src/core/transcription.ts+++ b/src/core/transcription.ts@@ -178,7 +178,7 @@ async function transcribeLargeFile(// shell metacharacters (`;`, `$()`, backticks, quotes) would be a command// injection if passed through a shell. Argument arrays bypass the shell// entirely, so audioPath is always a single literal argv element.- const { execFileSync } = await import('child_process');+ const { execFileSync } = await import('./spawn.ts');const tmpDir = execFileSync('mktemp', ['-d']).toString().trim();try {@@ -240,7 +240,7 @@ async function transcribeLargeFile(async function checkFfmpeg(): Promise<boolean> {try {- const { execFileSync } = await import('child_process');+ const { execFileSync } = await import('./spawn.ts');execFileSync('ffmpeg', ['-version'], { stdio: 'pipe' });return true;} catch {