pi-hashline-edit-pro 2.7.1 → 2.8.0
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 +35 -34
- package/index.ts +11 -9
- package/package.json +2 -2
- package/prompts/grep-guidelines.md +3 -6
- package/prompts/grep-snippet.md +1 -1
- package/prompts/grep.md +1 -1
- package/prompts/insert-guidelines.md +3 -6
- package/prompts/insert-snippet.md +1 -1
- package/prompts/insert.md +1 -1
- package/prompts/read-guidelines.md +2 -2
- package/prompts/read-snippet.md +1 -1
- package/prompts/read.md +1 -1
- package/prompts/replace-guidelines.md +5 -8
- package/prompts/replace-snippet.md +1 -1
- package/prompts/replace.md +1 -1
- package/prompts/undo-last-change-guidelines.md +2 -3
- package/prompts/undo-last-change-snippet.md +1 -1
- package/prompts/undo-last-change.md +1 -1
- package/src/constants.ts +4 -2
- package/src/file-kind.ts +8 -6
- package/src/file-reader.ts +25 -11
- package/src/fs-write.ts +28 -2
- package/src/grep.ts +137 -43
- package/src/hash-store.ts +57 -17
- package/src/hashline/hash.ts +16 -9
- package/src/hashline/index.ts +1 -0
- package/src/hashline/parse.ts +17 -3
- package/src/hashline/resolve.ts +9 -8
- package/src/insert.ts +11 -16
- package/src/payload-contract.ts +102 -0
- package/src/read.ts +32 -11
- package/src/replace-diff.ts +108 -19
- package/src/replace-render.ts +47 -43
- package/src/replace-response.ts +4 -1
- package/src/replace-undo.ts +17 -12
- package/src/replace.ts +44 -106
- package/src/served.ts +26 -5
- package/src/utils.ts +71 -0
- package/src/write-hook.ts +59 -0
- package/src/replace-normalize.ts +0 -13
package/README.md
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/pi-hashline-edit-pro) [](https://www.npmjs.com/package/pi-hashline-edit-pro)
|
|
4
4
|
|
|
5
|
-
|
|
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
|
|
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 `
|
|
12
|
-
- `replace` targets a range of
|
|
13
|
-
- `insert` adds lines after or before a line by
|
|
14
|
-
- `grep` returns matching lines (and requested context) with `
|
|
15
|
-
- Editing one part of a file leaves the
|
|
16
|
-
- After a `write` you get the new anchors. After a `replace` or `insert` you get the diff with the new
|
|
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
|
|
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 `
|
|
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
|
|
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
|
|
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
|
|
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
|
|
95
|
-
| `remove_to` | 3-char
|
|
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 `
|
|
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 `
|
|
103
|
-
- Every line in the removed range must match what was last shown to you. The extension records the `
|
|
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
|
|
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,19 +127,19 @@ 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 `
|
|
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
|
|
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
|
| --- | --- |
|
|
140
140
|
| `pattern` | Search pattern (regex, or literal text when `literal` is true). |
|
|
141
141
|
| `path` | File or directory to search (default: the current working directory). |
|
|
142
|
-
| `glob` | Filter files by glob pattern; `*` matches across directories, e.g. `*.ts` or `**/*.spec.ts`. |
|
|
142
|
+
| `glob` | Filter files by glob pattern; `*` matches across directories, e.g. `*.ts` or `**/*.spec.ts`. A leading `/` is ignored, and the pattern may be relative to the search root or to the current directory. |
|
|
143
143
|
| `ignoreCase` | Case-insensitive search (default: false). |
|
|
144
144
|
| `literal` | Treat the pattern as literal text instead of a regex (default: false). |
|
|
145
145
|
| `context` | Lines of context before and after each match; context rows carry anchors too (default: 0). |
|
|
@@ -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
|
|
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.
|
|
@@ -167,10 +167,10 @@ Notes:
|
|
|
167
167
|
|
|
168
168
|
## Auto-read
|
|
169
169
|
|
|
170
|
-
Enabled by default. After a successful `write
|
|
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.
|
|
171
171
|
|
|
172
|
-
- After `replace`, `insert`, and `undo_last_change`, the result shows the post-edit diff. The `+
|
|
173
|
-
- Auto-read keeps
|
|
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).
|
|
174
174
|
- Toggle at runtime with `/toggle-auto-read`; the setting persists across sessions.
|
|
175
175
|
|
|
176
176
|
## Tool result details
|
|
@@ -178,9 +178,9 @@ Enabled by default. After a successful `write` that changes the file, the extens
|
|
|
178
178
|
All five tools return machine-readable metadata in `details` alongside the model-visible text:
|
|
179
179
|
|
|
180
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`.
|
|
181
|
-
- `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`.
|
|
182
|
-
- `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`).
|
|
183
|
-
- `grep`: `details.metrics` with `matches
|
|
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).
|
|
184
184
|
|
|
185
185
|
## Settings
|
|
186
186
|
|
|
@@ -198,7 +198,7 @@ Settings live in `~/.config/pi-hashline-edit-pro/config.json`, created automatic
|
|
|
198
198
|
|
|
199
199
|
## How anchors work
|
|
200
200
|
|
|
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.
|
|
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.
|
|
202
202
|
|
|
203
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.
|
|
204
204
|
|
|
@@ -220,11 +220,11 @@ A no-op replace never changes the file, so anchors remain valid. On first run af
|
|
|
220
220
|
| Code | Meaning |
|
|
221
221
|
| --- | --- |
|
|
222
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). |
|
|
223
|
-
| `[E_BAD_REF]` | An anchor in `remove_from`/`remove_to` is not a bare 3-char
|
|
223
|
+
| `[E_BAD_REF]` | An anchor in `remove_from`/`remove_to` is not a bare 3-char anchor. |
|
|
224
224
|
| `[E_STALE_ANCHOR]` | An anchor does not match any line in the current file; call `read` for fresh anchors. |
|
|
225
225
|
| `[E_AMBIGUOUS_ANCHOR]` | An anchor matches multiple lines; call `read` for fresh anchors. |
|
|
226
|
-
| `[E_INVALID_PATCH]` | A `replacement_lines` element is a diff-preview row (`+
|
|
227
|
-
| `[E_BARE_HASH_PREFIX]` | A `replacement_lines` element starts with
|
|
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. |
|
|
228
228
|
| `[E_BAD_OP]` | Range start line is after range end line. The pair is swapped automatically with a warning. |
|
|
229
229
|
| `[E_WOULD_EMPTY]` | An edit would empty a non-empty file; use `write` instead. |
|
|
230
230
|
| `[E_NOT_FOUND]` | The path does not exist. |
|
|
@@ -235,6 +235,7 @@ A no-op replace never changes the file, so anchors remain valid. On first run af
|
|
|
235
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. |
|
|
236
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. |
|
|
237
237
|
| `[E_FILE_TOO_LARGE]` | The file exceeds the 238,328-line hashline limit or the 100MB size limit. |
|
|
238
|
+
| `[E_WRITE_HASH_ECHO]` | A `write` `content` line begins with the exact `anchor│` served for this file at the same line. The write is refused, file byte-identical; retry with bare content (remove the copied anchors). |
|
|
238
239
|
|
|
239
240
|
## Troubleshooting
|
|
240
241
|
|
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,
|
|
@@ -17,10 +16,10 @@ import {
|
|
|
17
16
|
import { loadHashStore, pruneMissing } from "./src/hash-store";
|
|
18
17
|
import { recordServedSafe, clearServed } from "./src/served";
|
|
19
18
|
import { clearBoundaryBypass } from "./src/boundary-bypass";
|
|
19
|
+
import { registerWriteHook } from "./src/write-hook";
|
|
20
20
|
import { readNormFile } from "./src/file-reader";
|
|
21
21
|
import { loadFileKindAndText } from "./src/file-kind";
|
|
22
|
-
import {
|
|
23
|
-
import { resolveTarget } from "./src/fs-write";
|
|
22
|
+
import { resolveInCwd } from "./src/fs-write";
|
|
24
23
|
import { valAccess } from "./src/validation";
|
|
25
24
|
|
|
26
25
|
export default function (pi: ExtensionAPI): void {
|
|
@@ -30,6 +29,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
30
29
|
regInsert(pi);
|
|
31
30
|
regGrep(pi);
|
|
32
31
|
regUndo(pi);
|
|
32
|
+
registerWriteHook(pi);
|
|
33
33
|
|
|
34
34
|
let autoRead = true;
|
|
35
35
|
|
|
@@ -68,7 +68,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
68
68
|
let resolvedPath: string | undefined;
|
|
69
69
|
if (typeof writtenPath === "string") {
|
|
70
70
|
try {
|
|
71
|
-
resolvedPath = await
|
|
71
|
+
resolvedPath = (await resolveInCwd(writtenPath, ctx.cwd)).resolved;
|
|
72
72
|
await clearUndo(resolvedPath);
|
|
73
73
|
clearBoundaryBypass(resolvedPath);
|
|
74
74
|
const store = await loadHashStore();
|
|
@@ -80,7 +80,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
80
80
|
if (!autoRead) return;
|
|
81
81
|
if (typeof writtenPath !== "string") return;
|
|
82
82
|
try {
|
|
83
|
-
resolvedPath ??= await
|
|
83
|
+
resolvedPath ??= (await resolveInCwd(writtenPath, ctx.cwd)).resolved;
|
|
84
84
|
await valAccess(resolvedPath, writtenPath);
|
|
85
85
|
const file = await loadFileKindAndText(resolvedPath, { maxLines: MAX_HASH_LINES, displayPath: writtenPath });
|
|
86
86
|
if (file.kind !== "text") return;
|
|
@@ -93,7 +93,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
93
93
|
fileHashes,
|
|
94
94
|
absolutePath,
|
|
95
95
|
DEFAULT_MAX_BYTES,
|
|
96
|
-
|
|
96
|
+
DEFAULT_MAX_LINES,
|
|
97
97
|
);
|
|
98
98
|
await recordServedSafe(absolutePath, preview.servedHashes, "auto-read", new Set(fileHashes));
|
|
99
99
|
return {
|
|
@@ -125,7 +125,8 @@ export default function (pi: ExtensionAPI): void {
|
|
|
125
125
|
if (metrics?.classification === "noop") return;
|
|
126
126
|
|
|
127
127
|
const diff = (event.details as { diff?: string } | undefined)?.diff;
|
|
128
|
-
if (
|
|
128
|
+
if (typeof diff !== "string") return;
|
|
129
|
+
const hasDiff = diff.length > 0;
|
|
129
130
|
|
|
130
131
|
const rendered = (event.content ?? [])
|
|
131
132
|
.filter(
|
|
@@ -135,11 +136,12 @@ export default function (pi: ExtensionAPI): void {
|
|
|
135
136
|
.map((entry) => entry.text)
|
|
136
137
|
.join("\n");
|
|
137
138
|
const warnings = extractWarnings(rendered);
|
|
139
|
+
const hint = hasDiff ? (warnings ? `${diff}\n\n${warnings}` : diff) : warnings ? `[post-edit] applied successfully; the diff is empty (whitespace-only change).\n\n${warnings}` : "[post-edit] applied successfully; the diff is empty (whitespace-only change).";
|
|
138
140
|
return {
|
|
139
141
|
content: [
|
|
140
142
|
{
|
|
141
143
|
type: "text",
|
|
142
|
-
text:
|
|
144
|
+
text: hint,
|
|
143
145
|
},
|
|
144
146
|
],
|
|
145
147
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-hashline-edit-pro",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
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",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"xxhash-wasm": "^1.1.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@earendil-works/pi-coding-agent": ">=0.
|
|
48
|
+
"@earendil-works/pi-coding-agent": ">=0.84.0",
|
|
49
49
|
"@earendil-works/pi-tui": "*"
|
|
50
50
|
},
|
|
51
51
|
"engines": {
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
- `grep`:
|
|
2
|
-
- `grep`:
|
|
3
|
-
- `grep`:
|
|
4
|
-
- `grep`: use `context` to see surrounding lines; context rows carry anchors too.
|
|
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.
|
|
1
|
+
- `grep`: every hit and `context` line comes back as `anchor│content` — use that anchor directly for `replace`/`insert` without a new `read`.
|
|
2
|
+
- `grep`: use `path` for file or folder (default cwd), `glob` like `*.ts` to filter, `literal:true` for literal text, `context:N` for surrounding lines.
|
|
3
|
+
- `grep`: search skips `node_modules/.git/.tmp/coverage` and skips binary/image files.
|
package/prompts/grep-snippet.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Search
|
|
1
|
+
Search with `anchor│content` hits usable directly for `replace`/`insert`; use `literal`/`glob`/`context`
|
package/prompts/grep.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Search text files for a pattern.
|
|
1
|
+
Search text files for a pattern. Every hit and each `context` line is returned as `anchor│content` so you can use that anchor directly for `replace`/`insert` without a new `read`. Directory search skips `node_modules/.git/.tmp/coverage` and skips binary/image files. Matching lines longer than 500 bytes are shown as a fragment around the match with `...`, but the anchor is still valid for the whole line. If output says truncated, refine `pattern` or raise `limit` as hinted.
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
- `insert`: anchor
|
|
2
|
-
- `insert`:
|
|
3
|
-
- `insert`:
|
|
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.
|
|
6
|
-
- `insert`: lines are applied literally — never deduplicated — so restating a neighbor is safe and has no effect on the result.
|
|
1
|
+
- `insert`: `anchor` is bare `aB3` from `aB3│content` (never the content), direction `after` adds below, `before` adds above. Do not put the anchor line in `lines`; `[""]` is a blank line.
|
|
2
|
+
- `insert`: `lines` is bare content, one element per line, kept literally even if it duplicates neighbors — nothing is removed.
|
|
3
|
+
- `insert`: the anchor must have been shown by `read`, a post-edit diff (`+anchor│`/` anchor│`), or `grep`. For an empty file, `read` shows one `anchor│` empty row — insert `after` it.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Insert lines after
|
|
1
|
+
Insert `lines` after/before bare anchor `aB3` from `aB3│content`: anchor stays, lines are bare without `│`, one per element
|
package/prompts/insert.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Insert lines after or before
|
|
1
|
+
Insert lines after or before one existing line in a text file, using a bare anchor like `aB3` from `aB3│content`. The anchor line stays; your `lines` are added after (`"after"`) or before (`"before"`) it, one string per line. Use `[""]` for a blank line, never put `\n` inside an element and never include the anchor line in `lines`. Lines are added literally, even if they duplicate neighbors.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
- `read`: call before `replace` when you need fresh
|
|
2
|
-
- `read`: call again after an edit when you need anchors you do not have
|
|
1
|
+
- `read`: call before `replace` when you need fresh anchors for a file.
|
|
2
|
+
- `read`: call again after an edit when you need anchors you do not have — post-edit diff `+anchor│`/` anchor│` rows and `grep` hits are already fresh anchors for the changed range, so no new `read` needed for those lines.
|
package/prompts/read-snippet.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Read a file; each line returned as
|
|
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
|
|
1
|
+
Read a text file; each line returned as `anchor│content` with a 3-character alphanumeric anchor (e.g. `aB3│hello` is anchor `aB3` plus content `hello`). 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. If output says truncated, use `offset`/`limit` as hinted.
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
- `replace`: remove_from and remove_to
|
|
2
|
-
- `replace`:
|
|
3
|
-
- `replace`:
|
|
4
|
-
- `replace`:
|
|
5
|
-
- `replace`:
|
|
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.
|
|
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.
|
|
1
|
+
- `replace`: `remove_from` and `remove_to` are bare anchors like `aB3` (the 3 chars before `│` in `aB3│content`), never the full row or file content. Use the same anchor for both to change one line.
|
|
2
|
+
- `replace`: `replacement_lines` is bare content without `│`, one element per line. Use `[]` to delete, `[""]` for one blank line, never put `\n` inside an element and never include the `anchor│` prefix.
|
|
3
|
+
- `replace`: the range from `remove_from` to `remove_to` is exactly deleted and replaced in order — make it tight, only the lines that actually change, and copy leading spaces exactly.
|
|
4
|
+
- `replace`: diff markers like `+aB3│` or `-aB3│` are stripped automatically if pasted, but always try to send bare content.
|
|
5
|
+
- `replace`: `+anchor│` and ` anchor│` rows in a post-edit diff are fresh anchors — you can use them for the next edit without a new `read`. Do one `replace`/`insert` per turn and check the diff before the next edit.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Replace lines
|
|
1
|
+
Replace lines via bare 3-char anchor `aB3` from `aB3│content`: `remove_from`/`remove_to` are `aB3` only, `replacement_lines` is bare lines without `│`; one edit per call
|
package/prompts/replace.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Replace a range of lines (or a single line) in a text file, targeted by
|
|
1
|
+
Replace a range of lines (or a single line) in a text file, targeted by 3-character anchors from read output. Saw `aB3│content` in read/diff/grep: `aB3` is the bare HASH before `│`, `aB3│content` is the full row. `remove_from` and `remove_to` are bare HASH only (e.g. `"aB3"`), never the full row or file content. `replacement_lines` is bare content without `│`, one string per line — use `[]` to delete. Example: read showed `aB3│old` and `kQm│old2`, to replace both use `{"remove_from":"aB3","remove_to":"kQm","replacement_lines":["new line 1","new line 2"]}`. Single line → same anchor for both.
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
- `undo_last_change`:
|
|
2
|
-
- `undo_last_change`:
|
|
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.
|
|
1
|
+
- `undo_last_change`: only the last `replace`/`insert` per file can be undone; a successful `write` clears it, so call immediately after a bad diff (look for `-anchor│` lines you wanted to keep).
|
|
2
|
+
- `undo_last_change`: if the file changed after the edit you get `[E_UNDO_STALE]` — the record is kept, so undo again after the file matches the edited state; if the file was deleted it is restored.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Undo
|
|
1
|
+
Undo last `replace`/`insert` on a file; restores deleted file, keeps record on `[E_UNDO_STALE]`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Undo the last
|
|
1
|
+
Undo the last `replace` or `insert` on a file, restoring previous content, BOM and line endings. Use after a bad edit when the diff showed wrong lines removed. If the file was deleted, it is restored; if changed elsewhere, you get `[E_UNDO_STALE]` and the record is kept so you can retry after restoring the edited state. If output says truncated, use `read` to see full file.
|
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;
|
package/src/file-kind.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { open as fsOpen, stat as fsStat } from "fs/promises";
|
|
2
2
|
import { fileTypeFromBuffer } from "file-type";
|
|
3
3
|
import { SNIFF_BYTES, MAX_BYTES } from "./constants";
|
|
4
|
+
import { assertLineLimit, lineLimitMoreThanMessage } from "./utils";
|
|
4
5
|
|
|
5
6
|
const IMG_TYPES = new Set<string>([
|
|
6
7
|
"image/bmp",
|
|
@@ -141,11 +142,7 @@ export async function loadFileKindAndText(
|
|
|
141
142
|
for (let i = 0; i < decoded.length; i++) {
|
|
142
143
|
if (decoded.charCodeAt(i) === 10) newlineCount++;
|
|
143
144
|
}
|
|
144
|
-
if (newlineCount > options.maxLines)
|
|
145
|
-
throw new Error(
|
|
146
|
-
`[E_FILE_TOO_LARGE] ${options.displayPath ?? filePath} has more than ${options.maxLines} lines, exceeding the ${options.maxLines}-line hashline limit. For very large files, use write.`,
|
|
147
|
-
);
|
|
148
|
-
}
|
|
145
|
+
if (newlineCount > options.maxLines) throw new Error(lineLimitMoreThanMessage(options.displayPath ?? filePath, options.maxLines));
|
|
149
146
|
}
|
|
150
147
|
return decoded;
|
|
151
148
|
}
|
|
@@ -169,6 +166,11 @@ export async function loadFileKindAndText(
|
|
|
169
166
|
position += chunkBytesRead;
|
|
170
167
|
}
|
|
171
168
|
parts.push(decodeChunk(new Uint8Array(0), false));
|
|
169
|
+
const text = parts.join("");
|
|
170
|
+
if (options?.maxLines !== undefined && text.length > 0) {
|
|
171
|
+
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
172
|
+
assertLineLimit(normalized, options.displayPath ?? filePath, options.maxLines);
|
|
173
|
+
}
|
|
172
174
|
|
|
173
175
|
if (containsNul) {
|
|
174
176
|
return { kind: "binary", description: "contains NUL bytes" };
|
|
@@ -176,7 +178,7 @@ export async function loadFileKindAndText(
|
|
|
176
178
|
|
|
177
179
|
return {
|
|
178
180
|
kind: "text",
|
|
179
|
-
text
|
|
181
|
+
text,
|
|
180
182
|
...(hadUtf8DecodeErrors ? { hadUtf8DecodeErrors: true as const } : {}),
|
|
181
183
|
};
|
|
182
184
|
} finally {
|
package/src/file-reader.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { constants } from "fs";
|
|
2
2
|
import { stat } from "fs/promises";
|
|
3
|
+
import { relative } from "path";
|
|
3
4
|
import { lineHashes } from "./hashline";
|
|
4
5
|
import { loadFileKindAndText, type LFile } from "./file-kind";
|
|
5
6
|
import { resolveTarget } from "./fs-write";
|
|
6
7
|
import { toCwd } from "./paths";
|
|
7
8
|
import { detectEnding, toLF, stripBOM, type LineEnding } from "./replace-diff";
|
|
8
|
-
import { abortIf } from "./utils";
|
|
9
|
+
import { abortIf, errCode, assertLineLimit } from "./utils";
|
|
9
10
|
import { valKind, valAccess } from "./validation";
|
|
10
|
-
import { visLines } from "./utils";
|
|
11
11
|
import type { HashStore } from "./hash-store";
|
|
12
12
|
export interface NormFile {
|
|
13
13
|
absolutePath: string;
|
|
@@ -52,7 +52,7 @@ export async function safeSnapId(
|
|
|
52
52
|
try {
|
|
53
53
|
return (await fileSnap(absolutePath)).snapshotId;
|
|
54
54
|
} catch (error) {
|
|
55
|
-
console.error(`
|
|
55
|
+
console.error(`[safeSnapId] ${context}: failed to stat "${absolutePath}" (code=${errCode(error) ?? "?"}):`, error);
|
|
56
56
|
return undefined;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -91,14 +91,7 @@ export async function readNormFile(
|
|
|
91
91
|
const originalEnding = detectEnding(rawContent);
|
|
92
92
|
const normalized = toLF(rawContent);
|
|
93
93
|
|
|
94
|
-
if (options?.maxLines !== undefined)
|
|
95
|
-
const lineCount = visLines(normalized).length;
|
|
96
|
-
if (lineCount > options.maxLines) {
|
|
97
|
-
throw new Error(
|
|
98
|
-
`[E_FILE_TOO_LARGE] ${path} has ${lineCount} lines, exceeding the ${options.maxLines}-line hashline limit. For very large files, use write.`,
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
94
|
+
if (options?.maxLines !== undefined) assertLineLimit(normalized, path, options.maxLines);
|
|
102
95
|
|
|
103
96
|
const fileHashes = await lineHashes(normalized, resolvedPath, undefined, options?.store, options?.noPersist !== true);
|
|
104
97
|
return {
|
|
@@ -110,3 +103,24 @@ export async function readNormFile(
|
|
|
110
103
|
hadUtf8DecodeErrors: file.hadUtf8DecodeErrors === true,
|
|
111
104
|
};
|
|
112
105
|
}
|
|
106
|
+
|
|
107
|
+
export async function tryReadNormFile(
|
|
108
|
+
absPath: string,
|
|
109
|
+
cwd: string,
|
|
110
|
+
options?: ReadNormOptions,
|
|
111
|
+
): Promise<NormFile | undefined> {
|
|
112
|
+
try {
|
|
113
|
+
const displayPath = relative(cwd, absPath).replace(/\\/g, "/") || absPath;
|
|
114
|
+
const file = await loadFileKindAndText(absPath, { maxLines: options?.maxLines, displayPath });
|
|
115
|
+
if (file.kind !== "text") return undefined;
|
|
116
|
+
return await readNormFile(absPath, cwd, { ...options, preloadedFile: file });
|
|
117
|
+
} catch (error) {
|
|
118
|
+
const code = errCode(error);
|
|
119
|
+
if (code === "EACCES" || code === "EPERM" || code === "ENOENT" || code === "ELOOP") return undefined;
|
|
120
|
+
if (error instanceof Error) {
|
|
121
|
+
const msg = error.message;
|
|
122
|
+
if (msg.startsWith("[E_FILE_TOO_LARGE]") || msg.startsWith("[E_NOT_FOUND]") || msg.startsWith("[E_ACCESS]") || msg.startsWith("[E_NOT_TEXT]")) return undefined;
|
|
123
|
+
}
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
}
|