MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / saveMessageHistory

Function saveMessageHistory

cli/src/utils/message-history.ts:96–123  ·  view source on GitHub ↗
(history: string[])

Source from the content-addressed store, hash-verified

94 * Save message history to file system
95 */
96export 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

Callers 1

useInputHistoryFunction · 0.90

Calls 2

getConfigDirFunction · 0.90
getMessageHistoryPathFunction · 0.85

Tested by

no test coverage detected