MCPcopy Create free account
hub / github.com/anus-dev/ANUS / readHistoryFile

Function readHistoryFile

packages/cli/src/ui/hooks/useShellHistory.ts:30–57  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

28
29// Handle multiline commands
30async function readHistoryFile(filePath: string): Promise<string[]> {
31 try {
32 const text = await fs.readFile(filePath, 'utf-8');
33 const result: string[] = [];
34 let cur = '';
35
36 for (const raw of text.split(/\r?\n/)) {
37 if (!raw.trim()) continue;
38 const line = raw;
39
40 const m = cur.match(/(\\+)$/);
41 if (m && m[1].length % 2) {
42 // odd number of trailing '\'
43 cur = cur.slice(0, -1) + ' ' + line;
44 } else {
45 if (cur) result.push(cur);
46 cur = line;
47 }
48 }
49
50 if (cur) result.push(cur);
51 return result;
52 } catch (err) {
53 if (isNodeError(err) && err.code === 'ENOENT') return [];
54 console.error('Error reading history:', err);
55 return [];
56 }
57}
58
59async function writeHistoryFile(
60 filePath: string,

Callers 1

loadHistoryFunction · 0.85

Calls 2

isNodeErrorFunction · 0.85
readFileMethod · 0.80

Tested by

no test coverage detected