@openclaw/codex 2026.9.1-beta.1 → 2026.9.2

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 (81) hide show
  1. package/dist/api.js +8 -9
  2. package/dist/{attempt-client-cleanup-bfsmcQ6m.js → attempt-client-cleanup-Bp1ZOnk2.js} +105 -75
  3. package/dist/attempt-context-CSazkWns.js +634 -0
  4. package/dist/{auth-binding-B4FfbcCg.js → auth-binding-Ds_QVm-X.js} +18 -3
  5. package/dist/{bounded-turn-B7iBUcuP.js → bounded-turn-DxGJRYbY.js} +53 -57
  6. package/dist/{capabilities-BRMh0aIq.js → capabilities-B1mgvpP8.js} +2 -1
  7. package/dist/cli-metadata.js +1 -1
  8. package/dist/{command-formatters-DEsIufkt.js → command-formatters-DSbGMXA0.js} +5 -4
  9. package/dist/{command-handlers-D_-1_qRp.js → command-handlers-DOJvGv6-.js} +243 -148
  10. package/dist/{compact-BglNFZrQ.js → compact-Y_xBqrHN.js} +109 -65
  11. package/dist/{config-giW8X0QA.js → config-CyapYSji.js} +328 -374
  12. package/dist/config-utils-C57JiJrU.js +69 -0
  13. package/dist/{context-compaction-activity-BOeJf7yo.js → context-compaction-activity-CMla5FPJ.js} +4 -1
  14. package/dist/{conversation-binding-data-CW2GuupV.js → conversation-binding-data-BiodpIzq.js} +2 -1
  15. package/dist/doctor-contract-api.js +144 -14
  16. package/dist/{dynamic-tools-Dnlfa--w.js → dynamic-tools-BwpvTxaX.js} +1119 -1135
  17. package/dist/{effective-mcp-catalog-CTeGrnfO.js → effective-mcp-catalog-CY9Jn4bA.js} +4 -3
  18. package/dist/{event-projector-assistant-message-C5-Ds8mA.js → event-projector-assistant-message-B9kp6iGC.js} +15 -6
  19. package/dist/event-projector-usage-ZqEVbAEY.js +212 -0
  20. package/dist/{harness-Csz0F-DK.js → harness-Czh2Sdoc.js} +65 -52
  21. package/dist/harness.js +1 -1
  22. package/dist/{image-payload-sanitizer-CnfoUPCE.js → image-payload-sanitizer-tupAr-2o.js} +29 -15
  23. package/dist/index.js +495 -457
  24. package/dist/{isolated-completion-Cv6FqygM.js → isolated-completion-CRh-51AK.js} +9 -21
  25. package/dist/{managed-binary-DFYK4DWq.js → managed-binary-DcpnJF9x.js} +117 -80
  26. package/dist/media-understanding-provider.js +1 -1
  27. package/dist/model-catalog-DT5vo6qo.js +101 -0
  28. package/dist/{models-TS3HBU-q.js → models-CcrgSMQR.js} +26 -29
  29. package/dist/{native-subagent-monitor-4Mfq2HDs.js → native-subagent-monitor-B3bvQGcg.js} +63 -122
  30. package/dist/{node-exec-server.runtime-BpWqJO1V.js → node-exec-server.runtime-nfbUOtUB.js} +10 -7
  31. package/dist/{plugin-approval-roundtrip-bUm777tR.js → plugin-approval-roundtrip-aQVdyL5g.js} +30 -3
  32. package/dist/{plugin-marketplace-discovery-B9DvaAG-.js → plugin-marketplace-discovery-B7gHXJ3d.js} +44 -30
  33. package/dist/{plugin-metadata-cache-CTCT3w5L.js → plugin-metadata-cache-BwCLTY_U.js} +6 -6
  34. package/dist/provider-capabilities-BpG9Ltc5.js +101 -0
  35. package/dist/{rate-limits-C5_D8Gmb.js → rate-limits-Fx_l4eNa.js} +3 -2
  36. package/dist/{sandbox-guard-kuWTn9C5.js → request-C8H22rPi.js} +195 -2
  37. package/dist/{run-attempt-DYc0QCBF.js → run-attempt-BzthFQSM.js} +1616 -2634
  38. package/dist/{runtime-artifact-BvyT1uyd.js → runtime-artifact-Bh_gf6-t.js} +22 -15
  39. package/dist/{session-binding-Bcynfd-_.js → session-binding-4Ki04sW-.js} +282 -399
  40. package/dist/session-binding-record-CyaXZvTe.js +270 -0
  41. package/dist/{session-catalog-DaLKVtpH.js → session-catalog-B47uwekb.js} +812 -504
  42. package/dist/{session-cli-DMc4oS2w.js → session-cli-BjLhpmS1.js} +1 -1
  43. package/dist/session-history-DWmMqiqW.js +93 -0
  44. package/dist/session-history-read-LHldwvyh.js +36 -0
  45. package/dist/session-history-worker-runtime.js +48 -0
  46. package/dist/session-history.worker-zZVcx0ME.js +267 -0
  47. package/dist/session-history.worker.js +2 -0
  48. package/dist/session-initialization-BCFVnLL4.js +75 -0
  49. package/dist/{session-permission-policy-BrNH1bjy.js → session-permission-policy-BaueHmSj.js} +2 -2
  50. package/dist/session-retirement-DNdmYdFc.js +97 -0
  51. package/dist/{session-upstream-marker-BIkusb95.js → session-upstream-marker-DReTpGz6.js} +20 -4
  52. package/dist/settled-turn-context-BOM3Y1pl.js +45 -0
  53. package/dist/settled-turn-finalizer-BI-b1sry.js +115 -0
  54. package/dist/{shared-client-DKz23hHY.js → shared-client-CKhX2kFt.js} +3659 -847
  55. package/dist/{side-question-DjA_jsNe.js → side-question-B6DWAw1A.js} +168 -81
  56. package/dist/{thread-lifecycle-L7oEkTlq.js → thread-lifecycle-DPK30jad.js} +2412 -2145
  57. package/dist/{thread-ownership-DZeuKH1j.js → thread-ownership-CbucAmmp.js} +27 -16
  58. package/dist/thread-policy-CTalhWFy.js +105 -0
  59. package/dist/{plugin-app-cache-key-C1CAdfcP.js → thread-resume-BLgqkUc1.js} +61 -9
  60. package/dist/{transcript-mirror-DsCMWBca.js → transcript-mirror-_njEB84z.js} +114 -110
  61. package/dist/transcript-mirror-attestation-Byl34PC-.js +76 -0
  62. package/dist/transport-stdio-CzTngV0j.js +728 -0
  63. package/dist/{upstream-prompt-provenance-CFmsKwr9.js → upstream-prompt-provenance-LphB8slG.js} +8 -4
  64. package/dist/upstream-session-fork-1fwbNKzQ.js +886 -0
  65. package/dist/{usage-ROIaW3wo.js → usage-i9fv5-4m.js} +3 -3
  66. package/dist/{web-search-provider.runtime-ClaNPV7N.js → web-search-provider.runtime-DKQn67A7.js} +3 -3
  67. package/openclaw.plugin.json +1 -30
  68. package/package.json +6 -6
  69. package/dist/binding-connection-BMvPX73o.js +0 -45
  70. package/dist/command-rpc-CCeCkf_v.js +0 -90
  71. package/dist/event-projector-usage-Bk1I90Bg.js +0 -328
  72. package/dist/incognito-session-ET_ufDH-.js +0 -2
  73. package/dist/model-catalog-i9rNBthX.js +0 -48
  74. package/dist/protocol-validators-VeJxxJ0U.js +0 -2421
  75. package/dist/request-DXXGHko0.js +0 -157
  76. package/dist/session-catalog-home-id-BNwAJ9D7.js +0 -18
  77. package/dist/session-retirement-CcNC3YSY.js +0 -36
  78. package/dist/settled-turn-finalizer-Dc3ApjU4.js +0 -328
  79. package/dist/thread-resume-BE9qNEW0.js +0 -30
  80. package/dist/transport-stdio-DhoGy33Z.js +0 -99
  81. package/dist/upstream-session-fork-DlaHxSLC.js +0 -326
