@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.
- package/README.md +2 -0
- package/dist/api.js +18 -23
- package/dist/apply-B6el6hdO.js +357 -0
- package/dist/{attempt-client-cleanup-DYHcRQAa.js → attempt-client-cleanup-D6cR54TV.js} +113 -49
- package/dist/{attempt-context-DmQUNWwT.js → attempt-context-AO4DSjE0.js} +11 -9
- package/dist/{event-projector-usage-C5mcrGjp.js → attempt-notifications--H8zXR5-.js} +3 -89
- package/dist/auth-cache-key-Kq6oerr6.js +498 -0
- package/dist/auth-profile-CwzO4_RG.js +43 -0
- package/dist/auth-profile-selection-DFu9e167.js +45 -0
- package/dist/{binding-connection-E6uDsPlx.js → binding-connection-QqgcPCgk.js} +18 -3
- package/dist/{bounded-turn-wzJrwKKe.js → bounded-turn-lRpmZHFv.js} +54 -150
- package/dist/build-state-6RL6qohz.js +19 -0
- package/dist/{capabilities-dIjNVCYH.js → capabilities-BeqLPbtM.js} +2 -1
- package/dist/cli-metadata.js +1 -1
- package/dist/client-BEKu4yDx.js +3983 -0
- package/dist/command-dispatch-CisT9Jqq.js +21 -0
- package/dist/{command-formatters-CLHhEB1Q.js → command-formatters-DeTfrapr.js} +2 -2
- package/dist/{command-handlers-CTGb2csu.js → command-handlers-BfIsJEuA.js} +158 -76
- package/dist/command-rpc-BMqRQOFX.js +226 -0
- package/dist/{compact-_t0HQrUS.js → compact-CGJZ2rlb.js} +89 -49
- package/dist/config-JDfTI4VI.js +106 -0
- package/dist/{config-BhmfC1s6.js → config-options-jnIFvwxD.js} +208 -654
- package/dist/config-runtime-BWf6JLWG.js +11 -0
- package/dist/config-utils-C57JiJrU.js +69 -0
- package/dist/conversation-binding-CxOlHiix.js +889 -0
- package/dist/{plugin-marketplace-discovery-CfFlKqDl.js → conversation-control-CUCrSIQI.js} +36 -155
- package/dist/doctor-contract-api.js +8 -9
- package/dist/{dynamic-tools-BU9tmlYm.js → dynamic-tools-D-JBoaLt.js} +734 -698
- package/dist/{effective-mcp-catalog-DzYBW4h1.js → effective-mcp-catalog-J_5Ep5Um.js} +4 -3
- package/dist/{elicitation-input-DMkeki8d.js → elicitation-input-DPoK8F7w.js} +8 -22
- package/dist/ephemeral-turn-DSwzP8YY.js +101 -0
- package/dist/{event-projector-assistant-message-DHRFXKbS.js → event-projector-assistant-message-BmBM4qBV.js} +23 -27
- package/dist/event-projector-usage-CIyrYYid.js +102 -0
- package/dist/{harness-DXVZ5II5.js → harness-FR6eQgyO.js} +47 -17
- package/dist/harness.js +1 -1
- package/dist/history-rejection-B4nOXNXF.js +13 -0
- package/dist/{image-payload-sanitizer-CnfoUPCE.js → image-payload-sanitizer-tupAr-2o.js} +29 -15
- package/dist/incognito-session-uhrBF6wJ.js +15 -0
- package/dist/index.js +413 -2893
- package/dist/{isolated-completion-kg9kv4iH.js → isolated-completion-DHBefrzg.js} +12 -21
- package/dist/{managed-binary-4-Vjz5GH.js → managed-binary-DrjjRRUD.js} +17 -84
- package/dist/managed-thread-store-D1t5jh3G.js +66 -0
- package/dist/media-understanding-provider.js +4 -1
- package/dist/{model-catalog-CUM68Hkl.js → model-catalog-B_6M04Wo.js} +6 -5
- package/dist/{models-sYnEc0gd.js → models-P9k2qAof.js} +4 -4
- package/dist/native-execution-policy-umd0tgh4.js +128 -0
- package/dist/{native-subagent-monitor-CnH147jH.js → native-subagent-monitor-BbCUKRwC.js} +76 -48
- package/dist/node-cli-sessions-rj0ysJwM.js +527 -0
- package/dist/{node-exec-server.runtime-CstNHCmC.js → node-exec-server.runtime-BY_ctYnT.js} +54 -23
- package/dist/plan-BMJdMOEF.js +711 -0
- package/dist/plugin-activation-BQK-f5sV.js +133 -0
- package/dist/{thread-resume-C7pyVKeW.js → plugin-app-cache-key-CdSQzWyX.js} +5 -53
- package/dist/{plugin-approval-roundtrip-CNe-Xrjx.js → plugin-approval-roundtrip-DeW95wB5.js} +1 -1
- package/dist/plugin-inventory-CoRCzWW4.js +325 -0
- package/dist/plugin-marketplace-discovery-3akBizzF.js +134 -0
- package/dist/{plugin-metadata-cache-BFrPhb2c.js → plugin-metadata-cache-DgNfRAGA.js} +13 -9
- package/dist/protocol-CAAcVIKF.js +275 -0
- package/dist/{provider-capabilities-DW5p4k9w.js → provider-capabilities-W4tfK5Y5.js} +2 -2
- package/dist/{rate-limits-CawQJfUS.js → rate-limits-Bqnx1N4z.js} +1 -1
- package/dist/request-CGvGOpeR.js +198 -0
- package/dist/{run-attempt-D1hJO4fX.js → run-attempt-DwKds3DN.js} +1498 -1028
- package/dist/{runtime-artifact-C3jVimFn.js → runtime-artifact-T-NwqeSH.js} +28 -28
- package/dist/sandbox-guard-BcT66fWy.js +165 -0
- package/dist/{session-binding-BHuTCRZQ.js → session-binding-CKSepwIC.js} +118 -324
- package/dist/session-binding-record-CaZjYwNS.js +256 -0
- package/dist/session-catalog-HaDcp7Sv.js +1533 -0
- package/dist/session-catalog-adoption-BKLtSrwi.js +251 -0
- package/dist/session-catalog-archive-D0i2pGj2.js +56 -0
- package/dist/session-catalog-home-id-D7-aLiNt.js +190 -0
- package/dist/session-catalog-node-adoption-BUuDYY8R.js +182 -0
- package/dist/session-catalog-node-continue-CBtc4wkI.js +238 -0
- package/dist/session-catalog-parsing-CdD3JhdM.js +280 -0
- package/dist/session-catalog-provenance-DkJHo735.js +124 -0
- package/dist/{session-cli-CmFEXMAM.js → session-cli-CbgaHh0f.js} +3 -2
- package/dist/session-history-Cz-tOOYj.js +96 -0
- package/dist/{session-upstream-marker-C351-5Qw.js → session-history-import-DFN7sWRU.js} +5 -49
- package/dist/session-history-read-cxPUxyVV.js +50 -0
- package/dist/session-history-worker-runtime.js +60 -0
- package/dist/{settled-turn-context-D3SNWtUn.js → session-history.worker-CNEvGaU5.js} +75 -69
- package/dist/session-history.worker.js +2 -0
- package/dist/{session-initialization-BeWzjGiR.js → session-initialization-Jo86C60I.js} +2 -1
- package/dist/{session-permission-policy-DeWVTCMj.js → session-permission-policy-B22InTp_.js} +4 -7
- package/dist/{session-retirement-BujDjXVF.js → session-retirement-BSNG_mhf.js} +8 -7
- package/dist/session-upstream-marker-D15C9NHp.js +46 -0
- package/dist/settled-turn-context-Du6gdUDd.js +45 -0
- package/dist/{settled-turn-finalizer-BVJx4yoc.js → settled-turn-finalizer-BuLUrZl2.js} +54 -42
- package/dist/shared-client-CVhez2Uo.js +2911 -0
- package/dist/{side-question-BTZAII4l.js → side-question-DLbr2vUU.js} +135 -191
- package/dist/source-Da-h6f7e.js +518 -0
- package/dist/thread-archive-guard-D1bP04Tf.js +53 -0
- package/dist/{thread-lifecycle-DAcEJ_Om.js → thread-lifecycle-D1pzRwHB.js} +467 -977
- package/dist/{thread-ownership-zGokd8i1.js → thread-ownership-D6oASVRu.js} +15 -17
- package/dist/{thread-policy-g4KbJPzp.js → thread-policy-D8kI7yAO.js} +2 -2
- package/dist/thread-resume-T5cveyxA.js +52 -0
- package/dist/timeout-BVw8aaM1.js +33 -0
- package/dist/transcript-mirror-attestation-DibE0krH.js +89 -0
- package/dist/{transcript-mirror-DTUxFWa_.js → transcript-mirror-t5TOccct.js} +111 -379
- package/dist/{transport-stdio-CyPldczm.js → transport-stdio-BGjHoYLr.js} +80 -48
- package/dist/{upstream-session-fork-CYlBIGVt.js → upstream-session-fork-De-sLJ2r.js} +94 -166
- package/dist/{usage-Bj-rrzkR.js → usage-CPPTmBvZ.js} +4 -3
- package/dist/version-omm6IPI3.js +12 -0
- package/dist/{web-search-provider.runtime-D2FWSK4w.js → web-search-provider.runtime-CSVgQL0w.js} +3 -3
- package/openclaw.plugin.json +22 -1
- package/package.json +6 -6
- package/dist/request-DYAI5FQE.js +0 -475
- package/dist/session-catalog-yyvTWFOw.js +0 -3120
- package/dist/session-history-C5J1AKzG.js +0 -87
- package/dist/shared-client-DxcfF9KX.js +0 -7494
- package/dist/{auth-binding-Ds_QVm-X.js → auth-binding-Co2Vfcf_.js} +1 -1
|
@@ -1,267 +1,11 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
|
|
1
2
|
import { i as readUpstreamUserText, n as attachUpstreamUserText, r as readMirrorIdentity, t as attachCodexMirrorIdentity } from "./upstream-prompt-provenance-LphB8slG.js";
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import fsSync from "node:fs";
|
|
7
|
-
import { truncateUtf8Prefix } from "openclaw/plugin-sdk/text-utility-runtime";
|
|
3
|
+
import { r as projectBoundedCodexThreadHistory } from "./session-catalog-home-id-D7-aLiNt.js";
|
|
4
|
+
import { a as fingerprintCodexMirrorSourceMessage, c as readCodexMirrorSourceFingerprint, i as buildCodexMirrorDedupeIdentity, n as attachCodexMirrorAttestation, r as attachCodexMirrorRunId, s as isMirroredAgentMessage, t as applyCodexTranscriptTaint } from "./transcript-mirror-attestation-DibE0krH.js";
|
|
5
|
+
import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
6
|
+
import { deliverAgentHarnessUserInputPrompt, embeddedAgentLog, formatErrorMessage, projectAgentHarnessTranscriptMessageForDisplay, restorePreparedUserTurnOperationalMetaForRuntime, runAgentHarnessBeforeMessageWriteHook } from "openclaw/plugin-sdk/agent-harness-runtime";
|
|
8
7
|
import { withCodexSessionTranscriptMirrorWriteLock } from "openclaw/plugin-sdk/codex-session-transcript-runtime";
|
|
9
8
|
import { publishSessionTranscriptUpdateByIdentity } from "openclaw/plugin-sdk/session-transcript-runtime";
|
|
10
|
-
import { Buffer } from "node:buffer";
|
|
11
|
-
//#region extensions/codex/src/session-catalog-home-id.ts
|
|
12
|
-
function canonicalCodexCatalogHome(value) {
|
|
13
|
-
const resolved = path.resolve(value);
|
|
14
|
-
try {
|
|
15
|
-
return fsSync.realpathSync.native(resolved);
|
|
16
|
-
} catch {
|
|
17
|
-
return resolved;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
/** One canonical identity for catalog discovery and durable ownership rows. */
|
|
21
|
-
function codexCatalogHomeId(codexHome) {
|
|
22
|
-
return createHash("sha256").update("openclaw:codex-session-catalog-home:v1\0").update(canonicalCodexCatalogHome(codexHome)).digest("hex");
|
|
23
|
-
}
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region extensions/codex/src/app-server/transcript-history-projection.ts
|
|
26
|
-
const CODEX_HISTORY_IMPORT_MAX_MESSAGES = 200;
|
|
27
|
-
const CODEX_HISTORY_IMPORT_MAX_BYTES = 524288;
|
|
28
|
-
const CODEX_HISTORY_IMPORT_MAX_MESSAGE_BYTES = 65536;
|
|
29
|
-
const CODEX_HISTORY_TRUNCATION_SUFFIX = "\n\n[Message truncated during Codex history import.]";
|
|
30
|
-
const CODEX_HISTORY_ASSISTANT_API = "openai-chatgpt-responses";
|
|
31
|
-
const CODEX_HISTORY_ASSISTANT_PROVIDER = "openai";
|
|
32
|
-
const CODEX_HISTORY_ASSISTANT_MODEL = "native-history";
|
|
33
|
-
const CODEX_HISTORY_ZERO_USAGE = {
|
|
34
|
-
input: 0,
|
|
35
|
-
output: 0,
|
|
36
|
-
cacheRead: 0,
|
|
37
|
-
cacheWrite: 0,
|
|
38
|
-
totalTokens: 0,
|
|
39
|
-
cost: {
|
|
40
|
-
input: 0,
|
|
41
|
-
output: 0,
|
|
42
|
-
cacheRead: 0,
|
|
43
|
-
cacheWrite: 0,
|
|
44
|
-
total: 0
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
function normalizeImportedHistoryText(value) {
|
|
48
|
-
if (typeof value !== "string") return;
|
|
49
|
-
const text = value.trim();
|
|
50
|
-
if (!text) return;
|
|
51
|
-
if (Buffer.byteLength(text, "utf8") <= CODEX_HISTORY_IMPORT_MAX_MESSAGE_BYTES) return text;
|
|
52
|
-
const suffixBytes = Buffer.byteLength(CODEX_HISTORY_TRUNCATION_SUFFIX, "utf8");
|
|
53
|
-
const contentLimitBytes = Math.max(0, CODEX_HISTORY_IMPORT_MAX_MESSAGE_BYTES - suffixBytes);
|
|
54
|
-
return `${truncateUtf8Prefix(text, contentLimitBytes)}${CODEX_HISTORY_TRUNCATION_SUFFIX}`;
|
|
55
|
-
}
|
|
56
|
-
function projectCodexUserItemText(item) {
|
|
57
|
-
if (!Array.isArray(item.content)) return;
|
|
58
|
-
const parts = [];
|
|
59
|
-
for (const value of item.content) {
|
|
60
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) continue;
|
|
61
|
-
const input = value;
|
|
62
|
-
if (input.type === "text") {
|
|
63
|
-
const text = normalizeImportedHistoryText(input.text);
|
|
64
|
-
if (text) parts.push(text);
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
if (input.type === "image" || input.type === "localImage") {
|
|
68
|
-
parts.push("[Image attachment]");
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
if (input.type === "audio" || input.type === "localAudio" || input.type === "local_audio") parts.push("[Audio attachment]");
|
|
72
|
-
if (input.type === "skill" || input.type === "mention") {
|
|
73
|
-
const name = normalizeOptionalString(input.name);
|
|
74
|
-
if (name) parts.push(`${input.type === "skill" ? "$" : "@"}${name}`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return normalizeImportedHistoryText(parts.join("\n"));
|
|
78
|
-
}
|
|
79
|
-
function selectTurnsThroughBoundary(thread, throughTurnId) {
|
|
80
|
-
if (throughTurnId === null) return [];
|
|
81
|
-
const turns = thread.turns ?? [];
|
|
82
|
-
const boundaryIndex = turns.findIndex((turn) => turn.id === throughTurnId);
|
|
83
|
-
if (boundaryIndex < 0) throw new Error(`Codex history boundary turn not found: ${throughTurnId}`);
|
|
84
|
-
const boundary = turns[boundaryIndex];
|
|
85
|
-
if (boundary?.status !== "completed" && boundary?.status !== "interrupted" && boundary?.status !== "failed") throw new Error(`Codex history boundary turn is not terminal: ${throughTurnId}`);
|
|
86
|
-
return turns.slice(0, boundaryIndex + 1);
|
|
87
|
-
}
|
|
88
|
-
function projectCodexThreadHistory(params) {
|
|
89
|
-
const projected = [];
|
|
90
|
-
const threadTimestamp = typeof params.thread.createdAt === "number" && Number.isFinite(params.thread.createdAt) ? params.thread.createdAt * 1e3 : params.importedAt;
|
|
91
|
-
let itemOffset = 0;
|
|
92
|
-
for (const turn of selectTurnsThroughBoundary(params.thread, params.throughTurnId)) for (const value of turn.items) {
|
|
93
|
-
const item = value;
|
|
94
|
-
const itemId = normalizeOptionalString(item.id);
|
|
95
|
-
const identity = `${turn.id}:${itemId ?? itemOffset}`;
|
|
96
|
-
const timestampSeconds = item.type === "agentMessage" ? turn.completedAt ?? turn.startedAt : turn.startedAt ?? turn.completedAt;
|
|
97
|
-
const timestamp = typeof timestampSeconds === "number" && Number.isFinite(timestampSeconds) ? timestampSeconds * 1e3 + itemOffset : threadTimestamp + itemOffset;
|
|
98
|
-
const text = item.type === "userMessage" ? projectCodexUserItemText(item) : item.type === "agentMessage" ? normalizeImportedHistoryText(item.text) : void 0;
|
|
99
|
-
const role = item.type === "userMessage" ? "user" : item.type === "agentMessage" ? "assistant" : void 0;
|
|
100
|
-
itemOffset += 1;
|
|
101
|
-
if (!text || !role) continue;
|
|
102
|
-
const phase = item.phase === "commentary" || item.phase === "final_answer" ? item.phase : void 0;
|
|
103
|
-
const asyncDelivery = item.delivery === "async";
|
|
104
|
-
const message = role === "assistant" ? attachCodexMirrorIdentity({
|
|
105
|
-
role,
|
|
106
|
-
content: [{
|
|
107
|
-
type: "text",
|
|
108
|
-
text
|
|
109
|
-
}],
|
|
110
|
-
api: CODEX_HISTORY_ASSISTANT_API,
|
|
111
|
-
provider: normalizeOptionalString(params.modelProvider) ?? normalizeOptionalString(params.thread.modelProvider) ?? CODEX_HISTORY_ASSISTANT_PROVIDER,
|
|
112
|
-
model: CODEX_HISTORY_ASSISTANT_MODEL,
|
|
113
|
-
usage: CODEX_HISTORY_ZERO_USAGE,
|
|
114
|
-
stopReason: turn.status === "interrupted" ? "aborted" : turn.status === "failed" ? "error" : "stop",
|
|
115
|
-
...turn.status === "failed" && turn.error?.message ? { errorMessage: turn.error.message } : {},
|
|
116
|
-
...phase ? { phase } : {},
|
|
117
|
-
...asyncDelivery && itemId ? { openclawAsyncDelivery: { itemId } } : {},
|
|
118
|
-
timestamp
|
|
119
|
-
}, identity) : attachCodexMirrorIdentity({
|
|
120
|
-
role,
|
|
121
|
-
content: text,
|
|
122
|
-
timestamp
|
|
123
|
-
}, identity);
|
|
124
|
-
projected.push({
|
|
125
|
-
message,
|
|
126
|
-
responseItem: {
|
|
127
|
-
type: "message",
|
|
128
|
-
role,
|
|
129
|
-
content: [{
|
|
130
|
-
type: role === "assistant" ? "output_text" : "input_text",
|
|
131
|
-
text
|
|
132
|
-
}],
|
|
133
|
-
...role === "assistant" && phase ? { phase } : {}
|
|
134
|
-
},
|
|
135
|
-
textBytes: Buffer.byteLength(text, "utf8")
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
return projected;
|
|
139
|
-
}
|
|
140
|
-
function selectBoundedCodexHistoryTail(projected) {
|
|
141
|
-
const selected = [];
|
|
142
|
-
let selectedBytes = 0;
|
|
143
|
-
for (let index = projected.length - 1; index >= 0; index -= 1) {
|
|
144
|
-
const candidate = projected[index];
|
|
145
|
-
if (!candidate) continue;
|
|
146
|
-
if (selected.length >= CODEX_HISTORY_IMPORT_MAX_MESSAGES || selectedBytes + candidate.textBytes > CODEX_HISTORY_IMPORT_MAX_BYTES) break;
|
|
147
|
-
selected.push(candidate);
|
|
148
|
-
selectedBytes += candidate.textBytes;
|
|
149
|
-
}
|
|
150
|
-
return selected.toReversed();
|
|
151
|
-
}
|
|
152
|
-
/** Projects one terminal Codex history prefix into transcript and Responses API items. */
|
|
153
|
-
function projectBoundedCodexThreadHistory(params) {
|
|
154
|
-
const projected = projectCodexThreadHistory({
|
|
155
|
-
thread: params.thread,
|
|
156
|
-
throughTurnId: params.throughTurnId,
|
|
157
|
-
importedAt: params.importedAt,
|
|
158
|
-
...params.modelProvider ? { modelProvider: params.modelProvider } : {}
|
|
159
|
-
});
|
|
160
|
-
const selected = selectBoundedCodexHistoryTail(projected);
|
|
161
|
-
return {
|
|
162
|
-
importedMessages: selected.length,
|
|
163
|
-
omittedMessages: projected.length - selected.length,
|
|
164
|
-
responseItems: selected.filter(({ message }) => message.role !== "assistant" || message.stopReason !== "aborted" && message.stopReason !== "error" && !("openclawAsyncDelivery" in message)).map(({ responseItem }) => responseItem),
|
|
165
|
-
transcriptMessages: selected.map(({ message }) => message)
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
/** Projects only visible local user/assistant messages through the same bounded history policy. */
|
|
169
|
-
function projectBoundedCodexVisibleSessionHistory(entries) {
|
|
170
|
-
const projected = [];
|
|
171
|
-
for (const entry of entries) {
|
|
172
|
-
if (entry.role !== "user" && entry.role !== "assistant" || !("content" in entry.message)) continue;
|
|
173
|
-
if (entry.role === "assistant" && ("stopReason" in entry.message && (entry.message.stopReason === "aborted" || entry.message.stopReason === "error") || "openclawAsyncDelivery" in entry.message)) continue;
|
|
174
|
-
const content = entry.message.content;
|
|
175
|
-
const text = normalizeImportedHistoryText(typeof content === "string" ? content : Array.isArray(content) ? content.flatMap((part) => part && typeof part === "object" && "text" in part && typeof part.text === "string" ? [part.text] : []).join("\n") : void 0);
|
|
176
|
-
if (!text) continue;
|
|
177
|
-
projected.push({
|
|
178
|
-
message: entry.message,
|
|
179
|
-
responseItem: {
|
|
180
|
-
type: "message",
|
|
181
|
-
role: entry.role,
|
|
182
|
-
content: [{
|
|
183
|
-
type: entry.role === "assistant" ? "output_text" : "input_text",
|
|
184
|
-
text
|
|
185
|
-
}]
|
|
186
|
-
},
|
|
187
|
-
textBytes: Buffer.byteLength(text, "utf8")
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
return selectBoundedCodexHistoryTail(projected).map(({ responseItem }) => responseItem);
|
|
191
|
-
}
|
|
192
|
-
//#endregion
|
|
193
|
-
//#region extensions/codex/src/app-server/transcript-mirror-attestation.ts
|
|
194
|
-
const MIRROR_ORIGIN_META_KEY = "mirrorOrigin";
|
|
195
|
-
const MIRROR_SOURCE_FINGERPRINT_META_KEY = "mirrorSourceFingerprint";
|
|
196
|
-
const CODEX_APP_SERVER_MIRROR_ORIGIN = "codex-app-server";
|
|
197
|
-
const CODEX_META_KEY = "__openclaw";
|
|
198
|
-
function applyCodexTranscriptTaint(message, state) {
|
|
199
|
-
if (message.role === "user") {
|
|
200
|
-
state.tainted = false;
|
|
201
|
-
return message;
|
|
202
|
-
}
|
|
203
|
-
const existing = CODEX_META_KEY in message ? message[CODEX_META_KEY] : void 0;
|
|
204
|
-
const metadata = asOptionalRecord(existing);
|
|
205
|
-
state.tainted ||= metadata?.turnTainted === true || metadata?.resultContentSource === "network";
|
|
206
|
-
return message.role === "assistant" && state.tainted ? {
|
|
207
|
-
...message,
|
|
208
|
-
__openclaw: {
|
|
209
|
-
...metadata,
|
|
210
|
-
turnTainted: true
|
|
211
|
-
}
|
|
212
|
-
} : message;
|
|
213
|
-
}
|
|
214
|
-
function attachCodexMirrorAttestation(message, sourceFingerprint) {
|
|
215
|
-
const existing = CODEX_META_KEY in message ? message[CODEX_META_KEY] : void 0;
|
|
216
|
-
const baseMeta = existing && typeof existing === "object" && !Array.isArray(existing) ? existing : {};
|
|
217
|
-
return {
|
|
218
|
-
...message,
|
|
219
|
-
[CODEX_META_KEY]: {
|
|
220
|
-
...baseMeta,
|
|
221
|
-
[MIRROR_ORIGIN_META_KEY]: CODEX_APP_SERVER_MIRROR_ORIGIN,
|
|
222
|
-
...sourceFingerprint ? { [MIRROR_SOURCE_FINGERPRINT_META_KEY]: sourceFingerprint } : {}
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
function attachCodexMirrorRunId(message, runId, terminal = false) {
|
|
227
|
-
const existing = CODEX_META_KEY in message ? message[CODEX_META_KEY] : void 0;
|
|
228
|
-
const { runTerminal: _staleTerminal, ...current } = asOptionalRecord(existing) ?? {};
|
|
229
|
-
return {
|
|
230
|
-
...message,
|
|
231
|
-
[CODEX_META_KEY]: {
|
|
232
|
-
...current,
|
|
233
|
-
runId,
|
|
234
|
-
...terminal ? { runTerminal: true } : {}
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
function hasCodexMirrorOrigin(message) {
|
|
239
|
-
const meta = CODEX_META_KEY in message ? message[CODEX_META_KEY] : void 0;
|
|
240
|
-
return asOptionalRecord(meta)?.[MIRROR_ORIGIN_META_KEY] === CODEX_APP_SERVER_MIRROR_ORIGIN;
|
|
241
|
-
}
|
|
242
|
-
function readCodexMirrorSourceFingerprint(message) {
|
|
243
|
-
const meta = CODEX_META_KEY in message ? message[CODEX_META_KEY] : void 0;
|
|
244
|
-
if (!meta || typeof meta !== "object" || Array.isArray(meta)) return;
|
|
245
|
-
const value = meta[MIRROR_SOURCE_FINGERPRINT_META_KEY];
|
|
246
|
-
return typeof value === "string" && value ? value : void 0;
|
|
247
|
-
}
|
|
248
|
-
function serializeCodexMirrorSourceEvidence(message) {
|
|
249
|
-
const content = "content" in message ? message.content : void 0;
|
|
250
|
-
return JSON.stringify({
|
|
251
|
-
role: message.role,
|
|
252
|
-
content,
|
|
253
|
-
...message.role === "user" ? { upstreamUserText: readUpstreamUserText(message) } : {},
|
|
254
|
-
...message.role === "toolResult" ? {
|
|
255
|
-
toolCallId: message.toolCallId,
|
|
256
|
-
toolName: message.toolName,
|
|
257
|
-
isError: message.isError
|
|
258
|
-
} : {}
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
function fingerprintCodexMirrorSourceMessage(message) {
|
|
262
|
-
return createHash("sha256").update(serializeCodexMirrorSourceEvidence(message)).digest("hex").slice(0, 32);
|
|
263
|
-
}
|
|
264
|
-
//#endregion
|
|
265
9
|
//#region extensions/codex/src/app-server/user-prompt-message.ts
|
|
266
10
|
function buildSenderLabel(params) {
|
|
267
11
|
const label = params.senderName ?? params.senderUsername ?? params.senderE164 ?? params.senderId;
|
|
@@ -306,14 +50,29 @@ function promptSnapshot(params, turnId, upstreamUserText) {
|
|
|
306
50
|
async function buildResolvedCodexUserPromptMessage(params) {
|
|
307
51
|
return buildFromPrepared(params, await params.userTurnTranscriptRecorder?.resolveMessage() ?? params.userTurnTranscriptRecorder?.message);
|
|
308
52
|
}
|
|
53
|
+
async function resolveFinalCodexMirrorMessages(params) {
|
|
54
|
+
if (params.params.suppressNextUserMessagePersistence || !params.params.userTurnTranscriptRecorder) return params.messagesSnapshot;
|
|
55
|
+
const previousPrompt = params.messagesSnapshot.find((message) => message.role === "user");
|
|
56
|
+
const resolvedBase = attachCodexMirrorIdentity(await buildResolvedCodexUserPromptMessage(params.params), `${params.turnId}:prompt`);
|
|
57
|
+
const upstreamUserText = readUpstreamUserText(previousPrompt);
|
|
58
|
+
const resolvedPrompt = upstreamUserText ? attachUpstreamUserText(resolvedBase, upstreamUserText) : resolvedBase;
|
|
59
|
+
const firstUserIndex = params.messagesSnapshot.findIndex((message) => message.role === "user");
|
|
60
|
+
if (firstUserIndex === -1) return [resolvedPrompt, ...params.messagesSnapshot];
|
|
61
|
+
const messages = params.messagesSnapshot.slice();
|
|
62
|
+
messages[firstUserIndex] = resolvedPrompt;
|
|
63
|
+
return messages;
|
|
64
|
+
}
|
|
309
65
|
//#endregion
|
|
310
66
|
//#region extensions/codex/src/app-server/transcript-mirror.ts
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
67
|
+
var transcript_mirror_exports = /* @__PURE__ */ __exportAll({
|
|
68
|
+
codexTranscriptMirrorRuntime: () => codexTranscriptMirrorRuntime,
|
|
69
|
+
createCodexAppServerUserMessagePersistenceNotifier: () => createCodexAppServerUserMessagePersistenceNotifier,
|
|
70
|
+
importCodexThreadHistoryToTranscript: () => importCodexThreadHistoryToTranscript,
|
|
71
|
+
mirrorPromptAtTurnStartBestEffort: () => mirrorPromptAtTurnStartBestEffort,
|
|
72
|
+
projectBoundedCodexThreadHistory: () => projectBoundedCodexThreadHistory
|
|
73
|
+
});
|
|
314
74
|
function readMirroredAssistantText(message) {
|
|
315
|
-
|
|
316
|
-
return message.content.flatMap((part) => part.type === "text" ? [part.text] : []).join("\n") || void 0;
|
|
75
|
+
return message?.role === "assistant" ? message.content.flatMap((part) => part.type === "text" ? [part.text] : []).join("\n") || void 0 : void 0;
|
|
317
76
|
}
|
|
318
77
|
/** Imports a bounded, user-visible Codex history tail into a new OpenClaw transcript. */
|
|
319
78
|
async function importCodexThreadHistoryToTranscript(params) {
|
|
@@ -350,7 +109,9 @@ async function mirrorBestEffort(params) {
|
|
|
350
109
|
messagesSnapshot: params.result.messagesSnapshot,
|
|
351
110
|
turnId: params.turnId
|
|
352
111
|
});
|
|
112
|
+
params.assertWriteCurrent?.();
|
|
353
113
|
const mirrorResult = await mirror({
|
|
114
|
+
assertWriteCurrent: params.assertWriteCurrent,
|
|
354
115
|
agentId: params.agentId,
|
|
355
116
|
sessionKey: params.sessionKey,
|
|
356
117
|
sessionId: params.params.sessionId,
|
|
@@ -360,15 +121,16 @@ async function mirrorBestEffort(params) {
|
|
|
360
121
|
idempotencyScope: `codex-app-server:${params.threadId}`,
|
|
361
122
|
runId: params.params.runId,
|
|
362
123
|
runMirrorIdentityPrefix: `${params.turnId}:`,
|
|
363
|
-
terminalAssistantOwner: {
|
|
124
|
+
terminalAssistantOwner: params.params.deferTerminalLifecycle && params.result.terminal.kind === "failed" ? void 0 : {
|
|
364
125
|
mirrorIdentity: `${params.turnId}:assistant`,
|
|
365
|
-
runId: params.params.runId
|
|
126
|
+
runId: params.params.runId,
|
|
127
|
+
settlementWarning: params.settlementWarning
|
|
366
128
|
},
|
|
367
129
|
prepareAssistantTranscriptMessage: params.params.prepareAssistantTranscriptMessage,
|
|
368
130
|
config: params.params.config
|
|
369
131
|
});
|
|
370
132
|
for (const receipt of mirrorResult.userMessageReceipts) try {
|
|
371
|
-
params.notifyUserMessagePersisted(receipt
|
|
133
|
+
params.notifyUserMessagePersisted(receipt);
|
|
372
134
|
} catch (error) {
|
|
373
135
|
embeddedAgentLog.warn("failed to notify codex app-server user-message persistence", { error: formatErrorMessage(error) });
|
|
374
136
|
}
|
|
@@ -406,26 +168,14 @@ async function mirrorBestEffort(params) {
|
|
|
406
168
|
};
|
|
407
169
|
}
|
|
408
170
|
}
|
|
409
|
-
async function resolveFinalCodexMirrorMessages(params) {
|
|
410
|
-
if (params.params.suppressNextUserMessagePersistence || !params.params.userTurnTranscriptRecorder) return params.messagesSnapshot;
|
|
411
|
-
const promptSnapshot = params.messagesSnapshot.find((message) => message.role === "user");
|
|
412
|
-
const resolvedBase = attachCodexMirrorIdentity(await buildResolvedCodexUserPromptMessage(params.params), `${params.turnId}:prompt`);
|
|
413
|
-
const upstreamUserText = readUpstreamUserText(promptSnapshot);
|
|
414
|
-
const resolvedPrompt = upstreamUserText ? attachUpstreamUserText(resolvedBase, upstreamUserText) : resolvedBase;
|
|
415
|
-
const firstUserIndex = params.messagesSnapshot.findIndex((message) => message.role === "user");
|
|
416
|
-
if (firstUserIndex === -1) return [resolvedPrompt, ...params.messagesSnapshot];
|
|
417
|
-
const messages = params.messagesSnapshot.slice();
|
|
418
|
-
messages[firstUserIndex] = resolvedPrompt;
|
|
419
|
-
return messages;
|
|
420
|
-
}
|
|
421
171
|
function createCodexAppServerUserMessagePersistenceNotifier(runParams) {
|
|
422
172
|
let notified = false;
|
|
423
|
-
return (
|
|
173
|
+
return (receipt) => {
|
|
424
174
|
if (notified) return;
|
|
425
175
|
notified = true;
|
|
426
|
-
runParams.userTurnTranscriptRecorder?.markRuntimePersisted(message, anchor);
|
|
176
|
+
runParams.userTurnTranscriptRecorder?.markRuntimePersisted(receipt.message, receipt.anchor, receipt);
|
|
427
177
|
try {
|
|
428
|
-
runParams.onUserMessagePersisted?.(message);
|
|
178
|
+
runParams.onUserMessagePersisted?.(receipt.message);
|
|
429
179
|
} catch (error) {
|
|
430
180
|
embeddedAgentLog.warn("codex app-server user persistence notification failed", { error: formatErrorMessage(error) });
|
|
431
181
|
}
|
|
@@ -439,7 +189,8 @@ async function mirrorPromptAtTurnStartBestEffort(params) {
|
|
|
439
189
|
hidden: params.params.trigger === "memory",
|
|
440
190
|
message: attachUpstreamUserText(attachCodexMirrorIdentity(await buildResolvedCodexUserPromptMessage(params.params), `${params.turnId}:prompt`), params.upstreamUserText)
|
|
441
191
|
});
|
|
442
|
-
|
|
192
|
+
const recorder = params.params.userTurnTranscriptRecorder;
|
|
193
|
+
if (recorder?.getAdmissionReceipt() && recorder.getPersistedMessage?.()?.display !== false) {
|
|
443
194
|
const annotate = params.params.hostCapabilities.annotateCurrentUserTurn;
|
|
444
195
|
if (!annotate || userPromptMessage.role !== "user") throw new Error("current host admission is unavailable for native prompt annotation");
|
|
445
196
|
await annotate({
|
|
@@ -462,7 +213,7 @@ async function mirrorPromptAtTurnStartBestEffort(params) {
|
|
|
462
213
|
runMirrorIdentityPrefix: `${params.turnId}:`,
|
|
463
214
|
config: params.params.config
|
|
464
215
|
});
|
|
465
|
-
for (const receipt of mirrorResult.userMessageReceipts) params.notifyUserMessagePersisted(receipt
|
|
216
|
+
for (const receipt of mirrorResult.userMessageReceipts) params.notifyUserMessagePersisted(receipt);
|
|
466
217
|
})();
|
|
467
218
|
params.params.userTurnTranscriptRecorder?.markRuntimePersistencePending(mirrorPromise);
|
|
468
219
|
await mirrorPromise;
|
|
@@ -474,28 +225,16 @@ async function mirrorPromptAtTurnStartBestEffort(params) {
|
|
|
474
225
|
});
|
|
475
226
|
}
|
|
476
227
|
}
|
|
477
|
-
function fingerprintMirrorMessageContent(message) {
|
|
478
|
-
const payload = JSON.stringify({
|
|
479
|
-
role: message.role,
|
|
480
|
-
content: message.content
|
|
481
|
-
});
|
|
482
|
-
return createHash("sha256").update(payload).digest("hex").slice(0, 16);
|
|
483
|
-
}
|
|
484
|
-
function buildMirrorDedupeIdentity(message) {
|
|
485
|
-
return readMirrorIdentity(message) || `${message.role}:${fingerprintMirrorMessageContent(message)}`;
|
|
486
|
-
}
|
|
487
228
|
async function mirror(params) {
|
|
488
229
|
const messages = params.messages.filter(isMirroredAgentMessage);
|
|
489
230
|
if (messages.length === 0) return {
|
|
490
|
-
assistantMirrorIdentitiesAppended: [],
|
|
491
231
|
assistantMirrorIdentitiesOwned: [],
|
|
492
232
|
anchorsByMirrorIdentity: /* @__PURE__ */ new Map(),
|
|
493
233
|
messagesPresent: [],
|
|
494
|
-
userMessageReceipts: []
|
|
495
|
-
userMessagesPresent: []
|
|
234
|
+
userMessageReceipts: []
|
|
496
235
|
};
|
|
497
236
|
const candidates = messages.map((message) => {
|
|
498
|
-
const dedupeIdentity =
|
|
237
|
+
const dedupeIdentity = buildCodexMirrorDedupeIdentity(message);
|
|
499
238
|
const sourceFingerprint = fingerprintCodexMirrorSourceMessage(message);
|
|
500
239
|
return {
|
|
501
240
|
dedupeIdentity,
|
|
@@ -506,28 +245,33 @@ async function mirror(params) {
|
|
|
506
245
|
});
|
|
507
246
|
const candidateIdempotencyKeys = candidates.flatMap(({ idempotencyKey }) => idempotencyKey ? [idempotencyKey] : []);
|
|
508
247
|
const transcriptTarget = resolveCodexMirrorTranscriptTarget(params);
|
|
509
|
-
|
|
248
|
+
const assertWritable = () => {
|
|
249
|
+
params.assertCurrent?.();
|
|
250
|
+
params.assertWriteCurrent?.();
|
|
251
|
+
};
|
|
252
|
+
assertWritable();
|
|
510
253
|
const mirrorBatch = await withCodexSessionTranscriptMirrorWriteLock({
|
|
511
254
|
...transcriptTarget,
|
|
512
255
|
config: params.config
|
|
513
256
|
}, async (transcript) => {
|
|
514
|
-
|
|
257
|
+
assertWritable();
|
|
515
258
|
const nextAppendedUpdates = [];
|
|
516
|
-
const nextAssistantMirrorIdentitiesAppended = /* @__PURE__ */ new Set();
|
|
517
259
|
const nextAssistantMirrorIdentitiesOwned = /* @__PURE__ */ new Set();
|
|
518
260
|
const nextAnchorsByMirrorIdentity = /* @__PURE__ */ new Map();
|
|
519
261
|
const nextMessagesPresent = [];
|
|
520
262
|
const nextUserMessageReceipts = [];
|
|
521
|
-
const nextUserMessagesPresent = [];
|
|
522
263
|
const mirrorFacts = await transcript.readMessageFacts({ idempotencyKeys: candidateIdempotencyKeys });
|
|
523
|
-
|
|
264
|
+
assertWritable();
|
|
265
|
+
const taint = { tainted: false };
|
|
524
266
|
for (const { dedupeIdentity, idempotencyKey, message, sourceFingerprint } of candidates) {
|
|
267
|
+
const sourceMessage = applyCodexTranscriptTaint(message, taint);
|
|
525
268
|
const mirrorIdentity = readMirrorIdentity(message);
|
|
526
269
|
const ownsRun = Boolean(params.runId && (!params.runMirrorIdentityPrefix || mirrorIdentity?.startsWith(params.runMirrorIdentityPrefix)));
|
|
527
270
|
const terminalOwner = params.terminalAssistantOwner;
|
|
528
271
|
const ownsTerminal = Boolean(ownsRun && terminalOwner && mirrorIdentity === terminalOwner.mirrorIdentity);
|
|
272
|
+
const ownedMessage = ownsRun && params.runId ? attachCodexMirrorRunId(sourceMessage, params.runId, ownsTerminal, terminalOwner?.settlementWarning) : sourceMessage;
|
|
529
273
|
const transcriptMessage = {
|
|
530
|
-
...attachCodexMirrorAttestation(
|
|
274
|
+
...attachCodexMirrorAttestation(ownedMessage, sourceFingerprint),
|
|
531
275
|
...idempotencyKey ? { idempotencyKey } : {}
|
|
532
276
|
};
|
|
533
277
|
if (idempotencyKey && mirrorFacts.existingIdempotencyKeys.has(idempotencyKey)) {
|
|
@@ -535,18 +279,25 @@ async function mirror(params) {
|
|
|
535
279
|
const persistedAnchor = mirrorFacts.anchorsByIdempotencyKey.get(idempotencyKey);
|
|
536
280
|
if (persistedMessage && isMirroredAgentMessage(persistedMessage)) {
|
|
537
281
|
nextMessagesPresent.push(persistedMessage);
|
|
538
|
-
if (persistedMessage.role === "user") {
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
});
|
|
544
|
-
}
|
|
282
|
+
if (persistedMessage.role === "user" && persistedAnchor) nextUserMessageReceipts.push({
|
|
283
|
+
anchor: persistedAnchor,
|
|
284
|
+
appended: false,
|
|
285
|
+
message: persistedMessage
|
|
286
|
+
});
|
|
545
287
|
}
|
|
546
288
|
if (persistedAnchor) nextAnchorsByMirrorIdentity.set(dedupeIdentity, persistedAnchor);
|
|
547
289
|
if (message.role === "assistant") nextAssistantMirrorIdentitiesOwned.add(dedupeIdentity);
|
|
548
290
|
continue;
|
|
549
291
|
}
|
|
292
|
+
assertWritable();
|
|
293
|
+
const preparedUserMessage = transcriptMessage.role === "user" ? {
|
|
294
|
+
...transcriptMessage,
|
|
295
|
+
__openclaw: { ...Reflect.get(transcriptMessage, "__openclaw") }
|
|
296
|
+
} : void 0;
|
|
297
|
+
if (preparedUserMessage?.["__openclaw"].humanMentions !== void 0) {
|
|
298
|
+
preparedUserMessage.content = structuredClone(preparedUserMessage.content);
|
|
299
|
+
preparedUserMessage["__openclaw"].humanMentions = structuredClone(preparedUserMessage["__openclaw"].humanMentions);
|
|
300
|
+
}
|
|
550
301
|
const nextMessage = runAgentHarnessBeforeMessageWriteHook({
|
|
551
302
|
message: transcriptMessage,
|
|
552
303
|
agentId: params.agentId,
|
|
@@ -558,22 +309,27 @@ async function mirror(params) {
|
|
|
558
309
|
if (message.role === "assistant") nextAssistantMirrorIdentitiesOwned.add(dedupeIdentity);
|
|
559
310
|
continue;
|
|
560
311
|
}
|
|
312
|
+
const restoredMessage = restorePreparedUserTurnOperationalMetaForRuntime({
|
|
313
|
+
runtimeMessage: nextMessage,
|
|
314
|
+
preparedMessage: preparedUserMessage
|
|
315
|
+
});
|
|
561
316
|
let messageToAppend = idempotencyKey ? {
|
|
562
|
-
...attachCodexMirrorAttestation(
|
|
317
|
+
...attachCodexMirrorAttestation(restoredMessage, sourceFingerprint),
|
|
563
318
|
idempotencyKey
|
|
564
|
-
} : attachCodexMirrorAttestation(
|
|
319
|
+
} : attachCodexMirrorAttestation(restoredMessage, sourceFingerprint);
|
|
565
320
|
if (mirrorIdentity) messageToAppend = attachCodexMirrorIdentity(messageToAppend, mirrorIdentity);
|
|
566
|
-
if (ownsRun && params.runId) messageToAppend = attachCodexMirrorRunId(messageToAppend, params.runId, ownsTerminal);
|
|
321
|
+
if (ownsRun && params.runId) messageToAppend = attachCodexMirrorRunId(messageToAppend, params.runId, ownsTerminal, terminalOwner?.settlementWarning);
|
|
567
322
|
if (message.role === "assistant" && message.openclawAsyncDelivery) messageToAppend = Object.assign(messageToAppend, { openclawAsyncDelivery: { itemId: message.openclawAsyncDelivery.itemId } });
|
|
323
|
+
messageToAppend = applyCodexTranscriptTaint(messageToAppend, taint);
|
|
568
324
|
messageToAppend = projectAgentHarnessTranscriptMessageForDisplay({
|
|
569
325
|
hidden: message.display === false,
|
|
570
326
|
message: messageToAppend
|
|
571
327
|
});
|
|
572
|
-
|
|
328
|
+
assertWritable();
|
|
573
329
|
const { messageSeq, result: appended } = await transcript.appendMessageWithMessageSequence({
|
|
574
330
|
message: messageToAppend,
|
|
575
|
-
...params.assertCurrent ? { prepareMessageAfterIdempotencyCheck: (preparedMessage) => {
|
|
576
|
-
|
|
331
|
+
...params.assertCurrent || params.assertWriteCurrent ? { prepareMessageAfterIdempotencyCheck: (preparedMessage) => {
|
|
332
|
+
assertWritable();
|
|
577
333
|
return preparedMessage;
|
|
578
334
|
} } : {},
|
|
579
335
|
idempotencyLookup: "scan",
|
|
@@ -588,21 +344,16 @@ async function mirror(params) {
|
|
|
588
344
|
}
|
|
589
345
|
if (message.role === "assistant") nextAssistantMirrorIdentitiesOwned.add(dedupeIdentity);
|
|
590
346
|
if (appended.anchor) nextAnchorsByMirrorIdentity.set(dedupeIdentity, appended.anchor);
|
|
591
|
-
if (appendedMessage.role === "user" && appended.anchor) {
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
messageId,
|
|
602
|
-
message: appendedMessage,
|
|
603
|
-
...messageSeq !== void 0 ? { messageSeq } : {}
|
|
604
|
-
});
|
|
605
|
-
}
|
|
347
|
+
if (appendedMessage.role === "user" && appended.anchor) nextUserMessageReceipts.push({
|
|
348
|
+
anchor: appended.anchor,
|
|
349
|
+
appended: appended.appended,
|
|
350
|
+
message: appendedMessage
|
|
351
|
+
});
|
|
352
|
+
if (appended.appended) nextAppendedUpdates.push({
|
|
353
|
+
messageId,
|
|
354
|
+
message: appendedMessage,
|
|
355
|
+
...messageSeq !== void 0 ? { messageSeq } : {}
|
|
356
|
+
});
|
|
606
357
|
if (idempotencyKey) {
|
|
607
358
|
mirrorFacts.existingIdempotencyKeys.add(idempotencyKey);
|
|
608
359
|
if (appended.anchor) mirrorFacts.anchorsByIdempotencyKey.set(idempotencyKey, appended.anchor);
|
|
@@ -610,16 +361,14 @@ async function mirror(params) {
|
|
|
610
361
|
}
|
|
611
362
|
return {
|
|
612
363
|
appendedUpdates: nextAppendedUpdates,
|
|
613
|
-
assistantMirrorIdentitiesAppended: [...nextAssistantMirrorIdentitiesAppended],
|
|
614
364
|
assistantMirrorIdentitiesOwned: [...nextAssistantMirrorIdentitiesOwned],
|
|
615
365
|
anchorsByMirrorIdentity: nextAnchorsByMirrorIdentity,
|
|
616
366
|
messagesPresent: nextMessagesPresent,
|
|
617
|
-
userMessageReceipts: nextUserMessageReceipts
|
|
618
|
-
userMessagesPresent: nextUserMessagesPresent
|
|
367
|
+
userMessageReceipts: nextUserMessageReceipts
|
|
619
368
|
};
|
|
620
369
|
});
|
|
621
370
|
params.assertCurrent?.();
|
|
622
|
-
const { appendedUpdates,
|
|
371
|
+
const { appendedUpdates, ...result } = mirrorBatch;
|
|
623
372
|
for (const update of appendedUpdates) try {
|
|
624
373
|
const terminalOwner = params.terminalAssistantOwner;
|
|
625
374
|
const terminalRunId = update.message.role === "assistant" && terminalOwner && readMirrorIdentity(update.message) === terminalOwner.mirrorIdentity ? terminalOwner.runId : void 0;
|
|
@@ -637,14 +386,7 @@ async function mirror(params) {
|
|
|
637
386
|
} catch (error) {
|
|
638
387
|
embeddedAgentLog.warn("failed to publish codex app-server transcript update", { error: formatErrorMessage(error) });
|
|
639
388
|
}
|
|
640
|
-
return
|
|
641
|
-
assistantMirrorIdentitiesAppended,
|
|
642
|
-
assistantMirrorIdentitiesOwned,
|
|
643
|
-
anchorsByMirrorIdentity,
|
|
644
|
-
messagesPresent,
|
|
645
|
-
userMessageReceipts,
|
|
646
|
-
userMessagesPresent
|
|
647
|
-
};
|
|
389
|
+
return result;
|
|
648
390
|
}
|
|
649
391
|
async function deliverAsyncMessageBestEffort(params) {
|
|
650
392
|
const mirrorIdentity = `${params.turnId}:async:${params.itemId}`;
|
|
@@ -654,13 +396,22 @@ async function deliverAsyncMessageBestEffort(params) {
|
|
|
654
396
|
params.itemId
|
|
655
397
|
].map(encodeURIComponent).join(":")}`;
|
|
656
398
|
const target = params.params.sessionTarget;
|
|
657
|
-
|
|
658
|
-
|
|
399
|
+
let text;
|
|
400
|
+
if (target) {
|
|
401
|
+
let result;
|
|
659
402
|
try {
|
|
660
|
-
await
|
|
661
|
-
|
|
403
|
+
result = await mirror({
|
|
404
|
+
agentId: target.agentId ?? params.params.agentId,
|
|
405
|
+
sessionId: target.sessionId ?? params.params.sessionId,
|
|
406
|
+
sessionKey: target.sessionKey ?? params.params.sessionKey,
|
|
407
|
+
storePath: target.storePath,
|
|
408
|
+
cwd: params.cwd,
|
|
409
|
+
config: params.params.config,
|
|
410
|
+
messages: [attachCodexMirrorIdentity(params.message, mirrorIdentity)],
|
|
411
|
+
idempotencyScope: `codex-app-server:${params.threadId}`
|
|
412
|
+
});
|
|
662
413
|
} catch (error) {
|
|
663
|
-
embeddedAgentLog.warn("failed to
|
|
414
|
+
embeddedAgentLog.warn("failed to persist codex async agent message", {
|
|
664
415
|
error: formatErrorMessage(error),
|
|
665
416
|
itemId: params.itemId,
|
|
666
417
|
runId: params.params.runId,
|
|
@@ -669,35 +420,16 @@ async function deliverAsyncMessageBestEffort(params) {
|
|
|
669
420
|
});
|
|
670
421
|
return "retry";
|
|
671
422
|
}
|
|
423
|
+
if (!result.assistantMirrorIdentitiesOwned.includes(mirrorIdentity)) return "retry";
|
|
424
|
+
text = readMirroredAssistantText(result.messagesPresent.find((message) => readMirrorIdentity(message) === mirrorIdentity));
|
|
425
|
+
} else {
|
|
426
|
+
if (!params.params.onBlockReply) return "retry";
|
|
427
|
+
text = params.text;
|
|
672
428
|
}
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
result = await mirror({
|
|
676
|
-
agentId: target.agentId ?? params.params.agentId,
|
|
677
|
-
sessionId: target.sessionId ?? params.params.sessionId,
|
|
678
|
-
sessionKey: target.sessionKey ?? params.params.sessionKey,
|
|
679
|
-
storePath: target.storePath,
|
|
680
|
-
cwd: params.cwd,
|
|
681
|
-
config: params.params.config,
|
|
682
|
-
messages: [attachCodexMirrorIdentity(params.message, mirrorIdentity)],
|
|
683
|
-
idempotencyScope: `codex-app-server:${params.threadId}`
|
|
684
|
-
});
|
|
685
|
-
} catch (error) {
|
|
686
|
-
embeddedAgentLog.warn("failed to persist codex async agent message", {
|
|
687
|
-
error: formatErrorMessage(error),
|
|
688
|
-
itemId: params.itemId,
|
|
689
|
-
runId: params.params.runId,
|
|
690
|
-
threadId: params.threadId,
|
|
691
|
-
turnId: params.turnId
|
|
692
|
-
});
|
|
693
|
-
return "retry";
|
|
694
|
-
}
|
|
695
|
-
if (!result.assistantMirrorIdentitiesOwned.includes(mirrorIdentity)) return "retry";
|
|
696
|
-
const persistedText = readMirroredAssistantText(result.messagesPresent.find((message) => readMirrorIdentity(message) === mirrorIdentity));
|
|
697
|
-
if (params.params.onBlockReply && persistedText !== void 0) try {
|
|
698
|
-
await deliverAsyncBlockReply(params.params.onBlockReply, persistedText, deliveryIntentId);
|
|
429
|
+
if (params.params.onBlockReply && text !== void 0) try {
|
|
430
|
+
await deliverAsyncBlockReply(params.params.onBlockReply, text, deliveryIntentId);
|
|
699
431
|
} catch (error) {
|
|
700
|
-
embeddedAgentLog.warn("failed to deliver persisted codex async agent message", {
|
|
432
|
+
embeddedAgentLog.warn(target ? "failed to deliver persisted codex async agent message" : "failed to deliver codex async agent message", {
|
|
701
433
|
error: formatErrorMessage(error),
|
|
702
434
|
itemId: params.itemId,
|
|
703
435
|
runId: params.params.runId,
|
|
@@ -728,4 +460,4 @@ function resolveCodexMirrorTranscriptTarget(params) {
|
|
|
728
460
|
};
|
|
729
461
|
}
|
|
730
462
|
//#endregion
|
|
731
|
-
export {
|
|
463
|
+
export { transcript_mirror_exports as a, mirrorPromptAtTurnStartBestEffort as i, createCodexAppServerUserMessagePersistenceNotifier as n, buildCodexUserPromptMessage as o, importCodexThreadHistoryToTranscript as r, promptSnapshot as s, codexTranscriptMirrorRuntime as t };
|