hashline-core

June 17, 2026 · View on GitHub

Generated: 2026-06-17

OVERVIEW

The engine behind the Hashline edit tool (inspired by oh-my-pi). Tags every line with a LINE#HASH| content hash, validates edit refs against current content (rejecting stale lines), then applies structured replace/append/prepend edits with autocorrection, deduplication, and unified-diff generation. Package: @oh-my-opencode/hashline-core.

PUBLIC API (src/index.ts, ~26 fns + 7 types) — by area

AreaFilesKey exports
Hash computehash-computation.ts, xxhash32.ts, constants.tscomputeLineHash, computeLegacyLineHash, formatHashLine(s), streamHashLinesFrom{Utf8,Lines}, NIBBLE_STR, HASHLINE_DICT
Validationvalidation.tsparseLineRef, validateLineRef(s), normalizeLineRef, HashlineMismatchError
Applyedit-operations.ts, edit-operation-primitives.tsapplyHashlineEdits, applyHashlineEditsWithReport, apply{SetLine,ReplaceLines,InsertAfter,InsertBefore,Append,Prepend}
Normalize/dedup/ordernormalize-edits.ts, edit-deduplication.ts, edit-ordering.tsnormalizeHashlineEdits, dedupeEdits, detectOverlappingRanges
Autocorrectautocorrect-replacement-lines.ts, edit-text-normalization.tsautocorrectReplacementLines, prefix/indent/echo strippers
Diff/displaydiff-utils.ts, hashline-edit-diff.tstoHashlineContent, generateUnifiedDiff, countLineDiffs, generateHashlineDiff
Canonicalize/chunkfile-text-canonicalization.ts, hashline-chunk-formatter.tscanonicalizeFileText/restoreFileText (BOM + LF/CRLF), createHashlineChunkFormatter (200 lines / 64 KB)

DEPENDENCIES & CONSUMERS

  • Depends on: diff (^9) — for createTwoFilesPatch in generateUnifiedDiff only. Otherwise self-contained.
  • Consumed by: the ~15 thin re-export shims under omo-opencode/src/tools/hashline-edit/. NOT consumed by the Codex edition (Light has no hashline).

NOTES

  • "Option 2" hashing: no npm xxhash dependency. xxhash32.ts prefers native Bun.hash.xxHash32() at call time and falls back to a pure-JS impl, so it runs under Bun and Node.
  • Legacy hash compatibility: validation accepts both computeLineHash (trimEnd + strip \r) and computeLegacyLineHash (strip ALL whitespace) — old stored hashes still validate.
  • Seed rule: content lines seed 0; whitespace-only lines seed lineNumber (distinct hash per position).
  • normalizeHashlineEdits rejects unknown ops with "Legacy format was removed; use op/pos/end/lines." — the discriminated union is replace | append | prepend only.
  • Parent: packages/AGENTS.md.