Pi package that blocks stale edit and destructive existing-file write operations when files changed since the agent last read them.
Disclaimer: this is clanker slop. Use at your own risk.
This adds Claude Code-style stale-file protection to Pi without patching Pi core. It reduces accidental clobbers when a file is edited externally, by another agent, or by a parallel workflow after the current agent last read it.
From npm:
pi install npm:pi-read-before-writeFrom GitHub:
pi install git:github.com/SteelDynamite/pi-read-before-writeFor project-local install:
pi install -l npm:pi-read-before-writeFor local development/testing:
npm install
npm run build
pi -e ./dist/index.js- Successful
readcalls record a SHA-256 fingerprint of the full file on disk. editis blocked unless the file was read in the current Pi session and is unchanged.writeto an existing file is blocked unless the file was read in the current Pi session and is unchanged.writeto a new file is allowed.- If a previously read file is deleted before
editorwrite, the operation is blocked. - Successful
edit/writecalls refresh the recorded fingerprint. - Fingerprints are held in a bounded LRU cache: 100 files or 1MB of fingerprint metadata, whichever is hit first.
- Paths are resolved against Pi's current working directory, normalize Unicode spaces, strip a leading
@, expand~, supportfile://URLs, and userealpath()when possible so symlink aliases share one fingerprint.
Unread file:
Blocked stale write: file has not been read in this session. Read it before editing: path/to/file.ts
Changed file:
Blocked stale write: file changed on disk since the last read. Read it again before editing: path/to/file.ts
Deleted file:
Blocked stale write: file was deleted since the last read: path/to/file.ts
- It does not block file mutations through
bash, external scripts, or other custom tools. - It cannot fully close the small race between extension preflight and Pi's built-in write execution without core support.
- Fingerprints are in memory and are lost when Pi restarts; resumed sessions should re-read files before editing.
- Multiple Pi processes do not share fingerprint state.
- Large files are hashed in full.
- Fingerprints can be evicted from the bounded LRU cache; evicted files must be read again before editing.
npm install
npm run typecheck
npm test
npm run test:pack
npm run audit:release
npm run buildThe implementation lives in src/index.ts. The original design notes are in docs/PLAN.md.
MIT