( options: ChatOptions, )
| 86 | } |
| 87 | |
| 88 | export async function initializeChatHistory( |
| 89 | options: ChatOptions, |
| 90 | ): Promise<ChatHistoryItem[]> { |
| 91 | let session: Session | null = null; |
| 92 | |
| 93 | // Fork from an existing session if --fork flag is used |
| 94 | if (options.fork) { |
| 95 | const { loadSessionById, startNewSession } = await import("../session.js"); |
| 96 | const sessionToFork = loadSessionById(options.fork); |
| 97 | if (sessionToFork) { |
| 98 | logger.info(chalk.yellow("Forking from existing session...")); |
| 99 | const newSession = startNewSession(sessionToFork.history); |
| 100 | return newSession.history; |
| 101 | } else { |
| 102 | logger.error(chalk.red(`Session with ID "${options.fork}" not found.`)); |
| 103 | await gracefulExit(1); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | // Load previous session if --resume flag is used |
| 108 | if (options.resume) { |
| 109 | session = loadSession(); |
| 110 | if (session) { |
| 111 | logger.info(chalk.yellow("Resuming previous session...")); |
| 112 | return session.history; |
| 113 | } else { |
| 114 | logger.info(chalk.yellow("No previous session found, starting fresh...")); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | return []; |
| 119 | } |
| 120 | |
| 121 | // Helper function to handle manual compaction |
| 122 | async function handleManualCompaction( |
no test coverage detected