()
| 668 | } |
| 669 | |
| 670 | private async init(): Promise<boolean> { |
| 671 | setExperimentalFeatures(await this.harness.getExperimentalFeatures()); |
| 672 | await this.authFlow.refreshAvailableModels(); |
| 673 | void this.refreshProviderModelsInBackground(); |
| 674 | |
| 675 | const { startup } = this.options; |
| 676 | const { workDir } = this.state.appState; |
| 677 | let session: Session | undefined; |
| 678 | let shouldReplayHistory = false; |
| 679 | const isResumeStartup = startup.sessionFlag !== undefined || startup.continueLast; |
| 680 | const createSessionOptions: MutableCreateSessionOptions = { |
| 681 | workDir, |
| 682 | model: startup.model, |
| 683 | permission: startup.auto ? 'auto' : startup.yolo ? 'yolo' : undefined, |
| 684 | planMode: startup.plan ? true : undefined, |
| 685 | }; |
| 686 | if (this.state.appState.additionalDirs.length > 0) { |
| 687 | createSessionOptions.additionalDirs = [...this.state.appState.additionalDirs]; |
| 688 | } |
| 689 | |
| 690 | try { |
| 691 | if (isResumeStartup) { |
| 692 | if (startup.sessionFlag === '') { |
| 693 | this.state.startupState = 'picker'; |
| 694 | return false; |
| 695 | } |
| 696 | |
| 697 | if (startup.sessionFlag !== undefined) { |
| 698 | const sessions = await this.harness.listSessions({ |
| 699 | sessionId: startup.sessionFlag, |
| 700 | workDir, |
| 701 | }); |
| 702 | const target = sessions[0]; |
| 703 | if (target === undefined) { |
| 704 | throw new Error(`Session "${startup.sessionFlag}" not found.`); |
| 705 | } |
| 706 | if (resolve(target.workDir) !== resolve(workDir)) { |
| 707 | this.state.ui.stop(); |
| 708 | process.stderr.write( |
| 709 | `${currentTheme.fg( |
| 710 | 'warning', |
| 711 | `Session "${startup.sessionFlag}" was created under a different directory.\n` + |
| 712 | ` cd "${target.workDir}" && kimi -r ${startup.sessionFlag}`, |
| 713 | )}\n\n`, |
| 714 | ); |
| 715 | throw new Error( |
| 716 | `Session "${startup.sessionFlag}" was created under a different directory.`, |
| 717 | ); |
| 718 | } |
| 719 | session = await this.harness.resumeSession({ |
| 720 | id: startup.sessionFlag, |
| 721 | additionalDirs: createSessionOptions.additionalDirs, |
| 722 | }); |
| 723 | shouldReplayHistory = true; |
| 724 | } else { |
| 725 | const sessions = await this.harness.listSessions({ workDir }); |
| 726 | const target = sessions[0]; |
| 727 | if (target !== undefined) { |
no test coverage detected