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/README.md
CHANGED
|
@@ -27,14 +27,20 @@ The anchor width is baked into the build. Set `PI_BETTER_EDIT_ANCHOR_WIDTH` when
|
|
|
27
27
|
|
|
28
28
|
| Value | Anchor width | Usable space | Anchor generation |
|
|
29
29
|
| --- | --- | --- | --- |
|
|
30
|
-
| unset (default) | 3 chars |
|
|
30
|
+
| unset (default) | 3 chars | 157,943 (2-token codebook) | 3 |
|
|
31
31
|
| `4` | 4 chars | 14,766,336 | 1 |
|
|
32
32
|
|
|
33
33
|
The value is inlined into the bundle at build time (`esbuild define`), so the installed plugin never reads an environment variable at runtime — a 3-char build stays 3-char. The persisted store is keyed by the anchor generation, so changing the build width is a hard cache miss (served rows are simply re-read), never a cross-width hit. Width 4 keeps generation 1, so existing stores keep working unchanged.
|
|
34
34
|
|
|
35
35
|
Prompt prose is width-neutral: shipped prompt files use the `{{HASH_LEN}}` placeholder, resolved from the baked width, so a 3-char and a 4-char build each expose their own width through every prompt and guidance surface.
|
|
36
36
|
|
|
37
|
-
Measured on the DeepSeek-V4.1 tokenizer,
|
|
37
|
+
Measured on the DeepSeek-V4.1 tokenizer, every width-3 anchor is exactly two tokens (the codebook admits only the 157,943 two-token spellings) and a width-4 anchor averages ~3.0 tokens per served line (see [ADR-0034](docs/adr/0034-line-number-gutter-and-two-token-codebook.md)). The default is 3; build with `PI_BETTER_EDIT_ANCHOR_WIDTH=4` to ship the 4-char artifact, whose generation-1 store keeps existing rows valid.
|
|
38
|
+
|
|
39
|
+
### Line-number gutter and the 2-token codebook
|
|
40
|
+
|
|
41
|
+
Every served row is prefixed by a **display-only line-number gutter** — `12→` by default (line number, then U+2192), or `12: ` in the opt-in **native** gutter. The gutter is presentation only: the anchor is the build-width characters immediately left of `│`, and the gutter never participates in addressing. `PI_BETTER_EDIT_ROW_GUTTER` selects `arrow` (default) or `native`; native exists only for A/B measurement, because `12: ` merges with the anchor's first token for about 23% of anchors (only ~77% keep the two-token boundary, versus 100% with `12→`).
|
|
42
|
+
|
|
43
|
+
At width 3 the served anchors are drawn only from the **157,943 base62 three-character spellings that tokenize to exactly two tokens** on DeepSeek-V4.1 (a subset of the 238,328 total `62^3` spellings), so every anchor reads as a stable two-token unit. Width 4 keeps the historical rule (the all-digit sub-cube stays reserved; `62^4 − 10^4 = 14,766,336` usable). The width-3 generation is `3` (width 4 stays `1`), so a width-3 build is a one-time hard cache miss — existing width-3 anchors and stores are re-read once.
|
|
38
44
|
|
|
39
45
|
## Install
|
|
40
46
|
|
|
@@ -64,19 +70,19 @@ The bundle ships `lib/index.js` plus `lib/types/**`; `prompts/` must sit next to
|
|
|
64
70
|
|
|
65
71
|
## The anchored model
|
|
66
72
|
|
|
67
|
-
A served read looks like this (`│` is U+2502, the separator):
|
|
73
|
+
A served read looks like this (`12→` is the display-only line-number gutter; `│` is U+2502, the separator):
|
|
68
74
|
|
|
69
75
|
```text
|
|
70
|
-
ve7│function calculateTotal(items: CartItem[]): number {
|
|
71
|
-
szJ│ let total = 0;
|
|
72
|
-
kQm│ for (const item of items) {
|
|
73
|
-
m2z│ total += item.price;
|
|
74
|
-
d2x│ }
|
|
75
|
-
p9r│ return total;
|
|
76
|
-
a1b│}
|
|
76
|
+
1→ve7│function calculateTotal(items: CartItem[]): number {
|
|
77
|
+
2→szJ│ let total = 0;
|
|
78
|
+
3→kQm│ for (const item of items) {
|
|
79
|
+
4→m2z│ total += item.price;
|
|
80
|
+
5→d2x│ }
|
|
81
|
+
6→p9r│ return total;
|
|
82
|
+
7→a1b│}
|
|
77
83
|
```
|
|
78
84
|
|
|
79
|
-
Copy only the build-width characters
|
|
85
|
+
Copy only the build-width characters immediately left of `│` — the segment between the display-only line-number gutter and `│` (3 by default; 4 in a 4-char build); the gutter is never part of an anchor. `edit` passes them as `anchor_from`, plus `anchor_to` only when the range spans more than one line; `apply_patch` writes them as `@@<anchor>` for one row or `@@<from>-<to>` for a span. Both forms target an inclusive served range; a successful call returns a diff whose modified and context rows carry fresh anchors:
|
|
80
86
|
|
|
81
87
|
```text
|
|
82
88
|
- szJ│ let total = 0;
|
|
@@ -140,9 +146,9 @@ read({
|
|
|
140
146
|
})
|
|
141
147
|
```
|
|
142
148
|
|
|
143
|
-
- **Served mode** returns one `HASH│content`
|
|
149
|
+
- **Served mode** returns one row per line — a display-only line-number gutter (`12→` by default, `12: ` in the native gutter), then `HASH│content` — and records every shown row as a lease for this session. A windowed read also includes a `[Lines A-B of N total]` page header. Every row shown is usable by one subsequent `apply_patch` or `edit`, even when the windows are far apart.
|
|
144
150
|
- **Verbatim mode** returns the same page as plain text with no anchors and serves nothing; an `apply_patch` identity hunk or an `edit` item cannot target those lines.
|
|
145
|
-
- **Folded mode** is the whole-file structural skeleton (`mode: "folded"`): one row per syntax item in file order, the item's opening line verbatim, and the item's first and last anchors — `HASH│opening line` for a single-line item, `HASH1..HASH2│opening line` for a multi-line one. An item is the language's decorated scope (wrapper plus leading doc comment), so a whole-item replacement owns the docs too. Lines no retained item covers collapse into ONE gap row per contiguous run, `HASH1..HASH2│… (N lines) …`: the edges are served, the interior is not. `foldDepth` (1–3, default 1) sets the fold depth; it is refused unless `mode: "folded"`, and `offset`/`limit`/`windows` are refused with folded (`E_BAD_PAYLOAD`). The page header is `[Folded view, N items, M lines elided: file (X lines total)]`. Folded is fail-open: no grammar, a cold grammar, a parse failure or an empty file fall back to the ordinary served page with one note row naming the reason — never a guessed anchor ([ADR-0029](docs/adr/0029-folded-read-mode-and-range-rows.md)).
|
|
151
|
+
- **Folded mode** is the whole-file structural skeleton (`mode: "folded"`): one row per syntax item in file order, the item's opening line verbatim, and the item's first and last anchors — `12→HASH│opening line` for a single-line item, `12..30→HASH1..HASH2│opening line` for a multi-line one (the `12→` / `12..30→` prefix is a display-only line-number gutter). An item is the language's decorated scope (wrapper plus leading doc comment), so a whole-item replacement owns the docs too. Lines no retained item covers collapse into ONE gap row per contiguous run, `12..30→HASH1..HASH2│… (N lines) …`: the edges are served, the interior is not. `foldDepth` (1–3, default 1) sets the fold depth; it is refused unless `mode: "folded"`, and `offset`/`limit`/`windows` are refused with folded (`E_BAD_PAYLOAD`). The page header is `[Folded view, N items, M lines elided: file (X lines total)]`. Folded is fail-open: no grammar, a cold grammar, a parse failure or an empty file fall back to the ordinary served page with one note row naming the reason — never a guessed anchor ([ADR-0029](docs/adr/0029-folded-read-mode-and-range-rows.md)).
|
|
146
152
|
- A small requested window — up to 61 lines after folding — may widen to its enclosing function, method, class, section or paragraph; a `[widened …]` note names the block that was served. Expansion applies in both modes. Languages: TypeScript/TSX, Python, Go, Rust, Java and Vue through pinned tree-sitter wasm grammars (all seven ship inside the package under `grammars/` and are verified against a committed SHA-256; the lazy download only covers a manifest entry with no shipped asset), plus Bash through the existing `unbash` parser (no wasm). Vue widens a top-level `template`/`script`/`style` block without parsing embedded JS/TS. SQL is not supported: real migrations largely fail to parse and `.tql` is a Java template, not SQL (see [`docs/spec/sql-vue-feasibility-gate.md`](docs/spec/sql-vue-feasibility-gate.md)).
|
|
147
153
|
- `offset`/`limit` and `windows` are page requests, not anchors: only anchored output grants a mutation lease, and `folded` is whole-file, so it accepts none of the three.
|
|
148
154
|
|
package/lib/client.js
CHANGED
|
@@ -33,7 +33,8 @@ var SWITCHES = [
|
|
|
33
33
|
{ key: "applyPatch", label: "swApplyPatch", hint: "swApplyPatchHint", fallback: true },
|
|
34
34
|
{ key: "edit", label: "swEdit", hint: "swEditHint", fallback: false },
|
|
35
35
|
{ key: "codegraph", label: "swCodegraph", hint: "swCodegraphHint", fallback: false },
|
|
36
|
-
{ key: "diagnostics", label: "swDiagnostics", hint: "swDiagnosticsHint", fallback: false }
|
|
36
|
+
{ key: "diagnostics", label: "swDiagnostics", hint: "swDiagnosticsHint", fallback: false },
|
|
37
|
+
{ key: "nativeGutter", label: "swNativeGutter", hint: "swNativeGutterHint", fallback: false }
|
|
37
38
|
];
|
|
38
39
|
var en = {
|
|
39
40
|
swRead: "Read (shadow the host read)",
|
|
@@ -55,7 +56,9 @@ var en = {
|
|
|
55
56
|
rejected: "The host refused this save; reset and review your changes.",
|
|
56
57
|
loading: "Loading host settings\u2026",
|
|
57
58
|
unavailable: "Enable this row with the built-in switch to edit its settings.",
|
|
58
|
-
rowSummary: "Read, apply_patch, edit, codegraph and diagnostics switches."
|
|
59
|
+
rowSummary: "Read, apply_patch, edit, codegraph and diagnostics switches.",
|
|
60
|
+
swNativeGutter: "Native line-number gutter (A/B)",
|
|
61
|
+
swNativeGutterHint: "Render served rows as `12: HASH\u2502content` (host read style) instead of the default `12\u2192HASH\u2502content`. Native needs the smaller strictly-separated 2-token codebook (21,330 vs 157,943) and invalidates old anchors \u2014 open a new session after switching."
|
|
59
62
|
};
|
|
60
63
|
var zh = {
|
|
61
64
|
swRead: "\u8BFB\u53D6\uFF08\u906E\u853D\u5BBF\u4E3B read\uFF09",
|
|
@@ -77,7 +80,9 @@ var zh = {
|
|
|
77
80
|
rejected: "\u5BBF\u4E3B\u62D2\u7EDD\u4E86\u6B64\u6B21\u4FDD\u5B58\uFF1B\u8BF7\u91CD\u7F6E\u540E\u91CD\u65B0\u68C0\u67E5\u66F4\u6539\u3002",
|
|
78
81
|
loading: "\u6B63\u5728\u52A0\u8F7D\u5BBF\u4E3B\u8BBE\u7F6E\u2026",
|
|
79
82
|
unavailable: "\u8BF7\u5148\u7528\u5185\u7F6E\u5F00\u5173\u542F\u7528\u6B64\u884C\u540E\u518D\u7F16\u8F91\u8BBE\u7F6E\u3002",
|
|
80
|
-
rowSummary: "\u8BFB\u53D6\u3001apply_patch\u3001\u533A\u95F4\u7F16\u8F91\u3001codegraph \u4E0E diagnostics \u5F00\u5173\u3002"
|
|
83
|
+
rowSummary: "\u8BFB\u53D6\u3001apply_patch\u3001\u533A\u95F4\u7F16\u8F91\u3001codegraph \u4E0E diagnostics \u5F00\u5173\u3002",
|
|
84
|
+
swNativeGutter: "\u539F\u751F\u884C\u53F7\uFF08A/B \u5B9E\u6D4B\uFF09",
|
|
85
|
+
swNativeGutterHint: "\u670D\u52A1\u884C\u6E32\u67D3\u4E3A `12: HASH\u2502content`\uFF08\u5BBF\u4E3B read \u98CE\u683C\uFF09\uFF0C\u66FF\u4EE3\u9ED8\u8BA4\u7684 `12\u2192HASH\u2502content`\u3002\u539F\u751F\u9700\u66F4\u5C0F\u7684\u201C\u4E25\u683C\u5206\u79BB\u201D2-token \u7801\u672C\uFF0821,330 vs 157,943\uFF09\uFF0C\u4E14\u4F1A\u8BA9\u65E7\u951A\u70B9\u5931\u6548\u2014\u2014\u5207\u6362\u540E\u8BF7\u5F00\u65B0\u4F1A\u8BDD\u3002"
|
|
81
86
|
};
|
|
82
87
|
var CSS = `
|
|
83
88
|
.hashline-settings { display:flex; flex-direction:column; gap:12px; font:inherit; color:var(--dsw-alias-label-primary,#222); }
|