refactor(node-host): share invoke type definitions

This commit is contained in:
Peter Steinberger
2026-02-21 22:47:11 +00:00
parent a32edf423b
commit b25fd03b8c
3 changed files with 52 additions and 79 deletions

View File

@@ -20,46 +20,12 @@ import {
import type { ExecHostRequest, ExecHostResponse, ExecHostRunResult } from "../infra/exec-host.js"; import type { ExecHostRequest, ExecHostResponse, ExecHostRunResult } from "../infra/exec-host.js";
import { getTrustedSafeBinDirs } from "../infra/exec-safe-bin-trust.js"; import { getTrustedSafeBinDirs } from "../infra/exec-safe-bin-trust.js";
import { resolveSystemRunCommand } from "../infra/system-run-command.js"; import { resolveSystemRunCommand } from "../infra/system-run-command.js";
import type {
type SystemRunParams = { ExecEventPayload,
command: string[]; RunResult,
rawCommand?: string | null; SkillBinsProvider,
cwd?: string | null; SystemRunParams,
env?: Record<string, string>; } from "./invoke-types.js";
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<Set<string>>;
};
type SystemRunInvokeResult = { type SystemRunInvokeResult = {
ok: boolean; ok: boolean;

View File

@@ -0,0 +1,39 @@
export type SystemRunParams = {
command: string[];
rawCommand?: string | null;
cwd?: string | null;
env?: Record<string, string>;
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<Set<string>>;
};

View File

@@ -21,6 +21,12 @@ import {
import { sanitizeHostExecEnv } from "../infra/host-env-security.js"; import { sanitizeHostExecEnv } from "../infra/host-env-security.js";
import { runBrowserProxyCommand } from "./invoke-browser.js"; import { runBrowserProxyCommand } from "./invoke-browser.js";
import { handleSystemRunInvoke } from "./invoke-system-run.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_CAP = 200_000;
const OUTPUT_EVENT_TAIL = 20_000; const OUTPUT_EVENT_TAIL = 20_000;
@@ -30,20 +36,6 @@ const execHostEnforced = process.env.OPENCLAW_NODE_EXEC_HOST?.trim().toLowerCase
const execHostFallbackAllowed = const execHostFallbackAllowed =
process.env.OPENCLAW_NODE_EXEC_FALLBACK?.trim().toLowerCase() !== "0"; process.env.OPENCLAW_NODE_EXEC_FALLBACK?.trim().toLowerCase() !== "0";
type SystemRunParams = {
command: string[];
rawCommand?: string | null;
cwd?: string | null;
env?: Record<string, string>;
timeoutMs?: number | null;
needsScreenRecording?: boolean | null;
agentId?: string | null;
sessionKey?: string | null;
approved?: boolean | null;
approvalDecision?: string | null;
runId?: string | null;
};
type SystemWhichParams = { type SystemWhichParams = {
bins: string[]; bins: string[];
}; };
@@ -60,28 +52,6 @@ type ExecApprovalsSnapshot = {
file: ExecApprovalsFile; 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 = { export type NodeInvokeRequestPayload = {
id: string; id: string;
nodeId: string; nodeId: string;
@@ -91,9 +61,7 @@ export type NodeInvokeRequestPayload = {
idempotencyKey?: string | null; idempotencyKey?: string | null;
}; };
export type SkillBinsProvider = { export type { SkillBinsProvider } from "./invoke-types.js";
current(force?: boolean): Promise<Set<string>>;
};
function resolveExecSecurity(value?: string): ExecSecurity { function resolveExecSecurity(value?: string): ExecSecurity {
return value === "deny" || value === "allowlist" || value === "full" ? value : "allowlist"; return value === "deny" || value === "allowlist" || value === "full" ? value : "allowlist";