Skip to content

Commit 82abf72

Browse files
authored
fix(codex): expose selectable node exec (#104198)
* fix(codex): expose selectable node exec * chore: defer Codex node release note
1 parent 96b1be1 commit 82abf72

3 files changed

Lines changed: 159 additions & 14 deletions

File tree

‎docs/plugins/codex-harness.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ dynamic tools routed through the app-server `item/tool/call` bridge. An
2626
active OpenClaw sandbox or restricted tool policy disables native code mode
2727
entirely unless you opt into the experimental sandbox exec-server path.
2828

29+
With the default `tools.exec.host: "auto"` and no active OpenClaw sandbox,
30+
Codex also receives `node_exec` and `node_process` tools for commands on paired
31+
nodes. Native shell remains on the Codex app-server host and workspace
32+
(Gateway-local for the default stdio deployment); `node_exec` selects a node by
33+
name or id and keeps OpenClaw's node approval policy in force.
34+
2935
This Codex-native feature is separate from
3036
[OpenClaw code mode](/reference/code-mode), an opt-in QuickJS-WASI runtime
3137
for generic OpenClaw runs with a different `exec` input shape. For the

‎extensions/codex/src/app-server/dynamic-tool-build.test.ts‎

Lines changed: 128 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,128 @@ describe("Codex app-server dynamic tool build", () => {
855855
]);
856856
});
857857

