dsh-better-edit 0.1.7 → 0.1.9

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/CHANGELOG.md ADDED
@@ -0,0 +1,81 @@
1
+ # Changelog
2
+
3
+ All notable changes to the `dsh-better-edit` plugin will be documented in this file.
4
+
5
+ Entries link to the originating spec issue in [pi-hashline-edit-lsz](https://github.com/Rianico/pi-hashline-edit-lsz) where one exists.
6
+
7
+ ## [0.1.9] - 2026-08-15
8
+
9
+ ### Changed
10
+
11
+ - READMEs (English and 中文): added a concise "Why you need this" opening section — the transcription cost and 46–51% patch-failure rate of `str_replace`, the 31%/43% edit-token savings, verified landing, and the leaner-context benefit (the model's attention stays on the code, not on re-transcribing it) — placed before Quick Start so the demo stays immediately visible. Fixed the stale static version badge.
12
+
13
+ ## [0.1.8] - 2026-08-15
14
+
15
+ ### Added
16
+
17
+ - This CHANGELOG (Keep-a-Changelog style, following the pi-interactive-shell layout), shipped in the npm tarball.
18
+ - Git tag / GitHub release automation: a `postpublish` hook (`scripts/tag-current.mjs`) reads the version from `package.json`, creates an annotated `vX.Y.Z` tag at HEAD and pushes it, so every successful `npm publish` stays in sync with git; a GitHub Actions workflow (`.github/workflows/release.yml`) turns any `v*` tag push into a release with auto-generated notes.
19
+ - Backfilled `v0.1.0`–`v0.1.7` git tags and GitHub releases at their version-bump commits.
20
+
21
+ ## [0.1.7] - 2026-08-15
22
+
23
+ ### Added
24
+
25
+ - `assets/logo.svg` and `assets/banner.svg` (file.ts → read → hashed lines → edit by hash → diff), shipped in the npm tarball.
26
+ - READMEs (English and 中文) restyled in a centered, image-led layout: badge row, harness-problem pull-quote, example-driven Quick Start, a hashline-vs-`str_replace`-vs-line-number comparison table, project-structure tree, roadmap, acknowledgments, and a star-history chart.
27
+
28
+ ### Changed
29
+
30
+ - The published tarball now includes `assets/` alongside `README.md` and `README.zh.md`.
31
+
32
+ ## [0.1.6] - 2026-08-15
33
+
34
+ ### Added
35
+
36
+ - Chinese README (`README.zh.md`) — a full translation mirroring the English one (pillars, diagrams, benchmark, tools, error codes, lineage).
37
+ - Reciprocal language links at the top of both READMEs; `README.zh.md` shipped in the npm tarball.
38
+
39
+ ## [0.1.5] - 2026-08-15
40
+
41
+ ### Added
42
+
43
+ - Reproducible token-cost benchmark (`benchmark/run.mjs` + frozen 103-line corpus + methodology): hashline vs `str_replace` on the same file with the same 12 replacements — 31% fewer output tokens over the session (43% on multi-line ranges), ~1.4× cheaper on effective cost at the 5× output-token rate. Deterministic: content-addressed self-checking edit script, pinned `js-tiktoken` `cl100k_base` devDependency. Run with `npm run benchmark`.
44
+ - README rewritten around the three pillars — token-saving, correctness, and the modern content-addressed edit pattern — with Mermaid diagrams, a `str_replace` comparison table, and an inspiration/lineage section (The Harness Problem, pi-hashline-edit, pi-hashline-edit-pro, pi-hashline-edit-lsz).
45
+
46
+ ## [0.1.4] - 2026-08-15
47
+
48
+ ### Fixed
49
+
50
+ - `E_RANGE_UNVERIFIED` ("served at N positions") on edits after a shrinking write: the served-state array was upserted by position but never truncated to the file's current line count, so a stale tail kept a surviving line's hash at its OLD position while the current serve held it at its new one. `recordServed`/`recordServes` now take the current line count and truncate before upserting, threaded from every whole-file serve — read, write auto-read, drift rows, and all rejection-echo sites. Regression test covers the 8-line→2-line write case ([Rianico/pi-hashline-edit-lsz#27](https://github.com/Rianico/pi-hashline-edit-lsz/issues/27)).
51
+ - The fix is a candidate to upstream into pi-hashline-edit-lsz / upstream, whose `upsertServed` has the same never-truncate behavior (tracked in [Rianico/pi-hashline-edit-lsz#27](https://github.com/Rianico/pi-hashline-edit-lsz/issues/27)).
52
+
53
+ ## [0.1.3] - 2026-08-15
54
+
55
+ ### Fixed
56
+
57
+ - Sandboxed sessions rejected in-workspace edits while the built-in `write` succeeded: the shadowed mutating tools called `fs.writeText` without the per-call sandbox policy, so a confined backend fell back to the deployment root. Tools now mirror `@deepseek-ai/dsh-tool-fs`'s `FsSandboxController` — resolve the policy with the session cwd as the workspace root, advertise `sandbox_permissions`/`justification`, pass the policy to `fs.writeText`, and map `FS_SANDBOX_DENIED` to the shared `[sandbox: …]` marker.
58
+
59
+ ## [0.1.2] - 2026-08-15
60
+
61
+ ### Changed
62
+
63
+ - The hash store moved from `$DSH_HOME/plugins/dsh-better-edit` to a per-workspace location: `<workspace>/.dsh_better_edit/hash-store.sqlite`, carried per tool call via an AsyncLocalStorage workspace context (`src/workspace.ts`). Parallel sessions in different workspaces no longer share anchors or undo history. The shared home path remains the fallback for tests/previews.
64
+ - Undo history from before 0.1.2 is not migrated to the new layout.
65
+
66
+ ## [0.1.1] - 2026-08-15
67
+
68
+ ### Fixed
69
+
70
+ - Shadowed tools silently never registering, leaving sessions on the built-ins: per-agent installation failed with `cannot get property "fs" without inject` at `session-start`. The plugin now declares `inject = ['tools', 'systemPrompt', 'fs']` and resolves the host `fs` service from the plugin's own `rootCtx` (the agent fiber chain does not carry the plugin's inject list).
71
+
72
+ ## [0.1.0] - 2026-08-14
73
+
74
+ ### Added
75
+
76
+ - Initial dsh port of pi-hashline-edit-lsz: hash-anchored `read` / `edit` / `batch_edit` / `undo_last_edit` tools for DeepSeek Harness. Every line gets a unique 3-character content hash; edits target `remove_from`/`remove_to` hashes. The hashline core is ported byte-for-byte; the tool layer is rewritten on dsh's plugin API ([batch_edit spec: Rianico/pi-hashline-edit-lsz#19](https://github.com/Rianico/pi-hashline-edit-lsz/issues/19)).
77
+ - Built-in replacement via scope-layered registry shadowing: on `agent/session-start` the tools and the `tool:read`/`tool:edit` prompt sections are registered on the agent's own layer (own-layer-wins), unwinding automatically on disposal; a `tools/post-execute` listener appends the auto-read to built-in `write` results.
78
+ - Served-state range verification with reject-and-serve: every line of the resolved range is checked against what the model was shown; stale/never-served/unverified ranges are hard-rejected with the current `HASH│content` rows echoed back (retry needs no `read`). Drift notices report served territory changed outside the edit range ([reject-and-serve spec: Rianico/pi-hashline-edit-lsz#13](https://github.com/Rianico/pi-hashline-edit-lsz/issues/13)).
79
+ - Chained edits without re-reading: post-edit diff rows and rejection echoes count as serves, so follow-up edits verify cleanly.
80
+ - Error-code contract (`[E_*]` codes, README-documented and test-enforced) including the noop-loop guard ([Rianico/pi-hashline-edit-lsz#18](https://github.com/Rianico/pi-hashline-edit-lsz/issues/18)); `undo_last_edit` surviving restarts; and safe writes preserving permissions, line endings, BOMs, symlinks, and hard links via `ctx.fs`.
81
+ - Test suite ported from pi-hashline-edit-lsz (614 tests at release), driving the dsh tool builders directly over a local filesystem bridge.
package/README.md CHANGED
@@ -24,7 +24,7 @@
24
24
  </p>
25
25
 
26
26
  <p align="center">
27
- <img src="https://img.shields.io/badge/version-0.1.6-blue.svg" alt="Version">
27
+ <img src="https://img.shields.io/badge/version-0.1.9-blue.svg" alt="Version">
28
28
  <img src="https://img.shields.io/badge/license-MIT-green.svg" alt="MIT License">
29
29
  <img src="https://img.shields.io/badge/DeepSeek_Harness-Plugin-blueviolet.svg" alt="DeepSeek Harness Plugin">
30
30
  <img src="https://img.shields.io/npm/v/dsh-better-edit" alt="npm version">
@@ -47,6 +47,14 @@ replace-style edits. **dsh-better-edit** goes deeper. Every line of a file gets
47
47
  content hash, and edits target hashes. The old text is never echoed, anchors survive edits, and every
48
48
  resolved range is verified against exactly what the model saw — wrong-line edits cannot silently land.
49
49
 
50
+ ## Why you need this
51
+
52
+ `str_replace` makes the model re-type the code it's replacing — pure transcription cost (output tokens, billed ~5-6× input), and where agents fail most: 46–51% patch failures on real models, worse on bigger blocks, each failure costing a re-read and a retry.
53
+
54
+ Hashline sends two hashes instead of the old text — **31% fewer edit tokens** (43% on multi-line ranges) — and verifies every range against what the model saw: an edit lands where you meant, or fails loudly with fresh anchors. Anchors are content addresses that survive edits above, so chained edits skip re-reads — and a leaner context keeps the model's attention on the code, not on re-transcribing it.
55
+
56
+ Not for one-line touch-ups (near parity) or new files (`write`). It pays off in long sessions and structural edits — anywhere an edit must not land on the wrong line.
57
+
50
58
  ## Quick Start
51
59
 
52
60
  `read` returns every line prefixed by its hash — the hash *is* the line's address:
@@ -80,7 +88,7 @@ and produces a diff with fresh anchors, so the next edit verifies cleanly with n
80
88
 
81
89
  **Token-saving.** An edit call carries `remove_from` / `remove_to` (two 3-char hashes) plus the
82
90
  replacement text — it never echoes the text being replaced. A `str_replace` call must reproduce that
83
- text verbatim. On a 12-edit session over a realistic file this is **28% fewer output tokens** (40%
91
+ text verbatim. On a 12-edit session over a realistic file this is **31% fewer output tokens** (43%
84
92
  on multi-line ranges) — and these are *output* tokens, billed at ~5-6× the input rate. See the
85
93
  [benchmark](#benchmark).
86
94
 
@@ -116,8 +124,8 @@ Measured on the same 103-line file with the same 12 replacements (8 single-line,
116
124
  | Criterion | hashline | str_replace |
117
125
  | ----------- | :---: | :---: |
118
126
  | Replaced text sent over the wire | ✅ never | ❌ every edit |
119
- | Output tokens saved (12-edit session) | ✅ **28%** | ❌ 0% |
120
- | Multi-line range savings (3–15 lines) | ✅ **25–46%** | ❌ 0% |
127
+ | Output tokens saved (12-edit session) | ✅ **31%** | ❌ 0% |
128
+ | Multi-line range savings (3–15 lines) | ✅ **29–47%** | ❌ 0% |
121
129
  | Effective cost at 5× output pricing | ✅ **~1.4× less** | ❌ 1× |
122
130
  | Ranges verified against served state | ✅ 100% | ❌ none |
123
131
  | Deterministic, reproducible locally | ✅ `npm run benchmark` | — |
@@ -128,9 +136,9 @@ The numbers above are **deterministic and you can reproduce them locally** — `
128
136
 
129
137
  | Scenario | Lines | hashline | str_replace | Saved | % |
130
138
  | --- | :---: | :---: | :---: | :---: | :---: |
131
- | single-line ×8 | 1 | 311 | 314 | 3 | 1% |
132
- | multi-line ×4 | 3–15 | 390 | 655 | 265 | **40%** |
133
- | **TOTAL ×12** | | **701** | **969** | **268** | **28%** |
139
+ | single-line ×8 | 1 | 309 | 324 | 15 | 5% |
140
+ | multi-line ×4 | 3–15 | 393 | 691 | 298 | **43%** |
141
+ | **TOTAL ×12** | | **702** | **1015** | **313** | **31%** |
134
142
 
135
143
  The script is deterministic by construction: a frozen corpus, a content-addressed edit script that
136
144
  self-checks (a reformatted corpus throws instead of silently changing what's measured), and a pinned
package/README.zh.md CHANGED
@@ -24,7 +24,7 @@
24
24
  </p>
25
25
 
26
26
  <p align="center">
27
- <img src="https://img.shields.io/badge/version-0.1.7-blue.svg" alt="Version">
27
+ <img src="https://img.shields.io/badge/version-0.1.9-blue.svg" alt="Version">
28
28
  <img src="https://img.shields.io/badge/license-MIT-green.svg" alt="MIT License">
29
29
  <img src="https://img.shields.io/badge/DeepSeek_Harness-Plugin-blueviolet.svg" alt="DeepSeek Harness Plugin">
30
30
  <img src="https://img.shields.io/npm/v/dsh-better-edit" alt="npm version">
@@ -43,6 +43,14 @@
43
43
 
44
44
  大多数编辑工具要求模型在改动任何东西之前,先**逐 token** 复述旧代码——而这正是 Agent 最容易出错的地方:多个模型在 replace 式编辑下的补丁格式失败率高达 46–51%。**dsh-better-edit** 走得更远。文件的每一行都分配一个唯一的 3 字符内容哈希,编辑时按哈希定位。旧文本从不回显,锚点在编辑后依然有效,每个解析出的范围都会与模型实际看到的内容逐一核对——错行编辑不可能悄悄落盘。
45
45
 
46
+ ## 为什么需要它
47
+
48
+ `str_replace` 会让模型逐字复述它要替换的代码——纯粹的转录成本(输出 token,按约 5-6 倍输入计费),也是 Agent 最容易出错的地方:真实模型补丁失败率高达 46–51%,块越大越糟,每次失败都要重新读取并重试。
49
+
50
+ Hashline 用两个哈希代替旧文本——**编辑 token 减少 31%**(多行范围达 43%)——并对照模型所见内容校验每个范围:编辑要么落在你想要的行的位置,要么响亮失败并回传新锚点。锚点是内容地址,上方编辑后依然有效,连续编辑无需重读;上下文更精简,模型的注意力也保持在代码上,而不是复述上。
51
+
52
+ 不适用于单行小改动(接近持平)或新建文件(用 `write`)。它的价值在长会话与结构性编辑中体现——任何不允许改错行的场景。
53
+
46
54
  ## 快速开始
47
55
 
48
56
  `read` 返回的每一行都带有哈希前缀——哈希*就是*这一行的地址:
@@ -74,7 +82,7 @@ kQm│}
74
82
 
75
83
  ## 为什么用 Hashline
76
84
 
77
- **省 token。** 一次编辑调用只携带 `remove_from` / `remove_to`(两个 3 字符哈希)加替换文本——从不回显被替换的文本。`str_replace` 调用则必须逐字复现被替换的文本。在一个真实文件上的 12 次编辑会话中,这可以**减少 28% 的输出 token**(多行范围达 40%)——而且这些是*输出* token,按输入的约 5-6 倍计费。见[基准测试](#基准测试)。
85
+ **省 token。** 一次编辑调用只携带 `remove_from` / `remove_to`(两个 3 字符哈希)加替换文本——从不回显被替换的文本。`str_replace` 调用则必须逐字复现被替换的文本。在一个真实文件上的 12 次编辑会话中,这可以**减少 31% 的输出 token**(多行范围达 43%)——而且这些是*输出* token,按输入的约 5-6 倍计费。见[基准测试](#基准测试)。
78
86
 
79
87
  **正确性。** 每个解析出的编辑范围都会与模型实际看到的行逐行核对。过期、从未提供或歧义的范围会在**写入任何内容之前**被硬性拒绝,并把当前范围以全新锚点的形式回显(reject-and-serve)——重试无需 `read`。
80
88
 
@@ -101,8 +109,8 @@ kQm│}
101
109
  | 指标 | hashline | str_replace |
102
110
  | ----------- | :---: | :---: |
103
111
  | 被替换文本是否上线 | ✅ 从不 | ❌ 每次编辑都发 |
104
- | 输出 token 节省(12 次编辑) | ✅ **28%** | ❌ 0% |
105
- | 多行范围节省(3–15 行) | ✅ **25–46%** | ❌ 0% |
112
+ | 输出 token 节省(12 次编辑) | ✅ **31%** | ❌ 0% |
113
+ | 多行范围节省(3–15 行) | ✅ **29–47%** | ❌ 0% |
106
114
  | 按 5 倍输出计价的实际成本 | ✅ **低约 1.4 倍** | ❌ 1× |
107
115
  | 范围对照已提供状态校验 | ✅ 100% | ❌ 无 |
108
116
  | 确定性、可在本地复现 | ✅ `npm run benchmark` | — |
@@ -113,9 +121,9 @@ kQm│}
113
121
 
114
122
  | 场景 | 行数 | hashline | str_replace | 节省 | % |
115
123
  | --- | :---: | :---: | :---: | :---: | :---: |
116
- | 单行 ×8 | 1 | 311 | 314 | 3 | 1% |
117
- | 多行 ×4 | 3–15 | 390 | 655 | 265 | **40%** |
118
- | **合计 ×12** | | **701** | **969** | **268** | **28%** |
124
+ | 单行 ×8 | 1 | 309 | 324 | 15 | 5% |
125
+ | 多行 ×4 | 3–15 | 393 | 691 | 298 | **43%** |
126
+ | **合计 ×12** | | **702** | **1015** | **313** | **31%** |
119
127
 
120
128
  脚本天然确定:固定语料、内容寻址且自带自检的编辑脚本(语料被重排会直接抛错,而不是悄悄改变测量对象)、固定版本的 tokenizer。因为一切都是固定的,`npm run benchmark` 对每个人都是同一个结果。
121
129
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-better-edit",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "type": "module",
5
5
  "description": "Hash-anchored read/edit/batch_edit/undo_last_edit tools for DeepSeek Harness (dsh). Every line gets a unique 3-char hash (A-Za-z0-9) that stays stable across edits; stale or ambiguous anchors are rejected, never fuzzy-matched. Undo persists across restarts.",
6
6
  "main": "lib/index.js",
@@ -18,7 +18,8 @@
18
18
  "README.md",
19
19
  "LICENSE",
20
20
  "README.zh.md",
21
- "assets/"
21
+ "assets/",
22
+ "CHANGELOG.md"
22
23
  ],
23
24
  "repository": {
24
25
  "type": "git",
@@ -74,7 +75,8 @@
74
75
  "test": "vitest run",
75
76
  "test:watch": "vitest",
76
77
  "prepublishOnly": "npm run typecheck && npm test",
77
- "benchmark": "node benchmark/run.mjs"
78
+ "benchmark": "node benchmark/run.mjs",
79
+ "postpublish": "node scripts/tag-current.mjs"
78
80
  },
79
81
  "devDependencies": {
80
82
  "@deepseek-ai/cordis": "^4.0.1",