@@ -1,4 +1,4 @@
1
- import "./session-catalog-DaLKVtpH.js";
1
+ import "./session-catalog-B47uwekb.js";
2
2
  import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
3
3
  import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
4
4
  import { sanitizeTerminalText } from "openclaw/plugin-sdk/text-chunking";
@@ -0,0 +1,93 @@
1
+ import { n as readCodexNativeHistory, t as consumeCodexHistory } from "./session-history-read-LHldwvyh.js";
2
+ import { getSessionEntry, parseSqliteSessionFileMarker, resolveTranscriptSessionKeyBySessionId } from "openclaw/plugin-sdk/session-store-runtime";
3
+ import { SessionManager } from "openclaw/plugin-sdk/agent-sessions";
4
+ //#region extensions/codex/src/app-server/session-history.ts
5
+ function resolveCodexHistoryTarget(target, admission) {
6
+ if (target.sessionTarget) {
7
+ const { agentId, sessionId, sessionKey, storePath } = target.sessionTarget;
8
+ if (!agentId || !sessionId || !sessionKey || !storePath || sessionId !== target.sessionId || target.agentId !== void 0 && agentId !== target.agentId || target.sessionKey !== void 0 && sessionKey !== target.sessionKey) return { kind: "empty" };
9
+ return {
10
+ kind: "sqlite",
11
+ target: {
12
+ agentId,
13
+ sessionId,
14
+ sessionKey,
15
+ storePath
16
+ }
17
+ };
18
+ }
19
+ const sqliteMarker = parseSqliteSessionFileMarker(target.sessionFile);
20
+ if (sqliteMarker) {
21
+ if (sqliteMarker.sessionId !== target.sessionId || target.agentId !== void 0 && sqliteMarker.agentId !== target.agentId) return { kind: "empty" };
22
+ const sessionKey = resolveSqliteMarkerSessionKey(target, sqliteMarker);
23
+ return sessionKey ? {
24
+ kind: "sqlite",
25
+ target: {
26
+ agentId: sqliteMarker.agentId,
27
+ sessionId: sqliteMarker.sessionId,
28
+ sessionKey,
29
+ storePath: sqliteMarker.storePath
30
+ }
31
+ } : { kind: "empty" };
32
+ }
33
+ if (admission) {
34
+ if (admission.sessionId !== target.sessionId || target.agentId !== void 0 && admission.agentId !== target.agentId || target.sessionKey !== void 0 && admission.sessionKey !== target.sessionKey) return { kind: "empty" };
35
+ return {
36
+ kind: "sqlite",
37
+ target: {
38
+ agentId: admission.agentId,
39
+ sessionId: admission.sessionId,
40
+ sessionKey: admission.sessionKey,
41
+ storePath: admission.storePath
42
+ }
43
+ };
44
+ }
45
+ return {
46
+ kind: "file",
47
+ sessionFile: target.sessionFile
48
+ };
49
+ }
50
+ /** Returns sanitized session-context messages for consumers that need an owned array. */
51
+ async function readCodexMirroredSessionHistoryMessages(target, admission, view = "native-evidence", signal) {
52
+ signal?.throwIfAborted();
53
+ try {
54
+ let result;
55
+ if (view === "native-evidence") {
56
+ const { readCodexHistoryMessagesInWorker } = await import("./session-history-worker-runtime.js");
57
+ result = await readCodexHistoryMessagesInWorker(target, admission, signal);
58
+ } else {
59
+ const resolved = resolveCodexHistoryTarget(target, admission);
60
+ const read = (messages) => Array.from(messages);
61
+ if (resolved.kind === "sqlite") {
62
+ const loaded = await SessionManager.openModelContextAsync(resolved.target, {
63
+ admission,
64
+ signal
65
+ });
66
+ result = consumeCodexHistory(loaded.buildSessionContext().messages, loaded.getHeader(), target.sessionId, read, "codex mirrored model context");
67
+ } else result = await readCodexNativeHistory(resolved, target.sessionId, read, admission);
68
+ }
69
+ signal?.throwIfAborted();
70
+ return result;
71
+ } catch {
72
+ signal?.throwIfAborted();
73
+ return;
74
+ }
75
+ }
76
+ function resolveSqliteMarkerSessionKey(target, marker) {
77
+ const explicitSessionKey = target.sessionKey?.trim();
78
+ if (explicitSessionKey) {
79
+ const explicitEntry = getSessionEntry({
80
+ agentId: marker.agentId,
81
+ sessionKey: explicitSessionKey,
82
+ storePath: marker.storePath
83
+ });
84
+ if (explicitEntry) return explicitEntry.sessionId === marker.sessionId ? explicitSessionKey : void 0;
85
+ }
86
+ return resolveTranscriptSessionKeyBySessionId({
87
+ agentId: marker.agentId,
88
+ sessionId: marker.sessionId,
89
+ storePath: marker.storePath
90
+ });
91
+ }
92
+ //#endregion
93
+ export { resolveCodexHistoryTarget as n, readCodexMirroredSessionHistoryMessages as t };
@@ -0,0 +1,36 @@
1
+ import { n as sanitizeCodexHistoryImagePayloads } from "./image-payload-sanitizer-tupAr-2o.js";
2
+ import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
3
+ import fs from "node:fs/promises";
4
+ import { readCodexSessionContext } from "openclaw/plugin-sdk/codex-session-transcript-runtime";
5
+ //#region extensions/codex/src/app-server/session-history-read.ts
6
+ function consumeCodexHistory(messages, header, sessionId, read, imageLabel = "codex mirrored history") {
7
+ if (!isRecord(header) || header.type !== "session") return read([]);
8
+ if (typeof header.id !== "string") return;
9
+ if (header.id !== sessionId) return read([]);
10
+ return read((function* () {
11
+ for (const message of messages) yield sanitizeCodexHistoryImagePayloads(message, imageLabel);
12
+ })());
13
+ }
14
+ /** Keeps native evidence and its synchronous consumer inside the same readonly snapshot. */
15
+ async function readCodexNativeHistory(target, sessionId, read, admission, onSnapshot) {
16
+ const consume = (messages, header, version) => {
17
+ onSnapshot?.(version);
18
+ return consumeCodexHistory(messages, header, sessionId, read);
19
+ };
20
+ try {
21
+ if (target.kind === "empty") return read([]);
22
+ if (target.kind === "sqlite") return readCodexSessionContext(target.target, consume, admission);
23
+ const { buildSessionContext, migrateSessionEntries, parseSessionEntries } = await import("openclaw/plugin-sdk/agent-sessions");
24
+ const entries = parseSessionEntries(await fs.readFile(target.sessionFile, "utf-8"));
25
+ return consume((function* () {
26
+ migrateSessionEntries(entries);
27
+ const sessionEntries = entries.filter((entry) => isRecord(entry) && entry.type !== "session");
28
+ yield* buildSessionContext(sessionEntries).messages;
29
+ })(), entries[0]);
30
+ } catch (error) {
31
+ if (isRecord(error) && error.code === "ENOENT") return read([]);
32
+ return;
33
+ }
34
+ }
35
+ //#endregion
36
+ export { readCodexNativeHistory as n, consumeCodexHistory as t };
@@ -0,0 +1,48 @@
1
+ import { n as runCodexHistoryWorkerInput, t as codexHistoryWorkerUrl } from "./session-history.worker-zZVcx0ME.js";
2
+ import { n as resolveCodexHistoryTarget } from "./session-history-DWmMqiqW.js";
3
+ import { WorkerTaskPool } from "openclaw/plugin-sdk/process-runtime";
4
+ import { captureCodexSessionTranscriptReadAdmission, validateCodexSessionTranscriptContextVersion, validateCodexSessionTranscriptReadAdmission } from "openclaw/plugin-sdk/codex-session-transcript-runtime";
5
+ import { isIncognitoSessionKey } from "openclaw/plugin-sdk/session-key-runtime";
6
+ //#region extensions/codex/session-history-worker-runtime.ts
7
+ const historyReads = new WorkerTaskPool({
8
+ workerUrl: codexHistoryWorkerUrl,
9
+ maxWorkers: 1
10
+ });
11
+ async function readHistory(target, operation, admission, signal) {
12
+ signal?.throwIfAborted();
13
+ const resolved = resolveCodexHistoryTarget(target, admission);
14
+ const receipt = admission ?? (resolved.kind === "sqlite" ? captureCodexSessionTranscriptReadAdmission(resolved.target) : void 0);
15
+ const input = {
16
+ ...operation,
17
+ target: resolved,
18
+ sessionId: target.sessionId,
19
+ ...receipt ? { admission: { ...receipt } } : {}
20
+ };
21
+ const result = resolved.kind === "sqlite" && isIncognitoSessionKey(resolved.target.sessionKey) ? await runCodexHistoryWorkerInput(input) : await historyReads.run(input, {
22
+ timeoutMs: 6e4,
23
+ signal
24
+ });
25
+ signal?.throwIfAborted();
26
+ if (resolved.kind === "sqlite") {
27
+ if (input.admission) validateCodexSessionTranscriptReadAdmission(resolved.target, input.admission);
28
+ else validateCodexSessionTranscriptContextVersion(resolved.target, result.version);
29
+ }
30
+ return result;
31
+ }
32
+ async function readCodexHistoryMessagesInWorker(target, admission, signal) {
33
+ const result = await readHistory(target, { kind: "messages" }, admission, signal);
34
+ return result.kind === "messages" ? result.messages : void 0;
35
+ }
36
+ async function projectCodexSettledHistoryInWorker(target, signal) {
37
+ const result = await readHistory(target, {
38
+ kind: "settled",
39
+ evidence: {
40
+ mirroredMessages: target.mirroredMessages,
41
+ settledMessages: target.settledMessages,
42
+ turnId: target.turnId
43
+ }
44
+ }, void 0, signal);
45
+ return result.kind === "settled" ? result.data : void 0;
46
+ }
47
+ //#endregion
48
+ export { projectCodexSettledHistoryInWorker, readCodexHistoryMessagesInWorker };
@@ -0,0 +1,267 @@
1
+ import { i as readUpstreamUserText, r as readMirrorIdentity } from "./upstream-prompt-provenance-LphB8slG.js";
2
+ import { s as serializeCodexMirrorSourceEvidence } from "./transcript-mirror-attestation-Byl34PC-.js";
3
+ import { n as readCodexNativeHistory } from "./session-history-read-LHldwvyh.js";
4
+ import { isRecord, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
5
+ import { serveWorkerTasks } from "openclaw/plugin-sdk/process-runtime";
6
+ import { Buffer } from "node:buffer";
7
+ //#region extensions/codex/src/app-server/settled-turn-projection.ts
8
+ const MAX_RESPONSE_ITEMS = 200;
9
+ const MAX_PROJECTION_BYTES = 524288;
10
+ const MAX_TEXT_BYTES = 65536;
11
+ const TOOL_NAME_PATTERN = /^[a-zA-Z0-9._-]{1,128}$/u;
12
+ const TOOL_ERROR_STATUS_PREFIX = "[Tool result status: error]\n";
13
+ function readBoundedText(value, label, maxBytes = MAX_TEXT_BYTES) {
14
+ if (typeof value !== "string" || !value.trim()) return;
15
+ if (Buffer.byteLength(value, "utf8") > maxBytes) throw new Error(`Codex settled-turn projection found oversized ${label}`);
16
+ return value;
17
+ }
18
+ function requireBoundedText(value, label, maxBytes = MAX_TEXT_BYTES) {
19
+ const text = readBoundedText(value, label, maxBytes);
20
+ if (!text) throw new Error(`Codex settled-turn projection found empty ${label}`);
21
+ return text;
22
+ }
23
+ function responseItemBytes(item) {
24
+ return Buffer.byteLength(JSON.stringify(item), "utf8");
25
+ }
26
+ function requireCallId(value) {
27
+ const callId = normalizeOptionalString(value);
28
+ if (!callId || callId.length > 256) throw new Error("Codex settled-turn projection found an invalid tool call id");
29
+ return callId;
30
+ }
31
+ function requireToolName(value) {
32
+ const name = normalizeOptionalString(value);
33
+ if (!name || !TOOL_NAME_PATTERN.test(name)) throw new Error(`Codex settled-turn projection found an invalid tool name${name ? `: ${name.slice(0, 64)}` : ""}`);
34
+ return name;
35
+ }
36
+ function serializeToolArguments(value) {
37
+ if (typeof value === "string") {
38
+ let parsed;
39
+ try {
40
+ parsed = JSON.parse(value);
41
+ } catch {
42
+ throw new Error("Codex settled-turn projection found invalid JSON tool arguments");
43
+ }
44
+ if (!isRecord(parsed)) throw new Error("Codex settled-turn projection requires object tool arguments");
45
+ return requireBoundedText(value, "tool arguments");
46
+ }
47
+ if (!isRecord(value)) throw new Error("Codex settled-turn projection requires object tool arguments");
48
+ let serialized;
49
+ try {
50
+ serialized = JSON.stringify(value);
51
+ } catch {
52
+ throw new Error("Codex settled-turn projection found unserializable tool arguments");
53
+ }
54
+ return requireBoundedText(serialized, "tool arguments");
55
+ }
56
+ function projectUserMessage(message) {
57
+ const upstreamUserText = readUpstreamUserText(message);
58
+ if (typeof message.content === "string") return {
59
+ type: "message",
60
+ role: "user",
61
+ content: [{
62
+ type: "input_text",
63
+ text: upstreamUserText ? requireBoundedText(upstreamUserText, "upstream user text", MAX_PROJECTION_BYTES) : requireBoundedText(message.content, "user message")
64
+ }]
65
+ };
66
+ if (!Array.isArray(message.content)) throw new Error("Codex settled-turn projection found unsupported user content");
67
+ const content = [];
68
+ let bytes = responseItemBytes({
69
+ type: "message",
70
+ role: "user",
71
+ content
72
+ });
73
+ for (const value of message.content) {
74
+ if (!isRecord(value)) throw new Error("Codex settled-turn projection found malformed user content");
75
+ if (value.type !== "text") throw new Error(`Codex settled-turn projection does not support user content ${value.type}`);
76
+ const text = readBoundedText(value.text, "user text");
77
+ if (text) {
78
+ const part = {
79
+ type: "input_text",
80
+ text
81
+ };
82
+ bytes += responseItemBytes(part) + (content.length > 0 ? 1 : 0);
83
+ if (bytes > MAX_PROJECTION_BYTES) throw new Error("Codex settled-turn projection exceeds the byte limit");
84
+ content.push(part);
85
+ }
86
+ }
87
+ if (content.length === 0) throw new Error("Codex settled-turn projection found an empty user message");
88
+ return {
89
+ type: "message",
90
+ role: "user",
91
+ content
92
+ };
93
+ }
94
+ function* projectAssistantMessage(message) {
95
+ const values = typeof message.content === "string" ? [{
96
+ type: "text",
97
+ text: message.content
98
+ }] : message.content;
99
+ if (!Array.isArray(values)) throw new Error("Codex settled-turn projection found unsupported assistant content");
100
+ for (const value of values) {
101
+ if (!isRecord(value)) throw new Error("Codex settled-turn projection found malformed assistant content");
102
+ if (value.type === "text") {
103
+ const text = readBoundedText(value.text, "assistant text");
104
+ if (text) yield { item: {
105
+ type: "message",
106
+ role: "assistant",
107
+ content: [{
108
+ type: "output_text",
109
+ text
110
+ }]
111
+ } };
112
+ continue;
113
+ }
114
+ if (value.type === "toolCall") {
115
+ const id = requireCallId(value.id ?? value.toolCallId);
116
+ const name = requireToolName(value.name ?? value.toolName);
117
+ yield {
118
+ call: {
119
+ id,
120
+ name
121
+ },
122
+ item: {
123
+ type: "function_call",
124
+ call_id: id,
125
+ name,
126
+ arguments: serializeToolArguments(value.arguments ?? value.input)
127
+ }
128
+ };
129
+ continue;
130
+ }
131
+ if (value.type === "thinking" || value.type === "reasoning") continue;
132
+ throw new Error(`Codex settled-turn projection does not support assistant content ${String(value.type)}`);
133
+ }
134
+ }
135
+ function projectToolResult(message) {
136
+ const id = requireCallId(message.toolCallId);
137
+ const name = requireToolName(message.toolName);
138
+ if (!Array.isArray(message.content)) throw new Error("Codex settled-turn projection found unsupported tool result content");
139
+ const isErrorValue = message.isError;
140
+ if (isErrorValue !== void 0 && typeof isErrorValue !== "boolean") throw new Error("Codex settled-turn projection found invalid tool result status");
141
+ const isError = isErrorValue === true;
142
+ const parts = [];
143
+ let bytes = 0;
144
+ const appendText = (text) => {
145
+ bytes += Buffer.byteLength(text, "utf8") + (parts.length > 0 ? 1 : 0);
146
+ if (bytes > MAX_TEXT_BYTES) throw new Error("Codex settled-turn projection found oversized tool result output");
147
+ parts.push(text);
148
+ };
149
+ for (const value of message.content) {
150
+ if (!isRecord(value)) throw new Error("Codex settled-turn projection found malformed tool result content");
151
+ if (value.type === "image") {
152
+ appendText(`[Image tool result: ${normalizeOptionalString(value.mimeType) ?? "unknown type"}]`);
153
+ continue;
154
+ }
155
+ if (value.type !== "text" && value.type !== "toolResult") throw new Error("Codex settled-turn projection found malformed tool result content");
156
+ const text = value.type === "text" ? readBoundedText(value.text, "tool result text") : readBoundedText(value.content ?? value.text, "tool result text");
157
+ if (text) appendText(text);
158
+ }
159
+ const resultText = parts.join("\n") || (isError ? "Tool failed without textual output." : "Tool completed without textual output.");
160
+ const output = requireBoundedText(isError ? `${TOOL_ERROR_STATUS_PREFIX}${resultText}` : resultText, "tool result output", isError ? MAX_TEXT_BYTES + Buffer.byteLength(TOOL_ERROR_STATUS_PREFIX, "utf8") : MAX_TEXT_BYTES);
161
+ return {
162
+ result: {
163
+ id,
164
+ name
165
+ },
166
+ item: {
167
+ type: "function_call_output",
168
+ call_id: id,
169
+ output
170
+ }
171
+ };
172
+ }
173
+ function* projectMessage(message) {
174
+ if (message.role === "user") yield { item: projectUserMessage(message) };
175
+ else if (message.role === "assistant") yield* projectAssistantMessage(message);
176
+ else if (message.role === "toolResult") yield projectToolResult(message);
177
+ else throw new Error(`Codex settled-turn projection does not support role ${message.role}`);
178
+ }
179
+ /** Consumes complete evidence or rejects at the existing limits, never truncating its history. */
180
+ function projectSettledCodexMessages(messages) {
181
+ const items = [];
182
+ const calls = /* @__PURE__ */ new Map();
183
+ const results = /* @__PURE__ */ new Set();
184
+ let bytes = 0;
185
+ for (const message of messages) for (const { item, call, result } of projectMessage(message)) {
186
+ if (call) {
187
+ if (calls.has(call.id)) throw new Error("Codex settled-turn projection found a duplicate tool call");
188
+ calls.set(call.id, call.name);
189
+ }
190
+ if (result) {
191
+ if (calls.get(result.id) !== result.name || results.has(result.id)) throw new Error("Codex settled-turn projection found an ambiguous tool transcript");
192
+ results.add(result.id);
193
+ }
194
+ if (items.length === MAX_RESPONSE_ITEMS) throw new Error("Codex settled-turn projection exceeds the item limit");
195
+ bytes += responseItemBytes(item);
196
+ if (bytes > MAX_PROJECTION_BYTES) throw new Error("Codex settled-turn projection exceeds the byte limit");
197
+ items.push(item);
198
+ }
199
+ if (calls.size !== results.size) throw new Error("Codex settled-turn projection found an incomplete tool transcript");
200
+ if (results.size === 0) throw new Error("Codex settled-turn projection found no completed tool result");
201
+ return items;
202
+ }
203
+ //#endregion
204
+ //#region extensions/codex/src/app-server/settled-turn-evidence.ts
205
+ function rejectEvidence() {
206
+ throw new Error("Codex settled-turn transcript does not match the settled turn");
207
+ }
208
+ /** The worker consumes this verifier lazily; rejection never acquires the remaining payloads. */
209
+ function projectVerifiedSettledCodexMessages(history, params) {
210
+ return projectSettledCodexMessages(verifiedSettledMessages(history, params));
211
+ }
212
+ /** Yields only the settled prefix, but exhausts suffix identity checks before accepting it. */
213
+ function* verifiedSettledMessages(history, params) {
214
+ const promptIdentity = `${params.turnId}:prompt`;
215
+ const boundaryIndex = params.settledMessages.findLastIndex((message) => message.role === "toolResult");
216
+ const boundary = params.settledMessages[boundaryIndex];
217
+ const boundaryIdentity = boundary && readMirrorIdentity(boundary);
218
+ const requiredIds = params.settledMessages.slice(0, boundaryIndex + 1).flatMap((message) => readMirrorIdentity(message) ?? []);
219
+ if (!boundaryIdentity?.startsWith(`${params.turnId}:tool:`) || requiredIds.length !== boundaryIndex + 1 || new Set(requiredIds).size !== requiredIds.length || !requiredIds.includes(promptIdentity)) rejectEvidence();
220
+ const mirrored = params.mirroredMessages;
221
+ const mirroredIds = mirrored.flatMap((message) => readMirrorIdentity(message) ?? []);
222
+ const mirroredBoundaryIndex = mirrored.findIndex((message) => readMirrorIdentity(message) === boundaryIdentity);
223
+ if (new Set(mirroredIds).size !== mirroredIds.length || mirroredBoundaryIndex + 1 !== requiredIds.length || requiredIds.some((id, index) => readMirrorIdentity(mirrored[index]) !== id)) rejectEvidence();
224
+ const required = new Map(requiredIds.map((id, index) => [id, mirrored[index]]));
225
+ const seen = /* @__PURE__ */ new Set();
226
+ let matched = 0;
227
+ let throughBoundary = false;
228
+ for (const message of history) {
229
+ const identity = readMirrorIdentity(message);
230
+ if (identity) {
231
+ if (seen.has(identity)) rejectEvidence();
232
+ seen.add(identity);
233
+ const expected = required.get(identity);
234
+ if (expected) {
235
+ if (identity !== requiredIds[matched] || serializeCodexMirrorSourceEvidence(message) !== serializeCodexMirrorSourceEvidence(expected)) rejectEvidence();
236
+ matched += 1;
237
+ }
238
+ }
239
+ if (!throughBoundary) yield message;
240
+ throughBoundary ||= identity === boundaryIdentity;
241
+ }
242
+ if (!throughBoundary || matched !== requiredIds.length) rejectEvidence();
243
+ }
244
+ //#endregion
245
+ //#region extensions/codex/session-history.worker.ts
246
+ const codexHistoryWorkerUrl = new URL(import.meta.url);
247
+ async function runCodexHistoryWorkerInput(input) {
248
+ const request = input;
249
+ let version;
250
+ const onSnapshot = (value) => {
251
+ version = value;
252
+ };
253
+ if (request.kind === "messages") return {
254
+ kind: request.kind,
255
+ messages: await readCodexNativeHistory(request.target, request.sessionId, (messages) => Array.from(messages), request.admission, onSnapshot),
256
+ version
257
+ };
258
+ if (request.kind === "settled") return {
259
+ kind: request.kind,
260
+ data: await readCodexNativeHistory(request.target, request.sessionId, (messages) => projectVerifiedSettledCodexMessages(messages, request.evidence), request.admission, onSnapshot),
261
+ version
262
+ };
263
+ throw new Error("Invalid Codex history worker operation");
264
+ }
265
+ serveWorkerTasks(runCodexHistoryWorkerInput);
266
+ //#endregion
267
+ export { runCodexHistoryWorkerInput as n, codexHistoryWorkerUrl as t };
@@ -0,0 +1,2 @@
1
+ import { n as runCodexHistoryWorkerInput, t as codexHistoryWorkerUrl } from "./session-history.worker-zZVcx0ME.js";
2
+ export { codexHistoryWorkerUrl, runCodexHistoryWorkerInput };
@@ -0,0 +1,75 @@
1
+ import { d as validateBindingForWrite } from "./session-binding-record-CyaXZvTe.js";
2
+ import "./session-binding-4Ki04sW-.js";
3
+ import { isDeepStrictEqual } from "node:util";
4
+ import { deleteSessionUpstreamLink, upsertSessionUpstreamLink } from "openclaw/plugin-sdk/session-catalog";
5
+ //#region extensions/codex/src/app-server/session-initialization.ts
6
+ const initializations = /* @__PURE__ */ new WeakMap();
7
+ /** Associate the host's exact handle before any potentially committing plugin write. */
8
+ function prepareCodexSessionInitialization(params) {
9
+ const { initialization, bindingStore, identity } = params;
10
+ initialization.assertCurrent();
11
+ let link;
12
+ const ownership = {
13
+ store: bindingStore,
14
+ identity: structuredClone(identity),
15
+ assertCleanupAllowed: params.assertCleanupAllowed,
16
+ cleanup: async () => {
17
+ initialization.assertRollbackCurrent();
18
+ if (link && deleteSessionUpstreamLink(link.sessionKey, link.agentId, {
19
+ expected: link,
20
+ assertCommitAllowed: initialization.assertRollbackCurrent
21
+ }) === "changed") throw new Error("Codex initialization link changed before cleanup");
22
+ initialization.assertRollbackCurrent();
23
+ await cleanup?.(initialization.assertRollbackCurrent);
24
+ initialization.assertRollbackCurrent();
25
+ }
26
+ };
27
+ initializations.set(initialization, ownership);
28
+ const cleanup = params.prepareCleanup?.();
29
+ return {
30
+ assertCurrent: initialization.assertCurrent,
31
+ async bind(binding) {
32
+ initialization.assertCurrent();
33
+ ownership.binding = validateBindingForWrite(binding);
34
+ if (!await bindingStore.mutate(identity, {
35
+ kind: "set",
36
+ if: { kind: "absent" },
37
+ binding: ownership.binding
38
+ }, initialization.assertCurrent)) {
39
+ ownership.binding = void 0;
40
+ throw new Error("Codex session binding changed during initialization");
41
+ }
42
+ initialization.assertCurrent();
43
+ },
44
+ link(input) {
45
+ initialization.assertCurrent();
46
+ const now = Date.now();
47
+ link = structuredClone({
48
+ ...input,
49
+ createdAt: now,
50
+ updatedAt: now
51
+ });
52
+ if (!upsertSessionUpstreamLink(input, {
53
+ now,
54
+ ifAbsent: true,
55
+ assertCommitAllowed: initialization.assertCurrent
56
+ })) {
57
+ link = void 0;
58
+ throw new Error("Codex initialization link could not be persisted");
59
+ }
60
+ initialization.assertCurrent();
61
+ }
62
+ };
63
+ }
64
+ function getCodexSessionInitializationRollback(store, params, identity, binding) {
65
+ const handle = params.initialization;
66
+ if (!handle) return;
67
+ handle.assertRollbackCurrent();
68
+ const ownership = initializations.get(handle);
69
+ if (!ownership && !binding) return;
70
+ if (!ownership || ownership.store !== store || !isDeepStrictEqual(ownership.identity, identity) || binding && !isDeepStrictEqual(ownership.binding, binding)) throw new Error("Codex initialization binding owner changed before rollback");
71
+ ownership.assertCleanupAllowed?.();
72
+ return ownership.cleanup;
73
+ }
74
+ //#endregion
75
+ export { prepareCodexSessionInitialization as n, getCodexSessionInitializationRollback as t };
@@ -1,6 +1,6 @@
1
- import { A as selectUserApprovalsReviewer, E as parseAllowedSandboxModesFromCodexRequirements, M as selectGuardianSandbox, O as selectGuardianApprovalPolicy, T as parseAllowedApprovalsReviewersFromCodexRequirements, k as selectGuardianApprovalsReviewer, l as resolveCodexAppServerNetworkProxy, w as parseAllowedApprovalPoliciesFromCodexRequirements, x as canUseCodexModelBackedApprovalsReviewerForModel } from "./config-giW8X0QA.js";
2
- import { hostname } from "node:os";
1
+ import { S as selectUserApprovalsReviewer, _ as parseAllowedApprovalsReviewersFromCodexRequirements, b as selectGuardianApprovalPolicy, g as parseAllowedApprovalPoliciesFromCodexRequirements, j as selectGuardianSandbox, m as canUseCodexModelBackedApprovalsReviewerForModel, u as resolveCodexAppServerNetworkProxy, v as parseAllowedSandboxModesFromCodexRequirements, x as selectGuardianApprovalsReviewer } from "./config-CyapYSji.js";
3
2
  import { isPathInside } from "openclaw/plugin-sdk/file-access-runtime";
3
+ import { hostname } from "node:os";
4
4
  //#region extensions/codex/src/app-server/app-server-policy.ts
5
5
  function resolveCodexAppServerForModelProvider(params) {
6
6
  const explicitProvider = normalizeModelBackedReviewerProvider(params.provider);
@@ -0,0 +1,97 @@
1
+ import { Et as hasCodexAppServerLiveThread, Ot as isCodexAppServerLiveThreadClaimed, _ as retainSharedCodexAppServerClientByInstanceId, jt as releaseCodexAppServerLiveThread } from "./shared-client-CKhX2kFt.js";
2
+ import { a as closeCodexStartupClientBestEffort, d as unsubscribeCodexThreadBestEffort, n as CODEX_APP_SERVER_UNSUBSCRIBE_TIMEOUT_MS, r as CodexAppServerUnsafeSubscriptionError } from "./attempt-client-cleanup-Bp1ZOnk2.js";
3
+ import { l as isIncognitoSessionKey, o as withCodexAppServerThreadMutation, t as isSameCodexAppServerThreadOwner } from "./thread-ownership-CbucAmmp.js";
4
+ import { t as getCodexSessionInitializationRollback } from "./session-initialization-BCFVnLL4.js";
5
+ import { t as codexNativeSubagentMonitorRuntime } from "./native-subagent-monitor-B3bvQGcg.js";
6
+ //#region extensions/codex/src/app-server/session-retirement.ts
7
+ async function releaseSessionSubscription(client, binding, sessionKey, assertCurrent) {
8
+ assertCurrent?.();
9
+ codexNativeSubagentMonitorRuntime.retireParent(client, binding.threadId);
10
+ const released = await releaseCodexAppServerLiveThread(client, binding.threadId, assertCurrent);
11
+ assertCurrent?.();
12
+ if (!released && isIncognitoSessionKey(sessionKey)) {
13
+ const unsubscribed = await unsubscribeCodexThreadBestEffort(client, {
14
+ threadId: binding.threadId,
15
+ timeoutMs: CODEX_APP_SERVER_UNSUBSCRIBE_TIMEOUT_MS,
16
+ assertCurrent
17
+ });
18
+ assertCurrent?.();
19
+ if (!unsubscribed) {
20
+ await closeCodexStartupClientBestEffort(client);
21
+ throw new CodexAppServerUnsafeSubscriptionError(`Codex retired session subscription could not be released: ${binding.threadId}`);
22
+ }
23
+ }
24
+ }
25
+ /** Prepare exact binding deletion before the session owner commits either database. */
26
+ async function withCodexAppServerSessionDeletion(bindingStore, params, run) {
27
+ const { assertCurrent } = params;
28
+ const identity = {
29
+ kind: "session",
30
+ agentId: params.agentId,
31
+ sessionKey: params.sessionKey,
32
+ sessionId: params.sessionId
33
+ };
34
+ const remove = () => bindingStore.withSessionDeletion(identity, assertCurrent, async (binding, mutation) => {
35
+ assertCurrent();
36
+ const rollbackInitialization = getCodexSessionInitializationRollback(bindingStore, params, identity, binding);
37
+ if (binding?.connectionScope === "supervision" && !rollbackInitialization) throw new Error("Cannot delete a session while its Codex binding is owned by supervision");
38
+ const clientLease = binding?.clientId ? retainSharedCodexAppServerClientByInstanceId(binding.clientId) : void 0;
39
+ const assertUnclaimed = () => {
40
+ assertCurrent();
41
+ if (clientLease && binding && isCodexAppServerLiveThreadClaimed(clientLease.client, binding.threadId)) throw new Error("Cannot delete a session while its Codex thread is claimed by active work");
42
+ };
43
+ let committed = false;
44
+ try {
45
+ assertUnclaimed();
46
+ return await run({
47
+ commit() {
48
+ assertUnclaimed();
49
+ mutation.commit();
50
+ committed = true;
51
+ },
52
+ rollback() {
53
+ mutation.rollback();
54
+ committed = false;
55
+ }
56
+ });
57
+ } finally {
58
+ try {
59
+ if (committed && rollbackInitialization) {
60
+ assertCurrent();
61
+ await rollbackInitialization();
62
+ }
63
+ if (committed && binding && clientLease) await withCodexAppServerThreadMutation(binding.threadId, async () => {
64
+ assertCurrent();
65
+ if (!hasCodexAppServerLiveThread(clientLease.client, binding.threadId) && !isIncognitoSessionKey(params.sessionKey)) return;
66
+ if (await bindingStore.hasOtherThreadOwner(binding.threadId)) return;
67
+ await releaseSessionSubscription(clientLease.client, binding, params.sessionKey, assertUnclaimed);
68
+ });
69
+ } finally {
70
+ clientLease?.release();
71
+ }
72
+ }
73
+ });
74
+ return params.initialization ? await bindingStore.withThreadArchiveFence(remove) : await remove();
75
+ }
76
+ /** Retire binding and native subscription under the same generation/physical-client ownership fence. */
77
+ async function retireCodexAppServerSessionGeneration(params) {
78
+ const retireGeneration = () => params.mode === "reset" ? params.bindingStore.resetSessionGeneration(params.identity) : params.bindingStore.retireSessionGeneration(params.identity);
79
+ const expectedBinding = params.bindingStore.read(params.identity);
80
+ if (!expectedBinding) return await retireGeneration();
81
+ return await withCodexAppServerThreadMutation(expectedBinding.threadId, () => params.bindingStore.withLease(params.identity, async () => {
82
+ const binding = params.bindingStore.read(params.identity);
83
+ if (!binding || !isSameCodexAppServerThreadOwner(binding, expectedBinding)) return "conflict";
84
+ const result = await retireGeneration();
85
+ if (result !== "applied" || !binding?.clientId) return result;
86
+ const clientLease = retainSharedCodexAppServerClientByInstanceId(binding.clientId);
87
+ if (!clientLease) return result;
88
+ try {
89
+ await releaseSessionSubscription(clientLease.client, binding, params.identity.sessionKey);
90
+ } finally {
91
+ clientLease.release();
92
+ }
93
+ return result;
94
+ }));
95
+ }
96
+ //#endregion
97
+ export { retireCodexAppServerSessionGeneration, withCodexAppServerSessionDeletion };