From b25fd03b8c37876c11ca1d37f04426938dd3935d Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 21 Feb 2026 22:47:11 +0000 Subject: [PATCH] refactor(node-host): share invoke type definitions --- src/node-host/invoke-system-run.ts | 46 ++++-------------------------- src/node-host/invoke-types.ts | 39 +++++++++++++++++++++++++ src/node-host/invoke.ts | 46 +++++------------------------- 3 files changed, 52 insertions(+), 79 deletions(-) create mode 100644 src/node-host/invoke-types.ts diff --git a/src/node-host/invoke-system-run.ts b/src/node-host/invoke-system-run.ts index 9a190b58c4a..c22a65b5120 100644 --- a/src/node-host/invoke-system-run.ts +++ b/src/node-host/invoke-system-run.ts @@ -20,46 +20,12 @@ import { import type { ExecHostRequest, ExecHostResponse, ExecHostRunResult } from "../infra/exec-host.js"; import { getTrustedSafeBinDirs } from "../infra/exec-safe-bin-trust.js"; import { resolveSystemRunCommand } from "../infra/system-run-command.js"; - -type SystemRunParams = { - command: string[]; - rawCommand?: string | null; - cwd?: string | null; - env?: Record; - timeoutMs?: number | null; - needsScreenRecording?: boolean | null; - agentId?: string | null; - sessionKey?: string | null; - approved?: boolean | null; - approvalDecision?: string | null; - runId?: string | null; -}; - -type RunResult = { - exitCode?: number; - timedOut: boolean; - success: boolean; - stdout: string; - stderr: string; - error?: string | null; - truncated: boolean; -}; - -type ExecEventPayload = { - sessionKey: string; - runId: string; - host: string; - command?: string; - exitCode?: number; - timedOut?: boolean; - success?: boolean; - output?: string; - reason?: string; -}; - -export type SkillBinsProvider = { - current(force?: boolean): Promise>; -}; +import type { + ExecEventPayload, + RunResult, + SkillBinsProvider, + SystemRunParams, +} from "./invoke-types.js"; type SystemRunInvokeResult = { ok: boolean; diff --git a/src/node-host/invoke-types.ts b/src/node-host/invoke-types.ts new file mode 100644 index 00000000000..ae41d56b961 --- /dev/null +++ b/src/node-host/invoke-types.ts @@ -0,0 +1,39 @@ +export type SystemRunParams = { + command: string[]; + rawCommand?: string | null; + cwd?: string | null; + env?: Record; + timeoutMs?: number | null; + needsScreenRecording?: boolean | null; + agentId?: string | null; + sessionKey?: string | null; + approved?: boolean | null; + approvalDecision?: string | null; + runId?: string | null; +}; + +export type RunResult = { + exitCode?: number; + timedOut: boolean; + success: boolean; + stdout: string; + stderr: string; + error?: string | null; + truncated: boolean; +}; + +export type ExecEventPayload = { + sessionKey: string; + runId: string; + host: string; + command?: string; + exitCode?: number; + timedOut?: boolean; + success?: boolean; + output?: string; + reason?: string; +}; + +export type SkillBinsProvider = { + current(force?: boolean): Promise>; +}; diff --git a/src/node-host/invoke.ts b/src/node-host/invoke.ts index 5b9ae837084..f91584d0dc4 100644 --- a/src/node-host/invoke.ts +++ b/src/node-host/invoke.ts @@ -21,6 +21,12 @@ import { import { sanitizeHostExecEnv } from "../infra/host-env-security.js"; import { runBrowserProxyCommand } from "./invoke-browser.js"; import { handleSystemRunInvoke } from "./invoke-system-run.js"; +import type { + ExecEventPayload, + RunResult, + SkillBinsProvider, + SystemRunParams, +} from "./invoke-types.js"; const OUTPUT_CAP = 200_000; const OUTPUT_EVENT_TAIL = 20_000; @@ -30,20 +36,6 @@ const execHostEnforced = process.env.OPENCLAW_NODE_EXEC_HOST?.trim().toLowerCase const execHostFallbackAllowed = process.env.OPENCLAW_NODE_EXEC_FALLBACK?.trim().toLowerCase() !== "0"; -type SystemRunParams = { - command: string[]; - rawCommand?: string | null; - cwd?: string | null; - env?: Record; - timeoutMs?: number | null; - needsScreenRecording?: boolean | null; - agentId?: string | null; - sessionKey?: string | null; - approved?: boolean | null; - approvalDecision?: string | null; - runId?: string | null; -}; - type SystemWhichParams = { bins: string[]; }; @@ -60,28 +52,6 @@ type ExecApprovalsSnapshot = { file: ExecApprovalsFile; }; -type RunResult = { - exitCode?: number; - timedOut: boolean; - success: boolean; - stdout: string; - stderr: string; - error?: string | null; - truncated: boolean; -}; - -type ExecEventPayload = { - sessionKey: string; - runId: string; - host: string; - command?: string; - exitCode?: number; - timedOut?: boolean; - success?: boolean; - output?: string; - reason?: string; -}; - export type NodeInvokeRequestPayload = { id: string; nodeId: string; @@ -91,9 +61,7 @@ export type NodeInvokeRequestPayload = { idempotencyKey?: string | null; }; -export type SkillBinsProvider = { - current(force?: boolean): Promise>; -}; +export type { SkillBinsProvider } from "./invoke-types.js"; function resolveExecSecurity(value?: string): ExecSecurity { return value === "deny" || value === "allowlist" || value === "full" ? value : "allowlist";