(history: string[])
| 94 | * Save message history to file system |
| 95 | */ |
| 96 | export const saveMessageHistory = (history: string[]): void => { |
| 97 | const configDir = getConfigDir() |
| 98 | const historyPath = getMessageHistoryPath() |
| 99 | |
| 100 | try { |
| 101 | // Ensure config directory exists |
| 102 | if (!fs.existsSync(configDir)) { |
| 103 | fs.mkdirSync(configDir, { recursive: true }) |
| 104 | } |
| 105 | |
| 106 | // Limit history size to prevent file from growing too large |
| 107 | const limitedHistory = |
| 108 | history.length > MAX_HISTORY_SIZE |
| 109 | ? history.slice(history.length - MAX_HISTORY_SIZE) |
| 110 | : history |
| 111 | |
| 112 | // Save history |
| 113 | fs.writeFileSync(historyPath, JSON.stringify(limitedHistory, null, 2)) |
| 114 | } catch (error) { |
| 115 | logger.error( |
| 116 | { |
| 117 | error: error instanceof Error ? error.message : String(error), |
| 118 | }, |
| 119 | 'Error saving message history', |
| 120 | ) |
| 121 | // Don't throw - history persistence is not critical |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Clear message history from file system |
no test coverage detected