dsh-better-edit 0.8.2 → 1.1.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.
Files changed (79) hide show
  1. package/CHANGELOG.md +173 -99
  2. package/README.md +61 -33
  3. package/README.zh.md +20 -17
  4. package/cordis.patch.yml +1 -1
  5. package/lib/constants.js +19 -4
  6. package/lib/contract.js +136 -79
  7. package/lib/domain-errors.js +570 -0
  8. package/lib/edit-diff.js +33 -7
  9. package/lib/file-encoding-state.js +27 -7
  10. package/lib/file-view.js +305 -82
  11. package/lib/fs-bridge.js +23 -7
  12. package/lib/guidance/materialize.js +7 -7
  13. package/lib/guidance/resolve.js +13 -8
  14. package/lib/hash-store.js +404 -278
  15. package/lib/hashline/anchor-pipeline.js +586 -378
  16. package/lib/hashline/hash-assign.js +21 -22
  17. package/lib/hashline/hash.js +6 -6
  18. package/lib/hashline/index.js +1 -1
  19. package/lib/hashline/resolve.js +1 -1
  20. package/lib/hashline/served-guard.js +181 -0
  21. package/lib/index.js +37 -11
  22. package/lib/mutation/engine.js +392 -96
  23. package/lib/mutation.js +22 -130
  24. package/lib/noop-guard.js +20 -9
  25. package/lib/prompts.js +20 -18
  26. package/lib/read-and-serve.js +44 -20
  27. package/lib/sandbox.js +1 -1
  28. package/lib/session-view.js +57 -43
  29. package/lib/snapshot-store/index.js +97 -0
  30. package/lib/snapshot-store/lineage-store.js +400 -0
  31. package/lib/snapshot-store/migrate.js +80 -0
  32. package/lib/snapshot-store/pairing.js +412 -0
  33. package/lib/snapshot-store/txn.js +63 -0
  34. package/lib/snapshot-store/vacuum.js +243 -0
  35. package/lib/store-lifecycle.js +13 -1
  36. package/lib/store-retry.js +34 -0
  37. package/lib/tool-edit.js +90 -44
  38. package/lib/tool-read.js +29 -1
  39. package/lib/tool-str-replace-editor.js +26 -18
  40. package/lib/tool-undo.js +25 -8
  41. package/lib/types/constants.d.ts +5 -2
  42. package/lib/types/contract.d.ts +76 -71
  43. package/lib/types/domain-errors.d.ts +410 -0
  44. package/lib/types/edit-response.d.ts +1 -1
  45. package/lib/types/file-encoding-state.d.ts +1 -0
  46. package/lib/types/file-view.d.ts +35 -6
  47. package/lib/types/guidance/materialize.d.ts +2 -2
  48. package/lib/types/guidance/resolve.d.ts +14 -2
  49. package/lib/types/hash-store.d.ts +38 -19
  50. package/lib/types/hashline/anchor-pipeline.d.ts +117 -36
  51. package/lib/types/hashline/hash-assign.d.ts +5 -5
  52. package/lib/types/hashline/hash.d.ts +1 -1
  53. package/lib/types/hashline/index.d.ts +2 -2
  54. package/lib/types/hashline/served-guard.d.ts +100 -0
  55. package/lib/types/index.d.ts +3 -3
  56. package/lib/types/mutation/engine.d.ts +49 -30
  57. package/lib/types/mutation.d.ts +1 -39
  58. package/lib/types/noop-guard.d.ts +4 -4
  59. package/lib/types/prompts.d.ts +1 -1
  60. package/lib/types/read-and-serve.d.ts +6 -0
  61. package/lib/types/sandbox.d.ts +1 -1
  62. package/lib/types/session-view.d.ts +38 -9
  63. package/lib/types/snapshot-store/index.d.ts +28 -0
  64. package/lib/types/snapshot-store/lineage-store.d.ts +96 -0
  65. package/lib/types/snapshot-store/migrate.d.ts +16 -0
  66. package/lib/types/snapshot-store/pairing.d.ts +99 -0
  67. package/lib/types/snapshot-store/txn.d.ts +12 -0
  68. package/lib/types/snapshot-store/vacuum.d.ts +79 -0
  69. package/lib/types/store-lifecycle.d.ts +0 -1
  70. package/lib/types/store-retry.d.ts +6 -0
  71. package/lib/types/tool-edit.d.ts +2 -2
  72. package/lib/types/tool-str-replace-editor.d.ts +2 -2
  73. package/lib/types/utils.d.ts +5 -6
  74. package/lib/types/workspace-context.d.ts +10 -1
  75. package/lib/undo-edit.js +27 -11
  76. package/lib/utils.js +12 -12
  77. package/lib/workspace-context.js +27 -9
  78. package/lib/write-hook.js +13 -4
  79. package/package.json +28 -30