858+
it("exposes selectable node shell tools beside native shell for auto host runs", async () => {
859+
const execTool = {
860+
...createRuntimeDynamicTool("exec"),
861+
parameters: {
862+
type: "object",
863+
properties: {
864+
command: { type: "string" },
865+
host: { type: "string" },
866+
security: { type: "string" },
867+
ask: { type: "string" },
868+
node: { type: "string" },
869+
},
870+
required: ["command"],
871+
additionalProperties: false,
872+
},
873+
};
874+
vi.mocked(execTool.execute).mockResolvedValueOnce({
875+
content: [{ type: "text", text: "arm64" }],
876+
details: { status: "completed" },
877+
});
878+
const processTool = createRuntimeDynamicTool("process");
879+
setOpenClawCodingToolsFactoryForTests(() => [
880+
execTool,
881+
processTool,
882+
createRuntimeDynamicTool("message"),
883+
]);
884+
const sessionFile = path.join(tempDir, "auto-node-session.jsonl");
885+
const workspaceDir = path.join(tempDir, "workspace");
886+
const params = createParams(sessionFile, workspaceDir);
887+
params.disableTools = false;
888+
params.runtimePlan = createCodexRuntimePlanFixture();
889+
890+
const tools = await buildDynamicToolsForTest(params, workspaceDir, {
891+
nativeToolSurfaceEnabled: true,
892+
});
893+
894+
expect(tools.map((tool) => tool.name)).toEqual(["message", "node_exec", "node_process"]);
895+
const nodeExec = tools.find((tool) => tool.name === "node_exec");
896+
expect(nodeExec?.description).toContain("Select the node by name or id");
897+
expect(nodeExec?.parameters).toEqual({
898+
type: "object",
899+
properties: {
900+
command: { type: "string" },
901+
node: { type: "string" },
902+
},
903+
required: ["command"],
904+
additionalProperties: false,
905+
});
906+
await nodeExec?.execute(
907+
"call-auto-node",
908+
{
909+
command: "/usr/bin/uname -m",
910+
node: "mac-mini",
911+
host: "gateway",
912+
security: "full",
913+
ask: "off",
914+
},
915+
undefined,
916+
);
917+
expect(execTool.execute).toHaveBeenCalledWith(
918+
"call-auto-node",
919+
{
920+
command: "/usr/bin/uname -m",
921+
node: "mac-mini",
922+
host: "node",
923+
},
924+
undefined,
925+
undefined,
926+
);
927+
928+
vi.mocked(execTool.execute).mockResolvedValueOnce({
929+
content: [{ type: "text", text: "arm64" }],
930+
details: { status: "completed" },
931+
});
932+
const boundAutoParams = createParams(
933+
path.join(tempDir, "bound-auto-node-session.jsonl"),
934+
workspaceDir,
935+
);
936+
boundAutoParams.disableTools = false;
937+
boundAutoParams.runtimePlan = createCodexRuntimePlanFixture();
938+
boundAutoParams.config = {
939+
tools: { exec: { host: "auto", node: "bound-mac-mini" } },
940+
} as never;
941+
const boundAutoTools = await buildDynamicToolsForTest(boundAutoParams, workspaceDir, {
942+
nativeToolSurfaceEnabled: true,
943+
});
944+
const boundNodeExec = boundAutoTools.find((tool) => tool.name === "node_exec");
945+
expect(boundNodeExec?.parameters).toEqual({
946+
type: "object",
947+
properties: { command: { type: "string" } },
948+
required: ["command"],
949+
additionalProperties: false,
950+
});
951+
await boundNodeExec?.execute(
952+
"call-bound-auto-node",
953+
{ command: "/usr/bin/uname -m", node: "other-node" },
954+
undefined,
955+
);
956+
expect(execTool.execute).toHaveBeenLastCalledWith(
957+
"call-bound-auto-node",
958+
{
959+
command: "/usr/bin/uname -m",
960+
node: "bound-mac-mini",
961+
host: "node",
962+
},
963+
undefined,
964+
undefined,
965+
);
966+
967+
const gatewayParams = createParams(
968+
path.join(tempDir, "gateway-node-session.jsonl"),
969+
workspaceDir,
970+
);
971+
gatewayParams.disableTools = false;
972+
gatewayParams.runtimePlan = createCodexRuntimePlanFixture();
973+
gatewayParams.execOverrides = { host: "gateway" };
974+
const gatewayTools = await buildDynamicToolsForTest(gatewayParams, workspaceDir, {
975+
nativeToolSurfaceEnabled: true,
976+
});
977+
expect(gatewayTools.map((tool) => tool.name)).toEqual(["message"]);
978+
});
979+
858980
it("exposes Docker sandbox shell tools when native Code Mode cannot honor sandbox paths", async () => {
859981
setOpenClawCodingToolsFactoryForTests(() => [
860982
createRuntimeDynamicTool("exec"),
@@ -882,7 +1004,7 @@ describe("Codex app-server dynamic tool build", () => {
8821004
);
8831005
});
8841006

885-
it("does not expose sandbox shell tools when sandbox routing is disabled", async () => {
1007+
it("exposes node shell but not sandbox shell tools when sandbox routing is disabled", async () => {
8861008
setOpenClawCodingToolsFactoryForTests(() => [
8871009
createRuntimeDynamicTool("exec"),
8881010
createRuntimeDynamicTool("process"),
@@ -898,7 +1020,11 @@ describe("Codex app-server dynamic tool build", () => {
8981020
sandbox: { enabled: false, backendId: "ssh" } as never,
8991021
});
9001022

901-
expect(disabledSandboxTools.map((tool) => tool.name)).toEqual(["message"]);
1023+
expect(disabledSandboxTools.map((tool) => tool.name)).toEqual([
1024+
"message",
1025+
"node_exec",
1026+
"node_process",
1027+
]);
9021028
});
9031029

9041030
it("does not expose sandbox_exec without a matching process follow-up tool", async () => {

‎extensions/codex/src/app-server/dynamic-tool-build.ts‎

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const CODEX_NATIVE_SANDBOX_TOOL_REQUIREMENTS = [
5959
const CODEX_MEMORY_FLUSH_DYNAMIC_TOOL_ALLOW = new Set(["read", "write"]);
6060
const CODEX_NODE_EXEC_DYNAMIC_TOOL_NAME = "node_exec";
6161
const CODEX_NODE_PROCESS_DYNAMIC_TOOL_NAME = "node_process";
62-
const CODEX_NODE_EXEC_HIDDEN_PARAMETER_NAMES = new Set(["host", "security", "ask", "node"]);
62+
const CODEX_NODE_EXEC_POLICY_PARAMETER_NAMES = new Set(["host", "security", "ask"]);
6363

6464
/** Runtime inputs needed to derive the exact Codex dynamic tool surface for a turn. */
6565
export type DynamicToolBuildParams = {
@@ -775,7 +775,10 @@ function addNodeShellDynamicToolsIfNeeded(
775775
if (isCodexMemoryFlushRun(input.params)) {
776776
return filteredTools;
777777
}
778-
if (nodePolicy.effectiveExecHost !== "node") {
778+
const nodeExecIsDefault = nodePolicy.effectiveExecHost === "node";
779+
const nodeExecAvailableFromAuto =
780+
nodePolicy.requestedExecHost === "auto" && nodePolicy.effectiveExecHost === "gateway";
781+
if (!nodeExecIsDefault && !nodeExecAvailableFromAuto) {
779782
return filteredTools;
780783
}
781784
const execTool = allTools.find((tool) => normalizeCodexDynamicToolName(tool.name) === "exec");
@@ -812,16 +815,20 @@ function createNodeExecDynamicTool(
812815
execTool: OpenClawDynamicTool,
813816
configuredNode: string | undefined,
814817
): OpenClawDynamicTool {
818+
const pinnedNode = configuredNode?.trim();
815819
return {
816820
...execTool,
817821
name: CODEX_NODE_EXEC_DYNAMIC_TOOL_NAME,
818-
description:
819-
"Run a shell command on the OpenClaw configured remote node for this session. This tool always uses OpenClaw host=node internally and follows the existing node exec approval and allowlist policy. Use node_process for follow-up on backgrounded node_exec sessions. Use Codex's native shell for local app-server work.",
820-
parameters: hideNodeExecDynamicToolParameters(execTool.parameters),
822+
description: pinnedNode
823+
? "Run a shell command on the OpenClaw configured remote node for this session. This tool always uses OpenClaw host=node internally and follows the existing node exec approval and allowlist policy. Use node_process for follow-up on backgrounded node_exec sessions. Use Codex's native shell for local app-server work."
824+
: "Run a shell command on an OpenClaw remote node. Select the node by name or id when multiple nodes are available. This tool always uses OpenClaw host=node internally and follows the existing node exec approval and allowlist policy. Use node_process for follow-up on backgrounded node_exec sessions. Use Codex's native shell for local app-server work.",
825+
parameters: hideNodeExecDynamicToolParameters(execTool.parameters, {
826+
hideNode: Boolean(pinnedNode),
827+
}),
821828
execute: async (toolCallId, args, signal, onUpdate) => {
822829
const result = await execTool.execute(
823830
toolCallId,
824-
pinNodeExecDynamicToolArgs(args, configuredNode),
831+
pinNodeExecDynamicToolArgs(args, pinnedNode),
825832
signal,
826833
onUpdate,
827834
);
@@ -847,7 +854,7 @@ function createNodeProcessDynamicTool(processTool: OpenClawDynamicTool): OpenCla
847854
...processTool,
848855
name: CODEX_NODE_PROCESS_DYNAMIC_TOOL_NAME,
849856
description:
850-
"Manage node_exec sessions that were started on the OpenClaw configured remote node for this session: list, poll, log, write, send-keys, submit, paste, kill, clear, or remove. Use only for node_exec follow-up; use Codex's native shell session handling for local app-server work.",
857+
"Manage node_exec sessions that were started on OpenClaw remote nodes: list, poll, log, write, send-keys, submit, paste, kill, clear, or remove. Use only for node_exec follow-up; use Codex's native shell session handling for local app-server work.",
851858
};
852859
}
853860

@@ -856,16 +863,19 @@ function pinNodeExecDynamicToolArgs(args: unknown, configuredNode: string | unde
856863
args && typeof args === "object" && !Array.isArray(args)
857864
? (args as Record<string, unknown>)
858865
: {};
859-
const { host: _host, security: _security, ask: _ask, node: _node, ...rest } = source;
860-
const node = configuredNode?.trim();
866+
const { host: _host, security: _security, ask: _ask, node: requestedNode, ...rest } = source;
867+
const node = configuredNode ?? (typeof requestedNode === "string" ? requestedNode.trim() : "");
861868
return {
862869
...rest,
863870
host: "node",
864871
...(node ? { node } : {}),
865872
};
866873
}
867874

868-
function hideNodeExecDynamicToolParameters(parameters: OpenClawDynamicTool["parameters"]) {
875+
function hideNodeExecDynamicToolParameters(
876+
parameters: OpenClawDynamicTool["parameters"],
877+
options: { hideNode: boolean },
878+
) {
869879
if (!parameters || typeof parameters !== "object" || Array.isArray(parameters)) {
870880
return parameters;
871881
}
@@ -876,15 +886,18 @@ function hideNodeExecDynamicToolParameters(parameters: OpenClawDynamicTool["para
876886
}
877887
const nextProperties = Object.fromEntries(
878888
Object.entries(rawProperties).filter(
879-
([name]) => !CODEX_NODE_EXEC_HIDDEN_PARAMETER_NAMES.has(normalizeCodexDynamicToolName(name)),
889+
([name]) =>
890+
!CODEX_NODE_EXEC_POLICY_PARAMETER_NAMES.has(normalizeCodexDynamicToolName(name)) &&
891+
!(options.hideNode && normalizeCodexDynamicToolName(name) === "node"),
880892
),
881893
);
882894
const rawRequired = schema.required;
883895
const nextRequired = Array.isArray(rawRequired)
884896
? rawRequired.filter(
885897
(name) =>
886898
typeof name !== "string" ||
887-
!CODEX_NODE_EXEC_HIDDEN_PARAMETER_NAMES.has(normalizeCodexDynamicToolName(name)),
899+
(!CODEX_NODE_EXEC_POLICY_PARAMETER_NAMES.has(normalizeCodexDynamicToolName(name)) &&
900+
!(options.hideNode && normalizeCodexDynamicToolName(name) === "node")),
888901
)
889902
: rawRequired;
890903
return {

0 commit comments

Comments
 (0)