@kodelyth/codex 2026.5.42 → 2026.6.1

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 +16 -1
  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,41 +0,0 @@
1
- import type {
2
- MigrationPlan,
3
- MigrationProviderContext,
4
- MigrationProviderPlugin,
5
- } from "klaw/plugin-sdk/plugin-entry";
6
- import { applyCodexMigrationPlan, prepareTargetCodexAppServer } from "./apply.js";
7
- import { buildCodexMigrationPlan } from "./plan.js";
8
- import { discoverCodexSource, hasCodexSource } from "./source.js";
9
-
10
- export function buildCodexMigrationProvider(
11
- params: {
12
- runtime?: MigrationProviderContext["runtime"];
13
- } = {},
14
- ): MigrationProviderPlugin {
15
- return {
16
- id: "codex",
17
- label: "Codex",
18
- description:
19
- "Inventory and promote Codex CLI skills while keeping Codex native plugins and hooks explicit.",
20
- async detect(ctx) {
21
- const source = await discoverCodexSource({
22
- input: ctx.source,
23
- });
24
- const found = hasCodexSource(source);
25
- return {
26
- found,
27
- source: source.root,
28
- label: "Codex",
29
- confidence: found ? source.confidence : "low",
30
- message: found ? "Codex state found." : "Codex state not found.",
31
- };
32
- },
33
- plan: buildCodexMigrationPlan,
34
- prepareApply(ctx) {
35
- return prepareTargetCodexAppServer(ctx);
36
- },
37
- async apply(ctx, plan?: MigrationPlan) {
38
- return await applyCodexMigrationPlan({ ctx, plan, runtime: params.runtime });
39
- },
40
- };
41
- }
@@ -1,643 +0,0 @@
1
- import type { Dirent } from "node:fs";
2
- import fs from "node:fs/promises";
3
- import path from "node:path";
4
- import {
5
- defaultCodexAppInventoryCache,
6
- type CodexAppInventoryRequest,
7
- } from "../app-server/app-inventory-cache.js";
8
- import { CODEX_PLUGINS_MARKETPLACE_NAME } from "../app-server/config.js";
9
- import type { CodexAppServerStartOptions } from "../app-server/config.js";
10
- import { buildCodexPluginAppCacheKey } from "../app-server/plugin-app-cache-key.js";
11
- import {
12
- pluginReadParams,
13
- type CodexPluginMarketplaceRef,
14
- } from "../app-server/plugin-inventory.js";
15
- import type { CodexGetAccountResponse, v2 } from "../app-server/protocol.js";
16
- import { requestCodexAppServerJson } from "../app-server/request.js";
17
- import {
18
- exists,
19
- isDirectory,
20
- readJsonObject,
21
- resolveHomePath,
22
- resolveUserHomeDir,
23
- } from "./helpers.js";
24
-
25
- const SKILL_FILENAME = "SKILL.md";
26
- const MAX_SCAN_DEPTH = 6;
27
- const MAX_DISCOVERED_DIRS = 2000;
28
-
29
- export type CodexSkillSource = {
30
- name: string;
31
- source: string;
32
- sourceLabel: string;
33
- };
34
-
35
- export type CodexPluginSource = {
36
- name: string;
37
- source: string;
38
- sourceKind: "app-server" | "cache";
39
- migratable: boolean;
40
- manifestPath?: string;
41
- marketplaceName?: typeof CODEX_PLUGINS_MARKETPLACE_NAME;
42
- pluginName?: string;
43
- installed?: boolean;
44
- enabled?: boolean;
45
- apps?: CodexPluginMigrationAppFact[];
46
- migrationBlock?: CodexPluginMigrationBlock;
47
- message?: string;
48
- };
49
-
50
- export type CodexPluginMigrationBlockCode =
51
- | "plugin_disabled"
52
- | "codex_subscription_required"
53
- | "codex_account_unavailable"
54
- | "plugin_read_unavailable"
55
- | "app_inventory_unavailable"
56
- | "app_inaccessible"
57
- | "app_disabled"
58
- | "app_missing";
59
-
60
- export type CodexPluginMigrationAppFact = {
61
- id: string;
62
- name: string;
63
- needsAuth?: boolean;
64
- isAccessible?: boolean;
65
- isEnabled?: boolean;
66
- };
67
-
68
- export type CodexPluginMigrationBlock = {
69
- code: CodexPluginMigrationBlockCode;
70
- apps?: CodexPluginMigrationAppFact[];
71
- error?: string;
72
- };
73
-
74
- type CodexArchiveSource = {
75
- id: string;
76
- path: string;
77
- relativePath: string;
78
- message?: string;
79
- };
80
-
81
- type CodexSource = {
82
- root: string;
83
- confidence: "low" | "medium" | "high";
84
- codexHome: string;
85
- codexSkillsDir?: string;
86
- personalAgentsSkillsDir?: string;
87
- configPath?: string;
88
- hooksPath?: string;
89
- skills: CodexSkillSource[];
90
- plugins: CodexPluginSource[];
91
- pluginDiscoveryError?: string;
92
- archivePaths: CodexArchiveSource[];
93
- };
94
-
95
- type CodexSourceDiscoveryOptions = {
96
- input?: string;
97
- evaluatePluginMigrationEligibility?: boolean;
98
- verifyPluginApps?: boolean;
99
- };
100
-
101
- type SourceAppServerRequestOptions = {
102
- startOptions: CodexAppServerStartOptions;
103
- };
104
-
105
- type PluginReadResult =
106
- | {
107
- ok: true;
108
- detail: v2.PluginDetail;
109
- }
110
- | {
111
- ok: false;
112
- error: string;
113
- };
114
-
115
- function defaultCodexHome(): string {
116
- return resolveHomePath(process.env.CODEX_HOME?.trim() || "~/.codex");
117
- }
118
-
119
- function personalAgentsSkillsDir(): string {
120
- return path.join(resolveUserHomeDir(), ".agents", "skills");
121
- }
122
-
123
- async function safeReadDir(dir: string): Promise<Dirent[]> {
124
- return await fs.readdir(dir, { withFileTypes: true }).catch(() => []);
125
- }
126
-
127
- async function discoverSkillDirs(params: {
128
- root: string | undefined;
129
- sourceLabel: string;
130
- excludeSystem?: boolean;
131
- }): Promise<CodexSkillSource[]> {
132
- if (!params.root || !(await isDirectory(params.root))) {
133
- return [];
134
- }
135
- const discovered: CodexSkillSource[] = [];
136
- async function visit(dir: string, depth: number): Promise<void> {
137
- if (discovered.length >= MAX_DISCOVERED_DIRS || depth > MAX_SCAN_DEPTH) {
138
- return;
139
- }
140
- const name = path.basename(dir);
141
- if (params.excludeSystem && depth === 1 && name === ".system") {
142
- return;
143
- }
144
- if (await exists(path.join(dir, SKILL_FILENAME))) {
145
- discovered.push({ name, source: dir, sourceLabel: params.sourceLabel });
146
- return;
147
- }
148
- for (const entry of await safeReadDir(dir)) {
149
- if (!entry.isDirectory()) {
150
- continue;
151
- }
152
- await visit(path.join(dir, entry.name), depth + 1);
153
- }
154
- }
155
- await visit(params.root, 0);
156
- return discovered;
157
- }
158
-
159
- async function discoverPluginDirs(codexHome: string): Promise<CodexPluginSource[]> {
160
- const root = path.join(codexHome, "plugins", "cache");
161
- if (!(await isDirectory(root))) {
162
- return [];
163
- }
164
- const discovered = new Map<string, CodexPluginSource>();
165
- async function visit(dir: string, depth: number): Promise<void> {
166
- if (discovered.size >= MAX_DISCOVERED_DIRS || depth > MAX_SCAN_DEPTH) {
167
- return;
168
- }
169
- const manifestPath = path.join(dir, ".codex-plugin", "plugin.json");
170
- if (await exists(manifestPath)) {
171
- const manifest = await readJsonObject(manifestPath);
172
- const manifestName = typeof manifest.name === "string" ? manifest.name.trim() : "";
173
- const name = manifestName || path.basename(dir);
174
- discovered.set(dir, {
175
- name,
176
- source: dir,
177
- manifestPath,
178
- sourceKind: "cache",
179
- migratable: false,
180
- message:
181
- "Cached Codex plugin bundle found. Review manually unless the plugin is also installed in the source Codex app-server inventory",
182
- });
183
- return;
184
- }
185
- for (const entry of await safeReadDir(dir)) {
186
- if (!entry.isDirectory()) {
187
- continue;
188
- }
189
- await visit(path.join(dir, entry.name), depth + 1);
190
- }
191
- }
192
- await visit(root, 0);
193
- return [...discovered.values()].toSorted((a, b) => a.source.localeCompare(b.source));
194
- }
195
-
196
- async function discoverInstalledCuratedPlugins(
197
- codexHome: string,
198
- options: CodexSourceDiscoveryOptions = {},
199
- ): Promise<{
200
- plugins: CodexPluginSource[];
201
- error?: string;
202
- }> {
203
- const startOptions = sourceCodexAppServerStartOptions(codexHome);
204
- const requestOptions = { startOptions };
205
- try {
206
- const response = await requestSourceCodexAppServerJson<v2.PluginListResponse>(requestOptions, {
207
- method: "plugin/list",
208
- requestParams: { cwds: [] } satisfies v2.PluginListParams,
209
- });
210
- const marketplace = response.marketplaces.find(
211
- (entry) => entry.name === CODEX_PLUGINS_MARKETPLACE_NAME,
212
- );
213
- if (!marketplace) {
214
- return {
215
- plugins: [],
216
- error: `Codex marketplace ${CODEX_PLUGINS_MARKETPLACE_NAME} was not found in source plugin inventory.`,
217
- };
218
- }
219
- const plugins = marketplace.plugins
220
- .filter((plugin) => plugin.installed)
221
- .map((plugin) => buildInstalledPluginSource(plugin))
222
- .filter((plugin): plugin is CodexPluginSource => plugin !== undefined);
223
- const withEligibility =
224
- options.evaluatePluginMigrationEligibility === true
225
- ? await withPluginMigrationEligibility({
226
- plugins,
227
- marketplace: marketplaceRef(marketplace),
228
- requestOptions,
229
- verifyPluginApps: options.verifyPluginApps === true,
230
- })
231
- : plugins;
232
- const sorted = withEligibility.toSorted((a, b) =>
233
- (a.pluginName ?? a.name).localeCompare(b.pluginName ?? b.name),
234
- );
235
- return { plugins: sorted };
236
- } catch (error) {
237
- return {
238
- plugins: [],
239
- error: error instanceof Error ? error.message : String(error),
240
- };
241
- }
242
- }
243
-
244
- function sourceCodexAppServerStartOptions(codexHome: string): CodexAppServerStartOptions {
245
- return {
246
- transport: "stdio",
247
- command: "codex",
248
- commandSource: "managed",
249
- args: ["app-server", "--listen", "stdio://"],
250
- headers: {},
251
- env: {
252
- CODEX_HOME: codexHome,
253
- HOME: path.dirname(codexHome),
254
- },
255
- };
256
- }
257
-
258
- async function requestSourceCodexAppServerJson<T>(
259
- options: SourceAppServerRequestOptions,
260
- params: {
261
- method: string;
262
- requestParams?: unknown;
263
- },
264
- ): Promise<T> {
265
- return await requestCodexAppServerJson<T>({
266
- method: params.method,
267
- requestParams: params.requestParams,
268
- timeoutMs: 60_000,
269
- startOptions: options.startOptions,
270
- authProfileId: null,
271
- isolated: true,
272
- });
273
- }
274
-
275
- function buildInstalledPluginSource(plugin: v2.PluginSummary): CodexPluginSource | undefined {
276
- const pluginName = pluginNameFromSummary(plugin);
277
- if (!pluginName) {
278
- return undefined;
279
- }
280
- return {
281
- name: plugin.name,
282
- pluginName,
283
- marketplaceName: CODEX_PLUGINS_MARKETPLACE_NAME,
284
- source: `${CODEX_PLUGINS_MARKETPLACE_NAME}/${pluginName}`,
285
- sourceKind: "app-server",
286
- migratable: true,
287
- installed: plugin.installed,
288
- enabled: plugin.enabled,
289
- };
290
- }
291
-
292
- function marketplaceRef(marketplace: v2.PluginMarketplaceEntry): CodexPluginMarketplaceRef {
293
- return {
294
- name: CODEX_PLUGINS_MARKETPLACE_NAME,
295
- ...(marketplace.path ? { path: marketplace.path } : {}),
296
- ...(!marketplace.path ? { remoteMarketplaceName: marketplace.name } : {}),
297
- };
298
- }
299
-
300
- async function withPluginMigrationEligibility(params: {
301
- plugins: CodexPluginSource[];
302
- marketplace: CodexPluginMarketplaceRef;
303
- requestOptions: SourceAppServerRequestOptions;
304
- verifyPluginApps: boolean;
305
- }): Promise<CodexPluginSource[]> {
306
- const pending: Array<{ plugin: CodexPluginSource; apps: CodexPluginMigrationAppFact[] }> = [];
307
- const evaluated: CodexPluginSource[] = [];
308
-
309
- for (const plugin of params.plugins) {
310
- if (plugin.enabled !== true) {
311
- evaluated.push({
312
- ...plugin,
313
- migratable: false,
314
- migrationBlock: { code: "plugin_disabled" },
315
- message: `Codex plugin "${plugin.pluginName ?? plugin.name}" is installed in Codex but disabled; enable it in Codex before migrating it to Klaw.`,
316
- });
317
- continue;
318
- }
319
-
320
- const detail = await readPluginDetail(params.requestOptions, params.marketplace, plugin);
321
- if (!detail.ok) {
322
- evaluated.push({
323
- ...plugin,
324
- migratable: false,
325
- migrationBlock: { code: "plugin_read_unavailable", error: detail.error },
326
- message: `Codex plugin "${plugin.pluginName ?? plugin.name}" detail could not be read: ${detail.error}`,
327
- });
328
- continue;
329
- }
330
-
331
- if (detail.detail.apps.length === 0) {
332
- evaluated.push({
333
- ...plugin,
334
- migratable: true,
335
- });
336
- continue;
337
- }
338
-
339
- const apps = detail.detail.apps
340
- .map(sourcePluginAppFact)
341
- .toSorted((left, right) => left.id.localeCompare(right.id));
342
- pending.push({ plugin, apps });
343
- }
344
-
345
- if (pending.length === 0) {
346
- return evaluated;
347
- }
348
-
349
- let sourceAccount: Awaited<ReturnType<typeof readSourceCodexAccount>> | undefined;
350
- try {
351
- sourceAccount = await readSourceCodexAccount(params.requestOptions);
352
- } catch (error) {
353
- if (!params.verifyPluginApps) {
354
- const message = error instanceof Error ? error.message : String(error);
355
- for (const { plugin, apps } of pending) {
356
- evaluated.push({
357
- ...plugin,
358
- migratable: false,
359
- migrationBlock: { code: "codex_account_unavailable", apps, error: message },
360
- message: `Codex plugin "${plugin.pluginName ?? plugin.name}" owns apps, but the source Codex app-server account could not be read: ${message}`,
361
- });
362
- }
363
- return evaluated;
364
- }
365
- }
366
- if (sourceAccount && sourceAccount !== "chatgpt") {
367
- for (const { plugin, apps } of pending) {
368
- evaluated.push({
369
- ...plugin,
370
- migratable: false,
371
- migrationBlock: { code: "codex_subscription_required", apps },
372
- message: codexSubscriptionRequiredMessage(plugin),
373
- });
374
- }
375
- return evaluated;
376
- }
377
-
378
- if (!params.verifyPluginApps) {
379
- for (const { plugin, apps } of pending) {
380
- evaluated.push({
381
- ...plugin,
382
- apps,
383
- migratable: true,
384
- });
385
- }
386
- return evaluated;
387
- }
388
-
389
- const snapshot = await refreshSourceAppInventory(params.requestOptions).catch((error) => {
390
- const message = error instanceof Error ? error.message : String(error);
391
- for (const { plugin, apps } of pending) {
392
- evaluated.push({
393
- ...plugin,
394
- migratable: false,
395
- migrationBlock: {
396
- code: "app_inventory_unavailable",
397
- apps,
398
- error: message,
399
- },
400
- message: `Codex plugin "${plugin.pluginName ?? plugin.name}" owns apps, but source app inventory could not be read: ${message}`,
401
- });
402
- }
403
- return undefined;
404
- });
405
- if (!snapshot) {
406
- return evaluated;
407
- }
408
-
409
- const appInfoById = new Map(snapshot.apps.map((app) => [app.id, app] as const));
410
- for (const { plugin, apps: declaredApps } of pending) {
411
- const apps = declaredApps
412
- .map((app) => sourcePluginAppFactWithInventory(app, appInfoById.get(app.id)))
413
- .toSorted((left, right) => left.id.localeCompare(right.id));
414
- const blockCode = migrationBlockCodeForApps(apps);
415
- if (!blockCode) {
416
- evaluated.push({ ...plugin, apps, migratable: true });
417
- continue;
418
- }
419
- evaluated.push({
420
- ...plugin,
421
- migratable: false,
422
- migrationBlock: { code: blockCode, apps },
423
- message: appInventoryBlockMessage(plugin, apps, blockCode),
424
- });
425
- }
426
-
427
- return evaluated;
428
- }
429
-
430
- async function readSourceCodexAccount(
431
- options: SourceAppServerRequestOptions,
432
- ): Promise<"chatgpt" | "non_chatgpt" | "missing"> {
433
- const response = await requestSourceCodexAppServerJson<CodexGetAccountResponse>(options, {
434
- method: "account/read",
435
- requestParams: { refreshToken: false },
436
- });
437
- if (
438
- !response.account ||
439
- typeof response.account !== "object" ||
440
- Array.isArray(response.account)
441
- ) {
442
- return "missing";
443
- }
444
- const type = response.account.type;
445
- return type === "chatgpt" ? "chatgpt" : "non_chatgpt";
446
- }
447
-
448
- async function readPluginDetail(
449
- options: SourceAppServerRequestOptions,
450
- marketplace: CodexPluginMarketplaceRef,
451
- plugin: CodexPluginSource,
452
- ): Promise<PluginReadResult> {
453
- try {
454
- const response = await requestSourceCodexAppServerJson<v2.PluginReadResponse>(options, {
455
- method: "plugin/read",
456
- requestParams: pluginReadParams(marketplace, plugin.pluginName ?? plugin.name),
457
- });
458
- return { ok: true, detail: response.plugin };
459
- } catch (error) {
460
- return { ok: false, error: error instanceof Error ? error.message : String(error) };
461
- }
462
- }
463
-
464
- async function refreshSourceAppInventory(
465
- options: SourceAppServerRequestOptions,
466
- ): Promise<Awaited<ReturnType<typeof defaultCodexAppInventoryCache.refreshNow>>> {
467
- const key = buildCodexPluginAppCacheKey({
468
- appServer: { start: options.startOptions },
469
- });
470
- const request: CodexAppInventoryRequest = async (method, requestParams) =>
471
- await requestSourceCodexAppServerJson<v2.AppsListResponse>(options, {
472
- method,
473
- requestParams,
474
- });
475
- return await defaultCodexAppInventoryCache.refreshNow({
476
- key,
477
- request,
478
- forceRefetch: true,
479
- });
480
- }
481
-
482
- function sourcePluginAppFact(app: v2.AppSummary): CodexPluginMigrationAppFact {
483
- return {
484
- id: app.id,
485
- name: app.name,
486
- needsAuth: app.needsAuth,
487
- };
488
- }
489
-
490
- function sourcePluginAppFactWithInventory(
491
- app: CodexPluginMigrationAppFact,
492
- info: v2.AppInfo | undefined,
493
- ): CodexPluginMigrationAppFact {
494
- if (!info) {
495
- return app;
496
- }
497
- return {
498
- ...app,
499
- isAccessible: info.isAccessible,
500
- isEnabled: info.isEnabled,
501
- };
502
- }
503
-
504
- function migrationBlockCodeForApps(
505
- apps: readonly CodexPluginMigrationAppFact[],
506
- ): CodexPluginMigrationBlockCode | undefined {
507
- if (apps.some((app) => app.isAccessible === false)) {
508
- return "app_inaccessible";
509
- }
510
- if (apps.some((app) => app.isEnabled === false)) {
511
- return "app_disabled";
512
- }
513
- if (apps.some((app) => app.isAccessible === undefined || app.isEnabled === undefined)) {
514
- return "app_missing";
515
- }
516
- return undefined;
517
- }
518
-
519
- function appInventoryBlockMessage(
520
- plugin: CodexPluginSource,
521
- apps: readonly CodexPluginMigrationAppFact[],
522
- code: CodexPluginMigrationBlockCode,
523
- ): string {
524
- const status =
525
- code === "app_inaccessible" ? "inaccessible" : code === "app_disabled" ? "disabled" : "missing";
526
- const blocking =
527
- apps.find((app) =>
528
- code === "app_inaccessible"
529
- ? app.isAccessible === false
530
- : code === "app_disabled"
531
- ? app.isEnabled === false
532
- : app.isAccessible === undefined || app.isEnabled === undefined,
533
- ) ?? apps[0];
534
- const appLabel = blocking ? ` app "${blocking.name}"` : " an owned app";
535
- return `Codex plugin "${plugin.pluginName ?? plugin.name}" owns${appLabel} but the source app inventory reports it is ${status}; authenticate or enable the app in Codex before migrating it to Klaw.`;
536
- }
537
-
538
- export function codexPluginMigrationSubscriptionWarning(): string {
539
- return "Codex app-backed plugin migration requires the Codex app-server source account to be logged in with a ChatGPT subscription account. Log in to the Codex app with subscription auth; Klaw auth or API-key auth does not satisfy Codex app connector access.";
540
- }
541
-
542
- function codexSubscriptionRequiredMessage(plugin: CodexPluginSource): string {
543
- return `Codex plugin "${plugin.pluginName ?? plugin.name}" owns apps, but ${codexPluginMigrationSubscriptionWarning()}`;
544
- }
545
-
546
- function pluginNameFromSummary(summary: v2.PluginSummary): string | undefined {
547
- const candidates = [summary.id, summary.name];
548
- for (const candidate of candidates) {
549
- const trimmed = candidate.trim();
550
- if (!trimmed) {
551
- continue;
552
- }
553
- const withoutMarketplaceSuffix = trimmed.endsWith(`@${CODEX_PLUGINS_MARKETPLACE_NAME}`)
554
- ? trimmed.slice(0, -`@${CODEX_PLUGINS_MARKETPLACE_NAME}`.length)
555
- : trimmed;
556
- const pathSegment = withoutMarketplaceSuffix.split("/").at(-1)?.trim();
557
- const normalized = pathSegment?.toLowerCase().replaceAll(/\s+/gu, "-");
558
- if (normalized) {
559
- return normalized;
560
- }
561
- }
562
- return undefined;
563
- }
564
-
565
- export async function discoverCodexSource(
566
- inputOrOptions?: string | CodexSourceDiscoveryOptions,
567
- ): Promise<CodexSource> {
568
- const options =
569
- typeof inputOrOptions === "string" || inputOrOptions === undefined
570
- ? { input: inputOrOptions }
571
- : inputOrOptions;
572
- const codexHome = resolveHomePath(options.input?.trim() || defaultCodexHome());
573
- const codexSkillsDir = path.join(codexHome, "skills");
574
- const agentsSkillsDir = personalAgentsSkillsDir();
575
- const configPath = path.join(codexHome, "config.toml");
576
- const hooksPath = path.join(codexHome, "hooks", "hooks.json");
577
- const codexSkills = await discoverSkillDirs({
578
- root: codexSkillsDir,
579
- sourceLabel: "Codex skill",
580
- excludeSystem: true,
581
- });
582
- const personalAgentSkills = await discoverSkillDirs({
583
- root: agentsSkillsDir,
584
- sourceLabel: "personal AgentSkill",
585
- });
586
- const sourcePluginDiscovery = await discoverInstalledCuratedPlugins(codexHome, options);
587
- const sourcePluginNames = new Set(
588
- sourcePluginDiscovery.plugins.flatMap((plugin) =>
589
- plugin.pluginName ? [plugin.pluginName] : [],
590
- ),
591
- );
592
- const cachedPlugins = (await discoverPluginDirs(codexHome)).filter((plugin) => {
593
- const normalizedName = sanitizePluginName(plugin.name);
594
- return !sourcePluginNames.has(normalizedName);
595
- });
596
- const plugins = [...sourcePluginDiscovery.plugins, ...cachedPlugins].toSorted((a, b) =>
597
- a.source.localeCompare(b.source),
598
- );
599
- const archivePaths: CodexArchiveSource[] = [];
600
- if (await exists(configPath)) {
601
- archivePaths.push({
602
- id: "archive:config.toml",
603
- path: configPath,
604
- relativePath: "config.toml",
605
- message: "Codex config is archived for manual review; it is not activated automatically",
606
- });
607
- }
608
- if (await exists(hooksPath)) {
609
- archivePaths.push({
610
- id: "archive:hooks/hooks.json",
611
- path: hooksPath,
612
- relativePath: "hooks/hooks.json",
613
- message:
614
- "Codex native hooks are archived for manual review because they can execute commands",
615
- });
616
- }
617
- const skills = [...codexSkills, ...personalAgentSkills].toSorted((a, b) =>
618
- a.source.localeCompare(b.source),
619
- );
620
- const high = Boolean(codexSkills.length || plugins.length || archivePaths.length);
621
- const medium = personalAgentSkills.length > 0;
622
- return {
623
- root: codexHome,
624
- confidence: high ? "high" : medium ? "medium" : "low",
625
- codexHome,
626
- ...((await isDirectory(codexSkillsDir)) ? { codexSkillsDir } : {}),
627
- ...((await isDirectory(agentsSkillsDir)) ? { personalAgentsSkillsDir: agentsSkillsDir } : {}),
628
- ...((await exists(configPath)) ? { configPath } : {}),
629
- ...((await exists(hooksPath)) ? { hooksPath } : {}),
630
- skills,
631
- plugins,
632
- ...(sourcePluginDiscovery.error ? { pluginDiscoveryError: sourcePluginDiscovery.error } : {}),
633
- archivePaths,
634
- };
635
- }
636
-
637
- export function hasCodexSource(source: CodexSource): boolean {
638
- return source.confidence !== "low";
639
- }
640
-
641
- function sanitizePluginName(value: string): string {
642
- return value.trim().toLowerCase().replaceAll(/\s+/gu, "-");
643
- }
@@ -1,25 +0,0 @@
1
- import path from "node:path";
2
- import {
3
- resolveAgentConfig,
4
- resolveAgentWorkspaceDir,
5
- resolveDefaultAgentId,
6
- } from "klaw/plugin-sdk/agent-runtime";
7
- import type { MigrationProviderContext } from "klaw/plugin-sdk/plugin-entry";
8
- import { resolveHomePath } from "./helpers.js";
9
-
10
- type CodexMigrationTargets = {
11
- workspaceDir: string;
12
- agentDir: string;
13
- };
14
-
15
- export function resolveCodexMigrationTargets(ctx: MigrationProviderContext): CodexMigrationTargets {
16
- const cfg = ctx.config;
17
- const agentId = resolveDefaultAgentId(cfg);
18
- const workspaceDir = resolveAgentWorkspaceDir(cfg, agentId);
19
- const configuredAgentDir = resolveAgentConfig(cfg, agentId)?.agentDir?.trim();
20
- const agentDir =
21
- ctx.runtime?.agent?.resolveAgentDir(cfg, agentId) ??
22
- (configuredAgentDir ? resolveHomePath(configuredAgentDir) : undefined) ??
23
- path.join(ctx.stateDir, "agents", agentId, "agent");
24
- return { workspaceDir, agentDir };
25
- }