package/README.md CHANGED
@@ -4,8 +4,8 @@
4
4
 
5
5
  <h1 align="center">dsh-better-edit</h1>
6
6
  <p align="center">
7
- <strong>A better edit tool for DeepSeek Harness<br>
8
- Position-free hashes — one read, many edits, fewer tokens, more room for real work.</strong>
7
+ <strong>High-precision, hash-anchored file editing for DeepSeek Harness (dsh).</strong><br>
8
+ Replaces fragile line numbers and token-wasting code echoes with content-addressed line hashes &mdash; 0 silent miswrites, 0 token re-reads.
9
9
  </p>
10
10
  <p align="center">
11
11
  <strong>English</strong> ·
@@ -13,14 +13,15 @@
13
13
  </p>
14
14
 
15
15
  <p align="center">
16
- <a href="#why-you-need-this"><img src="https://img.shields.io/badge/why-hashline-blue?style=flat" alt="why hashline"></a>
16
+ <a href="#why-you-need-it"><img src="https://img.shields.io/badge/why-hashline-blue?style=flat" alt="why hashline"></a>
17
17
  <a href="#quick-start"><img src="https://img.shields.io/badge/quick_start-30s-brightgreen?style=flat" alt="quick start 30s"></a>
18
18
  <a href="#benchmark"><img src="https://img.shields.io/badge/correctness-23%2F23-success?style=flat" alt="23/23 battery"></a>
19
19
  </p>
20
20
 
21
21
  <p align="center">
22
+ <a href="#why-you-need-it">Why You Need It</a> •
23
+ <a href="#core-pillars">Core Pillars</a> •
22
24
  <a href="#quick-start">Quick Start</a> •
23
- <a href="#why-hashline">Why Hashline</a> •
24
25
  <a href="#tools">Tools</a> •
25
26
  <a href="#benchmark">Benchmark</a> •
26
27
  <a href="#how-anchors-work">How Anchors Work</a> •
@@ -28,7 +29,7 @@
28
29
  </p>
29
30
 
30
31
  <p align="center">
31
- <img src="https://img.shields.io/badge/version-0.7.0-blue.svg" alt="Version">
32
+ <img src="https://img.shields.io/badge/version-1.0.0-blue.svg" alt="Version">
32
33
  <img src="https://img.shields.io/badge/license-MIT-green.svg" alt="MIT License">
33
34
  <img src="https://img.shields.io/badge/DeepSeek_Harness-Plugin-blueviolet.svg" alt="DeepSeek Harness Plugin">
34
35
  <img src="https://img.shields.io/npm/v/dsh-better-edit" alt="npm version">
@@ -42,31 +43,55 @@
42
43
 
43
44
  ---
44
45
 
