pi-hashline-edit-pro 4.1.0 → 4.2.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 CHANGED
@@ -89,7 +89,7 @@ Single line: use the same anchor for `remove_from` and `remove_to`. `replace_fro
89
89
 
90
90
  The request is checked before any file I/O, so a bad request never touches the file.
91
91
 
92
- Common copy-paste slips are fixed automatically and reported as warnings: a leftover `anchor│` prefix in `replacement_lines` or the anchor fields (a prefix of 4 to 5 characters before `│`, for example `ab12│`), diff-preview rows pasted into the replacement, a reversed range, and a boundary line pasted twice. New lines that re-include a block adjacent to the range are stripped when that block is unique in the file. The whole run is stripped as one unit, so re-including an unchanged block next to the range never duplicates it.
92
+ Common copy-paste slips are fixed automatically and reported as warnings: a leftover `anchor│` prefix in `replacement_lines` or the anchor fields (a prefix of 4 to 5 characters before `│`, for example `ab12│`), diff-preview rows pasted into the replacement, a reversed range, and a boundary line pasted twice. New lines that re-include a block adjacent to the range are stripped when that block is unique in the file. The whole run is stripped as one unit, so re-including an unchanged block next to the range never duplicates it. Boundary dedup has three modes in `/hashline-config`: `on` strips with a warning, `off` applies edits literally, and `strict` rejects the edit with `[E_BOUNDARY_STRICT]` when any replacement line would be stripped.
93
93
 
94
94
  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, `anchor_grep` output, the auto-read block after `write`, the `+anchor│` and ` anchor│` rows of post-edit diffs, the current-range rows of `[E_RANGE_STALE]` feedback, and the context rows of stale-anchor feedback) and verifies the whole range against that record before writing. A line that changed on disk since it was shown, or an anchor that is not owned in this session, refuses the edit with `[E_RANGE_STALE]` or `[E_STALE_ANCHOR]` and returns the current range with fresh anchors, so the retry needs no `read`. An owned anchor enters the served record when its row is shown (after a restart, restored ownership counts as shown), so a file with no owned anchors cannot be edited by anchor at all; call `read` first. An owned line that was never shown — for example beyond an auto-read preview's truncation cap — is refused with `[E_RANGE_STALE]` and returns the current range, so the retry still needs no `read`.
95
95
 
@@ -97,7 +97,7 @@ An edit that produces identical content reports `No changes made` and leaves the
97
97
 
98
98
  After a successful edit, the diff is capped at 50KB. A row over 50KB is shown as a marker that keeps the row's anchor, and 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`.
99
99
 
100
- 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.
100
+ Multiple `replace` and `insert` calls on the same file in one message are grouped per file into one batch that validates every call against the pre-batch state and then applies them together on the batch's last call: earlier calls reply `In batch` (`In batch N` when several files batch) and the batch's last call shows the combined diff, with one undo reverting the whole batch. Batched calls must target disjoint ranges; overlapping ranges, or any failing call, aborts the whole batch with nothing written. Verify each batch diff before the next turn's edits on that file.
101
101
 
102
102
  ### insert
103
103
 
@@ -139,7 +139,7 @@ Output is capped at `limit` matched lines, 2000 rows, and 50KB of text, whicheve
139
139
 
140
140
  `undo_last_change` reverts the most recent successful `replace` or `insert` on a file, restoring the exact previous content, BOM and line endings included, plus the previous anchors.
141
141
 
142
- - History is per-file and single-level: only the most recent `replace` or `insert` can be reverted.
142
+ - History is per-file and single-level: only the most recent `replace` or `insert` can be reverted. A same-turn batch of `replace`/`insert` calls on one file counts as one entry: one undo reverts the whole batch.
143
143
  - History is persisted and survives session restarts. A failed `write` does not clear it.
144
144
  - Every applied `replace` or `insert` is undoable; the undo record is saved before the edit is written.
145
145
  - A successful `write` clears the history for that file.
@@ -151,7 +151,7 @@ Output is capped at `limit` matched lines, 2000 rows, and 50KB of text, whicheve
151
151
 
152
152
  Auto-read is enabled by default. After a successful `write`, the extension reads the file and appends an `--- Auto-read (hashline anchors) ---` block, so you get fresh `anchor│content` anchors without a separate `read` call.
153
153
 
