MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / loadHistory

Function loadHistory

apps/cli/src/lib/storage/history.ts:28–57  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26 * Returns empty array if file doesn't exist or is invalid
27 */
28export async function loadHistory(): Promise<string[]> {
29 const filePath = getHistoryFilePath()
30
31 try {
32 const content = await fs.readFile(filePath, "utf-8")
33 const data: HistoryData = JSON.parse(content)
34
35 // Validate structure
36 if (!data || typeof data !== "object") {
37 return []
38 }
39
40 if (!Array.isArray(data.entries)) {
41 return []
42 }
43
44 // Filter to only valid strings
45 return data.entries.filter((entry): entry is string => typeof entry === "string" && entry.trim().length > 0)
46 } catch (err) {
47 const error = err as NodeJS.ErrnoException
48 // File doesn't exist - that's expected on first run
49 if (error.code === "ENOENT") {
50 return []
51 }
52
53 // JSON parse error or other issue - log and return empty
54 console.error("Warning: Could not load CLI history:", error.message)
55 return []
56 }
57}
58
59/**
60 * Save history entries to file

Callers 3

addToHistoryFunction · 0.85
history.test.tsFile · 0.85
useInputHistoryFunction · 0.85

Calls 4

getHistoryFilePathFunction · 0.85
parseMethod · 0.80
errorMethod · 0.65
readFileMethod · 0.45

Tested by

no test coverage detected