dsh-hashline-edit 0.6.0 → 0.6.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-hashline-edit",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Hash-anchored read/apply_patch/edit tools for DeepSeek Harness (dsh). Every line gets a unique 3- or 4-char hash (A-Za-z0-9, configurable) that stays stable across edits; apply_patch and the anchored range edit tool are the file-mutation entry points, each committing its whole batch as one transaction.",
5
5
  "keywords": [
6
6
  "anchors",
@@ -1,4 +1,5 @@
1
1
  - edit: one call targets one `file` in one transaction — batch all N changes to that file as N items in the same call, and use parallel `edit` calls for different target files.
2
+ - edit: **prefer anchors — always.** Use `anchor_from`/`anchor_to` for essentially every change, including long multi-line ranges (name both bounds) and whole items (`expand: "item"`): anchors never re-type existing code and are verified against served rows. `{ old_string, new_string }` string replacement is a LAST-RESORT fallback only for a short, single-line, unique fragment you cannot address with an anchor — it must match `old_string` verbatim, so it is fragile, and a long/multi-line `old_string`, whitespace drift, or a non-unique fragment fails (`E_UNIQUE_MATCH`) and writes nothing; never use it to move or rewrite a block.
2
3
  - edit: every item carries exactly one payload — `text` (literal content; `""` deletes the range when `at` is `"in-place"`, and is a no-op for `"before"`/`"after"`), `text_ref` (with required non-null `mode`: `"copy"` re-inserts the served span's bytes, `"cut"` also deletes the source lines), or one of the insertion slots `after`/`before` (the lines to place immediately below/above `anchor_from`); never two, never none.
3
4
  - edit: when `text_ref` uses `mode: "cut"` (same file or another served file via `text_ref.file`), the source lines are deleted automatically in the same correlated transaction — never send a second `edit` to delete the source span.
4
5
  - edit: anchors are strictly the `{{HASH_LEN}}` characters immediately left of `│` in served rows — the segment between the display-only line-number gutter (`12{{GUTTER}}`) and `│`, never the gutter, a line number, the full row, or null. `anchor_from` is always required and names the first line of the range; `anchor_to` is optional and names the last line — omit it to edit the single line `anchor_from` names (the range is single-line without it, which is mandatory when `at` is `"before"` or `"after"`), and a `text_ref` span always names both bounds.
package/prompts/edit.md CHANGED
@@ -1,4 +1,4 @@
1
1
  Change one or more line ranges in one target text file with hash anchors: pass `file`, `edits` (one item per change), and optional top-level `mode` (`"general"` by default, or `"literal"`). Each item names one inclusive bare `{{HASH_LEN}}`-character anchor from before `│` in served rows (`anchor_from`), an optional second one closing a multi-line range (`anchor_to` — omit it to edit the single line `anchor_from` names; pass the identical hash to spell a single line explicitly), optional `at` (`"in-place"` by default; `"before"` or `"after"` inserts at a single-line target), and exactly one payload — `text` for replacement content (`""` deletes the span when `at` is `"in-place"`, and is a no-op with `"before"`/`"after"`) or `text_ref` (`{ anchor_from, anchor_to, file?, mode: "copy" | "cut" }`, whose two bounds are always required, where required `mode` `"copy"` re-inserts the served span's bytes and `"cut"` also deletes the source lines). One call targets one `file`; only `text_ref.file` may reference another served file as the copy/cut source (with `"cut"` deleting those source lines in the same correlated transaction). A rejected call writes nothing. Two shortcuts cover the common pure insertions: `after` and `before` each carry the exact lines to place immediately below or above the single line `anchor_from` names, instead of spelling `at` plus `text`. An item still carries exactly one payload — `text`, `text_ref`, `after`, or `before`.
2
2
 
3
3
  Two optional modifiers change where and how much the payload replaces. `indent: "auto"` (default `"as-is"`) re-bases a `text`/`after`/`before` payload on the leading whitespace of the line `anchor_from` names: write the snippet flush-left — or at any uniform extra indentation — and the tool drops the snippet's own shared leading-whitespace prefix, then writes every non-blank line at the anchor line's depth. Tabs and spaces stay literal (no conversion), blank lines are left as written, and `text_ref` refuses `indent` because those bytes are copied verbatim; the result's notes name the depth it landed at. `expand: "item"` replaces the whole syntax item that contains `anchor_from` — its leading doc comment/attributes/decorators and its matching closing brace — instead of a range you spell out: name only `anchor_from` (`anchor_to` is refused, because the AST decides the end) with a `text` payload, on a shipped code grammar (rust, typescript, tsx, vue, python, go, java). Prefer `expand` over hand-writing a whole function, class or method: you never have to reproduce the doc comment or the closing brace, and the diff shows the expanded range it replaced. A non-code file, an unavailable grammar, or an anchor outside any syntax item refuses and writes nothing. An expanded item must be the only item in its call.
4
- String replacement (native `str_replace` style) is an alternative when anchors are unavailable or awkward: an item may instead be `{ old_string, new_string }`, which replaces the exact, unique occurrence of `old_string` with `new_string` character-for-character (a match inside one line is fine). `old_string` must occur exactly once — zero or multiple matches refuse and write nothing — so include surrounding content to make it unique. A call may mix anchor items and string items: each item is one or the other, and items apply in order, each to the result of the previous.
4
+ **Prefer anchors — always.** Anchored items are the primary API for every change: `anchor_from`/`anchor_to` plus `text` (or `text_ref`/`after`/`before`) never re-type existing code, work at any size, and are verified against served rows — use them for essentially every edit, including long multi-line ranges (name both bounds) and whole items (`expand: "item"`). `{ old_string, new_string }` (native `str_replace`) is only a **last-resort fallback** for a SHORT, single-line, unique fragment you cannot address with an anchor; it is character-level and must reproduce `old_string` verbatim, so it is fragile and often fails — a long or multi-line `old_string`, whitespace or indentation drift, or a non-unique fragment refuses (`E_UNIQUE_MATCH`) and writes nothing. Never use it to move or rewrite a block: read the file and use anchors, or `expand: "item"`. A call may mix anchor and string items, but default every item to an anchor.