| 1048 | } |
| 1049 | |
| 1050 | export function printMigrateHelp(): void { |
| 1051 | console.log(` |
| 1052 | Magic Context doctor migrate |
| 1053 | ───────────────────────────── |
| 1054 | |
| 1055 | Copy OpenCode session message content into a new Pi JSONL session, |
| 1056 | PLUS the source session's Magic Context state (compartments + facts) |
| 1057 | into the shared cortexkit database under the new Pi session id. |
| 1058 | |
| 1059 | Supported pairs (V1): |
| 1060 | --from opencode --to pi |
| 1061 | |
| 1062 | Usage: |
| 1063 | npx @cortexkit/opencode-magic-context@latest doctor migrate \\ |
| 1064 | --from opencode --to pi --session ses_xxx [--max-messages N] [--dry-run] |
| 1065 | |
| 1066 | Fidelity: |
| 1067 | - text, reasoning text, tool calls, and tool results are preserved |
| 1068 | - assistant 'usage' fields carry real input/output/cache token counts |
| 1069 | from the source so Pi's getContextUsage() reports realistic numbers |
| 1070 | - reasoning signatures are stripped; step-start/step-finish are skipped |
| 1071 | - file bytes are replaced with <file omitted: name> markers |
| 1072 | - compartments + session_facts are copied to the new Pi session_id; |
| 1073 | compartment boundary message IDs are remapped to the corresponding |
| 1074 | Pi entry IDs (nearest-at-or-before for boundaries that don't have |
| 1075 | a direct message-level Pi entry) |
| 1076 | `); |
| 1077 | } |
| 1078 | |
| 1079 | export async function runMigrateCli(args: string[]): Promise<number> { |
| 1080 | try { |