@openclaw/codex 2026.9.1 → 2026.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/README.md +2 -0
  2. package/dist/api.js +18 -23
  3. package/dist/apply-B6el6hdO.js +357 -0
  4. package/dist/{attempt-client-cleanup-DYHcRQAa.js → attempt-client-cleanup-D6cR54TV.js} +113 -49
  5. package/dist/{attempt-context-DmQUNWwT.js → attempt-context-AO4DSjE0.js} +11 -9
  6. package/dist/{event-projector-usage-C5mcrGjp.js → attempt-notifications--H8zXR5-.js} +3 -89
  7. package/dist/auth-cache-key-Kq6oerr6.js +498 -0
  8. package/dist/auth-profile-CwzO4_RG.js +43 -0
  9. package/dist/auth-profile-selection-DFu9e167.js +45 -0
  10. package/dist/{binding-connection-E6uDsPlx.js → binding-connection-QqgcPCgk.js} +18 -3
  11. package/dist/{bounded-turn-wzJrwKKe.js → bounded-turn-lRpmZHFv.js} +54 -150
  12. package/dist/build-state-6RL6qohz.js +19 -0
  13. package/dist/{capabilities-dIjNVCYH.js → capabilities-BeqLPbtM.js} +2 -1
  14. package/dist/cli-metadata.js +1 -1
  15. package/dist/client-BEKu4yDx.js +3983 -0
  16. package/dist/command-dispatch-CisT9Jqq.js +21 -0
  17. package/dist/{command-formatters-CLHhEB1Q.js → command-formatters-DeTfrapr.js} +2 -2
  18. package/dist/{command-handlers-CTGb2csu.js → command-handlers-BfIsJEuA.js} +158 -76
  19. package/dist/command-rpc-BMqRQOFX.js +226 -0
  20. package/dist/{compact-_t0HQrUS.js → compact-CGJZ2rlb.js} +89 -49
  21. package/dist/config-JDfTI4VI.js +106 -0
  22. package/dist/{config-BhmfC1s6.js → config-options-jnIFvwxD.js} +208 -654
  23. package/dist/config-runtime-BWf6JLWG.js +11 -0
  24. package/dist/config-utils-C57JiJrU.js +69 -0
  25. package/dist/conversation-binding-CxOlHiix.js +889 -0
  26. package/dist/{plugin-marketplace-discovery-CfFlKqDl.js → conversation-control-CUCrSIQI.js} +36 -155
  27. package/dist/doctor-contract-api.js +8 -9
  28. package/dist/{dynamic-tools-BU9tmlYm.js → dynamic-tools-D-JBoaLt.js} +734 -698
  29. package/dist/{effective-mcp-catalog-DzYBW4h1.js → effective-mcp-catalog-J_5Ep5Um.js} +4 -3
  30. package/dist/{elicitation-input-DMkeki8d.js → elicitation-input-DPoK8F7w.js} +8 -22
  31. package/dist/ephemeral-turn-DSwzP8YY.js +101 -0
  32. package/dist/{event-projector-assistant-message-DHRFXKbS.js → event-projector-assistant-message-BmBM4qBV.js} +23 -27
  33. package/dist/event-projector-usage-CIyrYYid.js +102 -0
  34. package/dist/{harness-DXVZ5II5.js → harness-FR6eQgyO.js} +47 -17
  35. package/dist/harness.js +1 -1
  36. package/dist/history-rejection-B4nOXNXF.js +13 -0
  37. package/dist/{image-payload-sanitizer-CnfoUPCE.js → image-payload-sanitizer-tupAr-2o.js} +29 -15
  38. package/dist/incognito-session-uhrBF6wJ.js +15 -0
  39. package/dist/index.js +413 -2893
  40. package/dist/{isolated-completion-kg9kv4iH.js → isolated-completion-DHBefrzg.js} +12 -21
  41. package/dist/{managed-binary-4-Vjz5GH.js → managed-binary-DrjjRRUD.js} +17 -84
  42. package/dist/managed-thread-store-D1t5jh3G.js +66 -0
  43. package/dist/media-understanding-provider.js +4 -1
  44. package/dist/{model-catalog-CUM68Hkl.js → model-catalog-B_6M04Wo.js} +6 -5
  45. package/dist/{models-sYnEc0gd.js → models-P9k2qAof.js} +4 -4
  46. package/dist/native-execution-policy-umd0tgh4.js +128 -0
  47. package/dist/{native-subagent-monitor-CnH147jH.js → native-subagent-monitor-BbCUKRwC.js} +76 -48
  48. package/dist/node-cli-sessions-rj0ysJwM.js +527 -0
  49. package/dist/{node-exec-server.runtime-CstNHCmC.js → node-exec-server.runtime-BY_ctYnT.js} +54 -23
  50. package/dist/plan-BMJdMOEF.js +711 -0
  51. package/dist/plugin-activation-BQK-f5sV.js +133 -0
  52. package/dist/{thread-resume-C7pyVKeW.js → plugin-app-cache-key-CdSQzWyX.js} +5 -53
  53. package/dist/{plugin-approval-roundtrip-CNe-Xrjx.js → plugin-approval-roundtrip-DeW95wB5.js} +1 -1
  54. package/dist/plugin-inventory-CoRCzWW4.js +325 -0
  55. package/dist/plugin-marketplace-discovery-3akBizzF.js +134 -0
  56. package/dist/{plugin-metadata-cache-BFrPhb2c.js → plugin-metadata-cache-DgNfRAGA.js} +13 -9
  57. package/dist/protocol-CAAcVIKF.js +275 -0
  58. package/dist/{provider-capabilities-DW5p4k9w.js → provider-capabilities-W4tfK5Y5.js} +2 -2
  59. package/dist/{rate-limits-CawQJfUS.js → rate-limits-Bqnx1N4z.js} +1 -1
  60. package/dist/request-CGvGOpeR.js +198 -0
  61. package/dist/{run-attempt-D1hJO4fX.js → run-attempt-DwKds3DN.js} +1498 -1028
  62. package/dist/{runtime-artifact-C3jVimFn.js → runtime-artifact-T-NwqeSH.js} +28 -28
  63. package/dist/sandbox-guard-BcT66fWy.js +165 -0
  64. package/dist/{session-binding-BHuTCRZQ.js → session-binding-CKSepwIC.js} +118 -324
  65. package/dist/session-binding-record-CaZjYwNS.js +256 -0
  66. package/dist/session-catalog-HaDcp7Sv.js +1533 -0
  67. package/dist/session-catalog-adoption-BKLtSrwi.js +251 -0
  68. package/dist/session-catalog-archive-D0i2pGj2.js +56 -0
  69. package/dist/session-catalog-home-id-D7-aLiNt.js +190 -0
  70. package/dist/session-catalog-node-adoption-BUuDYY8R.js +182 -0
  71. package/dist/session-catalog-node-continue-CBtc4wkI.js +238 -0
  72. package/dist/session-catalog-parsing-CdD3JhdM.js +280 -0
  73. package/dist/session-catalog-provenance-DkJHo735.js +124 -0
  74. package/dist/{session-cli-CmFEXMAM.js → session-cli-CbgaHh0f.js} +3 -2
  75. package/dist/session-history-Cz-tOOYj.js +96 -0
  76. package/dist/{session-upstream-marker-C351-5Qw.js → session-history-import-DFN7sWRU.js} +5 -49
  77. package/dist/session-history-read-cxPUxyVV.js +50 -0
  78. package/dist/session-history-worker-runtime.js +60 -0
  79. package/dist/{settled-turn-context-D3SNWtUn.js → session-history.worker-CNEvGaU5.js} +75 -69
  80. package/dist/session-history.worker.js +2 -0
  81. package/dist/{session-initialization-BeWzjGiR.js → session-initialization-Jo86C60I.js} +2 -1
  82. package/dist/{session-permission-policy-DeWVTCMj.js → session-permission-policy-B22InTp_.js} +4 -7
  83. package/dist/{session-retirement-BujDjXVF.js → session-retirement-BSNG_mhf.js} +8 -7
  84. package/dist/session-upstream-marker-D15C9NHp.js +46 -0
  85. package/dist/settled-turn-context-Du6gdUDd.js +45 -0
  86. package/dist/{settled-turn-finalizer-BVJx4yoc.js → settled-turn-finalizer-BuLUrZl2.js} +54 -42
  87. package/dist/shared-client-CVhez2Uo.js +2911 -0
  88. package/dist/{side-question-BTZAII4l.js → side-question-DLbr2vUU.js} +135 -191
  89. package/dist/source-Da-h6f7e.js +518 -0
  90. package/dist/thread-archive-guard-D1bP04Tf.js +53 -0
  91. package/dist/{thread-lifecycle-DAcEJ_Om.js → thread-lifecycle-D1pzRwHB.js} +467 -977
  92. package/dist/{thread-ownership-zGokd8i1.js → thread-ownership-D6oASVRu.js} +15 -17
  93. package/dist/{thread-policy-g4KbJPzp.js → thread-policy-D8kI7yAO.js} +2 -2
  94. package/dist/thread-resume-T5cveyxA.js +52 -0
  95. package/dist/timeout-BVw8aaM1.js +33 -0
  96. package/dist/transcript-mirror-attestation-DibE0krH.js +89 -0
  97. package/dist/{transcript-mirror-DTUxFWa_.js → transcript-mirror-t5TOccct.js} +111 -379
  98. package/dist/{transport-stdio-CyPldczm.js → transport-stdio-BGjHoYLr.js} +80 -48
  99. package/dist/{upstream-session-fork-CYlBIGVt.js → upstream-session-fork-De-sLJ2r.js} +94 -166
  100. package/dist/{usage-Bj-rrzkR.js → usage-CPPTmBvZ.js} +4 -3
  101. package/dist/version-omm6IPI3.js +12 -0
  102. package/dist/{web-search-provider.runtime-D2FWSK4w.js → web-search-provider.runtime-CSVgQL0w.js} +3 -3
  103. package/openclaw.plugin.json +22 -1
  104. package/package.json +6 -6
  105. package/dist/request-DYAI5FQE.js +0 -475
  106. package/dist/session-catalog-yyvTWFOw.js +0 -3120
  107. package/dist/session-history-C5J1AKzG.js +0 -87
  108. package/dist/shared-client-DxcfF9KX.js +0 -7494
  109. package/dist/{auth-binding-Ds_QVm-X.js → auth-binding-Co2Vfcf_.js} +1 -1
