@openclaw/codex 2026.7.2-beta.7 → 2026.8.1-beta.3
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.
- package/README.md +2 -0
- package/dist/api.js +147 -0
- package/dist/app-server-policy-bg5QPSVP.js +25 -0
- package/dist/attempt-client-cleanup-URjUlCHg.js +735 -0
- package/dist/binding-connection-DAvZwp96.js +45 -0
- package/dist/{bounded-turn-D2ZAgZVz.js → bounded-turn-4BjrZEwW.js} +63 -56
- package/dist/{capabilities-BFDTVYr4.js → capabilities-CH3K57v4.js} +8 -2
- package/dist/cli-metadata.js +1 -1
- package/dist/{command-formatters-C336eRVS.js → command-formatters-D0nZ3qtd.js} +18 -18
- package/dist/{command-handlers-DAHUSry9.js → command-handlers-DC86lgT4.js} +507 -101
- package/dist/command-rpc-xUIIonsO.js +90 -0
- package/dist/{compact-D_uvHurS.js → compact-COqgBRny.js} +234 -214
- package/dist/{session-binding-BXpo9ymA.js → config-CpNeo5AE.js} +284 -1163
- package/dist/context-compaction-activity-BOeJf7yo.js +58 -0
- package/dist/{conversation-binding-data-BHRpYbX3.js → conversation-binding-data-CW2GuupV.js} +6 -10
- package/dist/doctor-contract-api.js +48 -50
- package/dist/{dynamic-tools-D2gYkSBO.js → dynamic-tools-fJZhl4CE.js} +3442 -1433
- package/dist/{effective-mcp-catalog-Bbd98Inw.js → effective-mcp-catalog-4YKn51aG.js} +20 -15
- package/dist/elicitation-input-DMkeki8d.js +71 -0
- package/dist/{event-projector-assistant-message-DTgnPPVF.js → event-projector-assistant-message-BwxV4d6N.js} +11 -23
- package/dist/{attempt-notifications-AP-a-Q5k.js → event-projector-usage-CLwNEJqW.js} +113 -29
- package/dist/harness-DoKQcF8n.js +258 -0
- package/dist/harness.js +2 -160
- package/dist/image-payload-sanitizer-CnfoUPCE.js +65 -0
- package/dist/index.js +730 -256
- package/dist/isolated-completion-DPMtlH9r.js +75 -0
- package/dist/local-runtime-attribution-B_2mnqhb.js +19 -0
- package/dist/managed-binary-By4FZC6i.js +212 -0
- package/dist/media-understanding-provider.js +5 -5
- package/dist/model-catalog-CmGoqVKB.js +48 -0
- package/dist/{models-BBMKU4jA.js → models-CZw1wClT.js} +12 -17
- package/dist/native-subagent-monitor-GGq3RnOo.js +3225 -0
- package/dist/node-exec-server.runtime-Bsu1LdFZ.js +192 -0
- package/dist/{plugin-app-cache-key-DztPafOA.js → plugin-app-cache-key-DMNQ8Zi8.js} +18 -6
- package/dist/plugin-approval-roundtrip-C75Yiiwc.js +95 -0
- package/dist/plugin-marketplace-discovery-CSWDkMrP.js +399 -0
- package/dist/{computer-use-CYEc8U3w.js → plugin-metadata-cache-BXH5NF-4.js} +109 -6
- package/dist/protocol-validators-VAVyEnDp.js +2399 -0
- package/dist/{rate-limits-CU-gVCCS.js → rate-limits-BI1dMHDG.js} +17 -35
- package/dist/{request-qKh331yu.js → request-DSK0W6YI.js} +3 -3
- package/dist/{run-attempt-CY9WlDLc.js → run-attempt-BV3HzuCf.js} +3416 -7194
- package/dist/{runtime-artifact-CmtG_t1L.js → runtime-artifact-BvyT1uyd.js} +11 -29
- package/dist/{sandbox-guard-NuhpXmPB.js → sandbox-guard-C1qEeZ5C.js} +29 -30
- package/dist/session-binding-BTrLf9Qm.js +874 -0
- package/dist/{session-catalog-DyOgR4WH.js → session-catalog-ezP_UcRM.js} +1584 -1289
- package/dist/session-catalog-home-id-BNwAJ9D7.js +18 -0
- package/dist/{session-cli-2PZaFLRh.js → session-cli-B1hKvfkI.js} +20 -7
- package/dist/session-retirement-CE4iMiLh.js +36 -0
- package/dist/{session-upstream-marker-B6U7tLw5.js → session-upstream-marker-D_2npHlA.js} +1 -1
- package/dist/{settled-turn-finalizer-CXY2Z9dT.js → settled-turn-finalizer-Dx1onIqg.js} +40 -28
- package/dist/{shared-client-DTbvH-XV.js → shared-client-Dw-rzii0.js} +1315 -469
- package/dist/{side-question-_ulBk1AL.js → side-question-DbXkJZzg.js} +140 -69
- package/dist/{thread-lifecycle-DF53ogiA.js → thread-lifecycle-DKdrnTMX.js} +927 -768
- package/dist/thread-ownership-i2NBwDUL.js +92 -0
- package/dist/thread-resume-CdJk2Ehf.js +30 -0
- package/dist/transcript-mirror-BU0_LKAL.js +588 -0
- package/dist/{transport-stdio-DXgGZ7Ib.js → transport-stdio-DhoGy33Z.js} +13 -2
- package/dist/upstream-prompt-provenance-CFmsKwr9.js +39 -0
- package/dist/{upstream-session-fork-Dy4Xvuoj.js → upstream-session-fork-BDVJCLAD.js} +14 -8
- package/dist/{usage-CQ6GhD5-.js → usage-9dKJCgcy.js} +3 -3
- package/dist/{web-search-provider.runtime-CCFhg2z5.js → web-search-provider.runtime-DCdx4DGu.js} +8 -9
- package/openclaw.plugin.json +49 -4
- package/package.json +6 -5
- package/dist/app-server-policy-BSaO2JIT.js +0 -49
- package/dist/conversation-control-xsIeXbo4.js +0 -287
- package/dist/event-projector-usage-Xp4AlR2k.js +0 -86
- package/dist/notification-correlation-CU6_AnOb.js +0 -67
- package/dist/transcript-mirror-DzsdNCf5.js +0 -6924
|
@@ -1,33 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as CODEX_APP_SERVER_BINDING_NAMESPACE, t as CODEX_APP_SERVER_BINDING_MAX_ENTRIES } from "./session-binding-meta-B7aEMU7g.js";
|
|
1
|
+
import { asOptionalRecord as readRecord, normalizeOptionalString as readNonEmptyString, normalizeTrimmedStringList, parseBooleanValue } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
3
2
|
import path from "node:path";
|
|
4
3
|
import { resolvePositiveTimerTimeoutMs } from "openclaw/plugin-sdk/number-runtime";
|
|
5
|
-
import {
|
|
6
|
-
import { createHash, createHmac, randomBytes
|
|
7
|
-
import { ensureAuthProfileStore, resolveDefaultAgentDir, resolveProviderIdForAuth, resolveSessionAgentIds as resolveSessionAgentIds$1 } from "openclaw/plugin-sdk/agent-runtime";
|
|
4
|
+
import { AgentHarnessPreflightError } from "openclaw/plugin-sdk/agent-harness-runtime";
|
|
5
|
+
import { createHash, createHmac, randomBytes } from "node:crypto";
|
|
8
6
|
import { readFileSync } from "node:fs";
|
|
9
7
|
import { homedir, hostname } from "node:os";
|
|
8
|
+
import { resolveProviderIdForAuth } from "openclaw/plugin-sdk/agent-runtime";
|
|
9
|
+
import { parse } from "smol-toml";
|
|
10
|
+
import { resolveAgentConfig as resolveAgentConfig$1 } from "openclaw/plugin-sdk/agent-scope-runtime";
|
|
10
11
|
import { resolveExecApprovalsFromFile } from "openclaw/plugin-sdk/exec-approvals-runtime";
|
|
11
|
-
import { normalizeAgentId } from "openclaw/plugin-sdk/routing";
|
|
12
12
|
import { buildSecretInputSchema, normalizeResolvedSecretInputString } from "openclaw/plugin-sdk/secret-input";
|
|
13
|
-
import { normalizeTrimmedStringList } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
14
13
|
import { detectWindowsSpawnCommandInlineArgs } from "openclaw/plugin-sdk/windows-spawn";
|
|
15
14
|
import { z } from "zod";
|
|
16
|
-
import { parse } from "smol-toml";
|
|
17
15
|
import { isLoopbackHost } from "openclaw/plugin-sdk/ssrf-runtime";
|
|
18
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
19
|
-
import { getSessionEntry, resolveStorePath } from "openclaw/plugin-sdk/session-store-runtime";
|
|
20
|
-
//#region extensions/codex/src/app-server/config-contracts.ts
|
|
21
|
-
const CODEX_PLUGINS_MARKETPLACE_NAME = "openai-curated";
|
|
22
|
-
const CODEX_PLUGINS_WORKSPACE_MARKETPLACE_NAME = "workspace-directory";
|
|
23
|
-
//#endregion
|
|
24
16
|
//#region extensions/codex/src/app-server/config-utils.ts
|
|
25
17
|
const START_OPTIONS_KEY_SECRET_SYMBOL = Symbol.for("openclaw.codexAppServerStartOptionsKeySecret");
|
|
26
18
|
const START_OPTIONS_KEY_SECRET = getStartOptionsKeySecret();
|
|
27
19
|
const PLAIN_DECIMAL_NUMBER_RE = /^[+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))$/;
|
|
28
|
-
function readRecord(value) {
|
|
29
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
30
|
-
}
|
|
31
20
|
function normalizeCodexServiceTier(value) {
|
|
32
21
|
if (typeof value !== "string") return;
|
|
33
22
|
const trimmed = value.trim();
|
|
@@ -53,24 +42,8 @@ function normalizeHeaders(value) {
|
|
|
53
42
|
function normalizeCodexAppServerSecretInput(params) {
|
|
54
43
|
return normalizeResolvedSecretInputString(params);
|
|
55
44
|
}
|
|
56
|
-
function normalizeStringList(value) {
|
|
57
|
-
return normalizeTrimmedStringList(value);
|
|
58
|
-
}
|
|
59
45
|
function readBooleanEnv(value) {
|
|
60
|
-
|
|
61
|
-
const normalized = value.trim().toLowerCase();
|
|
62
|
-
if ([
|
|
63
|
-
"1",
|
|
64
|
-
"true",
|
|
65
|
-
"yes",
|
|
66
|
-
"on"
|
|
67
|
-
].includes(normalized)) return true;
|
|
68
|
-
if ([
|
|
69
|
-
"0",
|
|
70
|
-
"false",
|
|
71
|
-
"no",
|
|
72
|
-
"off"
|
|
73
|
-
].includes(normalized)) return false;
|
|
46
|
+
return parseBooleanValue(value);
|
|
74
47
|
}
|
|
75
48
|
function readExecSecurity(value) {
|
|
76
49
|
return value === "deny" || value === "allowlist" || value === "full" ? value : void 0;
|
|
@@ -89,10 +62,6 @@ function resolveArgs(configArgs, envArgs) {
|
|
|
89
62
|
if (typeof configArgs === "string") return splitShellWords(configArgs);
|
|
90
63
|
return splitShellWords(envArgs ?? "");
|
|
91
64
|
}
|
|
92
|
-
function readNonEmptyString(value) {
|
|
93
|
-
if (typeof value !== "string") return;
|
|
94
|
-
return value.trim() || void 0;
|
|
95
|
-
}
|
|
96
65
|
function hashSecretForKey(value, label) {
|
|
97
66
|
if (!value) return null;
|
|
98
67
|
return createHmac("sha256", START_OPTIONS_KEY_SECRET).update(label).update("\0").update(value).digest("hex");
|
|
@@ -159,20 +128,16 @@ function resolveApprovalsReviewer(value) {
|
|
|
159
128
|
return value === "auto_review" || value === "guardian_subagent" || value === "user" ? value : void 0;
|
|
160
129
|
}
|
|
161
130
|
function resolveOpenClawExecPolicyFromConfig(params) {
|
|
162
|
-
const
|
|
163
|
-
const globalExec = readRecord(readRecord(root?.tools)?.exec);
|
|
131
|
+
const globalExec = readRecord(params.config?.tools?.exec);
|
|
164
132
|
const globalPolicy = applyOpenClawExecPolicyLayer(createDefaultOpenClawExecPolicy(), globalExec);
|
|
165
133
|
const agentId = params.agentId?.trim();
|
|
166
|
-
|
|
167
|
-
const agents = readRecord(root?.agents);
|
|
168
|
-
const agentList = Array.isArray(agents?.list) ? agents.list : [];
|
|
169
|
-
const normalizedAgentId = normalizeAgentId(agentId);
|
|
170
|
-
return applyOpenClawExecPolicyLayer(globalPolicy, readRecord(readRecord(readRecord(agentList.find((entry) => {
|
|
171
|
-
const id = readRecord(entry)?.id;
|
|
172
|
-
return typeof id === "string" && normalizeAgentId(id) === normalizedAgentId;
|
|
173
|
-
}))?.tools)?.exec));
|
|
134
|
+
return applyOpenClawExecPolicyLayer(globalPolicy, agentId ? readRecord(resolveAgentConfig$1(params.config ?? {}, agentId)?.tools?.exec) : void 0);
|
|
174
135
|
}
|
|
175
136
|
function resolveOpenClawExecPolicyForCodexAppServer(params) {
|
|
137
|
+
if (params.permissionMode === "full") return {
|
|
138
|
+
...resolveOpenClawExecPolicyForMode("full"),
|
|
139
|
+
touched: true
|
|
140
|
+
};
|
|
176
141
|
const overridePolicy = applyOpenClawExecPolicyLayer(resolveOpenClawExecPolicyFromConfig({
|
|
177
142
|
config: params.config,
|
|
178
143
|
agentId: params.agentId
|
|
@@ -192,12 +157,11 @@ function resolveCodexPolicyModeForOpenClawExecMode(mode) {
|
|
|
192
157
|
return "guardian";
|
|
193
158
|
}
|
|
194
159
|
function assertCodexAppServerAllowedForOpenClawExecMode(mode) {
|
|
195
|
-
if (mode === "deny" || mode === "allowlist") throw new
|
|
160
|
+
if (mode === "deny" || mode === "allowlist") throw new AgentHarnessPreflightError(`Codex app-server local execution is unavailable because effective tools.exec.mode=${mode}. Execution-host approvals are authoritative. For gateway turns, inspect them with \`openclaw approvals get --gateway\` and update that same target with \`openclaw approvals set --gateway --stdin\`; for local \`agent exec\`, omit \`--gateway\`. Intentionally align that host policy before retrying.`, { scope: "harness" });
|
|
196
161
|
}
|
|
197
162
|
function createDefaultOpenClawExecPolicy() {
|
|
198
163
|
return {
|
|
199
|
-
|
|
200
|
-
ask: "off",
|
|
164
|
+
...resolveOpenClawExecPolicyForMode("full"),
|
|
201
165
|
touched: false
|
|
202
166
|
};
|
|
203
167
|
}
|
|
@@ -301,228 +265,9 @@ function readExecMode(value) {
|
|
|
301
265
|
return value === "deny" || value === "allowlist" || value === "ask" || value === "auto" || value === "full" ? value : void 0;
|
|
302
266
|
}
|
|
303
267
|
//#endregion
|
|
304
|
-
//#region extensions/codex/src/app-server/session-discovery-config.ts
|
|
305
|
-
const codexSessionCatalogConfigSchema = z.object({ enabled: z.boolean().optional() }).strict();
|
|
306
|
-
const codexDiscoveryConfigSchema = z.object({
|
|
307
|
-
enabled: z.boolean().optional(),
|
|
308
|
-
timeoutMs: z.number().positive().optional()
|
|
309
|
-
}).strict();
|
|
310
|
-
//#endregion
|
|
311
|
-
//#region extensions/codex/src/app-server/config-parsing.ts
|
|
312
|
-
const DEFAULT_CODEX_COMPUTER_USE_PLUGIN_NAME = "computer-use";
|
|
313
|
-
const DEFAULT_CODEX_COMPUTER_USE_MARKETPLACE_DISCOVERY_TIMEOUT_MS = 6e4;
|
|
314
|
-
const DEFAULT_CODEX_COMPUTER_USE_LIVE_TEST_TIMEOUT_MS = 6e4;
|
|
315
|
-
const DEFAULT_CODEX_COMPUTER_USE_TOOL_CALL_TIMEOUT_MS = 6e4;
|
|
316
|
-
const DEFAULT_CODEX_APP_SERVER_NETWORK_PROXY_PROFILE_PREFIX = "openclaw-network";
|
|
317
|
-
const codexAppServerTransportSchema = z.enum([
|
|
318
|
-
"stdio",
|
|
319
|
-
"websocket",
|
|
320
|
-
"unix"
|
|
321
|
-
]);
|
|
322
|
-
const codexAppServerHomeScopeSchema = z.enum(["agent", "user"]);
|
|
323
|
-
const SecretInputSchema = buildSecretInputSchema();
|
|
324
|
-
const codexAppServerPolicyModeSchema = z.enum(["yolo", "guardian"]);
|
|
325
|
-
const codexAppServerApprovalPolicySchema = z.preprocess((value) => value === "on-failure" ? "on-request" : value, z.enum([
|
|
326
|
-
"never",
|
|
327
|
-
"on-request",
|
|
328
|
-
"untrusted"
|
|
329
|
-
]));
|
|
330
|
-
const codexAppServerSandboxSchema = z.enum([
|
|
331
|
-
"read-only",
|
|
332
|
-
"workspace-write",
|
|
333
|
-
"danger-full-access"
|
|
334
|
-
]);
|
|
335
|
-
const codexAppServerApprovalsReviewerSchema = z.enum([
|
|
336
|
-
"user",
|
|
337
|
-
"auto_review",
|
|
338
|
-
"guardian_subagent"
|
|
339
|
-
]);
|
|
340
|
-
const codexDynamicToolsLoadingSchema = z.enum(["searchable", "direct"]);
|
|
341
|
-
const codexComputerUseHealthIntervalSchema = z.union([
|
|
342
|
-
z.literal(30),
|
|
343
|
-
z.literal(60),
|
|
344
|
-
z.literal(120),
|
|
345
|
-
z.literal(240)
|
|
346
|
-
]);
|
|
347
|
-
const codexComputerUsePluginCacheModeSchema = z.enum(["shared", "independent"]);
|
|
348
|
-
const codexPluginDestructivePolicySchema = z.union([
|
|
349
|
-
z.boolean(),
|
|
350
|
-
z.literal("auto"),
|
|
351
|
-
z.literal("ask")
|
|
352
|
-
]);
|
|
353
|
-
const codexAppServerServiceTierSchema = z.preprocess((value) => value === null ? null : normalizeCodexServiceTier(value), z.string().trim().min(1).nullable().optional()).optional();
|
|
354
|
-
const codexAppServerExperimentalSchema = z.object({ sandboxExecServer: z.boolean().optional() }).strict();
|
|
355
|
-
const codexAppServerRemoteWorkspaceRootSchema = z.string().trim().min(1);
|
|
356
|
-
const codexAppServerNetworkProxyDomainPermissionSchema = z.enum(["allow", "deny"]);
|
|
357
|
-
const codexAppServerNetworkProxyUnixSocketPermissionSchema = z.enum(["allow", "none"]);
|
|
358
|
-
const codexAppServerNetworkProxySchema = z.object({
|
|
359
|
-
enabled: z.boolean().optional(),
|
|
360
|
-
profileName: z.string().trim().min(1).optional(),
|
|
361
|
-
baseProfile: z.enum(["read-only", "workspace"]).optional(),
|
|
362
|
-
mode: z.enum(["limited", "full"]).optional(),
|
|
363
|
-
domains: z.record(z.string(), codexAppServerNetworkProxyDomainPermissionSchema).optional(),
|
|
364
|
-
unixSockets: z.record(z.string(), codexAppServerNetworkProxyUnixSocketPermissionSchema).optional(),
|
|
365
|
-
proxyUrl: z.string().trim().min(1).optional(),
|
|
366
|
-
socksUrl: z.string().trim().min(1).optional(),
|
|
367
|
-
enableSocks5: z.boolean().optional(),
|
|
368
|
-
enableSocks5Udp: z.boolean().optional(),
|
|
369
|
-
allowUpstreamProxy: z.boolean().optional(),
|
|
370
|
-
allowLocalBinding: z.boolean().optional(),
|
|
371
|
-
dangerouslyAllowNonLoopbackProxy: z.boolean().optional(),
|
|
372
|
-
dangerouslyAllowAllUnixSockets: z.boolean().optional()
|
|
373
|
-
}).strict();
|
|
374
|
-
const codexPluginEntryConfigSchema = z.object({
|
|
375
|
-
enabled: z.boolean().optional(),
|
|
376
|
-
marketplaceName: z.enum([CODEX_PLUGINS_MARKETPLACE_NAME, CODEX_PLUGINS_WORKSPACE_MARKETPLACE_NAME]).optional(),
|
|
377
|
-
pluginName: z.string().trim().min(1).optional(),
|
|
378
|
-
allow_destructive_actions: codexPluginDestructivePolicySchema.optional()
|
|
379
|
-
}).strict();
|
|
380
|
-
const codexPluginsConfigSchema = z.object({
|
|
381
|
-
enabled: z.boolean().optional(),
|
|
382
|
-
allow_all_plugins: z.boolean().optional(),
|
|
383
|
-
allow_destructive_actions: codexPluginDestructivePolicySchema.optional(),
|
|
384
|
-
plugins: z.record(z.string(), codexPluginEntryConfigSchema).optional()
|
|
385
|
-
}).strict();
|
|
386
|
-
const codexSupervisionEndpointSchema = z.union([z.object({
|
|
387
|
-
id: z.string().optional(),
|
|
388
|
-
label: z.string().optional(),
|
|
389
|
-
transport: z.literal("stdio-proxy").optional(),
|
|
390
|
-
command: z.string().optional(),
|
|
391
|
-
args: z.array(z.string()).optional(),
|
|
392
|
-
cwd: z.string().optional()
|
|
393
|
-
}).strict(), z.object({
|
|
394
|
-
id: z.string().optional(),
|
|
395
|
-
label: z.string().optional(),
|
|
396
|
-
transport: z.literal("websocket"),
|
|
397
|
-
url: z.string(),
|
|
398
|
-
authTokenEnv: z.string().optional()
|
|
399
|
-
}).strict()]);
|
|
400
|
-
const codexSupervisionConfigSchema = z.object({
|
|
401
|
-
enabled: z.boolean().optional(),
|
|
402
|
-
endpoints: z.array(codexSupervisionEndpointSchema).optional(),
|
|
403
|
-
allowRawTranscripts: z.boolean().optional(),
|
|
404
|
-
allowWriteControls: z.boolean().optional()
|
|
405
|
-
}).strict();
|
|
406
|
-
const codexPluginConfigSchema = z.object({
|
|
407
|
-
codexDynamicToolsLoading: codexDynamicToolsLoadingSchema.optional(),
|
|
408
|
-
codexDynamicToolsExclude: z.array(z.string()).optional(),
|
|
409
|
-
sessionCatalog: codexSessionCatalogConfigSchema.optional(),
|
|
410
|
-
discovery: codexDiscoveryConfigSchema.optional(),
|
|
411
|
-
computerUse: z.object({
|
|
412
|
-
enabled: z.boolean().optional(),
|
|
413
|
-
autoInstall: z.boolean().optional(),
|
|
414
|
-
marketplaceDiscoveryTimeoutMs: z.number().positive().optional(),
|
|
415
|
-
liveTestTimeoutMs: z.number().positive().optional(),
|
|
416
|
-
toolCallTimeoutMs: z.number().positive().optional(),
|
|
417
|
-
healthCheckEnabled: z.boolean().optional(),
|
|
418
|
-
healthCheckIntervalMinutes: codexComputerUseHealthIntervalSchema.optional(),
|
|
419
|
-
pluginCacheMode: codexComputerUsePluginCacheModeSchema.optional(),
|
|
420
|
-
strictReadiness: z.boolean().optional(),
|
|
421
|
-
autoRepair: z.boolean().optional(),
|
|
422
|
-
marketplaceSource: z.string().optional(),
|
|
423
|
-
marketplacePath: z.string().optional(),
|
|
424
|
-
marketplaceName: z.string().optional(),
|
|
425
|
-
pluginName: z.string().optional(),
|
|
426
|
-
mcpServerName: z.string().optional()
|
|
427
|
-
}).strict().optional(),
|
|
428
|
-
codexPlugins: z.unknown().optional(),
|
|
429
|
-
supervision: codexSupervisionConfigSchema.optional(),
|
|
430
|
-
appServer: z.object({
|
|
431
|
-
mode: codexAppServerPolicyModeSchema.optional(),
|
|
432
|
-
transport: codexAppServerTransportSchema.optional(),
|
|
433
|
-
homeScope: codexAppServerHomeScopeSchema.optional(),
|
|
434
|
-
command: z.string().optional(),
|
|
435
|
-
args: z.union([z.array(z.string()), z.string()]).optional(),
|
|
436
|
-
url: z.string().optional(),
|
|
437
|
-
authToken: SecretInputSchema.optional(),
|
|
438
|
-
headers: z.record(z.string(), SecretInputSchema).optional(),
|
|
439
|
-
clearEnv: z.array(z.string()).optional(),
|
|
440
|
-
remoteWorkspaceRoot: codexAppServerRemoteWorkspaceRootSchema.optional(),
|
|
441
|
-
codeModeOnly: z.boolean().optional(),
|
|
442
|
-
loopDetectionPreToolUseRelay: z.boolean().optional(),
|
|
443
|
-
requestTimeoutMs: z.number().positive().optional(),
|
|
444
|
-
turnCompletionIdleTimeoutMs: z.number().positive().optional(),
|
|
445
|
-
turnAssistantCompletionIdleTimeoutMs: z.number().positive().optional(),
|
|
446
|
-
postToolRawAssistantCompletionIdleTimeoutMs: z.number().positive().optional(),
|
|
447
|
-
approvalPolicy: codexAppServerApprovalPolicySchema.optional(),
|
|
448
|
-
sandbox: codexAppServerSandboxSchema.optional(),
|
|
449
|
-
approvalsReviewer: codexAppServerApprovalsReviewerSchema.optional(),
|
|
450
|
-
serviceTier: codexAppServerServiceTierSchema,
|
|
451
|
-
networkProxy: codexAppServerNetworkProxySchema.optional(),
|
|
452
|
-
defaultWorkspaceDir: z.string().optional(),
|
|
453
|
-
experimental: codexAppServerExperimentalSchema.optional()
|
|
454
|
-
}).strict().optional()
|
|
455
|
-
}).strict();
|
|
456
|
-
function readCodexPluginConfig(value) {
|
|
457
|
-
const parsed = codexPluginConfigSchema.safeParse(value);
|
|
458
|
-
if (!parsed.success) return {};
|
|
459
|
-
const { codexPlugins: rawCodexPlugins, ...config } = parsed.data;
|
|
460
|
-
const plugins = codexPluginsConfigSchema.safeParse(rawCodexPlugins);
|
|
461
|
-
if (!plugins.success) return config;
|
|
462
|
-
return {
|
|
463
|
-
...config,
|
|
464
|
-
...plugins.data ? { codexPlugins: plugins.data } : {}
|
|
465
|
-
};
|
|
466
|
-
}
|
|
467
|
-
function isCodexSandboxExecServerEnabled(pluginConfig) {
|
|
468
|
-
return readCodexPluginConfig(pluginConfig).appServer?.experimental?.sandboxExecServer === true;
|
|
469
|
-
}
|
|
470
|
-
function assertCodexAppServerCommandHasNoInlineArgs(params) {
|
|
471
|
-
const inlineArgs = detectWindowsSpawnCommandInlineArgs(params.command);
|
|
472
|
-
if (!inlineArgs) return;
|
|
473
|
-
const sourceLabel = params.source === "env" ? "OPENCLAW_CODEX_APP_SERVER_BIN" : "plugins.entries.codex.config.appServer.command";
|
|
474
|
-
const argsLabel = params.source === "env" ? "OPENCLAW_CODEX_APP_SERVER_ARGS" : "plugins.entries.codex.config.appServer.args";
|
|
475
|
-
throw new Error(`${sourceLabel} must be only the Codex app-server executable path; "${inlineArgs.executable}" was configured with inline arguments "${inlineArgs.arguments}". Move those arguments to ${argsLabel}, or remove the override to use the managed Codex startup path.`);
|
|
476
|
-
}
|
|
477
|
-
function resolveCodexPluginsPolicy(pluginConfig) {
|
|
478
|
-
const config = readCodexPluginConfig(pluginConfig).codexPlugins;
|
|
479
|
-
const configured = config !== void 0;
|
|
480
|
-
const enabled = config?.enabled === true;
|
|
481
|
-
const destructivePolicy = resolveCodexPluginDestructivePolicy(config?.allow_destructive_actions ?? true);
|
|
482
|
-
const pluginPolicies = Object.entries(config?.plugins ?? {}).flatMap(([configKey, entry]) => {
|
|
483
|
-
if (!isCodexPluginMarketplaceName(entry.marketplaceName) || !entry.pluginName) return [];
|
|
484
|
-
const entryDestructivePolicy = resolveCodexPluginDestructivePolicy(entry.allow_destructive_actions ?? config?.allow_destructive_actions ?? true);
|
|
485
|
-
return [{
|
|
486
|
-
configKey,
|
|
487
|
-
marketplaceName: entry.marketplaceName,
|
|
488
|
-
pluginName: entry.pluginName,
|
|
489
|
-
enabled: enabled && entry.enabled !== false,
|
|
490
|
-
allowDestructiveActions: entryDestructivePolicy.allowDestructiveActions,
|
|
491
|
-
destructiveApprovalMode: entryDestructivePolicy.destructiveApprovalMode
|
|
492
|
-
}];
|
|
493
|
-
}).toSorted((left, right) => left.configKey.localeCompare(right.configKey));
|
|
494
|
-
return {
|
|
495
|
-
configured,
|
|
496
|
-
enabled,
|
|
497
|
-
allowAllPlugins: enabled && config?.allow_all_plugins === true,
|
|
498
|
-
allowDestructiveActions: destructivePolicy.allowDestructiveActions,
|
|
499
|
-
destructiveApprovalMode: destructivePolicy.destructiveApprovalMode,
|
|
500
|
-
pluginPolicies
|
|
501
|
-
};
|
|
502
|
-
}
|
|
503
|
-
function isCodexPluginMarketplaceName(value) {
|
|
504
|
-
return value === "openai-curated" || value === "workspace-directory";
|
|
505
|
-
}
|
|
506
|
-
function resolveCodexPluginDestructivePolicy(policy) {
|
|
507
|
-
if (policy === "auto" || policy === "ask") return {
|
|
508
|
-
allowDestructiveActions: true,
|
|
509
|
-
destructiveApprovalMode: policy
|
|
510
|
-
};
|
|
511
|
-
return {
|
|
512
|
-
allowDestructiveActions: policy,
|
|
513
|
-
destructiveApprovalMode: policy ? "allow" : "deny"
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
//#endregion
|
|
517
268
|
//#region extensions/codex/src/app-server/config-requirements.ts
|
|
518
269
|
const UNIX_CODEX_REQUIREMENTS_PATH = "/etc/codex/requirements.toml";
|
|
519
270
|
const WINDOWS_CODEX_REQUIREMENTS_SUFFIX = "\\OpenAI\\Codex\\requirements.toml";
|
|
520
|
-
function isCodexAppServerApprovalPolicyAllowedByRequirements(policy, params = {}) {
|
|
521
|
-
const content = readCodexRequirementsToml(params);
|
|
522
|
-
if (content === void 0) return true;
|
|
523
|
-
const allowedApprovalPolicies = parseAllowedApprovalPoliciesFromCodexRequirements(content);
|
|
524
|
-
return allowedApprovalPolicies === void 0 || allowedApprovalPolicies.has(policy);
|
|
525
|
-
}
|
|
526
271
|
function readCodexRequirementsToml(params) {
|
|
527
272
|
if (params.requirementsToml !== void 0) return params.requirementsToml ?? void 0;
|
|
528
273
|
const requirementsPath = readNonEmptyString(params.requirementsPath) ?? resolveCodexRequirementsPath(params.env ?? process.env, params.platform ?? process.platform);
|
|
@@ -911,38 +656,269 @@ function inferProviderFromModelRef(model) {
|
|
|
911
656
|
return slashIndex > 0 ? normalized?.slice(0, slashIndex) : void 0;
|
|
912
657
|
}
|
|
913
658
|
//#endregion
|
|
914
|
-
//#region extensions/codex/src/app-server/config-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
659
|
+
//#region extensions/codex/src/app-server/config-contracts.ts
|
|
660
|
+
const CODEX_PLUGINS_MARKETPLACE_NAME = "openai-curated";
|
|
661
|
+
const CODEX_PLUGINS_WORKSPACE_MARKETPLACE_NAME = "workspace-directory";
|
|
662
|
+
const CODEX_PLUGIN_MARKETPLACE_NAME_PATTERN = /^[A-Za-z0-9_-]+$/;
|
|
663
|
+
//#endregion
|
|
664
|
+
//#region extensions/codex/src/app-server/session-discovery-config.ts
|
|
665
|
+
const codexSessionCatalogHomeSchema = z.union([z.string().trim().min(1), z.object({
|
|
666
|
+
path: z.string().trim().min(1),
|
|
667
|
+
label: z.string().trim().min(1).optional()
|
|
668
|
+
}).strict()]);
|
|
669
|
+
const codexSessionCatalogConfigSchema = z.object({
|
|
670
|
+
enabled: z.boolean().optional(),
|
|
671
|
+
homes: z.array(codexSessionCatalogHomeSchema).optional()
|
|
672
|
+
}).strict();
|
|
673
|
+
const codexDiscoveryConfigSchema = z.object({
|
|
674
|
+
enabled: z.boolean().optional(),
|
|
675
|
+
timeoutMs: z.number().positive().optional()
|
|
676
|
+
}).strict();
|
|
677
|
+
//#endregion
|
|
678
|
+
//#region extensions/codex/src/app-server/config-parsing.ts
|
|
679
|
+
const DEFAULT_CODEX_COMPUTER_USE_PLUGIN_NAME = "computer-use";
|
|
680
|
+
const DEFAULT_CODEX_COMPUTER_USE_MARKETPLACE_DISCOVERY_TIMEOUT_MS = 6e4;
|
|
681
|
+
const DEFAULT_CODEX_COMPUTER_USE_LIVE_TEST_TIMEOUT_MS = 6e4;
|
|
682
|
+
const DEFAULT_CODEX_COMPUTER_USE_TOOL_CALL_TIMEOUT_MS = 6e4;
|
|
683
|
+
const DEFAULT_CODEX_APP_SERVER_NETWORK_PROXY_PROFILE_PREFIX = "openclaw-network";
|
|
684
|
+
const codexAppServerTransportSchema = z.enum([
|
|
685
|
+
"stdio",
|
|
686
|
+
"websocket",
|
|
687
|
+
"unix"
|
|
688
|
+
]);
|
|
689
|
+
const codexAppServerHomeScopeSchema = z.enum(["agent", "user"]);
|
|
690
|
+
const SecretInputSchema = buildSecretInputSchema();
|
|
691
|
+
const codexAppServerPolicyModeSchema = z.enum(["yolo", "guardian"]);
|
|
692
|
+
const codexAppServerApprovalPolicySchema = z.preprocess((value) => value === "on-failure" ? "on-request" : value, z.enum([
|
|
693
|
+
"never",
|
|
694
|
+
"on-request",
|
|
695
|
+
"untrusted"
|
|
696
|
+
]));
|
|
697
|
+
const codexAppServerSandboxSchema = z.enum([
|
|
698
|
+
"read-only",
|
|
699
|
+
"workspace-write",
|
|
700
|
+
"danger-full-access"
|
|
701
|
+
]);
|
|
702
|
+
const codexAppServerApprovalsReviewerSchema = z.enum([
|
|
703
|
+
"user",
|
|
704
|
+
"auto_review",
|
|
705
|
+
"guardian_subagent"
|
|
706
|
+
]);
|
|
707
|
+
const codexDynamicToolsLoadingSchema = z.enum(["searchable", "direct"]);
|
|
708
|
+
const codexComputerUseHealthIntervalSchema = z.union([
|
|
709
|
+
z.literal(30),
|
|
710
|
+
z.literal(60),
|
|
711
|
+
z.literal(120),
|
|
712
|
+
z.literal(240)
|
|
713
|
+
]);
|
|
714
|
+
const codexComputerUsePluginCacheModeSchema = z.enum(["shared", "independent"]);
|
|
715
|
+
const codexPluginDestructivePolicySchema = z.union([
|
|
716
|
+
z.boolean(),
|
|
717
|
+
z.literal("auto"),
|
|
718
|
+
z.literal("ask")
|
|
719
|
+
]);
|
|
720
|
+
const codexAppServerServiceTierSchema = z.preprocess((value) => value === null ? null : normalizeCodexServiceTier(value), z.string().trim().min(1).nullable().optional()).optional();
|
|
721
|
+
const codexAppServerExperimentalSchema = z.object({ sandboxExecServer: z.boolean().optional() }).strict();
|
|
722
|
+
const codexAppServerRemoteWorkspaceRootSchema = z.string().trim().min(1);
|
|
723
|
+
const codexAppServerNetworkProxyDomainPermissionSchema = z.enum(["allow", "deny"]);
|
|
724
|
+
const codexAppServerNetworkProxyUnixSocketPermissionSchema = z.enum(["allow", "none"]);
|
|
725
|
+
const codexAppServerNetworkProxySchema = z.object({
|
|
726
|
+
enabled: z.boolean().optional(),
|
|
727
|
+
profileName: z.string().trim().min(1).optional(),
|
|
728
|
+
baseProfile: z.enum(["read-only", "workspace"]).optional(),
|
|
729
|
+
mode: z.enum(["limited", "full"]).optional(),
|
|
730
|
+
domains: z.record(z.string(), codexAppServerNetworkProxyDomainPermissionSchema).optional(),
|
|
731
|
+
unixSockets: z.record(z.string(), codexAppServerNetworkProxyUnixSocketPermissionSchema).optional(),
|
|
732
|
+
proxyUrl: z.string().trim().min(1).optional(),
|
|
733
|
+
socksUrl: z.string().trim().min(1).optional(),
|
|
734
|
+
enableSocks5: z.boolean().optional(),
|
|
735
|
+
enableSocks5Udp: z.boolean().optional(),
|
|
736
|
+
allowUpstreamProxy: z.boolean().optional(),
|
|
737
|
+
allowLocalBinding: z.boolean().optional(),
|
|
738
|
+
dangerouslyAllowNonLoopbackProxy: z.boolean().optional(),
|
|
739
|
+
dangerouslyAllowAllUnixSockets: z.boolean().optional()
|
|
740
|
+
}).strict();
|
|
741
|
+
const codexPluginEntryConfigSchema = z.object({
|
|
742
|
+
enabled: z.boolean().optional(),
|
|
743
|
+
marketplaceName: z.string().regex(CODEX_PLUGIN_MARKETPLACE_NAME_PATTERN).optional(),
|
|
744
|
+
pluginName: z.string().trim().min(1).optional(),
|
|
745
|
+
allow_destructive_actions: codexPluginDestructivePolicySchema.optional()
|
|
746
|
+
}).strict();
|
|
747
|
+
const codexPluginsConfigSchema = z.object({
|
|
748
|
+
enabled: z.boolean().optional(),
|
|
749
|
+
allow_all_plugins: z.boolean().optional(),
|
|
750
|
+
allow_destructive_actions: codexPluginDestructivePolicySchema.optional(),
|
|
751
|
+
plugins: z.record(z.string(), codexPluginEntryConfigSchema).optional()
|
|
752
|
+
}).strict();
|
|
753
|
+
const codexSupervisionEndpointSchema = z.union([z.object({
|
|
754
|
+
id: z.string().optional(),
|
|
755
|
+
label: z.string().optional(),
|
|
756
|
+
transport: z.literal("stdio-proxy").optional(),
|
|
757
|
+
command: z.string().optional(),
|
|
758
|
+
args: z.array(z.string()).optional(),
|
|
759
|
+
cwd: z.string().optional()
|
|
760
|
+
}).strict(), z.object({
|
|
761
|
+
id: z.string().optional(),
|
|
762
|
+
label: z.string().optional(),
|
|
763
|
+
transport: z.literal("websocket"),
|
|
764
|
+
url: z.string(),
|
|
765
|
+
authTokenEnv: z.string().optional()
|
|
766
|
+
}).strict()]);
|
|
767
|
+
const codexSupervisionConfigSchema = z.object({
|
|
768
|
+
enabled: z.boolean().optional(),
|
|
769
|
+
endpoints: z.array(codexSupervisionEndpointSchema).optional(),
|
|
770
|
+
allowRawTranscripts: z.boolean().optional(),
|
|
771
|
+
allowWriteControls: z.boolean().optional()
|
|
772
|
+
}).strict();
|
|
773
|
+
const codexPluginConfigSchema = z.object({
|
|
774
|
+
codexDynamicToolsLoading: codexDynamicToolsLoadingSchema.optional(),
|
|
775
|
+
codexDynamicToolsExclude: z.array(z.string()).optional(),
|
|
776
|
+
sessionCatalog: codexSessionCatalogConfigSchema.optional(),
|
|
777
|
+
discovery: codexDiscoveryConfigSchema.optional(),
|
|
778
|
+
computerUse: z.object({
|
|
779
|
+
enabled: z.boolean().optional(),
|
|
780
|
+
autoInstall: z.boolean().optional(),
|
|
781
|
+
marketplaceDiscoveryTimeoutMs: z.number().positive().optional(),
|
|
782
|
+
liveTestTimeoutMs: z.number().positive().optional(),
|
|
783
|
+
toolCallTimeoutMs: z.number().positive().optional(),
|
|
784
|
+
healthCheckEnabled: z.boolean().optional(),
|
|
785
|
+
healthCheckIntervalMinutes: codexComputerUseHealthIntervalSchema.optional(),
|
|
786
|
+
pluginCacheMode: codexComputerUsePluginCacheModeSchema.optional(),
|
|
787
|
+
strictReadiness: z.boolean().optional(),
|
|
788
|
+
autoRepair: z.boolean().optional(),
|
|
789
|
+
marketplaceSource: z.string().optional(),
|
|
790
|
+
marketplacePath: z.string().optional(),
|
|
791
|
+
marketplaceName: z.string().optional(),
|
|
792
|
+
pluginName: z.string().optional(),
|
|
793
|
+
mcpServerName: z.string().optional()
|
|
794
|
+
}).strict().optional(),
|
|
795
|
+
codexPlugins: z.unknown().optional(),
|
|
796
|
+
supervision: codexSupervisionConfigSchema.optional(),
|
|
797
|
+
appServer: z.object({
|
|
798
|
+
mode: codexAppServerPolicyModeSchema.optional(),
|
|
799
|
+
transport: codexAppServerTransportSchema.optional(),
|
|
800
|
+
homeScope: codexAppServerHomeScopeSchema.optional(),
|
|
801
|
+
command: z.string().optional(),
|
|
802
|
+
args: z.union([z.array(z.string()), z.string()]).optional(),
|
|
803
|
+
url: z.string().optional(),
|
|
804
|
+
authToken: SecretInputSchema.optional(),
|
|
805
|
+
headers: z.record(z.string(), SecretInputSchema).optional(),
|
|
806
|
+
clearEnv: z.array(z.string()).optional(),
|
|
807
|
+
remoteWorkspaceRoot: codexAppServerRemoteWorkspaceRootSchema.optional(),
|
|
808
|
+
codeModeOnly: z.boolean().optional(),
|
|
809
|
+
loopDetectionPreToolUseRelay: z.boolean().optional(),
|
|
810
|
+
requestTimeoutMs: z.number().positive().optional(),
|
|
811
|
+
turnCompletionIdleTimeoutMs: z.number().positive().optional(),
|
|
812
|
+
turnAssistantCompletionIdleTimeoutMs: z.number().positive().optional(),
|
|
813
|
+
postToolRawAssistantCompletionIdleTimeoutMs: z.number().positive().optional(),
|
|
814
|
+
approvalPolicy: codexAppServerApprovalPolicySchema.optional(),
|
|
815
|
+
sandbox: codexAppServerSandboxSchema.optional(),
|
|
816
|
+
approvalsReviewer: codexAppServerApprovalsReviewerSchema.optional(),
|
|
817
|
+
serviceTier: codexAppServerServiceTierSchema,
|
|
818
|
+
networkProxy: codexAppServerNetworkProxySchema.optional(),
|
|
819
|
+
defaultWorkspaceDir: z.string().optional(),
|
|
820
|
+
experimental: codexAppServerExperimentalSchema.optional()
|
|
821
|
+
}).strict().optional()
|
|
822
|
+
}).strict();
|
|
823
|
+
function readCodexPluginConfig(value) {
|
|
824
|
+
const parsed = codexPluginConfigSchema.safeParse(value);
|
|
825
|
+
if (!parsed.success) return {};
|
|
826
|
+
const { codexPlugins: rawCodexPlugins, ...config } = parsed.data;
|
|
827
|
+
const plugins = codexPluginsConfigSchema.safeParse(rawCodexPlugins);
|
|
828
|
+
if (!plugins.success) return config;
|
|
829
|
+
return {
|
|
830
|
+
...config,
|
|
831
|
+
...plugins.data ? { codexPlugins: plugins.data } : {}
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
function isCodexSandboxExecServerEnabled(pluginConfig, sandbox) {
|
|
835
|
+
return isCodexRemoteExecPlacementSandbox(sandbox) || readCodexPluginConfig(pluginConfig).appServer?.experimental?.sandboxExecServer === true;
|
|
836
|
+
}
|
|
837
|
+
function isCodexRemoteExecPlacementSandbox(sandbox) {
|
|
838
|
+
return typeof sandbox === "object" && sandbox !== null && "placementExecutionMode" in sandbox && sandbox.placementExecutionMode === "remote-exec";
|
|
839
|
+
}
|
|
840
|
+
function isCodexPairedNodeRemoteExecPlacementSandbox(sandbox) {
|
|
841
|
+
return isCodexRemoteExecPlacementSandbox(sandbox) && typeof sandbox === "object" && sandbox !== null && "placementNodeId" in sandbox && typeof sandbox.placementNodeId === "string" && sandbox.placementNodeId.length > 0;
|
|
842
|
+
}
|
|
843
|
+
function assertCodexAppServerCommandHasNoInlineArgs(params) {
|
|
844
|
+
const inlineArgs = detectWindowsSpawnCommandInlineArgs(params.command);
|
|
845
|
+
if (!inlineArgs) return;
|
|
846
|
+
const sourceLabel = params.source === "env" ? "OPENCLAW_CODEX_APP_SERVER_BIN" : "plugins.entries.codex.config.appServer.command";
|
|
847
|
+
const argsLabel = params.source === "env" ? "OPENCLAW_CODEX_APP_SERVER_ARGS" : "plugins.entries.codex.config.appServer.args";
|
|
848
|
+
throw new Error(`${sourceLabel} must be only the Codex app-server executable path; "${inlineArgs.executable}" was configured with inline arguments "${inlineArgs.arguments}". Move those arguments to ${argsLabel}, or remove the override to use the managed Codex startup path.`);
|
|
849
|
+
}
|
|
850
|
+
function resolveCodexPluginsPolicy(pluginConfig) {
|
|
851
|
+
const config = readCodexPluginConfig(pluginConfig).codexPlugins;
|
|
852
|
+
const configured = config !== void 0;
|
|
853
|
+
const enabled = config?.enabled === true;
|
|
854
|
+
const destructivePolicy = resolveCodexPluginDestructivePolicy(config?.allow_destructive_actions ?? true);
|
|
855
|
+
const pluginPolicies = Object.entries(config?.plugins ?? {}).flatMap(([configKey, entry]) => {
|
|
856
|
+
if (!isCodexPluginMarketplaceName(entry.marketplaceName) || !entry.pluginName) return [];
|
|
857
|
+
const entryDestructivePolicy = resolveCodexPluginDestructivePolicy(entry.allow_destructive_actions ?? config?.allow_destructive_actions ?? true);
|
|
858
|
+
return [{
|
|
859
|
+
configKey,
|
|
860
|
+
marketplaceName: entry.marketplaceName,
|
|
861
|
+
pluginName: entry.pluginName,
|
|
862
|
+
enabled: enabled && entry.enabled !== false,
|
|
863
|
+
allowDestructiveActions: entryDestructivePolicy.allowDestructiveActions,
|
|
864
|
+
destructiveApprovalMode: entryDestructivePolicy.destructiveApprovalMode
|
|
865
|
+
}];
|
|
866
|
+
}).toSorted((left, right) => left.configKey.localeCompare(right.configKey));
|
|
867
|
+
return {
|
|
868
|
+
configured,
|
|
869
|
+
enabled,
|
|
870
|
+
allowAllPlugins: enabled && config?.allow_all_plugins === true,
|
|
871
|
+
allowDestructiveActions: destructivePolicy.allowDestructiveActions,
|
|
872
|
+
destructiveApprovalMode: destructivePolicy.destructiveApprovalMode,
|
|
873
|
+
pluginPolicies
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
function isCodexPluginMarketplaceName(value) {
|
|
877
|
+
return typeof value === "string" && CODEX_PLUGIN_MARKETPLACE_NAME_PATTERN.test(value);
|
|
878
|
+
}
|
|
879
|
+
function resolveCodexPluginDestructivePolicy(policy) {
|
|
880
|
+
if (policy === "auto" || policy === "ask") return {
|
|
881
|
+
allowDestructiveActions: true,
|
|
882
|
+
destructiveApprovalMode: policy
|
|
883
|
+
};
|
|
884
|
+
return {
|
|
885
|
+
allowDestructiveActions: policy,
|
|
886
|
+
destructiveApprovalMode: policy ? "allow" : "deny"
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
//#endregion
|
|
890
|
+
//#region extensions/codex/src/app-server/config-security.ts
|
|
891
|
+
function shouldAutoApproveCodexAppServerApprovals(appServer) {
|
|
892
|
+
return appServer.networkProxy === void 0 && appServer.approvalPolicy === "never" && appServer.sandbox === "danger-full-access";
|
|
893
|
+
}
|
|
894
|
+
function resolveCodexAppServerNetworkProxy(config, sandbox) {
|
|
895
|
+
if (config?.enabled !== true) return {};
|
|
896
|
+
const fileSystemMode = config.baseProfile === "read-only" || !config.baseProfile && sandbox === "read-only" ? "read" : "write";
|
|
897
|
+
const networkConfig = removeUndefinedJsonFields({
|
|
898
|
+
enabled: true,
|
|
899
|
+
mode: config.mode,
|
|
900
|
+
domains: normalizeNetworkProxyPermissionMap(config.domains),
|
|
901
|
+
unix_sockets: normalizeNetworkProxyPermissionMap(config.unixSockets),
|
|
902
|
+
proxy_url: readNonEmptyString(config.proxyUrl),
|
|
903
|
+
socks_url: readNonEmptyString(config.socksUrl),
|
|
904
|
+
enable_socks5: config.enableSocks5,
|
|
905
|
+
enable_socks5_udp: config.enableSocks5Udp,
|
|
906
|
+
allow_upstream_proxy: config.allowUpstreamProxy,
|
|
907
|
+
allow_local_binding: config.allowLocalBinding,
|
|
908
|
+
dangerously_allow_non_loopback_proxy: config.dangerouslyAllowNonLoopbackProxy,
|
|
909
|
+
dangerously_allow_all_unix_sockets: config.dangerouslyAllowAllUnixSockets
|
|
910
|
+
});
|
|
911
|
+
const profile = {
|
|
912
|
+
filesystem: {
|
|
913
|
+
":minimal": "read",
|
|
914
|
+
":project_roots": { ".": fileSystemMode }
|
|
915
|
+
},
|
|
916
|
+
network: networkConfig
|
|
917
|
+
};
|
|
918
|
+
const profileName = resolveNetworkProxyPermissionProfileName(config, profile);
|
|
919
|
+
const configPatch = {
|
|
920
|
+
"features.network_proxy.enabled": true,
|
|
921
|
+
default_permissions: profileName,
|
|
946
922
|
permissions: { [profileName]: profile }
|
|
947
923
|
};
|
|
948
924
|
return { networkProxy: {
|
|
@@ -1088,9 +1064,11 @@ function resolveCodexAppServerHomeScope(params) {
|
|
|
1088
1064
|
}
|
|
1089
1065
|
function resolveCodexAppServerRuntimeOptions(params = {}) {
|
|
1090
1066
|
const env = params.env ?? process.env;
|
|
1091
|
-
const
|
|
1067
|
+
const pluginConfig = readCodexPluginConfig(params.pluginConfig);
|
|
1068
|
+
const config = pluginConfig.appServer ?? {};
|
|
1092
1069
|
const transport = resolveTransport(config.transport);
|
|
1093
1070
|
const homeScope = resolveCodexAppServerHomeScope({ appServer: config });
|
|
1071
|
+
if (transport !== "stdio" && pluginConfig.sessionCatalog?.homes?.length) throw new Error("plugins.entries.codex.config.sessionCatalog.homes requires appServer.transport=stdio");
|
|
1094
1072
|
const configCommand = readNonEmptyString(config.command);
|
|
1095
1073
|
const envCommand = readNonEmptyString(env.OPENCLAW_CODEX_APP_SERVER_BIN);
|
|
1096
1074
|
const command = configCommand ?? envCommand ?? "codex";
|
|
@@ -1101,7 +1079,7 @@ function resolveCodexAppServerRuntimeOptions(params = {}) {
|
|
|
1101
1079
|
});
|
|
1102
1080
|
const args = resolveArgs(config.args, env.OPENCLAW_CODEX_APP_SERVER_ARGS);
|
|
1103
1081
|
const headers = normalizeHeaders(config.headers);
|
|
1104
|
-
const clearEnv =
|
|
1082
|
+
const clearEnv = normalizeTrimmedStringList(config.clearEnv);
|
|
1105
1083
|
const authToken = normalizeCodexAppServerSecretInput({
|
|
1106
1084
|
value: config.authToken,
|
|
1107
1085
|
path: "plugins.entries.codex.config.appServer.authToken"
|
|
@@ -1117,7 +1095,7 @@ function resolveCodexAppServerRuntimeOptions(params = {}) {
|
|
|
1117
1095
|
execMode: params.execMode,
|
|
1118
1096
|
execPolicy: params.execPolicy
|
|
1119
1097
|
});
|
|
1120
|
-
assertCodexAppServerAllowedForOpenClawExecMode(execMode);
|
|
1098
|
+
if (!params.sessionPermissionMode) assertCodexAppServerAllowedForOpenClawExecMode(execMode);
|
|
1121
1099
|
const explicitPolicyMode = resolvePolicyMode(config.mode) ?? resolvePolicyMode(env.OPENCLAW_CODEX_APP_SERVER_MODE);
|
|
1122
1100
|
const configuredSandbox = resolveSandbox(config.sandbox) ?? resolveSandbox(env.OPENCLAW_CODEX_APP_SERVER_SANDBOX);
|
|
1123
1101
|
const explicitApprovalsReviewer = resolveApprovalsReviewer(config.approvalsReviewer);
|
|
@@ -1354,861 +1332,4 @@ function resolveCodexSupervisionAppServerRuntimeOptions(params = {}) {
|
|
|
1354
1332
|
});
|
|
1355
1333
|
}
|
|
1356
1334
|
//#endregion
|
|
1357
|
-
|
|
1358
|
-
/** SQLite-backed Codex app-server thread bindings. */
|
|
1359
|
-
var session_binding_exports = /* @__PURE__ */ __exportAll({
|
|
1360
|
-
CODEX_APP_SERVER_BINDING_GUARDED_REQUEST_TIMEOUT_MS: () => CODEX_APP_SERVER_BINDING_GUARDED_REQUEST_TIMEOUT_MS,
|
|
1361
|
-
CODEX_APP_SERVER_BINDING_MAX_ENTRIES: () => CODEX_APP_SERVER_BINDING_MAX_ENTRIES,
|
|
1362
|
-
CODEX_APP_SERVER_BINDING_NAMESPACE: () => CODEX_APP_SERVER_BINDING_NAMESPACE,
|
|
1363
|
-
CodexSupervisionBindingReplacementError: () => CodexSupervisionBindingReplacementError,
|
|
1364
|
-
assertCodexBindingMayBeReplaced: () => assertCodexBindingMayBeReplaced,
|
|
1365
|
-
bindingStoreKey: () => bindingStoreKey,
|
|
1366
|
-
createCodexAppServerBindingStore: () => createCodexAppServerBindingStore,
|
|
1367
|
-
createCodexSessionGenerationSupersededError: () => createCodexSessionGenerationSupersededError,
|
|
1368
|
-
createStoredCodexAppServerBinding: () => createStoredCodexAppServerBinding,
|
|
1369
|
-
hashCodexAppServerBindingFingerprint: () => hashCodexAppServerBindingFingerprint,
|
|
1370
|
-
isCodexAppServerNativeAuthProfile: () => isCodexAppServerNativeAuthProfile,
|
|
1371
|
-
normalizeCodexAppServerBindingModelProvider: () => normalizeCodexAppServerBindingModelProvider,
|
|
1372
|
-
normalizeStoredCodexAppServerBindingFingerprints: () => normalizeStoredCodexAppServerBindingFingerprints,
|
|
1373
|
-
readCodexAppServerThreadBinding: () => readCodexAppServerThreadBinding,
|
|
1374
|
-
readStoredCodexAppServerBinding: () => readStoredCodexAppServerBinding,
|
|
1375
|
-
reclaimCurrentCodexSessionGeneration: () => reclaimCurrentCodexSessionGeneration,
|
|
1376
|
-
resolveCodexAppServerBindingModelProvider: () => resolveCodexAppServerBindingModelProvider,
|
|
1377
|
-
resolveCodexRunSessionBindingAuthority: () => resolveCodexRunSessionBindingAuthority,
|
|
1378
|
-
scopeCodexRunBindingStore: () => scopeCodexRunBindingStore,
|
|
1379
|
-
sessionBindingIdentity: () => sessionBindingIdentity
|
|
1380
|
-
});
|
|
1381
|
-
const CODEX_APP_SERVER_NATIVE_AUTH_PROVIDER = "openai";
|
|
1382
|
-
const PUBLIC_OPENAI_MODEL_PROVIDER = "openai";
|
|
1383
|
-
const BINDING_LEASE_RETRY_INTERVAL_MS = 1e3;
|
|
1384
|
-
const BOUNDED_BINDING_FINGERPRINT_PATTERN = /^sha256:[a-f0-9]{64}$/i;
|
|
1385
|
-
const CODEX_APP_SERVER_BINDING_GUARDED_REQUEST_TIMEOUT_MS = 6e4;
|
|
1386
|
-
const BINDING_LEASE_STALE_MS = 65e3;
|
|
1387
|
-
const BINDING_LEASE_WAIT_MS = 7e4;
|
|
1388
|
-
const BINDING_LEASE_RENEW_INTERVAL_MS = Math.floor(BINDING_LEASE_STALE_MS / 3);
|
|
1389
|
-
const PHYSICAL_SESSION_RETIRE_TTL_MS = BINDING_LEASE_WAIT_MS;
|
|
1390
|
-
/** Resolves the same agent scope OpenClaw uses for transcript/session ownership. */
|
|
1391
|
-
function sessionBindingIdentity(params) {
|
|
1392
|
-
const { sessionAgentId } = resolveSessionAgentIds$1(params);
|
|
1393
|
-
const sessionKey = params.sessionKey?.trim();
|
|
1394
|
-
return {
|
|
1395
|
-
kind: "session",
|
|
1396
|
-
agentId: sessionAgentId,
|
|
1397
|
-
sessionId: params.sessionId,
|
|
1398
|
-
...sessionKey ? { sessionKey } : {}
|
|
1399
|
-
};
|
|
1400
|
-
}
|
|
1401
|
-
/** Decides whether a run may share the durable stable-key binding owner. */
|
|
1402
|
-
function resolveCodexRunSessionBindingAuthority(params) {
|
|
1403
|
-
const sessionKey = params.identity.sessionKey?.trim();
|
|
1404
|
-
if (!sessionKey) return "ephemeral";
|
|
1405
|
-
try {
|
|
1406
|
-
const storePath = params.storePath?.trim() || resolveStorePath(params.config?.session?.store, { agentId: params.identity.agentId });
|
|
1407
|
-
const entry = getSessionEntry({
|
|
1408
|
-
agentId: params.identity.agentId,
|
|
1409
|
-
hydrateSkillPromptRefs: false,
|
|
1410
|
-
readConsistency: "latest",
|
|
1411
|
-
sessionKey,
|
|
1412
|
-
storePath
|
|
1413
|
-
});
|
|
1414
|
-
if (!entry) return "ephemeral";
|
|
1415
|
-
return entry.sessionId === params.identity.sessionId ? "current" : "superseded";
|
|
1416
|
-
} catch {
|
|
1417
|
-
return "superseded";
|
|
1418
|
-
}
|
|
1419
|
-
}
|
|
1420
|
-
/** Builds the terminal coordination error used when a newer OpenClaw session owns the binding. */
|
|
1421
|
-
function createCodexSessionGenerationSupersededError(sessionId) {
|
|
1422
|
-
return new AgentHarnessSessionSupersededError(`Codex session generation is no longer current: ${sessionId}`);
|
|
1423
|
-
}
|
|
1424
|
-
const optionalStringSchema = z.string().optional().catch(void 0);
|
|
1425
|
-
const optionalBooleanSchema = z.boolean().optional().catch(void 0);
|
|
1426
|
-
const optionalNonBlankStringSchema = z.string().refine((value) => Boolean(value.trim())).optional().catch(void 0);
|
|
1427
|
-
const optionalTimestampSchema = z.string().refine((value) => Number.isFinite(Date.parse(value))).optional().catch(void 0);
|
|
1428
|
-
const pendingSupervisionBranchSchema = z.object({
|
|
1429
|
-
sourceThreadId: z.string().trim().min(1),
|
|
1430
|
-
connectionFingerprint: z.string().trim().min(1).optional(),
|
|
1431
|
-
lastTurnId: z.string().trim().min(1).optional(),
|
|
1432
|
-
cleanupThreadIds: z.array(z.string().trim().min(1)).max(2).optional()
|
|
1433
|
-
}).strict().superRefine((pending, context) => {
|
|
1434
|
-
const cleanupThreadIds = pending.cleanupThreadIds ?? [];
|
|
1435
|
-
if (new Set(cleanupThreadIds).size !== cleanupThreadIds.length) context.addIssue({
|
|
1436
|
-
code: "custom",
|
|
1437
|
-
message: "pending supervision cleanup thread ids must be unique"
|
|
1438
|
-
});
|
|
1439
|
-
if (cleanupThreadIds.includes(pending.sourceThreadId)) context.addIssue({
|
|
1440
|
-
code: "custom",
|
|
1441
|
-
message: "pending supervision cleanup cannot target its source"
|
|
1442
|
-
});
|
|
1443
|
-
});
|
|
1444
|
-
const contextEngineProjectionSchema = z.object({
|
|
1445
|
-
schemaVersion: z.literal(1),
|
|
1446
|
-
mode: z.literal("thread_bootstrap"),
|
|
1447
|
-
epoch: z.string().refine((value) => Boolean(value.trim())),
|
|
1448
|
-
fingerprint: optionalStringSchema
|
|
1449
|
-
}).strict();
|
|
1450
|
-
const contextEngineSchema = z.object({
|
|
1451
|
-
schemaVersion: z.literal(1),
|
|
1452
|
-
engineId: z.string(),
|
|
1453
|
-
policyFingerprint: z.string(),
|
|
1454
|
-
projection: contextEngineProjectionSchema.optional().catch(void 0)
|
|
1455
|
-
}).strict();
|
|
1456
|
-
const destructiveApprovalModeSchema = z.enum([
|
|
1457
|
-
"allow",
|
|
1458
|
-
"deny",
|
|
1459
|
-
"auto",
|
|
1460
|
-
"ask"
|
|
1461
|
-
]).optional().catch(void 0);
|
|
1462
|
-
const accountAppPolicyEntrySchema = z.object({
|
|
1463
|
-
source: z.literal("account"),
|
|
1464
|
-
appName: z.string(),
|
|
1465
|
-
allowDestructiveActions: z.boolean(),
|
|
1466
|
-
destructiveApprovalMode: destructiveApprovalModeSchema,
|
|
1467
|
-
mcpServerNames: z.array(z.string())
|
|
1468
|
-
}).strict();
|
|
1469
|
-
const pluginAppPolicyEntrySchema = z.object({
|
|
1470
|
-
source: z.literal("plugin").optional(),
|
|
1471
|
-
configKey: z.string(),
|
|
1472
|
-
marketplaceName: z.enum([CODEX_PLUGINS_MARKETPLACE_NAME, CODEX_PLUGINS_WORKSPACE_MARKETPLACE_NAME]),
|
|
1473
|
-
pluginName: z.string(),
|
|
1474
|
-
allowDestructiveActions: z.boolean(),
|
|
1475
|
-
destructiveApprovalMode: destructiveApprovalModeSchema,
|
|
1476
|
-
mcpServerNames: z.array(z.string())
|
|
1477
|
-
}).strict();
|
|
1478
|
-
const pluginAppPolicyContextSchema = z.object({
|
|
1479
|
-
fingerprint: z.string(),
|
|
1480
|
-
apps: z.record(z.string(), z.union([accountAppPolicyEntrySchema, pluginAppPolicyEntrySchema])),
|
|
1481
|
-
pluginAppIds: z.record(z.string(), z.array(z.string())).default({})
|
|
1482
|
-
}).strict();
|
|
1483
|
-
const threadBindingSchema = z.object({
|
|
1484
|
-
threadId: z.string().refine((value) => Boolean(value.trim())),
|
|
1485
|
-
clientId: optionalStringSchema,
|
|
1486
|
-
cwd: z.string(),
|
|
1487
|
-
rolloutPath: optionalNonBlankStringSchema,
|
|
1488
|
-
connectionScope: z.literal("supervision").optional(),
|
|
1489
|
-
supervisionSourceThreadId: z.string().trim().min(1).optional(),
|
|
1490
|
-
authProfileId: optionalStringSchema,
|
|
1491
|
-
model: optionalStringSchema,
|
|
1492
|
-
preserveNativeModel: z.literal(true).optional().catch(void 0),
|
|
1493
|
-
pendingSupervisionBranch: pendingSupervisionBranchSchema.optional(),
|
|
1494
|
-
modelProvider: z.string().transform((value) => value.trim()).pipe(z.string().min(1)).optional().catch(void 0),
|
|
1495
|
-
approvalPolicy: z.preprocess((value) => value === "on-failure" ? "on-request" : value, z.enum([
|
|
1496
|
-
"never",
|
|
1497
|
-
"on-request",
|
|
1498
|
-
"untrusted"
|
|
1499
|
-
]).optional()).catch(void 0),
|
|
1500
|
-
sandbox: z.enum([
|
|
1501
|
-
"read-only",
|
|
1502
|
-
"workspace-write",
|
|
1503
|
-
"danger-full-access"
|
|
1504
|
-
]).optional().catch(void 0),
|
|
1505
|
-
serviceTier: z.preprocess(normalizeCodexServiceTier, z.custom((value) => typeof value === "string").optional()).optional().catch(void 0),
|
|
1506
|
-
networkProxyProfileName: optionalStringSchema,
|
|
1507
|
-
networkProxyConfigFingerprint: optionalStringSchema,
|
|
1508
|
-
dynamicToolsFingerprint: optionalStringSchema,
|
|
1509
|
-
dynamicToolsContainDeferred: optionalBooleanSchema,
|
|
1510
|
-
webSearchThreadConfigFingerprint: optionalStringSchema,
|
|
1511
|
-
nativeSkillIsolationFingerprint: optionalStringSchema,
|
|
1512
|
-
userMcpServersFingerprint: optionalStringSchema,
|
|
1513
|
-
mcpServersFingerprint: optionalStringSchema,
|
|
1514
|
-
ringZeroConfigFingerprint: optionalStringSchema,
|
|
1515
|
-
ringZeroClientInstanceId: optionalStringSchema,
|
|
1516
|
-
nativeHookRelayGeneration: optionalNonBlankStringSchema,
|
|
1517
|
-
appServerRuntimeFingerprint: optionalStringSchema,
|
|
1518
|
-
pluginAppsFingerprint: optionalStringSchema,
|
|
1519
|
-
pluginAppsInputFingerprint: optionalStringSchema,
|
|
1520
|
-
pluginAppPolicyContext: pluginAppPolicyContextSchema.optional().catch(void 0),
|
|
1521
|
-
contextEngine: contextEngineSchema.optional().catch(void 0),
|
|
1522
|
-
environmentSelectionFingerprint: optionalStringSchema,
|
|
1523
|
-
conversationStartId: optionalStringSchema,
|
|
1524
|
-
conversationSourceTransferComplete: z.literal(true).optional().catch(void 0),
|
|
1525
|
-
historyCoveredThrough: optionalTimestampSchema
|
|
1526
|
-
}).superRefine((binding, context) => {
|
|
1527
|
-
if (binding.connectionScope === "supervision") {
|
|
1528
|
-
if (!binding.supervisionSourceThreadId) context.addIssue({
|
|
1529
|
-
code: "custom",
|
|
1530
|
-
message: "supervision connection ownership requires its native source thread id"
|
|
1531
|
-
});
|
|
1532
|
-
if (binding.preserveNativeModel !== true) context.addIssue({
|
|
1533
|
-
code: "custom",
|
|
1534
|
-
message: "supervision connection ownership requires native model ownership"
|
|
1535
|
-
});
|
|
1536
|
-
if (binding.conversationSourceTransferComplete !== true) context.addIssue({
|
|
1537
|
-
code: "custom",
|
|
1538
|
-
message: "supervision connection ownership requires a completed source transfer"
|
|
1539
|
-
});
|
|
1540
|
-
if (!binding.pendingSupervisionBranch && (!binding.model?.trim() || !binding.modelProvider)) context.addIssue({
|
|
1541
|
-
code: "custom",
|
|
1542
|
-
message: "materialized supervision bindings require a native model and provider"
|
|
1543
|
-
});
|
|
1544
|
-
}
|
|
1545
|
-
if (binding.supervisionSourceThreadId && binding.connectionScope !== "supervision") context.addIssue({
|
|
1546
|
-
code: "custom",
|
|
1547
|
-
message: "a supervision source thread id requires supervision connection ownership"
|
|
1548
|
-
});
|
|
1549
|
-
if (!binding.pendingSupervisionBranch) return;
|
|
1550
|
-
if (binding.threadId !== binding.pendingSupervisionBranch.sourceThreadId) context.addIssue({
|
|
1551
|
-
code: "custom",
|
|
1552
|
-
message: "pending supervision source must match the provisional thread binding"
|
|
1553
|
-
});
|
|
1554
|
-
if (binding.supervisionSourceThreadId !== binding.pendingSupervisionBranch.sourceThreadId) context.addIssue({
|
|
1555
|
-
code: "custom",
|
|
1556
|
-
message: "pending supervision source must match its durable source identity"
|
|
1557
|
-
});
|
|
1558
|
-
if (binding.preserveNativeModel !== true) context.addIssue({
|
|
1559
|
-
code: "custom",
|
|
1560
|
-
message: "pending supervision bindings must defer model selection to Codex App Server"
|
|
1561
|
-
});
|
|
1562
|
-
if (binding.connectionScope !== "supervision") context.addIssue({
|
|
1563
|
-
code: "custom",
|
|
1564
|
-
message: "pending supervision bindings require supervision connection ownership"
|
|
1565
|
-
});
|
|
1566
|
-
});
|
|
1567
|
-
var CodexSupervisionBindingReplacementError = class extends Error {
|
|
1568
|
-
constructor(threadId, operation) {
|
|
1569
|
-
super(`Refusing to replace supervised Codex thread ${threadId} while ${operation}; its native user-home connection and model ownership must be preserved`);
|
|
1570
|
-
this.name = "CodexSupervisionBindingReplacementError";
|
|
1571
|
-
}
|
|
1572
|
-
};
|
|
1573
|
-
function assertCodexBindingMayBeReplaced(binding, operation) {
|
|
1574
|
-
if (binding?.connectionScope === "supervision") throw new CodexSupervisionBindingReplacementError(binding.threadId, operation);
|
|
1575
|
-
}
|
|
1576
|
-
const bindingLeaseSchema = z.object({
|
|
1577
|
-
token: z.string().refine((value) => Boolean(value.trim())),
|
|
1578
|
-
expiresAt: z.number().finite()
|
|
1579
|
-
});
|
|
1580
|
-
const storedSessionIdSchema = z.string().transform((value) => value.trim()).pipe(z.string().min(1)).optional().catch(void 0);
|
|
1581
|
-
const storedBindingSchema = z.discriminatedUnion("state", [z.object({
|
|
1582
|
-
version: z.literal(1),
|
|
1583
|
-
state: z.literal("active"),
|
|
1584
|
-
binding: threadBindingSchema,
|
|
1585
|
-
sessionId: storedSessionIdSchema,
|
|
1586
|
-
lease: bindingLeaseSchema.optional().catch(void 0)
|
|
1587
|
-
}), z.object({
|
|
1588
|
-
version: z.literal(1),
|
|
1589
|
-
state: z.literal("cleared"),
|
|
1590
|
-
sessionId: storedSessionIdSchema,
|
|
1591
|
-
lease: bindingLeaseSchema.optional().catch(void 0),
|
|
1592
|
-
retired: z.literal(true).optional().catch(void 0)
|
|
1593
|
-
})]);
|
|
1594
|
-
function hashCodexAppServerBindingFingerprint(canonical) {
|
|
1595
|
-
return `sha256:${createHash("sha256").update(canonical).digest("hex")}`;
|
|
1596
|
-
}
|
|
1597
|
-
function normalizeLegacyBindingFingerprint(value) {
|
|
1598
|
-
if (typeof value !== "string" || value === "" || value === "[]" || BOUNDED_BINDING_FINGERPRINT_PATTERN.test(value)) return value;
|
|
1599
|
-
return hashCodexAppServerBindingFingerprint(value);
|
|
1600
|
-
}
|
|
1601
|
-
function normalizeLegacyBindingFingerprints(record) {
|
|
1602
|
-
let normalized = record;
|
|
1603
|
-
for (const key of ["dynamicToolsFingerprint", "userMcpServersFingerprint"]) {
|
|
1604
|
-
const value = record[key];
|
|
1605
|
-
const next = normalizeLegacyBindingFingerprint(value);
|
|
1606
|
-
if (next === value) continue;
|
|
1607
|
-
if (normalized === record) normalized = { ...record };
|
|
1608
|
-
normalized[key] = next;
|
|
1609
|
-
}
|
|
1610
|
-
return normalized;
|
|
1611
|
-
}
|
|
1612
|
-
function normalizeStoredCodexAppServerBindingFingerprints(value) {
|
|
1613
|
-
const stored = readStoredCodexAppServerBinding(value);
|
|
1614
|
-
if (!stored || stored.state !== "active") return stored;
|
|
1615
|
-
const binding = normalizeLegacyBindingFingerprints(stored.binding);
|
|
1616
|
-
return binding === stored.binding ? stored : readStoredCodexAppServerBinding({
|
|
1617
|
-
...stored,
|
|
1618
|
-
binding
|
|
1619
|
-
});
|
|
1620
|
-
}
|
|
1621
|
-
/** Encodes a migrated sidecar binding as one canonical plugin-state row. */
|
|
1622
|
-
function createStoredCodexAppServerBinding(value, options = {}) {
|
|
1623
|
-
const rawRecord = asRecord(value);
|
|
1624
|
-
if (!rawRecord) return;
|
|
1625
|
-
const record = normalizeLegacyBindingFingerprints(rawRecord);
|
|
1626
|
-
if (record.schemaVersion !== 1 && record.schemaVersion !== 2) return;
|
|
1627
|
-
const pluginAppPolicyContext = readPluginAppPolicyContext(record.pluginAppPolicyContext, record.schemaVersion);
|
|
1628
|
-
const historyCoveredThrough = readTimestamp(record.historyCoveredThrough) ?? readTimestamp(record.updatedAt) ?? readTimestamp(record.createdAt) ?? readTimestamp(options.now) ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
1629
|
-
const authProfileId = typeof record.authProfileId === "string" ? record.authProfileId : void 0;
|
|
1630
|
-
const binding = readCodexAppServerThreadBinding({
|
|
1631
|
-
...record,
|
|
1632
|
-
modelProvider: normalizeCodexAppServerBindingModelProvider({
|
|
1633
|
-
...options.lookup,
|
|
1634
|
-
authProfileId,
|
|
1635
|
-
modelProvider: typeof record.modelProvider === "string" ? record.modelProvider : void 0
|
|
1636
|
-
}),
|
|
1637
|
-
cwd: typeof record.cwd === "string" ? record.cwd : "",
|
|
1638
|
-
pluginAppPolicyContext,
|
|
1639
|
-
historyCoveredThrough
|
|
1640
|
-
});
|
|
1641
|
-
return binding ? {
|
|
1642
|
-
version: 1,
|
|
1643
|
-
state: "active",
|
|
1644
|
-
binding: stripUndefinedBinding(binding)
|
|
1645
|
-
} : void 0;
|
|
1646
|
-
}
|
|
1647
|
-
function bindingLeaseLostError(key, cause) {
|
|
1648
|
-
return new Error(`Lost Codex binding lease: ${key}`, cause === void 0 ? void 0 : { cause });
|
|
1649
|
-
}
|
|
1650
|
-
/** Carries one prepared run identity through callers that rederive it from public params. */
|
|
1651
|
-
function scopeCodexRunBindingStore(params) {
|
|
1652
|
-
const mapSessionIdentity = (identity) => identity.agentId === params.logicalIdentity.agentId && identity.sessionId === params.logicalIdentity.sessionId && identity.sessionKey?.trim() === params.logicalIdentity.sessionKey?.trim() ? params.physicalIdentity : identity;
|
|
1653
|
-
const mapIdentity = (identity) => identity.kind === "session" ? mapSessionIdentity(identity) : identity;
|
|
1654
|
-
return {
|
|
1655
|
-
read: (identity) => params.bindingStore.read(mapIdentity(identity)),
|
|
1656
|
-
hasOtherThreadOwner: (threadId, identity) => params.bindingStore.hasOtherThreadOwner(threadId, identity ? mapIdentity(identity) : void 0),
|
|
1657
|
-
mutate: (identity, mutation) => params.bindingStore.mutate(mapIdentity(identity), mutation),
|
|
1658
|
-
prepareSessionGenerationReclaim: (identity) => params.bindingStore.prepareSessionGenerationReclaim(mapSessionIdentity(identity)),
|
|
1659
|
-
adoptSessionGeneration: (identity, expectedPreviousSessionId) => params.bindingStore.adoptSessionGeneration(mapSessionIdentity(identity), expectedPreviousSessionId),
|
|
1660
|
-
resetSessionGeneration: (identity) => params.bindingStore.resetSessionGeneration(mapSessionIdentity(identity)),
|
|
1661
|
-
retireSessionGeneration: (identity) => params.bindingStore.retireSessionGeneration(mapSessionIdentity(identity)),
|
|
1662
|
-
withThreadArchiveFence: (run) => params.bindingStore.withThreadArchiveFence(run),
|
|
1663
|
-
withLease: (identity, run) => params.bindingStore.withLease(mapIdentity(identity), run)
|
|
1664
|
-
};
|
|
1665
|
-
}
|
|
1666
|
-
/** Lets the authoritative OpenClaw session generation claim a stale stable binding row. */
|
|
1667
|
-
async function reclaimCurrentCodexSessionGeneration(params) {
|
|
1668
|
-
const sessionKey = params.identity.sessionKey?.trim();
|
|
1669
|
-
if (!sessionKey) return true;
|
|
1670
|
-
const plan = await params.bindingStore.prepareSessionGenerationReclaim(params.identity);
|
|
1671
|
-
if (plan.kind === "resolved") return plan.result;
|
|
1672
|
-
try {
|
|
1673
|
-
const storePath = params.storePath?.trim() || resolveStorePath(params.config?.session?.store, { agentId: params.identity.agentId });
|
|
1674
|
-
if (getSessionEntry({
|
|
1675
|
-
agentId: params.identity.agentId,
|
|
1676
|
-
hydrateSkillPromptRefs: false,
|
|
1677
|
-
readConsistency: "latest",
|
|
1678
|
-
sessionKey,
|
|
1679
|
-
storePath
|
|
1680
|
-
})?.sessionId !== params.identity.sessionId) return false;
|
|
1681
|
-
} catch {
|
|
1682
|
-
return false;
|
|
1683
|
-
}
|
|
1684
|
-
return await params.bindingStore.mutate(params.identity, {
|
|
1685
|
-
kind: "reclaim-generation",
|
|
1686
|
-
expectedPreviousSessionId: plan.expectedPreviousSessionId
|
|
1687
|
-
});
|
|
1688
|
-
}
|
|
1689
|
-
/** Creates the single binding facade owned by the Codex plugin runtime. */
|
|
1690
|
-
function createCodexAppServerBindingStore(state) {
|
|
1691
|
-
const update = state.update?.bind(state);
|
|
1692
|
-
if (!update) throw new Error("Codex app-server bindings require atomic plugin-state updates");
|
|
1693
|
-
const leaseContext = new AsyncLocalStorage();
|
|
1694
|
-
const archiveContext = new AsyncLocalStorage();
|
|
1695
|
-
let activeBindingMutations = 0;
|
|
1696
|
-
let pendingArchives = 0;
|
|
1697
|
-
let archiveTail = Promise.resolve();
|
|
1698
|
-
let bindingMutationsDrained = [];
|
|
1699
|
-
const waitForBindingMutations = async () => {
|
|
1700
|
-
if (activeBindingMutations === 0) return;
|
|
1701
|
-
await new Promise((resolve) => {
|
|
1702
|
-
bindingMutationsDrained.push(resolve);
|
|
1703
|
-
});
|
|
1704
|
-
};
|
|
1705
|
-
const runBindingMutation = async (run) => {
|
|
1706
|
-
if (archiveContext.getStore() === true) return await run();
|
|
1707
|
-
if (pendingArchives > 0) throw new Error("Codex binding mutation blocked while a native archive is in progress; retry");
|
|
1708
|
-
activeBindingMutations += 1;
|
|
1709
|
-
try {
|
|
1710
|
-
return await run();
|
|
1711
|
-
} finally {
|
|
1712
|
-
activeBindingMutations -= 1;
|
|
1713
|
-
if (activeBindingMutations === 0) {
|
|
1714
|
-
const drained = bindingMutationsDrained;
|
|
1715
|
-
bindingMutationsDrained = [];
|
|
1716
|
-
for (const resolve of drained) resolve();
|
|
1717
|
-
}
|
|
1718
|
-
}
|
|
1719
|
-
};
|
|
1720
|
-
const renewLease = (key, owner) => {
|
|
1721
|
-
if (owner.failure) return;
|
|
1722
|
-
try {
|
|
1723
|
-
let renewed = false;
|
|
1724
|
-
const stored = update(key, (raw) => {
|
|
1725
|
-
const current = readStoredCodexAppServerBinding(raw);
|
|
1726
|
-
if (raw !== void 0 && !current) throw new Error(`Invalid Codex app-server binding row: ${key}`);
|
|
1727
|
-
const lease = current?.lease;
|
|
1728
|
-
const now = Date.now();
|
|
1729
|
-
if (!lease || lease.token !== owner.token || lease.expiresAt <= now) return;
|
|
1730
|
-
renewed = true;
|
|
1731
|
-
return {
|
|
1732
|
-
...current,
|
|
1733
|
-
lease: {
|
|
1734
|
-
token: owner.token,
|
|
1735
|
-
expiresAt: now + BINDING_LEASE_STALE_MS
|
|
1736
|
-
}
|
|
1737
|
-
};
|
|
1738
|
-
});
|
|
1739
|
-
if (!renewed || !stored) owner.failure = bindingLeaseLostError(key);
|
|
1740
|
-
} catch (error) {
|
|
1741
|
-
owner.failure = bindingLeaseLostError(key, error);
|
|
1742
|
-
}
|
|
1743
|
-
};
|
|
1744
|
-
const transactKey = async (key, apply, ttlMs) => {
|
|
1745
|
-
const deadline = Date.now() + BINDING_LEASE_WAIT_MS;
|
|
1746
|
-
while (true) {
|
|
1747
|
-
let busy = false;
|
|
1748
|
-
let leaseLost = false;
|
|
1749
|
-
let result;
|
|
1750
|
-
const ownedLease = leaseContext.getStore()?.get(key);
|
|
1751
|
-
if (ownedLease?.failure) throw ownedLease.failure;
|
|
1752
|
-
const ownedToken = ownedLease?.token;
|
|
1753
|
-
update(key, (raw) => {
|
|
1754
|
-
const current = readStoredCodexAppServerBinding(raw);
|
|
1755
|
-
if (raw !== void 0 && !current) throw new Error(`Invalid Codex app-server binding row: ${key}`);
|
|
1756
|
-
const activeLease = current?.lease;
|
|
1757
|
-
const now = Date.now();
|
|
1758
|
-
if (ownedToken && (!activeLease || activeLease.token !== ownedToken || activeLease.expiresAt <= now)) {
|
|
1759
|
-
leaseLost = true;
|
|
1760
|
-
return;
|
|
1761
|
-
}
|
|
1762
|
-
if (activeLease && activeLease.token !== ownedToken && activeLease.expiresAt > now) {
|
|
1763
|
-
busy = true;
|
|
1764
|
-
return;
|
|
1765
|
-
}
|
|
1766
|
-
const applied = apply(current, ownedToken);
|
|
1767
|
-
result = applied.result;
|
|
1768
|
-
return applied.next;
|
|
1769
|
-
}, ttlMs == null ? void 0 : { ttlMs });
|
|
1770
|
-
if (leaseLost) {
|
|
1771
|
-
const failure = bindingLeaseLostError(key);
|
|
1772
|
-
if (ownedLease) ownedLease.failure = failure;
|
|
1773
|
-
throw failure;
|
|
1774
|
-
}
|
|
1775
|
-
if (!busy) return result;
|
|
1776
|
-
if (Date.now() >= deadline) throw new Error(`Timed out waiting for Codex binding lease: ${key}`);
|
|
1777
|
-
await sleep(BINDING_LEASE_RETRY_INTERVAL_MS);
|
|
1778
|
-
}
|
|
1779
|
-
};
|
|
1780
|
-
return {
|
|
1781
|
-
async read(identity) {
|
|
1782
|
-
const key = bindingStoreKey(identity);
|
|
1783
|
-
const raw = state.lookup(key);
|
|
1784
|
-
const stored = readStoredCodexAppServerBinding(raw);
|
|
1785
|
-
if (raw !== void 0 && !stored) throw new Error(`Invalid Codex app-server binding row: ${key}`);
|
|
1786
|
-
return stored?.state === "active" && ownsStoredSessionGeneration(identity, stored) ? stored.binding : void 0;
|
|
1787
|
-
},
|
|
1788
|
-
async hasOtherThreadOwner(threadId, currentIdentity) {
|
|
1789
|
-
const currentKey = currentIdentity ? bindingStoreKey(currentIdentity) : void 0;
|
|
1790
|
-
return state.entries().some(({ key, value }) => {
|
|
1791
|
-
const stored = readStoredCodexAppServerBinding(value);
|
|
1792
|
-
if (!stored) throw new Error(`Invalid Codex app-server binding row: ${key}`);
|
|
1793
|
-
const isCurrentOwner = currentIdentity !== void 0 && key === currentKey && (currentIdentity.kind === "conversation" || stored.sessionId === currentIdentity.sessionId.trim());
|
|
1794
|
-
if (stored.state !== "active" || stored.binding.threadId !== threadId || isCurrentOwner) return false;
|
|
1795
|
-
return true;
|
|
1796
|
-
});
|
|
1797
|
-
},
|
|
1798
|
-
async prepareSessionGenerationReclaim(identity) {
|
|
1799
|
-
const key = bindingStoreKey(identity);
|
|
1800
|
-
const raw = state.lookup(key);
|
|
1801
|
-
const current = readStoredCodexAppServerBinding(raw);
|
|
1802
|
-
if (raw !== void 0 && !current) throw new Error(`Invalid Codex app-server binding row: ${key}`);
|
|
1803
|
-
if (!current) return {
|
|
1804
|
-
kind: "resolved",
|
|
1805
|
-
result: true
|
|
1806
|
-
};
|
|
1807
|
-
const currentSessionId = current.sessionId;
|
|
1808
|
-
if (!currentSessionId) return {
|
|
1809
|
-
kind: "resolved",
|
|
1810
|
-
result: current.state !== "cleared" || current.retired !== true
|
|
1811
|
-
};
|
|
1812
|
-
if (currentSessionId === identity.sessionId) return current.state === "cleared" && current.retired === true ? {
|
|
1813
|
-
kind: "verify",
|
|
1814
|
-
expectedPreviousSessionId: currentSessionId
|
|
1815
|
-
} : {
|
|
1816
|
-
kind: "resolved",
|
|
1817
|
-
result: true
|
|
1818
|
-
};
|
|
1819
|
-
return {
|
|
1820
|
-
kind: "verify",
|
|
1821
|
-
expectedPreviousSessionId: currentSessionId
|
|
1822
|
-
};
|
|
1823
|
-
},
|
|
1824
|
-
async mutate(identity, mutation) {
|
|
1825
|
-
return await runBindingMutation(async () => {
|
|
1826
|
-
const key = bindingStoreKey(identity);
|
|
1827
|
-
const retainLegacyClear = mutation.kind === "clear" && key.startsWith("conversation:legacy-");
|
|
1828
|
-
return await transactKey(key, (current, leaseToken) => {
|
|
1829
|
-
const ownsGeneration = ownsStoredSessionGeneration(identity, current);
|
|
1830
|
-
const ownedLease = current?.lease && current.lease.token === leaseToken ? { lease: current.lease } : {};
|
|
1831
|
-
if (mutation.kind === "reclaim-generation") {
|
|
1832
|
-
if (identity.kind !== "session" || !identity.sessionKey?.trim()) return { result: false };
|
|
1833
|
-
if (!current) return { result: true };
|
|
1834
|
-
if (ownsGeneration) {
|
|
1835
|
-
if (current.state === "cleared" && current.retired === true && current.sessionId === mutation.expectedPreviousSessionId) return {
|
|
1836
|
-
result: true,
|
|
1837
|
-
next: {
|
|
1838
|
-
version: 1,
|
|
1839
|
-
state: "cleared",
|
|
1840
|
-
sessionId: identity.sessionId,
|
|
1841
|
-
...ownedLease
|
|
1842
|
-
}
|
|
1843
|
-
};
|
|
1844
|
-
return { result: current.state !== "cleared" || current.retired !== true };
|
|
1845
|
-
}
|
|
1846
|
-
if (current.sessionId !== mutation.expectedPreviousSessionId) return { result: false };
|
|
1847
|
-
if (current.state === "active" && current.binding.connectionScope === "supervision") return { result: false };
|
|
1848
|
-
return {
|
|
1849
|
-
result: true,
|
|
1850
|
-
next: {
|
|
1851
|
-
version: 1,
|
|
1852
|
-
state: "cleared",
|
|
1853
|
-
sessionId: identity.sessionId,
|
|
1854
|
-
...ownedLease
|
|
1855
|
-
}
|
|
1856
|
-
};
|
|
1857
|
-
}
|
|
1858
|
-
const storedActive = current?.state === "active" ? current : void 0;
|
|
1859
|
-
const active = ownsGeneration ? storedActive : void 0;
|
|
1860
|
-
const retiredGeneration = current?.state === "cleared" && current.retired === true && ownsGeneration;
|
|
1861
|
-
const preservesSupervisionOwner = mutation.kind === "set" && active?.binding.connectionScope === "supervision" && isSameSupervisionOwner(active.binding, mutation.binding);
|
|
1862
|
-
const clearsPendingSupervisionOwner = mutation.kind === "clear" && active?.binding.connectionScope === "supervision" && matchesPendingSupervisionClear(active.binding, mutation.threadId, mutation.expectedPendingSupervisionBranch);
|
|
1863
|
-
if (mutation.kind === "set" && (mutation.if?.kind === "absent" && storedActive || current !== void 0 && !ownsGeneration || retiredGeneration || active?.binding.connectionScope === "supervision" && !preservesSupervisionOwner) || mutation.kind === "patch" && active?.binding.threadId !== mutation.threadId || (mutation.kind === "patch-pending-supervision-branch" || mutation.kind === "commit-pending-supervision-branch") && !matchesPendingSupervisionBranch(active?.binding, mutation.expected) || mutation.kind === "clear" && (mutation.threadId !== void 0 && active?.binding.threadId !== mutation.threadId || !ownsGeneration || active?.binding.connectionScope === "supervision" && !clearsPendingSupervisionOwner)) return { result: false };
|
|
1864
|
-
if (mutation.kind === "clear" && retiredGeneration) return { result: true };
|
|
1865
|
-
if (mutation.kind === "clear") return {
|
|
1866
|
-
result: true,
|
|
1867
|
-
next: {
|
|
1868
|
-
version: 1,
|
|
1869
|
-
state: "cleared",
|
|
1870
|
-
...storedSessionGeneration(identity, current),
|
|
1871
|
-
...ownedLease
|
|
1872
|
-
}
|
|
1873
|
-
};
|
|
1874
|
-
let binding;
|
|
1875
|
-
if (mutation.kind === "set") binding = validateBindingForWrite(mutation.binding);
|
|
1876
|
-
else if (mutation.kind === "patch-pending-supervision-branch") binding = validateBindingForWrite({
|
|
1877
|
-
...active.binding,
|
|
1878
|
-
pendingSupervisionBranch: mutation.pending
|
|
1879
|
-
});
|
|
1880
|
-
else if (mutation.kind === "commit-pending-supervision-branch") binding = validateBindingForWrite({
|
|
1881
|
-
...active.binding,
|
|
1882
|
-
...mutation.patch,
|
|
1883
|
-
threadId: mutation.threadId,
|
|
1884
|
-
pendingSupervisionBranch: void 0
|
|
1885
|
-
});
|
|
1886
|
-
else binding = validateBindingForWrite({
|
|
1887
|
-
...active.binding,
|
|
1888
|
-
...mutation.patch,
|
|
1889
|
-
threadId: mutation.threadId
|
|
1890
|
-
});
|
|
1891
|
-
return {
|
|
1892
|
-
result: true,
|
|
1893
|
-
next: {
|
|
1894
|
-
version: 1,
|
|
1895
|
-
state: "active",
|
|
1896
|
-
binding,
|
|
1897
|
-
...storedSessionGeneration(identity, current),
|
|
1898
|
-
...ownedLease
|
|
1899
|
-
}
|
|
1900
|
-
};
|
|
1901
|
-
}, mutation.kind === "clear" && !retainLegacyClear && !leaseContext.getStore()?.has(key) ? 1 : void 0);
|
|
1902
|
-
});
|
|
1903
|
-
},
|
|
1904
|
-
async adoptSessionGeneration(identity, expectedPreviousSessionId) {
|
|
1905
|
-
return await runBindingMutation(async () => {
|
|
1906
|
-
const key = bindingStoreKey(identity);
|
|
1907
|
-
const expectedSessionId = expectedPreviousSessionId.trim();
|
|
1908
|
-
const targetSessionId = identity.sessionId.trim();
|
|
1909
|
-
if (!expectedSessionId) throw new Error("Codex session generation adoption requires the previous session id");
|
|
1910
|
-
return await transactKey(key, (current) => {
|
|
1911
|
-
if (current?.state !== "active") return { result: "absent" };
|
|
1912
|
-
if (current.sessionId === targetSessionId) return { result: "current" };
|
|
1913
|
-
if (current.sessionId !== expectedSessionId) return { result: "conflict" };
|
|
1914
|
-
return {
|
|
1915
|
-
result: "adopted",
|
|
1916
|
-
next: {
|
|
1917
|
-
...current,
|
|
1918
|
-
sessionId: targetSessionId
|
|
1919
|
-
}
|
|
1920
|
-
};
|
|
1921
|
-
});
|
|
1922
|
-
});
|
|
1923
|
-
},
|
|
1924
|
-
async resetSessionGeneration(identity) {
|
|
1925
|
-
return await runBindingMutation(async () => {
|
|
1926
|
-
const key = bindingStoreKey(identity);
|
|
1927
|
-
return await transactKey(key, (current, leaseToken) => {
|
|
1928
|
-
if (!current) return { result: "absent" };
|
|
1929
|
-
if (!ownsStoredSessionGeneration(identity, current)) return { result: "conflict" };
|
|
1930
|
-
if (current.state === "cleared" && current.retired === true) return { result: "conflict" };
|
|
1931
|
-
return {
|
|
1932
|
-
result: "applied",
|
|
1933
|
-
next: {
|
|
1934
|
-
version: 1,
|
|
1935
|
-
state: "cleared",
|
|
1936
|
-
...storedSessionGeneration(identity, current),
|
|
1937
|
-
...current.lease && current.lease.token === leaseToken ? { lease: current.lease } : {}
|
|
1938
|
-
}
|
|
1939
|
-
};
|
|
1940
|
-
}, leaseContext.getStore()?.has(key) ? void 0 : 1);
|
|
1941
|
-
});
|
|
1942
|
-
},
|
|
1943
|
-
async retireSessionGeneration(identity) {
|
|
1944
|
-
return await runBindingMutation(async () => {
|
|
1945
|
-
const key = bindingStoreKey(identity);
|
|
1946
|
-
return await transactKey(key, (current, leaseToken) => {
|
|
1947
|
-
if (!current) return { result: "absent" };
|
|
1948
|
-
if (!ownsStoredSessionGeneration(identity, current)) return { result: "conflict" };
|
|
1949
|
-
if (current.state === "cleared" && current.retired === true) return { result: "applied" };
|
|
1950
|
-
return {
|
|
1951
|
-
result: "applied",
|
|
1952
|
-
next: {
|
|
1953
|
-
version: 1,
|
|
1954
|
-
state: "cleared",
|
|
1955
|
-
retired: true,
|
|
1956
|
-
...storedSessionGeneration(identity, current),
|
|
1957
|
-
...current.lease && current.lease.token === leaseToken ? { lease: current.lease } : {}
|
|
1958
|
-
}
|
|
1959
|
-
};
|
|
1960
|
-
}, identity.sessionKey?.trim() ? void 0 : PHYSICAL_SESSION_RETIRE_TTL_MS);
|
|
1961
|
-
});
|
|
1962
|
-
},
|
|
1963
|
-
async withThreadArchiveFence(run) {
|
|
1964
|
-
pendingArchives += 1;
|
|
1965
|
-
const operation = archiveTail.then(async () => {
|
|
1966
|
-
await waitForBindingMutations();
|
|
1967
|
-
return await archiveContext.run(true, run);
|
|
1968
|
-
});
|
|
1969
|
-
archiveTail = operation.then(() => void 0, () => void 0);
|
|
1970
|
-
try {
|
|
1971
|
-
return await operation;
|
|
1972
|
-
} finally {
|
|
1973
|
-
pendingArchives -= 1;
|
|
1974
|
-
}
|
|
1975
|
-
},
|
|
1976
|
-
async withLease(identity, run) {
|
|
1977
|
-
const key = bindingStoreKey(identity);
|
|
1978
|
-
const owned = leaseContext.getStore();
|
|
1979
|
-
const existingOwner = owned?.get(key);
|
|
1980
|
-
if (existingOwner) {
|
|
1981
|
-
const failureBeforeRun = existingOwner.failure;
|
|
1982
|
-
if (failureBeforeRun) throw failureBeforeRun;
|
|
1983
|
-
const result = await run();
|
|
1984
|
-
const failureAfterRun = existingOwner.failure;
|
|
1985
|
-
if (failureAfterRun) throw failureAfterRun;
|
|
1986
|
-
return result;
|
|
1987
|
-
}
|
|
1988
|
-
const token = randomUUID();
|
|
1989
|
-
if (!await transactKey(key, (current) => {
|
|
1990
|
-
if (current?.state === "cleared" && current.retired === true && ownsStoredSessionGeneration(identity, current)) return { result: false };
|
|
1991
|
-
const lease = {
|
|
1992
|
-
token,
|
|
1993
|
-
expiresAt: Date.now() + BINDING_LEASE_STALE_MS
|
|
1994
|
-
};
|
|
1995
|
-
if (current?.state === "active") return {
|
|
1996
|
-
result: true,
|
|
1997
|
-
next: {
|
|
1998
|
-
...current,
|
|
1999
|
-
...preservedSessionGeneration(identity, current),
|
|
2000
|
-
lease
|
|
2001
|
-
}
|
|
2002
|
-
};
|
|
2003
|
-
if (current?.state === "cleared" && current.retired === true) return {
|
|
2004
|
-
result: true,
|
|
2005
|
-
next: {
|
|
2006
|
-
...current,
|
|
2007
|
-
lease
|
|
2008
|
-
}
|
|
2009
|
-
};
|
|
2010
|
-
return {
|
|
2011
|
-
result: true,
|
|
2012
|
-
next: {
|
|
2013
|
-
version: 1,
|
|
2014
|
-
state: "cleared",
|
|
2015
|
-
...preservedSessionGeneration(identity, current),
|
|
2016
|
-
lease
|
|
2017
|
-
}
|
|
2018
|
-
};
|
|
2019
|
-
})) throw new Error(`Codex binding generation was retired: ${key}`);
|
|
2020
|
-
const owner = { token };
|
|
2021
|
-
const nested = new Map(owned);
|
|
2022
|
-
nested.set(key, owner);
|
|
2023
|
-
const heartbeat = setInterval(() => renewLease(key, owner), BINDING_LEASE_RENEW_INTERVAL_MS);
|
|
2024
|
-
heartbeat.unref();
|
|
2025
|
-
try {
|
|
2026
|
-
const result = await leaseContext.run(nested, run);
|
|
2027
|
-
if (owner.failure) throw owner.failure;
|
|
2028
|
-
return result;
|
|
2029
|
-
} finally {
|
|
2030
|
-
clearInterval(heartbeat);
|
|
2031
|
-
try {
|
|
2032
|
-
const removeOwnedLease = (raw, matches) => {
|
|
2033
|
-
const current = readStoredCodexAppServerBinding(raw);
|
|
2034
|
-
if (!current || !matches(current) || current.lease?.token !== token) return;
|
|
2035
|
-
const { lease: _lease, ...released } = current;
|
|
2036
|
-
return released;
|
|
2037
|
-
};
|
|
2038
|
-
if (!update(key, (raw) => removeOwnedLease(raw, (current) => current.state === "active"))) {
|
|
2039
|
-
if (!update(key, (raw) => removeOwnedLease(raw, (current) => current.state === "cleared" && current.retired === true), key.startsWith("session:") ? { ttlMs: PHYSICAL_SESSION_RETIRE_TTL_MS } : void 0)) update(key, (raw) => removeOwnedLease(raw, (current) => current.state === "cleared"), { ttlMs: 1 });
|
|
2040
|
-
}
|
|
2041
|
-
} catch (error) {
|
|
2042
|
-
embeddedAgentLog.warn("failed to release codex app-server binding lease", {
|
|
2043
|
-
key,
|
|
2044
|
-
error
|
|
2045
|
-
});
|
|
2046
|
-
}
|
|
2047
|
-
}
|
|
2048
|
-
}
|
|
2049
|
-
};
|
|
2050
|
-
}
|
|
2051
|
-
function matchesPendingSupervisionBranch(binding, expected) {
|
|
2052
|
-
const pending = binding?.pendingSupervisionBranch;
|
|
2053
|
-
if (!pending || binding?.threadId !== expected.sourceThreadId) return false;
|
|
2054
|
-
if (pending.sourceThreadId !== expected.sourceThreadId || pending.connectionFingerprint !== expected.connectionFingerprint || pending.lastTurnId !== expected.lastTurnId) return false;
|
|
2055
|
-
const currentCleanup = pending.cleanupThreadIds ?? [];
|
|
2056
|
-
const expectedCleanup = expected.cleanupThreadIds ?? [];
|
|
2057
|
-
return currentCleanup.length === expectedCleanup.length && currentCleanup.every((threadId, index) => threadId === expectedCleanup[index]);
|
|
2058
|
-
}
|
|
2059
|
-
function isSameSupervisionOwner(current, replacement) {
|
|
2060
|
-
return replacement.connectionScope === "supervision" && replacement.threadId === current.threadId && replacement.supervisionSourceThreadId === current.supervisionSourceThreadId;
|
|
2061
|
-
}
|
|
2062
|
-
function matchesPendingSupervisionClear(binding, threadId, expected) {
|
|
2063
|
-
if (!expected) return false;
|
|
2064
|
-
const sourceThreadId = expected.sourceThreadId;
|
|
2065
|
-
return threadId === sourceThreadId && binding.supervisionSourceThreadId === sourceThreadId && matchesPendingSupervisionBranch(binding, expected);
|
|
2066
|
-
}
|
|
2067
|
-
/** Stable plugin-state key for one current binding owner. */
|
|
2068
|
-
function bindingStoreKey(identity) {
|
|
2069
|
-
if (identity.kind === "session") {
|
|
2070
|
-
const rawAgentId = identity.agentId.trim();
|
|
2071
|
-
const sessionId = identity.sessionId.trim();
|
|
2072
|
-
if (!rawAgentId) throw new Error("Codex app-server binding requires an agent id");
|
|
2073
|
-
if (!sessionId) throw new Error("Codex app-server binding requires a session id");
|
|
2074
|
-
const agentId = resolveSessionAgentIds$1({ agentId: rawAgentId }).sessionAgentId;
|
|
2075
|
-
const sessionKey = identity.sessionKey?.trim();
|
|
2076
|
-
if (sessionKey) return `session-key:${agentId}:${createHash("sha256").update(sessionKey).digest("base64url")}`;
|
|
2077
|
-
return `session:${agentId}:${sessionId}`;
|
|
2078
|
-
}
|
|
2079
|
-
const bindingId = identity.bindingId.trim();
|
|
2080
|
-
if (!bindingId) throw new Error("Codex app-server conversation binding requires a binding id");
|
|
2081
|
-
return `conversation:${bindingId}`;
|
|
2082
|
-
}
|
|
2083
|
-
function readStoredCodexAppServerBinding(value) {
|
|
2084
|
-
const result = storedBindingSchema.safeParse(value);
|
|
2085
|
-
return result.success ? stripUndefinedValue(result.data) : void 0;
|
|
2086
|
-
}
|
|
2087
|
-
function storedSessionGeneration(identity, current) {
|
|
2088
|
-
if (identity.kind === "session") return { sessionId: identity.sessionId };
|
|
2089
|
-
return current?.sessionId ? { sessionId: current.sessionId } : {};
|
|
2090
|
-
}
|
|
2091
|
-
function preservedSessionGeneration(identity, current) {
|
|
2092
|
-
if (current?.sessionId) return { sessionId: current.sessionId };
|
|
2093
|
-
return storedSessionGeneration(identity, current);
|
|
2094
|
-
}
|
|
2095
|
-
function ownsStoredSessionGeneration(identity, current) {
|
|
2096
|
-
return identity.kind !== "session" || !current?.sessionId || current.sessionId === identity.sessionId;
|
|
2097
|
-
}
|
|
2098
|
-
function validateBindingForWrite(binding) {
|
|
2099
|
-
const validated = readCodexAppServerThreadBinding(binding);
|
|
2100
|
-
if (!validated) throw new Error("Invalid Codex app-server thread binding");
|
|
2101
|
-
return stripUndefinedBinding(validated);
|
|
2102
|
-
}
|
|
2103
|
-
/** Parses stored or shipped sidecar data into the current domain value. */
|
|
2104
|
-
function readCodexAppServerThreadBinding(value) {
|
|
2105
|
-
const result = threadBindingSchema.safeParse(value);
|
|
2106
|
-
if (!result.success) return;
|
|
2107
|
-
return result.data;
|
|
2108
|
-
}
|
|
2109
|
-
function stripUndefinedBinding(binding) {
|
|
2110
|
-
return stripUndefinedValue(binding);
|
|
2111
|
-
}
|
|
2112
|
-
function stripUndefinedValue(value) {
|
|
2113
|
-
if (Array.isArray(value)) return value.map(stripUndefinedValue);
|
|
2114
|
-
if (!value || typeof value !== "object") return value;
|
|
2115
|
-
return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== void 0).map(([key, entry]) => [key, stripUndefinedValue(entry)]));
|
|
2116
|
-
}
|
|
2117
|
-
function asRecord(value) {
|
|
2118
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
2119
|
-
}
|
|
2120
|
-
function readTimestamp(value) {
|
|
2121
|
-
return optionalTimestampSchema.parse(value);
|
|
2122
|
-
}
|
|
2123
|
-
function readPluginAppPolicyContext(value, bindingSchemaVersion) {
|
|
2124
|
-
const record = asRecord(value);
|
|
2125
|
-
if (!record || typeof record.fingerprint !== "string") return;
|
|
2126
|
-
const apps = asRecord(record.apps);
|
|
2127
|
-
if (!apps) return;
|
|
2128
|
-
const parsedApps = {};
|
|
2129
|
-
for (const [appId, rawEntry] of Object.entries(apps)) {
|
|
2130
|
-
const entry = asRecord(rawEntry);
|
|
2131
|
-
if (!entry) return;
|
|
2132
|
-
const destructiveApprovalMode = readDestructiveApprovalMode(entry.destructiveApprovalMode, bindingSchemaVersion);
|
|
2133
|
-
const mcpServerNamesValid = Array.isArray(entry.mcpServerNames) && entry.mcpServerNames.every((serverName) => typeof serverName === "string");
|
|
2134
|
-
if (entry.source === "account") {
|
|
2135
|
-
if ("appId" in entry || typeof entry.appName !== "string" || typeof entry.allowDestructiveActions !== "boolean" || destructiveApprovalMode === "invalid" || !mcpServerNamesValid) return;
|
|
2136
|
-
parsedApps[appId] = {
|
|
2137
|
-
source: "account",
|
|
2138
|
-
appName: entry.appName,
|
|
2139
|
-
allowDestructiveActions: entry.allowDestructiveActions,
|
|
2140
|
-
...destructiveApprovalMode ? { destructiveApprovalMode } : {},
|
|
2141
|
-
mcpServerNames: entry.mcpServerNames
|
|
2142
|
-
};
|
|
2143
|
-
continue;
|
|
2144
|
-
}
|
|
2145
|
-
if ("appId" in entry || entry.source !== void 0 && entry.source !== "plugin" || typeof entry.configKey !== "string" || entry.marketplaceName !== "openai-curated" && entry.marketplaceName !== "workspace-directory" || typeof entry.pluginName !== "string" || typeof entry.allowDestructiveActions !== "boolean" || destructiveApprovalMode === "invalid" || !mcpServerNamesValid) return;
|
|
2146
|
-
parsedApps[appId] = {
|
|
2147
|
-
configKey: entry.configKey,
|
|
2148
|
-
marketplaceName: entry.marketplaceName,
|
|
2149
|
-
pluginName: entry.pluginName,
|
|
2150
|
-
allowDestructiveActions: entry.allowDestructiveActions,
|
|
2151
|
-
...destructiveApprovalMode ? { destructiveApprovalMode } : {},
|
|
2152
|
-
mcpServerNames: entry.mcpServerNames
|
|
2153
|
-
};
|
|
2154
|
-
}
|
|
2155
|
-
const parsedPluginAppIds = {};
|
|
2156
|
-
if (record.pluginAppIds !== void 0 && (!record.pluginAppIds || typeof record.pluginAppIds !== "object" || Array.isArray(record.pluginAppIds))) return;
|
|
2157
|
-
if (record.pluginAppIds && typeof record.pluginAppIds === "object") for (const [configKey, appIds] of Object.entries(record.pluginAppIds)) {
|
|
2158
|
-
if (!Array.isArray(appIds) || appIds.some((appId) => typeof appId !== "string")) return;
|
|
2159
|
-
parsedPluginAppIds[configKey] = appIds;
|
|
2160
|
-
}
|
|
2161
|
-
return {
|
|
2162
|
-
fingerprint: record.fingerprint,
|
|
2163
|
-
apps: parsedApps,
|
|
2164
|
-
pluginAppIds: parsedPluginAppIds
|
|
2165
|
-
};
|
|
2166
|
-
}
|
|
2167
|
-
function readDestructiveApprovalMode(value, bindingSchemaVersion) {
|
|
2168
|
-
if (value === void 0) return;
|
|
2169
|
-
if (value === "allow" || value === "deny") return value;
|
|
2170
|
-
if (value === "auto") return bindingSchemaVersion === 1 ? "allow" : "auto";
|
|
2171
|
-
if (value === "ask" && bindingSchemaVersion === 2) return "ask";
|
|
2172
|
-
if (value === "on-request" && bindingSchemaVersion === 1) return "auto";
|
|
2173
|
-
return "invalid";
|
|
2174
|
-
}
|
|
2175
|
-
function sleep(ms) {
|
|
2176
|
-
return new Promise((resolve) => {
|
|
2177
|
-
setTimeout(resolve, ms);
|
|
2178
|
-
});
|
|
2179
|
-
}
|
|
2180
|
-
/** Returns true when an auth profile uses native Codex/OpenAI app-server auth. */
|
|
2181
|
-
function isCodexAppServerNativeAuthProfile(lookup) {
|
|
2182
|
-
const authProfileId = lookup.authProfileId?.trim();
|
|
2183
|
-
if (!authProfileId) return false;
|
|
2184
|
-
try {
|
|
2185
|
-
const credential = (lookup.authProfileStore ?? ensureAuthProfileStore(lookup.agentDir?.trim() || resolveDefaultAgentDir(lookup.config ?? {}), {
|
|
2186
|
-
allowKeychainPrompt: false,
|
|
2187
|
-
config: lookup.config,
|
|
2188
|
-
externalCliProviderIds: [CODEX_APP_SERVER_NATIVE_AUTH_PROVIDER],
|
|
2189
|
-
externalCliProfileIds: [authProfileId]
|
|
2190
|
-
})).profiles[authProfileId];
|
|
2191
|
-
if (!credential || credential.type === "api_key") return false;
|
|
2192
|
-
const provider = credential.provider?.trim();
|
|
2193
|
-
return Boolean(provider && resolveProviderIdForAuth(provider, { config: lookup.config }) === CODEX_APP_SERVER_NATIVE_AUTH_PROVIDER);
|
|
2194
|
-
} catch (error) {
|
|
2195
|
-
embeddedAgentLog.debug("failed to resolve codex app-server auth profile provider", {
|
|
2196
|
-
authProfileId,
|
|
2197
|
-
error
|
|
2198
|
-
});
|
|
2199
|
-
return false;
|
|
2200
|
-
}
|
|
2201
|
-
}
|
|
2202
|
-
/** Hides redundant OpenAI provider attribution for native Codex auth bindings. */
|
|
2203
|
-
function normalizeCodexAppServerBindingModelProvider(params) {
|
|
2204
|
-
const modelProvider = params.modelProvider?.trim();
|
|
2205
|
-
if (!modelProvider) return;
|
|
2206
|
-
if (isCodexAppServerNativeAuthProfile(params) && modelProvider.toLowerCase() === PUBLIC_OPENAI_MODEL_PROVIDER) return;
|
|
2207
|
-
return modelProvider;
|
|
2208
|
-
}
|
|
2209
|
-
/** Restores the sole provider intentionally omitted from canonical binding rows. */
|
|
2210
|
-
function resolveCodexAppServerBindingModelProvider(params) {
|
|
2211
|
-
return params.modelProvider?.trim() || (isCodexAppServerNativeAuthProfile(params) ? PUBLIC_OPENAI_MODEL_PROVIDER : void 0);
|
|
2212
|
-
}
|
|
2213
|
-
//#endregion
|
|
2214
|
-
export { resolveOpenClawExecPolicyForCodexAppServer as A, canUseCodexModelBackedApprovalsReviewerForModel as C, isCodexSandboxExecServerEnabled as D, isCodexAppServerApprovalPolicyAllowedByRequirements as E, CODEX_PLUGINS_MARKETPLACE_NAME as M, CODEX_PLUGINS_WORKSPACE_MARKETPLACE_NAME as N, readCodexPluginConfig as O, withMcpElicitationsApprovalPolicy as S, resolveCodexModelBackedReviewerPolicyContext as T, resolveCodexAppServerStartOptionsForAgent as _, hashCodexAppServerBindingFingerprint as a, assertCodexAppServerConnectionSecurity as b, reclaimCurrentCodexSessionGeneration as c, sessionBindingIdentity as d, session_binding_exports as f, resolveCodexAppServerRuntimeOptions as g, resolveCodexAppServerHomeScope as h, createCodexSessionGenerationSupersededError as i, isCodexFastServiceTier as j, resolveCodexPluginsPolicy as k, resolveCodexRunSessionBindingAuthority as l, codexSandboxPolicyForTurn as m, assertCodexBindingMayBeReplaced as n, isCodexAppServerNativeAuthProfile as o, codexAppServerStartOptionsKey as p, bindingStoreKey as r, normalizeCodexAppServerBindingModelProvider as s, CODEX_APP_SERVER_BINDING_GUARDED_REQUEST_TIMEOUT_MS as t, scopeCodexRunBindingStore as u, resolveCodexComputerUseConfig as v, resolveCodexAppServerUserHomeDir as w, shouldAutoApproveCodexAppServerApprovals as x, resolveCodexSupervisionAppServerRuntimeOptions as y };
|
|
1335
|
+
export { resolveOpenClawExecPolicyForCodexAppServer as A, parseAllowedApprovalPoliciesFromCodexRequirements as C, selectGuardianApprovalPolicy as D, readCodexRequirementsToml as E, isCodexFastServiceTier as M, normalizeCodexServiceTier as N, selectGuardianApprovalsReviewer as O, resolveCodexModelBackedReviewerPolicyContext as S, parseAllowedSandboxModesFromCodexRequirements as T, CODEX_PLUGINS_MARKETPLACE_NAME as _, resolveCodexAppServerStartOptionsForAgent as a, canUseCodexModelBackedApprovalsReviewerForModel as b, assertCodexAppServerConnectionSecurity as c, withMcpElicitationsApprovalPolicy as d, isCodexPairedNodeRemoteExecPlacementSandbox as f, resolveCodexPluginsPolicy as g, readCodexPluginConfig as h, resolveCodexAppServerRuntimeOptions as i, selectGuardianSandbox as j, selectUserApprovalsReviewer as k, resolveCodexAppServerNetworkProxy as l, isCodexSandboxExecServerEnabled as m, codexSandboxPolicyForTurn as n, resolveCodexComputerUseConfig as o, isCodexRemoteExecPlacementSandbox as p, resolveCodexAppServerHomeScope as r, resolveCodexSupervisionAppServerRuntimeOptions as s, codexAppServerStartOptionsKey as t, shouldAutoApproveCodexAppServerApprovals as u, CODEX_PLUGINS_WORKSPACE_MARKETPLACE_NAME as v, parseAllowedApprovalsReviewersFromCodexRequirements as w, resolveCodexAppServerUserHomeDir as x, CODEX_PLUGIN_MARKETPLACE_NAME_PATTERN as y };
|