dsh-hashline-edit 0.5.4 → 0.5.6
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 +19 -13
- package/lib/client.js +8 -3
- package/lib/index.js +208 -86
- package/lib/types/dsh/index.d.ts +3 -0
- package/lib/types/src/file-content/preview.d.ts +1 -1
- package/lib/types/src/hashline/anchor-codebook.d.ts +15 -0
- package/lib/types/src/hashline/apply.d.ts +1 -1
- package/lib/types/src/hashline/gutter.d.ts +13 -0
- package/lib/types/src/hashline/hash-identity.d.ts +8 -5
- package/lib/types/src/hashline/row-mode.d.ts +17 -0
- package/lib/types/src/served-session/serve-render.d.ts +6 -0
- package/lib/types/src/store-kernel/constants.d.ts +1 -1
- package/package.json +1 -1
- package/prompts/apply-patch-guidelines.md +2 -2
- package/prompts/codegraph-guidelines.md +2 -2
- package/prompts/diagnostics-guidelines.md +1 -1
- package/prompts/edit-guidelines.md +2 -2
- package/prompts/read-description.md +1 -1
- package/prompts/read-guidelines.md +3 -3
- package/prompts/rg-guidelines.md +2 -2
- package/prompts/write-guidelines.md +2 -2
- package/src/file-content/preview.ts +23 -13
- package/src/hash-store.ts +46 -1
- package/src/hashline/anchor-codebook.ts +19 -0
- package/src/hashline/apply.ts +10 -4
- package/src/hashline/gutter.ts +35 -0
- package/src/hashline/hash-identity.ts +61 -19
- package/src/hashline/parse.ts +3 -2
- package/src/hashline/resolve.ts +7 -5
- package/src/hashline/row-mode.ts +43 -0
- package/src/prompts.ts +3 -1
- package/src/served-session/serve-render.ts +18 -1
- package/src/snapshot-store/vacuum.ts +6 -0
- package/src/store-kernel/constants.ts +1 -1
package/src/hashline/parse.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ANCHOR_LEN, ALPHA_RE, HASH_CLASS } from "./hash-identity.js";
|
|
2
|
+
import { stripLineGutter } from "./gutter.js";
|
|
2
3
|
import { DomainError } from "../domain-errors.js";
|
|
3
4
|
|
|
4
5
|
export type Anchor = { hash: string };
|
|
@@ -22,8 +23,8 @@ function diagPayload(ref: string): { rawAnchor: string; reason: string } {
|
|
|
22
23
|
|
|
23
24
|
if (trimmed.includes("│") && trimmed.includes("\n")) {
|
|
24
25
|
const lines = trimmed.split("\n");
|
|
25
|
-
const first = lines[0] ?? "";
|
|
26
|
-
const last = lines.at(-1) ?? "";
|
|
26
|
+
const first = stripLineGutter(lines[0] ?? "");
|
|
27
|
+
const last = stripLineGutter(lines.at(-1) ?? "");
|
|
27
28
|
// SAFETY: HASH_CLASS is derived from the trusted alphabet at the configured width, bounded linear search — no user-controlled pattern, no ReDoS.
|
|
28
29
|
const hashRe = new RegExp(HASH_CLASS);
|
|
29
30
|
const firstMatch = first.match(hashRe);
|
package/src/hashline/resolve.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { abortIf, rejectUnknownFields } from "../utils.js";
|
|
2
2
|
import { DomainError, formatWarning } from "../domain-errors.js";
|
|
3
3
|
import { HASH_CLASS, HASH_LEN } from "./hash-identity.js";
|
|
4
|
+
import { ROW_GUTTER_PREFIX, stripLineGutter } from "./gutter.js";
|
|
4
5
|
import { parseHashRef, parseText, type Anchor } from "./parse.js";
|
|
5
6
|
import type { ServedRow } from "../served-session/serve-render.js";
|
|
6
7
|
import type { FileSnapshotContext } from "../served-session/serve-render.js";
|
|
@@ -410,14 +411,15 @@ function assertItem(edit: Record<string, unknown>): void {
|
|
|
410
411
|
}
|
|
411
412
|
|
|
412
413
|
// SAFETY: HASH_CLASS is derived from the trusted alphabet at the configured width, linear row prefix — bounded, no user input, no ReDoS.
|
|
413
|
-
const ANCHOR_ROW_RE = new RegExp(`^([+-]?)(${HASH_CLASS})│`);
|
|
414
|
+
const ANCHOR_ROW_RE = new RegExp(`^([+-]?)(?:${ROW_GUTTER_PREFIX})?(${HASH_CLASS})│`);
|
|
414
415
|
function firstHashFromBlock(block: string): string | undefined {
|
|
415
416
|
for (const line of block.split("\n")) {
|
|
416
417
|
const m = line.match(ANCHOR_ROW_RE);
|
|
417
418
|
if (m) return m[2]!;
|
|
418
|
-
//
|
|
419
|
-
|
|
420
|
-
|
|
419
|
+
// WHY: strip the display-only gutter and reject an all-digit run (a line number, never a served
|
|
420
|
+
// WHY: anchor) so a pasted `12: abcd│…` resolves to `abcd`, not the leading digits.
|
|
421
|
+
const bare = stripLineGutter(line).match(new RegExp(HASH_CLASS));
|
|
422
|
+
if (bare && !/^\d+$/.test(bare[0]!)) return bare[0]!;
|
|
421
423
|
}
|
|
422
424
|
return undefined;
|
|
423
425
|
}
|
|
@@ -449,7 +451,7 @@ export function resEdit(edit: HTEdit): HEdit {
|
|
|
449
451
|
} else if (match[1] === "-") {
|
|
450
452
|
reason = `anchor carries a leading "-" marker ("${trimmed}"). Nothing was written; pass the bare ${HASH_LEN}-char anchor and retry.`;
|
|
451
453
|
} else {
|
|
452
|
-
reason = `anchor carries a
|
|
454
|
+
reason = `anchor carries a served-row prefix ("${trimmed}"). Nothing was written; copy only the ${HASH_LEN}-char anchor immediately left of │ and retry.`;
|
|
453
455
|
}
|
|
454
456
|
throw new DomainError("E_MALFORMED_ANCHOR", { rawAnchor: trimmed, reason });
|
|
455
457
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The active line-number gutter mode, shared by every renderer and by the anchor codebook.
|
|
3
|
+
*
|
|
4
|
+
* WHY module state + a setter rather than a load-time constant: the mode is a live plugin setting
|
|
5
|
+
* (the `nativeGutter` Volatile switch). The host re-mounts agents on a volatile update, and the plugin
|
|
6
|
+
* calls `applyConfigRowGutter()` then `configureAnchorSpace()` so the codebook, capacity and anchor
|
|
7
|
+
* generation all follow the switch. Changing it invalidates old anchors (new generation) — the caller
|
|
8
|
+
* opens a fresh session. `PI_BETTER_EDIT_ROW_GUTTER` pins the mode for tests/CI and wins over config.
|
|
9
|
+
*/
|
|
10
|
+
export type RowGutter = "arrow" | "native";
|
|
11
|
+
|
|
12
|
+
export const ROW_GUTTER_ENV_VAR = "PI_BETTER_EDIT_ROW_GUTTER";
|
|
13
|
+
|
|
14
|
+
/** Arrow is the default: it does not merge with the following anchor token. */
|
|
15
|
+
export const ROW_GUTTER_DEFAULT: RowGutter = "arrow";
|
|
16
|
+
|
|
17
|
+
export function resolveRowGutter(env: Record<string, string | undefined>): RowGutter {
|
|
18
|
+
const raw = env[ROW_GUTTER_ENV_VAR];
|
|
19
|
+
if (raw === undefined || raw.trim() === "") return ROW_GUTTER_DEFAULT;
|
|
20
|
+
const value = raw.trim().toLowerCase();
|
|
21
|
+
if (value === "arrow") return "arrow";
|
|
22
|
+
if (value === "native") return "native";
|
|
23
|
+
throw new Error(
|
|
24
|
+
`${ROW_GUTTER_ENV_VAR} must be "arrow" or "native" (got ${JSON.stringify(raw)}).`,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const envPinned = (() => {
|
|
29
|
+
const raw = process.env[ROW_GUTTER_ENV_VAR];
|
|
30
|
+
return raw !== undefined && raw.trim() !== "";
|
|
31
|
+
})();
|
|
32
|
+
|
|
33
|
+
let current: RowGutter = resolveRowGutter(process.env);
|
|
34
|
+
|
|
35
|
+
export function getRowGutter(): RowGutter {
|
|
36
|
+
return current;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Apply a config-driven mode unless the env var is set (tests/CI pin it). */
|
|
40
|
+
export function applyConfigRowGutter(mode: RowGutter): RowGutter {
|
|
41
|
+
if (!envPinned) current = mode;
|
|
42
|
+
return current;
|
|
43
|
+
}
|
package/src/prompts.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
|
|
3
3
|
import { HASH_LEN } from "./hashline/alphabet.js";
|
|
4
|
+
import { getRowGutter } from "./hashline/row-mode.js";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Resolve template variables in shipped prompt prose. Beyond caller-supplied replacements, the
|
|
@@ -14,7 +15,8 @@ function applyReplacements(content: string, replacements?: Record<string, string
|
|
|
14
15
|
out = out.split(`{{${key}}}`).join(value);
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
+
const withWidth = out.split("{{HASH_LEN}}").join(String(HASH_LEN));
|
|
19
|
+
return withWidth.split("{{GUTTER}}").join(getRowGutter() === "native" ? ": " : "→");
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
export function loadP(relativePath: string, replacements?: Record<string, string>): string {
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
*/
|
|
31
31
|
import { HASH_LEN, HASH_RE } from "../hashline/alphabet.js";
|
|
32
32
|
import { HASH_SEP } from "../hashline/hash-identity.js";
|
|
33
|
+
import { lineGutter as gutterLine, stripLineGutter } from "../hashline/gutter.js";
|
|
33
34
|
import { canonDigest } from "../hashline/hash-identity.js";
|
|
34
35
|
import { SERVED_ROWS_CAP } from "../constants.js";
|
|
35
36
|
import {
|
|
@@ -84,8 +85,22 @@ export function denseServeRows(hashes: readonly string[]): ServedRow[] {
|
|
|
84
85
|
return hashes.map((hash, position) => ({ position, hash }));
|
|
85
86
|
}
|
|
86
87
|
|
|
88
|
+
export function lineGutter(lineNumber: number): string {
|
|
89
|
+
return gutterLine(lineNumber);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* One served row: `12: abc│content`. WHY: line numbers are display-only, never part of the anchor —
|
|
94
|
+
* the anchor stays the HASH immediately left of the separator.
|
|
95
|
+
*/
|
|
96
|
+
export function formatServedRow(lineNumber: number, hash: string, content: string): string {
|
|
97
|
+
return `${lineGutter(lineNumber)}${hash}${HASH_SEP}${content}`;
|
|
98
|
+
}
|
|
99
|
+
|
|
87
100
|
export function fmtServedRows(rows: ServedRow[], fileLines: string[]): string {
|
|
88
|
-
return rows
|
|
101
|
+
return rows
|
|
102
|
+
.map((row) => formatServedRow(row.position + 1, row.hash, fileLines[row.position] ?? ""))
|
|
103
|
+
.join("\n");
|
|
89
104
|
}
|
|
90
105
|
|
|
91
106
|
// WHY: the one continuation a rejected edit offers (read-chrome): the `windows` offset, not a bare
|
|
@@ -448,6 +463,8 @@ function anchorShapeFromLine(line: string): { anchor: string; tail: string } | u
|
|
|
448
463
|
if (text.length > 0 && (text[0] === "+" || text[0] === "-" || text[0] === " ")) {
|
|
449
464
|
text = text.slice(1);
|
|
450
465
|
}
|
|
466
|
+
// WHY: a served row may carry the display-only line-number gutter (`12: `); it is not part of the anchor.
|
|
467
|
+
text = stripLineGutter(text);
|
|
451
468
|
if (text.length < HASH_LEN + 1) return undefined;
|
|
452
469
|
if (text[HASH_LEN] !== HASH_SEP) return undefined;
|
|
453
470
|
const anchor = text.slice(0, HASH_LEN);
|
|
@@ -185,6 +185,12 @@ export function vacuumSnapshots(db: DatabaseSync, options: VacuumOptions = {}):
|
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
if (evict.length > 0) deleteVacuumSnapshots(db, evict);
|
|
188
|
+
try {
|
|
189
|
+
// WHY: with incremental auto-vacuum (set on first upgrade reclaim) this returns freed TTL pages cheaply.
|
|
190
|
+
db.exec("PRAGMA incremental_vacuum");
|
|
191
|
+
} catch {
|
|
192
|
+
// best-effort: a legacy auto_vacuum=0 store reclaims on the next slow open instead.
|
|
193
|
+
}
|
|
188
194
|
const deferredBytes = Math.max(0, total - VACUUM_GLOBAL_BUDGET_BYTES);
|
|
189
195
|
return {
|
|
190
196
|
evicted: evict.length,
|
|
@@ -29,7 +29,7 @@ export const HASH_STORE_BUSY_TIMEOUT = 250;
|
|
|
29
29
|
// WHY: needs to stay covered. Without it every materialization re-scanned each path's lease set.
|
|
30
30
|
// WHY: v11 adds `file_snapshots.stat_key` plus `idx_snapshots_path_stat` — the stat identity a read
|
|
31
31
|
// WHY: materialization saw, so an unchanged file's next read adopts on `stat(2)` alone (ADR-0043).
|
|
32
|
-
export const HASH_STORE_VERSION =
|
|
32
|
+
export const HASH_STORE_VERSION = 12;
|
|
33
33
|
|
|
34
34
|
const BUSY_MAX_ATTEMPTS = 8;
|
|
35
35
|
const BUSY_BACKOFF_BASE_MS = 50;
|