@criogaid/pi-hashline-edit 0.3.1 → 0.4.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 +58 -49
- package/package.json +8 -3
- package/src/core/apply.test.ts +366 -310
- package/src/core/apply.ts +269 -202
- package/src/core/hash.test.ts +61 -23
- package/src/core/hash.ts +45 -16
- package/src/core/lines.test.ts +46 -27
- package/src/core/lines.ts +36 -28
- package/src/core/ranges.test.ts +73 -19
- package/src/core/ranges.ts +15 -15
- package/src/core/text.test.ts +3 -3
- package/src/core/text.ts +28 -9
- package/src/core/types.ts +54 -36
- package/src/index.ts +22 -16
- package/src/integration/grep-rg.test.ts +834 -219
- package/src/integration/large-text.test.ts +62 -0
- package/src/integration/replace-package.test.ts +37 -0
- package/src/pi/action-fusion.test.ts +535 -206
- package/src/pi/action-fusion.ts +469 -244
- package/src/pi/anchor-format.test.ts +30 -19
- package/src/pi/anchor-format.ts +27 -14
- package/src/pi/budgets.ts +20 -0
- package/src/pi/config.test.ts +60 -30
- package/src/pi/config.ts +45 -32
- package/src/pi/directory-sync.test.ts +55 -0
- package/src/pi/e2e-scenarios.test.ts +359 -0
- package/src/pi/edit-tool.ts +426 -262
- package/src/pi/error-text.ts +21 -0
- package/src/pi/execute.test.ts +1593 -712
- package/src/pi/failure-context.test.ts +105 -83
- package/src/pi/failure-context.ts +83 -71
- package/src/pi/failure-path.test.ts +171 -64
- package/src/pi/file-commit.test.ts +446 -233
- package/src/pi/file-commit.ts +347 -203
- package/src/pi/fusion-card.test.ts +118 -83
- package/src/pi/fusion-card.ts +120 -85
- package/src/pi/grep-output.ts +208 -0
- package/src/pi/grep-render.ts +58 -0
- package/src/pi/grep-scope.ts +152 -0
- package/src/pi/grep-search.ts +217 -0
- package/src/pi/grep-tool.ts +191 -766
- package/src/pi/grep.test.ts +562 -150
- package/src/pi/mutation-result.test.ts +37 -0
- package/src/pi/mutation-result.ts +107 -59
- package/src/pi/mutation-runner.ts +168 -0
- package/src/pi/path.ts +20 -12
- package/src/pi/pi.test.ts +95 -52
- package/src/pi/read-tool.ts +215 -132
- package/src/pi/registration.test.ts +274 -113
- package/src/pi/render.test.ts +218 -83
- package/src/pi/render.ts +152 -95
- package/src/pi/replace-apply.ts +109 -0
- package/src/pi/replace-tool.ts +280 -240
- package/src/pi/replace-worker.mjs +4 -0
- package/src/pi/replace-worker.ts +10 -0
- package/src/pi/replace.test.ts +773 -389
- package/src/pi/result-safety.test.ts +779 -342
- package/src/pi/rg-line-filter.test.ts +64 -36
- package/src/pi/rg-line-filter.ts +40 -124
- package/src/pi/rg-line-ranges.test.ts +57 -31
- package/src/pi/rg-line-ranges.ts +44 -82
- package/src/pi/rg-text-view.ts +106 -36
- package/src/pi/schema.ts +27 -0
- package/src/pi/state.ts +7 -7
- package/src/pi/text-stream.test.ts +118 -0
- package/src/pi/text-stream.ts +136 -0
- package/src/pi/tool-call.testing.ts +37 -0
- package/src/pi/write-tool.ts +115 -52
- package/src/pi/write.test.ts +248 -96
package/README.md
CHANGED
|
@@ -74,7 +74,7 @@ All text inspection and matching uses one logical representation: CRLF boundarie
|
|
|
74
74
|
|
|
75
75
|
### Edit operations
|
|
76
76
|
|
|
77
|
-
`edit`
|
|
77
|
+
`edit` declares a required `path` and a non-empty structured `edits` array. This extension does not normalize alternate formats: stringified JSON and top-level single-op fields are rejected. Pi's own argument validation may convert a single edit object to a one-element array before the extension sees it. Anchors are `"LINE#HASH"` strings whose hash has exactly `hashLen` characters; each `body` element is one logical line without CR or LF. An anchor of a different hash length, such as one copied before a `hashLen` change, is rejected before the file is read, and the error names each such anchor.
|
|
78
78
|
|
|
79
79
|
| `op` | Required | Optional | Effect |
|
|
80
80
|
| --- | --- | --- | --- |
|
|
@@ -83,9 +83,11 @@ All text inspection and matching uses one logical representation: CRLF boundarie
|
|
|
83
83
|
| `insert_before` / `insert_after` | `anchor`, `body` | — | Insert beside the anchor; keep the anchor line. |
|
|
84
84
|
| `prepend` / `append` | `body` | — | Insert at the start/end; no anchors. |
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
An empty `body: []` deletes the cited range for `replace` and leaves the file unchanged for insertion, `append`, or `prepend`. Anchors and batch validation still apply.
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
All operations in a batch use the same snapshot. Validation failure rejects the whole batch. Unknown fields, conflicting fields, and overlapping operations are rejected; some touching operations also conflict and need separate calls with fresh anchors. For insertion, **do not repeat the anchor line in `body`**. `edit` uses structured operations, not `oldText`/`newText` pairs.
|
|
89
|
+
|
|
90
|
+
For multi-operation batches that reach snapshot verification, rejected edits report each supplied anchor's status: `matched` or `mismatched`. Schema-invalid inputs fail before reading the file and have no anchor-status table. Single-operation edits omit the summary table and report the failure directly. Entries identify the zero-based operation index, `anchor` or `end`, and the cited token. The bounded list reports omitted entries explicitly. These statuses do not establish range/overlap validity, semantic intent, publication, command success, or validity on a later retry.
|
|
89
91
|
|
|
90
92
|
Recovery first searches within `shiftRadius` of the cited line. If that search finds no candidates, it searches the rest of the file and collects all checksum matches before deciding whether the result is unique or ambiguous. Existing local candidates take priority; distant matches are not added when local candidates exist. `shiftRadius: 0` disables both searches. Candidate matching holds the original line number fixed when hashing current content; returned anchors use each candidate's actual line number.
|
|
91
93
|
|
|
@@ -95,24 +97,24 @@ A unique recovery candidate returns its new anchor and complete line content, wi
|
|
|
95
97
|
|
|
96
98
|
Ambiguous failures list up to eight candidate anchors and include a bounded ±3-line neighborhood around each listed candidate from the same snapshot. Windows are clipped to file boundaries, merged, and emitted in ascending line order within byte budgets. Neighboring rows are observations, not recommended replacement targets. Candidate content already present in a neighborhood is not repeated in failure details. Inspect the code to choose the correct anchor and operation, then resubmit. No edit or retry is performed automatically, and every submitted anchor is verified again.
|
|
97
99
|
|
|
98
|
-
When no candidate is found, diagnostics
|
|
100
|
+
When no candidate is found, diagnostics show the current cited line as a complete `LINE#HASH│content` observation within the 4 KiB row limit. Confirm it is the intended target before reusing its anchor directly. Use `read` or `grep` for additional context, omitted rows, or out-of-range references. Retries revalidate.
|
|
99
101
|
|
|
100
102
|
### Bulk replacement
|
|
101
103
|
|
|
102
104
|
For a rename across a file:
|
|
103
105
|
|
|
104
106
|
```json
|
|
105
|
-
{ "path": "src/foo.ts", "find": "oldName", "replace": "newName" }
|
|
107
|
+
{ "path": "src/foo.ts", "replacements": [{ "find": "oldName", "replace": "newName" }] }
|
|
106
108
|
```
|
|
107
109
|
|
|
108
110
|
Literal mode keeps `$` text verbatim. Both literal and regex modes match the shared LF view: actual CRLF in the file and `find` normalizes to LF; standalone CR remains content. Match ranges map back to the original text before replacement, preserving bytes and separators outside each match, including an unmatched BOM or final newline.
|
|
109
111
|
|
|
110
112
|
Replacement text also normalizes CRLF to LF, then reuses matched separators in order. Additional lines use the last matched separator, or the file style when the match contains no separator (CRLF if present anywhere, otherwise LF).
|
|
111
113
|
|
|
112
|
-
Regex patterns run on LF text, so use `\n` for a line boundary. Captures and replacement templates also use the LF snapshot; the result then restores original separators. Use `write` for explicit line-ending conversion. Source-code escapes are ordinary text: JSON `"find": "\\r\\n"` finds the visible four-character sequence in literal mode, while `"find": "\r\n"` contains an actual CRLF boundary. Set `regex: true` for JavaScript capture groups and replacement templates:
|
|
114
|
+
Regex patterns use JavaScript syntax, unlike `grep`, which uses ripgrep's Rust regex; a pattern that works in one tool may fail or match differently in the other. Add the `m` flag for per-line `^`/`$`. `\d` matches only ASCII digits; `\w` and `\b` are ASCII-based, except that with both `i` and `u` they also treat `ſ` (U+017F) and `K` (U+212A) as word characters through case folding. Regex patterns run on LF text, so use `\n` for a line boundary. Captures and replacement templates also use the LF snapshot; the result then restores original separators. Use `write` for explicit line-ending conversion. Source-code escapes are ordinary text: JSON `"find": "\\r\\n"` finds the visible four-character sequence in literal mode, while `"find": "\r\n"` contains an actual CRLF boundary. Set `regex: true` for JavaScript capture groups and replacement templates:
|
|
113
115
|
|
|
114
116
|
```json
|
|
115
|
-
{ "path": "src/foo.ts", "find": "get([A-Z]\\w*)", "replace": "fetch$1", "regex": true }
|
|
117
|
+
{ "path": "src/foo.ts", "replacements": [{ "find": "get([A-Z]\\w*)", "replace": "fetch$1", "regex": true }] }
|
|
116
118
|
```
|
|
117
119
|
|
|
118
120
|
To apply several rules against the same original content:
|
|
@@ -134,63 +136,62 @@ Original `foo bar` becomes `bar baz`; inserted text is not searched again. All r
|
|
|
134
136
|
|
|
135
137
|
### Read
|
|
136
138
|
|
|
137
|
-
Required: `path`. Optional:
|
|
139
|
+
Required: non-empty `path`. Optional: positive safe-integer `offset` (1-based; default 1) and positive safe-integer `limit` (default 500 lines). Fractions, zero, negative values, and unknown fields are rejected. Returned text is capped at 256 KiB; oversized rows are not returned as partial editable lines. Files without a final newline are identified in the header.
|
|
140
|
+
|
|
141
|
+
When the line limit leaves more content, the result reports the shown range and the next `offset`, for example `showing lines 1-500 of 1200; use offset 501 to continue`. `details.pagination` contains 1-based `start`, inclusive `end`, `totalLines`, and `nextOffset`. This applies to default and explicit limits. Reads reaching EOF omit pagination; byte-limited reads retain their byte-truncation notice and metadata.
|
|
138
142
|
|
|
139
143
|
### Grep
|
|
140
144
|
|
|
141
145
|
| Parameter | Default | Meaning |
|
|
142
146
|
| --- | --- | --- |
|
|
143
|
-
| `pattern` | Required | Non-empty string or array. |
|
|
144
|
-
| `path` | Current directory |
|
|
145
|
-
| `
|
|
146
|
-
| `
|
|
147
|
-
| `
|
|
148
|
-
| `
|
|
149
|
-
| `
|
|
150
|
-
| `
|
|
151
|
-
| `
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
Long lines show a labeled partial preview of up to 500 UTF-16 units around a ripgrep match; context-only lines show their beginning. Labels report 1-based UTF-16 column ranges, and slicing preserves surrogate pairs. The anchor hashes the entire current line, not the preview; use `read` before reconstructing a line from its content.
|
|
147
|
+
| `pattern` | Required | Non-empty string (including whitespace-only text) or array of non-empty strings; arrays match any pattern (OR). When `ignoreCase` is omitted, smart-case is resolved for the entire query, not separately for each array item. |
|
|
148
|
+
| `path` | Current directory | Omit `path` to search the working directory. If supplied, it must be one non-empty existing file or directory, or a non-empty array of search roots; `""` and `[]` are invalid. Wildcards are not expanded; use `glob` to filter filenames. |
|
|
149
|
+
| `glob` | None | One non-empty glob or a non-empty ordered array; prefix exclusions with `!`. |
|
|
150
|
+
| `literal` | Automatic | Set `true` for literal code text, including regex punctuation such as `pi.on(`; this does not force case-sensitive matching. Set `false` for intentional ripgrep Rust regex, not JavaScript regex: lookaround and backreferences are unsupported, and `^`/`$` match at line boundaries. Automatic mode tries regex for metacharacters; an invalid single-pattern query falls back to searching the **entire string** literally and reports the fallback. Invalid pattern arrays fail instead of changing their meaning; invalid regex with `literal: false` fails. When the pattern contains lookaround or a backreference, the error or fallback notice says so and points to `replace` for JavaScript regex within one file. |
|
|
151
|
+
| `ignoreCase` | Smart-case | Query-level case override: `true` ignores case; `false` distinguishes case. Inline regex case flags may override either setting. |
|
|
152
|
+
| `multiline` | `false` | Allow matches across physical lines. CRLF is searched as LF; each distinct matched physical line counts toward `limit` and receives an anchor in content mode. `context` alone does not enable cross-line matching. The `.` wildcard still does not match newlines; use `\n` or `(?s)`. |
|
|
153
|
+
| `context` | `0` | Integer from 0 to 20: include that many anchored lines before and after each match (pass 3–5 to inspect code blocks without another read). Fractions are rejected, not rounded. Context lines do not count toward `limit`. |
|
|
154
|
+
| `limit` | `100` | Positive safe-integer maximum of distinct matching physical lines, across all files and patterns. Reaching the limit produces a notice; it does not prove that another match exists. |
|
|
155
|
+
| `outputMode` | `"content"` | `"content"` returns anchored matching lines plus context, `"files"` returns distinct paths, and `"count"` returns matching-line counts per file and a total. All modes use the same limited match set: files and counts may be incomplete when the limit or output byte cap is reached. |
|
|
156
|
+
|
|
157
|
+
The six former grep fields (`matchMode`, `excludePattern`, `wordMatch`, `pcre2`, `follow`, `noIgnore`) are no longer supported. Calls that contain them, including `false` or `null`, fail before searching; saved session history remains readable, but replaying an old call with these fields requires a new query. They are not silently converted to a different search.
|
|
158
|
+
|
|
159
|
+
Grep defaults to line-based code searches. With `multiline: true`, OR patterns are scanned separately to retain overlapping spans, and matching physical lines are deduplicated before counting. There is no built-in content exclusion, same-line AND, whole-word switch, or PCRE2. Displaying neighboring lines with `context` does not itself match across lines. More specialized searches require another tool (for example, Bash when available); an empty grep result does not establish that ignored files or linked directories contain no matches.
|
|
160
|
+
|
|
161
|
+
Directory traversal respects ignore rules, does not follow symbolic links, and includes hidden files. Explicitly named files can still be read through a link or from an ignored directory; ordered `glob` filters still apply to explicit file paths. These rules have different priorities for explicit paths and directory traversal and are not simply intersected.
|
|
162
|
+
|
|
163
|
+
Searches use bundled ripgrep on the shared LF view, independent of system `rg` or `PATH`. The tool disables external ripgrep configuration with `--no-config` and clears `RIPGREP_CONFIG_PATH`, and uses `--no-crlf` and `--encoding=none` so standalone CR and BOM remain content. NUL-containing files are searched as raw bytes; confirmed content-mode hits are rejected before anchoring, and multiline hits are rejected before mapping physical lines. Files without CRLF are searched at their original paths; CRLF text is normalized into temporary snapshots using bounded reads and writes. Batches contain up to 64 files or 8 MiB of source data (one large file can exceed that threshold); snapshots are removed after each batch and on failure/cancellation. Match paths refer to original files; text line and column positions refer to logical text. Regexes use ripgrep's default Rust-style engine, not PCRE2.
|
|
164
|
+
|
|
165
|
+
Search diagnostics are preserved even when a result limit stops ripgrep. Readable, confirmed matches remain available with a `Search incomplete` notice and `details.incomplete: true`; counts then cover only confirmed matches. If no results can be returned, the tool reports an error rather than claiming there are no matches. Search diagnostics have a separate 4 KiB display budget.
|
|
166
|
+
|
|
167
|
+
Long lines show a labeled partial preview of up to 500 UTF-16 units near a reported match column when available; context-only lines and matches without a recorded column show their beginning. Labels report 1-based UTF-16 column ranges, and slicing preserves surrogate pairs. The anchor hashes the entire current line, not the preview; use `read` before reconstructing a line from its content.
|
|
166
168
|
|
|
167
169
|
### Replace
|
|
168
170
|
|
|
169
|
-
Required: `path` and
|
|
171
|
+
Required: non-empty `path` and a non-empty `replacements` array. Use one item for a single rule; top-level `find`, `replace`, `regex`, and `flags` are not accepted. Each rule requires non-empty `find` and a `replace` string (which may be empty), with these optional fields:
|
|
170
172
|
|
|
171
173
|
- `regex`: defaults to `false`; both modes match the shared LF view. Regex mode supports capture groups, the full match, and prefix/suffix substitutions.
|
|
172
|
-
- `flags`: applies in both modes; `g` is always added.
|
|
173
|
-
- `maxMatches`: defaults to 2000 per rule and must be finite and positive; rejects excess matches before writing. Raise it for intentional bulk changes. It does not bound regex execution time or result size.
|
|
174
|
+
- `flags`: applies in both modes; `g` is always added. Only `g i m s u y d` characters are accepted; regex syntax errors are reported per rule before the file is read.
|
|
174
175
|
|
|
175
176
|
Zero matches in any rule, an invalid rule, or overlapping match ranges rejects the whole call without writing. Adjacent ranges are allowed. Zero-length matches conflict at the same position or at the start/interior of another match; a zero-length match at another match's end is allowed unless it conflicts with a following match. Error rule indices and string offsets are zero-based (offsets count UTF-16 code units in the original text). Literal and regex rules share the same original ranges for conflict detection.
|
|
176
177
|
|
|
177
178
|
Regex captures and prefix/suffix substitutions always refer to the original LF-normalized snapshot.
|
|
179
|
+
Regex batches run in a worker and are terminated on cancellation or after 5 seconds of evaluation. A cancelled or timed-out batch leaves the file unchanged; literal-only batches retain their existing execution path.
|
|
178
180
|
|
|
179
181
|
### Write
|
|
180
182
|
|
|
181
|
-
Required: `path`, `content`. By default, create missing files and overwrite existing ones. Content is used exactly as supplied; anchor-looking prefixes are not stripped.
|
|
183
|
+
Required: `path`, `content`. By default, create missing files and overwrite existing ones. Content is used exactly as supplied; anchor-looking prefixes are not stripped. Unknown fields, including misspelled modes, are rejected before writing.
|
|
182
184
|
|
|
183
185
|
- `mode: "create"`: refuse an existing target.
|
|
184
186
|
- `mode: "overwrite"`: require an existing target.
|
|
185
|
-
- `expectedRevision`: strictly check the current file's SHA-256; cannot be combined with create mode.
|
|
186
187
|
|
|
187
188
|
Write results report the write outcome without returning line anchors. Use `read` or content-mode `grep` to obtain anchors for a later `edit`.
|
|
188
189
|
|
|
189
|
-
Normal write result text omits the revision. Programmatic callers can read `details.publishedRevision`;
|
|
190
|
+
Normal write result text omits the revision. Programmatic callers can read `details.publishedRevision`; edit and replace use source revisions internally to reject stale writes.
|
|
190
191
|
|
|
191
192
|
With Action Fusion enabled, `edit`, `replace`, and `write` also accept `then_run`.
|
|
192
193
|
|
|
193
|
-
All three mutation tools treat identical final content as a successful no-op: report `no net change`, leave the existing file untouched, and return `publication: "NOT_PUBLISHED"`. A requested `then_run` still runs after freshness checks. Input, anchor, match, target-type, mode,
|
|
194
|
+
All three mutation tools treat identical final content as a successful no-op: report `no net change`, leave the existing file untouched, and return `publication: "NOT_PUBLISHED"`. A requested `then_run` still runs after freshness checks. Input, anchor, match, target-type, mode, and cancellation checks still apply; edit/replace reject stale source revisions, while zero matches and an existing target in create mode remain errors. Creating a missing empty file is a publication, not a no-op.
|
|
194
195
|
|
|
195
196
|
</details>
|
|
196
197
|
|
|
@@ -213,7 +214,7 @@ Add `hashlineEdit` to Pi's global settings (`~/.pi/agent/settings.json` by defau
|
|
|
213
214
|
| --- | --- | --- |
|
|
214
215
|
| `enabled` | `true` | Enable all five tools as one unit. Set `false` to restore built-in tools. |
|
|
215
216
|
| `actionFusion` | `true` | Expose `then_run` on mutation tools. Set `false` to disable command support. |
|
|
216
|
-
| `hashLen` | `4` | Integer checksum length, 2–8 characters. |
|
|
217
|
+
| `hashLen` | `4` | Integer checksum length, 2–8 characters. `edit` accepts only anchors of this length; anchors produced under another setting must be read again. |
|
|
217
218
|
| `shiftRadius` | `15` | Integer first-pass recovery-search radius, 0–100 lines. With no local candidates, recovery searches the rest of the file; `0` disables both searches. |
|
|
218
219
|
|
|
219
220
|
The project's `hashlineEdit` object replaces the global object as a whole; missing or invalid fields use defaults. Reload Pi after changes.
|
|
@@ -225,13 +226,12 @@ Action Fusion is enabled by default. Set `"actionFusion": false` in `hashlineEdi
|
|
|
225
226
|
```json
|
|
226
227
|
{
|
|
227
228
|
"path": "src/foo.ts",
|
|
228
|
-
"find": "oldName",
|
|
229
|
-
"replace": "newName",
|
|
229
|
+
"replacements": [{ "find": "oldName", "replace": "newName" }],
|
|
230
230
|
"then_run": { "command": "npm test", "timeout": 60 }
|
|
231
231
|
}
|
|
232
232
|
```
|
|
233
233
|
|
|
234
|
-
`command` is required; `timeout` is optional, in
|
|
234
|
+
`command` is required and must contain a non-whitespace character; `timeout` is optional, in seconds greater than zero and at most 2147483.647, with no default. Unknown `then_run` fields are rejected. Invalid command parameters fail before mutation. Mutation failure skips the command. Command failure after mutation success **does not roll back the file**: it is returned separately in result text and `details.actionFusion`, rather than thrown as failure of the whole mutation.
|
|
235
235
|
|
|
236
236
|
In the TUI, the mutation card owns the mutation's result or error summary, publication status, and freshness warnings. It turns successful when mutation execution and result generation finish. The command card owns command output and execution status; skipped or cancelled commands are neutral and show a short reason when execution never started. Mutation diagnostics never become command output, and command failure leaves a successful mutation card intact. RPC hosts receive the same progress and choose their own rendering.
|
|
237
237
|
|
|
@@ -242,7 +242,7 @@ Fusion serializes each mutation/command sequence for its target and checks the p
|
|
|
242
242
|
- **Anchors are checksums, not identities.** Each hash combines the 1-based line number and content. Short hashes can collide and do not prove the model observed a line.
|
|
243
243
|
- **Validation is local to supplied anchors.** Unrelated in-place changes leave stable anchors usable. A range verifies its supplied start/end anchors, not every interior line.
|
|
244
244
|
- **Line shifts change anchors.** Insertions/deletions can invalidate later references. Recovery searches within `shiftRadius`, then the rest of the file if no local candidates match. Unique candidates include bounded line content; ambiguous candidates include neighborhoods for comparison. Use `read` when no candidate is found or needed content is omitted. Retries verify again, without fuzzy matching or automatic relocation.
|
|
245
|
-
- **Edits preserve text representation.** `edit` preserves existing line endings, untouched separators, and the absence of a final newline. `edit`/`replace` reject invalid UTF-8 source text; all mutations reject NUL and output that cannot be encoded losslessly as UTF-8. UTF-16 and legacy code pages are not decoded or preserved; a BOM-free file whose bytes happen to be valid UTF-8 may still be misinterpreted.
|
|
245
|
+
- **Edits preserve text representation.** `edit` preserves existing line endings, untouched separators, and the absence of a final newline. `edit`/`replace` reject invalid UTF-8 source text; all mutations reject NUL and output that cannot be encoded losslessly as UTF-8. Supplied text (`write` content, `edit` body lines, `replace` replacement text) is checked before the file is read, naming the offending field; the final content is checked again before publication, because a transformation such as a regex without `u` can split a surrogate pair. UTF-16 and legacy code pages are not decoded or preserved; a BOM-free file whose bytes happen to be valid UTF-8 may still be misinterpreted.
|
|
246
246
|
- **Fresh anchors depend on the final observation.** After `then_run`, anchors are shown only for `unchanged` freshness. Without a command, observed and published revisions must agree. Later edits still verify anchors.
|
|
247
247
|
- **Local queues are not cross-process transactions.** Revision checks bind mutations to the bytes read, but an external writer can still race a check and publication. There is no strict workspace jail or multi-file transaction.
|
|
248
248
|
|
|
@@ -251,7 +251,7 @@ Fusion serializes each mutation/command sequence for its target and checks the p
|
|
|
251
251
|
|
|
252
252
|
### Hashing and BOM handling
|
|
253
253
|
|
|
254
|
-
`read`
|
|
254
|
+
`read` scans text in bounded chunks, validates the whole file, and retains requested line content within its output budget. It reports the total line count and computes hashes for complete output rows. `grep` scans matching files concurrently, retaining only selected matches/context while formatting each file's output. Completed workers retain formatted output blocks in discovery order. NUL-containing files are searched as raw bytes and confirmed content-mode hits are rejected before anchoring. Mutation revision checks cover actual bytes.
|
|
255
255
|
|
|
256
256
|
Line boundaries are LF or CRLF; a standalone CR remains line content. Anchored rows display standalone CR as `␍` (U+240D), while hashes use the original content. Edit/replace `details.diff` marks raw CR as `␍`; `details.displayDiff` renders the shared LF view for the TUI, so CRLF boundary markers stay hidden even in mixed-ending files or beside an unterminated last line. Standalone CR and literal `␍` characters remain visible. Unified patches retain the original characters and line endings. The marker is a display aid, not replacement text.
|
|
257
257
|
|
|
@@ -263,10 +263,10 @@ These limits bound model context, not file size. Omission notices direct the cal
|
|
|
263
263
|
|
|
264
264
|
| Output | Limit |
|
|
265
265
|
| --- | --- |
|
|
266
|
-
| `read` | Default
|
|
266
|
+
| `read` | Default 500 rows, overridable with `limit`; 256 KiB of anchored text. No partial anchor rows. An oversized single row directs the caller to inspect chunks with `bash` or make a known text change with `replace`; reducing `limit` cannot split a physical line. |
|
|
267
267
|
| `grep` | Default 100 matching lines, overridable; up to 500 UTF-16 units per partial line preview, plus labels and Pi's total output limits. Match previews use rg byte offsets; hashes use full content. Search error notices have a separate 4 KiB budget. |
|
|
268
268
|
| `edit` / `replace` anchors | 16 KiB including heading/omission notice, with no fixed entry-count limit. Compact tokens for changed positions; selected deletion successors retain complete content. Rows that do not fit are omitted in full; later rows that fit are still returned. |
|
|
269
|
-
| Anchor failure details | 16 KiB, with no fixed failure-count limit; unique candidates include complete rows up to 4 KiB, and ambiguous failures list up to eight candidates each. Unresolved anchors
|
|
269
|
+
| Anchor failure details | 16 KiB, with no fixed failure-count limit; unique candidates include complete rows up to 4 KiB, and ambiguous failures list up to eight candidates each. Unresolved anchors show the current cited row when it fits; oversized or out-of-range rows require a fresh `read` or `grep`. |
|
|
270
270
|
| Input-anchor checks | Independent 16 KiB block, with no fixed entry-count limit. Truncation is reported explicitly; omitted entries are not implied matched. |
|
|
271
271
|
| Ambiguous-candidate neighborhoods | 16 KiB of complete anchored row text, lowest-line first, plus headings; no fixed row-count limit. Uses the same first eight candidates per failure as the detail lists. Each listed candidate row is limited to 4 KiB. Rows exceeding either limit are omitted in full; later rows that fit are still returned, with gaps reflected in the neighborhood headings. |
|
|
272
272
|
|
|
@@ -285,7 +285,8 @@ The shared commit layer validates the target and skips publication when the requ
|
|
|
285
285
|
| Multiple hard links | Reject existing regular files with multiple links to avoid splitting the link set. |
|
|
286
286
|
| Permissions | Copy existing mode bits; new files use `0600`. No separate public permission setting. |
|
|
287
287
|
| Post-publication failure | Directory-sync, result-generation, revision observation, or cleanup errors retain `PUBLISHED`; unconfirmed publication is `UNKNOWN`. Read before retrying uncertain mutations. |
|
|
288
|
-
| Durability | Attempt
|
|
288
|
+
| Durability | Attempt directory synchronization on POSIX, including macOS; tolerate `EINVAL` / `ENOTSUP` from directory fsync and propagate other failures. Windows skips directory synchronization. |
|
|
289
|
+
| Cancellation | Every tool reports cancellation as an error starting with `Operation aborted`, matching Pi's built-in tools. Mutation tools add where it stopped and whether the file changed, for example `Operation aborted before apply; src/foo.ts was not changed.` |
|
|
289
290
|
|
|
290
291
|
### Result and card states
|
|
291
292
|
|
|
@@ -293,12 +294,20 @@ The shared commit layer validates the target and skips publication when the requ
|
|
|
293
294
|
| --- | --- |
|
|
294
295
|
| `publication` | `NOT_PUBLISHED`, `PUBLISHED`, or `UNKNOWN`. Fusion also reports it in `actionFusion.publication`. |
|
|
295
296
|
| `baseRevision` | SHA-256 of bytes read before mutation, when available. |
|
|
296
|
-
| `publishedRevision` | SHA-256 of intended published bytes
|
|
297
|
+
| `publishedRevision` | SHA-256 of intended published bytes. |
|
|
297
298
|
| `observedRevision` | SHA-256 observed by the commit layer after publication, or at the no-op check. |
|
|
298
299
|
| `actionFusion.command` | `not_requested`, `skipped`, `succeeded`, `failed`, `timeout`, or `cancelled`. |
|
|
299
300
|
| `actionFusion.freshness` | `unchanged`, `changed`, `missing`, or `unknown`, relative to the published revision. |
|
|
300
301
|
| `actionFusion.mutationCompleted` | Progress flag set after mutation execution and result generation succeed; publication alone is not mutation success. |
|
|
301
302
|
|
|
302
|
-
Streaming mutation summaries omit anchors. Result-generation failures preserve publication status and any completed command outcome; progress callback failures are reported separately from mutation/command outcomes. Command progress `output` contains only command output or execution errors, with an optional `reason` for commands that never started. Command cards persist only their own state and use native Bash output rendering. Final cards survive reloads without adding model-context messages; unfinished saved commands show an interrupted/unknown outcome.
|
|
303
|
+
Streaming mutation summaries omit anchors. Result-generation failures preserve publication status and any completed command outcome; progress callback failures are reported separately from mutation/command outcomes. Command progress `output` contains only command output or execution errors, with an optional `reason` for commands that never started. Command cards persist only their own state and use native Bash output rendering. Final cards survive reloads without adding model-context messages; unfinished saved commands show an interrupted/unknown outcome.
|
|
303
304
|
|
|
304
305
|
</details>
|
|
306
|
+
|
|
307
|
+
## Verification
|
|
308
|
+
|
|
309
|
+
- `npm run typecheck` checks source and test types.
|
|
310
|
+
- `npm test` runs core and tool tests.
|
|
311
|
+
- `npm run test:integration` exercises bundled ripgrep and files over 100 MiB, including LF and CRLF text.
|
|
312
|
+
- `npm run bench` measures core throughput and long-line match mapping.
|
|
313
|
+
- `node --expose-gc bench/grep-memory.bench.ts` measures grep latency and sampled peak heap/RSS for 24 files totaling 192 MiB, each with one matching line. It creates and removes its fixtures in the system temporary directory.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@criogaid/pi-hashline-edit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Hashline-style file editing for pi — line-anchored edits verified by content hash, replacing oldText/newText matching",
|
|
6
6
|
"homepage": "https://github.com/Criogaid/pi-hashline-edit#readme",
|
|
@@ -18,18 +18,23 @@
|
|
|
18
18
|
"LICENSE"
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
|
+
"format": "biome format --write src/",
|
|
22
|
+
"format:check": "biome format src/",
|
|
21
23
|
"typecheck": "tsc --noEmit",
|
|
22
24
|
"test": "node --test src/core/*.test.ts src/pi/*.test.ts",
|
|
23
25
|
"test:integration": "node --test src/integration/*.test.ts",
|
|
24
|
-
"test:all": "npm test && npm run test:integration"
|
|
26
|
+
"test:all": "npm test && npm run test:integration",
|
|
27
|
+
"bench": "node bench/throughput.bench.ts"
|
|
25
28
|
},
|
|
26
29
|
"dependencies": {
|
|
27
|
-
"@vscode/ripgrep": "1.18.0"
|
|
30
|
+
"@vscode/ripgrep": "1.18.0",
|
|
31
|
+
"jiti": "2.7.0"
|
|
28
32
|
},
|
|
29
33
|
"peerDependencies": {
|
|
30
34
|
"@earendil-works/pi-coding-agent": "*"
|
|
31
35
|
},
|
|
32
36
|
"devDependencies": {
|
|
37
|
+
"@biomejs/biome": "2.5.14",
|
|
33
38
|
"@earendil-works/pi-agent-core": "*",
|
|
34
39
|
"@earendil-works/pi-ai": "*",
|
|
35
40
|
"@earendil-works/pi-coding-agent": "*",
|