@kodelyth/codex 2026.5.42 → 2026.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/package.json +17 -2
  2. package/doctor-contract-api.test.ts +0 -44
  3. package/doctor-contract-api.ts +0 -68
  4. package/harness.ts +0 -72
  5. package/index.test.ts +0 -230
  6. package/index.ts +0 -66
  7. package/media-understanding-provider.test.ts +0 -486
  8. package/media-understanding-provider.ts +0 -521
  9. package/prompt-overlay-runtime-contract.test.ts +0 -48
  10. package/prompt-overlay.ts +0 -21
  11. package/provider-catalog.ts +0 -83
  12. package/provider-discovery.ts +0 -45
  13. package/provider.test.ts +0 -384
  14. package/provider.ts +0 -243
  15. package/src/app-server/app-inventory-cache.test.ts +0 -176
  16. package/src/app-server/app-inventory-cache.ts +0 -324
  17. package/src/app-server/approval-bridge.test.ts +0 -1471
  18. package/src/app-server/approval-bridge.ts +0 -1211
  19. package/src/app-server/auth-bridge.test.ts +0 -1449
  20. package/src/app-server/auth-bridge.ts +0 -614
  21. package/src/app-server/auth-profile-runtime-contract.test.ts +0 -239
  22. package/src/app-server/capabilities.ts +0 -27
  23. package/src/app-server/client-factory.ts +0 -24
  24. package/src/app-server/client.test.ts +0 -563
  25. package/src/app-server/client.ts +0 -715
  26. package/src/app-server/compact.test.ts +0 -710
  27. package/src/app-server/compact.ts +0 -500
  28. package/src/app-server/computer-use.test.ts +0 -788
  29. package/src/app-server/computer-use.ts +0 -683
  30. package/src/app-server/config.test.ts +0 -879
  31. package/src/app-server/config.ts +0 -1038
  32. package/src/app-server/context-engine-projection.test.ts +0 -252
  33. package/src/app-server/context-engine-projection.ts +0 -403
  34. package/src/app-server/delivery-no-reply-runtime-contract.test.ts +0 -80
  35. package/src/app-server/dynamic-tool-diagnostics.ts +0 -73
  36. package/src/app-server/dynamic-tool-profile.ts +0 -69
  37. package/src/app-server/dynamic-tools.test.ts +0 -1302
  38. package/src/app-server/dynamic-tools.ts +0 -623
  39. package/src/app-server/elicitation-bridge.test.ts +0 -1056
  40. package/src/app-server/elicitation-bridge.ts +0 -783
  41. package/src/app-server/event-projector.test.ts +0 -2668
  42. package/src/app-server/event-projector.ts +0 -2057
  43. package/src/app-server/image-payload-sanitizer.test.ts +0 -49
  44. package/src/app-server/image-payload-sanitizer.ts +0 -167
  45. package/src/app-server/klaw-owned-tool-runtime-contract.test.ts +0 -456
  46. package/src/app-server/local-runtime-attribution.ts +0 -39
  47. package/src/app-server/managed-binary.test.ts +0 -139
  48. package/src/app-server/managed-binary.ts +0 -193
  49. package/src/app-server/models.test.ts +0 -246
  50. package/src/app-server/models.ts +0 -172
  51. package/src/app-server/native-hook-relay.test.ts +0 -271
  52. package/src/app-server/native-hook-relay.ts +0 -150
  53. package/src/app-server/native-subagent-task-mirror.test.ts +0 -573
  54. package/src/app-server/native-subagent-task-mirror.ts +0 -497
  55. package/src/app-server/outcome-fallback-runtime-contract.test.ts +0 -404
  56. package/src/app-server/plugin-activation.test.ts +0 -336
  57. package/src/app-server/plugin-activation.ts +0 -283
  58. package/src/app-server/plugin-app-cache-key.ts +0 -74
  59. package/src/app-server/plugin-approval-roundtrip.ts +0 -122
  60. package/src/app-server/plugin-inventory.test.ts +0 -355
  61. package/src/app-server/plugin-inventory.ts +0 -357
  62. package/src/app-server/plugin-thread-config.test.ts +0 -865
  63. package/src/app-server/plugin-thread-config.ts +0 -455
  64. package/src/app-server/protocol-generated/json/DynamicToolCallParams.json +0 -33
  65. package/src/app-server/protocol-generated/json/v2/ErrorNotification.json +0 -199
  66. package/src/app-server/protocol-generated/json/v2/GetAccountResponse.json +0 -102
  67. package/src/app-server/protocol-generated/json/v2/ModelListResponse.json +0 -227
  68. package/src/app-server/protocol-generated/json/v2/ThreadResumeResponse.json +0 -2630
  69. package/src/app-server/protocol-generated/json/v2/ThreadStartResponse.json +0 -2630
  70. package/src/app-server/protocol-generated/json/v2/TurnCompletedNotification.json +0 -1659
  71. package/src/app-server/protocol-generated/json/v2/TurnStartResponse.json +0 -1655
  72. package/src/app-server/protocol-validators.test.ts +0 -75
  73. package/src/app-server/protocol-validators.ts +0 -203
  74. package/src/app-server/protocol.ts +0 -520
  75. package/src/app-server/rate-limit-cache.ts +0 -48
  76. package/src/app-server/rate-limits.test.ts +0 -202
  77. package/src/app-server/rate-limits.ts +0 -583
  78. package/src/app-server/request.ts +0 -73
  79. package/src/app-server/run-attempt.context-engine.test.ts +0 -1004
  80. package/src/app-server/run-attempt.test.ts +0 -9477
  81. package/src/app-server/run-attempt.ts +0 -4683
  82. package/src/app-server/run-attempt.vision-tools.test.ts +0 -35
  83. package/src/app-server/schema-normalization-runtime-contract.test.ts +0 -206
  84. package/src/app-server/session-binding.test.ts +0 -303
  85. package/src/app-server/session-binding.ts +0 -398
  86. package/src/app-server/session-history.ts +0 -44
  87. package/src/app-server/shared-client.test.ts +0 -589
  88. package/src/app-server/shared-client.ts +0 -289
  89. package/src/app-server/side-question.test.ts +0 -1175
  90. package/src/app-server/side-question.ts +0 -1007
  91. package/src/app-server/test-support.ts +0 -48
  92. package/src/app-server/thread-lifecycle.test.ts +0 -447
  93. package/src/app-server/thread-lifecycle.ts +0 -939
  94. package/src/app-server/thread-lifecycle.user-mcp-servers.test.ts +0 -442
  95. package/src/app-server/timeout.ts +0 -9
  96. package/src/app-server/tool-progress-normalization.ts +0 -77
  97. package/src/app-server/trajectory.test.ts +0 -205
  98. package/src/app-server/trajectory.ts +0 -365
  99. package/src/app-server/transcript-mirror.test.ts +0 -524
  100. package/src/app-server/transcript-mirror.ts +0 -208
  101. package/src/app-server/transcript-repair-runtime-contract.test.ts +0 -44
  102. package/src/app-server/transport-stdio.test.ts +0 -171
  103. package/src/app-server/transport-stdio.ts +0 -107
  104. package/src/app-server/transport-websocket.test.ts +0 -69
  105. package/src/app-server/transport-websocket.ts +0 -90
  106. package/src/app-server/transport.ts +0 -117
  107. package/src/app-server/user-input-bridge.test.ts +0 -249
  108. package/src/app-server/user-input-bridge.ts +0 -316
  109. package/src/app-server/version.ts +0 -4
  110. package/src/app-server/vision-tools.ts +0 -12
  111. package/src/command-account.ts +0 -544
  112. package/src/command-formatters.ts +0 -425
  113. package/src/command-handlers.ts +0 -2004
  114. package/src/command-rpc.test.ts +0 -16
  115. package/src/command-rpc.ts +0 -142
  116. package/src/commands.test.ts +0 -3312
  117. package/src/commands.ts +0 -65
  118. package/src/conversation-binding-data.ts +0 -124
  119. package/src/conversation-binding.test.ts +0 -599
  120. package/src/conversation-binding.ts +0 -561
  121. package/src/conversation-control.test.ts +0 -126
  122. package/src/conversation-control.ts +0 -303
  123. package/src/conversation-turn-collector.test.ts +0 -191
  124. package/src/conversation-turn-collector.ts +0 -186
  125. package/src/conversation-turn-input.test.ts +0 -141
  126. package/src/conversation-turn-input.ts +0 -106
  127. package/src/manifest.test.ts +0 -20
  128. package/src/migration/apply.ts +0 -501
  129. package/src/migration/helpers.ts +0 -55
  130. package/src/migration/plan.ts +0 -461
  131. package/src/migration/provider.test.ts +0 -1741
  132. package/src/migration/provider.ts +0 -41
  133. package/src/migration/source.ts +0 -643
  134. package/src/migration/targets.ts +0 -25
  135. package/src/node-cli-sessions.test.ts +0 -180
  136. package/src/node-cli-sessions.ts +0 -711
  137. package/test-api.ts +0 -82
  138. package/tsconfig.json +0 -16
