MCPcopy Create free account
hub / github.com/ZingerLittleBee/ServerBee / readRecentCommands

Function readRecentCommands

scripts/make-menu.ts:510–534  ·  view source on GitHub ↗
(historyPath = HISTORY_PATH)

Source from the content-addressed store, hash-verified

508 }
509
510 if (leftCommand.category !== rightCommand.category) {
511 return leftCommand.category.localeCompare(rightCommand.category)
512 }
513
514 return leftCommand.name.localeCompare(rightCommand.name)
515 })
516
517export const readRecentCommands = async (historyPath = HISTORY_PATH): Promise<Record<string, number>> => {
518 try {
519 const historyContent = await readFile(historyPath, 'utf8')
520
521 return historyContent
522 .split('\n')
523 .filter(Boolean)
524 .reduce<Record<string, number>>((recentCommands, line) => {
525 const [key, timestampValue] = line.split('\t')
526 const timestamp = Number(timestampValue)
527
528 if (key && Number.isFinite(timestamp)) {
529 recentCommands[key] = timestamp
530 }
531
532 return recentCommands
533 }, {})
534 } catch (error) {
535 if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
536 return {}
537 }

Callers 4

make-menu.test.tsFile · 0.90
recordRecentCommandFunction · 0.85
openMenuFunction · 0.85
printRecentCommandsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected