@leo-alvarenga/pi-hash-edit

Hash-anchored file reading and editing tools (hash_read / hash_edit) that eliminate code corruption and line drift

Packages

Package details

extensionskill

Install @leo-alvarenga/pi-hash-edit from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:@leo-alvarenga/pi-hash-edit
Package
@leo-alvarenga/pi-hash-edit
Version
0.2.7
Published
Sep 18, 2026
Downloads
268/mo · 30/wk
Author
leo-alvarenga
License
MIT
Types
extension, skill
Size
10.8 KB
Dependencies
0 dependencies · 2 peers
Pi manifest JSON
{
  "skills": [
    "./skills"
  ],
  "extensions": [
    "./src/hash-edit-tools.ts"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

@leo-alvarenga/pi-hash-edit

A pi extension providing two tools, hash_read and hash_edit, that eliminate code corruption and line drift by prefixing every line of a file with a short 4-character hash.

The agent reads a file with hash_read, then targets replacements with the exact hashes. If the file changed on disk in between, hash_edit refuses the edit: no silent drift.

Install

pi install npm:@leo-alvarenga/pi-hash-edit

Restart pi or run /reload.

Usage

  1. hash_read path [startLine] [endLine] → lines as [a1f2] 42 | const x = 10; (endLine is inclusive and must be greater than startLine; omit both to read the whole file)
  2. hash_edit path startHash endHash newContent → replaces the block between the two hashes

A hash mismatch returns:

Hash Mismatch Error: Could not find start hash [...] or end hash [...] in file. The file has been modified since your last read. Please re-run hash_read.

Notes:

  • To replace a single line, pass its hash as both startHash and endHash.
  • To delete lines, pass an empty newContent.
  • Identical lines share a hash — hash_edit targets the first occurrence; anchor on a unique line if needed.

How it works

  • Hashes are 4 hex chars (16 bits) of sha256 over the line with trailing whitespace trimmed (CRLF- and LF-tolerant)
  • Zero runtime dependencies beyond pi's bundled typebox; uses only node:fs, node:crypto, node:path

Skill

The package also ships a hash-edit skill (skills/hash-edit/SKILL.md), auto-loaded by pi. It instructs the agent to prefer hash_read / hash_edit over the built-in read/write/edit tools when working with existing files, and to re-read before every edit.