mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-27 01:11:40 +00:00
chore: formatting etc
This commit is contained in:
parent
56a69e519b
commit
5a5d90c85a
14 changed files with 698 additions and 237 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { existsSync, mkdirSync, readFileSync, appendFileSync } from 'node:fs'
|
||||
import { appendFileSync, existsSync, mkdirSync, readFileSync } from 'node:fs'
|
||||
import { homedir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
|
||||
|
|
@ -17,34 +17,51 @@ function decode(s: string): string {
|
|||
}
|
||||
|
||||
export function load(): string[] {
|
||||
if (cache) return cache
|
||||
if (cache) {
|
||||
return cache
|
||||
}
|
||||
|
||||
try {
|
||||
if (existsSync(file)) {
|
||||
cache = readFileSync(file, 'utf8')
|
||||
.split('\n')
|
||||
.filter(Boolean)
|
||||
.map(decode)
|
||||
.slice(-MAX)
|
||||
cache = readFileSync(file, 'utf8').split('\n').filter(Boolean).map(decode).slice(-MAX)
|
||||
} else {
|
||||
cache = []
|
||||
}
|
||||
} catch {
|
||||
cache = []
|
||||
}
|
||||
|
||||
return cache
|
||||
}
|
||||
|
||||
export function append(line: string): void {
|
||||
const trimmed = line.trim()
|
||||
if (!trimmed) return
|
||||
|
||||
if (!trimmed) {
|
||||
return
|
||||
}
|
||||
|
||||
const items = load()
|
||||
if (items.at(-1) === trimmed) return
|
||||
|
||||
if (items.at(-1) === trimmed) {
|
||||
return
|
||||
}
|
||||
|
||||
items.push(trimmed)
|
||||
if (items.length > MAX) items.splice(0, items.length - MAX)
|
||||
|
||||
if (items.length > MAX) {
|
||||
items.splice(0, items.length - MAX)
|
||||
}
|
||||
|
||||
try {
|
||||
if (!existsSync(dir)) mkdirSync(dir, { recursive: true })
|
||||
if (!existsSync(dir)) {
|
||||
mkdirSync(dir, { recursive: true })
|
||||
}
|
||||
|
||||
appendFileSync(file, encode(trimmed) + '\n')
|
||||
} catch { /* ignore */ }
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
|
||||
export function all(): string[] {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue