@openclaw/codex 2026.9.1 → 2026.9.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.
Files changed (109) hide show
  1. package/README.md +2 -0
  2. package/dist/api.js +18 -23
  3. package/dist/apply-B6el6hdO.js +357 -0
  4. package/dist/{attempt-client-cleanup-DYHcRQAa.js → attempt-client-cleanup-D6cR54TV.js} +113 -49
  5. package/dist/{attempt-context-DmQUNWwT.js → attempt-context-AO4DSjE0.js} +11 -9
  6. package/dist/{event-projector-usage-C5mcrGjp.js → attempt-notifications--H8zXR5-.js} +3 -89
  7. package/dist/auth-cache-key-Kq6oerr6.js +498 -0
  8. package/dist/auth-profile-CwzO4_RG.js +43 -0
  9. package/dist/auth-profile-selection-DFu9e167.js +45 -0
  10. package/dist/{binding-connection-E6uDsPlx.js → binding-connection-QqgcPCgk.js} +18 -3
  11. package/dist/{bounded-turn-wzJrwKKe.js → bounded-turn-lRpmZHFv.js} +54 -150
  12. package/dist/build-state-6RL6qohz.js +19 -0
  13. package/dist/{capabilities-dIjNVCYH.js → capabilities-BeqLPbtM.js} +2 -1
  14. package/dist/cli-metadata.js +1 -1
  15. package/dist/client-BEKu4yDx.js +3983 -0
  16. package/dist/command-dispatch-CisT9Jqq.js +21 -0
  17. package/dist/{command-formatters-CLHhEB1Q.js → command-formatters-DeTfrapr.js} +2 -2
  18. package/dist/{command-handlers-CTGb2csu.js → command-handlers-BfIsJEuA.js} +158 -76
  19. package/dist/command-rpc-BMqRQOFX.js +226 -0
  20. package/dist/{compact-_t0HQrUS.js → compact-CGJZ2rlb.js} +89 -49
  21. package/dist/config-JDfTI4VI.js +106 -0
  22. package/dist/{config-BhmfC1s6.js → config-options-jnIFvwxD.js} +208 -654
  23. package/dist/config-runtime-BWf6JLWG.js +11 -0
  24. package/dist/config-utils-C57JiJrU.js +69 -0
  25. package/dist/conversation-binding-CxOlHiix.js +889 -0
  26. package/dist/{plugin-marketplace-discovery-CfFlKqDl.js → conversation-control-CUCrSIQI.js} +36 -155
  27. package/dist/doctor-contract-api.js +8 -9
  28. package/dist/{dynamic-tools-BU9tmlYm.js → dynamic-tools-D-JBoaLt.js} +734 -698
  29. package/dist/{effective-mcp-catalog-DzYBW4h1.js → effective-mcp-catalog-J_5Ep5Um.js} +4 -3
  30. package/dist/{elicitation-input-DMkeki8d.js → elicitation-input-DPoK8F7w.js} +8 -22
  31. package/dist/ephemeral-turn-DSwzP8YY.js +101 -0
  32. package/dist/{event-projector-assistant-message-DHRFXKbS.js → event-projector-assistant-message-BmBM4qBV.js} +23 -27
  33. package/dist/event-projector-usage-CIyrYYid.js +102 -0
  34. package/dist/{harness-DXVZ5II5.js → harness-FR6eQgyO.js} +47 -17
  35. package/dist/harness.js +1 -1
  36. package/dist/history-rejection-B4nOXNXF.js +13 -0
  37. package/dist/{image-payload-sanitizer-CnfoUPCE.js → image-payload-sanitizer-tupAr-2o.js} +29 -15
  38. package/dist/incognito-session-uhrBF6wJ.js +15 -0
  39. package/dist/index.js +413 -2893
  40. package/dist/{isolated-completion-kg9kv4iH.js → isolated-completion-DHBefrzg.js} +12 -21
  41. package/dist/{managed-binary-4-Vjz5GH.js → managed-binary-DrjjRRUD.js} +17 -84
  42. package/dist/managed-thread-store-D1t5jh3G.js +66 -0
  43. package/dist/media-understanding-provider.js +4 -1
  44. package/dist/{model-catalog-CUM68Hkl.js → model-catalog-B_6M04Wo.js} +6 -5
  45. package/dist/{models-sYnEc0gd.js → models-P9k2qAof.js} +4 -4
  46. package/dist/native-execution-policy-umd0tgh4.js +128 -0
  47. package/dist/{native-subagent-monitor-CnH147jH.js → native-subagent-monitor-BbCUKRwC.js} +76 -48
  48. package/dist/node-cli-sessions-rj0ysJwM.js +527 -0
  49. package/dist/{node-exec-server.runtime-CstNHCmC.js → node-exec-server.runtime-BY_ctYnT.js} +54 -23
  50. package/dist/plan-BMJdMOEF.js +711 -0
  51. package/dist/plugin-activation-BQK-f5sV.js +133 -0
  52. package/dist/{thread-resume-C7pyVKeW.js → plugin-app-cache-key-CdSQzWyX.js} +5 -53
  53. package/dist/{plugin-approval-roundtrip-CNe-Xrjx.js → plugin-approval-roundtrip-DeW95wB5.js} +1 -1
  54. package/dist/plugin-inventory-CoRCzWW4.js +325 -0
  55. package/dist/plugin-marketplace-discovery-3akBizzF.js +134 -0
  56. package/dist/{plugin-metadata-cache-BFrPhb2c.js → plugin-metadata-cache-DgNfRAGA.js} +13 -9
  57. package/dist/protocol-CAAcVIKF.js +275 -0
  58. package/dist/{provider-capabilities-DW5p4k9w.js → provider-capabilities-W4tfK5Y5.js} +2 -2
  59. package/dist/{rate-limits-CawQJfUS.js → rate-limits-Bqnx1N4z.js} +1 -1
  60. package/dist/request-CGvGOpeR.js +198 -0
  61. package/dist/{run-attempt-D1hJO4fX.js → run-attempt-DwKds3DN.js} +1498 -1028
  62. package/dist/{runtime-artifact-C3jVimFn.js → runtime-artifact-T-NwqeSH.js} +28 -28
  63. package/dist/sandbox-guard-BcT66fWy.js +165 -0
  64. package/dist/{session-binding-BHuTCRZQ.js → session-binding-CKSepwIC.js} +118 -324
  65. package/dist/session-binding-record-CaZjYwNS.js +256 -0
  66. package/dist/session-catalog-HaDcp7Sv.js +1533 -0
  67. package/dist/session-catalog-adoption-BKLtSrwi.js +251 -0
  68. package/dist/session-catalog-archive-D0i2pGj2.js +56 -0
  69. package/dist/session-catalog-home-id-D7-aLiNt.js +190 -0
  70. package/dist/session-catalog-node-adoption-BUuDYY8R.js +182 -0
  71. package/dist/session-catalog-node-continue-CBtc4wkI.js +238 -0
  72. package/dist/session-catalog-parsing-CdD3JhdM.js +280 -0
  73. package/dist/session-catalog-provenance-DkJHo735.js +124 -0
  74. package/dist/{session-cli-CmFEXMAM.js → session-cli-CbgaHh0f.js} +3 -2
  75. package/dist/session-history-Cz-tOOYj.js +96 -0
  76. package/dist/{session-upstream-marker-C351-5Qw.js → session-history-import-DFN7sWRU.js} +5 -49
  77. package/dist/session-history-read-cxPUxyVV.js +50 -0
  78. package/dist/session-history-worker-runtime.js +60 -0
  79. package/dist/{settled-turn-context-D3SNWtUn.js → session-history.worker-CNEvGaU5.js} +75 -69
  80. package/dist/session-history.worker.js +2 -0
  81. package/dist/{session-initialization-BeWzjGiR.js → session-initialization-Jo86C60I.js} +2 -1
  82. package/dist/{session-permission-policy-DeWVTCMj.js → session-permission-policy-B22InTp_.js} +4 -7
  83. package/dist/{session-retirement-BujDjXVF.js → session-retirement-BSNG_mhf.js} +8 -7
  84. package/dist/session-upstream-marker-D15C9NHp.js +46 -0
  85. package/dist/settled-turn-context-Du6gdUDd.js +45 -0
  86. package/dist/{settled-turn-finalizer-BVJx4yoc.js → settled-turn-finalizer-BuLUrZl2.js} +54 -42
  87. package/dist/shared-client-CVhez2Uo.js +2911 -0
  88. package/dist/{side-question-BTZAII4l.js → side-question-DLbr2vUU.js} +135 -191
  89. package/dist/source-Da-h6f7e.js +518 -0
  90. package/dist/thread-archive-guard-D1bP04Tf.js +53 -0
  91. package/dist/{thread-lifecycle-DAcEJ_Om.js → thread-lifecycle-D1pzRwHB.js} +467 -977
  92. package/dist/{thread-ownership-zGokd8i1.js → thread-ownership-D6oASVRu.js} +15 -17
  93. package/dist/{thread-policy-g4KbJPzp.js → thread-policy-D8kI7yAO.js} +2 -2
  94. package/dist/thread-resume-T5cveyxA.js +52 -0
  95. package/dist/timeout-BVw8aaM1.js +33 -0
  96. package/dist/transcript-mirror-attestation-DibE0krH.js +89 -0
  97. package/dist/{transcript-mirror-DTUxFWa_.js → transcript-mirror-t5TOccct.js} +111 -379
  98. package/dist/{transport-stdio-CyPldczm.js → transport-stdio-BGjHoYLr.js} +80 -48
  99. package/dist/{upstream-session-fork-CYlBIGVt.js → upstream-session-fork-De-sLJ2r.js} +94 -166
  100. package/dist/{usage-Bj-rrzkR.js → usage-CPPTmBvZ.js} +4 -3
  101. package/dist/version-omm6IPI3.js +12 -0
  102. package/dist/{web-search-provider.runtime-D2FWSK4w.js → web-search-provider.runtime-CSVgQL0w.js} +3 -3
  103. package/openclaw.plugin.json +22 -1
  104. package/package.json +6 -6
  105. package/dist/request-DYAI5FQE.js +0 -475
  106. package/dist/session-catalog-yyvTWFOw.js +0 -3120
  107. package/dist/session-history-C5J1AKzG.js +0 -87
  108. package/dist/shared-client-DxcfF9KX.js +0 -7494
  109. package/dist/{auth-binding-Ds_QVm-X.js → auth-binding-Co2Vfcf_.js} +1 -1
@@ -1,475 +0,0 @@
1
- import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
- import { Nt as withTimeout, c as getLeasedSharedCodexAppServerClient, h as releaseLeasedSharedCodexAppServerClient, s as createIsolatedCodexAppServerClient, u as isCodexAppServerStartSelectionChangedError, y as retireSharedCodexAppServerClientIfCurrent } from "./shared-client-DxcfF9KX.js";
3
- import { w as isCodexRemoteExecPlacementSandbox } from "./config-BhmfC1s6.js";
4
- import { resolveAgentConfig, tryResolveDefaultAgentId } from "openclaw/plugin-sdk/agent-scope-runtime";
5
- import { getSessionEntry } from "openclaw/plugin-sdk/session-store-runtime";
6
- import { normalizeAgentId, parseAgentSessionKey } from "openclaw/plugin-sdk/routing";
7
- import { resolveSandboxRuntimeStatus } from "openclaw/plugin-sdk/sandbox";
8
- //#region extensions/codex/src/app-server/native-execution-policy.ts
9
- /** Projects node execution ownership into the runtime tool factory options. */
10
- function resolveCodexNodeExecToolOverrides(policy) {
11
- if (policy.effectiveExecHost !== "node") return;
12
- const node = policy.node?.trim();
13
- return {
14
- host: "node",
15
- ...node ? { node } : {}
16
- };
17
- }
18
- /** Resolves node/gateway/sandbox execution ownership from overrides, session, agent, and config. */
19
- function resolveCodexNativeExecutionPolicy(params) {
20
- const config = params.config ?? {};
21
- const sessionKey = params.sessionKey?.trim() || params.sessionId?.trim() || void 0;
22
- const agentId = resolvePolicyAgentId({
23
- config,
24
- sessionKey,
25
- agentId: params.agentId
26
- });
27
- const canReadSessionEntry = Boolean(agentId) && params.readRuntimeSessionEntry && shouldReadRuntimeSessionEntry({
28
- config,
29
- sessionKey,
30
- agentId
31
- });
32
- const sessionEntry = params.sessionEntry ?? (canReadSessionEntry && sessionKey && agentId ? readRuntimeSessionEntryBestEffort({
33
- sessionKey,
34
- agentId
35
- }) : void 0);
36
- const sandboxAgentId = parseAgentSessionKey(sessionKey)?.agentId ?? agentId;
37
- const sandboxAvailable = params.sandboxAvailable ?? (sessionKey && sandboxAgentId ? resolveSandboxRuntimeStatus({
38
- cfg: config,
39
- sessionKey,
40
- agentId: sandboxAgentId,
41
- classificationAgentId: sandboxAgentId
42
- }).sandboxed : false);
43
- const agentExec = agentId ? resolvePolicyAgentExec({
44
- config,
45
- agentId
46
- }) : void 0;
47
- const globalExec = config.tools?.exec;
48
- const requestedExecHost = normalizeExecTarget(params.execOverrides?.host) ?? normalizeExecTarget(sessionEntry?.execHost) ?? normalizeExecTarget(agentExec?.host) ?? normalizeExecTarget(globalExec?.host) ?? "auto";
49
- const effectiveExecHost = resolveEffectiveExecHost({
50
- requestedExecHost,
51
- sandboxAvailable
52
- });
53
- const node = params.execOverrides?.node ?? sessionEntry?.execNode ?? agentExec?.node ?? globalExec?.node;
54
- if (effectiveExecHost !== "node") return {
55
- nativeToolSurfaceAllowed: true,
56
- requestedExecHost,
57
- effectiveExecHost,
58
- node
59
- };
60
- return {
61
- nativeToolSurfaceAllowed: false,
62
- requestedExecHost,
63
- effectiveExecHost,
64
- node,
65
- blockReason: "OpenClaw exec host=node is active for this session. Codex app-server native execution cannot route shell, filesystem, MCP, or app-backed work through the selected OpenClaw node."
66
- };
67
- }
68
- /** Formats the user-facing explanation shown when native tools are blocked by exec host=node. */
69
- function formatCodexNativeNodeExecBlock(params) {
70
- return [
71
- `Codex-native ${params.surface} is unavailable because OpenClaw exec host=node is active for this session.`,
72
- params.reason ?? "Codex app-server native execution cannot route execution through the selected OpenClaw node.",
73
- "Use a normal Codex harness turn so OpenClaw exec/process tools run on the node, or switch exec host to gateway for native Codex app-server execution."
74
- ].join(" ");
75
- }
76
- function resolvePolicyAgentId(params) {
77
- const explicitAgentId = normalizeAgentIdOrDefault(params.agentId);
78
- if (explicitAgentId) return explicitAgentId;
79
- const sessionAgentId = parseAgentIdFromSessionKey(params.sessionKey);
80
- if (sessionAgentId) return sessionAgentId;
81
- return tryResolveDefaultAgentId(params.config);
82
- }
83
- function resolvePolicyAgentExec(params) {
84
- return resolveAgentConfig(params.config, params.agentId)?.tools?.exec;
85
- }
86
- function parseAgentIdFromSessionKey(sessionKey) {
87
- const raw = sessionKey?.trim();
88
- if (!raw) return;
89
- const parts = raw.toLowerCase().split(":").filter(Boolean);
90
- if (parts.length < 3 || parts[0] !== "agent" || !parts[2]) return;
91
- return normalizeAgentIdOrDefault(parts[1]);
92
- }
93
- function shouldReadRuntimeSessionEntry(params) {
94
- if (!params.sessionKey) return false;
95
- const explicitAgentId = normalizeAgentIdOrDefault(params.agentId);
96
- if (!explicitAgentId) return true;
97
- const sessionAgentId = parseAgentIdFromSessionKey(params.sessionKey);
98
- if (!sessionAgentId) return isDefaultAgentSessionKeyForAgent({
99
- config: params.config,
100
- agentId: explicitAgentId
101
- });
102
- return sessionAgentId === explicitAgentId;
103
- }
104
- function isDefaultAgentSessionKeyForAgent(params) {
105
- return normalizeAgentId(params.agentId) === tryResolveDefaultAgentId(params.config);
106
- }
107
- function normalizeAgentIdOrDefault(value) {
108
- const normalized = normalizeAgentId(value);
109
- return normalized === "main" && !(value ?? "").trim() ? void 0 : normalized;
110
- }
111
- function normalizeExecTarget(value) {
112
- const normalized = value?.trim().toLowerCase();
113
- if (normalized === "auto" || normalized === "sandbox" || normalized === "gateway" || normalized === "node") return normalized;
114
- }
115
- function resolveEffectiveExecHost(params) {
116
- if (params.requestedExecHost === "auto") return params.sandboxAvailable ? "sandbox" : "gateway";
117
- return params.requestedExecHost;
118
- }
119
- function readRuntimeSessionEntryBestEffort(params) {
120
- try {
121
- return getSessionEntry({
122
- sessionKey: params.sessionKey,
123
- agentId: params.agentId,
124
- hydrateSkillPromptRefs: false
125
- });
126
- } catch {
127
- return;
128
- }
129
- }
130
- //#endregion
131
- //#region extensions/codex/src/app-server/sandbox-guard.ts
132
- /**
133
- * Blocks direct Codex app-server requests that would bypass OpenClaw sandbox or
134
- * node-exec routing guarantees.
135
- */
136
- const DIRECT_METHOD_POLICIES = /* @__PURE__ */ new Map([
137
- ["account/rateLimits/read", "allowed-control-plane"],
138
- ["account/read", "allowed-control-plane"],
139
- ["app/installed", "allowed-control-plane"],
140
- ["app/list", "allowed-control-plane"],
141
- ["app/read", "allowed-control-plane"],
142
- ["config/batchWrite", "allowed-control-plane"],
143
- ["config/mcpServer/reload", "allowed-control-plane"],
144
- ["config/read", "allowed-control-plane"],
145
- ["config/value/write", "allowed-control-plane"],
146
- ["environment/add", "allowed-control-plane"],
147
- ["experimentalFeature/enablement/set", "allowed-control-plane"],
148
- ["feedback/upload", "allowed-control-plane"],
149
- ["hooks/list", "allowed-control-plane"],
150
- ["initialize", "allowed-control-plane"],
151
- ["marketplace/add", "allowed-control-plane"],
152
- ["mcpServerStatus/list", "allowed-control-plane"],
153
- ["model/list", "allowed-control-plane"],
154
- ["plugin/install", "allowed-control-plane"],
155
- ["plugin/installed", "allowed-control-plane"],
156
- ["plugin/list", "allowed-control-plane"],
157
- ["plugin/read", "allowed-control-plane"],
158
- ["skills/list", "allowed-control-plane"],
159
- ["thread/archive", "allowed-control-plane"],
160
- ["thread/inject_items", "allowed-control-plane"],
161
- ["thread/list", "allowed-control-plane"],
162
- ["thread/metadata/update", "allowed-control-plane"],
163
- ["thread/name/set", "allowed-control-plane"],
164
- ["thread/read", "allowed-control-plane"],
165
- ["thread/rollback", "allowed-control-plane"],
166
- ["thread/start", "requires-openclaw-environment"],
167
- ["thread/unarchive", "allowed-control-plane"],
168
- ["thread/unsubscribe", "allowed-control-plane"],
169
- ["turn/interrupt", "allowed-control-plane"],
170
- ["turn/steer", "allowed-control-plane"],
171
- ["command/exec", "blocked-native-bypass"],
172
- ["command/resize", "blocked-native-bypass"],
173
- ["command/terminate", "blocked-native-bypass"],
174
- ["command/write", "blocked-native-bypass"],
175
- ["fuzzyFileSearch", "blocked-native-bypass"],
176
- ["mcpServer/resource/read", "blocked-native-bypass"],
177
- ["mcpServer/tool/call", "blocked-native-bypass"],
178
- ["process/kill", "blocked-native-bypass"],
179
- ["process/resizePty", "blocked-native-bypass"],
180
- ["process/spawn", "blocked-native-bypass"],
181
- ["process/writeStdin", "blocked-native-bypass"],
182
- ["review/start", "blocked-native-bypass"],
183
- ["thread/compact/start", "blocked-native-bypass"],
184
- ["thread/fork", "blocked-native-bypass"],
185
- ["thread/resume", "blocked-native-bypass"],
186
- ["thread/shellCommand", "blocked-native-bypass"],
187
- ["turn/start", "blocked-native-bypass"]
188
- ]);
189
- const BLOCKED_DIRECT_METHOD_PREFIXES = [
190
- "command/",
191
- "fs/",
192
- "windowsSandbox/"
193
- ];
194
- const NODE_EXEC_BLOCKED_CONTROL_PLANE_METHODS = /* @__PURE__ */ new Set(["config/mcpServer/reload"]);
195
- /** Returns a block message when a direct app-server method would bypass OpenClaw execution policy. */
196
- function resolveCodexAppServerDirectSandboxBypassBlock(params) {
197
- const policy = resolveDirectMethodPolicy(params.method);
198
- if (NODE_EXEC_BLOCKED_CONTROL_PLANE_METHODS.has(params.method)) {
199
- const nodeExecBlock = resolveCodexNativeNodeExecBlock({
200
- config: params.config,
201
- sessionKey: params.sessionKey,
202
- sessionId: params.sessionId,
203
- surface: `app-server method \`${params.method}\``
204
- });
205
- if (nodeExecBlock) return nodeExecBlock;
206
- }
207
- if (policy === "allowed-control-plane") return;
208
- const nodeExecBlock = resolveCodexNativeNodeExecBlock({
209
- config: params.config,
210
- sessionKey: params.sessionKey,
211
- sessionId: params.sessionId,
212
- surface: `app-server method \`${params.method}\``
213
- });
214
- if (nodeExecBlock) return nodeExecBlock;
215
- const sessionKey = params.sessionKey?.trim() || params.sessionId?.trim();
216
- if (!sessionKey) return;
217
- const sandboxBlock = resolveCodexNativeSandboxBlock({
218
- config: params.config,
219
- sessionKey,
220
- sandbox: params.sandbox,
221
- surface: `app-server method \`${params.method}\``
222
- });
223
- if (!sandboxBlock) return;
224
- if (policy === "requires-openclaw-environment" && hasOpenClawSandboxEnvironmentSelection(params.requestParams)) return;
225
- return sandboxBlock;
226
- }
227
- /** Resolves the generic native-execution block for sandboxed or node-hosted sessions. */
228
- function resolveCodexNativeExecutionBlock(params) {
229
- return resolveCodexNativeSandboxBlock(params) ?? resolveCodexNativeNodeExecBlock(params);
230
- }
231
- /** Returns a block message when native Codex execution cannot honor active sandboxing. */
232
- function resolveCodexNativeSandboxBlock(params) {
233
- if (params.sandboxEnvironmentSelected) return;
234
- const sessionKey = params.sessionKey?.trim() || params.sessionId?.trim();
235
- if (!sessionKey) return;
236
- if (isCodexRemoteExecPlacementSandbox(params.sandbox) || params.sandbox?.enabled === true) return formatCodexNativeSandboxBlock({ surface: params.surface });
237
- const sandboxAgentId = parseAgentSessionKey(sessionKey)?.agentId ?? params.agentId ?? tryResolveDefaultAgentId(params.config ?? {});
238
- if (!sandboxAgentId) return;
239
- if (!resolveSandboxRuntimeStatus({
240
- cfg: params.config,
241
- sessionKey,
242
- agentId: sandboxAgentId,
243
- classificationAgentId: sandboxAgentId
244
- }).sandboxed) return;
245
- return formatCodexNativeSandboxBlock({ surface: params.surface });
246
- }
247
- function resolveDirectMethodPolicy(method) {
248
- const exact = DIRECT_METHOD_POLICIES.get(method);
249
- if (exact) return exact;
250
- if (BLOCKED_DIRECT_METHOD_PREFIXES.some((prefix) => method.startsWith(prefix))) return "blocked-native-bypass";
251
- return "blocked-native-bypass";
252
- }
253
- function hasOpenClawSandboxEnvironmentSelection(value) {
254
- if (!value || typeof value !== "object" || Array.isArray(value)) return false;
255
- const environments = value.environments;
256
- return Array.isArray(environments) && environments.length > 0 && environments.every((entry) => {
257
- if (!entry || typeof entry !== "object" || Array.isArray(entry)) return false;
258
- const environment = entry;
259
- return typeof environment.environmentId === "string" && environment.environmentId.startsWith("openclaw-sandbox-") && typeof environment.cwd === "string" && environment.cwd.trim().length > 0;
260
- });
261
- }
262
- function formatCodexNativeSandboxBlock(params) {
263
- return [
264
- `Codex-native ${params.surface} is unavailable because OpenClaw sandboxing is active for this session.`,
265
- "This mode cannot route execution through the OpenClaw sandbox backend.",
266
- "Use a normal Codex harness turn, or run an intentionally unsandboxed session."
267
- ].join(" ");
268
- }
269
- function resolveCodexNativeNodeExecBlock(params) {
270
- const sessionKey = params.sessionKey?.trim() || params.sessionId?.trim();
271
- const policy = resolveCodexNativeExecutionPolicy({
272
- config: params.config,
273
- sessionKey,
274
- agentId: params.agentId,
275
- readRuntimeSessionEntry: Boolean(sessionKey)
276
- });
277
- if (policy.nativeToolSurfaceAllowed) return;
278
- return formatCodexNativeNodeExecBlock({
279
- surface: params.surface,
280
- reason: policy.blockReason
281
- });
282
- }
283
- //#endregion
284
- //#region extensions/codex/src/app-server/request.ts
285
- var request_exports = /* @__PURE__ */ __exportAll({
286
- CodexAppServerScopedRequestRejectedError: () => CodexAppServerScopedRequestRejectedError,
287
- readCodexAppServerUsage: () => readCodexAppServerUsage,
288
- requestCodexAppServerClientJson: () => requestCodexAppServerClientJson,
289
- requestCodexAppServerJson: () => requestCodexAppServerJson,
290
- withCodexAppServerJsonClient: () => withCodexAppServerJsonClient
291
- });
292
- /** Sends one guarded request over a client lease owned by the caller. */
293
- async function requestCodexAppServerClientJson(params) {
294
- const sandboxBlock = resolveCodexAppServerDirectSandboxBypassBlock({
295
- method: params.method,
296
- requestParams: params.requestParams,
297
- config: params.config,
298
- sessionKey: params.sessionKey,
299
- sessionId: params.sessionId
300
- });
301
- if (sandboxBlock) throw new Error(sandboxBlock);
302
- const timeoutMs = params.timeoutMs ?? 6e4;
303
- return await withTimeout(params.client.request(params.method, params.requestParams, {
304
- timeoutMs,
305
- signal: params.signal,
306
- ...params.assertCurrent ? { assertCurrent: () => assertRequestOwnerCurrent(params.assertCurrent) } : {}
307
- }), timeoutMs, `codex app-server ${params.method} timed out`);
308
- }
309
- async function requestCodexAppServerJson(params) {
310
- const sandboxBlock = resolveCodexAppServerDirectSandboxBypassBlock({
311
- method: params.method,
312
- requestParams: params.requestParams,
313
- config: params.config,
314
- sessionKey: params.sessionKey,
315
- sessionId: params.sessionId
316
- });
317
- if (sandboxBlock) throw new Error(sandboxBlock);
318
- return await withCodexAppServerJsonClient({
319
- ...params,
320
- timeoutMessage: `codex app-server ${params.method} timed out`
321
- }, async (request) => await request({
322
- method: params.method,
323
- requestParams: params.requestParams
324
- }));
325
- }
326
- /** A scoped guard rejected the request before a physical write. */
327
- var CodexAppServerScopedRequestRejectedError = class extends Error {
328
- constructor(message, options) {
329
- super(message, options);
330
- this.name = "CodexAppServerScopedRequestRejectedError";
331
- }
332
- };
333
- function assertRequestOwnerCurrent(assertCurrent) {
334
- try {
335
- assertCurrent?.();
336
- } catch (cause) {
337
- throw new CodexAppServerScopedRequestRejectedError(cause instanceof Error ? cause.message : String(cause), { cause });
338
- }
339
- }
340
- const CODEX_USAGE_ISOLATED_SHUTDOWN = {
341
- forceKillDelayMs: 200,
342
- exitTimeoutMs: 300
343
- };
344
- const CODEX_ACCOUNT_READ_MAX_TIMEOUT_MS = 4e3;
345
- const CODEX_USAGE_DEADLINE_RESERVE_MS = CODEX_USAGE_ISOLATED_SHUTDOWN.forceKillDelayMs + CODEX_USAGE_ISOLATED_SHUTDOWN.exitTimeoutMs + 250;
346
- /** Reads rate limits and best-effort account identity from one isolated app-server session. */
347
- async function readCodexAppServerUsage(options) {
348
- const deadline = Date.now() + options.timeoutMs;
349
- return await withCodexAppServerJsonClient({
350
- timeoutMs: options.timeoutMs,
351
- timeoutMessage: "codex app-server usage read timed out",
352
- agentDir: options.agentDir,
353
- ...options.authProfileId ? { authProfileId: options.authProfileId } : {},
354
- config: options.config,
355
- startOptions: options.startOptions,
356
- isolated: true,
357
- isolatedShutdown: CODEX_USAGE_ISOLATED_SHUTDOWN
358
- }, async (request) => {
359
- const rateLimits = await request({ method: "account/rateLimits/read" });
360
- const accountEmail = await readCodexAccountEmailBestEffort(request, deadline);
361
- return {
362
- rateLimits,
363
- ...accountEmail ? { accountEmail } : {}
364
- };
365
- });
366
- }
367
- function extractCodexAccountEmail(value) {
368
- if (!value || typeof value !== "object") return;
369
- const record = value;
370
- const account = record.account && typeof record.account === "object" ? record.account : record;
371
- const email = account.email ?? account.accountEmail;
372
- return typeof email === "string" && email.trim() ? email.trim() : void 0;
373
- }
374
- async function readCodexAccountEmailBestEffort(request, deadline) {
375
- const boundMs = Math.min(CODEX_ACCOUNT_READ_MAX_TIMEOUT_MS, deadline - Date.now() - CODEX_USAGE_DEADLINE_RESERVE_MS);
376
- if (boundMs <= 0) return;
377
- const read = request({
378
- method: "account/read",
379
- requestParams: {}
380
- }).then((account) => extractCodexAccountEmail(account), () => void 0);
381
- let timer;
382
- const timeout = new Promise((resolve) => {
383
- timer = setTimeout(() => resolve(void 0), boundMs);
384
- timer.unref?.();
385
- });
386
- try {
387
- return await Promise.race([read, timeout]);
388
- } finally {
389
- if (timer) clearTimeout(timer);
390
- }
391
- }
392
- /**
393
- * Runs several guarded requests over one acquired client (shared lease or
394
- * isolated child) so related reads see the same app-server session. The whole
395
- * callback re-runs once when the client's start selection changed underneath it.
396
- */
397
- async function withCodexAppServerJsonClient(params, run) {
398
- const timeoutMs = params.timeoutMs ?? 6e4;
399
- const timeoutMessage = params.timeoutMessage ?? "codex app-server request timed out";
400
- const timeoutController = new AbortController();
401
- const deadline = Number.isFinite(timeoutMs) && timeoutMs > 0 ? Date.now() + timeoutMs : void 0;
402
- const isPastDeadline = () => deadline !== void 0 && Date.now() >= deadline;
403
- const throwIfAbandoned = () => {
404
- if (timeoutController.signal.aborted || isPastDeadline()) throw new CodexAppServerScopedRequestRejectedError(timeoutMessage);
405
- };
406
- const remainingTimeoutMs = () => {
407
- throwIfAbandoned();
408
- return deadline === void 0 ? timeoutMs : Math.max(1, deadline - Date.now());
409
- };
410
- try {
411
- return await withTimeout((async () => {
412
- for (let attempt = 0; attempt < 2; attempt += 1) {
413
- throwIfAbandoned();
414
- const client = await (params.isolated ? createIsolatedCodexAppServerClient : getLeasedSharedCodexAppServerClient)({
415
- startOptions: params.startOptions,
416
- pluginConfig: params.pluginConfig,
417
- timeoutMs: remainingTimeoutMs(),
418
- authProfileId: params.authProfileId,
419
- authProfileStore: params.authProfileStore,
420
- authBindingFingerprint: params.authBindingFingerprint,
421
- preparedAuth: params.preparedAuth,
422
- authRequirement: params.authRequirement,
423
- agentDir: params.agentDir,
424
- config: params.config,
425
- abandonSignal: timeoutController.signal
426
- });
427
- let scopeActive = true;
428
- const assertCurrent = () => {
429
- throwIfAbandoned();
430
- if (!scopeActive) throw new CodexAppServerScopedRequestRejectedError("Codex app-server request scope is closed");
431
- assertRequestOwnerCurrent(params.assertCurrent);
432
- };
433
- try {
434
- assertCurrent();
435
- const scopedRequest = async (request) => {
436
- const sandboxBlock = resolveCodexAppServerDirectSandboxBypassBlock({
437
- method: request.method,
438
- requestParams: request.requestParams,
439
- config: params.config,
440
- sessionKey: params.sessionKey,
441
- sessionId: params.sessionId
442
- });
443
- if (sandboxBlock) throw new CodexAppServerScopedRequestRejectedError(sandboxBlock);
444
- assertCurrent();
445
- return await client.request(request.method, request.requestParams, {
446
- timeoutMs: remainingTimeoutMs(),
447
- signal: timeoutController.signal,
448
- assertCurrent
449
- });
450
- };
451
- return await run(scopedRequest, client, { assertCurrent });
452
- } catch (error) {
453
- if (!isCodexAppServerStartSelectionChangedError(error) || attempt > 0) throw error;
454
- if (!params.isolated) retireSharedCodexAppServerClientIfCurrent(client);
455
- throwIfAbandoned();
456
- } finally {
457
- scopeActive = false;
458
- if (params.isolated) await client.closeAndWait({
459
- exitTimeoutMs: params.isolatedShutdown?.exitTimeoutMs ?? 2e3,
460
- forceKillDelayMs: params.isolatedShutdown?.forceKillDelayMs ?? 250
461
- });
462
- else releaseLeasedSharedCodexAppServerClient(client);
463
- }
464
- }
465
- throw new Error("Codex app-server selection retry loop exited unexpectedly");
466
- })(), timeoutMs, timeoutMessage);
467
- } catch (error) {
468
- if (isPastDeadline()) throw new Error(timeoutMessage, { cause: error });
469
- throw error;
470
- } finally {
471
- timeoutController.abort();
472
- }
473
- }
474
- //#endregion
475
- export { request_exports as a, resolveCodexNativeSandboxBlock as c, requestCodexAppServerJson as i, resolveCodexNativeExecutionPolicy as l, readCodexAppServerUsage as n, withCodexAppServerJsonClient as o, requestCodexAppServerClientJson as r, resolveCodexNativeExecutionBlock as s, CodexAppServerScopedRequestRejectedError as t, resolveCodexNodeExecToolOverrides as u };