(args: string[])
| 1077 | } |
| 1078 | |
| 1079 | export async function runMigrateCli(args: string[]): Promise<number> { |
| 1080 | try { |
| 1081 | const parsed = parseMigrateArgs(args); |
| 1082 | ensureValidOptions(parsed); |
| 1083 | const result = migrateOpenCodeSessionToPi({ |
| 1084 | sessionId: parsed.session, |
| 1085 | maxMessages: parsed.maxMessages, |
| 1086 | dryRun: parsed.dryRun, |
| 1087 | }); |
| 1088 | const action = result.dryRun ? "Would write" : "Wrote"; |
| 1089 | console.log(`${action} Pi session JSONL:`); |
| 1090 | console.log(` path: ${result.outputPath}`); |
| 1091 | console.log(` pi session id: ${result.piSessionId}`); |
| 1092 | console.log(` source messages: ${result.sourceMessageCount}`); |
| 1093 | console.log(` migrated entries: ${result.messageCount}`); |
| 1094 | console.log(` bytes: ${result.byteCount}`); |
| 1095 | console.log(` compartments copied: ${result.compartmentsCopied}`); |
| 1096 | console.log(` session facts copied: ${result.factsCopied}`); |
| 1097 | console.log( |
| 1098 | ` compaction marker: ${result.compactionMarkerWritten ? "yes" : "no"}${ |
| 1099 | result.compactionMarkerWritten |
| 1100 | ? ` (boundary: ${result.compactionBoundaryEntryId}, first kept: ${result.compactionFirstKeptEntryId})` |
| 1101 | : "" |
| 1102 | }`, |
| 1103 | ); |
| 1104 | if (result.boundariesApproximated > 0) { |
| 1105 | console.log( |
| 1106 | ` boundaries approximated: ${result.boundariesApproximated} (nearest-at-or-before)`, |
| 1107 | ); |
| 1108 | } |
| 1109 | if (!result.dryRun) { |
| 1110 | console.log("Pi may need to be restarted to pick up the new session file."); |
| 1111 | } |
| 1112 | return 0; |
| 1113 | } catch (error) { |
| 1114 | if (error instanceof Error && error.message === "HELP") { |
| 1115 | printMigrateHelp(); |
| 1116 | return 0; |
| 1117 | } |
| 1118 | console.error(error instanceof Error ? error.message : String(error)); |
| 1119 | console.error("Run `doctor migrate --help` for usage."); |
| 1120 | return 1; |
| 1121 | } |
| 1122 | } |
no test coverage detected