pi-hashline-edit-pro 2.7.0 → 2.7.2

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.
package/README.md CHANGED
@@ -2,18 +2,18 @@
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/pi-hashline-edit-pro.svg)](https://www.npmjs.com/package/pi-hashline-edit-pro) [![npm downloads](https://img.shields.io/npm/dm/pi-hashline-edit-pro.svg)](https://www.npmjs.com/package/pi-hashline-edit-pro)
4
4
 
5
- Hash-anchored `read`, `replace`, `insert`, and `grep` tools for [pi-coding-agent](https://github.com/badlogic/pi-mono/tree/main/packages/coding-agent). Every line of a file gets a unique 3-character hash, and you edit by hash. There are no line numbers and no fuzzy matching, so edits land on the lines you meant.
5
+ Anchor-based `read`, `replace`, `insert`, and `grep` tools for [pi-coding-agent](https://github.com/badlogic/pi-mono/tree/main/packages/coding-agent). Every line of a file gets a unique 3-character anchor, and you edit by anchor. There are no line numbers and no fuzzy matching, so edits land on the lines you meant.
6
6
 
7
- Fork of [pi-hashline-edit](https://github.com/RimuruW/pi-hashline-edit) by RimuruW, extended with 3-character hashes and collision resolution.
7
+ Fork of [pi-hashline-edit](https://github.com/RimuruW/pi-hashline-edit) by RimuruW, extended with 3-character anchors and collision resolution.
8
8
 
9
9
  ## Features
10
10
 
11
- - `read` returns every line as `HASH│content`. The hash is the line's address.
12
- - `replace` targets a range of hashes, so edits land on the lines you meant.
13
- - `insert` adds lines after or before a line by hash: the anchor line is preserved and the new lines are applied literally, never deduplicated.
14
- - `grep` returns matching lines (and requested context) with `HASH│content` rows that are served like read output, so search results are immediately editable.
15
- - Editing one part of a file leaves the hashes of the rest unchanged, so anchors from an earlier read stay valid across edits.
16
- - After a `write` you get the new anchors. After a `replace` or `insert` you get the diff with the new hashes.
11
+ - `read` returns every line as `anchor│content`. The anchor is the line's address.
12
+ - `replace` targets a range of anchors, so edits land on the lines you meant.
13
+ - `insert` adds lines after or before a line by anchor: the anchor line is preserved and the new lines are applied literally, never deduplicated.
14
+ - `grep` returns matching lines (and requested context) with `anchor│content` rows that are served like read output, so search results are immediately editable.
15
+ - Editing one part of a file leaves the anchors of the rest unchanged, so anchors from an earlier read stay valid across edits.
16
+ - After a `write` you get the new anchors. After a `replace` or `insert` you get the diff with the new anchors.
17
17
  - The most recent replace or insert on a file can be reverted, even after a restart.
18
18
  - Permissions, line endings, BOMs, symlinks, and hard links survive every edit.
19
19
 
@@ -27,7 +27,7 @@ szJ│ console.log("world");
27
27
  kQm│}
28
28
  ```
29
29
 
30
- 2. Replace a line by its hash:
30
+ 2. Replace a line by its anchor:
31
31
 
32
32
  ```json
33
33
  {
@@ -54,7 +54,7 @@ pi install /path/to/pi-hashline-edit-pro
54
54
 
55
55
  ## The read tool
56
56
 
57
- `read` returns a text file with every line prefixed by `HASH│content`. The hash is 3 characters from `A-Za-z0-9` (for example `aB3`).
57
+ `read` returns a text file with every line prefixed by `anchor│content`. The anchor is 3 characters from `A-Za-z0-9` (for example `aB3`).
58
58
 
59
59
  | Parameter | Description |
60
60
  | --- | --- |
@@ -63,20 +63,20 @@ pi install /path/to/pi-hashline-edit-pro
63
63
 
64
64
  Paged output ends with a continuation hint, for example `[Showing lines 1-50 of 120. Use offset=51 to continue.]`.
65
65
 
66
- Lines up to 200KB are shown in full. Larger lines are replaced by a marker with a bash inspection hint (`sed -n 'Np' <path> | head -c 204800`), because hash anchors need full lines.
66
+ Lines up to 50KB are shown in full. A larger line is replaced by a marker that keeps the line's anchor: `anchor│[Line N is 2.2MB, exceeds 50KB; content not shown. Use bash: sed -n 'Np' <path> | head -c 51200]`. The marker is served like a normal row, so the whole line can still be replaced via that anchor; `grep` shows an anchored fragment around a match on such a line instead.
67
67
 
68
68
  Edge cases:
69
69
 
70
70
  - Images (JPEG, PNG, GIF, WebP, BMP) come back as visual attachments. Other image formats (for example AVIF, HEIC/HEIF, TIFF, ICO, JPEG 2000, JPEG XL, PSD, APNG) are rejected as binary, since the built-in renderer cannot attach them.
71
71
  - Binary files and directories are rejected with a descriptive error. A magic-signature match is ignored when the sampled bytes contain no NUL bytes and decode as UTF-8, so a text file whose first bytes happen to match a binary or image signature (for example starting with `BM` or `8BPS`) is still read as text. The NUL-byte check covers the whole file, not just the sampled bytes: a file with a NUL byte anywhere is rejected as binary.
72
72
  - UTF-16 and UTF-32 text (detected via BOM) is rejected, since editing it would corrupt the file.
73
- - Empty files come back as a single empty-line hash (`HASH│`); use `replace` on that hash to insert content.
73
+ - Empty files come back as a single empty-line anchor (`anchor│`); use `replace` on that anchor to insert content.
74
74
  - BOMs are stripped for display. Non-UTF-8 bytes are shown as `U+FFFD`; editing such a file rewrites it as UTF-8, with a warning.
75
75
  - Files over 238,328 lines or 100MB are rejected with `[E_FILE_TOO_LARGE]`.
76
76
 
77
77
  ## The replace tool
78
78
 
79
- The built-in `edit` tool is disabled. `replace` and `insert` are the only edit paths, and both take the hash anchors from `read` output.
79
+ The built-in `edit` tool is disabled. `replace` and `insert` are the only edit paths, and both take the anchors from `read` output.
80
80
 
81
81
  One edit per call, with `remove_from`, `remove_to`, and `replacement_lines` at the top level:
82
82
 
@@ -91,17 +91,17 @@ One edit per call, with `remove_from`, `remove_to`, and `replacement_lines` at t
91
91
 
92
92
  | Field | Description |
93
93
  | --- | --- |
94
- | `remove_from` | 3-char hash from `read` output marking the FIRST line to remove (inclusive). |
95
- | `remove_to` | 3-char hash from `read` output marking the LAST line to remove (inclusive). |
94
+ | `remove_from` | 3-char anchor from `read` output marking the FIRST line to remove (inclusive). |
95
+ | `remove_to` | 3-char anchor from `read` output marking the LAST line to remove (inclusive). |
96
96
  | `replacement_lines` | Replacement lines as an array of strings, one element per line. Mirror the removed lines exactly, blank lines included: use `[]` to delete the range, `[""]` for a single blank line, `["a", ""]` for a line followed by a blank line, and `["", ""]` for two blank lines. Do not embed `\n` inside an element: each element is exactly one line. |
97
97
 
98
98
  Notes:
99
99
 
100
100
  - The request is checked before any file I/O, so a bad request never touches the file.
101
- - Common copy-paste slips are fixed automatically and reported: a leftover `HASH│` prefix (including a truncated or expanded prefix of up to 6 characters, e.g. `L3│` or `ab12│`) in `replacement_lines` or `remove_from`/`remove_to`, diff-preview rows pasted into the replacement, a reversed range, or a boundary line pasted twice. New lines that re-include a block adjacent to the range are stripped automatically when that block is unique in the file. The whole run is stripped as one unit (including repeated structural lines like `}`), so re-including an unchanged block next to the range never duplicates it. A missing `path` is resolved from the anchors when they uniquely identify a file in the hash store (reported as a warning); when the anchors match multiple known files the request is rejected with the candidate paths named. `file_path` works as an alias for `path` in all three tools.
102
- - An edit that produces identical content reports `No changes made` and leaves the anchors alone. When such a noop happened because a boundary anti-duplication cut removed lines from the replacement (the cut blocked a line that duplicates the block next to the range from being added), the same replacement sent once more runs with the edge anti-duplication turned off for that single call and is applied literally. The duplicated lines are kept, and the result carries a `[E_BOUNDARY_BYPASS]` notice. The pending bypass is per file and keyed to that payload; copied `HASH│` prefixes, diff markers, and stray whitespace in the resend are normalized before matching, so a copy-paste resend still hits it. Any applied edit clears it, and a successful `write` also clears it.
103
- - Every line in the removed range must match what was last shown to you. The extension records the `HASH│content` rows it serves (`read` output, the auto-read block after `write`, the `+HASH│`/` HASH│` rows of post-edit diffs (replace, insert, and undo), the current-range rows of `[E_RANGE_STALE]` feedback, and the context rows of stale/ambiguous-anchor feedback) and verifies the whole range against that record before writing. If an interior line changed on disk since it was shown (external editor, formatter-on-save, code generation) or was never shown, the edit is refused with `[E_RANGE_STALE]` and the current range is returned with fresh anchors, so the retry needs no `read`. Edits outside the served record are only possible for files that were never read (for example right after a `write` with auto-read disabled); once the file has been served, every replaced line must have been shown.
104
- - After a successful edit you get the post-edit diff with fresh anchors, so you can keep editing without re-reading.
101
+ - Common copy-paste slips are fixed automatically and reported: a leftover `anchor│` prefix (including a truncated or expanded prefix of up to 6 characters, e.g. `L3│` or `ab12│`) in `replacement_lines` or `remove_from`/`remove_to`, diff-preview rows pasted into the replacement, a reversed range, or a boundary line pasted twice. New lines that re-include a block adjacent to the range are stripped automatically when that block is unique in the file. The whole run is stripped as one unit (including repeated structural lines like `}`), so re-including an unchanged block next to the range never duplicates it. A missing `path` is resolved from the anchors when they uniquely identify a file in the hash store (reported as a warning); when the anchors match multiple known files the request is rejected with the candidate paths named. `file_path` works as an alias for `path` in all five tools.
102
+ - An edit that produces identical content reports `No changes made` and leaves the anchors alone. When such a noop happened because a boundary anti-duplication cut removed lines from the replacement (the cut blocked a line that duplicates the block next to the range from being added), the same replacement sent once more runs with the edge anti-duplication turned off for that single call and is applied literally. The duplicated lines are kept, and the result carries a `[E_BOUNDARY_BYPASS]` notice. The pending bypass is per file and keyed to that payload; copied `anchor│` prefixes, diff markers, and stray whitespace in the resend are normalized before matching, so a copy-paste resend still hits it. Any applied edit clears it, and a successful `write` also clears it.
103
+ - Every line in the removed range must match what was last shown to you. The extension records the `anchor│content` rows it serves (`read` output, the auto-read block after `write`, the `+anchor│`/` anchor│` rows of post-edit diffs (replace, insert, and undo), the current-range rows of `[E_RANGE_STALE]` feedback, and the context rows of stale/ambiguous-anchor feedback) and verifies the whole range against that record before writing. If an interior line changed on disk since it was shown (external editor, formatter-on-save, code generation) or was never shown, the edit is refused with `[E_RANGE_STALE]` and the current range is returned with fresh anchors, so the retry needs no `read`. Edits outside the served record are only possible for files that were never read (for example right after a `write` with auto-read disabled); once the file has been served, every replaced line must have been shown.
104
+ - After a successful edit you get the post-edit diff with fresh anchors, so you can keep editing without re-reading. The diff is capped at 50KB: a row longer than 50KB is shown as a marker that keeps the row's anchor (so the line stays editable via the diff), and when the total cap is hit the diff ends with a truncation note. Only the rows shown in the capped diff are recorded as served. The same caps apply to the `insert` and `undo_last_change` diffs, to the interactive previews, and to `details.patch` (which is flagged with `details.patchTruncated` when it was cut and can no longer be applied as-is).
105
105
  - Do not issue multiple replace or insert calls on the same file in one message; parallel edits split attention across the post-edit diffs and removed lines are easy to miss. Verify each diff before the next edit on that file.
106
106
 
107
107
  ## The insert tool
@@ -119,7 +119,7 @@ Notes:
119
119
 
120
120
  | Field | Description |
121
121
  | --- | --- |
122
- | `anchor` | 3-char hash from `read` output marking the line next to which the lines go (inclusive; the line is preserved). A pasted diff row like `+aB3│x` or a `HASH│` prefix is stripped automatically with a warning. |
122
+ | `anchor` | 3-char anchor from `read` output marking the line next to which the lines go (inclusive; the line is preserved). A pasted diff row like `+aB3│x` or an `anchor│` prefix is stripped automatically with a warning. |
123
123
  | `direction` | `"after"` to insert below the anchor line, `"before"` to insert above it. |
124
124
  | `lines` | Lines to insert as an array of strings, one element per line. Mirror `replacement_lines` semantics: use `[""]` for a blank line and do not embed `\n` inside an element. The anchor line is never part of `lines`. |
125
125
 
@@ -127,13 +127,13 @@ Notes:
127
127
 
128
128
  - The anchor line must have been shown to you (read output, a post-edit diff row, grep output, or stale-range feedback). The same verification as `replace` applies: a stale or unshown anchor is rejected with `[E_STALE_ANCHOR]`, `[E_AMBIGUOUS_ANCHOR]`, or `[E_RANGE_STALE]` and the retry needs no `read`.
129
129
  - Lines are applied literally: nothing is removed, and a line that duplicates its neighbor is kept. `replace`'s boundary anti-duplication never runs for `insert`.
130
- - To seed an empty file, read it and insert after the `HASH│` empty-line row.
130
+ - To seed an empty file, read it and insert after the `anchor│` empty-line row.
131
131
  - The same safety machinery as `replace` applies: undo is saved before the write (a failed write restores the previous undo record), line endings and BOMs survive, and an applied insert clears a pending boundary bypass.
132
132
  - Inserting nothing (`lines: []`) reports a noop and leaves the file unchanged; inserted lines are never deduplicated.
133
133
 
134
134
  ## The grep tool
135
135
 
136
- `grep` replaces the built-in grep with a hash-anchored search. Every matching line (and each requested context line) is returned as a `HASH│content` row, and those rows are recorded in the served state exactly like `read` output, so you can target them with `replace` or `insert` immediately without a separate `read`.
136
+ `grep` replaces the built-in grep with an anchored search. Every matching line (and each requested context line) is returned as an `anchor│content` row, and those rows are recorded in the served state exactly like `read` output, so you can target them with `replace` or `insert` immediately without a separate `read`.
137
137
 
138
138
  | Field | Description |
139
139
  | --- | --- |
@@ -148,7 +148,7 @@ Notes:
148
148
  Notes:
149
149
  - Results are grouped per file under a `=== path ===` header; every shown row carries the anchor it would have in `read` output.
150
150
  - Directory searches skip `node_modules`, `.git`, `.tmp`, and `coverage`. Binary, image, and oversized files are skipped silently.
151
- - Output is capped at `limit` matched lines and 2000 rows, with a hint when the cap cut results. Directory scans stop after 4000 files with a hint; results may be incomplete.
151
+ - Output is capped at `limit` matched lines, 2000 rows, and 50KB of text (whichever comes first), with a hint naming the cap that cut results. A matched line longer than 500 bytes is shown as a fragment around the match with `...` marking the truncated sides, so the relevant part of the hit stays visible; a context line over 500 bytes is shown as its head with a trailing `...`. Fragments keep the line's anchor (long lines are hashed from their first 500 bytes) and are served like full rows, so a fragmented match is still editable with `replace` (which always replaces the whole line). Directory scans stop after 4000 files with a hint; results may be incomplete.
152
152
  - `file_path` works as an alias for `path`.
153
153
  - Line endings and BOMs survive every edit. The file's line ending is detected from its first newline and restored on write; a file that mixes LF and CRLF (for example a WSL-edited file) is normalized to the first-seen ending.
154
154
  - Files with multiple hard links (`nlink > 1`) are rewritten in place rather than via a temp-file rename, so every link keeps seeing the same content; that write is direct rather than atomic.
@@ -161,14 +161,16 @@ Notes:
161
161
  - History is persisted and survives session restarts. A failed `write` does not clear it.
162
162
  - Every applied replace or insert is undoable: the undo record is saved before the edit is written.
163
163
  - A successful `write` clears the history for that file.
164
- - If the file was modified or deleted since the last replace or insert, the undo is refused rather than overwriting those changes.
164
+ - If the file was modified since the last replace or insert, the undo is refused rather than overwriting those changes. The undo record is kept: once the file matches the edited state again (for example you revert the external change), `undo_last_change` succeeds.
165
+ - If the file was deleted since the last replace or insert, `undo_last_change` restores it from the recorded pre-edit content. Nothing is overwritten, since the file no longer exists.
166
+ - Missing-file cleanup never touches the undo record: the per-session prune of the hash store removes the snapshots and served records of files that no longer exist (both are recomputed on the next read), but the undo history survives — even when the file is temporarily absent, for example during a branch switch.
165
167
 
166
168
  ## Auto-read
167
169
 
168
- Enabled by default. After a successful `write` that changes the file, the extension reads the file and appends an `--- Auto-read (hashline anchors) ---` block to the result, so you get fresh `HASH│content` anchors without a separate `read` call.
170
+ Enabled by default. After a successful `write`, the extension reads the file and appends an `--- Auto-read (hashline anchors) ---` block to the result, so you get fresh `anchor│content` anchors without a separate `read` call.
169
171
 
170
- - After `replace`, `insert`, and `undo_last_change`, the result shows the post-edit diff. The `+HASH│` and ` HASH│` rows carry the current hashes, so follow-up edits can anchor on the diff directly. The `-HASH│` rows show removed lines with their old hashes, so you can see exactly which anchors were deleted (those hashes are stale after the edit). When the context line touching a change is blank or whitespace-only, one more context line is shown in that direction, so the change stays anchored to visible content. Call `read` when you want the full file's anchors.
171
- - Auto-read keeps a 50KB display budget. Lines over 50KB are skipped with a marker instead of their content (use `read` for lines up to 200KB).
172
+ - After `replace`, `insert`, and `undo_last_change`, the result shows the post-edit diff. The `+anchor│` and ` anchor│` rows carry the current anchors, so follow-up edits can anchor on the diff directly. The `-anchor│` rows show removed lines with their old anchors, so you can see exactly which anchors were deleted (those anchors are stale after the edit). When the context line touching a change is blank or whitespace-only, one more context line is shown in that direction, so the change stays anchored to visible content. Call `read` when you want the full file's anchors.
173
+ - Auto-read keeps the same 50KB / 2000-line budget as `read`. Lines over 50KB are shown as markers that keep the line's anchor (use `grep` for a fragment around a match).
172
174
  - Toggle at runtime with `/toggle-auto-read`; the setting persists across sessions.
173
175
 
174
176
  ## Tool result details
@@ -176,9 +178,9 @@ Enabled by default. After a successful `write` that changes the file, the extens
176
178
  All five tools return machine-readable metadata in `details` alongside the model-visible text:
177
179
 
178
180
  - `read`: `details.truncation` (set when the output was truncated), `details.snapshotId` (a `v2|path|ino|mtime|ctime|size` fingerprint of the file), `details.nextOffset` (use as the next `offset`), and `details.metrics` with `truncated` and `next_offset`.
179
- - `replace` and `insert`: `details.diff` (the post-edit diff; `+HASH│` and ` HASH│` rows carry the current anchors), `details.patch` (a standard unified patch of the changes, for external tools), `details.firstChangedLine`, `details.snapshotId`, `details.classification` (`"noop"` when nothing changed), and `details.metrics`: `edits_attempted`, `edits_noop`, `warnings`, `classification` (`"applied"` or `"noop"`), `changed_lines` (`{ first, last }`), `added_lines`, `removed_lines`.
180
- - `undo_last_change`: `details.diff` (the undo diff with the restored anchors), `details.patch` (a standard unified patch of the restored changes), and `details.metrics` (same shape as `replace`).
181
- - `grep`: `details.metrics` with `matches`, `files`, and `truncated`.
181
+ - `replace` and `insert`: `details.diff` (the post-edit diff, capped at 50KB with markers for oversized rows; `+HASH│` and ` HASH│` rows carry the current anchors), `details.patch` (a standard unified patch of the changes, for external tools, capped at 50KB like the diff), `details.patchTruncated` (true when the patch was cut to fit the cap and cannot be applied as-is), `details.firstChangedLine`, `details.snapshotId`, `details.classification` (`"noop"` when nothing changed), and `details.metrics`: `edits_attempted`, `edits_noop`, `warnings`, `classification` (`"applied"` or `"noop"`), `changed_lines` (`{ first, last }`), `added_lines`, `removed_lines`.
182
+ - `undo_last_change`: `details.diff` (the undo diff with the restored anchors), `details.patch` (a standard unified patch of the restored changes, capped at 50KB like `replace`), `details.patchTruncated` (true when the patch was cut), and `details.metrics` (same shape as `replace`).
183
+ - `grep`: `details.metrics` with `matches` (matched lines found, capped at `limit`), `files`, and `truncated` (true when the row, byte, file-scan, or `limit` cap cut the results), plus `details.truncation` (the standard pi truncation report — `truncatedBy`, `totalLines`, `outputLines`, `maxLines`, `maxBytes`, … — when the output was cut) and `details.linesTruncated` (true when long lines were shown as fragments).
182
184
 
183
185
  ## Settings
184
186
 
@@ -196,7 +198,7 @@ Settings live in `~/.config/pi-hashline-edit-pro/config.json`, created automatic
196
198
 
197
199
  ## How anchors work
198
200
 
199
- Each line is canonicalized (carriage returns stripped, trailing whitespace trimmed) and hashed with [xxhash-wasm](https://github.com/jungomi/xxhash-wasm) (xxHash32), then mapped to a 3-character string over `A-Za-z0-9`, which gives 62³ = 238,328 possible anchors. The canonicalization keeps anchors stable across editor-save cycles that add or remove trailing whitespace.
201
+ Each line is canonicalized (carriage returns stripped, trailing whitespace trimmed) and hashed with [xxhash-wasm](https://github.com/jungomi/xxhash-wasm) (xxHash32), then mapped to a 3-character string over `A-Za-z0-9`, which gives 62³ = 238,328 possible anchors. The canonicalization keeps anchors stable across editor-save cycles that add or remove trailing whitespace. A line longer than 500 bytes is hashed from its first 500 bytes; uniqueness is still guaranteed by the collision-resolution below.
200
202
 
201
203
  The alphabet is sized for an LLM consumer: the model reads the hashes as tokens rather than inspecting glyph shapes, so letters and digits are all included. The URL-safe specials `-` and `_` are deliberately excluded. A hash starting with `-` looks like a diff-preview deletion row, and `-`/`_` at the start of a line are markdown-active, which invites mis-copying and false autocorrections.
202
204
 
@@ -218,17 +220,17 @@ A no-op replace never changes the file, so anchors remain valid. On first run af
218
220
  | Code | Meaning |
219
221
  | --- | --- |
220
222
  | `[E_BAD_SHAPE]` | Request envelope or edit item has unknown, missing, or wrongly-typed fields (for example `replacement_lines` must be an array of strings, one element per line). |
221
- | `[E_BAD_REF]` | An anchor in `remove_from`/`remove_to` is not a bare 3-char hash. |
223
+ | `[E_BAD_REF]` | An anchor in `remove_from`/`remove_to` is not a bare 3-char anchor. |
222
224
  | `[E_STALE_ANCHOR]` | An anchor does not match any line in the current file; call `read` for fresh anchors. |
223
225
  | `[E_AMBIGUOUS_ANCHOR]` | An anchor matches multiple lines; call `read` for fresh anchors. |
224
- | `[E_INVALID_PATCH]` | A `replacement_lines` element is a diff-preview row (`+HASH│`, `-HASH│`, `- │`). The marker is stripped automatically with a warning. |
225
- | `[E_BARE_HASH_PREFIX]` | A `replacement_lines` element starts with a hash-like `HASH│` prefix. The prefix is stripped automatically with a warning. |
226
+ | `[E_INVALID_PATCH]` | A `replacement_lines` element is a diff-preview row (`+anchor│`, `-anchor│`, `- │`). The marker is stripped automatically with a warning. |
227
+ | `[E_BARE_HASH_PREFIX]` | A `replacement_lines` element starts with an `anchor│` prefix (the anchor plus the separator). The prefix is stripped automatically with a warning. |
226
228
  | `[E_BAD_OP]` | Range start line is after range end line. The pair is swapped automatically with a warning. |
227
229
  | `[E_WOULD_EMPTY]` | An edit would empty a non-empty file; use `write` instead. |
228
230
  | `[E_NOT_FOUND]` | The path does not exist. |
229
231
  | `[E_ACCESS]` | The file is not readable or writable. |
230
232
  | `[E_NOT_TEXT]` | The path is a directory, binary file, image, or UTF-16/UTF-32 encoded text; hashline editing only supports text files. |
231
- | `[E_UNDO_STALE]` | `undo_last_change` refused: the file was modified or deleted after the last edit. |
233
+ | `[E_UNDO_STALE]` | `undo_last_change` refused: the file was modified after the last edit. The undo record is kept until the file matches the edited state again or a new edit replaces it. |
232
234
  | `[E_UNDO_UNAVAILABLE]` | Undo history could not be persisted to the hash store; the edit was refused and the file was left unchanged. |
233
235
  | `[E_RANGE_STALE]` | A line in the replaced range no longer matches what was last shown (the file changed on disk, or the line was never shown). The edit was refused; the current range is returned with fresh anchors. |
234
236
  | `[E_BOUNDARY_BYPASS]` | The boundary anti-duplication was turned off for one replace call (an identical replacement had previously been cut to a noop); the duplicate lines were applied literally. The dedup is restored for the next call. |
package/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
- import { DEFAULT_MAX_BYTES } from "@earendil-works/pi-coding-agent";
2
+ import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES } from "@earendil-works/pi-coding-agent";
3
3
  import { initHasher } from "./src/hashline";
4
4
  import { regReplace } from "./src/replace";
5
5
  import { regInsert } from "./src/insert";
@@ -9,7 +9,6 @@ import { regRead, fmtReadPreview } from "./src/read";
9
9
  import type { RMetrics } from "./src/replace-response";
10
10
  import { extractWarnings } from "./src/replace-render";
11
11
  import { MAX_HASH_LINES } from "./src/hashline";
12
- import { AUTO_READ_MAX } from "./src/constants";
13
12
  import {
14
13
  readConfig,
15
14
  toggleAutoRead,
@@ -65,13 +64,14 @@ export default function (pi: ExtensionAPI): void {
65
64
 
66
65
  if (event.toolName === "write") {
67
66
  const writtenPath = (event.input as Record<string, unknown>)?.path;
67
+ let resolvedPath: string | undefined;
68
68
  if (typeof writtenPath === "string") {
69
69
  try {
70
- const target = await resolveTarget(toCwd(writtenPath, ctx.cwd));
71
- await clearUndo(target);
72
- clearBoundaryBypass(target);
70
+ resolvedPath = await resolveTarget(toCwd(writtenPath, ctx.cwd));
71
+ await clearUndo(resolvedPath);
72
+ clearBoundaryBypass(resolvedPath);
73
73
  const store = await loadHashStore();
74
- clearServed(store, target);
74
+ clearServed(store, resolvedPath);
75
75
  } catch (error) {
76
76
  console.error("Failed to clear undo after write:", error);
77
77
  }
@@ -79,7 +79,7 @@ export default function (pi: ExtensionAPI): void {
79
79
  if (!autoRead) return;
80
80
  if (typeof writtenPath !== "string") return;
81
81
  try {
82
- const resolvedPath = await resolveTarget(toCwd(writtenPath, ctx.cwd));
82
+ resolvedPath ??= await resolveTarget(toCwd(writtenPath, ctx.cwd));
83
83
  await valAccess(resolvedPath, writtenPath);
84
84
  const file = await loadFileKindAndText(resolvedPath, { maxLines: MAX_HASH_LINES, displayPath: writtenPath });
85
85
  if (file.kind !== "text") return;
@@ -92,7 +92,7 @@ export default function (pi: ExtensionAPI): void {
92
92
  fileHashes,
93
93
  absolutePath,
94
94
  DEFAULT_MAX_BYTES,
95
- AUTO_READ_MAX,
95
+ DEFAULT_MAX_LINES,
96
96
  );
97
97
  await recordServedSafe(absolutePath, preview.servedHashes, "auto-read", new Set(fileHashes));
98
98
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-hashline-edit-pro",
3
- "version": "2.7.0",
3
+ "version": "2.7.2",
4
4
  "type": "module",
5
5
  "description": "Hash-anchored read/replace/insert/grep tools for pi-coding-agent. Every line gets a unique 3-char hash (A-Za-z0-9) that stays stable across edits; stale or ambiguous anchors are rejected, never fuzzy-matched. Undo persists across restarts.",
6
6
  "main": "index.ts",
@@ -1,6 +1,7 @@
1
- - `grep`: results carry `HASH│` anchors recorded like read output, so you can target them with replace or insert immediately.
1
+ - `grep`: results carry anchors recorded like read output, so you can target them with replace or insert immediately.
2
2
  - `grep`: pass `path` for a single file or directory; the default is the current working directory. Directory searches skip node_modules, .git, .tmp, and coverage.
3
3
  - `grep`: use `literal: true` when the pattern contains regex metacharacters you want matched literally.
4
4
  - `grep`: use `context` to see surrounding lines; context rows carry anchors too.
5
5
  - `grep`: use `glob` to filter files; `*` matches across directories, e.g. `*.ts` or `**/*.spec.ts`.
6
- - `grep`: results are capped at `limit` matches (default 100) and 2000 rows; refine the pattern or raise limit to see more.
6
+ - `grep`: results are capped at `limit` matches (default 100), 2000 rows, and 50KB; refine the pattern or raise limit to see more.
7
+ - `grep`: a matched line longer than 500 bytes is shown as a fragment around the match with `...` marking the truncated sides; the row keeps its anchor and is editable with replace (which replaces the whole line). Use read to see the full line.
@@ -1 +1 @@
1
- Search file contents; matching lines carry HASH│ anchors usable in replace/insert without a re-read
1
+ Search file contents; matching lines carry anchors usable in replace/insert without a re-read
package/prompts/grep.md CHANGED
@@ -1 +1 @@
1
- Search text files for a pattern. Returns every matching line (and the requested context lines) as `HASH│content` rows, so the results can be used directly as replace and insert anchors without a separate read. Directory searches skip node_modules, .git, .tmp, and coverage. Binary, image, and oversized files are skipped silently.
1
+ Search text files for a pattern. Returns every matching line (and the requested context lines) as `anchor│content` rows, so the results can be used directly as replace and insert anchors without a separate read. Directory searches skip node_modules, .git, .tmp, and coverage. Binary, image, and oversized files are skipped silently. Output is capped at `limit` matches (default 100), 2000 rows, and 50KB; a matched line longer than 500 bytes is shown as a fragment around the match with `...` marking the truncated sides, and the row keeps its anchor (long lines are hashed from their first 500 bytes), so the match is still editable.
@@ -1,6 +1,7 @@
1
- - `insert`: anchor takes ONLY the bare 3-char hash of the line next to which the new lines go: read row `ve7│function hello() {` means `"anchor": "ve7"`. Never paste the line content or the whole `HASH│content` row.
1
+ - `insert`: anchor takes ONLY the bare 3-char anchor of the line next to which the new lines go: read row `ve7│function hello() {` means `"anchor": "ve7"`. Never paste the line content or the whole `anchor│content` row.
2
2
  - `insert`: the anchor line is preserved. Include only the new lines in `lines`, never the anchor line itself.
3
3
  - `insert`: use `direction: "after"` to add lines after the anchor line, `"before"` to add them before it.
4
4
  - `insert`: read the file first, so the anchor line was shown to you. Use a post-edit diff row or grep output for follow-up inserts.
5
- - `insert`: to seed an empty file, read it and insert after the `HASH│` empty-line row.
5
+ - `insert`: to seed an empty file, read it and insert after the `anchor│` empty-line row.
6
6
  - `insert`: lines are applied literally — never deduplicated — so restating a neighbor is safe and has no effect on the result.
7
+ - `insert`: the post-edit diff is capped at 50KB; a row longer than 50KB is shown as a marker that keeps the row's anchor, and the diff ends with a truncation note when the cap is hit, so call read for content the diff did not show.
@@ -1 +1 @@
1
- Insert lines after or before a line in a text file via bare 3-char HASH anchor from read: the anchor line stays, new lines go after/before it, applied literally
1
+ Insert lines after or before a line in a text file via bare 3-char anchor from read: the anchor line stays, new lines go after/before it, applied literally
package/prompts/insert.md CHANGED
@@ -1 +1 @@
1
- Insert lines after or before an existing line in a text file, targeted by the 3-char HASH anchors from read output. The anchor line is preserved; the new lines are added after it (direction "after") or before it (direction "before"). Each element of lines is exactly one line; do not embed \n inside an element: use separate elements. Use [""] for a blank line. The lines you send are added literally: nothing is removed, and lines that duplicate their neighbors are kept.
1
+ Insert lines after or before an existing line in a text file, targeted by 3-character anchors from read output. The anchor line is preserved; the new lines are added after it (direction "after") or before it (direction "before"). Each element of lines is exactly one line; do not embed \n inside an element: use separate elements. Use [""] for a blank line. The lines you send are added literally: nothing is removed, and lines that duplicate their neighbors are kept. The post-edit diff is capped at 50KB: rows longer than 50KB are shown as markers that keep the row's anchor, and the diff ends with a truncation note when the cap is hit; call read for anything not shown.
@@ -1,2 +1,2 @@
1
- - `read`: call before `replace` when you need fresh HASH anchors for a file.
1
+ - `read`: call before `replace` when you need fresh anchors for a file.
2
2
  - `read`: call again after an edit when you need anchors you do not have. The post-edit diff after replace/insert and the anchored rows after grep already carry fresh anchors for the changed range.
@@ -1 +1 @@
1
- Read a file; each line returned as HASH│content
1
+ Read a file; each line returned as anchor│content
package/prompts/read.md CHANGED
@@ -1 +1 @@
1
- Read a text file; each line returned as HASH│content with a 3-char alphanumeric hash. No line numbers: use the HASH as the anchor in replace calls. Images → visual attachments; Binary/directory → rejected; UTF-16/UTF-32 (BOM) → rejected; empty → HASH│ (replace to insert); pageable with offset/limit; BOM stripped; non-UTF-8 shown as U+FFFD.
1
+ Read a text file; each line returned as `anchor│content` with a 3-character alphanumeric anchor. No line numbers: use the anchor in replace and insert calls. Images → visual attachments; Binary/directory → rejected; UTF-16/UTF-32 (BOM) → rejected; empty → anchor│ (replace to insert); pageable with offset/limit; BOM stripped; non-UTF-8 shown as U+FFFD.
@@ -1,8 +1,9 @@
1
- - `replace`: remove_from and remove_to take ONLY the bare 3-char hash: read row `ve7│function hello() {` means `"remove_from": "ve7"`. Never paste the line content, a code line, a paragraph, or the whole `HASH│content` row into these fields.
1
+ - `replace`: remove_from and remove_to take ONLY the bare 3-char anchor: read row `ve7│function hello() {` means `"remove_from": "ve7"`. Never paste the line content, a code line, a paragraph, or the whole `anchor│content` row into these fields.
2
2
  - `replace`: remove_from and remove_to mark the exact lines that are REMOVED, and replacement_lines is their complete replacement applied in order; nothing outside the range changes. Every line inside the range that is not reproduced byte-exact in replacement_lines is deleted from the file.
3
3
  - `replace`: keep the range as tight as the change: anchor only the first and last line that actually change, never a whole function, class, or import block when only part of it changes.
4
- - `replace`: to replace a single line, use the same hash for both remove_from and remove_to (e.g. remove_from: "<HASH>", remove_to: "<HASH>").
5
- - `replace`: when copying a line from read output, remove its HASH│ prefix and keep the leading whitespace exactly as shown.
4
+ - `replace`: to replace a single line, use the same anchor for both remove_from and remove_to (e.g. remove_from: "<ANCHOR>", remove_to: "<ANCHOR>").
5
+ - `replace`: when copying a line from read output, remove its `anchor│` prefix and keep the leading whitespace exactly as shown.
6
6
  - `replace`: replacement_lines is an array of strings, one element per line. Mirror the removed lines exactly, blank lines included: use `[]` to delete the range, `[""]` for a single blank line, `["a", ""]` for a line followed by a blank line, and `["", ""]` for two blank lines. Do not embed `\n` inside an element: each element is exactly one line.
7
- - `replace`: when auto-read shows the post-edit diff, its rows are the fresh anchors for the new file: `+HASH│` and ` HASH│` rows carry current hashes and unchanged lines keep their previous hashes, so you can anchor follow-up edits on the diff without re-reading.
7
+ - `replace`: when auto-read shows the post-edit diff, its rows are the fresh anchors for the new file: `+anchor│` and ` anchor│` rows carry current anchors and unchanged lines keep their previous anchors, so you can anchor follow-up edits on the diff without re-reading.
8
8
  - `replace`: do not issue multiple replace calls on the same file in one message. Issue the next edit only after verifying the previous diff.
9
+ - `replace`: the post-edit diff is capped at 50KB; a row longer than 50KB is shown as a marker that keeps the row's anchor, and the diff ends with a truncation note when the cap is hit, so call read for content the diff did not show.
@@ -1 +1 @@
1
- Replace lines in a text file via bare 3-char HASH anchors from read: hash only, never line content; anchor exactly the lines that change; one edit per tool call
1
+ Replace lines in a text file via bare 3-char anchors from read: anchor only, never line content; anchor exactly the lines that change; one edit per tool call
@@ -1 +1 @@
1
- Replace a range of lines (or a single line) in a text file, targeted by the 3-char HASH anchors from read output. remove_from and remove_to must each be a BARE 3-character hash: copy only the hash from the leftmost column of a read row (row `ve7│function hello() {` means `"remove_from": "ve7"`). Never pass the line content, a code line, or a paragraph into these fields.
1
+ Replace a range of lines (or a single line) in a text file, targeted by 3-character anchors from read output. remove_from and remove_to must each be a BARE anchor: copy only the anchor from the leftmost column of a read row (row `ve7│function hello() {` means `"remove_from": "ve7"`). Never pass the line content, a code line, or a paragraph into these fields. The post-edit diff is capped at 50KB: rows longer than 50KB are shown as markers that keep the row's anchor, and the diff ends with a truncation note when the cap is hit; call read for anything not shown.
@@ -1,2 +1,4 @@
1
- - `undo_last_change`: reverts only the most recent replace or insert on the file: any write to the file clears the undo history, so call it immediately after a bad edit. An edit is bad when its post-edit diff shows `-HASH│` rows for lines you meant to keep (a closing brace, import, or declaration).
2
- - `undo_last_change`: when auto-read shows the post-edit diff, its `+HASH│` and ` HASH│` rows are the fresh anchors for the restored file, so follow-up edits can anchor on the diff without re-reading.
1
+ - `undo_last_change`: reverts only the most recent replace or insert on the file: any write to the file clears the undo history, so call it immediately after a bad edit. An edit is bad when its post-edit diff shows `-anchor│` rows for lines you meant to keep (a closing brace, import, or declaration).
2
+ - `undo_last_change`: when auto-read shows the post-edit diff, its `+anchor│` and ` anchor│` rows are the fresh anchors for the restored file, so follow-up edits can anchor on the diff without re-reading.
3
+ - `undo_last_change`: if the file was deleted since the edit, the undo restores it from the recorded pre-edit content; if the file was modified since the edit, the undo is refused with `[E_UNDO_STALE]` and the record is kept, so reverting the external change makes the undo succeed.
4
+ - `undo_last_change`: the undo diff is capped at 50KB; a row longer than 50KB is shown as a marker that keeps the row's anchor, and the diff ends with a truncation note when the cap is hit, so call read for content the diff did not show.
@@ -1 +1 @@
1
- Undo the last change (replace or insert) on a file, reverting it to its previous state. Use when an edit produced incorrect results (e.g., wrong content, duplicated lines, broken syntax).
1
+ Undo the last change (replace or insert) on a file, reverting it to its previous state. Use when an edit produced incorrect results (e.g., wrong content, duplicated lines, broken syntax). If the file was deleted since the edit, the undo restores it from the recorded content. If the file was modified since the edit, the undo is refused and the record is kept until the file matches the edited state again. The undo diff is capped at 50KB: rows longer than 50KB are shown as markers that keep the row's anchor, and the diff ends with a truncation note when the cap is hit; call read for anything not shown.
@@ -1,6 +1,6 @@
1
1
  import { parseText } from "./hashline/parse";
2
2
  import { ANCHOR_ROW_RE } from "./hashline/resolve";
3
- import { HL_BARE_PREFIX_RE, HL_PREFIX_PLUS_RE, HL_PREFIX_MINUS_RE } from "./hashline/hash";
3
+ import { stripRowPrefix } from "./hashline/hash";
4
4
 
5
5
  function canonRef(ref: string): string {
6
6
  const trimmed = ref.trim();
@@ -9,15 +9,7 @@ function canonRef(ref: string): string {
9
9
  }
10
10
 
11
11
  function canonLines(lines: string[]): string[] {
12
- return parseText(lines).map((line) => {
13
- const bare = line.match(HL_BARE_PREFIX_RE);
14
- if (bare) return line.slice(bare[0].length);
15
- const plus = line.match(HL_PREFIX_PLUS_RE);
16
- if (plus) return line.slice(plus[0].length);
17
- const minus = line.match(HL_PREFIX_MINUS_RE);
18
- if (minus) return line.slice(minus[0].length);
19
- return line;
20
- });
12
+ return parseText(lines).map((line) => stripRowPrefix(line).text);
21
13
  }
22
14
 
23
15
  const boundaryBypassTracker = new Map<string, string>();
package/src/constants.ts CHANGED
@@ -1,8 +1,10 @@
1
- export const AUTO_READ_MAX = 2000;
2
1
  export const SNIFF_BYTES = 8192;
3
2
  export const MAX_BYTES = 100 * 1024 * 1024;
4
- export const MAX_READ_LINE_BYTES = 200 * 1024;
5
3
  export const MAX_RANGE_STALE_LINES = 100;
4
+ export const MAX_OVERSIZED_WARNING_LINES = 100;
5
+
6
+ export const MAX_HASH_SOURCE_BYTES = 500;
7
+ export const MAX_GREP_LINE_BYTES = 500;
6
8
 
7
9
  export const HASH_STORE_BUSY_TIMEOUT = 1000;
8
10
  export const HASH_STORE_VERSION = 5;