pi-hashline-edit-pro 4.1.0 → 4.2.1
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 +12 -8
- package/index.ts +27 -5
- package/package.json +1 -1
- package/prompts/insert-guidelines.md +1 -0
- package/prompts/insert.md +1 -1
- package/prompts/replace-guidelines.md +2 -1
- package/prompts/replace.md +1 -1
- package/src/anchor-registry.ts +6 -6
- package/src/batch.ts +615 -0
- package/src/commit.ts +3 -2
- package/src/config-ui.ts +58 -11
- package/src/config.ts +49 -8
- package/src/edit-common.ts +14 -12
- package/src/grep.ts +1 -1
- package/src/hashline/apply.ts +128 -84
- package/src/hashline/index.ts +3 -0
- package/src/insert.ts +61 -51
- package/src/payload-contract.ts +30 -2
- package/src/replace-response.ts +2 -2
- package/src/replace-undo.ts +3 -2
- package/src/replace.ts +65 -25
- package/src/write-hook.ts +2 -2
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
|
-
|
|
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,9 +151,9 @@ 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
|
-
Auto-read keeps the same 50KB and 2000-line budget as `read`. Change it in `/hashline-config`; both settings persist across sessions.
|
|
156
|
+
Auto-read keeps the same 50KB and 2000-line budget as `read`. Change it in `/hashline-config`; both settings persist across sessions. The post-edit diff shows 1 surrounding line by default; change Diff context in `/hashline-config` (0-10, needs Auto-read) to show more or fewer.
|
|
157
157
|
|
|
158
158
|
## Tool result details
|
|
159
159
|
|
|
@@ -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
|
|
|
@@ -170,7 +170,7 @@ All five tools return machine-readable metadata in `details` alongside the model
|
|
|
170
170
|
|
|
171
171
|
| Command | Description |
|
|
172
172
|
| --- | --- |
|
|
173
|
-
| `/hashline-config` | Open the settings window: auto-read anchors, `anchor_grep` tool, required `path`, strict input, and boundary dedup. Persists across sessions. |
|
|
173
|
+
| `/hashline-config` | Open the settings window: auto-read anchors, diff context lines, `anchor_grep` tool, required `path`, strict input, and boundary dedup. Persists across sessions. |
|
|
174
174
|
| `/clear-anchors` | Clear the session's anchor claims. Anchors are re-claimed on the next `read`. |
|
|
175
175
|
|
|
176
176
|
Settings live in `~/.config/pi-hashline-edit-pro/config.json`, created when a setting is first changed in `/hashline-config`:
|
|
@@ -181,7 +181,8 @@ 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
|
-
"
|
|
184
|
+
"boundaryDedupMode": "on",
|
|
185
|
+
"diffContextLines": 1
|
|
185
186
|
}
|
|
186
187
|
```
|
|
187
188
|
|
|
@@ -230,10 +231,13 @@ Codes starting with `E_` are errors (the operation failed); codes starting with
|
|
|
230
231
|
| `[E_UNDO_UNAVAILABLE]` | Undo history could not be persisted to the hash store; the edit was refused and the file was left unchanged. |
|
|
231
232
|
| `[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
233
|
| `[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. |
|
|
234
|
+
| `[E_BOUNDARY_STRICT]` | Strict boundary dedup rejected the edit because replacement lines re-include edge lines; resend without those lines. |
|
|
233
235
|
| `[E_FILE_TOO_LARGE]` | The file exceeds the 1,353,139-line hashline limit or the 100MB size limit. |
|
|
234
236
|
| `[E_REGISTRY]` | The anchor registry was not initialized; a serve or edit ran outside an initialized session. |
|
|
235
237
|
| `[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
238
|
| `[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. |
|
|
239
|
+
| `[E_BATCH_OVERLAP]` | Batched `replace`/`insert` calls target overlapping ranges; the whole batch was refused with nothing written. Retry with disjoint ranges. |
|
|
240
|
+
| `[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
241
|
| `[E_UNSAFE_REGEX]` | A grep regex can trigger excessive backtracking; simplify it or search with `literal: true`. |
|
|
238
242
|
|
|
239
243
|
## Troubleshooting
|
package/index.ts
CHANGED
|
@@ -16,12 +16,14 @@ import {
|
|
|
16
16
|
toggleAnchorGrep,
|
|
17
17
|
toggleRequirePath,
|
|
18
18
|
toggleStrictInput,
|
|
19
|
-
|
|
19
|
+
cycleBoundaryDedupMode,
|
|
20
|
+
adjustDiffContextLines,
|
|
20
21
|
} from "./src/config";
|
|
21
22
|
import { loadHashStore, persistSnapshot, pruneMissing } from "./src/hash-store";
|
|
22
23
|
import { initRegistry, gcRegistrySidecars, clearRegistry, freeAnchors, markServed as markServedScoped } from "./src/anchor-registry";
|
|
23
24
|
import { buildServedMap } from "./src/served";
|
|
24
25
|
import { clearBoundaryBypass } from "./src/boundary-bypass";
|
|
26
|
+
import { finalizeTurn, planAssistantMessage } from "./src/batch";
|
|
25
27
|
import { currentEditFlags } from "./src/edit-common";
|
|
26
28
|
import { HashlineConfigOverlay } from "./src/config-ui";
|
|
27
29
|
import { registerWriteHook } from "./src/write-hook";
|
|
@@ -30,6 +32,8 @@ import { loadFileKindAndText } from "./src/file-kind";
|
|
|
30
32
|
import { resolveInCwd } from "./src/fs-write";
|
|
31
33
|
import { valAccess } from "./src/validation";
|
|
32
34
|
import { splitLines } from "./src/utils";
|
|
35
|
+
import { hashSource } from "./src/hashline";
|
|
36
|
+
import { contentChecksum } from "./src/hashline/hasher";
|
|
33
37
|
|
|
34
38
|
export default function (pi: ExtensionAPI): void {
|
|
35
39
|
regRead(pi);
|
|
@@ -86,7 +90,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
86
90
|
});
|
|
87
91
|
|
|
88
92
|
pi.registerCommand("hashline-config", {
|
|
89
|
-
description: "Open the hashline settings window (auto-read, grep, path, strict input, dedup)",
|
|
93
|
+
description: "Open the hashline settings window (auto-read, diff context, grep, path, strict input, dedup)",
|
|
90
94
|
handler: async (_args, ctx) => {
|
|
91
95
|
if (!ctx.hasUI) {
|
|
92
96
|
ctx.ui.notify("/hashline-config requires interactive mode", "error");
|
|
@@ -97,8 +101,9 @@ export default function (pi: ExtensionAPI): void {
|
|
|
97
101
|
tui,
|
|
98
102
|
theme,
|
|
99
103
|
done,
|
|
100
|
-
onToggle: async (key) => {
|
|
104
|
+
onToggle: async (key, delta) => {
|
|
101
105
|
if (key === "autoRead") autoRead = await toggleAutoRead();
|
|
106
|
+
else if (key === "diffContextLines") await adjustDiffContextLines(delta ?? 1);
|
|
102
107
|
else if (key === "anchorGrepEnabled") {
|
|
103
108
|
const enabled = await toggleAnchorGrep();
|
|
104
109
|
const active = pi.getActiveTools();
|
|
@@ -106,7 +111,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
106
111
|
}
|
|
107
112
|
else if (key === "requirePath") await toggleRequirePath();
|
|
108
113
|
else if (key === "strictInput") await toggleStrictInput();
|
|
109
|
-
else await
|
|
114
|
+
else await cycleBoundaryDedupMode();
|
|
110
115
|
await refreshEditTools();
|
|
111
116
|
},
|
|
112
117
|
});
|
|
@@ -126,6 +131,21 @@ export default function (pi: ExtensionAPI): void {
|
|
|
126
131
|
ctx.ui.notify(`Anchor claims cleared for this session`, "info");
|
|
127
132
|
},
|
|
128
133
|
});
|
|
134
|
+
pi.on("message_end", async (event, ctx) => {
|
|
135
|
+
try {
|
|
136
|
+
await planAssistantMessage(event.message, ctx.cwd);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
console.error("Failed to plan edit batch:", error);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
pi.on("turn_end", async (event) => {
|
|
142
|
+
try {
|
|
143
|
+
const ids = (event.toolResults ?? []).map((result) => (result as { toolCallId?: unknown }).toolCallId).filter((id): id is string => typeof id === "string");
|
|
144
|
+
await finalizeTurn(ids);
|
|
145
|
+
} catch (error) {
|
|
146
|
+
console.error("Failed to finalize edit batch:", error);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
129
149
|
pi.on("tool_result", async (event, ctx) => {
|
|
130
150
|
if (event.isError) return;
|
|
131
151
|
|
|
@@ -161,7 +181,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
161
181
|
DEFAULT_MAX_LINES,
|
|
162
182
|
);
|
|
163
183
|
const fileLines = splitLines(normalized);
|
|
164
|
-
persistSnapshot(await loadHashStore(), absolutePath, normalized, fileHashes);
|
|
184
|
+
persistSnapshot(await loadHashStore(), absolutePath, normalized, fileHashes, fileLines.map((line) => contentChecksum(hashSource(line))));
|
|
165
185
|
markServedScoped(absolutePath, buildServedMap(fileHashes, fileLines, preview.servedHashes), new Set(fileHashes));
|
|
166
186
|
return {
|
|
167
187
|
content: [
|
|
@@ -191,6 +211,8 @@ export default function (pi: ExtensionAPI): void {
|
|
|
191
211
|
const metrics = (event.details as { metrics?: RMetrics } | undefined)?.metrics;
|
|
192
212
|
if (metrics?.classification === "noop") return;
|
|
193
213
|
|
|
214
|
+
const batched = (event.details as { batch?: { last?: boolean } } | undefined)?.batch;
|
|
215
|
+
if (batched?.last === false) return;
|
|
194
216
|
const toolDetails = event.details as ReplaceDetails | undefined;
|
|
195
217
|
const diff = toolDetails?.diff;
|
|
196
218
|
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
|
|
3
|
+
"version": "4.2.1",
|
|
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.
|
|
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).
|
package/prompts/replace.md
CHANGED
|
@@ -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.
|
package/src/anchor-registry.ts
CHANGED
|
@@ -65,6 +65,7 @@ export function foldRegistryEvents(events: RegistryEvent[]): SessionState {
|
|
|
65
65
|
} else if (event.kind === "allocate") {
|
|
66
66
|
for (const [anchor, checksum] of event.rows) {
|
|
67
67
|
state.owned.set(anchor, { path: event.path, checksum });
|
|
68
|
+
state.everMinted.add(anchor);
|
|
68
69
|
}
|
|
69
70
|
} else if (event.kind === "free") {
|
|
70
71
|
if (event.anchors) {
|
|
@@ -187,7 +188,7 @@ export function mintAnchor(state: SessionState): string {
|
|
|
187
188
|
}
|
|
188
189
|
}
|
|
189
190
|
throw new Error(
|
|
190
|
-
`${ANCHOR_POOL_EXHAUSTED_PREFIX};
|
|
191
|
+
`${ANCHOR_POOL_EXHAUSTED_PREFIX}; use write for very large files.`,
|
|
191
192
|
);
|
|
192
193
|
}
|
|
193
194
|
|
|
@@ -514,12 +515,8 @@ export async function allocateFileAnchors(
|
|
|
514
515
|
const lines = splitLines(content);
|
|
515
516
|
const checksums = lines.map((line) => contentChecksum(hashSource(line)));
|
|
516
517
|
if (options?.previous?.spans) {
|
|
517
|
-
const sessionState = current()!;
|
|
518
518
|
const prevChecksums = splitLines(options.previous.content).map((line) => contentChecksum(hashSource(line)));
|
|
519
519
|
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
520
|
if (!shadow && options.persist !== false) {
|
|
524
521
|
persistSnapshot(store, path, content, aligned.anchors, checksums);
|
|
525
522
|
}
|
|
@@ -545,9 +542,12 @@ export async function allocateFileAnchors(
|
|
|
545
542
|
: (() => {
|
|
546
543
|
const state = shadow ? cloneState(current()!) : current()!;
|
|
547
544
|
const reuseIndex = fingerprintIndex(state, path);
|
|
545
|
+
const reuseTaken = new Map<string, number>();
|
|
548
546
|
const anchors: string[] = checksums.map((checksum) => {
|
|
549
547
|
const candidates = reuseIndex.get(checksum) ?? [];
|
|
550
|
-
const
|
|
548
|
+
const taken = reuseTaken.get(checksum) ?? 0;
|
|
549
|
+
reuseTaken.set(checksum, taken + 1);
|
|
550
|
+
const anchor = taken < candidates.length ? candidates[taken]! : mintAnchor(state);
|
|
551
551
|
state.everMinted.add(anchor);
|
|
552
552
|
state.owned.set(anchor, { path, checksum });
|
|
553
553
|
return anchor;
|