154
- 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, which are stale after the edit. When the context line next to 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.
154
+ After `replace`, `insert`, and `undo_last_change`, the result shows the post-edit diff. Inside a same-turn batch, only the batch's last call shows the combined diff, headed by a `batch:` line (`batch N:` when several files batch); earlier calls reply `In batch` (`In batch N` when several files batch). 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, which are stale after the edit. When the context line next to 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.
155
155
 
156
156
  Auto-read keeps the same 50KB and 2000-line budget as `read`. Change it in `/hashline-config`; both settings persist across sessions.
157
157
 
@@ -162,7 +162,7 @@ All five tools return machine-readable metadata in `details` alongside the model
162
162
  | Tool | `details` |
163
163
  | --- | --- |
164
164
  | `read` | `truncation` (set when output was truncated), `snapshotId` (a `v2\|path\|ino\|mtime\|ctime\|size` fingerprint), `nextOffset` (use as the next `offset`), and `metrics` with `truncated` and `next_offset`. |
165
- | `replace`, `insert` | `diff` (post-edit diff, capped, with current anchors on `+HASH│` and ` HASH│` rows), `patch` (a standard unified patch for external tools, capped like the diff), `patchTruncated` (true when the patch was cut and can no longer be applied as-is), `firstChangedLine`, `snapshotId`, `classification` (`"noop"` when nothing changed), and `metrics`: `edits_attempted`, `edits_noop`, `warnings`, `classification` (`"applied"` or `"noop"`), `changed_lines` (`{ first, last }`), `added_lines`, `removed_lines`. |
165
+ | `replace`, `insert` | `diff` (post-edit diff, capped, with current anchors on `+HASH│` and ` HASH│` rows; a same-turn batch reports the combined diff on its last call and an empty diff on earlier calls), `patch` (a standard unified patch for external tools, capped like the diff), `patchTruncated` (true when the patch was cut and can no longer be applied as-is), `firstChangedLine`, `snapshotId`, `classification` (`"noop"` when nothing changed), `batch` (`{ id, size, last, total }` marking same-turn batch membership), and `metrics`: `edits_attempted`, `edits_noop`, `warnings`, `classification` (`"applied"` or `"noop"`), `changed_lines` (`{ first, last }`), `added_lines`, `removed_lines`. |
166
166
  | `undo_last_change` | `diff` (the undo diff with restored anchors), `patch`, `patchTruncated`, and `metrics` in the same shape as `replace`. |
167
167
  | `anchor_grep` | `metrics` with `matches` (capped at `limit`), `files`, and `truncated`; `truncation` (the standard pi truncation report) when output was cut; and `linesTruncated` (true when long lines were shown as fragments). |
168
168
 
@@ -181,7 +181,7 @@ Settings live in `~/.config/pi-hashline-edit-pro/config.json`, created when a se
181
181
  "anchorGrepEnabled": true,
182
182
  "requirePath": false,
183
183
  "strictInput": false,
184
- "boundaryDedupEnabled": true
184
+ "boundaryDedupMode": "on"
185
185
  }
