dsh-hashline-edit 0.1.0 → 0.2.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 (131) hide show
  1. package/README.md +72 -70
  2. package/cordis.patch.yml +1 -1
  3. package/lib/index.js +4494 -4813
  4. package/lib/types/dsh/contracts.d.ts +69 -6
  5. package/lib/types/dsh/fs.d.ts +38 -3
  6. package/lib/types/dsh/guidance.d.ts +5 -5
  7. package/lib/types/dsh/hide.d.ts +78 -0
  8. package/lib/types/dsh/host-compat.d.ts +7 -78
  9. package/lib/types/dsh/index.d.ts +17 -7
  10. package/lib/types/dsh/metrics/events.d.ts +8 -1
  11. package/lib/types/dsh/metrics/instrument.d.ts +20 -14
  12. package/lib/types/dsh/metrics/observer.d.ts +28 -0
  13. package/lib/types/dsh/sandbox.d.ts +2 -2
  14. package/lib/types/dsh/shell-hook.d.ts +17 -8
  15. package/lib/types/dsh/shell-view.d.ts +65 -3
  16. package/lib/types/dsh/tools/apply-patch.d.ts +38 -0
  17. package/lib/types/dsh/tools/context.d.ts +19 -1
  18. package/lib/types/dsh/tools/output.d.ts +32 -4
  19. package/lib/types/dsh/tools/read.d.ts +12 -15
  20. package/lib/types/dsh/tools/undo.d.ts +5 -0
  21. package/lib/types/dsh/write-hook.d.ts +8 -22
  22. package/lib/types/src/apply-patch/commit.d.ts +49 -0
  23. package/lib/types/src/apply-patch/grammar.d.ts +29 -0
  24. package/lib/types/src/apply-patch/lifecycle.d.ts +32 -0
  25. package/lib/types/src/apply-patch/plan.d.ts +50 -0
  26. package/lib/types/src/apply-patch/render.d.ts +51 -0
  27. package/lib/types/src/apply-patch/resolve.d.ts +129 -0
  28. package/lib/types/src/apply-patch/tool.d.ts +54 -0
  29. package/lib/types/src/apply-patch/types.d.ts +362 -0
  30. package/lib/types/src/bash-view-banner.d.ts +20 -0
  31. package/lib/types/src/domain-errors.d.ts +16 -2
  32. package/lib/types/src/edit-undo.d.ts +11 -2
  33. package/lib/types/src/file-content/detection.d.ts +17 -0
  34. package/lib/types/src/file-content/index.d.ts +2 -2
  35. package/lib/types/src/file-content/preview.d.ts +1 -1
  36. package/lib/types/src/fs-lifecycle.d.ts +44 -0
  37. package/lib/types/src/hashline/resolve.d.ts +6 -0
  38. package/lib/types/src/host-utils.d.ts +63 -0
  39. package/lib/types/src/mutation-engine/batch-span-gate.d.ts +6 -0
  40. package/lib/types/src/mutation-engine/edit-request.d.ts +34 -0
  41. package/lib/types/src/mutation-engine/pipeline.d.ts +18 -3
  42. package/lib/types/src/mutation-engine/types.d.ts +50 -58
  43. package/lib/types/src/read-expansion/grammar-manifest.d.ts +4 -2
  44. package/lib/types/src/read-expansion/java-decoration.d.ts +21 -0
  45. package/lib/types/src/read-expansion/span-expansion.d.ts +6 -2
  46. package/lib/types/src/read-expansion/span-kind.d.ts +3 -2
  47. package/lib/types/src/read-expansion/vue-decoration.d.ts +14 -0
  48. package/lib/types/src/served-session/serve-render.d.ts +9 -3
  49. package/lib/types/src/undo-store.d.ts +17 -1
  50. package/package.json +10 -22
  51. package/prompts/apply-patch-guidelines.md +10 -0
  52. package/prompts/apply-patch.md +1 -0
  53. package/prompts/read-guidelines.md +5 -5
  54. package/prompts/read.md +1 -1
  55. package/prompts/undo-last-edit-guidelines.md +2 -2
  56. package/prompts/undo-last-edit-snippet.md +1 -1
  57. package/prompts/undo-last-edit.md +1 -1
  58. package/src/apply-patch/commit.ts +190 -0
  59. package/src/apply-patch/grammar.ts +620 -0
  60. package/src/apply-patch/index.ts +17 -0
  61. package/src/apply-patch/lifecycle.ts +195 -0
  62. package/src/apply-patch/plan.ts +800 -0
  63. package/src/apply-patch/render.ts +137 -0
  64. package/src/apply-patch/resolve.ts +470 -0
  65. package/src/apply-patch/tool.ts +257 -0
  66. package/src/apply-patch/types.ts +387 -0
  67. package/src/cut-repair.ts +77 -11
  68. package/src/domain-errors.ts +58 -10
  69. package/src/edit-undo.ts +379 -25
  70. package/src/file-content/detection.ts +34 -0
  71. package/src/file-content/index.ts +2 -2
  72. package/src/file-content/preview.ts +1 -1
  73. package/src/file-content/served-header.ts +1 -1
  74. package/src/fs-lifecycle.ts +201 -0
  75. package/src/hash-store.ts +18 -1
  76. package/src/hashline/lease-resolve.ts +14 -8
  77. package/src/hashline/resolve.ts +30 -27
  78. package/src/host-utils.ts +224 -0
  79. package/src/mutation-engine/batch-span-gate.ts +17 -4
  80. package/src/mutation-engine/edit-request.ts +39 -0
  81. package/src/mutation-engine/pipeline.ts +535 -63
  82. package/src/mutation-engine/types.ts +49 -65
  83. package/src/mutation-queue.ts +1 -1
  84. package/src/prompts.ts +0 -28
  85. package/src/read-expansion/ast-provider.ts +4 -0
  86. package/src/read-expansion/grammar-manifest.ts +21 -2
  87. package/src/read-expansion/java-decoration.ts +34 -0
  88. package/src/read-expansion/span-expansion.ts +6 -2
  89. package/src/read-expansion/span-kind.ts +3 -1
  90. package/src/read-expansion/vue-decoration.ts +43 -0
  91. package/src/served-session/serve-render.ts +5 -5
  92. package/src/undo-store.ts +74 -5
  93. package/lib/types/dsh/encoding-bridge.d.ts +0 -25
  94. package/lib/types/dsh/encoding.d.ts +0 -144
  95. package/lib/types/dsh/tools/edit.d.ts +0 -10
  96. package/lib/types/src/edit-tool.d.ts +0 -41
  97. package/lib/types/src/mutation-engine/engine.d.ts +0 -31
  98. package/lib/types/src/payload-contract.d.ts +0 -124
  99. package/prompts/edit-guidelines.md +0 -10
  100. package/prompts/edit-snippet.md +0 -1
  101. package/prompts/edit.md +0 -1
  102. package/src/bash-classifier.ts +0 -1626
  103. package/src/bash-conversion/decide.ts +0 -812
  104. package/src/bash-display-transform.ts +0 -50
  105. package/src/bash-multifile-config.ts +0 -239
  106. package/src/bash-view-config.ts +0 -158
  107. package/src/edit-normalize.ts +0 -8
  108. package/src/edit-render.ts +0 -161
  109. package/src/edit-tool.ts +0 -116
  110. package/src/edit.ts +0 -136
  111. package/src/integrations/pi-lens/command.ts +0 -712
  112. package/src/integrations/pi-lens/config.ts +0 -148
  113. package/src/integrations/pi-lens/io-bridge-adapter.ts +0 -234
  114. package/src/integrations/pi-lens/io-bridge.ts +0 -112
  115. package/src/integrations/pi-lens/settings-overlay.ts +0 -272
  116. package/src/lifecycle-hooks/index.ts +0 -1992
  117. package/src/lifecycle-hooks/types.ts +0 -64
  118. package/src/mutated-files.ts +0 -75
  119. package/src/mutation-engine/engine.ts +0 -173
  120. package/src/mutation-engine/index.ts +0 -17
  121. package/src/payload-contract.ts +0 -637
  122. package/src/preview-controller.ts +0 -84
  123. package/src/read.ts +0 -865
  124. package/src/search-hook.ts +0 -41
  125. package/src/store-config.ts +0 -73
  126. package/src/store-janitor-warning.ts +0 -169
  127. package/src/store-janitor.ts +0 -539
  128. package/src/store-kernel/settings.ts +0 -233
  129. package/src/store.ts +0 -154
  130. package/src/tui-presenter.ts +0 -134
  131. package/src/write-hook.ts +0 -130
