dsh-better-edit 0.1.9 → 0.2.1

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 (58) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +168 -52
  3. package/README.zh.md +122 -46
  4. package/assets/logo.svg +183 -18
  5. package/lib/contract.js +95 -0
  6. package/lib/drift.js +1 -1
  7. package/lib/edit-diff.js +2 -2
  8. package/lib/edit-engine.js +456 -0
  9. package/lib/edit-pipeline.js +41 -116
  10. package/lib/file-reader.js +1 -2
  11. package/lib/fs-bridge.js +2 -2
  12. package/lib/fs-write.js +3 -46
  13. package/lib/guidance.js +282 -0
  14. package/lib/hash-store.js +246 -13
  15. package/lib/hashline/apply.js +2 -2
  16. package/lib/hashline/hash.js +16 -206
  17. package/lib/hashline/index.js +4 -3
  18. package/lib/hashline/parse.js +1 -1
  19. package/lib/hashline/pure.js +213 -0
  20. package/lib/hashline/resolve.js +1 -5
  21. package/lib/hashline/served.js +2 -2
  22. package/lib/index.js +48 -32
  23. package/lib/paths.js +55 -1
  24. package/lib/prompts.js +53 -49
  25. package/lib/read-and-serve.js +46 -0
  26. package/lib/schema.js +1 -1
  27. package/lib/served-store.js +144 -183
  28. package/lib/tool-batch-edit.js +28 -280
  29. package/lib/tool-edit.js +37 -32
  30. package/lib/tool-read.js +8 -31
  31. package/lib/tool-undo.js +4 -13
  32. package/lib/types/contract.d.ts +39 -0
  33. package/lib/types/edit-engine.d.ts +179 -0
  34. package/lib/types/edit-pipeline.d.ts +10 -17
  35. package/lib/types/fs-write.d.ts +0 -1
  36. package/lib/types/guidance.d.ts +98 -0
  37. package/lib/types/hash-store.d.ts +73 -25
  38. package/lib/types/hashline/hash.d.ts +8 -13
  39. package/lib/types/hashline/index.d.ts +4 -3
  40. package/lib/types/hashline/pure.d.ts +26 -0
  41. package/lib/types/hashline/resolve.d.ts +0 -1
  42. package/lib/types/index.d.ts +4 -0
  43. package/lib/types/paths.d.ts +9 -0
  44. package/lib/types/prompts.d.ts +19 -9
  45. package/lib/types/read-and-serve.d.ts +39 -0
  46. package/lib/types/schema.d.ts +2 -16
  47. package/lib/types/served-store.d.ts +63 -32
  48. package/lib/types/tool-batch-edit.d.ts +4 -1
  49. package/lib/types/tool-undo.d.ts +1 -1
  50. package/lib/undo-edit.js +16 -1
  51. package/lib/write-hook.js +30 -50
  52. package/package.json +5 -3
  53. package/lib/served-state.js +0 -34
  54. package/lib/snapshot-store.js +0 -108
  55. package/lib/types/served-state.d.ts +0 -3
  56. package/lib/types/snapshot-store.d.ts +0 -14
  57. package/lib/types/undo-store.d.ts +0 -14
  58. package/lib/undo-store.js +0 -43
package/CHANGELOG.md CHANGED
@@ -4,6 +4,38 @@ All notable changes to the `dsh-better-edit` plugin will be documented in this f
4
4
 
5
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
6
 
