@openclaw/codex 2026.5.7 → 2026.5.10-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { i as resolveCodexAppServerRuntimeOptions } from "./config-ByrA30No.js";
1
+ import { s as resolveCodexAppServerRuntimeOptions } from "./config-CT01BBDc.js";
2
2
  import { n as isRpcResponse } from "./protocol-C9UWI98H.js";
3
3
  import { createInterface } from "node:readline";
4
4
  import { OPENCLAW_VERSION, embeddedAgentLog } from "openclaw/plugin-sdk/agent-harness-runtime";
@@ -139,18 +139,19 @@ function websocketFrameToText(data) {
139
139
  //#endregion
140
140
  //#region extensions/codex/src/app-server/transport.ts
141
141
  function closeCodexAppServerTransport(child, options = {}) {
142
- child.stdout.destroy?.();
143
- child.stderr.destroy?.();
144
142
  child.stdin.end?.();
145
143
  child.stdin.destroy?.();
146
- signalCodexAppServerTransport(child, "SIGTERM");
147
144
  const forceKillDelayMs = options.forceKillDelayMs ?? 1e3;
148
145
  const forceKill = setTimeout(() => {
149
146
  if (hasCodexAppServerTransportExited(child)) return;
150
147
  signalCodexAppServerTransport(child, "SIGKILL");
151
148
  }, Math.max(1, forceKillDelayMs));
152
149
  forceKill.unref?.();
153
- child.once("exit", () => clearTimeout(forceKill));
150
+ child.once("exit", () => {
151
+ clearTimeout(forceKill);
152
+ child.stdout.destroy?.();
153
+ child.stderr.destroy?.();
154
+ });
154
155
  child.unref?.();
155
156
  child.stdout.unref?.();
156
157
  child.stderr.unref?.();
@@ -179,7 +180,6 @@ async function waitForCodexAppServerTransportExit(child, timeoutMs) {
179
180
  child.off?.("exit", onExit);
180
181
  resolve(false);
181
182
  }, Math.max(1, timeoutMs));
182
- timeout.unref?.();
183
183
  child.once("exit", onExit);
184
184
  });
185
185
  }
@@ -199,7 +199,7 @@ const MANAGED_CODEX_APP_SERVER_PACKAGE = "@openai/codex";
199
199
  const CODEX_APP_SERVER_PARSE_LOG_MAX = 500;
200
200
  const CODEX_APP_SERVER_PARSE_BUFFER_MAX = 1e6;
201
201
  const CODEX_APP_SERVER_PARSE_BUFFER_MAX_LINES = 1e3;
202
- const CODEX_DYNAMIC_TOOL_SERVER_REQUEST_TIMEOUT_MS = 3e4;
202
+ const CODEX_DYNAMIC_TOOL_SERVER_REQUEST_TIMEOUT_MS = 6e5;
203
203
  const CODEX_APP_SERVER_STDERR_TAIL_MAX = 2e3;