@@ -1,15 +1,14 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
- import { P as CODEX_PLUGIN_MARKETPLACE_NAME_PATTERN, j as normalizeCodexServiceTier } from "./config-BhmfC1s6.js";
2
+ import { g as CODEX_PLUGIN_MARKETPLACE_NAME_PATTERN } from "./config-utils-C57JiJrU.js";
3
+ import { a as readCodexAppServerThreadBinding, c as readStoredCodexAppServerBinding, d as validateBindingForWrite, i as ownsStoredSessionGeneration, l as sessionBindingIdentity, n as assertCodexBindingMayBeReplaced, o as readCodexBindingTimestamp, r as bindingStoreKey, s as readCurrentCodexAppServerBinding, t as CodexSupervisionBindingReplacementError, u as stripUndefinedBinding } from "./session-binding-record-CaZjYwNS.js";
3
4
  import { n as CODEX_APP_SERVER_BINDING_NAMESPACE, t as CODEX_APP_SERVER_BINDING_MAX_ENTRIES } from "./session-binding-meta-B7aEMU7g.js";
5
+ import { n as normalizeCodexAppServerBindingModelProvider } from "./auth-profile-CwzO4_RG.js";
4
6
  import { asOptionalRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
5
- import { AgentHarnessSessionSupersededError, embeddedAgentLog } from "openclaw/plugin-sdk/agent-harness-runtime";
6
7
  import { createHash, randomUUID } from "node:crypto";
7
8
  import { isDeepStrictEqual } from "node:util";
8
- import { ensureAuthProfileStore, resolveDefaultAgentDir, resolveProviderIdForAuth } from "openclaw/plugin-sdk/agent-runtime";
9
- import { resolveSessionAgentIdsStrict } from "openclaw/plugin-sdk/agent-scope-runtime";
10
- import { z } from "zod";
11
- import { AsyncLocalStorage } from "node:async_hooks";
9
+ import { AgentHarnessSessionSupersededError, embeddedAgentLog } from "openclaw/plugin-sdk/agent-harness-runtime";
12
10
  import { getSessionEntry, resolveStorePath } from "openclaw/plugin-sdk/session-store-runtime";
11
+ import { AsyncLocalStorage } from "node:async_hooks";
13
12
  //#region extensions/codex/src/app-server/session-binding.ts
14
13
  /** SQLite-backed Codex app-server thread bindings. */
15
14
  var session_binding_exports = /* @__PURE__ */ __exportAll({
@@ -23,19 +22,16 @@ var session_binding_exports = /* @__PURE__ */ __exportAll({
23
22
  createCodexSessionGenerationSupersededError: () => createCodexSessionGenerationSupersededError,
24
23
  createStoredCodexAppServerBinding: () => createStoredCodexAppServerBinding,
25
24
  hashCodexAppServerBindingFingerprint: () => hashCodexAppServerBindingFingerprint,
26
- isCodexAppServerNativeAuthProfile: () => isCodexAppServerNativeAuthProfile,
27
- normalizeCodexAppServerBindingModelProvider: () => normalizeCodexAppServerBindingModelProvider,
28
25
  normalizeStoredCodexAppServerBindingFingerprints: () => normalizeStoredCodexAppServerBindingFingerprints,
29
26
  readCodexAppServerThreadBinding: () => readCodexAppServerThreadBinding,
30
27
  readStoredCodexAppServerBinding: () => readStoredCodexAppServerBinding,
31
28
  reclaimCurrentCodexSessionGeneration: () => reclaimCurrentCodexSessionGeneration,
32
29
  resolveCodexRunSessionBindingAuthority: () => resolveCodexRunSessionBindingAuthority,
30
+ resolveCodexSessionBinding: () => resolveCodexSessionBinding,
33
31
  scopeCodexRunBindingStore: () => scopeCodexRunBindingStore,
34
32
  sessionBindingIdentity: () => sessionBindingIdentity,
35
33
  validateBindingForWrite: () => validateBindingForWrite
36
34
  });
37
- const CODEX_APP_SERVER_NATIVE_AUTH_PROVIDER = "openai";
38
- const PUBLIC_OPENAI_MODEL_PROVIDER = "openai";
39
35
  const BINDING_LEASE_RETRY_INTERVAL_MS = 1e3;
40
36
  const BOUNDED_BINDING_FINGERPRINT_PATTERN = /^sha256:[a-f0-9]{64}$/i;
41
37
  const CODEX_APP_SERVER_BINDING_GUARDED_REQUEST_TIMEOUT_MS = 6e4;
@@ -43,221 +39,66 @@ const BINDING_LEASE_STALE_MS = 65e3;
43
39
  const BINDING_LEASE_WAIT_MS = 7e4;
44
40
  const BINDING_LEASE_RENEW_INTERVAL_MS = Math.floor(BINDING_LEASE_STALE_MS / 3);
45
41
  const PHYSICAL_SESSION_RETIRE_TTL_MS = BINDING_LEASE_WAIT_MS;
46
- /** Resolves the same agent scope OpenClaw uses for transcript/session ownership. */
47
- function sessionBindingIdentity(params) {
48
- const { sessionAgentId } = resolveSessionAgentIdsStrict(params);
49
- const sessionKey = params.sessionKey?.trim();
50
- return {
51
- kind: "session",
52
- agentId: sessionAgentId,
53
- sessionId: params.sessionId,
54
- ...sessionKey ? { sessionKey } : {}
55
- };
56
- }
57
42
  /** Decides whether a run may share the durable stable-key binding owner. */
58
43
  function resolveCodexRunSessionBindingAuthority(params) {
59
- const sessionKey = params.identity.sessionKey?.trim();
60
- if (!sessionKey) return "ephemeral";
61
- try {
62
- const storePath = params.storePath?.trim() || resolveStorePath(params.config?.session?.store, { agentId: params.identity.agentId });
63
- const entry = getSessionEntry({
64
- agentId: params.identity.agentId,
65
- hydrateSkillPromptRefs: false,
66
- readConsistency: "latest",
67
- sessionKey,
68
- storePath
69
- });
70
- if (!entry) return "ephemeral";
71
- return entry.sessionId === params.identity.sessionId ? "current" : "superseded";
72
- } catch {
73
- return "superseded";
74
- }
44
+ return captureCodexSessionGenerationAuthority(params)[0];
45
+ }
46
+ /** Host lineage is recorded in the same transaction as its successor generation. */
47
+ function readCodexBindingSessionEntry(params) {
48
+ const { identity } = params;
49
+ return identity.sessionKey?.trim() ? getSessionEntry({
50
+ agentId: identity.agentId,
51
+ sessionKey: identity.sessionKey.trim(),
52
+ storePath: params.storePath?.trim() || resolveStorePath(params.config?.session?.store, { agentId: identity.agentId }),
53
+ hydrateSkillPromptRefs: false,
54
+ readConsistency: "latest"
55
+ }) : void 0;
56
+ }
57
+ /** Synchronous model selection recognizes the predecessor; admission rewrites its fence. */
58
+ function readCodexSessionOwnershipBinding(params) {
59
+ const binding = params.bindingStore.read(params.identity);
60
+ if (binding || params.identity.kind !== "session") return binding;
61
+ const entry = readCodexBindingSessionEntry({
62
+ ...params,
63
+ identity: params.identity
64
+ });
65
+ return entry?.sessionId === params.identity.sessionId && entry.previousSessionId ? params.bindingStore.read({
66
+ ...params.identity,
67
+ sessionId: entry.previousSessionId
68
+ }) : void 0;
69
+ }
70
+ function captureCodexSessionGenerationAuthority(params, assertCallerCurrent = () => {}) {
71
+ const readEntry = () => {
72
+ try {
73
+ return readCodexBindingSessionEntry(params);
74
+ } catch {
75
+ return null;
76
+ }
77
+ };
78
+ const entry = readEntry();
79
+ const current = entry?.sessionId === params.identity.sessionId;
80
+ const authority = entry === void 0 ? "ephemeral" : current ? "current" : "superseded";
81
+ const previousSessionId = current ? entry.previousSessionId : void 0;
82
+ const assertHostCurrent = () => {
83
+ if (authority === "ephemeral") return;
84
+ const latest = readEntry();
85
+ if (authority !== "current" || !latest || latest.sessionId !== params.identity.sessionId || latest.previousSessionId !== previousSessionId) throw createCodexSessionGenerationSupersededError(params.identity.sessionId);
86
+ };
87
+ const assertCurrent = () => {
88
+ assertCallerCurrent();
89
+ assertHostCurrent();
90
+ };
91
+ return [
92
+ authority,
93
+ previousSessionId,
94
+ assertHostCurrent,
95
+ assertCurrent
96
+ ];
75
97
  }
76
98
  /** Builds the terminal coordination error used when a newer OpenClaw session owns the binding. */
77
99
  function createCodexSessionGenerationSupersededError(sessionId) {
78
100
  return new AgentHarnessSessionSupersededError(`Codex session generation is no longer current: ${sessionId}`);
79
101
  }
80
- const optionalStringSchema = z.string().optional().catch(void 0);
81
- const optionalBooleanSchema = z.boolean().optional().catch(void 0);
82
- const optionalNonBlankStringSchema = z.string().refine((value) => Boolean(value.trim())).optional().catch(void 0);
83
- const optionalTimestampSchema = z.string().refine((value) => Number.isFinite(Date.parse(value))).optional().catch(void 0);
84
- const pendingSupervisionBranchSchema = z.object({
85
- sourceThreadId: z.string().trim().min(1),
86
- connectionFingerprint: z.string().trim().min(1).optional(),
87
- lastTurnId: z.string().trim().min(1).optional(),
88
- cleanupThreadIds: z.array(z.string().trim().min(1)).max(2).optional()
89
- }).strict().superRefine((pending, context) => {
90
- const cleanupThreadIds = pending.cleanupThreadIds ?? [];
91
- if (new Set(cleanupThreadIds).size !== cleanupThreadIds.length) context.addIssue({
92
- code: "custom",
93
- message: "pending supervision cleanup thread ids must be unique"
94
- });
95
- if (cleanupThreadIds.includes(pending.sourceThreadId)) context.addIssue({
96
- code: "custom",
97
- message: "pending supervision cleanup cannot target its source"
98
- });
99
- });
100
- const contextEngineProjectionSchema = z.object({
101
- schemaVersion: z.literal(1),
102
- mode: z.literal("thread_bootstrap"),
103
- epoch: z.string().refine((value) => Boolean(value.trim())),
104
- fingerprint: optionalStringSchema
105
- }).strict();
106
- const contextEngineSchema = z.object({
107
- schemaVersion: z.literal(1),
108
- engineId: z.string(),
109
- policyFingerprint: z.string(),
110
- projection: contextEngineProjectionSchema.optional().catch(void 0)
111
- }).strict();
112
- const destructiveApprovalModeSchema = z.enum([
113
- "allow",
114
- "deny",
115
- "auto",
116
- "ask"
117
- ]).optional().catch(void 0);
118
- const accountAppPolicyEntrySchema = z.object({
119
- source: z.literal("account"),
120
- appName: z.string(),
121
- allowDestructiveActions: z.boolean(),
122
- allowOpenWorld: z.boolean().optional(),
123
- destructiveApprovalMode: destructiveApprovalModeSchema,
124
- mcpServerNames: z.array(z.string())
125
- }).strict();
126
- const pluginAppPolicyEntrySchema = z.object({
127
- source: z.literal("plugin").optional(),
128
- configKey: z.string(),
129
- marketplaceName: z.string().regex(CODEX_PLUGIN_MARKETPLACE_NAME_PATTERN),
130
- pluginName: z.string(),
131
- allowDestructiveActions: z.boolean(),
132
- allowOpenWorld: z.boolean().optional(),
133
- destructiveApprovalMode: destructiveApprovalModeSchema,
134
- mcpServerNames: z.array(z.string())
135
- }).strict();
136
- const pluginAppPolicyContextSchema = z.object({
137
- fingerprint: z.string(),
138
- apps: z.record(z.string(), z.union([accountAppPolicyEntrySchema, pluginAppPolicyEntrySchema])),
139
- pluginAppIds: z.record(z.string(), z.array(z.string())).default({})
140
- }).strict();
141
- const threadBindingSchema = z.object({
142
- threadId: z.string().refine((value) => Boolean(value.trim())),
143
- clientId: optionalStringSchema,
144
- cwd: z.string(),
145
- rolloutPath: optionalNonBlankStringSchema,
146
- connectionScope: z.literal("supervision").optional(),
147
- supervisionSourceThreadId: z.string().trim().min(1).optional(),
148
- authProfileId: optionalStringSchema,
149
- agentWorkspaceDeveloperInstructions: optionalNonBlankStringSchema,
150
- model: optionalStringSchema,
151
- preserveNativeModel: z.literal(true).optional().catch(void 0),
152
- pendingSupervisionBranch: pendingSupervisionBranchSchema.optional(),
153
- pendingResumeConfiguration: z.literal(true).optional(),
154
- modelProvider: z.string().transform((value) => value.trim()).pipe(z.string().min(1)).optional().catch(void 0),
155
- approvalPolicy: z.preprocess((value) => value === "on-failure" ? "on-request" : value, z.enum([
156
- "never",
157
- "on-request",
158
- "untrusted"
159
- ]).optional()).catch(void 0),
160
- sandbox: z.enum([
161
- "read-only",
162
- "workspace-write",
163
- "danger-full-access"
164
- ]).optional().catch(void 0),
165
- serviceTier: z.preprocess(normalizeCodexServiceTier, z.custom((value) => typeof value === "string").optional()).optional().catch(void 0),
166
- networkProxyProfileName: optionalStringSchema,
167
- networkProxyConfigFingerprint: optionalStringSchema,
168
- dynamicToolsFingerprint: optionalStringSchema,
169
- dynamicToolsContainDeferred: optionalBooleanSchema,
170
- webSearchThreadConfigFingerprint: optionalStringSchema,
171
- nativeSkillIsolationFingerprint: optionalStringSchema,
172
- userMcpServersFingerprint: optionalStringSchema,
173
- mcpServersFingerprint: optionalStringSchema,
174
- configuredMcpOwnershipVersion: z.literal(1).optional().catch(void 0),
175
- ringZeroConfigFingerprint: optionalStringSchema,
176
- ringZeroClientInstanceId: optionalStringSchema,
177
- /** Durable fact preventing a later unrestricted turn from widening this thread. */
178
- nativeToolPolicyRestricted: z.literal(true).optional().catch(void 0),
179
- nativeHookRelayGeneration: optionalNonBlankStringSchema,
180
- appServerRuntimeFingerprint: optionalStringSchema,
181
- pluginAppsFingerprint: optionalStringSchema,
182
- pluginAppsInputFingerprint: optionalStringSchema,
183
- pluginAppPolicyContext: pluginAppPolicyContextSchema.optional().catch(void 0),
184
- contextEngine: contextEngineSchema.optional().catch(void 0),
185
- environmentSelectionFingerprint: optionalStringSchema,
186
- conversationStartId: optionalStringSchema,
187
- conversationSourceTransferComplete: z.literal(true).optional().catch(void 0),
188
- historyCoveredThrough: optionalTimestampSchema,
189
- continuityCalibration: z.object({
190
- promptChars: z.number().int().positive(),
191
- inputTokens: z.number().int().positive()
192
- }).optional().catch(void 0)
193
- }).superRefine((binding, context) => {
194
- if (binding.connectionScope === "supervision") {
195
- if (!binding.supervisionSourceThreadId) context.addIssue({
196
- code: "custom",
197
- message: "supervision connection ownership requires its native source thread id"
198
- });
199
- if (binding.preserveNativeModel !== true) context.addIssue({
200
- code: "custom",
201
- message: "supervision connection ownership requires native model ownership"
202
- });
203
- if (binding.conversationSourceTransferComplete !== true) context.addIssue({
204
- code: "custom",
205
- message: "supervision connection ownership requires a completed source transfer"
206
- });
207
- if (!binding.pendingSupervisionBranch && (!binding.model?.trim() || !binding.modelProvider)) context.addIssue({
208
- code: "custom",
209
- message: "materialized supervision bindings require a native model and provider"
210
- });
211
- }
212
- if (binding.supervisionSourceThreadId && binding.connectionScope !== "supervision") context.addIssue({
213
- code: "custom",
214
- message: "a supervision source thread id requires supervision connection ownership"
215
- });
216
- if (!binding.pendingSupervisionBranch) return;
217
- if (binding.threadId !== binding.pendingSupervisionBranch.sourceThreadId) context.addIssue({
218
- code: "custom",
219
- message: "pending supervision source must match the provisional thread binding"
220
- });
221
- if (binding.supervisionSourceThreadId !== binding.pendingSupervisionBranch.sourceThreadId) context.addIssue({
222
- code: "custom",
223
- message: "pending supervision source must match its durable source identity"
224
- });
225
- if (binding.preserveNativeModel !== true) context.addIssue({
226
- code: "custom",
227
- message: "pending supervision bindings must defer model selection to Codex App Server"
228
- });
229
- if (binding.connectionScope !== "supervision") context.addIssue({
230
- code: "custom",
231
- message: "pending supervision bindings require supervision connection ownership"
232
- });
233
- });
234
- var CodexSupervisionBindingReplacementError = class extends Error {
235
- constructor(threadId, operation) {
236
- super(`Refusing to replace supervised Codex thread ${threadId} while ${operation}; its native user-home connection and model ownership must be preserved`);
237
- this.name = "CodexSupervisionBindingReplacementError";
238
- }
239
- };
240
- function assertCodexBindingMayBeReplaced(binding, operation) {
241
- if (binding?.connectionScope === "supervision") throw new CodexSupervisionBindingReplacementError(binding.threadId, operation);
242
- }
243
- const bindingLeaseSchema = z.object({
244
- token: z.string().refine((value) => Boolean(value.trim())),
245
- expiresAt: z.number().finite()
246
- });
247
- const storedSessionIdSchema = z.string().transform((value) => value.trim()).pipe(z.string().min(1)).optional().catch(void 0);
248
- const storedBindingSchema = z.discriminatedUnion("state", [z.object({
249
- version: z.literal(1),
250
- state: z.literal("active"),
251
- binding: threadBindingSchema,
252
- sessionId: storedSessionIdSchema,
253
- lease: bindingLeaseSchema.optional().catch(void 0)
254
- }), z.object({
255
- version: z.literal(1),
256
- state: z.literal("cleared"),
257
- sessionId: storedSessionIdSchema,
258
- lease: bindingLeaseSchema.optional().catch(void 0),
259
- retired: z.literal(true).optional().catch(void 0)
260
- })]);
261
102
  function hashCodexAppServerBindingFingerprint(canonical) {
262
103
  return `sha256:${createHash("sha256").update(canonical).digest("hex")}`;
263
104
  }
@@ -292,7 +133,7 @@ function createStoredCodexAppServerBinding(value, options = {}) {
292
133
  const record = normalizeLegacyBindingFingerprints(rawRecord);
293
134
  if (record.schemaVersion !== 1 && record.schemaVersion !== 2) return;
294
135
  const pluginAppPolicyContext = readPluginAppPolicyContext(record.pluginAppPolicyContext, record.schemaVersion);
295
- const historyCoveredThrough = readTimestamp(record.historyCoveredThrough) ?? readTimestamp(record.updatedAt) ?? readTimestamp(record.createdAt) ?? readTimestamp(options.now) ?? (/* @__PURE__ */ new Date()).toISOString();
136
+ const historyCoveredThrough = readCodexBindingTimestamp(record.historyCoveredThrough) ?? readCodexBindingTimestamp(record.updatedAt) ?? readCodexBindingTimestamp(record.createdAt) ?? readCodexBindingTimestamp(options.now) ?? (/* @__PURE__ */ new Date()).toISOString();
296
137
  const authProfileId = typeof record.authProfileId === "string" ? record.authProfileId : void 0;
297
138
  const binding = readCodexAppServerThreadBinding({
298
139
  ...record,
@@ -324,7 +165,7 @@ function scopeCodexRunBindingStore(params) {
324
165
  hasOtherThreadOwner: (threadId, identity) => params.bindingStore.hasOtherThreadOwner(threadId, identity ? mapIdentity(identity) : void 0),
325
166
  mutate: (identity, mutation, assertCurrent) => params.bindingStore.mutate(mapIdentity(identity), mutation, assertCurrent),
326
167
  prepareSessionGenerationReclaim: (identity) => params.bindingStore.prepareSessionGenerationReclaim(mapSessionIdentity(identity)),
327
- adoptSessionGeneration: (identity, expectedPreviousSessionId) => params.bindingStore.adoptSessionGeneration(mapSessionIdentity(identity), expectedPreviousSessionId),
168
+ adoptSessionGeneration: (identity, expectedPreviousSessionId, assertCurrent) => params.bindingStore.adoptSessionGeneration(mapSessionIdentity(identity), expectedPreviousSessionId, assertCurrent),
328
169
  resetSessionGeneration: (identity) => params.bindingStore.resetSessionGeneration(mapSessionIdentity(identity)),
329
170
  retireSessionGeneration: (identity) => params.bindingStore.retireSessionGeneration(mapSessionIdentity(identity)),
330
171
  withSessionDeletion: (identity, assertCurrent, run) => params.bindingStore.withSessionDeletion(mapSessionIdentity(identity), assertCurrent, run),
@@ -332,30 +173,62 @@ function scopeCodexRunBindingStore(params) {
332
173
  withLease: (identity, run) => params.bindingStore.withLease(mapIdentity(identity), run)
333
174
  };
334
175
  }
335
- /** Lets the authoritative OpenClaw session generation claim a stale stable binding row. */
336
- async function reclaimCurrentCodexSessionGeneration(params) {
337
- params.assertCurrent?.();
338
- const sessionKey = params.identity.sessionKey?.trim();
339
- if (!sessionKey) return true;
176
+ async function reclaimPreparedCodexSessionGeneration(params, authority, assertCurrent = authority[3]) {
340
177
  const plan = await params.bindingStore.prepareSessionGenerationReclaim(params.identity);
341
- params.assertCurrent?.();
178
+ assertCurrent();
342
179
  if (plan.kind === "resolved") return plan.result;
343
- try {
344
- const storePath = params.storePath?.trim() || resolveStorePath(params.config?.session?.store, { agentId: params.identity.agentId });
345
- if (getSessionEntry({
346
- agentId: params.identity.agentId,
347
- hydrateSkillPromptRefs: false,
348
- readConsistency: "latest",
349
- sessionKey,
350
- storePath
351
- })?.sessionId !== params.identity.sessionId) return false;
352
- } catch {
353
- return false;
180
+ const [state, previousSessionId, assertHostCurrent] = authority;
181
+ if (state !== "current") return false;
182
+ params.onHostGenerationVerified?.(assertHostCurrent);
183
+ if (previousSessionId === plan.expectedPreviousSessionId) {
184
+ const adopted = await params.bindingStore.adoptSessionGeneration(params.identity, previousSessionId, assertCurrent);
185
+ if (adopted !== "absent") return adopted !== "conflict";
354
186
  }
355
- return await params.bindingStore.mutate(params.identity, {
187
+ if (params.reclaimStale === false) return false;
188
+ return params.bindingStore.mutate(params.identity, {
356
189
  kind: "reclaim-generation",
357
190
  expectedPreviousSessionId: plan.expectedPreviousSessionId
358
- }, params.assertCurrent);
191
+ }, assertCurrent);
192
+ }
193
+ /** Lets the authoritative OpenClaw session generation claim a stale stable binding row. */
194
+ async function reclaimCurrentCodexSessionGeneration(params) {
195
+ params.assertCurrent?.();
196
+ if (!params.identity.sessionKey?.trim()) return true;
197
+ const authority = captureCodexSessionGenerationAuthority(params, params.assertCurrent);
198
+ if (authority[0] === "superseded") return false;
199
+ return reclaimPreparedCodexSessionGeneration(params, authority);
200
+ }
201
+ /** Resolve continuity before selecting native queues, catalogs, or connections. */
202
+ async function resolveCodexSessionBinding(params) {
203
+ let assertCurrent = params.assertCurrent ?? (() => {});
204
+ const assertAdmissionCurrent = () => {
205
+ assertCurrent();
206
+ params.signal?.throwIfAborted();
207
+ };
208
+ assertAdmissionCurrent();
209
+ params.assertBinding?.(readCodexSessionOwnershipBinding(params));
210
+ const identity = params.identity;
211
+ const authority = identity.kind === "session" && identity.sessionKey?.trim() ? captureCodexSessionGenerationAuthority({
212
+ ...params,
213
+ identity
214
+ }, assertCurrent) : void 0;
215
+ assertCurrent = authority?.[3] ?? assertCurrent;
216
+ assertAdmissionCurrent();
217
+ let binding = params.bindingStore.read(identity);
218
+ if (!binding && authority && identity.kind === "session") {
219
+ if (!await reclaimPreparedCodexSessionGeneration({
220
+ ...params,
221
+ identity,
222
+ reclaimStale: params.reclaimStale === true
223
+ }, authority, assertAdmissionCurrent) && params.reclaimStale) throw createCodexSessionGenerationSupersededError(identity.sessionId);
224
+ binding = params.bindingStore.read(identity);
225
+ }
226
+ assertAdmissionCurrent();
227
+ params.assertBinding?.(binding);
228
+ return {
229
+ binding,
230
+ assertCurrent
231
+ };
359
232
  }
360
233
  /** Creates the single binding facade owned by the Codex plugin runtime. */
361
234
  function createCodexAppServerBindingStore(state) {
@@ -562,13 +435,7 @@ function createCodexAppServerBindingStore(state) {
562
435
  });
563
436
  };
564
437
  return {
565
- async read(identity) {
566
- const key = bindingStoreKey(identity);
567
- const raw = state.lookup(key);
568
- const stored = readStoredCodexAppServerBinding(raw);
569
- if (raw !== void 0 && !stored) throw new Error(`Invalid Codex app-server binding row: ${key}`);
570
- return stored?.state === "active" && ownsStoredSessionGeneration(identity, stored) ? stored.binding : void 0;
571
- },
438
+ read: (identity) => readCurrentCodexAppServerBinding(state, identity),
572
439
  async hasOtherThreadOwner(threadId, currentIdentity) {
573
440
  const currentKey = currentIdentity ? bindingStoreKey(currentIdentity) : void 0;
574
441
  return state.entries().some(({ key, value }) => {
@@ -685,7 +552,7 @@ function createCodexAppServerBindingStore(state) {
685
552
  }, mutation.kind === "clear" && !retainLegacyClear && !leaseContext.getStore()?.has(key) ? 1 : void 0, assertCurrent);
686
553
  });
687
554
  },
688
- async adoptSessionGeneration(identity, expectedPreviousSessionId) {
555
+ async adoptSessionGeneration(identity, expectedPreviousSessionId, assertCurrent) {
689
556
  return await runBindingMutation(async () => {
690
557
  const key = bindingStoreKey(identity);
691
558
  const expectedSessionId = expectedPreviousSessionId.trim();
@@ -702,7 +569,7 @@ function createCodexAppServerBindingStore(state) {
702
569
  sessionId: targetSessionId
703
570
  }
704
571
  };
705
- });
572
+ }, void 0, assertCurrent);
706
573
  });
707
574
  },
708
575
  resetSessionGeneration: (identity) => transitionSessionGeneration(identity, "reset"),
@@ -742,7 +609,8 @@ function createCodexAppServerBindingStore(state) {
742
609
  }
743
610
  return await withBindingLease(identity, async () => {
744
611
  const owner = leaseContext.getStore().get(key);
745
- const stored = readStoredCodexAppServerBinding(state.lookup(key));
612
+ const expected = state.lookup(key);
613
+ const stored = readStoredCodexAppServerBinding(expected);
746
614
  if (!stored || !ownsStoredSessionGeneration(identity, stored)) throw new Error("Codex binding generation changed before session deletion");
747
615
  const { lease: _lease, ...expectedValue } = stored;
748
616
  let deleted;
@@ -800,26 +668,6 @@ function matchesPendingSupervisionBranch(binding, expected) {
800
668
  function isSameSupervisionOwner(current, replacement) {
801
669
  return replacement.connectionScope === "supervision" && replacement.threadId === current.threadId && replacement.supervisionSourceThreadId === current.supervisionSourceThreadId;
802
670
  }
803
- /** Stable plugin-state key for one current binding owner. */
804
- function bindingStoreKey(identity) {
805
- if (identity.kind === "session") {
806
- const rawAgentId = identity.agentId.trim();
807
- const sessionId = identity.sessionId.trim();
808
- if (!rawAgentId) throw new Error("Codex app-server binding requires an agent id");
809
- if (!sessionId) throw new Error("Codex app-server binding requires a session id");
810
- const agentId = resolveSessionAgentIdsStrict({ agentId: rawAgentId }).sessionAgentId;
811
- const sessionKey = identity.sessionKey?.trim();
812
- if (sessionKey) return `session-key:${agentId}:${createHash("sha256").update(sessionKey).digest("base64url")}`;
813
- return `session:${agentId}:${sessionId}`;
814
- }
815
- const bindingId = identity.bindingId.trim();
816
- if (!bindingId) throw new Error("Codex app-server conversation binding requires a binding id");
817
- return `conversation:${bindingId}`;
818
- }
819
- function readStoredCodexAppServerBinding(value) {
820
- const result = storedBindingSchema.safeParse(value);
821
- return result.success ? stripUndefinedValue(result.data) : void 0;
822
- }
823
671
  function storedSessionGeneration(identity, current) {
824
672
  if (identity.kind === "session") return { sessionId: identity.sessionId };
825
673
  return current?.sessionId ? { sessionId: current.sessionId } : {};
@@ -828,31 +676,6 @@ function preservedSessionGeneration(identity, current) {
828
676
  if (current?.sessionId) return { sessionId: current.sessionId };
829
677
  return storedSessionGeneration(identity, current);
830
678
  }
831
- function ownsStoredSessionGeneration(identity, current) {
832
- return identity.kind !== "session" || !current?.sessionId || current.sessionId === identity.sessionId;
833
- }
834
- function validateBindingForWrite(binding) {
835
- const validated = readCodexAppServerThreadBinding(binding);
836
- if (!validated) throw new Error("Invalid Codex app-server thread binding");
837
- return stripUndefinedBinding(validated);
838
- }
839
- /** Parses stored or shipped sidecar data into the current domain value. */
840
- function readCodexAppServerThreadBinding(value) {
841
- const result = threadBindingSchema.safeParse(value);
842
- if (!result.success) return;
843
- return result.data;
844
- }
845
- function stripUndefinedBinding(binding) {
846
- return stripUndefinedValue(binding);
847
- }
848
- function stripUndefinedValue(value) {
849
- if (Array.isArray(value)) return value.map(stripUndefinedValue);
850
- if (!value || typeof value !== "object") return value;
851
- return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== void 0).map(([key, entry]) => [key, stripUndefinedValue(entry)]));
852
- }
853
- function readTimestamp(value) {
854
- return optionalTimestampSchema.parse(value);
855
- }
856
679
  function readPluginAppPolicyContext(value, bindingSchemaVersion) {
857
680
  const record = asOptionalRecord(value);
858
681
  if (!record || typeof record.fingerprint !== "string") return;
@@ -912,34 +735,5 @@ function sleep(ms) {
912
735
  setTimeout(resolve, ms);
913
736
  });
914
737
  }
915
- /** Returns true when an auth profile uses native Codex/OpenAI app-server auth. */
916
- function isCodexAppServerNativeAuthProfile(lookup) {
917
- const authProfileId = lookup.authProfileId?.trim();
918
- if (!authProfileId) return false;
919
- try {
920
- const credential = (lookup.authProfileStore ?? ensureAuthProfileStore(lookup.agentDir?.trim() || resolveDefaultAgentDir(lookup.config ?? {}), {
921
- allowKeychainPrompt: false,
922
- config: lookup.config,
923
- externalCliProviderIds: [CODEX_APP_SERVER_NATIVE_AUTH_PROVIDER],
924
- externalCliProfileIds: [authProfileId]
925
- })).profiles[authProfileId];
926
- if (!credential || credential.type === "api_key") return false;
927
- const provider = credential.provider?.trim();
928
- return Boolean(provider && resolveProviderIdForAuth(provider, { config: lookup.config }) === CODEX_APP_SERVER_NATIVE_AUTH_PROVIDER);
929
- } catch (error) {
930
- embeddedAgentLog.debug("failed to resolve codex app-server auth profile provider", {
931
- authProfileId,
932
- error
933
- });
934
- return false;
935
- }
936
- }
937
- /** Hides redundant OpenAI provider attribution for native Codex auth bindings. */
938
- function normalizeCodexAppServerBindingModelProvider(params) {
939
- const modelProvider = params.modelProvider?.trim();
940
- if (!modelProvider) return;
941
- if (isCodexAppServerNativeAuthProfile(params) && modelProvider.toLowerCase() === PUBLIC_OPENAI_MODEL_PROVIDER) return;
942
- return modelProvider;
943
- }
944
738
  //#endregion
945
- export { hashCodexAppServerBindingFingerprint as a, reclaimCurrentCodexSessionGeneration as c, sessionBindingIdentity as d, session_binding_exports as f, createCodexSessionGenerationSupersededError as i, resolveCodexRunSessionBindingAuthority as l, assertCodexBindingMayBeReplaced as n, isCodexAppServerNativeAuthProfile as o, validateBindingForWrite as p, bindingStoreKey as r, normalizeCodexAppServerBindingModelProvider as s, CODEX_APP_SERVER_BINDING_GUARDED_REQUEST_TIMEOUT_MS as t, scopeCodexRunBindingStore as u };
739
+ export { resolveCodexRunSessionBindingAuthority as a, session_binding_exports as c, reclaimCurrentCodexSessionGeneration as i, createCodexSessionGenerationSupersededError as n, resolveCodexSessionBinding as o, hashCodexAppServerBindingFingerprint as r, scopeCodexRunBindingStore as s, CODEX_APP_SERVER_BINDING_GUARDED_REQUEST_TIMEOUT_MS as t };