(cwd, options = {})
| 1056 | } |
| 1057 | |
| 1058 | export async function importExternalAgentSession(cwd, options = {}) { |
| 1059 | const availability = getCodexAvailability(cwd); |
| 1060 | if (!availability.available) { |
| 1061 | throw new Error("Codex CLI is not installed or is missing required runtime support. Install it with `npm install -g @openai/codex`, then rerun `/codex:setup`."); |
| 1062 | } |
| 1063 | if (!options.sourcePath) { |
| 1064 | throw new Error("A Claude session source path is required."); |
| 1065 | } |
| 1066 | |
| 1067 | return withDirectAppServer(cwd, async (client) => { |
| 1068 | emitProgress(options.onProgress, "Importing Claude session into Codex.", "transferring"); |
| 1069 | try { |
| 1070 | await requestExternalAgentSessionImport(client, externalAgentSessionMigration(options.sourcePath, cwd)); |
| 1071 | } catch (error) { |
| 1072 | if (error?.rpcCode === -32601) { |
| 1073 | throw new Error( |
| 1074 | "This Codex version does not support Claude session transfer. Update Codex with `npm install -g @openai/codex@latest`, then retry.", |
| 1075 | { cause: error } |
| 1076 | ); |
| 1077 | } |
| 1078 | throw error; |
| 1079 | } |
| 1080 | const threadId = importedThreadIdForSource(options.sourcePath); |
| 1081 | if (!threadId) { |
| 1082 | const stderr = cleanCodexStderr(client.stderr); |
| 1083 | throw new Error( |
| 1084 | `Codex reported that the Claude import completed, but did not record an imported thread.${stderr ? `\n${stderr}` : " Check the Codex app-server logs for the underlying import error."}` |
| 1085 | ); |
| 1086 | } |
| 1087 | emitProgress(options.onProgress, `Claude session imported (${threadId}).`, "completed", { threadId }); |
| 1088 | return { |
| 1089 | threadId, |
| 1090 | stderr: cleanCodexStderr(client.stderr) |
| 1091 | }; |
| 1092 | }); |
| 1093 | } |
| 1094 | |
| 1095 | export async function runAppServerTurn(cwd, options = {}) { |
| 1096 | const availability = getCodexAvailability(cwd); |
no test coverage detected