45
- > _"The harness — not the model — is the bottleneck."_ — Can Bölük, [_The Harness Problem_](https://stencil.so/blog/the-harness-problem)
46
+ > **What is `dsh-better-edit`?**
47
+ > A high-precision file editing plugin for [DeepSeek Harness (`dsh`)](https://github.com/deepseek-ai) that replaces volatile line numbers and token-wasting code echoes with immutable, content-addressed 3-character line hashes (`szJ│code`).
48
+ >
49
+ > **Core Philosophy:** Local compute is free; **the model's context window is the most precious resource**. By shifting verification, snapshotting, and alignment to the host, `dsh-better-edit` slashes output tokens by 40–60%, auto-rebases external file drift (e.g., Prettier, Git), and eliminates silent miswrites without forcing full-file re-reads.
46
50
 
47
- > **This is the harness fix.** Hashes replace line numbers — edits above don't shift anchors below. One `read` serves many `edit`s; drift outside your range passes with a notice, true conflicts retry with fresh anchors — no full `read` needed.
51
+ ---
48
52
 
49
- > **3 calls vs 6 · -55.8% tokens · 23/23 correctness.** Same external-drift refactor, same file (single stochastic run; [method](https://github.com/Rianico/pi-better-edit/blob/main/benchmarks/results/2026-08-17-practical-token-benchmark.md)). Payload numbers are deterministic — see [Benchmark](#benchmark).
53
+ ## Why You Need It
50
54
 
51
- ## Why you need this
55
+ ### The 3 Fatal Editing Traps of Autonomous Coding Agents
52
56
 
53
- **If you've watched `line 47 → 74` corrupt a file after an insert — this is for you.**
57
+ File editing is the #1 point of failure for autonomous agents. Traditional tools break down in three distinct ways:
54
58
 
55
- | Before: `str_replace` / line numbers | After: hashline `edit` |
56
- | -------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
57
- | Re-types old code (~5-6× billed) | Two `3-char` hashes, old text never echoed |
58
- | One insert shifts every number → silent wrong line | Content addresses — edits above don't move anchors below |
59
- | No check against what was shown | Every line verified; `[E_STALE_RANGE]`/`[E_UNSERVED_RANGE]` reject before write, then **reject-and-serve** returns fresh `HASH│content` |
59
+ | Fatal Trap in Traditional Tools | Why It Breaks Agents | How `dsh-better-edit` Solves It |
60
+ | ------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
61
+ | **`str_replace` Token Bleed** | Must re-type 30+ lines of unchanged code just to change 1 line ($O(S+R)$), burning expensive output tokens (billed ~5–6× input). | **$O(R)$ Payloads**: Sends only two 3-char hashes (`anchor_from`, `anchor_to`) + replacement. Cuts output tokens by 40–60%. |
62
+ | **Line-Number Coordinate Rot** | Inserting 1 line shifts all line numbers below it. Agents suffer off-by-one errors or must repeatedly re-read the file. | **Position-Independent Anchors**: Line hashes follow content, not line coordinates. Exterior shifts auto-rebase cleanly. |
63
+ | **Silent Miswrites & Drift** | Duplicate lines match the wrong function; external formatters (Prettier) or git updates cause blind overwrites or fatal errors. | **Content-Addressed Line Verification**: Unique anchors via coprime probing; format-tolerant whitespace hashing; fail-closed reject-and-serve. |
60
64
 
61
- > [!TIP]
62
- > **Shining points — honest:**
63
- >
64
- > - **Position-free.** `read 1..5` → `insert @0` → `edit 10..12` still lands at `10..12`. Anchors are `canon(line)` hashes, not positions (ADR-0013). Exterior drift is a notice, not a re-read.
65
- > - **Fewer round-trips.** Single-session `1 read → N edits` — no ritual re-reads. Multi-session exterior `A:10..12 / B:20..30` also passes; only overlapping `A∩B≠∅` retries once via `servedRows` (no full `read`). Harness `9/9` green.
66
- > - **Fewer tokens.** Compact payload `{path, edits:[[from,to,text]]}` + never echoing `old_string`; diff/echo/rejection rows count as serves. Envelope `-40%` pinned 12-edit corpus, session `-55.8%` on external-drift.
67
- > - **Concurrent-safe, not silent.** `retired anchor` per `(session,path)` epoch blocks re-bound `S@3→@3`; `retired` + `canon` + `hash` + `changed∩[L,R]` makes `pos-free` single-thread and `strict` only on true overlap. One retry vs silent wrong-line.
65
+ ---
66
+
67
+ ## Core Pillars
68
+
69
+ ### 1. 🪙 Token Economics (40–60% Context Savings)
70
+
71
+ - **$O(R)$ Edit Payloads**: The model emits only `{ "path": "...", "edits": [["a1b", "c3d", "..."]] }`, never echoing existing code.
72
+ - **Self-Serving Diffs**: Every applied edit returns fresh anchors in the post-edit diff — zero re-read roundtrips to chain edits.
73
+ - **Zero-Token Auto-Rebase**: Non-conflicting exterior shifts resolve locally without agent intervention — 0 tokens, 0 retries.
74
+ - **Atomic Multi-Item Batches**: Apply up to 32 same-file edits in one tool call; overlapping spans abort atomically (`[E_BATCH_ABORT]`) before touching disk.
68
75
 
69
- Not for one-line touch-ups (near parity) or new files (`write`). Pays off in long sessions and structural edits.
76
+ ### 2. 🛡️ Resistance to External Writes (Drift & Concurrency)
77
+
78
+ - **Auto-Formatter Immunity**: Strips ASCII whitespace before hashing. Prettier, Black, and ESLint format-on-save passes never rotate anchors.
79
+ - **Exterior Shift Auto-Rebase**: External edits, git checkouts, or background processes outside the edit span rebase seamlessly without agent intervention.
80
+ - **Fail-Closed Reject-and-Serve**: Contested interior spans fail closed without disk corruption and immediately return fresh on-disk rows in the error (`[E_STALE_RANGE]`, `[E_UNSERVED_RANGE]`) — recovering in **exactly 1 turn**.
81
+ - **Session-Keyed Leases**: Leases are isolated per session, preventing cross-agent race conditions or state pollution.
82
+
83
+ ### 3. 🎯 Zero Silent Miswrites
84
+
85
+ - **Decoupled Line Identity**: Lines are verified against served snapshot lineage, not ephemeral line coordinates.
86
+ - **Collision-Free Anchors**: Coprime bitset probing ensures duplicate lines in a file receive distinct, unambiguous 3-character hashes.
87
+ - **No Heuristic Guessing**: Retires fuzzy matching. If an anchor cannot be unambiguously resolved, it fails closed safely.
88
+ - **Persisted Undo**: `undo_last_edit` restores exact file content, BOM, line endings, and original anchors, persisting across session restarts.
89
+
90
+ ---
91
+
92
+ > _"The harness — not the model — is the bottleneck."_ — Can Bölük, [_The Harness Problem_](https://stencil.so/blog/the-harness-problem)
93
+ >
94
+ > **3 calls vs 6 · -55.8% tokens · 23/23 correctness.** Tested on realistic external-drift refactoring against OMP wrapper. Payload numbers are deterministic — see [Benchmark](#benchmark).
70
95
 
71
96
  ## Quick Start — install to verified edit in 30s
72
97
 
@@ -84,11 +109,14 @@ No config. Next session runs with hashline tools. Verify:
84
109
  dsh --profile <name> --dump-config # shows "# == dsh-better-edit" layer
85
110
  ```
86
111
 
87
- | Requirement | |
88
- | ----------- | ---------------------------------------- |
89
- | Node | `^22.19.0 \|\| >=24.0.0` |
90
- | Profile | `dsh` profile (`dsh plugin` creates one) |
91
- | Backends | sandboxed / remote `ctx.fs` |
112
+ | Requirement | |
113
+ | ----------- | --------------------------------------------------------------------------------- |
114
+ | Node | `^22.19.0 \|\| >=24.0.0` |
115
+ | Profile | `dsh` profile (`dsh plugin` creates one) |
116
+ | Backends | sandboxed / remote `ctx.fs` |
117
+ | dsh | `0.2.1-rc.2` (verified end-to-end; `0.1.6-alpha.2` was the last pre-0.2 baseline) |
118
+
119
+ **dsh 0.2.0+ is supported.** Registration uses `agent/created`, path resolution follows the session's live working directory (`workingDirectory`, with the session header as the pre-0.2.1 fallback), and tool-guidance order comes from `systemPrompt.getSectionOrder`. There is no peer range and no runtime version probing: compatibility comes from that stable surface plus optional-service fallbacks, so a composition that omits `workingDirectory` or `agentPresets` keeps working.
92
120
 
93
121
  ### See it work
94
122
 
@@ -135,7 +163,7 @@ One fails → none write (`[E_BATCH_ABORT]`).
135
163
 
136
164
  ### Configuration
137
165
 
138
- Tenancy and prompt guidance declare once, read at `agent/session-start`, no code change.
166
+ Tenancy and prompt guidance declare once, read at `agent/created`, no code change.
139
167
 
140
168
  **Store** central by default `$DSH_HOME/plugins/dsh-better-edit/runtime/<name>-<hash8>/` (`ls`-readable + `.wsPath` sidecar). DBs are disposable caches — `rm -rf runtime/<name>-<hash8>/` is safe, rebuilt on next `read`.
141
169
 
@@ -150,7 +178,7 @@ storeMaxTotalBytes: 524288000 # 500 MB LRU
150
178
 
151
179
  Env overrides yaml (`DSH_BETTER_EDIT_STORE_DIR`, `DSH_BETTER_EDIT_AUTO_GITIGNORE`).
152
180
 
153
- **Guidance per preset** — `tool:read` / `tool:edit` / `tool:undo_last_edit` are plain markdown per preset at `$DSH_HOME/plugins/dsh-better-edit/<preset>/<section>.md` (orders `130/131/133`). Delete or empty a file → default re-seeds at next boot; keep a `---` fence to blank on purpose.
181
+ **Guidance per preset** — `tool:read` / `tool:edit` / `tool:undo_last_edit` are plain markdown per preset at `$DSH_HOME/plugins/dsh-better-edit/<preset>/<section>.md`. The default order is the harness's own tool slot (`systemPrompt.getSectionOrder`: `1100` read, `1300` edit, `1310` undo), so a band change upstream moves the sections with it; front-matter pins a custom order. The seeded roster is the shipped presets — `standard`, `ptc`, `minimal`, `cordis`. Delete or empty a file → default re-seeds at next boot; keep a `---` fence to blank on purpose.
154
182
 
155
183
  ## Why Hashline
156
184
 
@@ -233,7 +261,7 @@ Full list in `src/` — every rejection echoes fresh rows, no `read` needed.
233
261
 
234
262
  ## How It Replaces Built-ins
235
263
 
236
- dsh resolves `agent → preset → global`; built-ins live on preset. Plugin via `cordis.patch.yml`: at `agent/session-start` registers `read/edit` on agent layer (shadows, auto-unwinds); `write` stays with `pre-execute` guard + `post-execute` auto-read.
264
+ dsh resolves `agent → preset → global`; built-ins live on preset. Plugin via `cordis.patch.yml`: at `agent/created` registers `read/edit` on agent layer (shadows, auto-unwinds); `write` stays with `pre-execute` guard + `post-execute` auto-read.
237
265
 
238
266
  ## Project Structure
239
267
 
@@ -281,12 +309,12 @@ Saved **313 (31%)**. Reproduce: upstream `npm run benchmark`. See [`pi-better-ed
281
309
 
282
310
  ## Roadmap
283
311
 
284
- **Current `0.7.0`:** pos-free `resist`/`strict` + retired anchor/canons/epoch, per-session `(session,path)` store, `1222` tests, `9/9` harness.
312
+ **Current `1.0.0`:** the v2 line-identity architecture, per-session `(session,path)` store, `1648` tests, dsh `0.2.1-rc.2`.
285
313
 
286
314
  <details><summary>Next</summary>
287
315
 
288
316
  - Keep `benchmark/run.mjs` in sync with `ADR-0013` (reads/retries/tokens per session)
289
- - Re-check wiring vs next `dsh` (pinned `0.1.0-rc.6`)
317
+ - Re-check wiring vs next `dsh` (pinned `0.2.1-rc.2`)
290
318
  - `README.zh.md` parity
291
319
 
292
320
  </details>
package/README.zh.md CHANGED
@@ -79,11 +79,14 @@ npx @deepseek-ai/dsh plugin --profile web add /path/to/dsh-better-edit # 从
79
79
  dsh --profile <name> --dump-config # 会显示 "# == dsh-better-edit" 层
80
80
  ```
81
81
 
82
- | 要求 | |
83
- | ------- | -------------------------------------------------------------- |
84
- | Node | `^22.19.0 \|\| >=24.0.0`(dsh 的要求;存储使用 `node:sqlite`) |
85
- | Profile | 一个 dsh profile(首次使用 `dsh plugin` 时初始化) |
86
- | 后端 | 支持沙箱/远程文件系统(写入经 `ctx.fs`) |
82
+ | 要求 | |
83
+ | ------- | --------------------------------------------------------------------- |
84
+ | Node | `^22.19.0 \|\| >=24.0.0`(dsh 的要求;存储使用 `node:sqlite`) |
85
+ | Profile | 一个 dsh profile(首次使用 `dsh plugin` 时初始化) |
86
+ | 后端 | 支持沙箱/远程文件系统(写入经 `ctx.fs`) |
87
+ | dsh | `0.2.1-rc.2`(已端到端验证;`0.1.6-alpha.2` 是上一个 0.2 之前的基线) |
88
+
89
+ **支持 dsh 0.2.0 及以上。** 注册走 `agent/created`,路径解析跟随会话的**实时**工作目录(`workingDirectory`,0.2.1 之前回退到 session header),工具指引的 order 取自 `systemPrompt.getSectionOrder`。没有 peer 版本范围,也不做运行时版本探测:兼容性来自这层稳定接口加可选服务回退——缺少 `workingDirectory` 或 `agentPresets` 的组合同样可用。
87
90
 
88
91
  `read` 返回的每一行都带有哈希前缀——哈希*就是*这一行的地址:
89
92
 
@@ -114,7 +117,7 @@ kQm│}
114
117
 
115
118
  ### 配置
116
119
 
117
- 租约与提示词指引都只需声明一次,在 `agent/session-start` 时读取,无需改代码。
120
+ 租约与提示词指引都只需声明一次,在 `agent/created` 时读取,无需改代码。
118
121
 
119
122
  #### 存储租约 — 默认 central
120
123
 
@@ -144,7 +147,7 @@ DSH_BETTER_EDIT_STORE_DIR=central|workspace|/abs
144
147
  DSH_BETTER_EDIT_AUTO_GITIGNORE=true|false # 大小写不敏感
145
148
  ```
146
149
 
147
- 旧的 `<workspace>/.dsh_better_edit/` 在首次以 central 打开时一次性拷贝;`runtime/<name>-<hash8>/` 可通过 `ls` 查看,带 `.wsPath` 旁路文件。生命周期详见 `docs/specs/issue-24-store-tenancy.md`(janitor `mtime>storeMaxAgeS` 后 LRU、WAL checkpoint、`undo` TTL)。
150
+ 旧的 `<workspace>/.dsh_better_edit/` 在首次以 central 打开时一次性拷贝;`runtime/<name>-<hash8>/` 可通过 `ls` 查看,带 `.wsPath` 旁路文件。工作区身份跟随会话的**实时**工作目录(`working_directory` 工具),而不是会话创建时的目录。生命周期详见 `docs/specs/issue-24-store-tenancy.md`(janitor `mtime>storeMaxAgeS` 后 LRU、WAL checkpoint、`undo` TTL)。
148
151
 
149
152
  #### 按 preset 的指引
150
153
 
@@ -158,11 +161,11 @@ $DSH_HOME/plugins/dsh-better-edit/<preset>/<section>.md
158
161
 
159
162
  | 文件 | 提示词片段 | 默认 order |
160
163
  | ------------------- | --------------------- | ---------- |
161
- | `read.md` | `tool:read` | 130 |
162
- | `edit.md` | `tool:edit` | 131 |
163
- | `undo_last_edit.md` | `tool:undo_last_edit` | 133 |
164
+ | `read.md` | `tool:read` | 1100 |
165
+ | `edit.md` | `tool:edit` | 1300 |
166
+ | `undo_last_edit.md` | `tool:undo_last_edit` | 1310 |
164
167
 
165
- 首次启动时插件会为三个随附 preset——`standard/`、`code/`、`minimal/`、`cordis/`——各自写入编译内置的可编辑指引文件(含 `order` front-matter)。详见[配置详情](#按-preset-配置指引)的重置/恢复。完整规范:`docs/specs/issue-24-store-tenancy.md` 与指引文档。
168
+ 首次启动时插件会为四个随附 preset——`standard/`、`ptc/`、`minimal/`、`cordis/`——各自写入编译内置的可编辑指引文件(含 `order` front-matter)。默认 order 取自 harness 自己的工具槽位(`systemPrompt.getSectionOrder`),上游调整 band 时会自动跟随;front-matter 可自行钉死。详见[配置详情](#按-preset-配置指引)的重置/恢复。完整规范:`docs/specs/issue-24-store-tenancy.md` 与指引文档。
166
169
 
167
170
  ##### 重置 / 恢复默认
168
171
 
@@ -177,7 +180,7 @@ $DSH_HOME/plugins/dsh-better-edit/<preset>/<section>.md
177
180
 
178
181
  - **为什么要连栅栏一起删**:只要文件里还有 `---` 栅栏,哪怕是空的、什么内容也没有,插件都当成“你有意留空”,不会去动它。所以“故意留空”就保留栅栏;“恢复默认”就把栅栏和内容一起清掉。
179
182
  - **栅栏写错了会怎样**:少了一个 `---`、`order` 不是数字、出现了不认识的键——只要栅栏格式不对,插件会直接忽略这个文件:仍然渲染默认指引,并在日志里提示是哪个文件、哪里写错了。你写的正文会原样留在磁盘上,方便改好后再用。
180
- - **自带 preset 与自定义 preset**:插件自带的四个 preset(`standard`、`code`、`minimal`、`cordis`)会在下一次启动时自动补全空白文件;自定义 preset 里删除的覆盖文件不会自动出现(删了就当“没有这个文件”)。删掉某一整个 preset 目录,下次启动时插件会重新生成里面的四个文件(仅限自带 preset)。
183
+ - **自带 preset 与自定义 preset**:插件自带的四个 preset(`standard`、`ptc`、`minimal`、`cordis`)会在下一次启动时自动补全空白文件;自定义 preset 里删除的覆盖文件不会自动出现(删了就当“没有这个文件”)。删掉某一整个 preset 目录,下次启动时插件会重新生成里面的三个片段文件(仅限自带 preset)。
181
184
  - **恢复的是“当前版本”的默认**:插件升级后,重置得到的是新版本带的新默认内容,不是旧版本留下的。
182
185
 
183
186
  文件的重新生成只发生在插件启动时,绝不影响进行中的会话。
@@ -300,14 +303,14 @@ token 基准测试衡量的是模型发出的负载——它假设模型每次
300
303
  dsh 的工具注册表按作用域解析:agent 看到的是 `agent → preset → global`,且**自身**层总是优先。内置的 `read`/`edit` 位于 agent-preset 层,因此普通的全局注册无法替换它们。本插件:
301
304
 
302
305
  1. 通过其 `cordis.patch.yml` bundle 补丁作为宿主层 Cordis 插件挂载。
303
- 2. 在 `agent/session-start` 时,将 hashline 工具**以及** `tool:read` / `tool:edit` 提示词片段注册到 agent 自身的作用域层——从而为该 agent 遮蔽 preset 的内置工具,并在 agent 销毁时自动解除。
306
+ 2. 在 `agent/created` 时,将 hashline 工具**以及** `tool:read` / `tool:edit` 提示词片段注册到 agent 自身的作用域层——从而为该 agent 遮蔽 preset 的内置工具,并在 agent 销毁时自动解除。
304
307
  3. 保留内置的 `write`,通过作用域内的 `tools/pre-execute` 监听器在执行前拒绝精确的同会话/同路径/同行锚点回显,并由 `tools/post-execute` 在成功结果后附加 hashline 自动读取。
305
308
 
306
309
  ## 存储
307
310
 
308
311
  哈希快照、已提供状态行与撤销历史存放在一个 SQLite 库中——**默认 central**(`$DSH_HOME/plugins/dsh-better-edit/runtime/<name>-<hash8>/hash-store.sqlite`,可通过 `ls` 查看,带 `.wsPath` 旁路文件)。旧的同址 `<workspace>/.dsh_better_edit/` 仍可通过 `config.yaml` 中 `storeDir: workspace` 启用,并在首次以 central 打开时一次性拷贝。不同工作区的并行会话各自持有独立的库(会话 cwd 会随每次工具调用传递),因此一个项目的锚点与撤销历史不会泄漏到另一个项目。在工具调用之外(测试、预览)会回退到共享的 DeepSeek Harness 主目录(`$DSH_HOME/plugins/dsh-better-edit/hash-store.sqlite`)。
309
312
 
310
- 7 天 TTL 清理已提供的行;`undo_ttl_s`(默认 7 天,`-1` 永久)清理撤销副本;缺失文件的快照在受控的 `openStore` 中清理;损坏的库会被隔离并自动重建。 central 的 janitor(`apply` + `agent/session-start` 受控节流 >24h)会先清理 `mtime>storeMaxAgeS`(默认 2592000 秒 = 30 天),再按 LRU 至 `count<100 && sum<500MB`,永不删除存活的 `hash(workspaceCwd)`,并在关闭时执行 `wal_checkpoint(TRUNCATE)`。DB 文件为可丢弃缓存——可安全删除,下次 `read` 时重建。
313
+ 7 天 TTL 清理已提供的行;`undo_ttl_s`(默认 7 天,`-1` 永久)清理撤销副本;缺失文件的快照在受控的 `openStore` 中清理;损坏的库会被隔离并自动重建。 central 的 janitor(`apply` + `agent/created` 受控节流 >24h)会先清理 `mtime>storeMaxAgeS`(默认 2592000 秒 = 30 天),再按 LRU 至 `count<100 && sum<500MB`,永不删除存活的 `hash(workspaceCwd)`,并在关闭时执行 `wal_checkpoint(TRUNCATE)`。DB 文件为可丢弃缓存——可安全删除,下次 `read` 时重建。
311
314
 
312
315
  ## 项目结构
313
316
 
@@ -354,14 +357,14 @@ npm publish --registry https://registry.npmjs.org # 版本未打 tag 前会被
354
357
 
355
358
  ## 路线图
356
359
 
357
- **当前状态(0.1.7):** 615 个测试、按工作区存储、参与沙箱策略、served-tail 截断修复、可复现基准测试、中英双语 README、已发布 npm。
360
+ **当前状态(1.0.0):** v2 行身份架构、按会话 `(session,path)` 存储、1648 个测试、中英双语 README、dsh `0.2.1-rc.2`。
358
361
 
359
362
  <details><summary>下一步</summary>
360
363
 
361
364
  - **缩小或证明与 @oh-my-pi/hashline 的差距**(参考:[`../oh-my-pi.md`](../oh-my-pi.md))。这个兄弟补丁语言负载更轻——基准测试中相对 `str_replace` 省 42%/53%,而我们省 31%,因为它裸文本式的补丁文档跳过了我们每次调用都要付的 JSON 外壳——还提供了我们不支持的四种能力:语法块操作(`PUT N*:`)、寄存器 + `REM`/`MV`、一次变更一个多 hunk 文档、可插拔文件系统。代价在正确性一侧:它的行号未经验证(当前标签下的错行号会静默落盘)、每次编辑都要重新编号、过期标签触发尽力而为的三方合并而非校验、语法也抬高了模型的技能门槛。逐项决定是拒绝还是采纳——负载差距本身不足以成为切换格式的理由。
362
- - 在 dsh 会话中实测 0.1.7(served-tail 修复之后)。
365
+ - 在 dsh 会话中实测 1.0.0(0.2.1-rc.2 运行时)。
363
366
  - 把 served-tail 截断修复回馈给 pi-hashline-edit-lsz / 上游(他们的 `upsertServed` 同样从不截断)。
364
- - 对照下一个 dsh 版本重新核对插件接线(当前固定在 `0.1.0-rc.6`;dsh 处于开发者预览阶段,承诺会有破坏性变更)。
367
+ - 对照下一个 dsh 版本重新核对插件接线(当前固定在 `0.2.1-rc.2`;dsh 处于开发者预览阶段,承诺会有破坏性变更)。
365
368
 
366
369
  </details>
367
370
 
package/cordis.patch.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # dsh-better-edit bundle patch: mount the host-plane plugin row.
2
2
  # Installed via `dsh plugin add dsh-better-edit` (or a profile's bundle list).
3
- # The plugin hooks agent/session-start and shadows the built-in read/edit tools
3
+ # The plugin hooks agent/created and shadows the built-in read/edit tools
4
4
  # (plus batch_edit / undo_last_edit) on each agent's own scope layer, so no
5
5
  # preset editing or user config is needed.
6
6
  - insert:
package/lib/constants.js CHANGED
@@ -1,18 +1,33 @@
1
+ import { formatError } from "./domain-errors.js";
1
2
  export const AUTO_READ_MAX = 2000;
2
3
  export const SNIFF_BYTES = 8192;
3
4
  export const MAX_BYTES = 100 * 1024 * 1024;
4
5
  export const MAX_READ_LINE_BYTES = 200 * 1024;
5
6
  export const HASH_STORE_BUSY_TIMEOUT = 1000;
6
- export const HASH_STORE_VERSION = 6;
7
+ export const HASH_STORE_VERSION = 7;
7
8
  export const EDITS_MAX_ITEMS = 32;
8
9
  /** @deprecated batch_edit seam removed (ADR-0003) — use EDITS_MAX_ITEMS */
9
10
  export const BATCH_EDIT_MAX_ITEMS = EDITS_MAX_ITEMS;
10
11
  export const SERVED_TTL_MS = 7 * 24 * 60 * 60 * 1000;
11
12
  export const SERVED_ECHO_CAP = 150;
13
+ // WHY: ADR-0024/D3 — the applied diff's removed-line cap, the mirror of the served-row cap on the
14
+ // WHY: refusal side: a range deletion renders head + tail with an exact omitted count instead of
15
+ // WHY: every removed row. The omitted rows still advance the render cursor, so every surviving row
16
+ // WHY: keeps its exact old line number and hash.
17
+ export const DIFF_REMOVED_CAP = 6;
18
+ export const DIFF_REMOVED_EDGE = 2;
12
19
  export const NOOP_LOOP_THRESHOLD = 3;
13
- export const NEW_CONTENT_NOT_STRING_MSG = `[MODEL] [E_BAD_PAYLOAD] "replacement_text" must be a string with \\n line separators, not an array.` +
20
+ export const NEW_CONTENT_BODY = `"replace_with" must be a string with \\n line separators, not an array.` +
14
21
  ` Do not pass an array of lines — pass the replacement text as one string: "line1\\nline2". Use "" to delete a range.`;
22
+ /** Model-facing header for a non-string replace_with, composed once by the registry. */
23
+ export const NEW_CONTENT_NOT_STRING_MSG = formatError("E_BAD_PAYLOAD", {
24
+ message: NEW_CONTENT_BODY,
25
+ });
15
26
  export function eLargeFileMsg(displayPath, lineCount, maxLines) {
16
- return `[MODEL] [E_LARGE_FILE] ${displayPath} has ${lineCount} lines, exceeding the ${maxLines}-line edit limit. Hashline editing targets source-sized files; for very large files use write or a non-line-based approach.`;
27
+ return formatError("E_LARGE_FILE", {
28
+ path: displayPath,
29
+ lineCount,
30
+ limit: maxLines,
31
+ limitKind: "lines",
32
+ });
17
33
  }
18
- export const E_ANCHOR_SPACE_EXHAUSTED_WARNING = "[E_ANCHOR_SPACE_EXHAUSTED] Anchor space exhausted";