| 867 | } |
| 868 | |
| 869 | function ensureValidOptions( |
| 870 | opts: MigrateCliOptions, |
| 871 | ): asserts opts is Required<Pick<MigrateCliOptions, "from" | "to" | "session">> & |
| 872 | MigrateCliOptions { |
| 873 | if (!opts.from) throw new Error("Missing required flag: --from <opencode>"); |
| 874 | if (!opts.to) throw new Error("Missing required flag: --to <pi>"); |
| 875 | if (opts.from !== "opencode" || opts.to !== "pi") { |
| 876 | if (opts.from === "pi" && opts.to === "opencode") { |
| 877 | throw new Error( |
| 878 | "Migration pi → opencode is not yet supported (V1 supports only opencode → pi)", |
| 879 | ); |
| 880 | } |
| 881 | throw new Error( |
| 882 | `Unsupported migration: ${opts.from} → ${opts.to} (V1 supports only opencode → pi)`, |
| 883 | ); |
| 884 | } |
| 885 | if (!opts.session) throw new Error("Missing required flag: --session <id>"); |
| 886 | if ( |
| 887 | opts.maxMessages !== undefined && |
| 888 | (!Number.isInteger(opts.maxMessages) || opts.maxMessages <= 0) |
| 889 | ) { |
| 890 | throw new Error("--max-messages must be a positive integer"); |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | export function migrateOpenCodeSessionToPi( |
| 895 | opts: MigrateOpenCodeSessionToPiOptions, |