@openclaw/codex 2026.9.4 → 2026.9.5

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 (148) hide show
  1. package/assets/activity.svg +30 -0
  2. package/assets/icon.png +0 -0
  3. package/dist/.setup/account-usage-runtime-C2MOIvfq.mjs +75 -0
  4. package/dist/{apply-CvT8tW5i.js → .setup/apply-CJ0ZfmBG.mjs} +11 -11
  5. package/dist/.setup/async-questions-DdhOCwGi.mjs +27 -0
  6. package/dist/{attempt-client-cleanup-DKHzbwt5.js → .setup/attempt-client-cleanup-BpYKdTA0.mjs} +29 -14
  7. package/dist/{attempt-context-D44yeDII.js → .setup/attempt-context-VXVwTCfS.mjs} +5 -5
  8. package/dist/.setup/attempt-terminal-gZrxQ35N.mjs +5 -0
  9. package/dist/{auth-binding-CWlKVccJ.js → .setup/auth-binding-DhLWa_7K.mjs} +1 -1
  10. package/dist/{auth-cache-key-7orQae_j.js → .setup/auth-cache-key-QirmgiCo.mjs} +3 -3
  11. package/dist/{auth-profile-CwzO4_RG.js → .setup/auth-profile-WqZtZfXN.mjs} +1 -1
  12. package/dist/.setup/binding-connection-Bm38niE8.mjs +50 -0
  13. package/dist/.setup/binding-connection.runtime-CnRMC0ta.mjs +48 -0
  14. package/dist/{bounded-turn-C_Hneydj.js → .setup/bounded-turn-BtlZcivC.mjs} +16 -11
  15. package/dist/{build-state-BCmg9-5p.js → .setup/build-state-Xx9ybZqa.mjs} +1 -1
  16. package/dist/{capabilities-8vx68WLH.js → .setup/capabilities-_vXcZGSx.mjs} +1 -1
  17. package/dist/{client-B57KWPQx.js → .setup/client-vXs2929Q.mjs} +332 -163
  18. package/dist/{command-dispatch-BpduNGVf.js → .setup/command-dispatch-naHIZwwF.mjs} +3 -3
  19. package/dist/{command-formatters-lxlkNZgU.js → .setup/command-formatters-CGEkdawF.mjs} +2 -2
  20. package/dist/{command-handlers-tiL9iWj7.js → .setup/command-handlers-BtAJEW1X.mjs} +59 -42
  21. package/dist/{command-rpc-CR5EOEZX.js → .setup/command-rpc-DHFpn4le.mjs} +22 -13
  22. package/dist/{compact-B_H3AOd7.js → .setup/compact-C3i3qlzj.mjs} +28 -43
  23. package/dist/{config-oIORaQ5T.js → .setup/config-CedDWjM-.mjs} +5 -4
  24. package/dist/{config-options-CXMq1T-C.js → .setup/config-options-BsanJ8QG.mjs} +6 -418
  25. package/dist/{protocol-5bh1G-H7.js → .setup/config-parsing-CcB9iPoq.mjs} +9 -51
  26. package/dist/{config-runtime-D0zGNIHu.js → .setup/config-runtime-CeAhl_h4.mjs} +2 -2
  27. package/dist/.setup/config-security-BRQ2mgW9.mjs +465 -0
  28. package/dist/{conversation-binding-DsB4-O7U.js → .setup/conversation-binding-DhzrpTM6.mjs} +23 -21
  29. package/dist/{conversation-binding-data-BiodpIzq.js → .setup/conversation-binding-data-CrcyZk6O.mjs} +1 -1
  30. package/dist/{conversation-control-CtUu1b3m.js → .setup/conversation-control-DN53ns41.mjs} +17 -13
  31. package/dist/.setup/cyber-failover-DYwbmf1o.mjs +123 -0
  32. package/dist/.setup/cyber-failover-notice-e9G3J9-e.mjs +17 -0
  33. package/dist/{dynamic-tools-CmN5RAip.js → .setup/dynamic-tools-D16lOp67.mjs} +101 -55
  34. package/dist/{effective-mcp-catalog-Bd73bqA8.js → .setup/effective-mcp-catalog-K6kLCN8X.mjs} +3 -3
  35. package/dist/{ephemeral-turn-D78_VmzO.js → .setup/ephemeral-turn-R1gA8Sn6.mjs} +4 -5
  36. package/dist/{event-projector-assistant-message-BmBM4qBV.js → .setup/event-projector-assistant-message-DNUR1s0A.mjs} +6 -3
  37. package/dist/{event-projector-items-5VhsECCO.js → .setup/event-projector-items-DyTQ_XqL.mjs} +1 -1
  38. package/dist/{attempt-notifications-C9XufG6l.js → .setup/event-projector-usage-C7Ntzs-f.mjs} +102 -9
  39. package/dist/{harness-C7rRa7bm.js → .setup/harness-rxaaoN-o.mjs} +74 -20
  40. package/dist/{inference-context-Dr_mzvk4.js → .setup/inference-context-fulhZuz8.mjs} +1 -1
  41. package/dist/{inference-proxy-HGXKUIre.js → .setup/inference-proxy-CC15HuSi.mjs} +4 -4
  42. package/dist/{isolated-completion-DWVb5U2J.js → .setup/isolated-completion-B6srt48J.mjs} +7 -7
  43. package/dist/{launch-args-RXQwn8zV.js → .setup/launch-args-DnMak49W.mjs} +22 -1
  44. package/dist/{managed-binary-D22rNEcR.js → .setup/managed-binary-DP6Rib3P.mjs} +2 -2
  45. package/dist/{managed-thread-store-D1t5jh3G.js → .setup/managed-thread-store-BMqgThVL.mjs} +48 -14
  46. package/dist/{model-catalog-Dq2n8f_p.js → .setup/model-catalog-DkvUuBey.mjs} +35 -10
  47. package/dist/{models-PCKOim-h.js → .setup/models-BDFgm_G-.mjs} +3 -3
  48. package/dist/.setup/native-auth-BLZGqFjw.mjs +57 -0
  49. package/dist/{native-subagent-history-DjtPloaU.js → .setup/native-subagent-history-YXaL6dMd.mjs} +24 -29
  50. package/dist/.setup/native-subagent-monitor-B1hxzIOy.mjs +5031 -0
  51. package/dist/{native-subagent-task-ids-BzTdT0Uw.js → .setup/native-subagent-task-ids-DsuOonKv.mjs} +32 -8
  52. package/dist/{node-cli-sessions-DKaOmVUh.js → .setup/node-cli-sessions-Cl8b2ZF3.mjs} +1 -1
  53. package/dist/{node-exec-server.runtime-Cl2vapEi.js → .setup/node-exec-server.runtime-BaViBKNz.mjs} +3 -3
  54. package/dist/{plan-7uG-Fp36.js → .setup/plan-xD7WKYTM.mjs} +64 -48
  55. package/dist/{plugin-activation-BYQculil.js → .setup/plugin-activation-r8nq5Jzp.mjs} +3 -3
  56. package/dist/{plugin-app-cache-key-d0eKxy7b.js → .setup/plugin-app-cache-key-BOxKP7db.mjs} +29 -25
  57. package/dist/{plugin-approval-roundtrip-Bz3FT8W5.js → .setup/plugin-approval-roundtrip-CjfzafAZ.mjs} +1 -1
  58. package/dist/{plugin-inventory-oL4Na1ZG.js → .setup/plugin-inventory-DUle8DLz.mjs} +7 -6
  59. package/dist/{plugin-metadata-cache-ClPJpRio.js → .setup/plugin-metadata-cache-DsS5buNa.mjs} +29 -14
  60. package/dist/{provider-capabilities-BvCUL69A.js → .setup/provider-capabilities-B8J4Dy-O.mjs} +2 -2
  61. package/dist/{provider-MQ8PVkuE.js → .setup/provider-fFh_-VR3.mjs} +4 -4
  62. package/dist/{rate-limits-CBMmWBr9.js → .setup/rate-limits-DOEGYRNs.mjs} +90 -46
  63. package/dist/{request-B7hEkBGq.js → .setup/request-BioXJLYa.mjs} +113 -33
  64. package/dist/.setup/run-attempt-lifecycle-B7JbY4-F.mjs +71 -0
  65. package/dist/{run-attempt-CvsAAGa0.js → .setup/run-attempt-rlA07pUv.mjs} +580 -498
  66. package/dist/{runtime-artifact-BJ0rXBZ_.js → .setup/runtime-artifact-Dy38Z5iU.mjs} +2 -2
  67. package/dist/{sandbox-guard-BxgyoM8M.js → .setup/sandbox-guard-BBP-RbTf.mjs} +3 -3
  68. package/dist/{session-binding-CI8UuilT.js → .setup/session-binding-_0W_fHRr.mjs} +46 -64
  69. package/dist/{session-binding-record-Bcvslnhf.js → .setup/session-binding-record-TH3xA0zj.mjs} +181 -3
  70. package/dist/.setup/session-binding-sidecars-CKYEcfNn.mjs +543 -0
  71. package/dist/{session-catalog-adoption-tcZi1IfX.js → .setup/session-catalog-adoption-CR_whkEW.mjs} +6 -6
  72. package/dist/{session-catalog-archive-CwKg8Xz2.js → .setup/session-catalog-archive-CwZaPacf.mjs} +6 -6
  73. package/dist/.setup/session-catalog-events-jMcYfQyd.mjs +250 -0
  74. package/dist/.setup/session-catalog-fUdWDx-U.mjs +2464 -0
  75. package/dist/.setup/session-catalog-index-B141u15s.mjs +1070 -0
  76. package/dist/.setup/session-catalog-index-order-Cc5BzlQr.mjs +48 -0
  77. package/dist/.setup/session-catalog-index-state-BAuDztHN.mjs +180 -0
  78. package/dist/{thread-history-page-D0JIp48V.js → .setup/session-catalog-native-projection-ChV3cCtm.mjs} +206 -95
  79. package/dist/{session-catalog-node-adoption-B1tgDW-m.js → .setup/session-catalog-node-adoption-BVRsYOSh.mjs} +3 -3
  80. package/dist/{session-catalog-node-continue-Ci-DXyJP.js → .setup/session-catalog-node-continue-Dowv8osw.mjs} +7 -7
  81. package/dist/.setup/session-catalog-projection-C1Bj9Jl-.mjs +414 -0
  82. package/dist/{session-cli-DNN_jhGc.js → .setup/session-cli-DIj-IE-E.mjs} +4 -4
  83. package/dist/{session-history-Cz-tOOYj.js → .setup/session-history-C--SrLI8.mjs} +10 -5
  84. package/dist/{session-history-import-DwyijFI6.js → .setup/session-history-import-JHXT5Xfi.mjs} +4 -4
  85. package/dist/{session-history-read-cxPUxyVV.js → .setup/session-history-read-B3ZfSUbF.mjs} +2 -2
  86. package/dist/{session-history.worker-BeK1YOyT.js → .setup/session-history.worker-CpNj7H_P.mjs} +5 -6
  87. package/dist/{session-initialization-Ct0_Hzmg.js → .setup/session-initialization-DH1z6fXn.mjs} +2 -2
  88. package/dist/{session-permission-policy-BBmXA8Eg.js → .setup/session-permission-policy-DhurXY0l.mjs} +2 -2
  89. package/dist/{session-retirement-B2YfbAAT.js → .setup/session-retirement-CU87AOg9.mjs} +6 -6
  90. package/dist/{settled-turn-context-Du6gdUDd.js → .setup/settled-turn-context-fmwouT5I.mjs} +2 -2
  91. package/dist/{settled-turn-finalizer-Dn91stmc.js → .setup/settled-turn-finalizer-CiY2bLFK.mjs} +9 -9
  92. package/dist/{shared-client-CscigXXL.js → .setup/shared-client-BpTtuLQ5.mjs} +286 -145
  93. package/dist/{side-question-BGMJQf4U.js → .setup/side-question-DSCZyoBD.mjs} +64 -47
  94. package/dist/{source-CElXU0Oy.js → .setup/source-Bjp4UQij.mjs} +7 -6
  95. package/dist/{thread-archive-guard-DfpBr-Sz.js → .setup/thread-archive-guard-jmecf6OJ.mjs} +1 -1
  96. package/dist/.setup/thread-history-page-BTx-4xsg.mjs +83 -0
  97. package/dist/{thread-lifecycle-DXl1-I6b.js → .setup/thread-lifecycle-Cik28qWn.mjs} +256 -128
  98. package/dist/{thread-ownership-BsDRTsyp.js → .setup/thread-ownership-skomxnIt.mjs} +4 -4
  99. package/dist/{thread-policy-BuEQfE0g.js → .setup/thread-policy-Cjs4B8xf.mjs} +2 -2
  100. package/dist/{thread-resume-DsDOZpFg.js → .setup/thread-resume-BkNpj9Pz.mjs} +8 -5
  101. package/dist/.setup/timeout-DZF05XrR.mjs +63 -0
  102. package/dist/{transcript-history-projection-v17wXgdK.js → .setup/transcript-history-projection-DHNBDhCU.mjs} +8 -3
  103. package/dist/{transcript-mirror-C5CKgNy6.js → .setup/transcript-mirror-D4qp_leP.mjs} +15 -6
  104. package/dist/{transcript-mirror-attestation-DibE0krH.js → .setup/transcript-mirror-attestation-CzM-94NC.mjs} +4 -1
  105. package/dist/{transport-stdio-BGjHoYLr.js → .setup/transport-stdio-Cmx94Oiy.mjs} +149 -44
  106. package/dist/{upstream-session-fork-BZerMte_.js → .setup/upstream-session-fork-D3UKxgVD.mjs} +27 -26
  107. package/dist/{usage-tCk-mg_x.js → .setup/usage-BOgBEKso.mjs} +4 -4
  108. package/dist/.setup/usage-limit-error-C0ow7DOc.mjs +166 -0
  109. package/dist/{version-omm6IPI3.js → .setup/version-CoqzXPgK.mjs} +1 -1
  110. package/dist/{web-search-provider.runtime-B7bGbGWq.js → .setup/web-search-provider.runtime-CTGuJt6i.mjs} +3 -3
  111. package/dist/api.js +6 -6
  112. package/dist/cli-metadata.js +1 -1
  113. package/dist/doctor-contract-api.js +8 -528
  114. package/dist/harness.js +1 -1
  115. package/dist/index.js +123 -83
  116. package/dist/media-understanding-provider.js +3 -3
  117. package/dist/migration-provider-api.js +1 -1
  118. package/dist/native-tool-policy.js +12 -0
  119. package/dist/provider-discovery.js +18 -0
  120. package/dist/session-history-worker-runtime.js +23 -5
  121. package/dist/session-history.worker.js +2 -2
  122. package/dist/web-search-contract-api.js +1 -1
  123. package/openclaw.plugin.json +354 -69
  124. package/package.json +11 -8
  125. package/dist/binding-connection-D3udKbIE.js +0 -60
  126. package/dist/event-projector-usage-BfXmpOec.js +0 -102
  127. package/dist/native-subagent-history-owner-Pcp7JuVF.js +0 -34
  128. package/dist/native-subagent-monitor-fQ7eIXEf.js +0 -2978
  129. package/dist/rpc-error-ttN_QjEm.js +0 -30
  130. package/dist/session-catalog-ct-AH01I.js +0 -1477
  131. package/dist/session-catalog-home-id-CwhLdC03.js +0 -18
  132. package/dist/session-catalog-provenance-D-dIfRAH.js +0 -96
  133. package/dist/timeout-BVw8aaM1.js +0 -33
  134. package/dist/{auth-profile-selection-DFu9e167.js → .setup/auth-profile-selection-DFu9e167.mjs} +0 -0
  135. package/dist/{config-utils-DujwEnhg.js → .setup/config-utils-DujwEnhg.mjs} +0 -0
  136. package/dist/{context-compaction-activity-CMla5FPJ.js → .setup/context-compaction-activity-CMla5FPJ.mjs} +0 -0
  137. package/dist/{elicitation-input-DPoK8F7w.js → .setup/elicitation-input-DPoK8F7w.mjs} +0 -0
  138. package/dist/{history-rejection-B4nOXNXF.js → .setup/history-rejection-B4nOXNXF.mjs} +0 -0
  139. package/dist/{image-payload-sanitizer-tupAr-2o.js → .setup/image-payload-sanitizer-tupAr-2o.mjs} +0 -0
  140. package/dist/{incognito-session-uhrBF6wJ.js → .setup/incognito-session-uhrBF6wJ.mjs} +0 -0
  141. package/dist/{local-runtime-attribution-B_2mnqhb.js → .setup/local-runtime-attribution-B_2mnqhb.mjs} +0 -0
  142. package/dist/{native-execution-policy-umd0tgh4.js → .setup/native-execution-policy-YBMHSzC4.mjs} +1 -1
  143. /package/dist/{plugin-marketplace-discovery-P-Vndfqq.js → .setup/plugin-marketplace-discovery-P-Vndfqq.mjs} +0 -0
  144. /package/dist/{rolldown-runtime-8H4AJuhK.js → .setup/rolldown-runtime-8H4AJuhK.mjs} +0 -0
  145. /package/dist/{session-binding-meta-B7aEMU7g.js → .setup/session-binding-meta-B7aEMU7g.mjs} +0 -0
  146. /package/dist/{session-upstream-marker-D15C9NHp.js → .setup/session-upstream-marker-D15C9NHp.mjs} +0 -0
  147. /package/dist/{upstream-prompt-provenance-LphB8slG.js → .setup/upstream-prompt-provenance-LphB8slG.mjs} +0 -0
  148. /package/dist/{web-search-provider.shared-BrZmlqyR.js → .setup/web-search-provider.shared-BrZmlqyR.mjs} +0 -0
