@oh-my-pi/hashline 15.11.4 → 15.11.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/CHANGELOG.md +222 -0
  2. package/package.json +3 -1
  3. package/src/apply.ts +20 -12
package/CHANGELOG.md ADDED
@@ -0,0 +1,222 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased]
4
+
5
+ ## [15.11.4] - 2026-06-12
6
+
7
+ ### Added
8
+
9
+ - Added inward landing correction for `insert after block N:`: a body indented deeper than the block's closing line now slides back across the block's trailing closer lines and lands inside the block at its claimed depth, with a warning naming the landing line. Same conservative guards as the outward shift — comparable indentation only, closers only, abandoned when another hunk targets a crossed line; plain `insert after M:` stays literal
10
+ - Added closer-anchor lowering for `insert after block N:`: anchoring on a pure closing-delimiter line (where no block begins, so resolution previously failed the whole patch) now applies as plain `insert after N:` with a warning teaching the opener-only rule. `resolveBlockEdits` gained an `onWarning` callback; apply, preview, and patcher paths surface it on `warnings`
11
+
12
+ ### Changed
13
+
14
+ - Condensed the edit-tool prompt: one-line op definitions, 5–20-word rules, and a tighter `<critical>` recap; landing-correction mechanics are no longer described to the agent
15
+
16
+ ## [15.11.1] - 2026-06-11
17
+
18
+ ### Fixed
19
+
20
+ - Fixed the `insert after block N:` prompt guidance so it explicitly says N must be the block opener, not the closing delimiter or last visible line, and points visible closing-line edits to plain `insert after M:`. ([#2292](https://github.com/can1357/oh-my-pi/issues/2292))
21
+
22
+ ## [15.11.0] - 2026-06-10
23
+
24
+ ### Changed
25
+
26
+ - Block-unresolved errors (`replace block N:` / `delete block N` / `insert after block N:` failing to resolve a syntactic block) now append a numbered preview of the file around the anchor line — same `*`-marked context rows the hash-mismatch error shows — so the offending line is visible without a re-read
27
+
28
+ ## [15.10.11] - 2026-06-10
29
+
30
+ ### Breaking Changes
31
+
32
+ - Changed `BlockResolution.isDelete` to `BlockResolution.op` (`"replace" | "delete" | "insert_after"`) so resolutions can describe every block-anchored op
33
+
34
+ ### Added
35
+
36
+ - Added `insert after block N:` patch syntax to insert body rows after the last line of the tree-sitter-resolved block beginning on line N, so a statement can be placed after a construct without counting to its closing line
37
+ - Added depth-guided landing correction for `insert after N:` hunks: a body indented shallower than its anchor line slides past the structural closer lines below the anchor until depth returns to the body's level, with a warning naming the final landing line. The shift never crosses content lines, skips incomparable indentation styles and pure-closer bodies, and is abandoned when another hunk targets a crossed line
38
+ - Added a global byte ceiling to `InMemorySnapshotStore` (`maxTotalBytes`, default 64 MiB): the cap was previously per-file only, so a session reading many large files retained up to 30 paths × 4 full-text versions indefinitely
39
+
40
+ ### Changed
41
+
42
+ - Trimmed the `replace block N:` ops entry in the patch prompt to grammar and pointing rules; the usage doctrine it duplicated stays in the rules section
43
+ - Changed `buildCompactDiffPreview` to treat blank rows as gap separators alongside `…` markers: separators never stack (removed lines omitted from the preview no longer leave two adjacent), and leading/trailing separators are trimmed
44
+
45
+ ### Fixed
46
+
47
+ - Fixed the boundary-echo repair stripping payload edges without the balance-neutrality guard its own documentation promised: in brace-heavy code where bare `}` lines repeat, a payload intentionally beginning/ending with lines identical to the range's neighbors had both edges silently dropped, writing content that differed from what was authored
48
+ - Fixed lenient bare-body handling silently mutating payloads: interior blank rows in an un-prefixed body were dropped outright, and a body of numeric-keyed literals (`1: "one"` dict/YAML shapes) satisfied the uniform line-prefix check and had its keys stripped from every line — blank rows are now preserved when proven interior, and the uniform strip refuses lone-literal remainders
49
+ - Fixed the multi-section "all-or-nothing" claim being false for write failures: commits run serially, so a mid-batch write error left earlier sections on disk while the thrown error said nothing — the error now lists exactly which sections were written and which were not
50
+ - Fixed `delete`/`replace` ranges ending on the phantom trailing line of a newline-terminated file silently stripping the file's final newline; such anchors are now rejected with guidance toward `N-1` / `insert tail:` (inserts there remain valid, and genuine empty last lines of unterminated files stay deletable)
51
+
52
+ ## [15.10.5] - 2026-06-08
53
+
54
+ ### Added
55
+
56
+ - Added `maxAddedRunContext` option to control how many added lines are shown at each side of collapsed inserted runs, with `maxUnchangedRun` kept as a backward-compatible alias
57
+
58
+ ### Changed
59
+
60
+ - Changed `buildCompactDiffPreview` to omit removed lines from the preview while preserving removal counts for offset tracking
61
+ - Changed `buildCompactDiffPreview` to collapse long contiguous added runs with a bare `…` marker, keeping only the first and last `maxAddedRunContext` lines visible (the surrounding line numbers convey how many were elided)
62
+
63
+ ### Fixed
64
+
65
+ - Fixed compact edit previews to omit deleted content, keep visible lines anchored to the current file, and collapse long inserted runs with a bare `…` elision marker.
66
+ - Fixed compact edit previews to render added/current lines without diff-prefix padding and normalize adjacent ASCII/Unicode elision markers to one `…`.
67
+
68
+ ## [15.10.3] - 2026-06-08
69
+
70
+ ### Added
71
+
72
+ - Added a `BlockResolution` type and surfaced resolved block spans on `ApplyResult.blockResolutions` / `PatchSectionResult.blockResolutions`. `resolveBlockEdits` now accepts an `onResolved` callback that reports each `replace block N:` / `delete block N` anchor's resolved `[start, end]` span (and whether it was a delete). Spans are surfaced only on the no-drift apply paths, where the resolved line numbers line up with the tag the caller read.
73
+
74
+ ### Changed
75
+
76
+ - Reworked the `edit` tool prompt (`prompt.md`): added a `replace block N` vs `replace N..M` decision rule, documented that a leading decorator/attribute/doc-comment is a separate node not swept into the block (point N at the first decorator line, or use `replace N..M` for a Rust-style `///` sibling comment), reframed the blast-radius guidance so "block replace" no longer reads as the dangerous option, and added a decorated-definition example.
77
+
78
+ ## [15.10.2] - 2026-06-08
79
+
80
+ ### Fixed
81
+
82
+ - Stripped read-output line-number prefixes (`N:`) from auto-piped bare body rows so that pasting `3:text` without a `+` prefix no longer injects `3:` as literal content. Stripping is applied only when *every* bare row in the hunk carries the prefix (the signature of a pasted snapshot) and removes at most one prefix per row, so a genuine body that merely starts with `digits:` (YAML port maps, timestamps) is left intact ([#1492](https://github.com/can1357/oh-my-pi/issues/1492)).
83
+
84
+ ## [15.9.67] - 2026-06-06
85
+
86
+ ### Breaking Changes
87
+
88
+ - Changed hashline file section headers from `¶PATH#TAG` to `[PATH#TAG]` so model-authored edits use ASCII delimiters instead of a pilcrow sigil.
89
+
90
+ ### Fixed
91
+
92
+ - Fixed missing-header diagnostics and copied-content prefix stripping to consistently teach and recognize 4-hex snapshot tags.
93
+
94
+ ## [15.8.2] - 2026-06-03
95
+
96
+ ### Fixed
97
+
98
+ - Fixed delimiter-balance boundary repair to also drop a single duplicated structural opener (e.g. a restated `foo(` / `if (x) {` signature line surviving just above the range), not only duplicated closers. Zero-balance duplicates remain untouched.
99
+
100
+ ## [15.8.0] - 2026-06-02
101
+
102
+ ### Fixed
103
+
104
+ - Fixed hashline replacements that accidentally restated unchanged lines above and below the selected range so they no longer duplicate both boundary lines ([#1664](https://github.com/can1357/oh-my-pi/issues/1664)).
105
+
106
+ ## [15.7.0] - 2026-05-31
107
+ ### Added
108
+
109
+ - Added `replace block N:` and `delete block N` patch syntax to replace or delete the entire syntactic block that begins on line N using tree-sitter-resolved spans
110
+ - Added `BlockResolver` support in `Patcher` and `PatchSection.applyTo`/`applyPartialTo` to wire language-specific block-resolution at apply time
111
+ - Added `resolveBlockEdits` and block edit type definitions to the package API for resolving deferred `replace block` / `delete block` edits
112
+
113
+ ## [15.5.13] - 2026-05-29
114
+ ### Breaking Changes
115
+
116
+ - Changed hashline section tags from 3-hex to 4-hex content-hash tags, so legacy 3-digit tags are no longer valid
117
+ - Changed hashline syntax to verb-based v4: body-bearing ops are `replace N..M:`, `insert before N:`, `insert after N:`, `insert head:`, and `insert tail:`, while bodyless `delete N..M` handles deletion. Removed `>A..B` repeat rows and the old `prepend:` / `append:` virtual insert headers; `-` rows remain rejected with a teaching error.
118
+
119
+ ### Added
120
+
121
+ - Added `maxPaths` and `maxVersionsPerPath` options to `InMemorySnapshotStore` to bound tracked paths and per-path snapshot history
122
+ - Re-introduced balance-validated boundary repair in `applyEdits`. A replacement hunk (`replace N..M:` + body) is normalized so its payload preserves the deleted region's delimiter balance: when the body restates a closing delimiter that survives just outside the range (duplicate `}` / `);` / `]`) the echo is dropped, and when the range deletes a structural closer the body never restates (missing closer) the closer is spared instead of deleted. A repair fires only when one boundary operation drives the per-channel `()` / `[]` / `{}` imbalance to exactly zero while leaving surrounding text byte-identical (single-line ops are limited to pure structural-closer lines), so balance-preserving edits and intentional balanced duplicates are never touched. Bracket couples are also bounded by line count: structural balance delta repair is capped to 10 duplicate lines across all channels combined, massive balanced blocks are skipped.
123
+
124
+ ### Changed
125
+
126
+ - Changed patch application to accept edits whenever the live file's normalized content hash matches the section tag, even when that anchor was not covered by a stored snapshot
127
+
128
+ ### Removed
129
+
130
+ - Removed `SnapshotStore.recordContiguous` and `SnapshotStore.recordSparse` in favor of full-file `record(path, fullText)` snapshots
131
+
132
+ ### Fixed
133
+
134
+ - Fixed hash mismatch rejections caused by CRLF or trailing spaces/tabs by normalizing those characters before computing file-hash tags
135
+
136
+ ## [15.5.12] - 2026-05-29
137
+
138
+ ### Changed
139
+
140
+ - `InMemorySnapshotStore` now coalesces consecutive same-path reads into one tag whenever their views agree on every shared line. Overlapping or directly abutting range reads extend the existing snapshot's contiguous run in place; reads separated by a gap union into a `SparseSnapshot` spanning both ranges. A disagreeing shared line is treated as "the file changed on disk" and mints a fresh tag, preserving the prior superset-dedup behavior. This stops sequential range reads of an unchanged file (e.g. `:50-100` then `:100-200`, or `:1-100` then `:150-200`) from fragmenting into separate anchors.
141
+
142
+ ## [15.5.11] - 2026-05-29
143
+
144
+ ### Added
145
+
146
+ - `MismatchError` now distinguishes "hash recognized but file content drifted" from "hash never recorded for this path". The latter (likely fabricated or carried over from a prior session) emits a dedicated `hash #X is not from this session` rejection message with explicit "never invent the tag" guidance. The `MismatchDetails` interface gains an optional `hashRecognized?: boolean` (defaults to `true` for backward compatibility); `MismatchError` exposes it as a readonly field so callers can branch on the cause.
147
+
148
+ ## [15.5.8] - 2026-05-28
149
+ ### Breaking Changes
150
+
151
+ - Removed the single-number hunk header shorthand. A hunk header now REQUIRES two line numbers (`A A` for a single line, `A B` for a range); a bare `A` row throws `single-number hunk header "A" is no longer accepted`. The `&A` body-row shorthand for `&A..A` is unchanged.
152
+ - Changed hunk header syntax from `A-B:` to `@@ A..B @@` with `@@ A @@` shorthand for single lines
153
+ - Changed repeat payload sigil from `^A-B` to `&A..B` with `&A` shorthand for single lines
154
+ - Changed range separator from `-` to `..` in all contexts (anchors and repeats)
155
+ - Changed empty hunk behavior: concrete ranges now delete (no blank-line insertion); BOF/EOF empty hunks are now no-ops
156
+ - Removed `ApplyOptions` parameter from `applyEdits()` and related APIs; auto-absorb behavior is no longer configurable
157
+ - Removed diagnostic warnings for auto-absorbed duplicates from `ApplyResult`; warnings now come only from parser, patcher, or recovery
158
+ - Removed legacy hashline block syntax `A-B:`, `A-B:-`, and `^A-B` and replaced edits with `@@ A..B @@` hunks using `+` and `&` body rows
159
+ - Removed `A:` shorthand syntax; use explicit `A-A:` for single-line anchors
160
+ - Removed `↑` and `↓` payload sigils; use `|TEXT` for literal rows and `^A-B` for repeating original lines
161
+ - Removed standalone delete rows; use inline `A-B:-` syntax instead
162
+ - Removed `after_anchor` cursor kind; all inserts now use `before_anchor` positioning
163
+ - Replaced insert-above/insert-below payload sigils with linear body rows: `|TEXT` emits literal text and `^A-B` repeats original file lines inline.
164
+ - Replaced standalone delete rows with inline range deletes: use `A-B:-`.
165
+ - Changed empty `A-B:`, `BOF:`, and `EOF:` blocks to write one blank line instead of being rejected.
166
+
167
+ ### Added
168
+
169
+ - Added compatibility parsing for apply_patch-style and unified-diff row noise by stripping path noise and converting context/delete body rows into hashline-compatible operations with warnings
170
+ - Added `A-B:-` inline delete syntax for concrete range anchors
171
+ - Added `^A-B` repeat payload syntax to emit original file lines inline
172
+ - Added support for empty anchor blocks to write one blank line at the anchor position
173
+
174
+ ### Changed
175
+
176
+ - Changed unified-diff compatibility mode to silently drop `-old` rows and convert context rows to `+TEXT` literals with a warning instead of rejecting them
177
+ - Changed `ABORT_MARKER` behavior to terminate parsing without surfacing a warning
178
+ - Changed numeric ranges to `A..B` form and accepted `@@ A @@` as shorthand for `@@ A..A @@`
179
+ - Changed empty hunk behavior so a concrete empty hunk deletes the selected range and `BOF`/`EOF` empty hunks no longer insert a blank line
180
+ - Changed parse behavior for `*** Abort` to stop processing without returning a speculative truncation warning
181
+ - Changed payload row format from three sigils (`|`, `↑`, `↓`) to two (`|`, `^`)
182
+ - Changed range anchor syntax to require explicit `A-B` form (no single-line shorthand)
183
+ - Changed error messages to reference new syntax and remove references to removed sigils
184
+
185
+ ## [15.5.5] - 2026-05-27
186
+
187
+ ### Breaking Changes
188
+
189
+ - Redesigned hashline syntax around range anchors (`A-B:`, `A:`, `BOF:`, `EOF:`) and per-line payload sigils (`|`, `↑`, `↓`). Old op-line insert syntax and `\` payload continuations are no longer supported.
190
+
191
+ ### Added
192
+
193
+ - Added `parsePatchStreaming(diff)` and `PatchSection.applyPartialTo(text, options)` for incremental diff previews. Both tolerate a trailing in-flight op (no payload yet, or a per-token parse error mid-stream) instead of throwing or emitting a phantom empty-payload edit.
194
+ - Added `Executor.endStreaming()` — sibling of `end()` that drops a pending op with no accumulated payload rather than flushing it.
195
+
196
+ ### Fixed
197
+
198
+ - Parser now skips markdown-style `# ...` lines when they directly precede a hashline operation, making model-generated explanatory rows in prompt examples non-blocking.
199
+
200
+ ### Removed
201
+
202
+ - Removed legacy deletion semantics that treated bare `A-B:` as a blank-line replacement; a bare range anchor now deletes the range.
203
+
204
+ All notable changes to this package will be documented in this file.
205
+
206
+ ## [15.5.4] - 2026-05-27
207
+ ### Added
208
+
209
+ - Added a high-level `Patcher` API with all-or-nothing `apply` and staged `prepare`/`commit` flows for multi-file patch updates
210
+ - Added pluggable `Filesystem` and `SnapshotStore` abstractions with built-in `NodeFilesystem`, `InMemoryFilesystem`, and `InMemorySnapshotStore` adapters
211
+ - Added patch parsing that consumes `¶PATH#HASH` hunk headers, validates section file hashes, and supports optional patch envelope markers
212
+ - Added tolerant input handling that strips read/search prefixes and supports optional `cwd`/fallback-path resolution when parsing patch payloads
213
+ - Added automatic line-ending and BOM normalization on read, with original encoding shape restored on write
214
+ - Added follow-up helpers `buildCompactDiffPreview` and `streamHashLines` for compact diff previews and chunked streaming of numbered lines
215
+ - Added stale-file-hash recovery that replays edits against snapshots and merges results onto current file content when direct hash validation fails
216
+ - Initial standalone release. Extracted from `@oh-my-pi/pi-coding-agent`.
217
+
218
+ ### Fixed
219
+
220
+ - Fixed repeated patch application mutating cached `after_anchor` edits between target snapshots
221
+ - Fixed multi-section patching to preflight write policies and reject duplicate canonical targets before any section is committed
222
+ - Fixed mixed line-ending restoration to preserve the first newline style instead of rewriting ties to LF
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@oh-my-pi/hashline",
4
- "version": "15.11.4",
4
+ "version": "15.11.7",
5
5
  "description": "Hashline: a compact, line-anchored patch language and applier. Pluggable FS/IO so it works over disk, in-memory, or any custom backend.",
6
6
  "homepage": "https://omp.sh",
7
7
  "author": "Can Boluk",
@@ -44,6 +44,8 @@
44
44
  },
45
45
  "files": [
46
46
  "src",
47
+ "README.md",
48
+ "CHANGELOG.md",
47
49
  "dist/types"
48
50
  ],
49
51
  "exports": {
package/src/apply.ts CHANGED
@@ -35,26 +35,31 @@ function getEditAnchors(edit: AppliedEdit): Anchor[] {
35
35
  return getCursorAnchors(edit.cursor);
36
36
  }
37
37
 
38
+ function trailingPhantomLine(fileLines: readonly string[]): number {
39
+ // `split("\n")` on a newline-terminated file yields a trailing "" sentinel.
40
+ // It is addressable for inserts (append-past-end), but it is not real
41
+ // content. Deleting it only strips the file's final newline, so ignore delete
42
+ // edits that land there; inclusive ranges ending at EOF then do the intended
43
+ // thing and delete through the last concrete line.
44
+ return fileLines.length > 1 && fileLines[fileLines.length - 1] === "" ? fileLines.length : 0;
45
+ }
46
+
47
+ function dropTrailingPhantomDeletes(edits: AppliedEdit[], fileLines: readonly string[]): AppliedEdit[] {
48
+ const phantomLine = trailingPhantomLine(fileLines);
49
+ if (phantomLine === 0) return edits;
50
+ return edits.filter(edit => edit.kind !== "delete" || edit.anchor.line !== phantomLine);
51
+ }
52
+
38
53
  /**
39
54
  * Verify every anchored edit points at an existing line. File-version binding is
40
55
  * checked once per section via the header hash before this function runs.
41
56
  */
42
- function validateLineBounds(edits: AppliedEdit[], fileLines: string[]): void {
43
- // `split("\n")` on a newline-terminated file yields a trailing "" sentinel.
44
- // It is addressable for inserts (append-past-end), but deleting it would
45
- // silently strip the file's final newline — an off-by-one that must error.
46
- const phantomLine = fileLines.length > 1 && fileLines[fileLines.length - 1] === "" ? fileLines.length : 0;
57
+ function validateLineBounds(edits: readonly AppliedEdit[], fileLines: readonly string[]): void {
47
58
  for (const edit of edits) {
48
59
  for (const anchor of getEditAnchors(edit)) {
49
60
  if (anchor.line < 1 || anchor.line > fileLines.length) {
50
61
  throw new Error(`Line ${anchor.line} does not exist (file has ${fileLines.length} lines)`);
51
62
  }
52
- if (edit.kind === "delete" && anchor.line === phantomLine) {
53
- throw new Error(
54
- `Line ${anchor.line} is the trailing blank sentinel of a newline-terminated file and has no content to delete. ` +
55
- `End the range at line ${anchor.line - 1}, or use \`insert tail:\` to append.`,
56
- );
57
- }
58
63
  }
59
64
  }
60
65
  }
@@ -742,7 +747,10 @@ export function applyEdits(text: string, edits: readonly Edit[]): ApplyResult {
742
747
  if (firstChangedLine === undefined || line < firstChangedLine) firstChangedLine = line;
743
748
  };
744
749
 
745
- const targetEdits = appliedEdits.map((edit, index) => cloneAppliedEdit(edit, index));
750
+ const targetEdits = dropTrailingPhantomDeletes(
751
+ appliedEdits.map((edit, index) => cloneAppliedEdit(edit, index)),
752
+ fileLines,
753
+ );
746
754
  validateLineBounds(targetEdits, fileLines);
747
755
  const { edits: repaired, warnings: boundaryWarnings } = repairReplacementBoundaries(targetEdits, fileLines);
748
756
  const { edits: landed, warnings: landingWarnings } = repairAfterInsertLandings(repaired, fileLines);