Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
refactor(spawn): commands launch through src/core/spawn.ts (#4992)
garrytancf41d808b040
diff --git a/src/cli/commands/smoke-test.ts b/src/cli/commands/smoke-test.tsindex a1983f7a1c..1ece244565 100644--- a/src/cli/commands/smoke-test.ts+++ b/src/cli/commands/smoke-test.ts@@ -9,7 +9,7 @@ import type { CliDispatchContext } from '../command-table.ts';export async function run(args: string[], ctx: CliDispatchContext): Promise<void> {const { cliModuleUrl } = ctx;// Run smoke tests — no DB connection needed, the script handles its own checks- const { execSync } = await import('child_process');+ const { execSync } = await import('../../core/spawn.ts');const { resolve, dirname } = await import('path');const { fileURLToPath } = await import('url');const scriptDir = dirname(fileURLToPath(cliModuleUrl));diff --git a/src/commands/connect.ts b/src/commands/connect.tsindex 48100bd416..fde78ecfd8 100644--- a/src/commands/connect.ts+++ b/src/commands/connect.ts@@ -37,7 +37,7 @@ import { harnessAdapter } from '../core/harness/registry.ts';* - generic: prints the connector fields for any other MCP client.*/-import { execFileSync } from 'child_process';+import { execFileSync } from '../core/spawn.ts';import { mkdirSync } from 'node:fs';import { dirname } from 'node:path';import type { ConnectProbeResult } from '../core/connect-probe.ts';diff --git a/src/commands/doctor/bootstrap-checks.ts b/src/commands/doctor/bootstrap-checks.tsindex 499c5727ea..71f7bb160a 100644--- a/src/commands/doctor/bootstrap-checks.ts+++ b/src/commands/doctor/bootstrap-checks.ts@@ -5,7 +5,7 @@*/import { join } from 'path';import { existsSync } from 'fs';-import { execFileSync } from 'child_process';+import { execFileSync } from '../../core/spawn.ts';import type { BrainEngine } from '../../core/engine.ts';import { LATEST_VERSION } from '../../core/migrate.ts';// Agent-bootstrap doctor group (plan B2/B4/ENG-4 + one-live-serve note).diff --git a/src/commands/doctor/checks/git-convergence.ts b/src/commands/doctor/checks/git-convergence.tsindex 7b8665c4f9..0a9c71c6c9 100644--- a/src/commands/doctor/checks/git-convergence.ts+++ b/src/commands/doctor/checks/git-convergence.ts@@ -13,7 +13,7 @@** The same entry emits `tracked_ownership_marker` (#5186) for the same roots.*/-import { execFileSync } from 'node:child_process';+import { execFileSync } from '../../../core/spawn.ts';import { statSync } from 'node:fs';import { join } from 'node:path';import type { BrainEngine } from '../../../core/engine.ts';diff --git a/src/commands/doctor/checks/local-audits.ts b/src/commands/doctor/checks/local-audits.tsindex 1a88f01aa1..243c3929e0 100644--- a/src/commands/doctor/checks/local-audits.ts+++ b/src/commands/doctor/checks/local-audits.ts@@ -398,7 +398,7 @@ async function runHomeDirInWorktree(ctx: DoctorContext): Promise<Check[]> {// PATH or the entry is broken. Skips silently when gbrain isn't on PATH// at all (e.g. running via `bun src/cli.ts`).try {- const { execSync } = await import('node:child_process');+ const { execSync } = await import('../../../core/spawn.ts');let candidates: string[] = [];try {candidates = execSync('which -a gbrain', {diff --git a/src/commands/eval-brainbench.ts b/src/commands/eval-brainbench.tsindex 813ccbb3cb..7cc61c1e81 100644--- a/src/commands/eval-brainbench.ts+++ b/src/commands/eval-brainbench.ts@@ -17,7 +17,7 @@import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';import { dirname, join } from 'node:path';-import { execSync } from 'node:child_process';+import { execSync } from '../core/spawn.ts';import { flushThenExit } from '../core/cli-force-exit.ts';import { cliOptsToProgressOptions, getCliOptions } from '../core/cli-options.ts';import { createProgress } from '../core/progress.ts';diff --git a/src/commands/eval-compare.ts b/src/commands/eval-compare.tsindex 4f66bee212..0c7f873596 100644--- a/src/commands/eval-compare.ts+++ b/src/commands/eval-compare.ts@@ -287,7 +287,7 @@ function readEvalResults(repoRoot: string, override?: string): ParsedRecord[] {function getRepoRoot(): string {try {- const { execSync } = require('child_process') as typeof import('child_process');+ const { execSync } = require('../core/spawn.ts') as typeof import('../core/spawn.ts');return execSync('git rev-parse --show-toplevel', { encoding: 'utf-8' }).trim();} catch {return process.cwd();diff --git a/src/commands/eval-run-all.ts b/src/commands/eval-run-all.tsindex c72bba7429..03fc971623 100644--- a/src/commands/eval-run-all.ts+++ b/src/commands/eval-run-all.ts@@ -214,7 +214,7 @@ export interface EvalRunRecord {function getRepoRoot(): string {try {- const { execSync } = require('child_process') as typeof import('child_process');+ const { execSync } = require('../core/spawn.ts') as typeof import('../core/spawn.ts');return execSync('git rev-parse --show-toplevel', { encoding: 'utf-8' }).trim();} catch {return process.cwd();@@ -223,7 +223,7 @@ function getRepoRoot(): string {function getCommitSha(): string {try {- const { execSync } = require('child_process') as typeof import('child_process');+ const { execSync } = require('../core/spawn.ts') as typeof import('../core/spawn.ts');return execSync('git rev-parse --short HEAD', { encoding: 'utf-8' }).trim();} catch {return 'unknown';diff --git a/src/commands/frontmatter-install-hook.ts b/src/commands/frontmatter-install-hook.tsindex 2173bfd00d..939c8867b8 100644--- a/src/commands/frontmatter-install-hook.ts+++ b/src/commands/frontmatter-install-hook.ts@@ -32,7 +32,7 @@import { existsSync, readFileSync, writeFileSync, mkdirSync, chmodSync, rmSync, copyFileSync, realpathSync, readdirSync, statSync, lstatSync } from 'fs';import { isAbsolute, join, relative, resolve } from 'path';-import { execFileSync } from 'child_process';+import { execFileSync } from '../core/spawn.ts';import type { BrainEngine } from '../core/engine.ts';import { loadConfig, toEngineConfig } from '../core/config.ts';import { createEngine } from '../core/engine-factory.ts';diff --git a/src/commands/frontmatter.ts b/src/commands/frontmatter.tsindex a6d5c8b050..05e9165306 100644--- a/src/commands/frontmatter.ts+++ b/src/commands/frontmatter.ts@@ -21,7 +21,7 @@ import { assertManagedFilesystemWrite, managedFilesystemRootFor } from '../core/*/import { readFileSync, writeFileSync, existsSync, lstatSync, readdirSync } from 'fs';-import { execFileSync } from 'child_process';+import { execFileSync } from '../core/spawn.ts';import { setCliExitVerdict } from '../core/cli-force-exit.ts';import { join, relative, resolve, basename, dirname, isAbsolute, posix } from 'path';import type { BrainEngine } from '../core/engine.ts';diff --git a/src/commands/init.ts b/src/commands/init.tsindex 14f59420f9..c88f88e427 100644--- a/src/commands/init.ts+++ b/src/commands/init.ts@@ -1,4 +1,4 @@-import { execSync } from 'child_process';+import { execSync } from '../core/spawn.ts';import { readdirSync, lstatSync, existsSync, copyFileSync, mkdirSync, readFileSync } from 'fs';import { join, dirname } from 'path';import { fileURLToPath } from 'url';diff --git a/src/commands/integrations.ts b/src/commands/integrations.tsindex 1b45513604..6c131ede2d 100644--- a/src/commands/integrations.ts+++ b/src/commands/integrations.ts@@ -25,7 +25,7 @@ import { join, basename } from 'path';import { homedir } from 'os';import { gbrainPath, loadConfig } from '../core/config.ts';import { buildGatewayConfig } from '../core/ai/build-gateway-config.ts';-import { execSync } from 'child_process';+import { execSync } from '../core/spawn.ts';import { fetchWithSSRFGuard, HttpProxyError, SSRFError } from '../core/ssrf-validate.ts';// --- Types ---@@ -314,7 +314,7 @@ export async function executeHealthCheck(return { ...base, status: 'blocked', output: `Blocked: command health_checks are restricted to embedded recipes. (${check.argv[0]})` };}try {- const { spawnSync } = await import('child_process');+ const { spawnSync } = await import('../core/spawn.ts');const result = spawnSync(check.argv[0], check.argv.slice(1), {timeout: 10000,encoding: 'utf-8',diff --git a/src/commands/migrations/in-process.ts b/src/commands/migrations/in-process.tsindex d762546c9f..6a58c9dab9 100644--- a/src/commands/migrations/in-process.ts+++ b/src/commands/migrations/in-process.ts@@ -21,7 +21,7 @@* `getaddrinfo ENOTFOUND` line instead of the bare `Command failed: ...`.*/-import { execSync } from 'child_process';+import { execSync } from '../../core/spawn.ts';import { resolveChildCliInvocation } from '../../core/minions/job-isolation.ts';import { loadConfig } from '../../core/config.ts';diff --git a/src/commands/migrations/v0_11_0.ts b/src/commands/migrations/v0_11_0.tsindex 63334f0b9e..d657350c2f 100644--- a/src/commands/migrations/v0_11_0.ts+++ b/src/commands/migrations/v0_11_0.ts@@ -22,7 +22,7 @@import { existsSync, readFileSync, writeFileSync, mkdirSync, appendFileSync, lstatSync, statSync, realpathSync } from 'fs';import { join, resolve, dirname } from 'path';-import { execSync } from 'child_process';+import { execSync } from '../../core/spawn.ts';import type { Migration, OrchestratorOpts, OrchestratorResult, OrchestratorPhaseResult } from './types.ts';import { gbrainChildCommand } from './in-process.ts';import { releaseRunEngine } from './run-engine.ts';diff --git a/src/commands/migrations/v0_12_0.ts b/src/commands/migrations/v0_12_0.tsindex 68d353dbe3..f32f854311 100644--- a/src/commands/migrations/v0_12_0.ts+++ b/src/commands/migrations/v0_12_0.ts@@ -31,7 +31,7 @@* fix manually.*/-import { execSync } from 'child_process';+import { execSync } from '../../core/spawn.ts';import { gbrainChildCommand, runGbrainSubprocess } from './in-process.ts';import type { Migration, OrchestratorOpts, OrchestratorResult, OrchestratorPhaseResult } from './types.ts';import { childGlobalFlags } from '../../core/cli-options.ts';diff --git a/src/commands/migrations/v0_12_2.ts b/src/commands/migrations/v0_12_2.tsindex 946590aa6f..102593c07c 100644--- a/src/commands/migrations/v0_12_2.ts+++ b/src/commands/migrations/v0_12_2.ts@@ -20,7 +20,7 @@* D. Record — append completed.jsonl.*/-import { execSync } from 'child_process';+import { execSync } from '../../core/spawn.ts';import { gbrainChildCommand, runGbrainSubprocess } from './in-process.ts';import type { Migration, OrchestratorOpts, OrchestratorResult, OrchestratorPhaseResult } from './types.ts';import { childGlobalFlags } from '../../core/cli-options.ts';diff --git a/src/commands/migrations/v0_13_0.ts b/src/commands/migrations/v0_13_0.tsindex fd0f36bd7b..29c76da738 100644--- a/src/commands/migrations/v0_13_0.ts+++ b/src/commands/migrations/v0_13_0.ts@@ -25,7 +25,7 @@* not one-time schema+backfill work.*/-import { execSync } from 'child_process';+import { execSync } from '../../core/spawn.ts';import { gbrainChildCommand, runGbrainSubprocess } from './in-process.ts';import type { Migration, OrchestratorOpts, OrchestratorResult, OrchestratorPhaseResult } from './types.ts';// Bug 3 — ledger writes moved to the runner (apply-migrations.ts). Thediff --git a/src/commands/migrations/v0_32_2.ts b/src/commands/migrations/v0_32_2.tsindex f046c38417..836f5b11ca 100644--- a/src/commands/migrations/v0_32_2.ts+++ b/src/commands/migrations/v0_32_2.ts@@ -37,7 +37,7 @@*/import { existsSync, readFileSync } from 'node:fs';-import { execFileSync } from 'node:child_process';+import { execFileSync } from '../../core/spawn.ts';import type {Migration, OrchestratorOpts, OrchestratorResult, OrchestratorPhaseResult,diff --git a/src/commands/skillify-check.ts b/src/commands/skillify-check.tsindex 9ee6c4b296..ba887446ae 100644--- a/src/commands/skillify-check.ts+++ b/src/commands/skillify-check.ts@@ -25,7 +25,7 @@import { existsSync, readFileSync, readdirSync, statSync } from 'fs';import { basename, dirname, join, resolve } from 'path';-import { spawnSync } from 'child_process';+import { spawnSync } from '../core/spawn.ts';import { gbrainPath } from '../core/config.ts';import {diff --git a/src/commands/skillopt.ts b/src/commands/skillopt.tsindex f4da79badd..4421f28e52 100644--- a/src/commands/skillopt.ts+++ b/src/commands/skillopt.ts@@ -293,7 +293,7 @@ export async function runSkillOptCommand(engine: BrainEngine | null, args: strin}, { allowProtectedSubmit: true });process.stdout.write(`job_id=${job.id}\n`);if (args.includes('--follow')) {- const { spawn } = await import('child_process');+ const { spawn } = await import('../core/spawn.ts');const cmd = process.argv[0] ?? 'bun';const script = process.argv[1] ?? '';const child = spawn(cmd, [script, 'jobs', 'follow', String(job.id)], { stdio: 'inherit' });diff --git a/src/commands/skillpack-check.ts b/src/commands/skillpack-check.tsindex 7f576b0ef9..cdbd10b700 100644--- a/src/commands/skillpack-check.ts+++ b/src/commands/skillpack-check.ts@@ -16,7 +16,7 @@* 2 — Could not determine (missing binary / crashed).*/-import { execFileSync } from 'child_process';+import { execFileSync } from '../core/spawn.ts';import { VERSION } from '../version.ts';import { getCliOptions } from '../core/cli-options.ts';diff --git a/src/commands/sources.ts b/src/commands/sources.tsindex 96339ace60..ee8364ec4c 100644--- a/src/commands/sources.ts+++ b/src/commands/sources.ts@@ -1514,7 +1514,7 @@ async function runTrackedBranch(engine: BrainEngine, args: string[]): Promise<voprocess.exit(1);}try {- const { execFileSync } = await import('node:child_process');+ const { execFileSync } = await import('../core/spawn.ts');const branch = execFileSync('git', ['-C', src.local_path, 'rev-parse', '--abbrev-ref', 'HEAD'], { encoding: 'utf8' }).trim();cfg.tracked_branch = branch;await engine.executeRaw(