()
| 63 | * @returns Array of previous messages, most recent last |
| 64 | */ |
| 65 | export const loadMessageHistory = (): string[] => { |
| 66 | const historyPath = getMessageHistoryPath() |
| 67 | |
| 68 | if (!fs.existsSync(historyPath)) { |
| 69 | return [] |
| 70 | } |
| 71 | |
| 72 | try { |
| 73 | const historyFile = fs.readFileSync(historyPath, 'utf8') |
| 74 | const history = JSON.parse(historyFile) |
| 75 | |
| 76 | if (!Array.isArray(history)) { |
| 77 | logger.warn('Message history file has invalid format, resetting') |
| 78 | return [] |
| 79 | } |
| 80 | |
| 81 | return history.filter((item) => typeof item === 'string') |
| 82 | } catch (error) { |
| 83 | logger.error( |
| 84 | { |
| 85 | error: error instanceof Error ? error.message : String(error), |
| 86 | }, |
| 87 | 'Error reading message history', |
| 88 | ) |
| 89 | return [] |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Save message history to file system |
no test coverage detected