@@ -1,17 +1,7 @@
1
- import { n as CODEX_APP_SERVER_BINDING_NAMESPACE, t as CODEX_APP_SERVER_BINDING_MAX_ENTRIES } from "./session-binding-meta-B7aEMU7g.js";
2
- import { asNullableRecord, asOptionalRecord, isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
1
+ import { n as CODEX_APP_SERVER_BINDING_NAMESPACE } from "./.setup/session-binding-meta-B7aEMU7g.mjs";
2
+ import { asNullableRecord, asOptionalRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
3
3
  import { createHash } from "node:crypto";
4
- import { listAgentIds, resolveAgentDir, resolveSessionAgentIdsStrict } from "openclaw/plugin-sdk/agent-scope-runtime";
5
- import path from "node:path";
6
- import fs from "node:fs/promises";
7
4
  import { setImmediate } from "node:timers/promises";
8
- import { canonicalPathFromExistingAncestor, isPathInside } from "openclaw/plugin-sdk/file-access-runtime";
9
- import { isDeepStrictEqual } from "node:util";
10
- import { withFileLock } from "openclaw/plugin-sdk/file-lock";
11
- import { normalizeAgentId } from "openclaw/plugin-sdk/routing";
12
- import { archiveLegacyStateSource, legacyStateFileExists } from "openclaw/plugin-sdk/runtime-doctor-migrations";
13
- import { pathExists } from "openclaw/plugin-sdk/security-runtime";
14
- import { resolveStorePath } from "openclaw/plugin-sdk/session-store-paths";
15
5
  //#region extensions/codex/src/migration/session-binding-orphans.ts
16
6
  const PAGE_SIZE = 512;
17
7
  const KEY_PREFIXES = ["session-key:", "session:"];
@@ -109,521 +99,6 @@ const codexOrphanedSessionBindingMigration = {
109
99
  }
110
100
  };
111
101
  //#endregion
112
- //#region extensions/codex/src/migration/session-binding-sidecars.ts
113
- const LEGACY_BINDING_SUFFIX = ".codex-app-server.json";
114
- const CODEX_AGENT_HARNESS_ID = "codex";
115
- const MAX_SESSION_DIRECTORY_DEPTH = 16;
116
- const LEGACY_BINDING_LOCK_OPTIONS = {
117
- retries: {
118
- retries: 75,
119
- factor: 1,
120
- minTimeout: 1e3,
121
- maxTimeout: 1e3
122
- },
123
- stale: 12e4
124
- };
125
- async function collectSessionSurfaces(params) {
126
- const surfaces = /* @__PURE__ */ new Map();
127
- const stateRoot = await canonicalPathFromExistingAncestor(params.stateDir);
128
- const add = async (root, storePath, agentId, scan) => {
129
- const canonicalRoot = await canonicalPathFromExistingAncestor(root);
130
- const surface = surfaces.get(canonicalRoot) ?? {
131
- root: canonicalRoot,
132
- scan: false,
133
- storePaths: /* @__PURE__ */ new Set(),
134
- agentIds: /* @__PURE__ */ new Set()
135
- };
136
- surface.scan ||= scan;
137
- surface.storePaths.add(path.resolve(storePath));
138
- if (agentId) surface.agentIds.add(agentId);
139
- surfaces.set(canonicalRoot, surface);
140
- };
141
- const agentIds = new Set(listAgentIds(params.config));
142
- const agentsDir = path.join(params.stateDir, "agents");
143
- for (const entry of await readDirectoryEntries(agentsDir)) {
144
- if (!entry.isDirectory() || entry.isSymbolicLink()) continue;
145
- const agentId = resolveSessionAgentIdsStrict({
146
- agentId: entry.name,
147
- config: params.config
148
- }).sessionAgentId;
149
- agentIds.add(agentId);
150
- const root = path.join(agentsDir, entry.name, "sessions");
151
- await add(root, path.join(root, "sessions.json"), agentId, true);
152
- }
153
- for (const agentId of agentIds) {
154
- const storePath = resolveStorePath(params.config.session?.store, {
155
- agentId,
156
- env: params.env
157
- });
158
- const root = path.dirname(storePath);
159
- await add(root, storePath, agentId, isPathInside(stateRoot, await canonicalPathFromExistingAncestor(root)));
160
- }
161
- const legacyRoot = path.join(params.stateDir, "sessions");
162
- const legacyOwner = tryResolveLegacyBindingOwnerAgentId({
163
- sessionKey: "",
164
- config: params.config
165
- });
166
- await add(legacyRoot, path.join(legacyRoot, "sessions.json"), legacyOwner, true);
167
- return [...surfaces.values()].toSorted((a, b) => a.root.localeCompare(b.root));
168
- }
169
- async function collectLegacyBindingSources(params, options = {}) {
170
- const surfaces = await collectSessionSurfaces(params);
171
- const sources = /* @__PURE__ */ new Map();
172
- const addSource = async (sidecarPath, surface) => {
173
- const canonicalSidecar = await canonicalPathFromExistingAncestor(sidecarPath);
174
- const source = sources.get(canonicalSidecar) ?? {
175
- sidecarPath: canonicalSidecar,
176
- transcriptPath: sidecarPath.slice(0, -22),
177
- agentIds: /* @__PURE__ */ new Set()
178
- };
179
- for (const agentId of surface.agentIds) source.agentIds.add(agentId);
180
- sources.set(canonicalSidecar, source);
181
- return source;
182
- };
183
- for (const surface of surfaces) {
184
- const sidecars = surface.scan ? walkSidecars(surface.root) : iterateIndexedSidecars(surface);
185
- for await (const sidecarPath of sidecars) {
186
- const source = await addSource(sidecarPath, surface);
187
- if (options.firstOnly) return {
188
- sources: [source],
189
- surfaces
190
- };
191
- }
192
- }
193
- return {
194
- sources: [...sources.values()].toSorted((a, b) => a.sidecarPath.localeCompare(b.sidecarPath)),
195
- surfaces
196
- };
197
- }
198
- async function readLegacySessionIndex(storePath) {
199
- let contents;
200
- try {
201
- contents = await fs.readFile(storePath, "utf8");
202
- } catch (error) {
203
- const code = error.code;
204
- return code === "ENOENT" ? { entries: [] } : { failure: `session index ${storePath} could not be read${code ? ` (${code})` : ""}` };
205
- }
206
- let raw;
207
- try {
208
- raw = JSON.parse(contents);
209
- } catch {
210
- return { failure: `session index ${storePath} could not be read (invalid JSON)` };
211
- }
212
- if (!isRecord(raw)) return { failure: `session index ${storePath} has invalid entries` };
213
- const entries = [];
214
- for (const [sessionKey, value] of Object.entries(raw)) {
215
- if (!isRecord(value)) return { failure: `session index ${storePath} has invalid entries` };
216
- if (value.sessionId === void 0) continue;
217
- const sessionId = typeof value.sessionId === "string" ? value.sessionId.trim() : "";
218
- const sessionFile = value.sessionFile;
219
- const lifecycleRevision = value.lifecycleRevision;
220
- const agentHarnessId = value.agentHarnessId;
221
- if (!isSafeLegacySessionId(value.sessionId) || sessionFile !== void 0 && typeof sessionFile !== "string" || lifecycleRevision !== void 0 && typeof lifecycleRevision !== "string" || agentHarnessId !== void 0 && typeof agentHarnessId !== "string") return { failure: `session index ${storePath} has invalid entries` };
222
- entries.push({
223
- sessionKey,
224
- entry: {
225
- sessionId,
226
- ...typeof sessionFile === "string" ? { sessionFile } : {},
227
- ...typeof lifecycleRevision === "string" ? { lifecycleRevision } : {},
228
- ...typeof agentHarnessId === "string" ? { agentHarnessId } : {},
229
- ...typeof value.updatedAt === "number" && Number.isFinite(value.updatedAt) && value.updatedAt >= 0 ? { updatedAt: value.updatedAt } : {}
230
- }
231
- });
232
- }
233
- return { entries };
234
- }
235
- async function* iterateIndexedSidecars(surface) {
236
- for (const storePath of surface.storePaths) {
237
- const index = await readLegacySessionIndex(storePath);
238
- if ("failure" in index) continue;
239
- for (const { entry } of index.entries) {
240
- if ((entry.sessionFile?.trim() ?? "").startsWith("sqlite:")) continue;
241
- let transcriptPath;
242
- try {
243
- transcriptPath = await resolveLegacySessionFileLocator(path.dirname(storePath), entry, entry.sessionId);
244
- } catch {
245
- continue;
246
- }
247
- const sidecarPath = `${transcriptPath}${LEGACY_BINDING_SUFFIX}`;
248
- if (await legacyStateFileExists(sidecarPath)) yield sidecarPath;
249
- }
250
- }
251
- }
252
- async function* walkSidecars(root) {
253
- const pending = [{
254
- directory: root,
255
- depth: 0
256
- }];
257
- while (pending.length > 0) {
258
- const current = pending.pop();
259
- for (const entry of (await readDirectoryEntries(current.directory)).toSorted((a, b) => a.name.localeCompare(b.name))) {
260
- if (entry.isSymbolicLink()) continue;
261
- const entryPath = path.join(current.directory, entry.name);
262
- if (entry.isFile() && entry.name.endsWith(LEGACY_BINDING_SUFFIX)) yield entryPath;
263
- else if (entry.isDirectory() && current.depth < MAX_SESSION_DIRECTORY_DEPTH) pending.push({
264
- directory: entryPath,
265
- depth: current.depth + 1
266
- });
267
- }
268
- }
269
- }
270
- async function collectBindingOwners(sources, surfaces, params) {
271
- const sourcePaths = new Set(await Promise.all(sources.map((source) => canonicalPathFromExistingAncestor(source.transcriptPath))));
272
- const owners = /* @__PURE__ */ new Map();
273
- const storePaths = new Set(surfaces.flatMap((surface) => [...surface.storePaths]));
274
- const storeAgentIds = /* @__PURE__ */ new Map();
275
- for (const surface of surfaces) for (const storePath of surface.storePaths) {
276
- const agents = storeAgentIds.get(storePath) ?? /* @__PURE__ */ new Set();
277
- for (const agentId of surface.agentIds) agents.add(agentId);
278
- storeAgentIds.set(storePath, agents);
279
- }
280
- const failures = [];
281
- for (const storePath of storePaths) {
282
- const canonicalStorePath = await canonicalPathFromExistingAncestor(storePath);
283
- const index = await readLegacySessionIndex(storePath);
284
- if ("failure" in index) {
285
- failures.push(index.failure);
286
- continue;
287
- }
288
- const sessionsDir = path.dirname(storePath);
289
- for (const { sessionKey, entry } of index.entries) {
290
- const sessionId = entry.sessionId;
291
- const agentId = tryResolveLegacyBindingOwnerAgentId({
292
- sessionKey,
293
- config: params.config,
294
- storeAgentIds: storeAgentIds.get(storePath)
295
- });
296
- if (!agentId) {
297
- failures.push(`session index ${storePath} has an ambiguous owner for ${sessionKey}`);
298
- continue;
299
- }
300
- let legacyTranscriptPath;
301
- let canonicalLegacyTranscriptPath;
302
- try {
303
- legacyTranscriptPath = await resolveLegacySessionFileLocator(sessionsDir, entry, sessionId);
304
- canonicalLegacyTranscriptPath = await canonicalPathFromExistingAncestor(legacyTranscriptPath);
305
- } catch {
306
- failures.push(`session index ${storePath} has an invalid locator for ${sessionKey}`);
307
- continue;
308
- }
309
- if (!sourcePaths.has(canonicalLegacyTranscriptPath)) continue;
310
- const owner = {
311
- agentId,
312
- sessionId,
313
- sessionKey,
314
- storePath,
315
- transcriptPath: legacyTranscriptPath,
316
- ...entry.lifecycleRevision ? { lifecycleRevision: entry.lifecycleRevision } : {},
317
- ...entry.agentHarnessId?.trim() ? { agentHarnessId: entry.agentHarnessId.trim() } : {},
318
- ...entry.updatedAt !== void 0 ? { updatedAt: entry.updatedAt } : {}
319
- };
320
- const candidates = owners.get(canonicalLegacyTranscriptPath) ?? /* @__PURE__ */ new Map();
321
- const ownerKey = `${agentId}\0${sessionId}\0${sessionKey}\0${canonicalStorePath}`;
322
- const configuredStorePath = resolveStorePath(params.config.session?.store, {
323
- agentId,
324
- env: params.env
325
- });
326
- if (!candidates.has(ownerKey) || storePath === configuredStorePath) candidates.set(ownerKey, owner);
327
- owners.set(canonicalLegacyTranscriptPath, candidates);
328
- }
329
- }
330
- return {
331
- owners: new Map([...owners].map(([key, values]) => [key, [...values.values()]])),
332
- failures
333
- };
334
- }
335
- async function resolveLegacySessionFileLocator(sessionsDir, entry, sessionId) {
336
- const base = path.resolve(sessionsDir);
337
- const fallback = path.join(base, `${sessionId}.jsonl`);
338
- const sessionFile = entry.sessionFile?.trim();
339
- if (!sessionFile) return fallback;
340
- const candidate = path.resolve(base, sessionFile);
341
- const [canonicalBase, canonicalCandidate] = await Promise.all([canonicalPathFromExistingAncestor(base), canonicalPathFromExistingAncestor(candidate)]);
342
- if (!isPathInside(canonicalBase, canonicalCandidate)) throw new Error("legacy session file locator escapes its session directory");
343
- return candidate;
344
- }
345
- function tryResolveLegacyBindingOwnerAgentId(params) {
346
- if (params.sessionKey.trim().toLowerCase().startsWith("agent:")) return resolveSessionAgentIdsStrict({
347
- sessionKey: params.sessionKey,
348
- config: params.config
349
- }).sessionAgentId;
350
- const storeAgentId = params.storeAgentIds?.size === 1 ? [...params.storeAgentIds][0] : void 0;
351
- const configuredAgentId = params.config.agents?.defaults?.systemAgent?.agentId?.trim();
352
- const systemAgentId = !storeAgentId && configuredAgentId ? normalizeAgentId(configuredAgentId) : void 0;
353
- const fallbackAgentIds = systemAgentId && listAgentIds(params.config).includes(systemAgentId) ? [void 0, systemAgentId] : [void 0];
354
- for (const fallbackAgentId of fallbackAgentIds) try {
355
- return resolveSessionAgentIdsStrict({
356
- sessionKey: params.sessionKey,
357
- config: params.config,
358
- ...storeAgentId ? { agentId: storeAgentId } : fallbackAgentId ? { fallbackAgentId } : {}
359
- }).sessionAgentId;
360
- } catch (error) {
361
- if (error.code !== "AGENT_SELECTION_REQUIRED") throw error;
362
- }
363
- }
364
- function copyBindingForSession(stored, sessionId) {
365
- return stored.state === "active" ? {
366
- version: 1,
367
- state: "active",
368
- binding: stored.binding,
369
- sessionId
370
- } : {
371
- version: 1,
372
- state: "cleared",
373
- sessionId,
374
- ...stored.retired ? { retired: true } : {}
375
- };
376
- }
377
- async function migrateSource(source, candidates, params, store) {
378
- let importedKeys = 0;
379
- const retain = (reason) => ({
380
- archived: false,
381
- importedKeys,
382
- warning: `Left Codex binding sidecar in place because ${reason}: ${source.sidecarPath}`
383
- });
384
- const retainNotice = (reason) => ({
385
- archived: false,
386
- importedKeys,
387
- notice: `Left Codex binding sidecar in place because ${reason}: ${source.sidecarPath}`
388
- });
389
- const owner = candidates.length === 1 ? candidates[0] : void 0;
390
- try {
391
- return await withFileLock(source.sidecarPath, LEGACY_BINDING_LOCK_OPTIONS, async () => {
392
- const [contents, stat] = await Promise.all([fs.readFile(source.sidecarPath, "utf8"), fs.stat(source.sidecarPath)]);
393
- const raw = JSON.parse(contents);
394
- const [{ bindingStoreKey, createStoredCodexAppServerBinding, normalizeStoredCodexAppServerBindingFingerprints, readStoredCodexAppServerBinding }, { legacyCodexConversationBindingId }] = await Promise.all([import("./session-binding-CI8UuilT.js").then((n) => n.c), import("./conversation-binding-data-BiodpIzq.js").then((n) => n.t)]);
395
- const agentId = owner?.agentId ?? (source.agentIds.size === 1 ? [...source.agentIds][0] : void 0);
396
- const baseStored = createStoredCodexAppServerBinding(raw, {
397
- now: stat.mtime.toISOString(),
398
- lookup: {
399
- config: params.config,
400
- ...agentId ? { agentDir: resolveAgentDir(params.config, agentId, params.env) } : {}
401
- }
402
- });
403
- if (!baseStored) return retain("its binding is invalid");
404
- if (candidates.length > 1) return retain(`${candidates.length} matching session owners make ownership ambiguous`);
405
- if (owner?.agentHarnessId && owner.agentHarnessId !== CODEX_AGENT_HARNESS_ID) return retainNotice(`its session is owned by agent harness ${owner.agentHarnessId}`);
406
- const sourceSessionFile = typeof raw.sessionFile === "string" && raw.sessionFile.trim() ? raw.sessionFile : source.transcriptPath;
407
- const ownerSessionFile = typeof raw.sessionFile === "string" && raw.sessionFile.trim() ? raw.sessionFile : owner?.transcriptPath;
408
- const conversationKeys = [sourceSessionFile, ...ownerSessionFile && ownerSessionFile !== sourceSessionFile ? [ownerSessionFile] : []].map((sessionFile) => bindingStoreKey({
409
- kind: "conversation",
410
- bindingId: legacyCodexConversationBindingId(sessionFile)
411
- }));
412
- const normalizeStoredRow = async (key, current) => {
413
- const parsed = readStoredCodexAppServerBinding(current);
414
- if (!parsed) return { warning: `canonical plugin state is invalid at ${key}` };
415
- const normalized = normalizeStoredCodexAppServerBindingFingerprints(parsed);
416
- if (!normalized) return { warning: `canonical plugin state is invalid at ${key}` };
417
- if (isDeepStrictEqual(parsed, normalized)) return { value: parsed };
418
- if (parsed.lease && parsed.lease.expiresAt > Date.now()) return { warning: `canonical plugin state is leased at ${key}` };
419
- const update = store.update;
420
- if (!update) return { warning: `canonical plugin state could not be normalized at ${key}` };
421
- await update(key, (candidate) => {
422
- const candidateParsed = readStoredCodexAppServerBinding(candidate);
423
- if (!candidateParsed || !isDeepStrictEqual(candidateParsed, parsed)) return;
424
- return normalized;
425
- });
426
- const persisted = readStoredCodexAppServerBinding(await store.lookup(key));
427
- if (!persisted || !isDeepStrictEqual(persisted, normalized)) return { warning: `canonical plugin state changed at ${key}` };
428
- importedKeys++;
429
- return { value: normalized };
430
- };
431
- let currentConversation;
432
- for (const key of conversationKeys) {
433
- const current = await store.lookup(key);
434
- if (current === void 0) continue;
435
- const result = await normalizeStoredRow(key, current);
436
- if (result.warning || !result.value) return retain(result.warning ?? `canonical plugin state is invalid at ${key}`);
437
- currentConversation ??= result.value;
438
- }
439
- const stored = currentConversation ?? baseStored;
440
- const sessionKey = owner ? bindingStoreKey({
441
- kind: "session",
442
- agentId: owner.agentId,
443
- sessionId: owner.sessionId,
444
- sessionKey: owner.sessionKey
445
- }) : void 0;
446
- const conversationEntries = conversationKeys.map((key) => ({
447
- key,
448
- value: stored
449
- }));
450
- const sessionEntry = owner && sessionKey ? {
451
- key: sessionKey,
452
- value: copyBindingForSession(stored, owner.sessionId)
453
- } : void 0;
454
- const entries = [...conversationEntries, ...sessionEntry ? [sessionEntry] : []];
455
- const hasExpected = (value, target) => {
456
- const parsed = readStoredCodexAppServerBinding(value);
457
- if (!parsed) return false;
458
- return target.state === "cleared" ? parsed.state === "cleared" && parsed.sessionId === target.sessionId && parsed.retired === target.retired : parsed.state === "active" && parsed.sessionId === target.sessionId && isDeepStrictEqual(parsed.binding, target.binding);
459
- };
460
- for (const entry of entries) {
461
- const current = await store.lookup(entry.key);
462
- if (current === void 0) continue;
463
- const result = await normalizeStoredRow(entry.key, current);
464
- if (result.warning || !result.value) return retain(result.warning ?? `canonical plugin state is invalid at ${entry.key}`);
465
- if (!hasExpected(result.value, entry.value)) return retain(`canonical plugin state changed at ${entry.key}`);
466
- }
467
- for (const entry of entries) {
468
- if (await store.registerIfAbsent(entry.key, entry.value)) importedKeys++;
469
- if (!hasExpected(await store.lookup(entry.key), entry.value)) return retain(`canonical plugin state changed at ${entry.key}`);
470
- }
471
- if (owner) {
472
- const ownershipWarning = await recordSessionOwner(owner, params.env);
473
- if (ownershipWarning) {
474
- if (sessionEntry?.value.state === "active") {
475
- const update = store.update;
476
- if (!update) return retain(`${ownershipWarning}; its stale session binding could not be retired`);
477
- await update(sessionEntry.key, (current) => {
478
- const parsed = readStoredCodexAppServerBinding(current);
479
- if (parsed?.lease && parsed.lease.expiresAt > Date.now()) return;
480
- if (!hasExpected(current, sessionEntry.value)) return;
481
- return {
482
- version: 1,
483
- state: "cleared",
484
- sessionId: owner.sessionId,
485
- retired: true
486
- };
487
- });
488
- if (hasExpected(await store.lookup(sessionEntry.key), sessionEntry.value)) return retain(`${ownershipWarning}; its stale session binding could not be retired`);
489
- }
490
- return retainNotice(ownershipWarning);
491
- }
492
- for (const entry of entries) if (!hasExpected(await store.lookup(entry.key), entry.value)) return retain(`canonical plugin state changed at ${entry.key}`);
493
- }
494
- const archiveWarnings = [];
495
- await archiveLegacyStateSource({
496
- filePath: source.sidecarPath,
497
- label: "Codex app-server binding",
498
- changes: [],
499
- warnings: archiveWarnings
500
- });
501
- if (archiveWarnings.length > 0 && await pathExists(source.sidecarPath)) return retain(archiveWarnings.join("; "));
502
- return {
503
- archived: true,
504
- importedKeys
505
- };
506
- });
507
- } catch (error) {
508
- if (error.code === "ENOENT" && !await pathExists(source.sidecarPath)) return {
509
- archived: true,
510
- importedKeys
511
- };
512
- return retain(`migration or archiving failed: ${String(error)}`);
513
- }
514
- }
515
- async function recordSessionOwner(owner, env) {
516
- const { patchSessionEntry } = await import("openclaw/plugin-sdk/session-store-runtime");
517
- const currentIndex = await readLegacySessionIndex(owner.storePath);
518
- if ("failure" in currentIndex) return "its legacy session owner could not be revalidated";
519
- const currentOwner = currentIndex.entries.find(({ sessionKey }) => sessionKey === owner.sessionKey);
520
- if (!currentOwner || currentOwner.entry.sessionId !== owner.sessionId) return "its session owner changed before Codex ownership could be recorded";
521
- let currentTranscriptPath;
522
- try {
523
- currentTranscriptPath = await resolveLegacySessionFileLocator(path.dirname(owner.storePath), currentOwner.entry, currentOwner.entry.sessionId);
524
- } catch {
525
- return "its session owner changed before Codex ownership could be recorded";
526
- }
527
- if (await canonicalPathFromExistingAncestor(currentTranscriptPath) !== await canonicalPathFromExistingAncestor(owner.transcriptPath) || currentOwner.entry.lifecycleRevision !== owner.lifecycleRevision) return "its session owner changed before Codex ownership could be recorded";
528
- const legacyHarnessId = currentOwner.entry.agentHarnessId?.trim();
529
- if (currentOwner.entry.agentHarnessId !== void 0 && !legacyHarnessId) return "its session owner changed before Codex ownership could be recorded";
530
- if (legacyHarnessId && legacyHarnessId !== CODEX_AGENT_HARNESS_ID) return `its session is owned by agent harness ${legacyHarnessId}`;
531
- let observedForeignHarness;
532
- const updated = await patchSessionEntry({
533
- agentId: owner.agentId,
534
- env,
535
- fallbackEntry: {
536
- sessionId: owner.sessionId,
537
- updatedAt: currentOwner.entry.updatedAt ?? owner.updatedAt ?? 0,
538
- ...owner.lifecycleRevision ? { lifecycleRevision: owner.lifecycleRevision } : {}
539
- },
540
- preserveActivity: true,
541
- requireWriteSuccess: true,
542
- skipMaintenance: true,
543
- storePath: owner.storePath,
544
- sessionKey: owner.sessionKey,
545
- update: (entry) => {
546
- if (entry.sessionId.trim() !== owner.sessionId || entry.lifecycleRevision !== owner.lifecycleRevision) return null;
547
- const harnessId = typeof entry.agentHarnessId === "string" ? entry.agentHarnessId.trim() : void 0;
548
- if (entry.agentHarnessId !== void 0 && !harnessId) return null;
549
- if (harnessId && harnessId !== CODEX_AGENT_HARNESS_ID) {
550
- observedForeignHarness = harnessId;
551
- return null;
552
- }
553
- return { agentHarnessId: CODEX_AGENT_HARNESS_ID };
554
- }
555
- });
556
- if (!updated) return observedForeignHarness ? `its session is owned by agent harness ${observedForeignHarness}` : "its session owner changed before Codex ownership could be recorded";
557
- if (updated.sessionId.trim() !== owner.sessionId || updated.lifecycleRevision !== owner.lifecycleRevision) return "its session owner changed before Codex ownership could be recorded";
558
- const harnessId = updated.agentHarnessId?.trim();
559
- return harnessId === CODEX_AGENT_HARNESS_ID ? void 0 : harnessId ? `its session is owned by agent harness ${harnessId}` : "Codex harness ownership could not be recorded on its session";
560
- }
561
- async function readDirectoryEntries(directory) {
562
- try {
563
- return await fs.readdir(directory, { withFileTypes: true });
564
- } catch (error) {
565
- if ([
566
- "EACCES",
567
- "ENOENT",
568
- "ENOTDIR",
569
- "EPERM"
570
- ].includes(error.code ?? "")) return [];
571
- throw error;
572
- }
573
- }
574
- function isSafeLegacySessionId(value) {
575
- if (typeof value !== "string") return false;
576
- const trimmed = value.trim();
577
- return trimmed.length > 0 && trimmed.length <= 255 && /^[A-Za-z0-9][A-Za-z0-9._:@-]*$/.test(trimmed);
578
- }
579
- const stateMigrations$1 = [{
580
- id: "codex-app-server-sidecars-to-plugin-state",
581
- label: "Codex app-server thread bindings",
582
- async detectLegacyState(params) {
583
- const { sources } = await collectLegacyBindingSources(params, { firstOnly: true });
584
- return sources.length > 0 ? { preview: [`- Codex app-server bindings: legacy sidecar -> plugin state (${CODEX_APP_SERVER_BINDING_NAMESPACE})`] } : null;
585
- },
586
- async migrateLegacyState(params) {
587
- const changes = [];
588
- const warnings = [];
589
- const notices = [];
590
- const { sources, surfaces } = await collectLegacyBindingSources(params);
591
- if (sources.length === 0) return {
592
- changes,
593
- warnings
594
- };
595
- const ownerCollection = await collectBindingOwners(sources, surfaces, params);
596
- if (ownerCollection.failures.length > 0) {
597
- warnings.push(`Left ${sources.length} Codex binding sidecar(s) in place because session ownership is indeterminate: ${ownerCollection.failures.join("; ")}`);
598
- return {
599
- changes,
600
- warnings
601
- };
602
- }
603
- const store = params.context.openPluginStateKeyedStore({
604
- namespace: CODEX_APP_SERVER_BINDING_NAMESPACE,
605
- maxEntries: CODEX_APP_SERVER_BINDING_MAX_ENTRIES,
606
- overflowPolicy: "reject-new"
607
- });
608
- let migrated = 0;
609
- let partialImports = 0;
610
- for (const source of sources) {
611
- const result = await migrateSource(source, ownerCollection.owners.get(await canonicalPathFromExistingAncestor(source.transcriptPath)) ?? [], params, store);
612
- if (result.warning) warnings.push(result.warning);
613
- if (result.notice) notices.push(result.notice);
614
- if (result.archived) migrated++;
615
- else partialImports += result.importedKeys;
616
- }
617
- if (migrated > 0) changes.push(`Migrated ${migrated} Codex app-server binding sidecar(s) to plugin state and archived the legacy sources`);
618
- if (partialImports > 0) changes.push(`Migrated ${partialImports} safe Codex app-server binding row(s) to plugin state; retained legacy sidecars needing review`);
619
- return {
620
- changes,
621
- warnings,
622
- ...notices.length > 0 ? { notices } : {}
623
- };
624
- }
625
- }];
626
- //#endregion
627
102
  //#region extensions/codex/doctor-contract-api.ts
628
103
  function hasRetiredDynamicToolsProfile(value) {
629
104
  return Object.hasOwn(asNullableRecord(value) ?? {}, "codexDynamicToolsProfile");
@@ -750,6 +225,11 @@ function normalizeCompatibilityConfig({ cfg }) {
750
225
  changes
751
226
  };
752
227
  }
753
- const stateMigrations = [...stateMigrations$1, codexOrphanedSessionBindingMigration];
228
+ const stateMigrations = [{
229
+ id: "codex-app-server-sidecars-to-plugin-state",
230
+ label: "Codex app-server thread bindings",
231
+ detectLegacyState: async (params) => (await import("./.setup/session-binding-sidecars-CKYEcfNn.mjs")).detectLegacySessionBindingSidecars(params),
232
+ migrateLegacyState: async (params) => (await import("./.setup/session-binding-sidecars-CKYEcfNn.mjs")).migrateLegacySessionBindingSidecars(params)
233
+ }, codexOrphanedSessionBindingMigration];
754
234
  //#endregion
755
235
  export { legacyConfigRules, normalizeCompatibilityConfig, stateMigrations };
package/dist/harness.js CHANGED
@@ -1,2 +1,2 @@
1
- import { n as createCodexAppServerNativeCompaction, t as createCodexAppServerAgentHarness } from "./harness-C7rRa7bm.js";
1
+ import { n as createCodexAppServerNativeCompaction, t as createCodexAppServerAgentHarness } from "./.setup/harness-rxaaoN-o.mjs";
2
2
  export { createCodexAppServerAgentHarness, createCodexAppServerNativeCompaction };