204
204
  var CodexAppServerRpcError = class extends Error {
205
205
  constructor(error, method) {
@@ -1,5 +1,5 @@
1
1
  //#region extensions/codex/src/app-server/client-factory.ts
2
- const defaultCodexAppServerClientFactory = (startOptions, authProfileId, agentDir, config) => import("./shared-client-Dfk3Enm-.js").then((n) => n.r).then(({ getSharedCodexAppServerClient }) => getSharedCodexAppServerClient({
2
+ const defaultCodexAppServerClientFactory = (startOptions, authProfileId, agentDir, config) => import("./shared-client-p-TvEiNL.js").then((n) => n.r).then(({ getSharedCodexAppServerClient }) => getSharedCodexAppServerClient({
3
3
  startOptions,
4
4
  authProfileId,
5
5
  agentDir,
@@ -1,10 +1,10 @@
1
- import { i as resolveCodexAppServerRuntimeOptions } from "./config-ByrA30No.js";
2
- import { n as listCodexAppServerModels, t as listAllCodexAppServerModels } from "./models-CkowdYbm.js";
1
+ import { i as isCodexFastServiceTier, s as resolveCodexAppServerRuntimeOptions } from "./config-CT01BBDc.js";
2
+ import { n as listCodexAppServerModels, t as listAllCodexAppServerModels } from "./models-OtCFiaj_.js";
3
3
  import { t as isJsonObject } from "./protocol-C9UWI98H.js";
4
- import { a as formatComputerUseStatus, c as formatThreads, d as CODEX_CONTROL_METHODS, f as describeControlFailure, i as formatCodexStatus, l as readString, n as formatAccount, o as formatList, r as formatCodexDisplayText, s as formatModels, t as buildHelp } from "./command-formatters-PiJcdUbu.js";
5
- import { i as readCodexAppServerBinding, o as writeCodexAppServerBinding, t as clearCodexAppServerBinding } from "./session-binding-DuJYTJQy.js";
6
- import { a as parseCodexFastModeArg, c as setCodexConversationFastMode, d as steerCodexConversationTurn, f as stopCodexConversationTurn, i as formatPermissionsMode, l as setCodexConversationModel, m as resolveCodexDefaultWorkspaceDir, o as parseCodexPermissionsModeArg, p as readCodexConversationBindingData, r as startCodexConversationThread, s as readCodexConversationActiveTurn, u as setCodexConversationPermissions } from "./conversation-binding-CtHkMJfG.js";
7
- import { a as readCodexComputerUseStatus, i as installCodexComputerUse, n as rememberCodexRateLimits, o as requestCodexAppServerJson } from "./rate-limit-cache-t6ebYmfS.js";
4
+ import { a as formatCodexStatus, c as formatModels, f as CODEX_CONTROL_METHODS, i as formatCodexDisplayText, l as formatThreads, n as buildHelp, o as formatComputerUseStatus, p as describeControlFailure, r as formatAccount, s as formatList, t as requestCodexAppServerJson, u as readString } from "./request-DC1Dz3iZ.js";
5
+ import { i as readCodexAppServerBinding, o as writeCodexAppServerBinding, t as clearCodexAppServerBinding } from "./session-binding-B44KIZM2.js";
6
+ import { a as parseCodexFastModeArg, c as setCodexConversationFastMode, d as steerCodexConversationTurn, f as stopCodexConversationTurn, i as formatPermissionsMode, l as setCodexConversationModel, m as resolveCodexDefaultWorkspaceDir, o as parseCodexPermissionsModeArg, p as readCodexConversationBindingData, r as startCodexConversationThread, s as readCodexConversationActiveTurn, u as setCodexConversationPermissions } from "./conversation-binding-FqeYliIk.js";
7
+ import { a as readCodexComputerUseStatus, i as installCodexComputerUse, n as rememberCodexRateLimits } from "./rate-limit-cache-DbZvmrAD.js";
8
8
  import crypto from "node:crypto";
9
9
  //#region extensions/codex/src/command-rpc.ts
10
10
  function requestOptions(pluginConfig, limit, config) {
@@ -217,7 +217,7 @@ async function describeConversationBinding(deps, ctx) {
217
217
  `- Thread: ${formatCodexDisplayText(threadBinding?.threadId ?? "unknown")}`,
218
218
  `- Workspace: ${formatCodexDisplayText(data.workspaceDir)}`,
219
219
  `- Model: ${formatCodexDisplayText(threadBinding?.model ?? "default")}`,
220
- `- Fast: ${threadBinding?.serviceTier === "fast" ? "on" : "off"}`,
220
+ `- Fast: ${isCodexFastServiceTier(threadBinding?.serviceTier) ? "on" : "off"}`,
221
221
  `- Permissions: ${threadBinding ? formatPermissionsMode(threadBinding) : "default"}`,
222
222
  `- Active run: ${formatCodexDisplayText(active ? active.turnId : "none")}`,
223
223
  `- Session: ${formatCodexDisplayText(data.sessionFile)}`
@@ -1,7 +1,7 @@
1
- import { i as resolveCodexAppServerRuntimeOptions } from "./config-ByrA30No.js";
1
+ import { s as resolveCodexAppServerRuntimeOptions } from "./config-CT01BBDc.js";
2
2
  import { t as isJsonObject } from "./protocol-C9UWI98H.js";
3
- import { i as readCodexAppServerBinding } from "./session-binding-DuJYTJQy.js";
4
- import { n as defaultCodexAppServerClientFactory, t as createCodexAppServerClientFactoryTestHooks } from "./client-factory--cll1Fba.js";
3
+ import { i as readCodexAppServerBinding } from "./session-binding-B44KIZM2.js";
4
+ import { n as defaultCodexAppServerClientFactory, t as createCodexAppServerClientFactoryTestHooks } from "./client-factory-BJL_efz4.js";
5
5
  import { embeddedAgentLog, formatErrorMessage, isActiveHarnessContextEngine, runHarnessContextEngineMaintenance } from "openclaw/plugin-sdk/agent-harness-runtime";
6
6
  //#region extensions/codex/src/app-server/compact.ts
7
7
  const DEFAULT_CODEX_COMPACTION_WAIT_TIMEOUT_MS = 300 * 1e3;
@@ -0,0 +1,496 @@
1
+ import { createHmac, randomBytes } from "node:crypto";
2
+ import { readFileSync } from "node:fs";
3
+ import { hostname } from "node:os";
4
+ import { z } from "openclaw/plugin-sdk/zod";
5
+ //#region extensions/codex/src/app-server/config.ts
6
+ const START_OPTIONS_KEY_SECRET = randomBytes(32);
7
+ const UNIX_CODEX_REQUIREMENTS_PATH = "/etc/codex/requirements.toml";
8
+ const WINDOWS_CODEX_REQUIREMENTS_SUFFIX = "\\OpenAI\\Codex\\requirements.toml";
9
+ const CODEX_PLUGINS_MARKETPLACE_NAME = "openai-curated";
10
+ const DEFAULT_CODEX_COMPUTER_USE_PLUGIN_NAME = "computer-use";
11
+ const DEFAULT_CODEX_COMPUTER_USE_MCP_SERVER_NAME = "computer-use";
12
+ const DEFAULT_CODEX_COMPUTER_USE_MARKETPLACE_DISCOVERY_TIMEOUT_MS = 6e4;
13
+ const codexAppServerTransportSchema = z.enum(["stdio", "websocket"]);
14
+ const codexAppServerPolicyModeSchema = z.enum(["yolo", "guardian"]);
15
+ const codexAppServerApprovalPolicySchema = z.enum([
16
+ "never",
17
+ "on-request",
18
+ "on-failure",
19
+ "untrusted"
20
+ ]);
21
+ const codexAppServerSandboxSchema = z.enum([
22
+ "read-only",
23
+ "workspace-write",
24
+ "danger-full-access"
25
+ ]);
26
+ const codexAppServerApprovalsReviewerSchema = z.enum([
27
+ "user",
28
+ "auto_review",
29
+ "guardian_subagent"
30
+ ]);
31
+ const codexDynamicToolsLoadingSchema = z.enum(["searchable", "direct"]);
32
+ const codexAppServerServiceTierSchema = z.preprocess((value) => value === null ? null : normalizeCodexServiceTier(value), z.string().trim().min(1).nullable().optional()).optional();
33
+ const codexPluginEntryConfigSchema = z.object({
34
+ enabled: z.boolean().optional(),
35
+ marketplaceName: z.literal(CODEX_PLUGINS_MARKETPLACE_NAME).optional(),
36
+ pluginName: z.string().trim().min(1).optional(),
37
+ allow_destructive_actions: z.boolean().optional()
38
+ }).strict();
39
+ const codexPluginsConfigSchema = z.object({
40
+ enabled: z.boolean().optional(),
41
+ allow_destructive_actions: z.boolean().optional(),
42
+ plugins: z.record(z.string(), codexPluginEntryConfigSchema).optional()
43
+ }).strict();
44
+ const codexPluginConfigSchema = z.object({
45
+ codexDynamicToolsLoading: codexDynamicToolsLoadingSchema.optional(),
46
+ codexDynamicToolsExclude: z.array(z.string()).optional(),
47
+ discovery: z.object({
48
+ enabled: z.boolean().optional(),
49
+ timeoutMs: z.number().positive().optional()
50
+ }).strict().optional(),
51
+ computerUse: z.object({
52
+ enabled: z.boolean().optional(),
53
+ autoInstall: z.boolean().optional(),
54
+ marketplaceDiscoveryTimeoutMs: z.number().positive().optional(),
55
+ marketplaceSource: z.string().optional(),
56
+ marketplacePath: z.string().optional(),
57
+ marketplaceName: z.string().optional(),
58
+ pluginName: z.string().optional(),
59
+ mcpServerName: z.string().optional()
60
+ }).strict().optional(),
61
+ codexPlugins: z.unknown().optional(),
62
+ appServer: z.object({
63
+ mode: codexAppServerPolicyModeSchema.optional(),
64
+ transport: codexAppServerTransportSchema.optional(),
65
+ command: z.string().optional(),
66
+ args: z.union([z.array(z.string()), z.string()]).optional(),
67
+ url: z.string().optional(),
68
+ authToken: z.string().optional(),
69
+ headers: z.record(z.string(), z.string()).optional(),
70
+ clearEnv: z.array(z.string()).optional(),
71
+ requestTimeoutMs: z.number().positive().optional(),
72
+ turnCompletionIdleTimeoutMs: z.number().positive().optional(),
73
+ approvalPolicy: codexAppServerApprovalPolicySchema.optional(),
74
+ sandbox: codexAppServerSandboxSchema.optional(),
75
+ approvalsReviewer: codexAppServerApprovalsReviewerSchema.optional(),
76
+ serviceTier: codexAppServerServiceTierSchema,
77
+ defaultWorkspaceDir: z.string().optional()
78
+ }).strict().optional()
79
+ }).strict();
80
+ function readCodexPluginConfig(value) {
81
+ const parsed = codexPluginConfigSchema.safeParse(value);
82
+ if (!parsed.success) return {};
83
+ const { codexPlugins: rawCodexPlugins, ...config } = parsed.data;
84
+ const plugins = codexPluginsConfigSchema.safeParse(rawCodexPlugins);
85
+ if (!plugins.success) return config;
86
+ return {
87
+ ...config,
88
+ ...plugins.data ? { codexPlugins: plugins.data } : {}
89
+ };
90
+ }
91
+ function resolveCodexPluginsPolicy(pluginConfig) {
92
+ const config = readCodexPluginConfig(pluginConfig).codexPlugins;
93
+ const configured = config !== void 0;
94
+ const enabled = config?.enabled === true;
95
+ const allowDestructiveActions = config?.allow_destructive_actions ?? false;
96
+ return {
97
+ configured,
98
+ enabled,
99
+ allowDestructiveActions,
100
+ pluginPolicies: Object.entries(config?.plugins ?? {}).flatMap(([configKey, entry]) => {
101
+ if (entry.marketplaceName !== "openai-curated" || !entry.pluginName) return [];
102
+ return [{
103
+ configKey,
104
+ marketplaceName: CODEX_PLUGINS_MARKETPLACE_NAME,
105
+ pluginName: entry.pluginName,
106
+ enabled: enabled && entry.enabled !== false,
107
+ allowDestructiveActions: entry.allow_destructive_actions ?? allowDestructiveActions
108
+ }];
109
+ }).toSorted((left, right) => left.configKey.localeCompare(right.configKey))
110
+ };
111
+ }
112
+ function resolveCodexAppServerRuntimeOptions(params = {}) {
113
+ const env = params.env ?? process.env;
114
+ const config = readCodexPluginConfig(params.pluginConfig).appServer ?? {};
115
+ const transport = resolveTransport(config.transport);
116
+ const configCommand = readNonEmptyString(config.command);
117
+ const envCommand = readNonEmptyString(env.OPENCLAW_CODEX_APP_SERVER_BIN);
118
+ const command = configCommand ?? envCommand ?? "codex";
119
+ const commandSource = configCommand ? "config" : envCommand ? "env" : "managed";
120
+ const args = resolveArgs(config.args, env.OPENCLAW_CODEX_APP_SERVER_ARGS);
121
+ const headers = normalizeHeaders(config.headers);
122
+ const clearEnv = normalizeStringList(config.clearEnv);
123
+ const authToken = readNonEmptyString(config.authToken);
124
+ const url = readNonEmptyString(config.url);
125
+ const explicitPolicyMode = resolvePolicyMode(config.mode) ?? resolvePolicyMode(env.OPENCLAW_CODEX_APP_SERVER_MODE);
126
+ const defaultPolicy = explicitPolicyMode ? void 0 : resolveDefaultCodexAppServerPolicy({
127
+ transport,
128
+ env,
129
+ requirementsToml: params.requirementsToml,
130
+ requirementsPath: params.requirementsPath,
131
+ readRequirementsFile: params.readRequirementsFile,
132
+ platform: params.platform,
133
+ hostName: params.hostName
134
+ });
135
+ const policyMode = explicitPolicyMode ?? defaultPolicy?.mode ?? "yolo";
136
+ const serviceTier = normalizeCodexServiceTier(config.serviceTier);
137
+ if (transport === "websocket" && !url) throw new Error("plugins.entries.codex.config.appServer.url is required when appServer.transport is websocket");
138
+ return {
139
+ start: {
140
+ transport,
141
+ command,
142
+ commandSource,
143
+ args: args.length > 0 ? args : [
144
+ "app-server",
145
+ "--listen",
146
+ "stdio://"
147
+ ],
148
+ ...url ? { url } : {},
149
+ ...authToken ? { authToken } : {},
150
+ headers,
151
+ ...transport === "stdio" && clearEnv.length > 0 ? { clearEnv } : {}
152
+ },
153
+ requestTimeoutMs: normalizePositiveNumber(config.requestTimeoutMs, 6e4),
154
+ turnCompletionIdleTimeoutMs: normalizePositiveNumber(config.turnCompletionIdleTimeoutMs, 6e4),
155
+ approvalPolicy: resolveApprovalPolicy(config.approvalPolicy) ?? resolveApprovalPolicy(env.OPENCLAW_CODEX_APP_SERVER_APPROVAL_POLICY) ?? defaultPolicy?.approvalPolicy ?? (policyMode === "guardian" ? "on-request" : "never"),
156
+ sandbox: resolveSandbox(config.sandbox) ?? resolveSandbox(env.OPENCLAW_CODEX_APP_SERVER_SANDBOX) ?? defaultPolicy?.sandbox ?? (policyMode === "guardian" ? "workspace-write" : "danger-full-access"),
157
+ approvalsReviewer: resolveApprovalsReviewer(config.approvalsReviewer) ?? defaultPolicy?.approvalsReviewer ?? (policyMode === "guardian" ? "auto_review" : "user"),
158
+ ...serviceTier ? { serviceTier } : {}
159
+ };
160
+ }
161
+ function resolveCodexComputerUseConfig(params = {}) {
162
+ const env = params.env ?? process.env;
163
+ const config = readCodexPluginConfig(params.pluginConfig).computerUse ?? {};
164
+ const marketplaceSource = readNonEmptyString(params.overrides?.marketplaceSource) ?? readNonEmptyString(config.marketplaceSource) ?? readNonEmptyString(env.OPENCLAW_CODEX_COMPUTER_USE_MARKETPLACE_SOURCE);
165
+ const marketplacePath = readNonEmptyString(params.overrides?.marketplacePath) ?? readNonEmptyString(config.marketplacePath) ?? readNonEmptyString(env.OPENCLAW_CODEX_COMPUTER_USE_MARKETPLACE_PATH);
166
+ const marketplaceName = readNonEmptyString(params.overrides?.marketplaceName) ?? readNonEmptyString(config.marketplaceName) ?? readNonEmptyString(env.OPENCLAW_CODEX_COMPUTER_USE_MARKETPLACE_NAME);
167
+ const autoInstall = params.overrides?.autoInstall ?? config.autoInstall ?? readBooleanEnv(env.OPENCLAW_CODEX_COMPUTER_USE_AUTO_INSTALL) ?? false;
168
+ const marketplaceDiscoveryTimeoutMs = normalizePositiveNumber(params.overrides?.marketplaceDiscoveryTimeoutMs ?? config.marketplaceDiscoveryTimeoutMs ?? readNumberEnv(env.OPENCLAW_CODEX_COMPUTER_USE_MARKETPLACE_DISCOVERY_TIMEOUT_MS), DEFAULT_CODEX_COMPUTER_USE_MARKETPLACE_DISCOVERY_TIMEOUT_MS);
169
+ return {
170
+ enabled: params.overrides?.enabled ?? config.enabled ?? readBooleanEnv(env.OPENCLAW_CODEX_COMPUTER_USE) ?? Boolean(autoInstall || marketplaceSource || marketplacePath || marketplaceName),
171
+ autoInstall,
172
+ marketplaceDiscoveryTimeoutMs,
173
+ pluginName: readNonEmptyString(params.overrides?.pluginName) ?? readNonEmptyString(config.pluginName) ?? readNonEmptyString(env.OPENCLAW_CODEX_COMPUTER_USE_PLUGIN_NAME) ?? DEFAULT_CODEX_COMPUTER_USE_PLUGIN_NAME,
174
+ mcpServerName: readNonEmptyString(params.overrides?.mcpServerName) ?? readNonEmptyString(config.mcpServerName) ?? readNonEmptyString(env.OPENCLAW_CODEX_COMPUTER_USE_MCP_SERVER_NAME) ?? DEFAULT_CODEX_COMPUTER_USE_MCP_SERVER_NAME,
175
+ ...marketplaceSource ? { marketplaceSource } : {},
176
+ ...marketplacePath ? { marketplacePath } : {},
177
+ ...marketplaceName ? { marketplaceName } : {}
178
+ };
179
+ }
180
+ function codexAppServerStartOptionsKey(options, params = {}) {
181
+ return JSON.stringify({
182
+ transport: options.transport,
183
+ command: options.command,
184
+ commandSource: options.commandSource ?? null,
185
+ args: options.args,
186
+ url: options.url ?? null,
187
+ authToken: hashSecretForKey(options.authToken, "authToken"),
188
+ headers: Object.entries(options.headers).toSorted(([left], [right]) => left.localeCompare(right)),
189
+ env: Object.entries(options.env ?? {}).toSorted(([left], [right]) => left.localeCompare(right)).map(([key, value]) => [key, hashSecretForKey(value, `env:${key}`)]),
190
+ clearEnv: [...options.clearEnv ?? []].toSorted(),
191
+ authProfileId: params.authProfileId ?? null,
192
+ agentDir: params.agentDir ?? null
193
+ });
194
+ }
195
+ function codexSandboxPolicyForTurn(mode, cwd) {
196
+ if (mode === "danger-full-access") return { type: "dangerFullAccess" };
197
+ if (mode === "read-only") return {
198
+ type: "readOnly",
199
+ networkAccess: false
200
+ };
201
+ return {
202
+ type: "workspaceWrite",
203
+ writableRoots: [cwd],
204
+ networkAccess: false,
205
+ excludeTmpdirEnvVar: false,
206
+ excludeSlashTmp: false
207
+ };
208
+ }
209
+ function withMcpElicitationsApprovalPolicy(policy) {
210
+ if (typeof policy !== "string") return { granular: {
211
+ ...policy.granular,
212
+ mcp_elicitations: true
213
+ } };
214
+ if (policy === "never") return { granular: {
215
+ mcp_elicitations: true,
216
+ rules: false,
217
+ sandbox_approval: false
218
+ } };
219
+ return { granular: {
220
+ mcp_elicitations: true,
221
+ rules: true,
222
+ sandbox_approval: true
223
+ } };
224
+ }
225
+ function resolveTransport(value) {
226
+ return value === "websocket" ? "websocket" : "stdio";
227
+ }
228
+ function resolvePolicyMode(value) {
229
+ return value === "guardian" || value === "yolo" ? value : void 0;
230
+ }
231
+ function resolveDefaultCodexAppServerPolicy(params) {
232
+ if (params.transport !== "stdio") return { mode: "yolo" };
233
+ const content = readCodexRequirementsToml(params);
234
+ if (content === void 0) return { mode: "yolo" };
235
+ const allowedSandboxModes = parseAllowedSandboxModesFromCodexRequirements(content, readNonEmptyString(params.hostName) ?? hostname());
236
+ const allowedApprovalPolicies = parseAllowedApprovalPoliciesFromCodexRequirements(content);
237
+ const allowedApprovalsReviewers = parseAllowedApprovalsReviewersFromCodexRequirements(content);
238
+ const yoloSandboxAllowed = allowedSandboxModes === void 0 || allowedSandboxModes.has("danger-full-access");
239
+ const yoloApprovalAllowed = allowedApprovalPolicies === void 0 || allowedApprovalPolicies.has("never");
240
+ const yoloReviewerAllowed = allowedApprovalsReviewers === void 0 || allowedApprovalsReviewers.has("user");
241
+ if (yoloSandboxAllowed && yoloApprovalAllowed && yoloReviewerAllowed) return { mode: "yolo" };
242
+ return {
243
+ mode: "guardian",
244
+ approvalPolicy: selectGuardianApprovalPolicy(allowedApprovalPolicies),
245
+ approvalsReviewer: selectGuardianApprovalsReviewer(allowedApprovalsReviewers),
246
+ sandbox: selectGuardianSandbox(allowedSandboxModes)
247
+ };
248
+ }
249
+ function readCodexRequirementsToml(params) {
250
+ if (params.requirementsToml !== void 0) return params.requirementsToml ?? void 0;
251
+ const path = readNonEmptyString(params.requirementsPath) ?? resolveCodexRequirementsPath(params.env ?? process.env, params.platform ?? process.platform);
252
+ try {
253
+ if (params.readRequirementsFile) return params.readRequirementsFile(path);
254
+ return readFileSync(path, "utf8");
255
+ } catch {
256
+ return;
257
+ }
258
+ }
259
+ function resolveCodexRequirementsPath(env, platform) {
260
+ if (platform === "win32") return `${(readNonEmptyString(env.ProgramData) ?? "C:\\ProgramData").replace(/[\\/]+$/, "")}${WINDOWS_CODEX_REQUIREMENTS_SUFFIX}`;
261
+ return UNIX_CODEX_REQUIREMENTS_PATH;
262
+ }
263
+ function parseAllowedSandboxModesFromCodexRequirements(content, hostName) {
264
+ const remoteSandboxModes = parseMatchingRemoteSandboxModesFromCodexRequirements(content, hostName);
265
+ if (remoteSandboxModes !== void 0) return remoteSandboxModes;
266
+ return parseRequirementsSandboxModes(parseTopLevelRequirementsStringArray(content, "allowed_sandbox_modes"));
267
+ }
268
+ function parseAllowedApprovalPoliciesFromCodexRequirements(content) {
269
+ const values = parseTopLevelRequirementsStringArray(content, "allowed_approval_policies");
270
+ if (values === void 0) return;
271
+ const normalizedPolicies = values.map((entry) => normalizeRequirementsApprovalPolicy(entry)).filter((entry) => entry !== void 0);
272
+ return normalizedPolicies.length > 0 ? new Set(normalizedPolicies) : void 0;
273
+ }
274
+ function parseAllowedApprovalsReviewersFromCodexRequirements(content) {
275
+ const values = parseTopLevelRequirementsStringArray(content, "allowed_approvals_reviewers");
276
+ if (values === void 0) return;
277
+ const normalizedReviewers = values.map((entry) => normalizeRequirementsApprovalsReviewer(entry)).filter((entry) => entry !== void 0);
278
+ return normalizedReviewers.length > 0 ? new Set(normalizedReviewers) : void 0;
279
+ }
280
+ function parseMatchingRemoteSandboxModesFromCodexRequirements(content, hostName) {
281
+ const normalizedHostName = normalizeRequirementsHostName(hostName);
282
+ if (normalizedHostName === void 0) return;
283
+ for (const section of parseTomlArrayTableSections(content, "remote_sandbox_config")) {
284
+ const patterns = parseRequirementsStringArray(section, "hostname_patterns");
285
+ if (!patterns || !requirementsHostNameMatchesAnyPattern(normalizedHostName, patterns)) continue;
286
+ return parseRequirementsSandboxModes(parseRequirementsStringArray(section, "allowed_sandbox_modes"));
287
+ }
288
+ }
289
+ function parseRequirementsSandboxModes(values) {
290
+ if (values === void 0) return;
291
+ const normalizedModes = values.map((entry) => normalizeRequirementsSandboxMode(entry)).filter((entry) => entry !== void 0);
292
+ return normalizedModes.length > 0 ? new Set(normalizedModes) : void 0;
293
+ }
294
+ function parseTopLevelRequirementsStringArray(content, key) {
295
+ return parseRequirementsStringArray(stripTomlLineComments(content).slice(0, firstTomlTableOffset(content)), key);
296
+ }
297
+ function parseRequirementsStringArray(content, key) {
298
+ const match = content.match(new RegExp(`(?:^|\\n)\\s*${key}\\s*=\\s*\\[([\\s\\S]*?)\\]`));
299
+ if (!match) return;
300
+ const arrayBody = match[1] ?? "";
301
+ const stringMatches = [...arrayBody.matchAll(/"([^"\\]*(?:\\.[^"\\]*)*)"|'([^']*)'/g)];
302
+ if (stringMatches.length === 0 && arrayBody.trim().length > 0) return;
303
+ return stringMatches.map((entry) => entry[1] ?? entry[2] ?? "");
304
+ }
305
+ function parseTomlArrayTableSections(content, table) {
306
+ const strippedContent = stripTomlLineComments(content);
307
+ const escapedTable = table.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
308
+ const headerPattern = new RegExp(`^\\s*\\[\\[\\s*${escapedTable}\\s*\\]\\]\\s*$`, "gm");
309
+ const sections = [];
310
+ for (let match = headerPattern.exec(strippedContent); match; match = headerPattern.exec(strippedContent)) {
311
+ const sectionStart = headerPattern.lastIndex;
312
+ const rest = strippedContent.slice(sectionStart);
313
+ const nextTableOffset = rest.search(/^\s*\[/m);
314
+ sections.push(nextTableOffset === -1 ? rest : rest.slice(0, nextTableOffset));
315
+ }
316
+ return sections;
317
+ }
318
+ function firstTomlTableOffset(content) {
319
+ return content.match(/^\s*\[[^\]\n]/m)?.index ?? content.length;
320
+ }
321
+ function stripTomlLineComments(value) {
322
+ let output = "";
323
+ let quote;
324
+ let escaped = false;
325
+ for (let index = 0; index < value.length; index += 1) {
326
+ const char = value[index] ?? "";
327
+ if (quote) {
328
+ output += char;
329
+ if (quote === "\"" && escaped) {
330
+ escaped = false;
331
+ continue;
332
+ }
333
+ if (quote === "\"" && char === "\\") {
334
+ escaped = true;
335
+ continue;
336
+ }
337
+ if (char === quote) quote = void 0;
338
+ continue;
339
+ }
340
+ if (char === "\"" || char === "'") {
341
+ quote = char;
342
+ output += char;
343
+ continue;
344
+ }
345
+ if (char === "#") {
346
+ while (index < value.length && value[index] !== "\n") index += 1;
347
+ if (value[index] === "\n") output += "\n";
348
+ continue;
349
+ }
350
+ output += char;
351
+ }
352
+ return output;
353
+ }
354
+ function normalizeRequirementsSandboxMode(value) {
355
+ const compact = value.replace(/[\s_-]/g, "").toLowerCase();
356
+ if (compact === "readonly") return "read-only";
357
+ if (compact === "workspacewrite") return "workspace-write";
358
+ if (compact === "dangerfullaccess") return "danger-full-access";
359
+ }
360
+ function normalizeRequirementsHostName(value) {
361
+ const normalized = value.trim().replace(/\.+$/g, "").toLowerCase();
362
+ return normalized.length > 0 ? normalized : void 0;
363
+ }
364
+ function requirementsHostNameMatchesAnyPattern(hostName, patterns) {
365
+ return patterns.some((pattern) => {
366
+ const normalizedPattern = normalizeRequirementsHostName(pattern);
367
+ return normalizedPattern !== void 0 && globPatternMatches(hostName, normalizedPattern);
368
+ });
369
+ }
370
+ function globPatternMatches(value, pattern) {
371
+ let regex = "^";
372
+ for (const char of pattern) if (char === "*") regex += ".*";
373
+ else if (char === "?") regex += ".";
374
+ else regex += char.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
375
+ regex += "$";
376
+ return new RegExp(regex).test(value);
377
+ }
378
+ function normalizeRequirementsApprovalPolicy(value) {
379
+ return resolveApprovalPolicy(value.trim().toLowerCase());
380
+ }
381
+ function normalizeRequirementsApprovalsReviewer(value) {
382
+ return resolveApprovalsReviewer(value.trim().toLowerCase());
383
+ }
384
+ function selectGuardianApprovalPolicy(allowedApprovalPolicies) {
385
+ if (allowedApprovalPolicies === void 0 || allowedApprovalPolicies.has("on-request")) return "on-request";
386
+ if (allowedApprovalPolicies.has("on-failure")) return "on-failure";
387
+ if (allowedApprovalPolicies.has("untrusted")) return "untrusted";
388
+ if (allowedApprovalPolicies.has("never")) return "never";
389
+ return "on-request";
390
+ }
391
+ function selectGuardianApprovalsReviewer(allowedApprovalsReviewers) {
392
+ if (allowedApprovalsReviewers === void 0 || allowedApprovalsReviewers.has("auto_review")) return "auto_review";
393
+ if (allowedApprovalsReviewers.has("guardian_subagent")) return "guardian_subagent";
394
+ if (allowedApprovalsReviewers.has("user")) return "user";
395
+ return "auto_review";
396
+ }
397
+ function selectGuardianSandbox(allowedSandboxModes) {
398
+ if (allowedSandboxModes === void 0 || allowedSandboxModes.has("workspace-write")) return "workspace-write";
399
+ if (allowedSandboxModes.has("read-only")) return "read-only";
400
+ if (allowedSandboxModes.has("danger-full-access")) return "danger-full-access";
401
+ return "workspace-write";
402
+ }
403
+ function resolveApprovalPolicy(value) {
404
+ return value === "on-request" || value === "on-failure" || value === "untrusted" || value === "never" ? value : void 0;
405
+ }
406
+ function resolveSandbox(value) {
407
+ return value === "read-only" || value === "workspace-write" || value === "danger-full-access" ? value : void 0;
408
+ }
409
+ function resolveApprovalsReviewer(value) {
410
+ return value === "auto_review" || value === "guardian_subagent" || value === "user" ? value : void 0;
411
+ }
412
+ function normalizeCodexServiceTier(value) {
413
+ if (typeof value !== "string") return;
414
+ const trimmed = value.trim();
415
+ if (!trimmed) return;
416
+ const normalized = trimmed.toLowerCase();
417
+ if (normalized === "fast" || normalized === "priority") return "priority";
418
+ if (normalized === "flex") return "flex";
419
+ return trimmed;
420
+ }
421
+ function isCodexFastServiceTier(value) {
422
+ return normalizeCodexServiceTier(value) === "priority";
423
+ }
424
+ function normalizePositiveNumber(value, fallback) {
425
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : fallback;
426
+ }
427
+ function normalizeHeaders(value) {
428
+ if (!value || typeof value !== "object" || Array.isArray(value)) return {};
429
+ return Object.fromEntries(Object.entries(value).map(([key, child]) => [key.trim(), readNonEmptyString(child)]).filter((entry) => Boolean(entry[0] && entry[1])));
430
+ }
431
+ function normalizeStringList(value) {
432
+ if (!Array.isArray(value)) return [];
433
+ return value.map((entry) => readNonEmptyString(entry)).filter((entry) => entry !== void 0);
434
+ }
435
+ function readBooleanEnv(value) {
436
+ if (value === void 0) return;
437
+ const normalized = value.trim().toLowerCase();
438
+ if ([
439
+ "1",
440
+ "true",
441
+ "yes",
442
+ "on"
443
+ ].includes(normalized)) return true;
444
+ if ([
445
+ "0",
446
+ "false",
447
+ "no",
448
+ "off"
449
+ ].includes(normalized)) return false;
450
+ }
451
+ function readNumberEnv(value) {
452
+ if (value === void 0) return;
453
+ const parsed = Number(value);
454
+ return Number.isFinite(parsed) ? parsed : void 0;
455
+ }
456
+ function resolveArgs(configArgs, envArgs) {
457
+ if (Array.isArray(configArgs)) return configArgs.map((entry) => readNonEmptyString(entry)).filter((entry) => entry !== void 0);
458
+ if (typeof configArgs === "string") return splitShellWords(configArgs);
459
+ return splitShellWords(envArgs ?? "");
460
+ }
461
+ function readNonEmptyString(value) {
462
+ if (typeof value !== "string") return;
463
+ return value.trim() || void 0;
464
+ }
465
+ function hashSecretForKey(value, label) {
466
+ if (!value) return null;
467
+ return createHmac("sha256", START_OPTIONS_KEY_SECRET).update(label).update("\0").update(value).digest("hex");
468
+ }
469
+ function splitShellWords(value) {
470
+ const words = [];
471
+ let current = "";
472
+ let quote = null;
473
+ for (const char of value) {
474
+ if (quote) {
475
+ if (char === quote) quote = null;
476
+ else current += char;
477
+ continue;
478
+ }
479
+ if (char === "\"" || char === "'") {
480
+ quote = char;
481
+ continue;
482
+ }
483
+ if (/\s/.test(char)) {
484
+ if (current) {
485
+ words.push(current);
486
+ current = "";
487
+ }
488
+ continue;
489
+ }
490
+ current += char;
491
+ }
492
+ if (current) words.push(current);
493
+ return words;
494
+ }
495
+ //#endregion
496
+ export { normalizeCodexServiceTier as a, resolveCodexComputerUseConfig as c, isCodexFastServiceTier as i, resolveCodexPluginsPolicy as l, codexAppServerStartOptionsKey as n, readCodexPluginConfig as o, codexSandboxPolicyForTurn as r, resolveCodexAppServerRuntimeOptions as s, CODEX_PLUGINS_MARKETPLACE_NAME as t, withMcpElicitationsApprovalPolicy as u };
@@ -1,8 +1,8 @@
1
- import { i as resolveCodexAppServerRuntimeOptions, n as codexSandboxPolicyForTurn } from "./config-ByrA30No.js";
1
+ import { i as isCodexFastServiceTier, r as codexSandboxPolicyForTurn, s as resolveCodexAppServerRuntimeOptions } from "./config-CT01BBDc.js";
2
2
  import { t as isJsonObject } from "./protocol-C9UWI98H.js";
3
- import { d as CODEX_CONTROL_METHODS, r as formatCodexDisplayText } from "./command-formatters-PiJcdUbu.js";
4
- import { n as getSharedCodexAppServerClient, s as resolveCodexAppServerAuthProfileIdForAgent } from "./shared-client-Dfk3Enm-.js";
5
- import { i as readCodexAppServerBinding, n as isCodexAppServerNativeAuthProfile, o as writeCodexAppServerBinding, r as normalizeCodexAppServerBindingModelProvider, t as clearCodexAppServerBinding } from "./session-binding-DuJYTJQy.js";
3
+ import { f as CODEX_CONTROL_METHODS, i as formatCodexDisplayText } from "./request-DC1Dz3iZ.js";
4
+ import { c as resolveCodexAppServerAuthProfileIdForAgent, n as getSharedCodexAppServerClient } from "./shared-client-p-TvEiNL.js";
5
+ import { i as readCodexAppServerBinding, n as isCodexAppServerNativeAuthProfile, o as writeCodexAppServerBinding, r as normalizeCodexAppServerBindingModelProvider, t as clearCodexAppServerBinding } from "./session-binding-B44KIZM2.js";
6
6
  import { formatErrorMessage } from "openclaw/plugin-sdk/agent-harness-runtime";
7
7
  import path from "node:path";
8
8
  import { fileURLToPath } from "node:url";
@@ -135,8 +135,8 @@ async function setCodexConversationModel(params) {
135
135
  }
136
136
  async function setCodexConversationFastMode(params) {
137
137
  const binding = await requireThreadBinding(params.sessionFile);
138
- if (params.enabled == null) return `Codex fast mode: ${binding.serviceTier === "fast" ? "on" : "off"}.`;
139
- const serviceTier = params.enabled ? "fast" : "flex";
138
+ if (params.enabled == null) return `Codex fast mode: ${isCodexFastServiceTier(binding.serviceTier) ? "on" : "off"}.`;
139
+ const serviceTier = params.enabled ? "priority" : "flex";
140
140
  await writeCodexAppServerBinding(params.sessionFile, {
141
141
  ...binding,
142
142
  serviceTier
@@ -498,6 +498,7 @@ async function attachExistingThread(params) {
498
498
  persistExtendedHistory: true
499
499
  }, { timeoutMs: runtime.requestTimeoutMs });
500
500
  const thread = response.thread;
501
+ const runtimeApprovalPolicy = typeof runtime.approvalPolicy === "string" ? runtime.approvalPolicy : void 0;
501
502
  await writeCodexAppServerBinding(params.sessionFile, {
502
503
  threadId: thread.id,
503
504
  cwd: thread.cwd ?? params.workspaceDir,
@@ -508,7 +509,7 @@ async function attachExistingThread(params) {
508
509
  authProfileId: params.authProfileId,
509
510
  modelProvider: response.modelProvider ?? params.modelProvider
510
511
  }),
511
- approvalPolicy: params.approvalPolicy ?? runtime.approvalPolicy,
512
+ approvalPolicy: params.approvalPolicy ?? runtimeApprovalPolicy,
512
513
  sandbox: params.sandbox ?? runtime.sandbox,
513
514
  serviceTier: params.serviceTier ?? runtime.serviceTier
514
515
  }, { config: params.config });
@@ -536,6 +537,7 @@ async function createThread(params) {
536
537
  experimentalRawEvents: true,
537
538
  persistExtendedHistory: true
538
539
  }, { timeoutMs: runtime.requestTimeoutMs });
540
+ const runtimeApprovalPolicy = typeof runtime.approvalPolicy === "string" ? runtime.approvalPolicy : void 0;
539
541
  await writeCodexAppServerBinding(params.sessionFile, {
540
542
  threadId: response.thread.id,
541
543
  cwd: response.thread.cwd ?? params.workspaceDir,
@@ -546,7 +548,7 @@ async function createThread(params) {
546
548
  authProfileId: params.authProfileId,
547
549
  modelProvider: response.modelProvider ?? params.modelProvider
548
550
  }),
549
- approvalPolicy: params.approvalPolicy ?? runtime.approvalPolicy,
551
+ approvalPolicy: params.approvalPolicy ?? runtimeApprovalPolicy,
550
552
  sandbox: params.sandbox ?? runtime.sandbox,
551
553
  serviceTier: params.serviceTier ?? runtime.serviceTier
552
554
  }, { config: params.config });