@yofriadi/pi-hashline-edit
```bash pi install git:github.com/yofriadi/pi-extensions@hashline-edit-v<version> ```
Package details
Install @yofriadi/pi-hashline-edit from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:@yofriadi/pi-hashline-edit- Package
@yofriadi/pi-hashline-edit- Version
0.1.1- Published
- Feb 17, 2026
- Downloads
- 15/mo · 3/wk
- Author
- yofriadi
- License
- unknown
- Types
- extension
- Size
- 34.1 KB
- Dependencies
- 0 dependencies · 1 peer
Pi manifest JSON
{
"extensions": [
"./src/index.ts"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
@yofriadi/pi-hashline-edit
Install from git URL
pi install git:github.com/yofriadi/pi-extensions@hashline-edit-v<version>
To load only this extension from the monorepo package source, use package filtering in settings:
{
"packages": [
{
"source": "git:github.com/yofriadi/pi-extensions@hashline-edit-v<version>",
"extensions": ["packages/hashline-edit/src/index.ts"]
}
]
}
Hashline edit mode for pi — a line-addressable edit format using content hashes.
Overview
Each line in a file is identified by its 1-indexed line number and an 8-char base16 hash derived from the exact line content (except trailing \r). The combined LINE:HASH reference acts as both an address and a staleness check.
Displayed format: LINENUM:HASH|CONTENT
Reference format: "LINENUM:HASH" (e.g. "5:a3f19c2e")
Usage
import {
computeLineHash,
formatHashLines,
applyHashlineEdits,
parseLineRef,
} from "@yofriadi/pi-hashline-edit";
// Format file content with hashline prefixes
const content = "function hello() {\n return 'world';\n}";
const formatted = formatHashLines(content);
// "1:a3f19c2e|function hello() {\n2:5b0ea94c| return 'world';\n3:0f8a2c11|}"
// Compute hash for a single line
const hash = computeLineHash(1, "function hello() {");
// Apply edits with hash verification
const result = applyHashlineEdits(content, [
{ set_line: { anchor: "2:5b0ea94c", new_text: " return 'universe';" } },
]);
Edit Operations
set_line: Replace a single linereplace_lines: Replace a contiguous range of linesinsert_after: Add new content after an anchor line
Note:
replacepayloads are intentionally not handled byapplyHashlineEdits; they should be processed by a separate replace-mode flow.
API
| Function | Description |
|---|---|
computeLineHash(idx, line) |
Compute short hash for a line |
formatHashLines(content, startLine?) |
Format content with LINE:HASH| prefixes |
applyHashlineEdits(content, edits) |
Apply hashline edits with validation |
parseLineRef(ref) |
Parse "LINE:HASH" string to {line, hash} |
validateLineRef(ref, fileLines) |
Validate hash matches current content |
streamHashLinesFromUtf8(source, options?) |
Stream hashline output from bytes |
streamHashLinesFromLines(lines, options?) |
Stream hashline output from lines |
License
MIT