package/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  Hash-anchored file editing for [DeepSeek Harness](https://github.com/deepseek-ai) (dsh) on Windows.
4
4
 
5
- `dsh-hashline-edit` is a dsh bundle that shadows the host's built-in `read` and `edit` tools with hashline equivalents and adds `undo_last_edit`. Every line a served read shows carries a stable 4-character base62 anchor (`A–Z`, `a–z`, `0–9`) derived from the file's canonical path and the line's content. An edit names two anchors and new text; it never re-types existing code. Anchors for unchanged lines stay stable across edits, and every successful edit returns fresh anchors for the changed lines, so chained edits need no re-read.
5
+ `dsh-hashline-edit` is a dsh bundle that shadows the host's built-in `read` with hash-anchored output, registers `apply_patch` as the only file-mutation entry point, and adds `undo_last_edit`. There is no `edit` tool and no pi host support: this package target is DeepSeek Harness only. Every line a served read shows carries a stable 4-character base62 anchor (`A–Z`, `a–z`, `0–9`) derived from the file's canonical path and the line's content. An `apply_patch` hunk either names served anchors or matches file content; the model never re-types existing code. Anchors for unchanged lines stay stable across edits, and every successful `apply_patch` call returns fresh anchors for the changed lines, so chained calls need no re-read.
6
6
 
7
- The semantic core is the [pi-better-edit](https://github.com/Rianico/pi-better-edit) v2.16.0 hashline engine (MIT). The `dsh/` tree is this repository's DeepSeek Harness host layer: tool registration, filesystem bridge, encoding governance, prompt guidance, shell integration, write integration and telemetry. See [`dsh/README.md`](dsh/README.md) for the host-layer map.
7
+ The semantic core is the [pi-better-edit](https://github.com/Rianico/pi-better-edit) v2.16.0 hashline engine (MIT), carried as an internal engine; the pi host integration has been removed. The `dsh/` tree is this repository's DeepSeek Harness host layer: tool registration, filesystem bridge, UTF-8-only admission, prompt guidance, shell integration, write integration and telemetry. See [`dsh/README.md`](dsh/README.md) for the host-layer map.
8
8
 
9
9
  ## Requirements
10
10
 
@@ -13,7 +13,7 @@ The semantic core is the [pi-better-edit](https://github.com/Rianico/pi-better-e
13
13
  | OS | Windows — this branch targets Windows only (see [`dsh/UPSTREAM.md`](dsh/UPSTREAM.md)) |
14
14
  | Node.js | ≥ 24.0.0 |
15
15
  | pnpm | 12.x |
16
- | DeepSeek Harness | plugin-capable build; the repository is developed against `@deepseek-ai/dsh-*@0.2.1-rc.2` |
16
+ | DeepSeek Harness | plugin-capable build; the repository is developed against `@deepseek-ai/dsh-*@0.2.2-alpha.3` |
17
17
 
18
18
  ## Install
19
19
 
@@ -36,7 +36,7 @@ For a tarball, pack first and add the archive:
36
36
 
37
37
  ```sh
38
38
  pnpm pack
39
- dsh plugin add ./dsh-hashline-edit-0.1.0.tgz
39
+ dsh plugin add ./dsh-hashline-edit-0.2.0.tgz
40
40
  ```
41
41
 
42
42
  The bundle ships `lib/index.js` plus `lib/types/**`; `prompts/` must sit next to `lib/` in the installed package (it is in `files`). Guidance override files are materialized under `<DSH_HOME>/plugins/dsh-hashline-edit/guidance/` and are shared between profiles.
@@ -55,7 +55,7 @@ p9rX│ return total;
55
55
  a1bX│}
56
56
  ```
57
57
 
58
- Copy only the 4 characters before `│` into `anchor_from` / `anchor_to`. An edit targets an inclusive range and returns a diff whose modified and context rows carry fresh anchors:
58
+ Copy only the 4 characters before `│` into `anchor_from` / `anchor_to`. An `apply_patch` identity hunk targets an inclusive served range; a successful call returns a diff whose modified and context rows carry fresh anchors:
59
59
 
60
60
  ```text
61
61
  - szJx│ let total = 0;
@@ -81,88 +81,87 @@ read({
81
81
  | { around_anchor: string; radius?: number } // radius defaults to 10
82
82
  >,
83
83
  mode?: "served" | "verbatim", // default "served"
84
- encoding?: string, // reopen a non-UTF-8 file, e.g. "gbk", "big5", "shift_jis", "utf16le"
85
84
  })
86
85
  ```
87
86
 
88
- - **Served mode** returns one `HASH│content` row per line and records every shown row as a lease for this session. A windowed read also includes a `[Lines A-B of N total]` page header. Every row shown is usable by one subsequent edit, even when the windows are far apart.
89
- - **Verbatim mode** returns the same page as plain text with no anchors and serves nothing; an edit cannot target those lines.
90
- - A small requested window may widen to its enclosing function, method, class, section or paragraph; a `[widened …]` note names the block that was served. Expansion applies in both modes.
91
- - `offset`/`limit` and `windows` are page requests, not anchors: only `served` output grants edit leases.
87
+ - **Served mode** returns one `HASH│content` row per line and records every shown row as a lease for this session. A windowed read also includes a `[Lines A-B of N total]` page header. Every row shown is usable by one subsequent `apply_patch`, even when the windows are far apart.
88
+ - **Verbatim mode** returns the same page as plain text with no anchors and serves nothing; an `apply_patch` identity hunk cannot target those lines.
89
+ - A small requested window — up to 61 lines after folding — may widen to its enclosing function, method, class, section or paragraph; a `[widened …]` note names the block that was served. Expansion applies in both modes. Languages: TypeScript/TSX, Python, Go, Rust, Java and Vue through pinned tree-sitter wasm grammars (fetched lazily and verified against a committed SHA-256), plus Bash through the existing `unbash` parser (no wasm). Vue widens a top-level `template`/`script`/`style` block without parsing embedded JS/TS. SQL is not supported: real migrations largely fail to parse and `.tql` is a Java template, not SQL (see [`docs/spec/sql-vue-feasibility-gate.md`](docs/spec/sql-vue-feasibility-gate.md)).
90
+ - `offset`/`limit` and `windows` are page requests, not anchors: only `served` output grants mutation leases.
92
91
 
93
- ### `edit`
92
+ ### `apply_patch`
94
93
 
95
- ```ts
96
- edit({
97
- file: string, // one text file per call
98
- edits: [{
99
- anchor_from: string, // bare 4-char anchor of the first range line (inclusive)
100
- anchor_to: string, // bare 4-char anchor of the last range line (inclusive)
101
- text?: string, // by-value content; "" deletes an in-place range
102
- text_ref?: { // by-reference content from a served span
103
- anchor_from: string,
104
- anchor_to: string,
105
- file?: string, // another served file (foreign-source copy/cut)
106
- mode: "copy" | "cut", // required: copy keeps the source, cut retires the span
107
- },
108
- at?: "in-place" | "before" | "after", // default "in-place"
109
- }],
110
- mode?: "general" | "literal", // "general" refuses served-row echoes; "literal" declares them intended
111
- })
112
- ```
94
+ The only file-mutation entry point. One call carries one Codex patch document and commits the whole
95
+ batch as one correlated transaction (pre-mirror, undo rows, deterministic member order, all-or-nothing
96
+ rollback, then per-file store commits).
113
97
 
114
- Each item carries exactly one of `text` or `text_ref`; supplying both or neither is refused. `before`/`after` insert at the range boundary and require a single-line resolved target. A foreign-source `cut` writes both files as one correlated transaction; `undo_last_edit` reverts both members. An edit never silently rewrites submitted text — a refused edit writes nothing.
115
-
116
- The result is the core's unified diff with fresh anchors for the changed lines, so the next edit can chain from them without a `read`. The host's built-in `write` is not replaced: the plugin guards it against served-row echoes and appends an anchored auto-read so following edits can use its output.
98
+ ```text
99
+ *** Begin Patch
100
+ *** Update File: src/config.ts
101
+ @@
102
+ - retries: 3,
103
+ + retries: 5,
104
+ *** Add File: src/new.ts
105
+ +export const x = 1;
106
+ *** End Patch
107
+ ```
117
108
 
109
+ Addressing works in two modes, and one patch may mix them:
110
+
111
+ - **Fragment hunks** use the official Codex syntax. `@@` starts the search window at the file start;
112
+ `@@ <one context line>` moves the window after that line's unique match. Body lines are
113
+ ` ` (context), `-` (remove) and `+` (add). Matching is byte-exact and must be unique: zero or
114
+ multiple matches reject the whole call and serve the candidate rows back.
115
+ - **Identity hunks** use the `@@<a>` / `@@<a>-<b>` extension: two inclusive 4-char anchors from rows
116
+ this session served. The body is `+` lines only; an empty body deletes the span. A stale, unknown
117
+ or foreign anchor is rejected with the file's current rows served.
118
+ - **Reference hunks** `*** Copy From: <path> <a>-<b>` / `*** Cut From: <path> <a>-<b>` take the
119
+ bytes of another served span; a cut also retires the source span in the same transaction.
120
+ - **Lifecycle** `*** Add File:`, `*** Delete File:` and `*** Move to:` join text edits in the same
121
+ transaction and the same undo record. `*** End of File` pins a hunk to the file tail.
122
+
123
+ `@@` followed by a space is Codex's context mode; `@@` immediately followed by four anchor
124
+ characters is identity mode. Any rejection leaves every file byte-identical and reports every
125
+ independent problem with its patch line number and `[E_*`] code. Success returns a file-level summary
126
+ (A/M/R/D) followed by fresh `HASH│content` anchors for every changed line, so the next call can chain
127
+ without a `read`. The host's built-in `write` remains for whole-file rewrites.
118
128
  ### `undo_last_edit`
119
129
 
120
130
  ```ts
121
131
  undo_last_edit({ path: string })
122
132
  ```
123
133
 
124
- Restores the previous file content, BOM, line endings and original anchors from a snapshot-pinned undo record. The record survives agent restarts. A file changed externally after the edit is refused with `[E_UNDO_STALE]`. A correlated cut's undo restores every member of the transaction, not only the named path.
134
+ Restores the previous file content, BOM, line endings and original anchors from a snapshot-pinned undo record. The record survives agent restarts. A file changed externally after the patch is refused with `[E_UNDO_STALE]`. A correlated cut's undo restores every member of the transaction, not only the named path.
125
135
 
126
136
  ## Shell view
127
137
 
128
- The plugin installs a `tools/post-execute` listener for the host's `pwsh` and `bash` tools. When the command is a whitelisted read-only file view, the captured stdout is replaced with the aligned file's `HASH│content` rows, and those rows are served (leased) exactly like a read — a following `edit` can use them with no re-read.
138
+ The plugin installs a `tools/post-execute` listener for the host's `pwsh`, `bash` and built-in `grep` tools. When the command is a whitelisted read-only file view, the captured stdout is replaced with the aligned file's `HASH│content` rows, and those rows are served (leased) exactly like a read — a following `apply_patch` can use them with no re-read. A built-in grep result whose matches are proven against disk is served the same way (see the table below).
129
139
 
130
140
  | Command shape | Served as |
131
141
  | --- | --- |
132
142
  | `Get-Content <file>`, `type <file>`, `cat <file>` | the file's lines |
133
- | `Get-Content <file> \| Select-Object -First/-Last/-Skip <N>` | the bounded slice |
143
+ | `Get-Content <file> \| Select-Object -First\|-Last\|-Skip <N>` | the bounded slice |
144
+ | `Get-Content <file> \| Select-Object -Skip N -First M` (either order) | disk lines N+1 through N+M |
134
145
  | `Select-String <pattern> <file>` | the matched lines, with their line numbers |
135
146
  | `rg <pattern> <file>` (explicit single file, no switches) | the matched lines, with their line numbers |
147
+ | built-in `grep` (`@deepseek-ai/dsh-tool-fs-search`) | the matched lines grouped per file, each row `HASH│content` |
136
148
 
137
- Alignment is strict: stdout lines are mapped to 1-based disk line numbers with a monotonic, unique match (search output's own line numbers are used as hints). Anything the view cannot prove — an unknown pipeline, a wildcard path, formatted output, a truncated capture, a failed command — passes through byte-for-byte. The hook never guesses and never serves the wrong occurrence of a duplicated line.
149
+ The grep view applies the host's spill policy: at most 250 matches and at most 12,500 inline tokens (the host estimate `ceil(chars / 4) + 4`). A result over either cap, a failed call, a forged or stale match line, or non-ascending coordinates passes through byte-for-byte with no lease.
138
150
 
139
- ## Encoding governance
151
+ Alignment is strict: stdout lines are mapped to 1-based disk line numbers with a monotonic, unique match (search output's own line numbers are used as hints). Every served view is prefixed with the shared `[Bash view: <file> (lines a-b of N total)]` page header, so the positions the raw output used to name are not lost. Anything the view cannot prove — an unknown pipeline, a statement separator (`;`), a variable path (`$f`), a wildcard, formatted output, a truncated capture, a failed command — passes through byte-for-byte. The hook never guesses and never serves the wrong occurrence of a duplicated line.
152
+ ## Encoding: UTF-8 only
140
153
 
141
- The dsh host reintroduces a VS Code-style encoding model on top of the UTF-8 core. Read admission is deterministic:
154
+ The dsh host reads and writes UTF-8. Read admission is one rule with one exemption:
142
155
 
143
- 1. explicit `read({ encoding })` hint;
144
- 2. BOM sniff (UTF-8, UTF-16LE/BE and UTF-32LE/BE BOMs);
145
- 3. strict UTF-8 decode;
146
- 4. the `autoGuessEncoding` gate (off by default);
147
- 5. Top-3 candidate preview on refusal, e.g. `not readable UTF-8 text — top guesses: gbk("你好"); try read({encoding: "<encoding>"}) or enable autoGuessEncoding to decode automatically`.
156
+ 1. a leading UTF-8 BOM (`EF BB BF`) is stripped, so it never reaches an anchor;
157
+ 2. the remaining bytes must be strict UTF-8.
148
158
 
149
- Text encodings offered to the model are `gbk`, `big5`, `shift_jis`, `euc-kr`, `windows-1251` and `utf16le` (case-insensitive), in addition to UTF-8 and BOM-detected Unicode.
150
-
151
- A governed read records the file's encoding state (encoding, BOM, line ending, file version). Both the `edit` lane and the built-in `write` lane invert that state on save through a single codec:
152
-
153
- - a GBK file edited through `read` → `edit` stays GBK on disk (byte comparison, not text equality);
154
- - a UTF-16LE file with a BOM keeps its BOM and its byte order;
155
- - a UTF-8 BOM file round-trips byte-for-byte.
156
-
157
- When a legacy code page cannot represent the new text, the save degrades to UTF-8 and appends a model-facing warning instead of writing lossy bytes:
158
-
159
- > Warning: the file was written as UTF-8 because the recorded gbk encoding cannot represent the edited text. Re-read the file before the next edit.
160
-
161
- Undo also inverts the recorded state for every member of a correlated cut — but only when a governed read recorded that file's encoding state in the same plugin process. Without a recorded state, undo keeps the core's UTF-8 behavior; on a legacy file that can surface as `[E_UNDO_STALE]` rather than a guessed re-encode.
159
+ A file that is not valid UTF-8 is refused with `[E_UNSUPPORTED_FILE]` naming the file path and telling the model to ask the user how to handle it — for example a GBK-encoded source file or a BOM-less UTF-16LE file. The host does not guess a code page, offers no reopen-with-encoding parameter, keeps no encoding/BOM memo, and does not re-encode on save. UTF-16/UTF-32 BOMs are still recognized by kind detection: they are named in the refusal (e.g. `UTF-16LE encoded text`) instead of being decoded. Convert a non-UTF-8 file with an external tool before editing it here.
162
160
 
161
+ The built-in `write` integration and `undo_last_edit` speak the same contract: they write UTF-8, and every file this plugin serves is UTF-8.
163
162
  ## Sandbox behavior
164
163
 
165
- `edit` and `undo_last_edit` carry the host's optional escalation fields `sandbox_permissions` and `justification` only when a confining filesystem backend is mounted. `dsh/sandbox.ts` mirrors the built-in `@deepseek-ai/dsh-tool-fs` controller: it validates the field pairing, repeats the standing mode without approval, and resolves a strictly wider mode through the host's approval channel before touching the filesystem. A provider `FS_SANDBOX_DENIED` error is mapped to the standard model-facing denial marker plus escalation hint; other errors pass through unchanged.
164
+ `apply_patch` and `undo_last_edit` carry the host's optional escalation fields `sandbox_permissions` and `justification` only when a confining filesystem backend is mounted. `dsh/sandbox.ts` mirrors the built-in `@deepseek-ai/dsh-tool-fs` controller: it validates the field pairing, repeats the standing mode without approval, and resolves a strictly wider mode through the host's approval channel before touching the filesystem. A provider `FS_SANDBOX_DENIED` error is mapped to the standard model-facing denial marker plus escalation hint; other errors pass through unchanged.
166
165
 
167
166
  ### Host-side `0xC0000142` workspace-write finding
168
167
 
@@ -183,7 +182,7 @@ The M3/M4 smoke runs therefore used `DSH_PERMISSION_MODE=danger-full-access`; th
183
182
  | `pnpm run lint` | `oxlint .` + `knip --max-issues 0` |
184
183
  | `pnpm run verify` | lint + format + typecheck + Windows coverage |
185
184
 
186
- The build enforces its own packaging contract: host packages stay external, the pi utility package is aliased to `dsh/host-compat.ts` (the bundle must not reference pi), and no bare import outside the allowlist can slip in. See [`dsh/README.md`](dsh/README.md#build-and-packaging).
185
+ The build enforces its own packaging contract: host packages stay external, the bundle must not reference pi (there is no pi host integration), and no bare import outside the allowlist can slip in. See [`dsh/README.md`](dsh/README.md#build-and-packaging).
187
186
 
188
187
  ## Error and warning codes
189
188
 
@@ -194,7 +193,7 @@ Every refusal carries a bracketed code; `src/domain-errors.ts` is the source of
194
193
  | `[E_ACCESS]` | The filesystem denied access to the target path. |
195
194
  | `[E_BAD_PAYLOAD]` | Malformed or unknown tool payload; nothing is written. |
196
195
  | `[E_BATCH_ABORT]` | A batch item failed; the whole batch was not applied. |
197
- | `[E_EMPTY_RANGE]` | The edit would empty a non-empty file; use `write`. |
196
+ | `[E_EMPTY_RANGE]` | The patch would empty a non-empty file; use `write`. |
198
197
  | `[E_FOREIGN_ANCHOR]` | The anchor belongs to a different file. |
199
198
  | `[E_INTERNAL_INVARIANT]` | An internal invariant was violated. |
200
199
  | `[E_LARGE_FILE]` | The file exceeds the served line or byte budget. |
@@ -202,37 +201,40 @@ Every refusal carries a bracketed code; `src/domain-errors.ts` is the source of
202
201
  | `[E_MALFORMED_ANCHOR]` | The anchor token cannot be parsed. |
203
202
  | `[E_NOOP_LOOP]` | Repeated identical no-op edits; refused with the current range served. |
204
203
  | `[E_NOT_FOUND]` | The target file does not exist or is unreachable. |
204
+ | `[E_PATCH_SYNTAX]` | The apply_patch text is not valid syntax; nothing is written. |
205
205
  | `[E_STALE_ANCHOR]` | A boundary anchor no longer resolves against the file. |
206
- | `[E_STALE_RANGE]` | The served range changed between serve and edit. |
206
+ | `[E_STALE_RANGE]` | The served range changed between serve and patch. |
207
207
  | `[E_SUSPICIOUS_TEXT]` | The replacement reproduces served anchor text (a copied `HASH│` echo). |
208
208
  | `[E_TARGET_LOST]` | The target line identity can no longer be resolved. |
209
209
  | `[E_UNDO_REVERT_FAILED]` | A correlated revert failed mid-way; a repair run finishes it. |
210
210
  | `[E_UNDO_STALE]` | The undo record is stale relative to the file. |
211
211
  | `[E_UNDO_UNAVAILABLE]` | There is no undo history for the path. |
212
+ | `[E_UNIQUE_MATCH]` | A fragment hunk matched zero or multiple places; candidates are served back. |
212
213
  | `[E_UNKNOWN]` | An unclassified failure; the message carries the cause. |
213
214
  | `[E_UNKNOWN_ANCHOR]` | The anchor was never served in this session. |
214
- | `[E_UNSUPPORTED_FILE]` | Binary, image or directory targets are not editable text. |
215
+ | `[E_UNSUPPORTED_FILE]` | Binary, image or directory targets are not editable text; a non-UTF-8 file is refused with its path and an instruction to ask the user how to handle it. |
215
216
  | `[E_UNVERIFIED_RANGE]` | The range interior cannot be verified (never served). |
216
- | `[W_LITERAL_BYPASS]` | Literal `HASH│` bytes were written through `edit` and accepted with a warning. |
217
- | `[W_NEVER_SERVED_SHAPE]` | A never-served hint was attached to an accepted edit. |
218
- | `[W_NOOP]` | The edit produced no content change and was accepted as a no-op. |
219
- | `[W_NOOP_INSERT]` | An insert-shaped edit produced no change. |
217
+ | `[W_LITERAL_BYPASS]` | Literal `HASH│` bytes were written through `apply_patch` and accepted with a warning. |
218
+ | `[W_NEVER_SERVED_SHAPE]` | A never-served hint was attached to an accepted patch. |
219
+ | `[W_NOOP]` | The patch produced no content change and was accepted as a no-op. |
220
+ | `[W_NOOP_INSERT]` | An insert-shaped hunk produced no change. |
220
221
  | `[W_REVERSED_ANCHORS]` | Boundaries were reversed and healed. |
221
222
  | `[W_SERVED_PREFIX_MISMATCH]` | A served prefix does not match; fresh rows were served. |
222
223
  | `[W_UNICODE_LITERAL]` | A Unicode literal in the payload looks like a copied anchor. |
223
224
 
225
+ Range-family rejections render their current-row evidence exactly once: the headline plus one `Current range (fresh read):` block. A single-line anchor pair (`anchor_from` equals `anchor_to`) is listed once, and the distinct-anchor lists de-duplicate. `[E_UNKNOWN_ANCHOR]` and `[E_FOREIGN_ANCHOR]` also name each distinct anchor once.
226
+
224
227
  ## Current limitations
225
228
 
226
- - **`ctx.fs` is read-only.** The read path can consume a mounted `ctx.fs` through the `CoreReadIo` port, but the mutation seams — `writeAtomic`, the edit engine and undo — remain local-only. `edit` and `undo_last_edit` fail closed with `E_NOT_FOUND` when the target is reachable only through `ctx.fs`.
227
- - **`edit`, `undo_last_edit` and `writeAtomic` are local-only.** A remote or sandboxed backend needs target-keyed store state and versioned writes; that is deferred to M6 (see [`dsh/README.md`](dsh/README.md#ctxfs-bridge-m5-read-only)).
228
- - **Undo preserves a legacy encoding only with recorded state.** The encoding memo lives in the plugin process and is version-gated; a fresh process or a file never governed-read in that process has no state to invert, so undo keeps the core's UTF-8 behavior.
229
+ - **Mutation stays on the local `node:fs` seam.** The read path consumes a `CoreReadIo` port (local or mounted `ctx.fs`), but `writeAtomic`, the `apply_patch` engine and undo remain local-only. `apply_patch` and `undo_last_edit` fail closed with `E_NOT_FOUND` when the target is reachable only through `ctx.fs`. A full mutation bridge needs target-keyed store state: the host's `ctx.fs` already exposes versioned writes in `0.2.2-alpha.3`, but the snapshot/lease store still keys on absolute paths and local stat identity (M6, see [`dsh/README.md`](dsh/README.md#ctxfs-deferral-m6)).
230
+ - **UTF-8 only.** Non-UTF-8 files are refused on read and must be converted with an external tool; the plugin does not decode legacy code pages, does not re-encode on save, and keeps no encoding state.
229
231
  - **Windows-only.** The branch targets Windows; POSIX-only suites are excluded in `vitest.config.windows.ts`, and that exclusion list must shrink, never grow (see [`dsh/UPSTREAM.md`](dsh/UPSTREAM.md)).
230
232
 
231
233
  ## Repository layout
232
234
 
233
235
  | Path | Role |
234
236
  | --- | --- |
235
- | `src/` | upstream pi-better-edit core (semantic source; synced from upstream) |
237
+ | `src/` | hashline engine core derived from pi-better-edit (semantic source; upstream fixes are picked selectively, see [`dsh/UPSTREAM.md`](dsh/UPSTREAM.md)) |
236
238
  | `dsh/` | DeepSeek Harness host layer — the only code that differs from upstream; map in [`dsh/README.md`](dsh/README.md) |
237
239
  | `dsh/UPSTREAM.md` | upstream sync cursor, policy and Windows adaptation patches |
238
240
  | `dsh/baseline/` | milestone measurement baselines (M0–M5) |
@@ -241,7 +243,7 @@ Every refusal carries a bracketed code; `src/domain-errors.ts` is the source of
241
243
 
242
244
  ## Upstream attribution
243
245
 
244
- The hashline engine is [**pi-better-edit**](https://github.com/Rianico/pi-better-edit) by [Rianico](https://github.com/Rianico), used under the MIT license and synced at upstream `673964c` (`v2.16.0`; see [`dsh/UPSTREAM.md`](dsh/UPSTREAM.md)). This repository keeps the upstream history and tree; the `dsh/` adapter is ours, is never merged upstream, and contains only host wiring.
246
+ The hashline engine is [**pi-better-edit**](https://github.com/Rianico/pi-better-edit) by [Rianico](https://github.com/Rianico), used under the MIT license and synced at upstream `673964c` (`v2.16.0`; see [`dsh/UPSTREAM.md`](dsh/UPSTREAM.md)). This repository is a self-maintained fork: upstream is the semantic source of the hashline core and a place to pick bug-fix commits from, recorded in `dsh/UPSTREAM.md`; there is no commit-for-commit sync promise. The `dsh/` adapter is ours, is never merged upstream, and contains only host wiring.
245
247
 
246
248
  ## License
247
249
 
package/cordis.patch.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  # dsh-hashline-edit bundle patch: mount the host-plane plugin row.
2
2
  # Installed via `dsh plugin --profile <name> add dsh-hashline-edit` (or a
3
3
  # profile's bundle list). The plugin hooks agent/created and shadows the
4
- # built-in read/edit tools on each agent's own scope layer, so no preset
4
+ # built-in read tool and hides its native edit surface on each agent's own scope layer, so no preset
5
5
  # editing or user config is needed.
6
6
  - insert:
7
7
  - id: dsh-hashline-edit