@@ -1,398 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import { embeddedAgentLog } from "klaw/plugin-sdk/agent-harness-runtime";
3
- import {
4
- ensureAuthProfileStore,
5
- resolveDefaultAgentDir,
6
- resolveProviderIdForAuth,
7
- type AuthProfileStore,
8
- } from "klaw/plugin-sdk/agent-runtime";
9
- import {
10
- CODEX_PLUGINS_MARKETPLACE_NAME,
11
- normalizeCodexServiceTier,
12
- type CodexAppServerApprovalPolicy,
13
- type CodexAppServerSandboxMode,
14
- } from "./config.js";
15
- import type { PluginAppPolicyContext } from "./plugin-thread-config.js";
16
- import type { CodexServiceTier } from "./protocol.js";
17
-
18
- const CODEX_APP_SERVER_NATIVE_AUTH_PROVIDER = "openai-codex";
19
- const PUBLIC_OPENAI_MODEL_PROVIDER = "openai";
20
-
21
- type ProviderAuthAliasLookupParams = Parameters<typeof resolveProviderIdForAuth>[1];
22
- type ProviderAuthAliasConfig = NonNullable<ProviderAuthAliasLookupParams>["config"];
23
-
24
- export type CodexAppServerAuthProfileLookup = {
25
- authProfileId?: string;
26
- authProfileStore?: AuthProfileStore;
27
- agentDir?: string;
28
- config?: ProviderAuthAliasConfig;
29
- };
30
-
31
- export type CodexAppServerThreadBinding = {
32
- schemaVersion: 1;
33
- threadId: string;
34
- sessionFile: string;
35
- cwd: string;
36
- authProfileId?: string;
37
- model?: string;
38
- modelProvider?: string;
39
- approvalPolicy?: CodexAppServerApprovalPolicy;
40
- sandbox?: CodexAppServerSandboxMode;
41
- serviceTier?: CodexServiceTier;
42
- dynamicToolsFingerprint?: string;
43
- userMcpServersFingerprint?: string;
44
- mcpServersFingerprint?: string;
45
- pluginAppsFingerprint?: string;
46
- pluginAppsInputFingerprint?: string;
47
- pluginAppPolicyContext?: PluginAppPolicyContext;
48
- contextEngine?: CodexAppServerContextEngineBinding;
49
- createdAt: string;
50
- updatedAt: string;
51
- };
52
-
53
- export type CodexAppServerContextEngineBinding = {
54
- schemaVersion: 1;
55
- engineId: string;
56
- policyFingerprint: string;
57
- projection?: CodexAppServerContextEngineProjectionBinding;
58
- };
59
-
60
- export type CodexAppServerContextEngineProjectionBinding = {
61
- schemaVersion: 1;
62
- mode: "thread_bootstrap";
63
- epoch: string;
64
- fingerprint?: string;
65
- };
66
-
67
- export function resolveCodexAppServerBindingPath(sessionFile: string): string {
68
- return `${sessionFile}.codex-app-server.json`;
69
- }
70
-
71
- export async function readCodexAppServerBinding(
72
- sessionFile: string,
73
- lookup: Omit<CodexAppServerAuthProfileLookup, "authProfileId"> = {},
74
- ): Promise<CodexAppServerThreadBinding | undefined> {
75
- const path = resolveCodexAppServerBindingPath(sessionFile);
76
- let raw: string;
77
- try {
78
- raw = await fs.readFile(path, "utf8");
79
- } catch (error) {
80
- if (isNotFound(error)) {
81
- return undefined;
82
- }
83
- embeddedAgentLog.warn("failed to read codex app-server binding", { path, error });
84
- return undefined;
85
- }
86
- try {
87
- const parsed = JSON.parse(raw) as Partial<CodexAppServerThreadBinding>;
88
- if (parsed.schemaVersion !== 1 || typeof parsed.threadId !== "string") {
89
- return undefined;
90
- }
91
- const authProfileId =
92
- typeof parsed.authProfileId === "string" ? parsed.authProfileId : undefined;
93
- return {
94
- schemaVersion: 1,
95
- threadId: parsed.threadId,
96
- sessionFile,
97
- cwd: typeof parsed.cwd === "string" ? parsed.cwd : "",
98
- authProfileId,
99
- model: typeof parsed.model === "string" ? parsed.model : undefined,
100
- modelProvider: normalizeCodexAppServerBindingModelProvider({
101
- ...lookup,
102
- authProfileId,
103
- modelProvider: typeof parsed.modelProvider === "string" ? parsed.modelProvider : undefined,
104
- }),
105
- approvalPolicy: readApprovalPolicy(parsed.approvalPolicy),
106
- sandbox: readSandboxMode(parsed.sandbox),
107
- serviceTier: readServiceTier(parsed.serviceTier),
108
- dynamicToolsFingerprint:
109
- typeof parsed.dynamicToolsFingerprint === "string"
110
- ? parsed.dynamicToolsFingerprint
111
- : undefined,
112
- userMcpServersFingerprint:
113
- typeof parsed.userMcpServersFingerprint === "string"
114
- ? parsed.userMcpServersFingerprint
115
- : undefined,
116
- mcpServersFingerprint:
117
- typeof parsed.mcpServersFingerprint === "string" ? parsed.mcpServersFingerprint : undefined,
118
- pluginAppsFingerprint:
119
- typeof parsed.pluginAppsFingerprint === "string" ? parsed.pluginAppsFingerprint : undefined,
120
- pluginAppsInputFingerprint:
121
- typeof parsed.pluginAppsInputFingerprint === "string"
122
- ? parsed.pluginAppsInputFingerprint
123
- : undefined,
124
- pluginAppPolicyContext: readPluginAppPolicyContext(parsed.pluginAppPolicyContext),
125
- contextEngine: readContextEngineBinding(parsed.contextEngine),
126
- createdAt: typeof parsed.createdAt === "string" ? parsed.createdAt : new Date().toISOString(),
127
- updatedAt: typeof parsed.updatedAt === "string" ? parsed.updatedAt : new Date().toISOString(),
128
- };
129
- } catch (error) {
130
- embeddedAgentLog.warn("failed to parse codex app-server binding", { path, error });
131
- return undefined;
132
- }
133
- }
134
-
135
- export async function writeCodexAppServerBinding(
136
- sessionFile: string,
137
- binding: Omit<
138
- CodexAppServerThreadBinding,
139
- "schemaVersion" | "sessionFile" | "createdAt" | "updatedAt"
140
- > & {
141
- createdAt?: string;
142
- },
143
- lookup: Omit<CodexAppServerAuthProfileLookup, "authProfileId"> = {},
144
- ): Promise<void> {
145
- const now = new Date().toISOString();
146
- const payload: CodexAppServerThreadBinding = {
147
- schemaVersion: 1,
148
- sessionFile,
149
- threadId: binding.threadId,
150
- cwd: binding.cwd,
151
- authProfileId: binding.authProfileId,
152
- model: binding.model,
153
- modelProvider: normalizeCodexAppServerBindingModelProvider({
154
- ...lookup,
155
- authProfileId: binding.authProfileId,
156
- modelProvider: binding.modelProvider,
157
- }),
158
- approvalPolicy: binding.approvalPolicy,
159
- sandbox: binding.sandbox,
160
- serviceTier: binding.serviceTier,
161
- dynamicToolsFingerprint: binding.dynamicToolsFingerprint,
162
- userMcpServersFingerprint: binding.userMcpServersFingerprint,
163
- mcpServersFingerprint: binding.mcpServersFingerprint,
164
- pluginAppsFingerprint: binding.pluginAppsFingerprint,
165
- pluginAppsInputFingerprint: binding.pluginAppsInputFingerprint,
166
- pluginAppPolicyContext: binding.pluginAppPolicyContext,
167
- contextEngine: binding.contextEngine,
168
- createdAt: binding.createdAt ?? now,
169
- updatedAt: now,
170
- };
171
- await fs.writeFile(
172
- resolveCodexAppServerBindingPath(sessionFile),
173
- `${JSON.stringify(payload, null, 2)}\n`,
174
- );
175
- }
176
-
177
- function readContextEngineBinding(value: unknown): CodexAppServerContextEngineBinding | undefined {
178
- if (!value || typeof value !== "object" || Array.isArray(value)) {
179
- return undefined;
180
- }
181
- const record = value as Record<string, unknown>;
182
- if (
183
- record.schemaVersion !== 1 ||
184
- typeof record.engineId !== "string" ||
185
- typeof record.policyFingerprint !== "string"
186
- ) {
187
- return undefined;
188
- }
189
- return {
190
- schemaVersion: 1,
191
- engineId: record.engineId,
192
- policyFingerprint: record.policyFingerprint,
193
- projection: readContextEngineProjectionBinding(record.projection),
194
- };
195
- }
196
-
197
- function readContextEngineProjectionBinding(
198
- value: unknown,
199
- ): CodexAppServerContextEngineProjectionBinding | undefined {
200
- if (!value || typeof value !== "object" || Array.isArray(value)) {
201
- return undefined;
202
- }
203
- const record = value as Record<string, unknown>;
204
- if (
205
- record.schemaVersion !== 1 ||
206
- record.mode !== "thread_bootstrap" ||
207
- typeof record.epoch !== "string" ||
208
- !record.epoch.trim()
209
- ) {
210
- return undefined;
211
- }
212
- return {
213
- schemaVersion: 1,
214
- mode: "thread_bootstrap",
215
- epoch: record.epoch,
216
- fingerprint: typeof record.fingerprint === "string" ? record.fingerprint : undefined,
217
- };
218
- }
219
-
220
- function readPluginAppPolicyContext(value: unknown): PluginAppPolicyContext | undefined {
221
- if (!value || typeof value !== "object" || Array.isArray(value)) {
222
- return undefined;
223
- }
224
- const record = value as Record<string, unknown>;
225
- if (typeof record.fingerprint !== "string") {
226
- return undefined;
227
- }
228
- const apps = record.apps;
229
- if (!apps || typeof apps !== "object" || Array.isArray(apps)) {
230
- return undefined;
231
- }
232
- const parsedApps: PluginAppPolicyContext["apps"] = {};
233
- for (const [appId, rawEntry] of Object.entries(apps)) {
234
- if (!rawEntry || typeof rawEntry !== "object" || Array.isArray(rawEntry)) {
235
- return undefined;
236
- }
237
- const entry = rawEntry as Record<string, unknown>;
238
- if (
239
- "appId" in entry ||
240
- typeof entry.configKey !== "string" ||
241
- entry.marketplaceName !== CODEX_PLUGINS_MARKETPLACE_NAME ||
242
- typeof entry.pluginName !== "string" ||
243
- typeof entry.allowDestructiveActions !== "boolean" ||
244
- !Array.isArray(entry.mcpServerNames) ||
245
- entry.mcpServerNames.some((serverName) => typeof serverName !== "string")
246
- ) {
247
- return undefined;
248
- }
249
- parsedApps[appId] = {
250
- configKey: entry.configKey,
251
- marketplaceName: entry.marketplaceName,
252
- pluginName: entry.pluginName,
253
- allowDestructiveActions: entry.allowDestructiveActions,
254
- mcpServerNames: entry.mcpServerNames,
255
- };
256
- }
257
- const parsedPluginAppIds: PluginAppPolicyContext["pluginAppIds"] = {};
258
- const rawPluginAppIds = record.pluginAppIds;
259
- if (rawPluginAppIds && (typeof rawPluginAppIds !== "object" || Array.isArray(rawPluginAppIds))) {
260
- return undefined;
261
- }
262
- if (rawPluginAppIds && typeof rawPluginAppIds === "object") {
263
- for (const [configKey, appIds] of Object.entries(rawPluginAppIds)) {
264
- if (!Array.isArray(appIds) || appIds.some((appId) => typeof appId !== "string")) {
265
- return undefined;
266
- }
267
- parsedPluginAppIds[configKey] = appIds;
268
- }
269
- }
270
- return {
271
- fingerprint: record.fingerprint,
272
- apps: parsedApps,
273
- pluginAppIds: parsedPluginAppIds,
274
- };
275
- }
276
-
277
- export async function clearCodexAppServerBinding(sessionFile: string): Promise<void> {
278
- try {
279
- await fs.unlink(resolveCodexAppServerBindingPath(sessionFile));
280
- } catch (error) {
281
- if (!isNotFound(error)) {
282
- embeddedAgentLog.warn("failed to clear codex app-server binding", { sessionFile, error });
283
- }
284
- }
285
- }
286
-
287
- function isNotFound(error: unknown): boolean {
288
- return Boolean(error && typeof error === "object" && "code" in error && error.code === "ENOENT");
289
- }
290
-
291
- export function isCodexAppServerNativeAuthProfile(
292
- lookup: CodexAppServerAuthProfileLookup,
293
- ): boolean {
294
- const authProfileId = lookup.authProfileId?.trim();
295
- if (!authProfileId) {
296
- return false;
297
- }
298
- try {
299
- const credential = resolveCodexAppServerAuthProfileCredential({
300
- ...lookup,
301
- authProfileId,
302
- });
303
- return isCodexAppServerNativeAuthProvider({
304
- provider: credential?.provider,
305
- config: lookup.config,
306
- });
307
- } catch (error) {
308
- embeddedAgentLog.debug("failed to resolve codex app-server auth profile provider", {
309
- authProfileId,
310
- error,
311
- });
312
- return false;
313
- }
314
- }
315
-
316
- export function normalizeCodexAppServerBindingModelProvider(params: {
317
- authProfileId?: string;
318
- modelProvider?: string;
319
- authProfileStore?: AuthProfileStore;
320
- agentDir?: string;
321
- config?: ProviderAuthAliasConfig;
322
- }): string | undefined {
323
- const modelProvider = params.modelProvider?.trim();
324
- if (!modelProvider) {
325
- return undefined;
326
- }
327
- if (
328
- isCodexAppServerNativeAuthProfile(params) &&
329
- modelProvider.toLowerCase() === PUBLIC_OPENAI_MODEL_PROVIDER
330
- ) {
331
- return undefined;
332
- }
333
- return modelProvider;
334
- }
335
-
336
- function resolveCodexAppServerAuthProfileCredential(
337
- lookup: CodexAppServerAuthProfileLookup,
338
- ): AuthProfileStore["profiles"][string] | undefined {
339
- const authProfileId = lookup.authProfileId?.trim();
340
- if (!authProfileId) {
341
- return undefined;
342
- }
343
- const store =
344
- lookup.authProfileStore ??
345
- loadCodexAppServerAuthProfileStore({
346
- agentDir: lookup.agentDir,
347
- authProfileId,
348
- config: lookup.config,
349
- });
350
- return store.profiles[authProfileId];
351
- }
352
-
353
- function loadCodexAppServerAuthProfileStore(params: {
354
- agentDir: string | undefined;
355
- authProfileId: string;
356
- config?: ProviderAuthAliasConfig;
357
- }): AuthProfileStore {
358
- return ensureAuthProfileStore(
359
- params.agentDir?.trim() || resolveDefaultAgentDir(params.config ?? {}),
360
- {
361
- allowKeychainPrompt: false,
362
- config: params.config,
363
- externalCliProviderIds: [CODEX_APP_SERVER_NATIVE_AUTH_PROVIDER],
364
- externalCliProfileIds: [params.authProfileId],
365
- },
366
- );
367
- }
368
-
369
- function isCodexAppServerNativeAuthProvider(params: {
370
- provider?: string;
371
- config?: ProviderAuthAliasConfig;
372
- }): boolean {
373
- const provider = params.provider?.trim();
374
- return Boolean(
375
- provider &&
376
- resolveProviderIdForAuth(provider, { config: params.config }) ===
377
- CODEX_APP_SERVER_NATIVE_AUTH_PROVIDER,
378
- );
379
- }
380
-
381
- function readApprovalPolicy(value: unknown): CodexAppServerApprovalPolicy | undefined {
382
- return value === "never" ||
383
- value === "on-request" ||
384
- value === "on-failure" ||
385
- value === "untrusted"
386
- ? value
387
- : undefined;
388
- }
389
-
390
- function readSandboxMode(value: unknown): CodexAppServerSandboxMode | undefined {
391
- return value === "read-only" || value === "workspace-write" || value === "danger-full-access"
392
- ? value
393
- : undefined;
394
- }
395
-
396
- function readServiceTier(value: unknown): CodexServiceTier | undefined {
397
- return normalizeCodexServiceTier(value);
398
- }
@@ -1,44 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import type { SessionEntry } from "@earendil-works/pi-coding-agent";
3
- import {
4
- buildSessionContext,
5
- migrateSessionEntries,
6
- parseSessionEntries,
7
- } from "@earendil-works/pi-coding-agent";
8
- import type { AgentMessage } from "klaw/plugin-sdk/agent-harness-runtime";
9
- import { sanitizeCodexHistoryImagePayloads } from "./image-payload-sanitizer.js";
10
-
11
- function isMissingFileError(error: unknown): boolean {
12
- return Boolean(
13
- error &&
14
- typeof error === "object" &&
15
- "code" in error &&
16
- (error as { code?: unknown }).code === "ENOENT",
17
- );
18
- }
19
-
20
- export async function readCodexMirroredSessionHistoryMessages(
21
- sessionFile: string,
22
- ): Promise<AgentMessage[] | undefined> {
23
- try {
24
- const raw = await fs.readFile(sessionFile, "utf-8");
25
- const entries = parseSessionEntries(raw);
26
- const firstEntry = entries[0] as { type?: unknown; id?: unknown } | undefined;
27
- if (firstEntry?.type !== "session" || typeof firstEntry.id !== "string") {
28
- return undefined;
29
- }
30
- migrateSessionEntries(entries);
31
- const sessionEntries = entries.filter(
32
- (entry): entry is SessionEntry => entry.type !== "session",
33
- );
34
- return sanitizeCodexHistoryImagePayloads(
35
- buildSessionContext(sessionEntries).messages,
36
- "codex mirrored history",
37
- );
38
- } catch (error) {
39
- if (isMissingFileError(error)) {
40
- return [];
41
- }
42
- return undefined;
43
- }
44
- }