dsh-hashline-edit 0.3.11 → 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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Hash-anchored file editing for [DeepSeek Harness](https://github.com/deepseek-ai) (dsh) on Windows.
4
4
 
5
- `dsh-hashline-edit` is a dsh bundle that shadows the host's built-in `read` with hash-anchored output, registers `apply_patch` for precise and batch text changes, and adds `undo_last_edit`. The host's built-in `write` stays visible and is integrated by the write hook; the native `edit`/`str_replace_editor` surface is hidden; there is no pi host support, because this package targets DeepSeek Harness only. Every line a served read shows carries a stable 3- or 4-character base62 anchor (`A–Z`, `a–z`, `0–9`; the width is a build-time setting, see [Anchor width](#anchor-width)) derived from the file's canonical path and the line's content. An `apply_patch` hunk either names served anchors or matches file content; the model never re-types existing code. Anchors for unchanged lines stay stable across edits, and every successful `apply_patch` call returns fresh anchors for the changed lines, so chained calls need no re-read.
5
+ `dsh-hashline-edit` is a dsh bundle that shadows the host's built-in `read` with hash-anchored output and offers two write tools over the same served rows: `apply_patch` for Codex patch documents and `edit` for anchored range edits. The host's built-in `write` stays visible and is integrated by the write hook; while either plugin write tool is registered, the native `edit`/`str_replace_editor`/`apply_patch` surface is hidden. There is no pi host support, because this package targets DeepSeek Harness only. Every line a served read shows carries a stable 3- or 4-character base62 anchor (`A–Z`, `a–z`, `0–9`; the width is a build-time setting, see [Anchor width](#anchor-width)) derived from the file's canonical path and the line's content. `apply_patch` hunks either name served anchors or match file content; every `edit` item names served anchors. The model never re-types existing code. Anchors for unchanged lines stay stable across edits, and every successful mutation returns fresh anchors for the changed lines, so chained calls need no re-read.
6
6
 
7
7
  The semantic core is the [pi-better-edit](https://github.com/Rianico/pi-better-edit) v2.16.0 hashline engine (MIT), carried as an internal engine; the pi host integration has been removed. The `dsh/` tree is this repository's DeepSeek Harness host layer: tool registration, filesystem bridge, UTF-8-only admission, prompt guidance, shell integration, write integration and telemetry. See [`dsh/README.md`](dsh/README.md) for the host-layer map.
8
8
 
@@ -29,6 +29,8 @@ The anchor width is baked into the build. Set `PI_BETTER_EDIT_ANCHOR_WIDTH` when
29
29
 
30
30
  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.
31
31
 
32
+ 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.
33
+
32
34
  Measured on the DeepSeek-V4.1 tokenizer, a 3-char anchor averages ~2.3 tokens and a 4-char anchor ~3.0 tokens per served line, and neither collapses to one token (see [ADR-0020](docs/adr/0020-configurable-anchor-width-3-4.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.
33
35
 
34
36
  ## Install
@@ -62,29 +64,52 @@ The bundle ships `lib/index.js` plus `lib/types/**`; `prompts/` must sit next to
62
64
  A served read looks like this (`│` is U+2502, the separator):
63
65
 
64
66
  ```text
65
- ve7x│function calculateTotal(items: CartItem[]): number {
66
- szJx│ let total = 0;
67
- kQmx│ for (const item of items) {
68
- m2zX│ total += item.price;
69
- d2xX│ }
70
- p9rX│ return total;
71
- a1bX│}
67
+ ve7│function calculateTotal(items: CartItem[]): number {
68
+ szJ│ let total = 0;
69
+ kQm│ for (const item of items) {
70
+ m2z│ total += item.price;
71
+ d2x│ }
72
+ p9r│ return total;
73
+ a1b│}
72
74
  ```
73
75
 
74
- Copy only the 4 characters before `│` into `anchor_from` / `anchor_to`. An `apply_patch` identity hunk targets an inclusive served range; a successful call returns a diff whose modified and context rows carry fresh anchors:
76
+ Copy only the build-width characters before `│` (3 by default; 4 in a 4-char build). `edit` passes them as `anchor_from` / `anchor_to`; `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:
75
77
 
76
78
  ```text
77
- - szJx│ let total = 0;
78
- - kQmx│ for (const item of items) {
79
- - m2zX│ total += item.price;
80
- +w4kQ│ let total = items.reduce((sum, item) => sum + item.price, 0);
81
- d2xX│ }
79
+ - szJ│ let total = 0;
80
+ - kQm│ for (const item of items) {
81
+ - m2z│ total += item.price;
82
+ +w4k│ let total = items.reduce((sum, item) => sum + item.price, 0);
83
+ d2x│ }
82
84
  ```
83
85
 
84
86
  Served anchors are leased per session and per file. A stale, unknown, retired or foreign anchor is refused with a `[MODEL] [E_*]` message; range refusals return the current rows as a fresh read (`Current range (fresh read):`) so the model can retry from the rejection alone. An ordinary refusal writes nothing; a foreign-source cut is ordered and repair-backed rather than filesystem-atomic across a crash.
85
87
 
86
88
  ## Tools
87
89
 
90
+ ### Live switches and profiles
91
+
92
+ `read`, `applyPatch` and `edit` are three live per-agent switches. The host reloads the bundle row and remounts every live agent, so flipping one takes effect without a rebuild. `read` shadows the built-in read and enables the shell/grep views; `applyPatch` registers the `apply_patch` tool; `edit` registers the anchored range `edit` tool.
93
+
94
+ | Switch | Default | Effect |
95
+ | --- | --- | --- |
96
+ | `read` | `true` | Register the hash-anchored `read` tool and its shell/grep views. |
97
+ | `applyPatch` | `true` | Register the `apply_patch` tool. |
98
+ | `edit` | `false` | Register the anchored range `edit` tool. |
99
+
100
+ The two mutation switches form three supported profiles. With both mutation switches off, neither write tool is registered and the native-hide layer is not installed; the native editors and the host's built-in `write` stay visible. Each snippet below is the `config` block of the `dsh-hashline-edit` row:
101
+
102
+ ```yaml
103
+ # apply_patch only (the shipped default)
104
+ config: { read: true, applyPatch: true, edit: false }
105
+
106
+ # both mutation tools
107
+ config: { read: true, applyPatch: true, edit: true }
108
+
109
+ # edit only
110
+ config: { read: true, applyPatch: false, edit: true }
111
+ ```
112
+
88
113
  ### `read`
89
114
 
90
115
  ```ts
@@ -100,14 +125,15 @@ read({
100
125
  })
101
126
  ```
102
127
 
103
- - **Served mode** returns one `HASH│content` row per line 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`, even when the windows are far apart.
104
- - **Verbatim mode** returns the same page as plain text with no anchors and serves nothing; an `apply_patch` identity hunk cannot target those lines.
128
+ - **Served mode** returns one `HASH│content` row per line 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.
129
+ - **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.
105
130
  - 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 (fetched lazily and verified against a committed SHA-256), 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)).
106
131
  - `offset`/`limit` and `windows` are page requests, not anchors: only `served` output grants mutation leases.
107
132
 
108
133
  ### `apply_patch`
109
134
 
110
- The precise and batch file-mutation entry point; the host's built-in `write` stays
135
+ One of the two write tools: the precise, batch patch-document surface. It shares
136
+ the served anchors, lease store and mutation queue with `edit`; the host's built-in `write` stays
111
137
  available for whole-file rewrites. One call carries one Codex patch document and commits the whole
112
138
  batch as one correlated transaction (pre-mirror, undo rows, deterministic member order, all-or-nothing
113
139
  rollback, then per-file store commits).
@@ -129,30 +155,43 @@ Addressing works in two modes, and one patch may mix them:
129
155
  `@@ <one context line>` moves the window after that line's unique match. Body lines are
130
156
  ` ` (context), `-` (remove) and `+` (add). Matching is byte-exact and must be unique: zero or
131
157
  multiple matches reject the whole call and serve the candidate rows back.
132
- - **Identity hunks** use the `@@<a>` / `@@<a>-<b>` extension: two inclusive 4-char anchors from rows
133
- this session served. The body is `+` lines only; an empty body deletes the span. A stale, unknown
158
+ - **Identity hunks** use the `@@<a>` / `@@<a>-<b>` extension: two inclusive anchors of this build's
159
+ width (3 or 4 chars) from rows this session served. The body is `+` lines only; an empty body deletes the span. A stale, unknown
134
160
  or foreign anchor is rejected with the file's current rows served.
135
161
  - **Reference hunks** `*** Copy From: <path> <a>-<b>` / `*** Cut From: <path> <a>-<b>` take the
136
162
  bytes of another served span; a cut also retires the source span in the same transaction.
137
163
  - **Lifecycle** `*** Add File:`, `*** Delete File:` and `*** Move to:` join text edits in the same
138
164
  transaction and the same undo record. `*** End of File` pins a hunk to the file tail.
139
165
 
140
- `@@` followed by a space is Codex's context mode; `@@` immediately followed by four anchor
166
+ `@@` followed by a space is Codex's context mode; `@@` immediately followed by `HASH_LEN` anchor
141
167
  characters is identity mode. Any rejection leaves every file byte-identical and reports every
142
168
  independent problem with its patch line number and `[E_*`] code. Success returns a file-level summary
143
169
  (A/M/R/D) followed by fresh `HASH│content` anchors for every changed line, so the next call can chain
144
170
  without a `read`. To replace a whole file, use one `*** Update File:` identity hunk spanning every served line.
145
- ### `undo_last_edit`
146
171
 
147
- ```ts
148
- undo_last_edit({ path: string })
172
+ ### `edit`
173
+
174
+ The anchored range writer. One call targets one file and carries one ordered `edits` array, so N changes in that file are N items in the same call.
175
+
176
+ ```json
177
+ {
178
+ "file": "src/config.ts",
179
+ "edits": [
180
+ { "anchor_from": "szJ", "anchor_to": "szJ", "text": " retries: 5," },
181
+ {
182
+ "anchor_from": "d2x",
183
+ "anchor_to": "d2x",
184
+ "text_ref": { "anchor_from": "a1b", "anchor_to": "a1b", "file": "src/defaults.ts", "mode": "copy" }
185
+ }
186
+ ]
187
+ }
149
188
  ```
150
189
 
151
- Restores the previous file content, BOM, line endings and original anchors from a snapshot-pinned undo record. The record survives agent restarts. A file changed externally after the patch is refused with `[E_UNDO_STALE]`. A correlated cut's undo restores every member of the transaction, not only the named path.
190
+ Each item names two inclusive bare anchors and exactly one payload: `text` is the replacement content (`""` deletes the range), or `text_ref` is a served span read in `copy` or `cut` mode. Optional `at` is `in-place` by default; `before` / `after` insert at the boundary and require a single-line target. A `text_ref.file` may name another served file as the copy/cut source, and `cut` also retires those source lines; the call's own target remains one file. The retired item-level `file` field is not part of the payload — an old multi-file item shape is refused with `[E_BAD_PAYLOAD]`, and a different target file is a different call. The call commits as one transaction and writes one undo record for recovery; undo is not exposed as a model tool.
152
191
 
153
192
  ## Shell view
154
193
 
155
- The plugin installs a `tools/post-execute` listener for the host's `pwsh`, `bash` and built-in `grep` tools. When the command is a whitelisted read-only file view, the captured stdout is replaced with the aligned file's `HASH│content` rows, and those rows are served (leased) exactly like a read — a following `apply_patch` can use them with no re-read. A built-in grep result whose matches are proven against disk is served the same way (see the table below).
194
+ The plugin installs a `tools/post-execute` listener for the host's `pwsh`, `bash` and built-in `grep` tools. When the command is a whitelisted read-only file view, the captured stdout is replaced with the aligned file's `HASH│content` rows, and those rows are served (leased) exactly like a read — a following `apply_patch` or `edit` can use them with no re-read. A built-in grep result whose matches are proven against disk is served the same way (see the table below).
156
195
 
157
196
  | Command shape | Served as |
158
197
  | --- | --- |
@@ -175,10 +214,10 @@ The dsh host reads and writes UTF-8. Read admission is one rule with one exempti
175
214
 
176
215
  A file that is not valid UTF-8 is refused with `[E_UNSUPPORTED_FILE]` naming the file path and telling the model to ask the user how to handle it — for example a GBK-encoded source file or a BOM-less UTF-16LE file. The host does not guess a code page, offers no reopen-with-encoding parameter, keeps no encoding/BOM memo, and does not re-encode on save. UTF-16/UTF-32 BOMs are still recognized by kind detection: they are named in the refusal (e.g. `UTF-16LE encoded text`) instead of being decoded. Convert a non-UTF-8 file with an external tool before editing it here.
177
216
 
178
- `apply_patch` and `undo_last_edit` speak the same contract: they write UTF-8, and every file this plugin serves is UTF-8. The built-in `write` integration keeps the same contract for a profile that deliberately keeps `write` visible.
217
+ `apply_patch` and `edit` speak the same contract: they write UTF-8, and every file this plugin serves is UTF-8. The built-in `write` integration keeps the same contract for a profile that deliberately keeps `write` visible.
179
218
  ## Sandbox behavior
180
219
 
181
- `apply_patch` and `undo_last_edit` carry the host's optional escalation fields `sandbox_permissions` and `justification` only when a confining filesystem backend is mounted. `dsh/sandbox.ts` mirrors the built-in `@deepseek-ai/dsh-tool-fs` controller: it validates the field pairing, repeats the standing mode without approval, and resolves a strictly wider mode through the host's approval channel before touching the filesystem. A provider `FS_SANDBOX_DENIED` error is mapped to the standard model-facing denial marker plus escalation hint; other errors pass through unchanged.
220
+ `apply_patch` and `edit` carry the host's optional escalation fields `sandbox_permissions` and `justification` only when a confining filesystem backend is mounted. `dsh/sandbox.ts` mirrors the built-in `@deepseek-ai/dsh-tool-fs` controller: it validates the field pairing, repeats the standing mode without approval, and resolves a strictly wider mode through the host's approval channel before touching the filesystem. A provider `FS_SANDBOX_DENIED` error is mapped to the standard model-facing denial marker plus escalation hint; other errors pass through unchanged.
182
221
 
183
222
  ### Host-side `0xC0000142` workspace-write finding
184
223
 
@@ -243,7 +282,7 @@ Range-family rejections render their current-row evidence exactly once: the head
243
282
 
244
283
  ## Current limitations
245
284
 
246
- - **Mutation stays on the local `node:fs` seam.** The read path consumes a `CoreReadIo` port (local or mounted `ctx.fs`), but `writeAtomic`, the `apply_patch` engine and undo remain local-only. `apply_patch` and `undo_last_edit` fail closed with `E_NOT_FOUND` when the target is reachable only through `ctx.fs`. A full mutation bridge needs target-keyed store state: the host's `ctx.fs` already exposes versioned writes in `0.2.2-alpha.3`, but the snapshot/lease store still keys on absolute paths and local stat identity (M6, see [`dsh/README.md`](dsh/README.md#ctxfs-deferral-m6)).
285
+ - **Mutation stays on the local `node:fs` seam.** The read path consumes a `CoreReadIo` port (local or mounted `ctx.fs`), but `writeAtomic`, the shared mutation engine and undo records remain local-only. `apply_patch` and `edit` fail closed with `E_NOT_FOUND` when the target is reachable only through `ctx.fs`. A full mutation bridge needs target-keyed store state: the host's `ctx.fs` already exposes versioned writes in `0.2.2-alpha.3`, but the snapshot/lease store still keys on absolute paths and local stat identity (M6, see [`dsh/README.md`](dsh/README.md#ctxfs-deferral-m6)).
247
286
  - **UTF-8 only.** Non-UTF-8 files are refused on read and must be converted with an external tool; the plugin does not decode legacy code pages, does not re-encode on save, and keeps no encoding state.
248
287
  - **Windows-only.** The branch targets Windows; POSIX-only suites are excluded in `vitest.config.windows.ts`, and that exclusion list must shrink, never grow (see [`dsh/UPSTREAM.md`](dsh/UPSTREAM.md)).
249
288
 
package/cordis.patch.yml CHANGED
@@ -1,14 +1,16 @@
1
1
  # dsh-hashline-edit bundle patch: mount the host-plane plugin row.
2
2
  # Installed via `dsh plugin --profile <name> add dsh-hashline-edit` (or a
3
3
  # profile's bundle list). The row carries three feature switches, edited on the
4
- # Plugins page: `read` shadows the built-in read, `apply_patch` hides the native
5
- # write/edit/apply_patch/str_replace_editor surface, `undo` exposes the
6
- # undo_last_edit tool. Each toggles live: the host reloads this row and the plugin
7
- # re-mounts every live agent. Defaults: read on, apply_patch on, undo off.
4
+ # Plugins page: `read` shadows the built-in read, `applyPatch` exposes the
5
+ # `apply_patch` tool, `edit` exposes the anchored range `edit` tool. Either
6
+ # mutation tool hides the native write/editor surface (`edit`, `apply_patch`,
7
+ # `str_replace_editor`) for the agent and leaves the built-in `write` visible;
8
+ # both may be on at once. Each toggles live: the host reloads this row and the
9
+ # plugin re-mounts every live agent. Defaults: read on, apply_patch on, edit off.
8
10
  - insert:
9
11
  - id: dsh-hashline-edit
10
12
  name: dsh-hashline-edit
11
13
  config:
12
14
  read: true
13
15
  applyPatch: true
14
- undo: false
16
+ edit: false
package/lib/client.js CHANGED
@@ -31,15 +31,15 @@ var import_jsx_runtime = require("react/jsx-runtime");
31
31
  var SWITCHES = [
32
32
  { key: "read", label: "swRead", hint: "swReadHint", fallback: true },
33
33
  { key: "applyPatch", label: "swApplyPatch", hint: "swApplyPatchHint", fallback: true },
34
- { key: "undo", label: "swUndo", hint: "swUndoHint", fallback: false }
34
+ { key: "edit", label: "swEdit", hint: "swEditHint", fallback: false }
35
35
  ];
36
36
  var en = {
37
37
  swRead: "Read (shadow the host read)",
38
38
  swReadHint: "Expose the hashline read tool with hash anchors and shadow the host's read.",
39
39
  swApplyPatch: "Apply patch",
40
40
  swApplyPatchHint: "Expose apply_patch and hide the native edit / write / apply_patch / str_replace_editor tools.",
41
- swUndo: "Undo",
42
- swUndoHint: "Expose undo_last_edit. Snapshots are always recorded; this only shows the tool to the model.",
41
+ swEdit: "Edit (anchored ranges)",
42
+ swEditHint: "Expose the single-file edit tool: N anchored range items in one call. It shares anchors, the store and the mutation queue with apply_patch.",
43
43
  groupTools: "Hashline tools",
44
44
  groupToolsHint: "Toggle each tool live. Turning one off restores the host's own tool.",
45
45
  save: "Save",
@@ -49,15 +49,15 @@ var en = {
49
49
  rejected: "The host refused this save; reset and review your changes.",
50
50
  loading: "Loading host settings\u2026",
51
51
  unavailable: "Enable this row with the built-in switch to edit its settings.",
52
- rowSummary: "Read, apply_patch and undo switches."
52
+ rowSummary: "Read, apply_patch and edit switches."
53
53
  };
54
54
  var zh = {
55
55
  swRead: "\u8BFB\u53D6\uFF08\u906E\u853D\u5BBF\u4E3B read\uFF09",
56
56
  swReadHint: "\u542F\u7528\u5E26\u54C8\u5E0C\u951A\u70B9\u7684 hashline read \u5DE5\u5177\uFF0C\u5E76\u906E\u853D\u5BBF\u4E3B\u7684 read\u3002",
57
57
  swApplyPatch: "\u5E94\u7528\u8865\u4E01",
58
58
  swApplyPatchHint: "\u542F\u7528 apply_patch\uFF0C\u5E76\u9690\u85CF\u539F\u751F edit / write / apply_patch / str_replace_editor\u3002",
59
- swUndo: "\u64A4\u9500",
60
- swUndoHint: "\u542F\u7528 undo_last_edit\u3002\u5FEB\u7167\u59CB\u7EC8\u8BB0\u5F55\uFF0C\u6B64\u9879\u4EC5\u5411\u6A21\u578B\u66B4\u9732\u5DE5\u5177\u3002",
59
+ swEdit: "\u533A\u95F4\u7F16\u8F91",
60
+ swEditHint: "\u542F\u7528\u5355\u6587\u4EF6 edit \u5DE5\u5177\uFF1A\u4E00\u6B21\u8C03\u7528\u63D0\u4EA4 N \u5904\u951A\u5B9A\u533A\u95F4\u4FEE\u6539\uFF1B\u4E0E apply_patch \u5171\u7528\u951A\u70B9\u3001\u5B58\u50A8\u4E0E\u53D8\u66F4\u961F\u5217\u3002",
61
61
  groupTools: "Hashline \u5DE5\u5177",
62
62
  groupToolsHint: "\u5B9E\u65F6\u5207\u6362\u6BCF\u4E2A\u5DE5\u5177\uFF1B\u5173\u95ED\u540E\u6062\u590D\u5BBF\u4E3B\u81EA\u5E26\u5DE5\u5177\u3002",
63
63
  save: "\u4FDD\u5B58",
@@ -67,7 +67,7 @@ var zh = {
67
67
  rejected: "\u5BBF\u4E3B\u62D2\u7EDD\u4E86\u6B64\u6B21\u4FDD\u5B58\uFF1B\u8BF7\u91CD\u7F6E\u540E\u91CD\u65B0\u68C0\u67E5\u66F4\u6539\u3002",
68
68
  loading: "\u6B63\u5728\u52A0\u8F7D\u5BBF\u4E3B\u8BBE\u7F6E\u2026",
69
69
  unavailable: "\u8BF7\u5148\u7528\u5185\u7F6E\u5F00\u5173\u542F\u7528\u6B64\u884C\u540E\u518D\u7F16\u8F91\u8BBE\u7F6E\u3002",
70
- rowSummary: "\u8BFB\u53D6\u3001apply_patch \u4E0E\u64A4\u9500\u5F00\u5173\u3002"
70
+ rowSummary: "\u8BFB\u53D6\u3001apply_patch \u4E0E\u533A\u95F4\u7F16\u8F91\u5F00\u5173\u3002"
71
71
  };
72
72
  var CSS = `
73
73
  .hashline-settings { display:flex; flex-direction:column; gap:12px; font:inherit; color:var(--dsw-alias-label-primary,#222); }