mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-12-03 03:29:51 +00:00
Add persistent disk cache for parsed session data
Some checks are pending
CI / semgrep (push) Waiting to run
Some checks are pending
CI / semgrep (push) Waiting to run
Cache normalized turns/calls to ~/.cache/codeburn/session-cache.json so the CLI skips re-parsing unchanged JSONL files on subsequent runs. File reconciliation uses dev+ino+mtime+size fingerprinting; cost, classification, and summaries are recomputed at query time. Atomic writes via temp+fsync+rename, deep structural validation on load, per-provider env fingerprinting, and best-effort save so cache failures never break the CLI. ~6x speedup on warm cache.
This commit is contained in:
parent
d568c8c103
commit
bd41fa3962
6 changed files with 1236 additions and 51 deletions
|
|
@ -71,6 +71,8 @@ export type SessionLine = string | Buffer
|
|||
type ReadSessionLinesOptions = {
|
||||
largeLineAsBuffer?: boolean
|
||||
largeLineThresholdBytes?: number
|
||||
startByteOffset?: number
|
||||
byteOffsetTracker?: { lastCompleteLineOffset: number }
|
||||
}
|
||||
|
||||
export function readSessionLines(
|
||||
|
|
@ -102,9 +104,10 @@ export async function* readSessionLines(
|
|||
return
|
||||
}
|
||||
|
||||
// Raw Buffers — no encoding. This avoids readline's ConsString trees
|
||||
// which OOM on V8 when regex-flattening 100 MB+ lines.
|
||||
const stream = createReadStream(filePath)
|
||||
const stream = createReadStream(
|
||||
filePath,
|
||||
options.startByteOffset !== undefined ? { start: options.startByteOffset } : undefined,
|
||||
)
|
||||
const SKIP_HEAD = 2048
|
||||
const largeLineThreshold = options.largeLineThresholdBytes ?? LARGE_STREAM_LINE_BYTES
|
||||
const formatLine = (buf: Buffer, lineLen: number, head?: string): SessionLine => {
|
||||
|
|
@ -115,6 +118,8 @@ export async function* readSessionLines(
|
|||
let len = 0
|
||||
let skipping = false
|
||||
let headChecked = false
|
||||
let chunkBase = options.startByteOffset ?? 0
|
||||
const tracker = options.byteOffsetTracker
|
||||
|
||||
try {
|
||||
for await (const raw of stream) {
|
||||
|
|
@ -128,6 +133,7 @@ export async function* readSessionLines(
|
|||
if (nl === -1) {
|
||||
pos = chunk.length
|
||||
} else {
|
||||
if (tracker) tracker.lastCompleteLineOffset = chunkBase + nl + 1
|
||||
skipping = false
|
||||
pos = nl + 1
|
||||
}
|
||||
|
|
@ -140,6 +146,7 @@ export async function* readSessionLines(
|
|||
len += nl - pos
|
||||
}
|
||||
pos = nl + 1
|
||||
if (tracker) tracker.lastCompleteLineOffset = chunkBase + pos
|
||||
|
||||
if (len === 0) {
|
||||
parts = []
|
||||
|
|
@ -183,6 +190,7 @@ export async function* readSessionLines(
|
|||
}
|
||||
}
|
||||
}
|
||||
chunkBase += chunk.length
|
||||
}
|
||||
|
||||
if (!skipping && len > 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue