v0.1.0-alpha.71
·
213 commits
to main
since this release
feat: Read-before-Edit gate (alpha.71)
Production-grade edit safety. Pattern lifted from Claude Code's
FileStateCache — one of their highest-impact patterns and the single
biggest source of stale-edit bugs in agents that don't have it.
NEW: src/lib/read-cache.ts
- LRU-bounded map (100 entries, 25MB content cap), keyed by
normalized absolute path, valued by {content, timestamp, offset,
limit, isPartialView}.
- recordRead() called from runReadFile after a successful read.
- recordWrite() refreshes cache after a successful write/edit so
chained edits of the same file don't need re-Reads between them.
- checkReadBeforeWrite() is the gate: refuses an edit when the path
has no read entry, when the entry is partial, OR when disk mtime
is newer than cached timestamp AND content has changed (the
Windows mtime-drift fallback uses content-hash equality).
- Module-scoped (not per-workspace) since absolute-path keys can't
collide across workspaces; clearAllReads() called on workspace
switch as belt-and-suspenders.
WIRED:
- runReadFile records every successful read.
- runWriteFile + runEditFile invoke the gate before any disk write.
New file creation is exempt (creation can't be stale).
- Both refresh the cache post-write so subsequent edits flow.
- workspace.ts:setCurrentWorkspace clears the cache on workspace
switch.
Error messages match Claude Code's phrasing:
- not_read: "File has not been read yet. Read it first..."
- stale: "File has been modified since you last read it..."
Effect: agent can no longer edit a file based on stale knowledge.
The single biggest class of "agent broke my code by editing what it
remembered, not what's there" bugs goes away.