dsh-better-edit 1.2.3 → 1.2.5
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 +33 -0
- package/README.md +39 -20
- package/README.zh.md +39 -31
- package/lib/contract.js +53 -22
- package/lib/domain-errors.js +18 -10
- package/lib/edit-mode.js +11 -0
- package/lib/encoding.js +2 -0
- package/lib/file-encoding-state.js +138 -44
- package/lib/file-view.js +26 -205
- package/lib/fs-bridge.js +53 -71
- package/lib/hashline/anchor-pipeline.js +8 -499
- package/lib/hashline/hash-assign.js +55 -4
- package/lib/hashline/index.js +5 -2
- package/lib/hashline/served-evidence.js +531 -0
- package/lib/index.js +177 -33
- package/lib/mutation/engine.js +19 -61
- package/lib/mutation.js +63 -105
- package/lib/noop-guard.js +24 -38
- package/lib/paths.js +9 -5
- package/lib/preset-toolset.js +144 -0
- package/lib/prompts.js +3 -3
- package/lib/read-and-serve.js +51 -53
- package/lib/reclaim.js +65 -0
- package/lib/self-heal.js +14 -13
- package/lib/session-view.js +79 -49
- package/lib/store/index.js +14 -14
- package/lib/store-config.js +4 -5
- package/lib/store-lifecycle.js +1 -1
- package/lib/tool-edit.js +14 -56
- package/lib/tool-read.js +2 -8
- package/lib/tool-str-replace-editor.js +34 -18
- package/lib/tool-undo.js +42 -24
- package/lib/types/contract.d.ts +11 -20
- package/lib/types/domain-errors.d.ts +14 -10
- package/lib/types/edit-mode.d.ts +11 -0
- package/lib/types/encoding.d.ts +1 -0
- package/lib/types/file-encoding-state.d.ts +51 -14
- package/lib/types/file-view.d.ts +18 -56
- package/lib/types/fs-bridge.d.ts +0 -1
- package/lib/types/hashline/anchor-pipeline.d.ts +6 -128
- package/lib/types/hashline/hash-assign.d.ts +40 -0
- package/lib/types/hashline/index.d.ts +6 -4
- package/lib/types/hashline/served-evidence.d.ts +152 -0
- package/lib/types/mutation/engine.d.ts +4 -12
- package/lib/types/mutation.d.ts +10 -58
- package/lib/types/noop-guard.d.ts +2 -33
- package/lib/types/paths.d.ts +0 -1
- package/lib/types/preset-toolset.d.ts +61 -0
- package/lib/types/reclaim.d.ts +36 -0
- package/lib/types/self-heal.d.ts +9 -3
- package/lib/types/session-view.d.ts +38 -8
- package/lib/types/store/index.d.ts +12 -11
- package/lib/types/store-config.d.ts +1 -1
- package/lib/types/store-lifecycle.d.ts +12 -2
- package/lib/types/tool-edit.d.ts +2 -4
- package/lib/types/tool-read.d.ts +0 -5
- package/lib/types/tool-str-replace-editor.d.ts +0 -6
- package/lib/types/tool-undo.d.ts +0 -5
- package/package.json +3 -2
- package/lib/drift.js +0 -5
- package/lib/dsh-context.js +0 -5
- package/lib/edit-engine.js +0 -7
- package/lib/edit-normalize.js +0 -9
- package/lib/edit-pipeline.js +0 -6
- package/lib/file-kind.js +0 -6
- package/lib/file-reader.js +0 -6
- package/lib/guidance/index.js +0 -8
- package/lib/hashline/alphabet.js +0 -2
- package/lib/hashline/apply.js +0 -2
- package/lib/hashline/hasher.js +0 -2
- package/lib/hashline/parse.js +0 -2
- package/lib/hashline/pure.js +0 -2
- package/lib/hashline/resolve.js +0 -3
- package/lib/hashline/served.js +0 -2
- package/lib/preview-controller.js +0 -65
- package/lib/read-render.js +0 -6
- package/lib/schema.js +0 -24
- package/lib/served-store.js +0 -5
- package/lib/tool-batch-edit.js +0 -190
- package/lib/truncate.js +0 -6
- package/lib/types/drift.d.ts +0 -5
- package/lib/types/dsh-context.d.ts +0 -5
- package/lib/types/edit-engine.d.ts +0 -7
- package/lib/types/edit-normalize.d.ts +0 -1
- package/lib/types/edit-pipeline.d.ts +0 -6
- package/lib/types/file-kind.d.ts +0 -6
- package/lib/types/file-reader.d.ts +0 -6
- package/lib/types/guidance/index.d.ts +0 -8
- package/lib/types/hashline/alphabet.d.ts +0 -1
- package/lib/types/hashline/apply.d.ts +0 -1
- package/lib/types/hashline/hasher.d.ts +0 -1
- package/lib/types/hashline/parse.d.ts +0 -1
- package/lib/types/hashline/pure.d.ts +0 -1
- package/lib/types/hashline/resolve.d.ts +0 -1
- package/lib/types/hashline/served.d.ts +0 -1
- package/lib/types/preview-controller.d.ts +0 -33
- package/lib/types/read-render.d.ts +0 -6
- package/lib/types/schema.d.ts +0 -25
- package/lib/types/served-store.d.ts +0 -5
- package/lib/types/tool-batch-edit.d.ts +0 -25
- package/lib/types/truncate.d.ts +0 -6
- package/lib/types/validation.d.ts +0 -6
- package/lib/types/workspace.d.ts +0 -5
- package/lib/validation.js +0 -6
- package/lib/workspace.js +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -11,6 +11,39 @@ All notable changes to this project will be documented in this file.
|
|
|
11
11
|
|
|
12
12
|
## [Unreleased]
|
|
13
13
|
|
|
14
|
+
## [1.2.5] - 2026-11-18
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* **noop-guard:** scope the noop-loop counter per `(session, file)` so one session's repeated no-op can no longer reject another session's first submission of the same edit, and delete the dead `runNoopPolicy`/`runNoopPolicySync` copy of the live decision (ADR-0039). (#133)
|
|
19
|
+
* **encoding:** give each file one memo identity — the encoding and auto-guess footer memos are keyed by the slash-normalized absolute path, so the dual-key writes and their three-spelling probe ladders are gone (ADR-0038). (#133)
|
|
20
|
+
* **install:** claim tools synchronously in `agent/created` turn, isolate per-step failures, and reclaim contested entries on collision (#123) (#131)
|
|
21
|
+
* **mutation:** restore the undo row of every file a failed write never wrote, so a multi-item edit's failure no longer leaves `undo_last_edit` reporting `E_UNDO_STALE "modified"` for the tool's own failed write (ADR-0034). (#133)
|
|
22
|
+
* **read:** stop a paged read that happens to cover every line from clearing retired anchors, hazard cards and the served canon map — the full-read verdict is FileView's alone, and the lease grant stays unconditional because a shown anchor must remain editable (ADR-0035). (#133)
|
|
23
|
+
* **retired-anchors:** append a retirement as an object entry instead of rewriting the column into bare strings, so an existing retired anchor keeps its death position and the incremental hazard sweep can free it again rather than accumulating until a full read (ADR-0036). (#133)
|
|
24
|
+
|
|
25
|
+
### Code Refactoring
|
|
26
|
+
|
|
27
|
+
* **hashline:** retire the six `hashline` shims (`alphabet`, `apply`, `hasher`, `parse`, `pure`, `resolve`) with every test importer re-pointed at the owning module and the `parse` barrel edge moved to `anchor-pipeline`; the now-dead `noRestrictedImports` guard and its two disablers go, and the test-only `resolveDisplayPath`/`snapshotIdFor` mutation exports are deleted (ADR-0033 amendment). (#133)
|
|
28
|
+
* **dead-code:** retire the duplicate-name shims and the dead FileView sub-graph — `edit-engine`, `preview-controller`, the five `file-view` re-export shims, and the `mutation.ts` deprecated re-export block go, and `SUPPORTED_ENCODINGS` becomes the one encoding roster (ADR-0033). (#133)
|
|
29
|
+
* **dead-code:** retire the four `register*Tool` bypasses, the stray `tests/` tree (unique cases ported into `test/`), the duplicate guidance barrel and the `paths.ts → store/index.ts` barrel edge; `pnpm run build` now cleans `lib/` first, so a stale module cannot ride the output. (#133)
|
|
30
|
+
* **hashline:** extract the served-evidence verdict into `served-evidence.ts` — one entry point (`verifyServedRange`), one row renderer behind `fmtServedRows`/`fmtRegion`, one `[... N more — …]` frame — and cut both import cycles the mixed seam held: `store-lifecycle` types its store face structurally and `EditMode` moves to a leaf, leaving only `file-view ↔ fs-bridge` (ADR-0037). (#133)
|
|
31
|
+
* **hashline:** split the anchor-space-exhaustion test into two named predicates in the error's own module — `isAnchorSpaceExhaustion` types the failure, `isPromotableAnchorSpaceExhaustion` decides whether clearing retired anchors could cure it — so the uncurable line-cap refusal rethrows before the read path touches hazard state; the windowed `served` record stops de-masking duplicate positions, the private `hashline/served` shim retires, and the stale `anchor-pipeline` prose cites re-point at `served-evidence`. (#133)
|
|
32
|
+
|
|
33
|
+
## [1.2.4] - 2026-11-17
|
|
34
|
+
|
|
35
|
+
### Tests
|
|
36
|
+
|
|
37
|
+
* **edit:** pin the applied-vs-rejection notice tier (#115) (#121)
|
|
38
|
+
|
|
39
|
+
### Bug Fixes
|
|
40
|
+
|
|
41
|
+
* **edit:** reject an unnamed file at admission instead of guessing it from anchors (#117) (#120)
|
|
42
|
+
* **domain-errors:** route `W_NOOP` to `MODEL` so the second identical no-op carries "Resend will reject" to the model that would resend, not a human-only `[USER]` notice — warnings are now guarded by an audience oracle that refuses model-directed text on a `USER` warning (ADR-0014 amendment) (#122)
|
|
43
|
+
* **install:** gate the hashline tools on the composed preset's own tool policy — `read` stays unconditional, while `edit`, `str_replace_editor`, `undo_last_edit` and the write hook follow the preset's layer, and self-heal heals exactly the installed set; ADR-0032 records the async scope seam and the fail-open fallback (#110) (#125)
|
|
44
|
+
* **edit-undo:** restore the pre-edit anchor strings on undo — the restore reuses the pre-edit assignment, revives it, and retires the superseded post-edit anchors in the same store unit, reversing ADR-0017's named deviation (#111) (#126)
|
|
45
|
+
* **encoding:** consume the encoding recorded by `read({ encoding })` in every mutating read, and refuse a write the text seam cannot reproduce byte-faithfully with the typed `E_ENCODING_UNWRITABLE` instead of transcoding silently; ADR-0012 amended (#112) (#127)
|
|
46
|
+
|
|
14
47
|
## [1.2.3] - 2026-11-16
|
|
15
48
|
|
|
16
49
|
### Bug Fixes
|
package/README.md
CHANGED
|
@@ -210,31 +210,50 @@ Single stochastic run, `opencode-go/gpt-5.6-luna` high. [Artifact](https://githu
|
|
|
210
210
|
|
|
211
211
|
## Tools
|
|
212
212
|
|
|
213
|
-
| Tool | What it does
|
|
214
|
-
| ---------------- |
|
|
215
|
-
| `read` | `HASH│content` with `offset`/`limit`; `[Showing N-M of T]` paging; `>200KB` lines show marker
|
|
216
|
-
| `read_skill` | Plain text, no hashes, no serves — editing after it needs a serve
|
|
217
|
-
| `edit` | `{
|
|
218
|
-
| `undo_last_edit` | `{path}` restores last edit (BOM/line endings/anchors), persisted
|
|
213
|
+
| Tool | What it does |
|
|
214
|
+
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
|
|
215
|
+
| `read` | `HASH│content` with `offset`/`limit`; `[Showing N-M of T]` paging; `>200KB` lines show marker |
|
|
216
|
+
| `read_skill` | Plain text, no hashes, no serves — editing after it needs a serve |
|
|
217
|
+
| `edit` | `{file, edits:[[from,to,text]]}` (named objects too; `path`/`file_path` aliases fold), `""` deletes, atomic ≤32, verify-then-write |
|
|
218
|
+
| `undo_last_edit` | `{path}` restores last edit (BOM/line endings/anchors), persisted |
|
|
219
219
|
|
|
220
220
|
`write` stays, but refuses an exact `HASH│` echo for same `session/path/line` before dispatch.
|
|
221
221
|
|
|
222
222
|
### Error codes
|
|
223
223
|
|
|
224
|
-
| Code
|
|
225
|
-
|
|
|
226
|
-
| `[E_BAD_PAYLOAD]`
|
|
227
|
-
| `[
|
|
228
|
-
| `[
|
|
229
|
-
| `[
|
|
230
|
-
| `[
|
|
231
|
-
| `[
|
|
232
|
-
| `[
|
|
233
|
-
| `[
|
|
234
|
-
| `[
|
|
235
|
-
| `[
|
|
236
|
-
|
|
237
|
-
|
|
224
|
+
| Code | Meaning | What to do |
|
|
225
|
+
| ------------------------- | ---------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
|
|
226
|
+
| `[E_BAD_PAYLOAD]` | Request shape is wrong (unknown field, missing `file`, bad tuple) | Fix the shape and resend |
|
|
227
|
+
| `[E_MALFORMED_ANCHOR]` | The anchor token is not a bare 3-char anchor (pasted block or pseudo-anchor) | Pass the bare anchor and retry |
|
|
228
|
+
| `[E_UNKNOWN_ANCHOR]` | The anchor was never served for this file | `read` the file for fresh anchors |
|
|
229
|
+
| `[E_FOREIGN_ANCHOR]` | The anchor belongs to another file or session | Use anchors served for this file |
|
|
230
|
+
| `[E_STALE_ANCHOR]` | The anchor no longer resolves (hash / retired / canon miss) | `read` for fresh anchors |
|
|
231
|
+
| `[E_AMBIGUOUS_MATCH]` | `str_replace` `old_str` matches more than once | Narrow `old_str` |
|
|
232
|
+
| `[E_NO_MATCH]` | `str_replace` `old_str` is absent | Re-`view` and retry |
|
|
233
|
+
| `[E_EMPTY_RANGE]` | The edit would empty a non-empty file | Use `write` |
|
|
234
|
+
| `[E_STALE_RANGE]` | The served range changed on disk | Apply the echoed fresh rows |
|
|
235
|
+
| `[E_UNSERVED_RANGE]` | The range contains lines that were never served | `read` that range |
|
|
236
|
+
| `[E_UNVERIFIED_RANGE]` | A boundary anchor could not be verified against served state | `read` and retry |
|
|
237
|
+
| `[E_SUSPICIOUS_TEXT]` | Replacement text carries copied `HASH│` or diff-preview markers | Remove them and resend |
|
|
238
|
+
| `[E_BLIND_REPLACE]` | `write` / `str_replace_editor` ran before the file was observed | `read` / `view` first |
|
|
239
|
+
| `[E_TARGET_LOST]` | The target vanished or changed identity mid-operation | `read` and re-target |
|
|
240
|
+
| `[E_BATCH_ABORT]` | One item failed; nothing was written | Fix the item and resend the batch |
|
|
241
|
+
| `[E_NOOP_LOOP]` | The same no-op edit was resubmitted | Change the edit |
|
|
242
|
+
| `[E_ACCESS]` | The path is not readable or writable | Fix the permission |
|
|
243
|
+
| `[E_NOT_FOUND]` | No such file | Check the parent directory |
|
|
244
|
+
| `[E_FILE_EXISTS]` | A `create` target already exists | Choose a new path |
|
|
245
|
+
| `[E_UNSUPPORTED_FILE]` | Directory, binary, or non-text file | Choose a text file |
|
|
246
|
+
| `[E_ENCODING_UNWRITABLE]` | The recorded encoding cannot be reproduced by a UTF-8 text write | Set `normalizeToUtf8: true` to migrate, or edit the file outside the plugin |
|
|
247
|
+
| `[E_UNSUPPORTED]` | `str_replace_editor undo_edit` is not implemented | Use `undo_last_edit` |
|
|
248
|
+
| `[E_BAD_COMMAND]` | Unknown `str_replace_editor` command | Use `view`, `str_replace`, `insert`, or `create` |
|
|
249
|
+
| `[E_LARGE_FILE]` | Above the line or anchor-space limit | Use `write` or split the file |
|
|
250
|
+
| `[E_UNDO_STALE]` | The file changed after the edit | No undo; re-read |
|
|
251
|
+
| `[E_UNDO_UNAVAILABLE]` | Undo history could not be persisted | Retry the edit |
|
|
252
|
+
| `[E_UNDO_NOT_RECORDED]` | The revert landed but the store could not record it | Re-read; the next undo clears the stale history |
|
|
253
|
+
| `[E_STORE_NEWER_VERSION]` | The store was written by a newer plugin version | Upgrade the plugin, or point the store elsewhere |
|
|
254
|
+
| `[E_UNKNOWN]` | Unexpected internal error | Report it; the message is preserved |
|
|
255
|
+
|
|
256
|
+
`ERROR_REGISTRY` in `src/domain-errors.ts` is the source of truth for this table; `test/arch/error-table-vocabulary.test.ts` fails when the two disagree.
|
|
238
257
|
|
|
239
258
|
## Comparison
|
|
240
259
|
|
package/README.zh.md
CHANGED
|
@@ -58,7 +58,7 @@ Hashline 用两个哈希代替旧文本——**编辑 token 减少 31%**(多
|
|
|
58
58
|
> - **自愈而非静默。** 外部编辑永不被覆盖——过期范围被拒绝并以全新 `HASH│content` 重发重试;孤儿 served 条目无需全量重读即可自愈(ADR-0008)。Fail-closed,而非自动合并。
|
|
59
59
|
> - **格式化容忍。** ASCII 空白不敏感锚点在 `prettier`/`black`/`eslint --fix` 之间存活(`formatOnSave`、监听、CI)。仅限 linter 场景——字符串内的空白不区分(ADR-0005)。
|
|
60
60
|
> - **链式与批量,无重读仪式。** 未受影响行的锚点保持有效;diff/回显/拒绝行即视为已提供。`edit` 最多 32 个同文件编辑原子执行(`[E_BATCH_ABORT]`),相比 `str_replace` 信封约 -40%。
|
|
61
|
-
> - **读守卫。** 从未展示过的行永不被编辑——`[
|
|
61
|
+
> - **读守卫。** 从未展示过的行永不被编辑——`[E_UNSERVED_RANGE]`/`[E_UNVERIFIED_RANGE]`/`[E_STALE_ANCHOR]` 在写入前拒绝,随后 `reject-and-serve`。
|
|
62
62
|
> - **更少往返。** 实测:同样外部漂移重构,OMP 封装需 6 次调用,hashline 仅 3 次;信封 vs `str_replace` 的节省是稳定值—— upstream 电池可复现(算法相同)。
|
|
63
63
|
|
|
64
64
|
不适用于单行小改动(接近持平)或新建文件(用 `write`)。它的价值在长会话与结构性编辑中体现——任何不允许改错行的场景。
|
|
@@ -225,8 +225,8 @@ token 基准测试衡量的是模型发出的负载——它假设模型每次
|
|
|
225
225
|
| 错误地址(锚点/行号差一行) | **不可能**——锚点解析到具体行;解析出的每一行都对照已提供状态校验,在**写入任何内容之前**被拒绝 | **可能**——当前标签下的错误行号会**悄悄**落到错误位置;标签只证明文件版本,从不证明行 |
|
|
226
226
|
| 模型查看后文件在磁盘上被改动 | 硬拒绝 + 回传新锚点(reject-and-serve);重试无需 `read` | 标签不匹配 → 拒绝**或**对未知的当前内容做尽力而为的三方合并 |
|
|
227
227
|
| 上方编辑导致文件移位 | 什么都不移位——锚点是内容地址;diff 提供新锚点 | **每次编辑都重新编号**——“RE-GROUND AFTER EVERY EDIT” 是它自己的头号规则;账由模型记 |
|
|
228
|
-
| 重复/相同文本 | 每行哈希唯一(冲突已消解);歧义 → `[
|
|
229
|
-
| 从未展示给模型的行 | `[
|
|
228
|
+
| 重复/相同文本 | 每行哈希唯一(冲突已消解);歧义 → `[E_STALE_ANCHOR]` | 基于位置,重复不会混淆——但位置本身未被校验 |
|
|
229
|
+
| 从未展示给模型的行 | `[E_UNSERVED_RANGE]`——硬拒绝并回传新锚点 | 未展示的 hunk 被拒绝——同样依赖模型知道自己看过什么 |
|
|
230
230
|
| 表达式中间 / 错误的块节点 | 无关——任何已校验的行范围都合法 | 语法规则 + `PUT N*:` 节点选择;点错(锚在 `def` 会让装饰器变成孤儿)会悄悄落错;无语法检查 |
|
|
231
231
|
| 多编辑批量中途失败 | `edit` 多条目——原子、全有或全无;失败项以新锚点回显 | 多段补丁先预检——同样原子 |
|
|
232
232
|
|
|
@@ -264,39 +264,47 @@ token 基准测试衡量的是模型发出的负载——它假设模型每次
|
|
|
264
264
|
|
|
265
265
|
## 工具
|
|
266
266
|
|
|
267
|
-
| 工具 | 作用
|
|
268
|
-
| ---------------- |
|
|
269
|
-
| `read` | 以 `HASH│内容` 形式返回文件。参数:`offset`(1 起始)、`limit`。分页输出以 `[Showing lines N-M of T. Use offset=… to continue.]` 结尾。超过 200KB 的行显示为标记并附 `sed` 提示——哈希锚点需要完整行。
|
|
270
|
-
| `edit` |
|
|
271
|
-
| `undo_last_edit` | `{ path }` 撤销该文件上一次 hashline 编辑,仅当文件仍与存储的编辑后内容一致时生效;重启后依然有效。
|
|
267
|
+
| 工具 | 作用 |
|
|
268
|
+
| ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
269
|
+
| `read` | 以 `HASH│内容` 形式返回文件。参数:`offset`(1 起始)、`limit`。分页输出以 `[Showing lines N-M of T. Use offset=… to continue.]` 结尾。超过 200KB 的行显示为标记并附 `sed` 提示——哈希锚点需要完整行。 |
|
|
270
|
+
| `edit` | `{file, edits:[[from,to,text]]}`(也接受命名对象;`path`/`file_path` 别名会被折叠),`""` 删除,原子 ≤32,先校验后写入。单条目编辑一个范围;多条目对同一文件原子批量(最多 32)。对每个包含范围内的每一行校验,reject-and-serve 返回新锚点。 |
|
|
271
|
+
| `undo_last_edit` | `{ path }` 撤销该文件上一次 hashline 编辑,仅当文件仍与存储的编辑后内容一致时生效;重启后依然有效。 |
|
|
272
272
|
|
|
273
273
|
内置 `write` 仍用于整文件替换。执行前,插件只会在候选行以同一会话、规范路径及行位置所提供的精确 `HASH│` 锚点开头时拒绝;文件保持不变,并提示仅用文件正文重试。插件不会泛化地剥离类似哈希的文本。
|
|
274
274
|
|
|
275
275
|
### 错误码
|
|
276
276
|
|
|
277
|
-
| 代码
|
|
278
|
-
|
|
|
279
|
-
| `[
|
|
280
|
-
| `[
|
|
281
|
-
| `[
|
|
282
|
-
| `[
|
|
283
|
-
| `[
|
|
284
|
-
| `[
|
|
285
|
-
| `[
|
|
286
|
-
| `[
|
|
287
|
-
| `[
|
|
288
|
-
| `[
|
|
289
|
-
| `[
|
|
290
|
-
| `[
|
|
291
|
-
| `[
|
|
292
|
-
| `[
|
|
293
|
-
| `[
|
|
294
|
-
| `[
|
|
295
|
-
| `[
|
|
296
|
-
| `[
|
|
297
|
-
| `[
|
|
298
|
-
| `[
|
|
299
|
-
| `[
|
|
277
|
+
| 代码 | 含义 | 处理方式 |
|
|
278
|
+
| ------------------------- | --------------------------------------------------- | ------------------------------------------------ |
|
|
279
|
+
| `[E_BAD_PAYLOAD]` | 请求形态错误(未知字段、缺少 `file`、元组位置错误) | 修正形态后重发 |
|
|
280
|
+
| `[E_MALFORMED_ANCHOR]` | 锚点不是裸 3 字符锚点(粘贴的块或伪锚点) | 传裸锚点后重试 |
|
|
281
|
+
| `[E_UNKNOWN_ANCHOR]` | 该锚点从未为本文件提供过 | `read` 获取新锚点 |
|
|
282
|
+
| `[E_FOREIGN_ANCHOR]` | 该锚点属于其他文件或会话 | 使用本文件提供的锚点 |
|
|
283
|
+
| `[E_STALE_ANCHOR]` | 锚点已无法解析(哈希/已退役/规范化失配) | `read` 获取新锚点 |
|
|
284
|
+
| `[E_AMBIGUOUS_MATCH]` | `str_replace` 的 `old_str` 命中多处 | 扩大 `old_str` 上下文 |
|
|
285
|
+
| `[E_NO_MATCH]` | `str_replace` 的 `old_str` 不存在 | 重新 `view` 后重试 |
|
|
286
|
+
| `[E_EMPTY_RANGE]` | 编辑会清空非空文件 | 改用 `write` |
|
|
287
|
+
| `[E_STALE_RANGE]` | 已提供的范围在磁盘上发生变化 | 使用回显的新行 |
|
|
288
|
+
| `[E_UNSERVED_RANGE]` | 范围内包含从未提供的行 | `read` 该范围 |
|
|
289
|
+
| `[E_UNVERIFIED_RANGE]` | 边界锚点无法对照已提供状态校验 | `read` 后重试 |
|
|
290
|
+
| `[E_SUSPICIOUS_TEXT]` | 替换文本含复制的 `HASH│` 或 diff 预览标记 | 移除后重发 |
|
|
291
|
+
| `[E_BLIND_REPLACE]` | `write` / `str_replace_editor` 在观察文件前执行 | 先 `read` / `view` |
|
|
292
|
+
| `[E_TARGET_LOST]` | 目标在操作中途消失或身份改变 | `read` 后重新定位 |
|
|
293
|
+
| `[E_BATCH_ABORT]` | 批次中某项失败,未写入任何内容 | 修正该项后重发批次 |
|
|
294
|
+
| `[E_NOOP_LOOP]` | 同一空操作编辑被反复提交 | 修改编辑内容 |
|
|
295
|
+
| `[E_ACCESS]` | 路径不可读或不可写 | 修正权限 |
|
|
296
|
+
| `[E_NOT_FOUND]` | 文件不存在 | 检查父目录 |
|
|
297
|
+
| `[E_FILE_EXISTS]` | `create` 目标已存在 | 换一个路径 |
|
|
298
|
+
| `[E_UNSUPPORTED_FILE]` | 目录、二进制或非文本文件 | 选择文本文件 |
|
|
299
|
+
| `[E_ENCODING_UNWRITABLE]` | 记录的编码无法由 UTF-8 文本写入复现 | 设 `normalizeToUtf8: true` 迁移,或在插件外编辑 |
|
|
300
|
+
| `[E_UNSUPPORTED]` | `str_replace_editor undo_edit` 未实现 | 改用 `undo_last_edit` |
|
|
301
|
+
| `[E_BAD_COMMAND]` | 未知的 `str_replace_editor` 命令 | 使用 `view`、`str_replace`、`insert` 或 `create` |
|
|
302
|
+
| `[E_LARGE_FILE]` | 超过行数或锚点空间上限 | 改用 `write` 或拆分文件 |
|
|
303
|
+
| `[E_UNDO_STALE]` | 编辑之后文件被修改 | 无法撤销;重新读取 |
|
|
304
|
+
| `[E_UNDO_UNAVAILABLE]` | 撤销历史无法持久化 | 重试编辑 |
|
|
305
|
+
| `[E_UNDO_NOT_RECORDED]` | 回滚已落盘但存储未能记录 | 重新读取;下次撤销会清掉旧历史 |
|
|
306
|
+
| `[E_STORE_NEWER_VERSION]` | 存储由更新版本的插件写入 | 升级插件,或改用其他存储目录 |
|
|
307
|
+
| `[E_UNKNOWN]` | 未预期的内部错误 | 上报;消息原文保留 |
|
|
300
308
|
|
|
301
309
|
## 如何替换内置工具
|
|
302
310
|
|
package/lib/contract.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* declared once here; every tool validates through these asserts, and the
|
|
5
5
|
* E_BAD_PAYLOAD vocabulary is shared instead of re-implemented per tool.
|
|
6
6
|
*
|
|
7
|
-
* Contract mirrors upstream ADR-0015: {file: string
|
|
7
|
+
* Contract mirrors upstream ADR-0015: {file: string, edits: [{anchor_from, anchor_to, replace_with},...]} named-object payload
|
|
8
8
|
* (plus legacy tuple items and legacy key spellings folded pre-validation), single-file, atomic. batch_edit is removed.
|
|
9
9
|
* @module dsh-better-edit/contract
|
|
10
10
|
*/
|
|
@@ -70,8 +70,8 @@ export function editRequestFrom(input) {
|
|
|
70
70
|
return undefined;
|
|
71
71
|
}
|
|
72
72
|
const { file, file_path, path, edits, mode } = rec;
|
|
73
|
-
// file preferred; legacy path/file_path fold (sanitized).
|
|
74
|
-
// the
|
|
73
|
+
// file preferred; legacy path/file_path fold (sanitized). #117: a null or
|
|
74
|
+
// absent file is an admission error — the anchor-inference seam is retired.
|
|
75
75
|
let effectiveFile;
|
|
76
76
|
if (file !== undefined)
|
|
77
77
|
effectiveFile = file;
|
|
@@ -81,19 +81,11 @@ export function editRequestFrom(input) {
|
|
|
81
81
|
effectiveFile = file_path;
|
|
82
82
|
else
|
|
83
83
|
return undefined;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return undefined;
|
|
89
|
-
effectivePath = sanitized;
|
|
90
|
-
}
|
|
91
|
-
else if (effectiveFile === null) {
|
|
92
|
-
effectivePath = null;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
84
|
+
if (typeof effectiveFile !== "string")
|
|
85
|
+
return undefined;
|
|
86
|
+
const effectivePath = sanitizePath(effectiveFile);
|
|
87
|
+
if (effectivePath === null)
|
|
95
88
|
return undefined;
|
|
96
|
-
}
|
|
97
89
|
if (!Array.isArray(edits) || edits.length === 0)
|
|
98
90
|
return undefined;
|
|
99
91
|
const items = [];
|
|
@@ -218,7 +210,47 @@ export function prepareEditArguments(args) {
|
|
|
218
210
|
});
|
|
219
211
|
}
|
|
220
212
|
// ---- assertions ---------------------------------------------------------------
|
|
213
|
+
/** The spellings a caller may name the target with, in payload precedence order. */
|
|
214
|
+
const FILE_SPELLINGS = ["file", "path", "file_path"];
|
|
215
|
+
/** The exact refusal ADR-0031 quotes; one sentence, one owner. */
|
|
216
|
+
const FILE_REQUIRED_MESSAGE = "Edit request file must be a non-empty string; name the file to edit.";
|
|
217
|
+
/**
|
|
218
|
+
* #117: is this raw record an unnamed target rather than a malformed payload?
|
|
219
|
+
*
|
|
220
|
+
* `normalizeRequest` stamps its marker only when `editRequestFrom` succeeds, and
|
|
221
|
+
* the fold rejects a null/absent file — so without this predicate the specific
|
|
222
|
+
* refusal is unreachable and the caller only sees the generic hint. A spelling
|
|
223
|
+
* that is present but wrongly typed is malformed, not unnamed, and stays generic.
|
|
224
|
+
*/
|
|
225
|
+
function namesNoFile(request) {
|
|
226
|
+
let seesUnnamed = false;
|
|
227
|
+
for (const key of FILE_SPELLINGS) {
|
|
228
|
+
if (!(key in request))
|
|
229
|
+
continue;
|
|
230
|
+
const value = request[key];
|
|
231
|
+
if (typeof value === "string") {
|
|
232
|
+
if (sanitizePath(value) !== null)
|
|
233
|
+
return false; // a usable name wins
|
|
234
|
+
seesUnnamed = true;
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
if (value === null || value === undefined) {
|
|
238
|
+
seesUnnamed = true;
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
return false; // present but wrongly typed: malformed payload
|
|
242
|
+
}
|
|
243
|
+
// No spelling at all is still unnamed when the record carries an edit payload;
|
|
244
|
+
// a record naming nothing and carrying nothing keeps the generic hint.
|
|
245
|
+
return seesUnnamed || Array.isArray(request.edits);
|
|
246
|
+
}
|
|
221
247
|
export function assertEditRequest(request) {
|
|
248
|
+
// #117: the specific refusal must be reachable before the marker guard — a raw
|
|
249
|
+
// record whose file is null/absent/empty never normalizes, so the generic hint
|
|
250
|
+
// would otherwise be the only message the caller sees.
|
|
251
|
+
if (isRec(request) && namesNoFile(request)) {
|
|
252
|
+
throw new DomainError("E_BAD_PAYLOAD", { message: FILE_REQUIRED_MESSAGE });
|
|
253
|
+
}
|
|
222
254
|
if (!isNormalizedEdit(request)) {
|
|
223
255
|
throw new DomainError("E_BAD_PAYLOAD", {
|
|
224
256
|
message: 'Edit request must be exactly { file, edits: [{ anchor_from, anchor_to, replace_with }, ...], mode?: "general" | "literal" }. ' +
|
|
@@ -227,9 +259,9 @@ export function assertEditRequest(request) {
|
|
|
227
259
|
}
|
|
228
260
|
rejectUnknownFields(request, EDIT_KS, "Edit request");
|
|
229
261
|
const req = request;
|
|
230
|
-
if (
|
|
262
|
+
if (typeof req.file !== "string" || req.file.length === 0) {
|
|
231
263
|
throw new DomainError("E_BAD_PAYLOAD", {
|
|
232
|
-
message:
|
|
264
|
+
message: FILE_REQUIRED_MESSAGE,
|
|
233
265
|
});
|
|
234
266
|
}
|
|
235
267
|
if (req.mode !== undefined && req.mode !== "general" && req.mode !== "literal") {
|
|
@@ -295,13 +327,12 @@ export const anchorToSchema = {
|
|
|
295
327
|
};
|
|
296
328
|
export const pathSchema = {
|
|
297
329
|
type: "string",
|
|
298
|
-
description: "File path
|
|
330
|
+
description: "File path",
|
|
299
331
|
};
|
|
300
332
|
export const editPathSchema = {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
],
|
|
333
|
+
type: "string",
|
|
334
|
+
minLength: 1,
|
|
335
|
+
description: "Text file to edit (a file, never a directory)",
|
|
305
336
|
};
|
|
306
337
|
export const editTupleSchema = {
|
|
307
338
|
type: "array",
|
package/lib/domain-errors.js
CHANGED
|
@@ -218,16 +218,14 @@ function batchAbortFormat(payload) {
|
|
|
218
218
|
function noopLoopFormat(payload) {
|
|
219
219
|
// WHY batch first: the batch ref already names the item (edits[i] (path)),
|
|
220
220
|
// so the batch arm renders from ref and appends the on-disk range when the
|
|
221
|
-
// engine supplies one
|
|
221
|
+
// engine supplies one. `enforceNoopLoop` is the only producer and always
|
|
222
|
+
// passes `batch: true`; the generic arm below keeps the message defined for
|
|
223
|
+
// a non-batch payload the type still admits.
|
|
222
224
|
if (payload.batch) {
|
|
223
225
|
return (`${payload.ref}: identical edit (${payload.anchorFrom} → ${payload.anchorTo}) submitted ${payload.count}×, no changes each time. ` +
|
|
224
226
|
`Range already contains this text; resend will reject the batch.` +
|
|
225
227
|
(payload.servedBlock ? `\nCurrent on-disk range:\n${payload.servedBlock}` : ""));
|
|
226
228
|
}
|
|
227
|
-
if (payload.path !== undefined) {
|
|
228
|
-
return (`identical edit (${payload.anchorFrom} → ${payload.anchorTo} in ${payload.path}) submitted ${payload.count}×, no changes each time. ` +
|
|
229
|
-
`Range already contains this text; resend will reject. Current range:\n${payload.servedBlock}`);
|
|
230
|
-
}
|
|
231
229
|
return (`identical edit (${payload.anchorFrom} → ${payload.anchorTo} ${payload.ref}) submitted ${payload.count}×, no changes each time. ` +
|
|
232
230
|
`Range already contains this text; resend will reject.`);
|
|
233
231
|
}
|
|
@@ -303,6 +301,12 @@ export const ERROR_REGISTRY = {
|
|
|
303
301
|
// WHY remedy: detection classified the target — kind (directory, binary or image) proves it is not an editable text file.
|
|
304
302
|
remedy: "Choose a text file and retry.",
|
|
305
303
|
},
|
|
304
|
+
E_ENCODING_UNWRITABLE: {
|
|
305
|
+
audience: "MODEL",
|
|
306
|
+
format: ({ path, encoding }) => `Cannot write ${path}: it was read as ${encoding}, and this filesystem exposes only a text write that always encodes UTF-8. Writing now would transcode the file silently, and its anchors would no longer describe the bytes on disk. Nothing was written. Set normalizeToUtf8: true (DSH_BETTER_EDIT_NORMALIZE_TO_UTF8=true) to migrate the file to UTF-8 explicitly, then retry.`,
|
|
307
|
+
// WHY remedy: the recorded encoding proves the text seam cannot reproduce it, and normalizeToUtf8 is the one setting that makes the write legal.
|
|
308
|
+
remedy: "Set normalizeToUtf8: true to migrate the file to UTF-8 explicitly, then retry.",
|
|
309
|
+
},
|
|
306
310
|
E_ACCESS: {
|
|
307
311
|
audience: "MODEL",
|
|
308
312
|
format: accessFormat,
|
|
@@ -432,7 +436,7 @@ export const WARNING_REGISTRY = {
|
|
|
432
436
|
format: () => "served-echo check bypassed by literal declaration.",
|
|
433
437
|
},
|
|
434
438
|
W_NOOP: {
|
|
435
|
-
audience: "
|
|
439
|
+
audience: "MODEL",
|
|
436
440
|
format: noopWarnFormat,
|
|
437
441
|
},
|
|
438
442
|
};
|
|
@@ -537,10 +541,14 @@ export const DECLARATION_ONLY_FIELDS = {
|
|
|
537
541
|
*
|
|
538
542
|
* | ported upstream diagnostic | upstream producer (pi-better-edit@b92e0ec) | local producer |
|
|
539
543
|
* |---|---|---|
|
|
540
|
-
* | `E_FOREIGN_ANCHOR` | `lease-resolve.ts:116` | `
|
|
541
|
-
* | `E_UNKNOWN_ANCHOR` | `lease-resolve.ts:118`, `served-verification.ts:745` | `
|
|
542
|
-
* | `E_UNVERIFIED_RANGE` | `lease-resolve.ts:186`, `served-verification.ts:187` | `
|
|
543
|
-
* | `E_TARGET_LOST` | `served-verification.ts:170`, `lease-resolve.ts:196` | `
|
|
544
|
+
* | `E_FOREIGN_ANCHOR` | `lease-resolve.ts:116` | `served-evidence.ts` (`throwUnknownOrForeign`, boundary placement) |
|
|
545
|
+
* | `E_UNKNOWN_ANCHOR` | `lease-resolve.ts:118`, `served-verification.ts:745` | `served-evidence.ts` (boundary placement, pre-gate) |
|
|
546
|
+
* | `E_UNVERIFIED_RANGE` | `lease-resolve.ts:186`, `served-verification.ts:187` | `served-evidence.ts` (pre-gate stale-boundary arm) |
|
|
547
|
+
* | `E_TARGET_LOST` | `served-verification.ts:170`, `lease-resolve.ts:196` | `served-evidence.ts` (pre-gate stale-boundary arm) |
|
|
548
|
+
*
|
|
549
|
+
* The upstream column is scoped to the upstream tree (`pi-better-edit@b92e0ec`): its
|
|
550
|
+
* `served-verification.ts` never existed downstream, so those cites never named a local
|
|
551
|
+
* file. The local column did move — the four arms live in `served-evidence.ts` (ADR-0037).
|
|
544
552
|
*
|
|
545
553
|
* Their owner is `"upstream absorb"` and their trigger is the absorb that
|
|
546
554
|
* ports the corresponding producer. When that happens, reintroduce the code
|
package/lib/edit-mode.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EditMode — the one member of the request contract the write pipeline names.
|
|
3
|
+
*
|
|
4
|
+
* WHY a module of its own (ADR-0037): `EditMode` is the only edge from
|
|
5
|
+
* anchor-pipeline back into contract.ts, and contract.ts reaches the read side
|
|
6
|
+
* through `ReadWindow`. Left there, the type re-closed the import ring; as a leaf
|
|
7
|
+
* it closes nothing — both ends import this file and never each other.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-better-edit/edit-mode
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
package/lib/encoding.js
CHANGED
|
@@ -12,6 +12,8 @@ export const SUPPORTED_ENCODINGS = [
|
|
|
12
12
|
"windows-1251",
|
|
13
13
|
"iso-8859-1",
|
|
14
14
|
];
|
|
15
|
+
// Rejection-message roster: utf8 is always accepted (see ALIASES), the roster is the six model codecs.
|
|
16
|
+
export const SUPPORTED_ENCODINGS_LABEL = `utf8, ${SUPPORTED_ENCODINGS.join(", ")}`;
|
|
15
17
|
const ALIASES = {
|
|
16
18
|
utf8: "utf8",
|
|
17
19
|
utf8bom: "utf8bom",
|