186
186
  ```
187
187
 
@@ -230,10 +230,13 @@ Codes starting with `E_` are errors (the operation failed); codes starting with
230
230
  | `[E_UNDO_UNAVAILABLE]` | Undo history could not be persisted to the hash store; the edit was refused and the file was left unchanged. |
231
231
  | `[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. |
232
232
  | `[W_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. |
233
+ | `[E_BOUNDARY_STRICT]` | Strict boundary dedup rejected the edit because replacement lines re-include edge lines; resend without those lines. |
233
234
  | `[E_FILE_TOO_LARGE]` | The file exceeds the 1,353,139-line hashline limit or the 100MB size limit. |
234
235
  | `[E_REGISTRY]` | The anchor registry was not initialized; a serve or edit ran outside an initialized session. |
235
236
  | `[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). |
236
237
  | `[E_PATH_CHANGED]` | A write target changed identity after it was read; the write was refused to avoid following a swapped symlink or overwriting a replacement file. |
238
+ | `[E_BATCH_OVERLAP]` | Batched `replace`/`insert` calls target overlapping ranges; the whole batch was refused with nothing written. Retry with disjoint ranges. |
239
+ | `[E_BATCH_ABORTED]` | A same-turn edit batch aborted (a member failed, or the file changed mid-turn); nothing was written. The first failure is quoted; fix it and retry the batch. |
237
240
  | `[E_UNSAFE_REGEX]` | A grep regex can trigger excessive backtracking; simplify it or search with `literal: true`. |
238
241
 
239
242
  ## Troubleshooting
package/index.ts CHANGED
@@ -16,12 +16,13 @@ import {
16
16
  toggleAnchorGrep,
17
17
  toggleRequirePath,
18
18
  toggleStrictInput,
19
- toggleBoundaryDedup,
19
+ cycleBoundaryDedupMode,
20
20
  } from "./src/config";
21
21
  import { loadHashStore, persistSnapshot, pruneMissing } from "./src/hash-store";
22
22
  import { initRegistry, gcRegistrySidecars, clearRegistry, freeAnchors, markServed as markServedScoped } from "./src/anchor-registry";
23
23
  import { buildServedMap } from "./src/served";
24
24
  import { clearBoundaryBypass } from "./src/boundary-bypass";
25
+ import { finalizeTurn, planAssistantMessage } from "./src/batch";
25
26
  import { currentEditFlags } from "./src/edit-common";
26
27
  import { HashlineConfigOverlay } from "./src/config-ui";
27
28
  import { registerWriteHook } from "./src/write-hook";
@@ -106,7 +107,7 @@ export default function (pi: ExtensionAPI): void {
106
107
  }
107
108
  else if (key === "requirePath") await toggleRequirePath();
108
109
  else if (key === "strictInput") await toggleStrictInput();
109
- else await toggleBoundaryDedup();
110
+ else await cycleBoundaryDedupMode();
110
111
  await refreshEditTools();
111
112
  },
112
113
  });
@@ -126,6 +127,21 @@ export default function (pi: ExtensionAPI): void {
126
127
  ctx.ui.notify(`Anchor claims cleared for this session`, "info");
127
128
  },
128
129
  });