7
+ ## [Unreleased]
8
+
9
+ ## [0.2.1] - 2026-08-18
10
+
11
+ ### Added
12
+
13
+ - Configurable per-preset tool guidance (issues #7, #8; tickets #9–#13): the four `tool:*` prompt sections resolve from plain-markdown override files keyed by agent preset — `$DSH_HOME/plugins/dsh-better-edit/<preset>/<section>.md` — with an optional `order` front-matter. On first boot the plugin seeds each shipped preset (`standard`, `code`, `minimal`, `cordis`) with its guidance as editable files plus a root README documenting the scheme. Per section the chain is `<preset>/<section>.md` → compiled default; files are read once per agent at session-start, so edits apply to new sessions. Deployments without the `agentPresets` service keep the compiled defaults untouched.
14
+ Default orders sit at 130–133, above the built-in tool-guidance band (100–116 in the shipped
15
+ dsh), so a same-order section merge with unrelated tool guidance cannot occur out of the box; the
16
+ seeded preset files expose that `order` as editable front-matter.
17
+ - Default guidance text simplified per the writing-for-agents principles; the `*_GUIDELINES` constants unified on `*_GUIDANCE`.
18
+ - Thanks to [@R-LEI2536](https://github.com/R-LEI2536) for requesting configurable per-preset prompts and for the design input that shaped this release (issue [#7](https://github.com/Rianico/dsh-better-edit/issues/7)).
19
+
20
+ ### Changed
21
+
22
+ - Benchmark extended to a third arm, `@oh-my-pi/hashline`: same corpus, same 12 replacements, two modes (per-edit `seq` with renumbered lines + one-document `batch` fixed to original line numbers). Payloads are built from the package's published grammar and validated before counting (the package is Bun-only, so it cannot run under the Node benchmark). Honest result, reported as such: hashline saves 31% vs `str_replace` on the session (43% on multi-line ranges) and remains the plugin's claim; the compact patch language saves 42% per edit / 53% batched — and this README says so. `npm run benchmark` stays byte-deterministic (verified over repeated runs).
23
+ - READMEs (English and 中文) refined along ponytail-style lines: "How It Compares" gains an `@oh-my-pi/hashline` column plus a same-lineage/different-jobs comparison; the Benchmark section documents all three arms, adds an honest "regenerate, don't trust" reproducibility note, and widens the scope-and-honesty block with what the payload numbers do *not* capture (renumber/tag-chase cost, block ops, Bun-vs-Node, tool-pair vs patcher library).
24
+ - `package.json` keywords now include `oh-my-pi` alongside `hashline`.
25
+ - Roadmap gains a first-class decision item: close or justify the gap vs `@oh-my-pi/hashline` (payload-lighter by 42%/53% vs 31%, with block ops / registers / `REM`/`MV` / multi-hunk documents / pluggable fs we do not support — against correctness costs: unverified line numbers, renumber-per-edit, best-effort merge on stale tags, model skill floor). A reference record lives at `../oh-my-pi.md` (workspace-level, outside this repo): the token comparison, the correctness asymmetry, the ability-by-ability status, and the decision rationale.
26
+
27
+ ## [0.2.0] - 2026-08-16
28
+
29
+ ### Changed
30
+
31
+ - Architecture deepening across six refactors (GitHub issues #1–#6), with the model-facing contract unchanged — every `[E_…]` code and message byte-identical, full suite green (615 → 626 tests):
32
+ - Served state (what the model has been shown) now lives in one async module: the doubled sync/async store interface (whose sync half had zero production callers) is gone, and the served-row merge invariant — stale tail / duplicate anchors — is one shared helper with a regression test.
33
+ - `edit` and `batch_edit` run on one edit-sequence engine — apply-one, the multi-edit sequencer, the noop-loop guard, and the persist-undo → write → restore transaction — replacing `batch_edit`'s duplicated 685-line pipeline with a thin orchestrator. Batch apply, atomic batch rejection, and undo revert are now covered by end-to-end tests.
34
+ - The hashline anchor math is a pure module (no store imports); persistence is a thin wrapper over it. The public hashline interface shrank to the consumer call surface.
35
+ - The `read` tool and the write auto-read share one read-and-serve operation; canonical path resolution moved out of the write module into the path helpers.
36
+ - All four tools validate requests through one contract module — field sets and the `[E_BAD_SHAPE]` vocabulary declared once.
37
+ - The hash store exposes domain APIs (snapshots / undo / served) instead of raw prepared statements; corruption handling and cross-table cleanup are owned by the store, and the import graph is acyclic.
38
+
7
39
  ## [0.1.9] - 2026-08-15
8
40
 
9
41
  ### Changed
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  <p align="center">
8
8
  <strong>Hash-anchored edit tools for DeepSeek Harness.<br>
9
- Edit by content address — not line numbers. Fewer tokens. Zero misapplied edits.</strong>
9
+ Edit by content address — not by line numbers, not by string replacement. Fewer tokens. More attention for real work. Zero misapplied edits.</strong>
10
10
  </p>
11
11
 
12
12
  <p align="center">
@@ -18,7 +18,6 @@
18
18
  <a href="#quick-start">Quick Start</a> •
19
19
  <a href="#why-hashline">Why Hashline</a> •
20
20
  <a href="#benchmark">Benchmark</a> •
21
- <a href="#installation">Installation</a> •
22
21
  <a href="#tools">Tools</a> •
23
22
  <a href="#acknowledgments">Acknowledgments</a>
24
23
  </p>
@@ -57,6 +56,25 @@ Not for one-line touch-ups (near parity) or new files (`write`). It pays off in
57
56
 
58
57
  ## Quick Start
59
58
 
59
+ ### Install
60
+
61
+ ```sh
62
+ dsh plugin --profile <name> add dsh-better-edit # from npm
63
+ dsh plugin --profile <name> add /path/to/dsh-better-edit # from a local checkout
64
+ ```
65
+
66
+ The profile's next session runs with the hashline tools installed. To verify the layer is active:
67
+
68
+ ```sh
69
+ dsh --profile <name> --dump-config # shows a "# == dsh-better-edit" layer
70
+ ```
71
+
72
+ | Requirement | |
73
+ | --- | --- |
74
+ | Node | `^22.19.0 \|\| >=24.0.0` (dsh's requirement; the store uses `node:sqlite`) |
75
+ | Profile | a dsh profile (`dsh plugin` initializes one on first use) |
76
+ | Backends | sandboxed / remote filesystems supported (writes go through `ctx.fs`) |
77
+
60
78
  `read` returns every line prefixed by its hash — the hash *is* the line's address:
61
79
 
62
80
  ```text
@@ -84,6 +102,52 @@ and produces a diff with fresh anchors, so the next edit verifies cleanly with n
84
102
  kQm │ }
85
103
  ```
86
104
 
105
+ ## Configuring Guidance per Preset
106
+
107
+ The `tool:read` / `tool:edit` / `tool:batch_edit` / `tool:undo_last_edit` guidance sections are
108
+ plain-markdown files, overridable per agent preset. Override files live in the plugin's shared
109
+ home — never the workspace store:
110
+
111
+ ```
112
+ $DSH_HOME/plugins/dsh-better-edit/<preset>/<section>.md
113
+ ```
114
+
115
+ (default home `~/.dsh`, so `~/.dsh/plugins/dsh-better-edit/`). The section table:
116
+
117
+ | File | Section | Default order |
118
+ | --- | --- | --- |
119
+ | `read.md` | `tool:read` | 130 |
120
+ | `edit.md` | `tool:edit` | 131 |
121
+ | `batch_edit.md` | `tool:batch_edit` | 132 |
122
+ | `undo_last_edit.md` | `tool:undo_last_edit` | 133 |
123
+
124
+ On first boot the plugin seeds the four shipped presets — `standard/`, `code/`,
125
+ `minimal/`, `cordis/` — each with the compiled guidance as editable files (plus
126
+ `order` front-matter), so every preset's guidance starts editable rather than
127
+ blank. A `README.md` at the plugin-home root documents the scheme. Files are
128
+ seeded once and never rewritten, so your edits survive. A preset directory may
129
+ hold only the sections you want to override — the rest fall through to the
130
+ compiled defaults.
131
+
132
+ A file is pure prose unless it opens with an `order` front-matter fence, which moves the section in
133
+ the assembled system prompt:
134
+
135
+ ```md
136
+ ---
137
+ order: 150
138
+ ---
139
+
140
+ <section text>
141
+ ```
142
+
143
+ Per section, resolution reads `<preset>/<section>.md`, else the compiled
144
+ default. Files are read once per agent at session-start, so edits apply to new
145
+ sessions — never mid-session. A preset with no seeded directory (e.g. a
146
+ user-authored one) falls back to the compiled defaults unless you copy a seeded
147
+ dir to its name. A deployment without the `agentPresets` service (no preset
148
+ roster) keeps the compiled defaults and never touches these files; presets are
149
+ never required.
150
+
87
151
  ## Why Hashline
88
152
 
89
153
  **Token-saving.** An edit call carries `remove_from` / `remove_to` (two 3-char hashes) plus the
@@ -92,6 +156,11 @@ text verbatim. On a 12-edit session over a realistic file this is **31% fewer ou
92
156
  on multi-line ranges) — and these are *output* tokens, billed at ~5-6× the input rate. See the
93
157
  [benchmark](#benchmark).
94
158
 
159
+ **But this was never about “fewest tokens.”** Savings scale with the replaced text — near parity on
160
+ one-line touch-ups — and a compact patch language like [@oh-my-pi/hashline](#how-it-compares) can
161
+ emit a lighter payload still (42–53% on the same session). The point is the *right* kind of edit
162
+ call: no re-typing old code, and nothing for the model to track except two stable content addresses.
163
+
95
164
  **Correctness.** Every resolved edit range is verified against the exact lines the model was shown.
96
165
  A stale, never-served, or ambiguous range is hard-rejected **before anything is written**, and the
97
166
  current range is echoed back as fresh anchors (reject-and-serve) — the retry needs no `read`.
@@ -102,74 +171,108 @@ pins a line by what it *is*, not by where it used to sit.
102
171
 
103
172
  ### How It Compares
104
173
 
105
- | | hashline `edit` | `str_replace` | line-number edit |
174
+ | | hashline `edit` | `str_replace` (Claude Code / Codex) | @oh-my-pi/hashline patch |
106
175
  | --- | :---: | :---: | :---: |
107
- | Replaced text echoed in the call | ✅ no — 2 hashes | ❌ verbatim | ✅ no |
108
- | Verification against what the model saw | ✅ every line | ❌ first match wins | ~ |
109
- | Stale file detected | ✅ rejects, fresh anchors | ❌ may match wrong spot | ~ |
110
- | Anchors survive edits above | ✅ content-addressed | ✅ content-based | ❌ re-read needed |
111
- | Chained edits without re-reads | ✅ diff serves fresh anchors | ~ | ❌ |
112
- | Unambiguous when text repeats | ✅ boundary anchors verified | ❌ first occurrence | ~ |
113
- | Wrong-line edit can land silently | ❌ impossible | ✅ | ✅ |
114
-
115
- > `~` = occasionally / inconsistently. Line-number edit tools accept a line range and apply it to
116
- > whatever is at that offset when the call executes — cheap, but stale the moment anything above
117
- > moves.
176
+ | Replaced text never echoed in the call | ✅ 2 hashes only | ❌ verbatim | ✅ `+` rows only |
177
+ | Lines addressed by | content hash | text match | number + file-content tag |
178
+ | Verified against what the model saw | ✅ every line | ❌ first match wins | ~ file version only |
179
+ | Stale file detected | ✅ rejects, fresh anchors | ❌ may match wrong spot | ✅ tag mismatch → refuse or 3-way merge |
180
+ | Anchors survive edits above | ✅ content-addressed | ✅ content-based | ❌ renumber + new tag |
181
+ | Chained edits without re-reads | ✅ diff serves fresh anchors | ~ | ~ via edit-response numbers |
182
+ | Unambiguous when text repeats | ✅ boundary anchors verified | ❌ first occurrence | ~ position, unverified per line |
183
+ | Wrong-line edit never lands silently | ✅ every line verified | ❌ first match wins | ~ possible in principle (tag checks version, not lines) |
184
+ | Block ops / registers / `MV` / `REM` | ❌ | ❌ | ✅ |
185
+ | One document per change | ❌ per-edit call | ❌ per-edit call | ✅ multi-hunk patch |
186
+ | Runtime | ✅ Node (dsh) | — | ⚠️ Bun only |
187
+ | Undo | ✅ persisted | ❌ | ❌ not in scope |
188
+
189
+ > `~` = occasionally / inconsistently. `@oh-my-pi/hashline` is a compact line-anchored patch language
190
+ > ([npm](https://www.npmjs.com/package/@oh-my-pi/hashline), [repo](https://github.com/can1357/oh-my-pi/tree/main/packages/hashline)):
191
+ > `[path#tag]` headers bind each hunk to a full-file content hash, `PUT N.=M:` addresses lines by
192
+ > number, and every edit renumbers — take the next numbers and tag from the edit response or a fresh `read`.
193
+
194
+ **Different jobs, same lineage.** Both descend from the
195
+ [harness-problem](https://stencil.so/blog/the-harness-problem) insight that the model should never
196
+ re-type old code. `@oh-my-pi/hashline` is a **patch-language library** — payload-light (42% saved
197
+ per edit, 53% in a single batch document, see [benchmark](#benchmark)), with syntactic block ops
198
+ (`PUT N*:`), registers, `REM`/`MV`, multi-hunk documents, a pluggable filesystem for any backend,
199
+ and session-aware 3-way-merge recovery on stale tags. This plugin is a **dsh tool pair**: `read`
200
+ hands the model 3-char content hashes, `edit` takes two of them, and every resolved line is verified
201
+ against the served state — no line numbers to renumber, no tag to re-fetch, a wrong anchor can never
202
+ land on the wrong line, and `undo_last_edit` survives restarts. Its trade-offs: a JSON envelope per
203
+ edit costs a little payload, there are no block ops, and it lives inside dsh (Node) rather than as a
204
+ standalone patcher (Bun). Pick hashline-the-library for a cross-backend patch format; pick
205
+ hashline-the-tool for verified, content-addressed edits in your agent.
206
+
207
+ ### Correctness in edge cases
208
+
209
+ The token benchmark measures the payload the model emits — it assumes the model gets every
210
+ address right, for free. Correctness is where the two hashline implementations actually diverge.
211
+ These are the real failure modes from the harness-problem literature (wrong-line edits, drift,
212
+ repeated text), and what each tool does when they hit:
213
+
214
+ | Edge case | hashline `edit` (this plugin) | @oh-my-pi/hashline patch |
215
+ | --- | --- | --- |
216
+ | Wrong address (off-by-one anchor / line number) | **Impossible** — anchors resolve to specific lines; every resolved line is verified against served state, rejected **before** anything is written | **Possible** — a wrong line number against a current tag applies **silently** at the wrong place; the tag proves the file version, never the lines |
217
+ | File changed on disk after the model's view | Hard reject + fresh anchors echoed (reject-and-serve); retry needs no `read` | Tag mismatch → refuse **or best-effort 3-way merge** onto unknown current content |
218
+ | An edit above shifts the file | Nothing shifts — anchors are content addresses; the diff serves fresh anchors | **Every edit renumbers** — “RE-GROUND AFTER EVERY EDIT” is the format's own #1 rule; the model carries the bookkeeping |
219
+ | Repeated / identical text | Per-line hashes are unique (collision-resolved); ambiguity → `[E_AMBIGUOUS_ANCHOR]` | Position-based, so repeats don't confuse it — but the position itself is unverified |
220
+ | Lines never shown to the model | `[E_RANGE_UNSERVED]` — hard reject with fresh anchors | Undisplayed hunks rejected — same reliance on the model knowing what it saw |
221
+ | Mid-expression / wrong block node | Irrelevant — any verified line range is valid | Grammar rules + `PUT N*:` node choice; mispointing (anchoring `def` orphans its decorator) silently lands wrong; no syntax check |
222
+ | Multi-edit batch fails mid-way | `batch_edit` — atomic, all-or-nothing; the failing item is echoed as fresh serves | Multi-section patches preflighted up front — also atomic |
223
+
224
+ > The 42–53% oh-my-pi payload saving is a lighter wire format; the table above is what that
225
+ > format asks the model to hold in its head instead — renumbering, tag-chasing, node choice —
226
+ > the exact component that fails most (46–51% patch-failure rates on replace-style edits). This
227
+ > plugin's 31% is the price of a contract where a wrong edit cannot land, and any rejection
228
+ > needs no re-read.
118
229
 
119
230
  ## Benchmark
120
231
 
121
232
  Measured on the same 103-line file with the same 12 replacements (8 single-line, 4 multi-line of
122
- 3/6/10/15 lines), tokenized with the pinned `js-tiktoken` `cl100k_base`:
123
-
124
- | Criterion | hashline | str_replace |
125
- | ----------- | :---: | :---: |
126
- | Replaced text sent over the wire | ✅ never | ❌ every edit |
127
- | Output tokens saved (12-edit session) | ✅ **31%** | ❌ 0% |
128
- | Multi-line range savings (3–15 lines) | ✅ **29–47%** | ❌ 0% |
129
- | Effective cost at 5× output pricing | ✅ **~1.4× less** | ❌ 1× |
130
- | Ranges verified against served state | ✅ 100% | ❌ none |
131
- | Deterministic, reproducible locally | ✅ `npm run benchmark` | — |
233
+ 3/6/10/15 lines), tokenized with the pinned `js-tiktoken` `cl100k_base`. Three arms emit the same
234
+ replacements: this plugin's `edit` (two 3-char anchors), a `str_replace` tool (old text echoed
235
+ verbatim), and [`@oh-my-pi/hashline`](https://www.npmjs.com/package/@oh-my-pi/hashline) in both of
236
+ its modes — one `[path#tag]` section per edit (`seq`) and one multi-hunk batch document (`batch`):
237
+
238
+ | Criterion | hashline | str_replace | oh-my-pi seq / batch |
239
+ | ----------- | :---: | :---: | :---: |
240
+ | Replaced text sent over the wire | ✅ never | ❌ every edit | ✅ never |
241
+ | Output tokens saved (12-edit session) | ✅ **31%** | ❌ 0% | ✅ **42% / 53%** |
242
+ | Multi-line range savings (3–15 lines) | ✅ **29–47%** | ❌ 0% | ✅ **40–53%** |
243
+ | Effective cost at 5× output pricing | ✅ **~1.4× less** | ❌ 1× | ✅ **~1.7× / ~2.1× less** |
244
+ | Ranges verified against served state | ✅ 100% | ❌ none | ~ file version only |
245
+ | Line numbers the model must track | ✅ none — content anchors | ✅ none — text match | ❌ renumber every edit |
246
+ | Deterministic, reproducible locally | ✅ `npm run benchmark` | — | — |
132
247
 
133
248
  ### Reproducible
134
249
 
135
250
  The numbers above are **deterministic and you can reproduce them locally** — `npm run benchmark`:
136
251
 
137
- | Scenario | Lines | hashline | str_replace | Saved | % |
252
+ | Scenario | Lines | hashline | str_replace | oh-my-pi seq | oh-my-pi batch |
138
253
  | --- | :---: | :---: | :---: | :---: | :---: |
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%** |
254
+ | single-line ×8 | 1 | 309 | 324 | 241 | — |
255
+ | multi-line ×4 | 3–15 | 393 | 691 | 349 | — |
256
+ | **TOTAL ×12** | | **702** | **1015** | **590** | **480** |
257
+
258
+ Saved vs `str_replace`: hashline **313 (31%)** · oh-my-pi per-edit **425 (42%)** · oh-my-pi batch **535 (53%)**.
142
259
 
143
260
  The script is deterministic by construction: a frozen corpus, a content-addressed edit script that
144
- self-checks (a reformatted corpus throws instead of silently changing what's measured), and a pinned
145
- tokenizer. Because everything is fixed, `npm run benchmark` gives everyone the same result.
261
+ self-checks (a reformatted corpus throws instead of silently changing what's measured), a pinned
262
+ tokenizer, and oh-my-pi payloads validated against the package's published grammar before counting.
263
+ Because everything is fixed, `npm run benchmark` gives everyone the same result — the numbers in
264
+ this README are a snapshot of that run; regenerate, don't trust.
146
265
 
147
266
  > **Scope & honesty.** The benchmark measures **request-payload tokens** — what the model emits per
148
267
  > edit call — with identical read traffic excluded (it cancels) and identical replacement text.
149
268
  > It does **not** model transcription failure and retries, which is where the real-world gap is
150
269
  > largest: the original [harness-problem](https://stencil.so/blog/the-harness-problem) post reported
151
270
  > a **61% output-token reduction** and patch-failure drops from 46–51% to near zero after switching
152
- > to anchored edits. Full methodology and limitations in
153
- > [`benchmark/README.md`](benchmark/README.md).
154
-
155
- ## Installation
156
-
157
- ```sh
158
- dsh plugin --profile <name> add dsh-better-edit # from npm
159
- dsh plugin --profile <name> add /path/to/dsh-better-edit # from a local checkout
160
- ```
161
-
162
- The profile's next session runs with the hashline tools installed. To verify the layer is active:
163
-
164
- ```sh
165
- dsh --profile <name> --dump-config # shows a "# == dsh-better-edit" layer
166
- ```
167
-
168
- | Requirement | |
169
- | --- | --- |
170
- | Node | `^22.19.0 \|\| >=24.0.0` (dsh's requirement; the store uses `node:sqlite`) |
171
- | Profile | a dsh profile (`dsh plugin` initializes one on first use) |
172
- | Backends | sandboxed / remote filesystems supported (writes go through `ctx.fs`) |
271
+ > to anchored edits. It also does **not** model what a line-numbered format costs the model *between*
272
+ > calls — renumbering and re-fetching the file tag after every edit — nor block-op power, nor the
273
+ > Bun-vs-Node runtime difference, nor the fact that `@oh-my-pi/hashline` is a standalone patcher
274
+ > while this plugin is a dsh tool pair with `read`/`edit`/`undo`. Full methodology, the per-edit
275
+ > table, and the complete limitation list in [`benchmark/README.md`](benchmark/README.md). The correctness gap behind those numbers is spelled out above in [Correctness in edge cases](#correctness-in-edge-cases).
173
276
 
174
277
  ## Tools
175
278
 
@@ -250,7 +353,7 @@ dsh-better-edit/
250
353
  │ ├── write-hook.ts # auto-read appended to write results
251
354
  │ ├── served-store.ts # per-workspace SQLite store (node:sqlite)
252
355
  │ └── workspace.ts # session-cwd AsyncLocalStorage carrier
253
- ├── benchmark/ # reproducible hashline-vs-str_replace token benchmark
356
+ ├── benchmark/ # reproducible hashline-vs-str_replace-vs-oh-my-pi token benchmark
254
357
  │ └── corpus/ # frozen 103-line fixture
255
358
  ├── test/ # 615 tests (ported + regression)
256
359
  ├── assets/ # logo + banner
@@ -268,6 +371,18 @@ npm run build # tsc → lib/
268
371
  npm run benchmark # reproducible token-cost benchmark (benchmark/)
269
372
  ```
270
373
 
374
+ ### Releasing (tag-first)
375
+
376
+ ```sh
377
+ npm run release -- 0.2.0 # bump + CHANGELOG move + commit + tag + push → GitHub release
378
+ npm publish --registry https://registry.npmjs.org # blocked until the version is tagged
379
+ ```
380
+
381
+ `npm run release` bumps `package.json`/lockfile, moves the CHANGELOG `[Unreleased]` section to the
382
+ version, commits, tags `vX.Y.Z`, and pushes — the tag push creates the GitHub release from the
383
+ changelog. `npm publish` refuses to run until that tag exists (prepublishOnly gate), so every npm
384
+ version is always already tagged and released.
385
+
271
386
  The test suite is ported from pi-hashline-edit-lsz and drives the dsh tool builders directly over a
272
387
  local filesystem bridge.
273
388
 
@@ -278,6 +393,7 @@ served-tail truncation fix, reproducible benchmark, EN + 中文 READMEs, publish
278
393
 
279
394
  <details><summary>Next</summary>
280
395
 
396
+ - **Close or justify the gap vs @oh-my-pi/hashline** (reference: [`../oh-my-pi.md`](../oh-my-pi.md)). The sibling patch language is payload-lighter — 42%/53% vs our 31% vs `str_replace` on the benchmark, because a bare patch document skips the JSON envelope we pay per call — and offers four abilities we do not support: syntactic block ops (`PUT N*:`), registers + `REM`/`MV`, one multi-hunk document per change, and a pluggable filesystem. The counterweight is correctness: its line numbers are unverified (a wrong number on a current tag lands silently), every edit renumbers, stale tags trigger best-effort 3-way merge instead of verification, and the grammar raises the model skill floor. Decide each ability reject-or-adopt on its own merits — the payload gap alone is not a reason to switch formats.
281
397
  - Verify 0.1.6 live in a dsh session after the served-tail fix.
282
398
  - Upstream the served-tail truncation fix to pi-hashline-edit-lsz / upstream (their `upsertServed`
283
399
  never truncates either).
package/README.zh.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  <p align="center">
8
8
  <strong>面向 DeepSeek Harness 的哈希锚定编辑工具。<br>
9
- 按内容地址编辑——而不是行号。更省 token。绝不会改错行。</strong>
9
+ 按内容地址编辑——不靠行号,也不靠字符串替换。更省 token。更多注意力留给真正的工作。绝不会改错行。</strong>
10
10
  </p>
11
11
 
12
12
  <p align="center">
@@ -18,7 +18,6 @@
18
18
  <a href="#快速开始">快速开始</a> •
19
19
  <a href="#为什么用-hashline">为什么用 Hashline</a> •
20
20
  <a href="#基准测试">基准测试</a> •
21
- <a href="#安装">安装</a> •
22
21
  <a href="#工具">工具</a> •
23
22
  <a href="#致谢">致谢</a>
24
23
  </p>
@@ -53,6 +52,25 @@ Hashline 用两个哈希代替旧文本——**编辑 token 减少 31%**(多
53
52
 
54
53
  ## 快速开始
55
54
 
55
+ ### 安装
56
+
57
+ ```sh
58
+ dsh plugin --profile <name> add dsh-better-edit # 从 npm
59
+ dsh plugin --profile <name> add /path/to/dsh-better-edit # 从本地源码
60
+ ```
61
+
62
+ 该 profile 的下一个会话将带着 hashline 工具运行。验证该层是否生效:
63
+
64
+ ```sh
65
+ dsh --profile <name> --dump-config # 会显示 "# == dsh-better-edit" 层
66
+ ```
67
+
68
+ | 要求 | |
69
+ | --- | --- |
70
+ | Node | `^22.19.0 \|\| >=24.0.0`(dsh 的要求;存储使用 `node:sqlite`) |
71
+ | Profile | 一个 dsh profile(首次使用 `dsh plugin` 时初始化) |
72
+ | 后端 | 支持沙箱/远程文件系统(写入经 `ctx.fs`) |
73
+
56
74
  `read` 返回的每一行都带有哈希前缀——哈希*就是*这一行的地址:
57
75
 
58
76
  ```text
@@ -80,73 +98,121 @@ kQm│}
80
98
  kQm │ }
81
99
  ```
82
100
 
101
+ ## 按 preset 配置指引
102
+
103
+ `tool:read` / `tool:edit` / `tool:batch_edit` / `tool:undo_last_edit` 四个提示词片段的指引是
104
+ 纯 Markdown 文件,可以按 agent preset 覆盖。覆盖文件位于插件的共享主目录——绝不放在工作区存储中:
105
+
106
+ ```
107
+ $DSH_HOME/plugins/dsh-better-edit/<preset>/<section>.md
108
+ ```
109
+
110
+ (默认主目录为 `~/.dsh`,即 `~/.dsh/plugins/dsh-better-edit/`)。片段对照表:
111
+
112
+ | 文件 | 提示词片段 | 默认 order |
113
+ | --- | --- | --- |
114
+ | `read.md` | `tool:read` | 130 |
115
+ | `edit.md` | `tool:edit` | 131 |
116
+ | `batch_edit.md` | `tool:batch_edit` | 132 |
117
+ | `undo_last_edit.md` | `tool:undo_last_edit` | 133 |
118
+
119
+ 首次启动时插件会为四个随附 preset——`standard/`、`code/`、`minimal/`、`cordis/`——各自写入编译内置的
120
+ 可编辑指引文件(含 `order` front-matter),让每个 preset 的指引一开始就可编辑,而不是空白。插件主目录
121
+ 根的 `README.md` 说明整套机制。文件只在首次写入时生成、之后绝不被覆盖,因此你的修改会保留。preset 目录
122
+ 里可以只放你想覆盖的片段文件,其余自动回退到编译内置默认值。
123
+
124
+ 文件默认为纯文本;除非以 `order` front-matter 栅栏开头,它会改变该片段在组装后的系统提示中的位置:
125
+
126
+ ```md
127
+ ---
128
+ order: 150
129
+ ---
130
+
131
+ <片段文本>
132
+ ```
133
+
134
+ 每个片段的解析顺序为:读取 `<preset>/<section>.md`,否则回退到编译内置默认值。文件只在 agent 的
135
+ session-start 时读取一次,因此修改只影响新会话——绝不影响进行中的会话。没有种子目录的 preset(例如
136
+ 用户自建的)会回退到编译内置默认值,除非你把某个种子目录复制成它的名字。没有 `agentPresets` 服务
137
+ (即没有 preset 名册)的部署继续使用编译内置默认值,完全不会触碰这些文件;
138
+ preset 从来不是必需的。
139
+
83
140
  ## 为什么用 Hashline
84
141
 
85
142
  **省 token。** 一次编辑调用只携带 `remove_from` / `remove_to`(两个 3 字符哈希)加替换文本——从不回显被替换的文本。`str_replace` 调用则必须逐字复现被替换的文本。在一个真实文件上的 12 次编辑会话中,这可以**减少 31% 的输出 token**(多行范围达 43%)——而且这些是*输出* token,按输入的约 5-6 倍计费。见[基准测试](#基准测试)。
86
143
 
144
+ **但这从来不是“最省 token”。** 节省随被替换文本的规模增长——单行微调时几乎持平——而且像 [@oh-my-pi/hashline](#对比) 这样的紧凑补丁语言还能发出更轻的负载(同一会话中 42–53%)。关键在于**正确形态**的编辑调用:不复述旧代码,模型除了两个稳定的内容地址外无需跟踪任何东西。
145
+
87
146
  **正确性。** 每个解析出的编辑范围都会与模型实际看到的行逐行核对。过期、从未提供或歧义的范围会在**写入任何内容之前**被硬性拒绝,并把当前范围以全新锚点的形式回显(reject-and-serve)——重试无需 `read`。
88
147
 
89
148
  **面向 Agent 的现代编辑范式。** 内容地址锚点与行号无关:编辑文件的一部分,其余行的哈希保持不变,因此连续编辑无需重新读取。模型按行**是什么**来定位,而不是按它之前在第几行。
90
149
 
91
150
  ### 对比
92
151
 
93
- | | hashline `edit` | `str_replace` | 行号编辑 |
152
+ | | hashline `edit` | `str_replace`(Claude Code / Codex) | @oh-my-pi/hashline 补丁 |
94
153
  | --- | :---: | :---: | :---: |
95
- | 调用中回显被替换文本 | ✅ 不需要——两个哈希 | ❌ 逐字回显 | ✅ 不需要 |
96
- | 对照模型所见内容校验 | ✅ 每一行 | ❌ 取第一个匹配 | ~ |
97
- | 检测文件已过期 | ✅ 拒绝并回传新锚点 | ❌ 可能匹配到错误位置 | ~ |
98
- | 上方编辑后锚点依然有效 | ✅ 内容寻址 | ✅ 基于内容 | ❌ 需要重读 |
99
- | 连续编辑无需重读 | ✅ diff 提供新锚点 | ~ | ❌ |
100
- | 文本重复时无歧义 | ✅ 边界锚点需校验 | ❌ 取第一个出现 | ~ |
101
- | 错行编辑会悄悄落盘 | ❌ 不可能 | ✅ | ✅ |
102
-
103
- > `~` = 偶尔/不稳定。行号编辑工具接受一个行范围,并在调用执行时应用到该偏移处的内容——成本低,但只要上方有任何内容移动就会失效。
154
+ | 调用中永不回显被替换文本 | ✅ 只有两个哈希 | ❌ 逐字回显 | ✅ 只有 `+` 行 |
155
+ | 按什么定位行 | 内容哈希 | 文本匹配 | 行号 + 文件内容标签 |
156
+ | 对照模型所见内容校验 | ✅ 每一行 | ❌ 取第一个匹配 | ~ 仅文件版本 |
157
+ | 检测文件已过期 | ✅ 拒绝并回传新锚点 | ❌ 可能匹配到错误位置 | ✅ 标签不匹配 → 拒绝或三方合并 |
158
+ | 上方编辑后锚点依然有效 | ✅ 内容寻址 | ✅ 基于内容 | ❌ 重新编号 + 新标签 |
159
+ | 连续编辑无需重读 | ✅ diff 提供新锚点 | ~ | ~ 从编辑响应取行号 |
160
+ | 文本重复时无歧义 | ✅ 边界锚点需校验 | ❌ 取第一个出现 | ~ 按位置,行未逐行校验 |
161
+ | 错行编辑永远不会悄悄落盘 | ✅ 每一行都校验 | ❌ 取第一个匹配 | ~ 原则上可能(标签只校验版本,不校验行) |
162
+ | 块操作 / 寄存器 / `MV` / `REM` | ❌ | ❌ | ✅ |
163
+ | 一次变更一个文档 | ❌ 每次一个调用 | ❌ 每次一个调用 | ✅ 多 hunk 补丁 |
164
+ | 运行时 | ✅ Node(dsh) | — | ⚠️ 仅 Bun |
165
+ | 撤销 | ✅ 持久化 | ❌ | ❌ 不在范围内 |
166
+
167
+ > `~` = 偶尔/不稳定。`@oh-my-pi/hashline` 是一种紧凑的行锚定补丁语言([npm](https://www.npmjs.com/package/@oh-my-pi/hashline)、[仓库](https://github.com/can1357/oh-my-pi/tree/main/packages/hashline)):`[path#tag]` 头把每个 hunk 绑定到全文件内容哈希,`PUT N.=M:` 按行号定位;每次编辑都会重新编号——下一次的行号与标签取自编辑响应或重新 `read`。
168
+
169
+ **不同的工作,同一条血脉。** 两者都源于 [harness-problem](https://stencil.so/blog/the-harness-problem) 的洞见:模型绝不该复述旧代码。`@oh-my-pi/hashline` 是**补丁语言库**——负载更轻(每次编辑省 42%,单个批量文档省 53%,见[基准测试](#基准测试)),支持语法块操作(`PUT N*:`)、寄存器、`REM`/`MV`、多 hunk 文档、可插拔文件系统(任何后端),以及标签过期时的会话感知三方合并恢复。本插件则是一对 **dsh 工具**:`read` 把 3 字符内容哈希交给模型,`edit` 取其中两个,并对解析出的每一行对照已提供状态校验——无需重新编号、无需重新取标签、错误锚点永远不可能落到错误的行,`undo_last_edit` 重启后依然有效。代价:每次编辑的 JSON 外壳会多一点负载、没有块操作,并且它活在 dsh(Node)内部,而不是独立补丁器(Bun)。要跨后端的补丁格式选 hashline 库;要在 Agent 里做可校验、内容寻址的编辑,选 hashline 工具。
170
+
171
+ ### 边界情况下的正确性
172
+
173
+ token 基准测试衡量的是模型发出的负载——它假设模型每次都能拿到**正确**的地址,而且免费。正确性才是两种 hashline 实现真正分道扬镳的地方。下面是 harness-problem 文献里的真实故障模式(错行编辑、漂移、重复文本),以及各自在遭遇它们时的表现:
174
+
175
+ | 边界情况 | hashline `edit`(本插件) | @oh-my-pi/hashline 补丁 |
176
+ | --- | --- | --- |
177
+ | 错误地址(锚点/行号差一行) | **不可能**——锚点解析到具体行;解析出的每一行都对照已提供状态校验,在**写入任何内容之前**被拒绝 | **可能**——当前标签下的错误行号会**悄悄**落到错误位置;标签只证明文件版本,从不证明行 |
178
+ | 模型查看后文件在磁盘上被改动 | 硬拒绝 + 回传新锚点(reject-and-serve);重试无需 `read` | 标签不匹配 → 拒绝**或**对未知的当前内容做尽力而为的三方合并 |
179
+ | 上方编辑导致文件移位 | 什么都不移位——锚点是内容地址;diff 提供新锚点 | **每次编辑都重新编号**——“RE-GROUND AFTER EVERY EDIT” 是它自己的头号规则;账由模型记 |
180
+ | 重复/相同文本 | 每行哈希唯一(冲突已消解);歧义 → `[E_AMBIGUOUS_ANCHOR]` | 基于位置,重复不会混淆——但位置本身未被校验 |
181
+ | 从未展示给模型的行 | `[E_RANGE_UNSERVED]`——硬拒绝并回传新锚点 | 未展示的 hunk 被拒绝——同样依赖模型知道自己看过什么 |
182
+ | 表达式中间 / 错误的块节点 | 无关——任何已校验的行范围都合法 | 语法规则 + `PUT N*:` 节点选择;点错(锚在 `def` 会让装饰器变成孤儿)会悄悄落错;无语法检查 |
183
+ | 多编辑批量中途失败 | `batch_edit`——原子、全有或全无;失败项以新锚点回显 | 多段补丁先预检——同样原子 |
184
+
185
+ > oh-my-pi 42–53% 的负载节省来自更轻的线格式;上表才是该格式反过来要求模型记在脑中的东西——重新编号、追标签、选节点——而这恰恰是最容易出错的组件(替换式编辑的补丁失败率 46–51%)。本插件 31% 的代价买来的是一个“错编辑落不了地、任何拒绝都不需要重读”的契约。
104
186
 
105
187
  ## 基准测试
106
188
 
107
- 在同一份 103 行文件上、用相同的 12 组替换(8 个单行、4 个 3/6/10/15 行多行),以固定的 `js-tiktoken` `cl100k_base` 词表测量:
189
+ 在同一份 103 行文件上、用相同的 12 组替换(8 个单行、4 个 3/6/10/15 行多行),以固定的 `js-tiktoken` `cl100k_base` 词表测量。三个被测方发出相同的替换文本:本插件的 `edit`(两个 3 字符锚点)、`str_replace` 工具(逐字回显旧文本)、以及 [`@oh-my-pi/hashline`](https://www.npmjs.com/package/@oh-my-pi/hashline) 的两种模式——每次编辑一个 `[path#tag]` 段(`seq`)和一个多 hunk 批量文档(`batch`):
108
190
 
109
- | 指标 | hashline | str_replace |
110
- | ----------- | :---: | :---: |
111
- | 被替换文本是否上线 | ✅ 从不 | ❌ 每次编辑都发 |
112
- | 输出 token 节省(12 次编辑) | ✅ **31%** | ❌ 0% |
113
- | 多行范围节省(3–15 行) | ✅ **29–47%** | ❌ 0% |
114
- | 按 5 倍输出计价的实际成本 | ✅ **低约 1.4 倍** | ❌ 1× |
115
- | 范围对照已提供状态校验 | ✅ 100% | ❌ 无 |
116
- | 确定性、可在本地复现 | ✅ `npm run benchmark` | — |
191
+ | 指标 | hashline | str_replace | oh-my-pi seq / batch |
192
+ | ----------- | :---: | :---: | :---: |
193
+ | 被替换文本是否上线 | ✅ 从不 | ❌ 每次编辑都发 | ✅ 从不 |
194
+ | 输出 token 节省(12 次编辑) | ✅ **31%** | ❌ 0% | ✅ **42% / 53%** |
195
+ | 多行范围节省(3–15 行) | ✅ **29–47%** | ❌ 0% | ✅ **40–53%** |
196
+ | 按 5 倍输出计价的实际成本 | ✅ **低约 1.4 倍** | ❌ 1× | ✅ **低约 1.7 倍 / 2.1 倍** |
197
+ | 范围对照已提供状态校验 | ✅ 100% | ❌ 无 | ~ 仅文件版本 |
198
+ | 模型需要跟踪的行号 | ✅ 无——内容锚点 | ✅ 无——文本匹配 | ❌ 每次编辑重新编号 |
199
+ | 确定性、可在本地复现 | ✅ `npm run benchmark` | — | — |
117
200
 
118
201
  ### 可复现
119
202
 
120
203
  上面的数字**是确定性的,你可以本地复现**——`npm run benchmark`:
121
204
 
122
- | 场景 | 行数 | hashline | str_replace | 节省 | % |
205
+ | 场景 | 行数 | hashline | str_replace | oh-my-pi seq | oh-my-pi batch |
123
206
  | --- | :---: | :---: | :---: | :---: | :---: |
124
- | 单行 ×8 | 1 | 309 | 324 | 15 | 5% |
125
- | 多行 ×4 | 3–15 | 393 | 691 | 298 | **43%** |
126
- | **合计 ×12** | | **702** | **1015** | **313** | **31%** |
127
-
128
- 脚本天然确定:固定语料、内容寻址且自带自检的编辑脚本(语料被重排会直接抛错,而不是悄悄改变测量对象)、固定版本的 tokenizer。因为一切都是固定的,`npm run benchmark` 对每个人都是同一个结果。
129
-
130
- > **范围与诚实。** 基准测试衡量的是**请求负载 token**——每次编辑调用时模型发出的内容——读文件流量完全相同故已排除(可抵消),替换文本也完全一致。它**没有**建模转录失败与重试,而真实差距恰恰主要在那边:最初的 [harness-problem](https://stencil.so/blog/the-harness-problem) 文章报告改用锚定编辑后**输出 token 减少 61%**,补丁失败率从 46–51% 降至接近零。完整的方法论与局限见 [`benchmark/README.md`](benchmark/README.md)。
131
-
132
- ## 安装
133
-
134
- ```sh
135
- dsh plugin --profile <name> add dsh-better-edit # 从 npm
136
- dsh plugin --profile <name> add /path/to/dsh-better-edit # 从本地源码
137
- ```
207
+ | 单行 ×8 | 1 | 309 | 324 | 241 | — |
208
+ | 多行 ×4 | 3–15 | 393 | 691 | 349 | — |
209
+ | **合计 ×12** | | **702** | **1015** | **590** | **480** |
138
210
 
139
- 该 profile 的下一个会话将带着 hashline 工具运行。验证该层是否生效:
211
+ 相对 `str_replace` 的节省:hashline **313(31%)** · oh-my-pi 逐次 **425(42%)** · oh-my-pi 批量 **535(53%)**。
140
212
 
141
- ```sh
142
- dsh --profile <name> --dump-config # 会显示 "# == dsh-better-edit" 层
143
- ```
213
+ 脚本天然确定:固定语料、内容寻址且自带自检的编辑脚本(语料被重排会直接抛错,而不是悄悄改变测量对象)、固定版本的 tokenizer,且 oh-my-pi 负载在计数前会对照其发布的语法校验。因为一切都是固定的,`npm run benchmark` 对每个人都是同一个结果——本 README 里的数字就是该次运行的一个快照;重新生成,不要轻信。
144
214
 
145
- | 要求 | |
146
- | --- | --- |
147
- | Node | `^22.19.0 \|\| >=24.0.0`(dsh 的要求;存储使用 `node:sqlite`) |
148
- | Profile | 一个 dsh profile(首次使用 `dsh plugin` 时初始化) |
149
- | 后端 | 支持沙箱/远程文件系统(写入经 `ctx.fs`) |
215
+ > **范围与诚实。** 基准测试衡量的是**请求负载 token**——每次编辑调用时模型发出的内容——读文件流量完全相同故已排除(可抵消),替换文本也完全一致。它**没有**建模转录失败与重试,而真实差距恰恰主要在那边:最初的 [harness-problem](https://stencil.so/blog/the-harness-problem) 文章报告改用锚定编辑后**输出 token 减少 61%**,补丁失败率从 46–51% 降至接近零。它同样**没有**建模行号格式在调用**之间**让模型付出的代价——每次编辑后重新编号、重新获取文件标签——也不包括块操作能力、Bun 与 Node 的运行时差异,以及 `@oh-my-pi/hashline` 是独立补丁器、而本插件是带 `read`/`edit`/`undo` 的 dsh 工具对这一事实。完整方法论、逐编辑表与完整局限清单见 [`benchmark/README.md`](benchmark/README.md)。这些数字背后的正确性差距见上文[边界情况下的正确性](#边界情况下的正确性)。
150
216
 
151
217
  ## 工具
152
218
 
@@ -216,7 +282,7 @@ dsh-better-edit/
216
282
  │ ├── write-hook.ts # 附加到 write 结果的自动读取
217
283
  │ ├── served-store.ts # 按工作区的 SQLite 存储(node:sqlite)
218
284
  │ └── workspace.ts # 会话 cwd 的 AsyncLocalStorage 载体
219
- ├── benchmark/ # 可复现的 hashline 与 str_replace token 基准测试
285
+ ├── benchmark/ # 可复现的 hashline、str_replace 与 oh-my-pi token 基准测试
220
286
  │ └── corpus/ # 固定的 103 行语料
221
287
  ├── test/ # 615 个测试(移植 + 回归)
222
288
  ├── assets/ # logo 与 banner
@@ -234,6 +300,15 @@ npm run build # tsc → lib/
234
300
  npm run benchmark # 可复现的 token 成本基准测试(benchmark/)
235
301
  ```
236
302
 
303
+ ### 发布流程(先打 tag)
304
+
305
+ ```sh
306
+ npm run release -- 0.2.0 # 升版本 + 迁移 CHANGELOG + 提交 + 打 tag + 推送 → 生成 GitHub release
307
+ npm publish --registry https://registry.npmjs.org # 版本未打 tag 前会被阻止
308
+ ```
309
+
310
+ `npm run release` 会更新 `package.json`/lockfile、把 CHANGELOG 的 `[Unreleased]` 段落迁移到版本号下、提交、打 `vX.Y.Z` tag 并推送——tag 推送会基于 changelog 自动创建 GitHub release。`npm publish` 在该 tag 存在之前会拒绝运行(prepublishOnly 门禁),因此每个 npm 版本都一定已经打好 tag 并发布过 release。
311
+
237
312
  测试套件移植自 pi-hashline-edit-lsz,通过本地文件系统桥接直接驱动 dsh 工具构建器。
238
313
 
239
314
  ## 路线图
@@ -242,6 +317,7 @@ npm run benchmark # 可复现的 token 成本基准测试(benchmark/)
242
317
 
243
318
  <details><summary>下一步</summary>
244
319
 
320
+ - **缩小或证明与 @oh-my-pi/hashline 的差距**(参考:[`../oh-my-pi.md`](../oh-my-pi.md))。这个兄弟补丁语言负载更轻——基准测试中相对 `str_replace` 省 42%/53%,而我们省 31%,因为它裸文本式的补丁文档跳过了我们每次调用都要付的 JSON 外壳——还提供了我们不支持的四种能力:语法块操作(`PUT N*:`)、寄存器 + `REM`/`MV`、一次变更一个多 hunk 文档、可插拔文件系统。代价在正确性一侧:它的行号未经验证(当前标签下的错行号会静默落盘)、每次编辑都要重新编号、过期标签触发尽力而为的三方合并而非校验、语法也抬高了模型的技能门槛。逐项决定是拒绝还是采纳——负载差距本身不足以成为切换格式的理由。
245
321
  - 在 dsh 会话中实测 0.1.7(served-tail 修复之后)。
246
322
  - 把 served-tail 截断修复回馈给 pi-hashline-edit-lsz / 上游(他们的 `upsertServed` 同样从不截断)。
247
323
  - 对照下一个 dsh 版本重新核对插件接线(当前固定在 `0.1.0-rc.6`;dsh 处于开发者预览阶段,承诺会有破坏性变更)。