Files
oh-my-pi/packages/hashline
can1357 02f870fb20 feat: supported markdown section operations for block edits
- Added tree-sitter markdown support to resolve headings into full sections in `pi-ast`.
- Enabled block operations (`SWAP.BLK`, `DEL.BLK`, `INS.BLK.POST`) on markdown headings so they encompass the entire section, including nested deeper headings.
- Updated system prompt to guide agents in using structured markdown heading edits for plans.
- Fixed `plan-mode-guard` to correctly resolve local protocol options for subagents.
2026-06-26 16:14:23 +02:00
..
2026-06-26 09:19:53 +02:00
2026-06-15 10:46:45 +02:00

@oh-my-pi/hashline

A compact, line-anchored patch language and applier.

Hashline is a diff format designed for LLM-driven file edits. It binds every hunk to a file-content hash so stale anchors are rejected before they corrupt code, and it abstracts over the filesystem so the same patcher works on disk, in memory, over the network, or against any custom backend.

Quick start

import {
	Filesystem,
	InMemoryFilesystem,
	InMemorySnapshotStore,
	Patcher,
	Patch,
} from "@oh-my-pi/hashline";

const fs = new InMemoryFilesystem();
const snapshots = new InMemorySnapshotStore();
const before = `const greeting = "hi";\nexport { greeting };\n`;
await fs.writeText("hello.ts", before);

const tag = snapshots.record("hello.ts", before);
const patcher = new Patcher({ fs, snapshots });
const patch = Patch.parse(String.raw`[hello.ts#${tag}]
SWAP 1.=1:
+const greeting = "hello";`);
const result = await patcher.apply(patch);

console.log(result.sections[0].op); // "update"
console.log(await fs.readText("hello.ts"));

Format

See src/prompt.md for the user-facing description and src/grammar.lark for the formal grammar.

Each file section starts with [PATH#TAG]. The tag is a 4-hex content hash of the full normalized file text recorded by the SnapshotStore, and it is not meaningful outside that store. The patcher protects against stale anchors by resolving the tag, verifying the live file still matches the recorded content hash, and refusing or attempting session-aware recovery on mismatch.

Inside a section:

  • SWAP A.=B: — replace lines A.=B with following +TEXT body rows.
  • SWAP.BLK A: — replace the syntactic block beginning on line A.
  • DEL A.=B / DEL.BLK A — delete concrete lines or a resolved block.
  • INS.PRE A: / INS.POST A: / INS.HEAD: / INS.TAIL: — insert following body rows.
  • INS.BLK.POST A: — insert following body rows after the resolved block's last line.
  • +TEXT — literal body row (use + alone for a blank line).

Abstractions

Filesystem

Read and write text by path. The default implementations:

  • InMemoryFilesystem — backed by a Map. Tests, sandboxes.
  • NodeFilesystem — disk-backed via Bun.file/Bun.write. Default for CLIs.

Subclass Filesystem to wire hashline into any storage: VFS, S3, an LSP text-document protocol, a Git tree, anything.

SnapshotStore

Required. Hashline tags are full-file content hashes recorded per path, so Patcher must receive the store that observed them. Recovery replays edits against the cached pre-edit snapshot and 3-way-merges onto current content when the live file diverged.

Patcher

The orchestration class. Reads, normalizes line endings + BOM, applies edits, restores line endings, and writes via the configured Filesystem. Multi-section patches are preflighted up front so a partial batch never lands.