130
+ pi.on("message_end", async (event, ctx) => {
131
+ try {
132
+ await planAssistantMessage(event.message, ctx.cwd);
133
+ } catch (error) {
134
+ console.error("Failed to plan edit batch:", error);
135
+ }
136
+ });
137
+ pi.on("turn_end", async (event) => {
138
+ try {
139
+ const ids = (event.toolResults ?? []).map((result) => (result as { toolCallId?: unknown }).toolCallId).filter((id): id is string => typeof id === "string");
140
+ await finalizeTurn(ids);
141
+ } catch (error) {
142
+ console.error("Failed to finalize edit batch:", error);
143
+ }
144
+ });
129
145
  pi.on("tool_result", async (event, ctx) => {
130
146
  if (event.isError) return;
131
147
 
@@ -191,6 +207,8 @@ export default function (pi: ExtensionAPI): void {
191
207
  const metrics = (event.details as { metrics?: RMetrics } | undefined)?.metrics;
192
208
  if (metrics?.classification === "noop") return;
193
209
 
210
+ const batched = (event.details as { batch?: { last?: boolean } } | undefined)?.batch;
211
+ if (batched?.last === false) return;
194
212
  const toolDetails = event.details as ReplaceDetails | undefined;
195
213
  const diff = toolDetails?.diff;
196
214
  const detailWarnings = Array.isArray(toolDetails?.warnings) ? toolDetails.warnings.filter((w): w is string => typeof w === "string") : [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-hashline-edit-pro",
3
- "version": "4.1.0",
3
+ "version": "4.2.0",
4
4
  "type": "module",
5
5
  "description": "Hash-anchored read/replace/insert/grep tools for pi-coding-agent. Every line gets a unique 4-char tokenizer-friendly anchor that stays stable across edits; stale or ambiguous anchors are rejected, never fuzzy-matched. Undo persists across restarts.",
6
6
  "main": "index.ts",
@@ -1 +1,2 @@
1
1
  - `insert`: the anchor must have been shown by `read`, a post-edit diff (`+anchor│`/` anchor│`), or any served `anchor│content` row. Empty file: `read` shows one `anchor│` row — insert `after` it.
2
+ - `insert`: same-file calls in one message join the file's batch: earlier calls reply `In batch` (`In batch N` when several files batch), the last call shows the combined diff.
package/prompts/insert.md CHANGED
@@ -1 +1 @@
1
- Insert lines after or before one existing line in a text file, addressed by a bare anchor from read output or a diff row. The anchor line is preserved: `lines` go after it with `direction: "after"` or before it with `direction: "before"`, one string per line, no anchor prefixes, no embedded newlines. Lines are added literally, even when they duplicate neighbors.
1
+ Insert lines after or before one existing line in a text file, addressed by a bare anchor from read output or a diff row. The anchor line is preserved: `lines` go after it with `direction: "after"` or before it with `direction: "before"`, one string per line, no anchor prefixes, no embedded newlines. Lines are added literally, even when they duplicate neighbors. Multiple `replace`/`insert` calls on the same file in one message form one batch per file with a single combined diff and a single undo.
@@ -1,4 +1,5 @@
1
1
  - `replace`: edit with `replace`/`insert`, not `sed -i` or heredocs — anchor edits are verified against what was shown and undoable.
2
2
  - `replace`: `replacement_lines` takes bare lines without `│`; `[""]` is one blank line; pasted `anchor│` prefixes are stripped automatically (single line: same anchor for `remove_from` and `remove_to`).
3
- - `replace`: post-edit diff `+anchor│`/` anchor│` rows are fresh anchors for the next edit — no new `read` needed. One edit per turn; check the diff before the next edit on that file.
3
+ - `replace`: post-edit diff `+anchor│`/` anchor│` rows are fresh anchors for the next edit — no new `read` needed. Same-file calls in one message form one batch with a single combined diff; check each batch diff before the next turn's edits on that file.
4
+ - `replace`: batched calls must target disjoint ranges and all be valid; an overlap or any failure aborts the whole batch with nothing applied.
4
5
  - `replace`: if `replacement_lines` re-include the boundary line adjacent to the range, it is deduplicated automatically, shown as `dedup│content` rows in the diff (not editable, never use `dedup` as an anchor).
@@ -1 +1 @@
1
- Replace a range of lines (or a single line) in a text file, targeted by 4-character anchors from read output. Give `remove_from` and `remove_to` as bare anchors marking the first and last line to remove, and `replacement_lines` as one string per new line with no anchor prefixes and no embedded newlines; `[]` deletes the range. Every line in the range must match what was last shown; if the file drifted, the edit is refused and the current range is returned with fresh anchors, so retry without re-reading. Anchor follow-up edits on the `+anchor│` and ` anchor│` rows of the post-edit diff instead of re-reading.
1
+ Replace a range of lines (or a single line) in a text file, targeted by 4-character anchors from read output. Give `remove_from` and `remove_to` as bare anchors marking the first and last line to remove, and `replacement_lines` as one string per new line with no anchor prefixes and no embedded newlines; `[]` deletes the range. Every line in the range must match what was last shown; if the file drifted, the edit is refused and the current range is returned with fresh anchors, so retry without re-reading. Anchor follow-up edits on the `+anchor│` and ` anchor│` rows of the post-edit diff instead of re-reading. Multiple `replace`/`insert` calls on the same file in one message form one batch per file: earlier calls reply `In batch` (`In batch N` when several files batch) and the last call shows the combined diff, with one undo for the whole batch.
@@ -187,7 +187,7 @@ export function mintAnchor(state: SessionState): string {
187
187
  }
188
188
  }
189
189
  throw new Error(
190
- `${ANCHOR_POOL_EXHAUSTED_PREFIX}; free anchors with /clear-anchors or use write for very large files.`,
190
+ `${ANCHOR_POOL_EXHAUSTED_PREFIX}; use write for very large files.`,
191
191
  );
192
192
  }
193
193
 
@@ -514,12 +514,8 @@ export async function allocateFileAnchors(
514
514
  const lines = splitLines(content);
515
515
  const checksums = lines.map((line) => contentChecksum(hashSource(line)));
516
516
  if (options?.previous?.spans) {
517
- const sessionState = current()!;
518
517
  const prevChecksums = splitLines(options.previous.content).map((line) => contentChecksum(hashSource(line)));
519
518
  const aligned = alignOwnershipWithSpans(path, options.previous.hashes, prevChecksums, checksums, options.previous.spans, { shadow });
520
- for (let i = 0; i < aligned.anchors.length; i++) {
521
- sessionState.owned.set(aligned.anchors[i]!, { path, checksum: checksums[i]! });
522
- }
523
519
  if (!shadow && options.persist !== false) {
524
520
  persistSnapshot(store, path, content, aligned.anchors, checksums);
525
521
  }