dsh-hashline-edit 0.4.2 → 0.4.3

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/README.md CHANGED
@@ -73,7 +73,7 @@ p9r│ return total;
73
73
  a1b│}
74
74
  ```
75
75
 
76
- Copy only the build-width characters before `│` (3 by default; 4 in a 4-char build). `edit` passes them as `anchor_from` / `anchor_to`; `apply_patch` writes them as `@@<anchor>` for one row or `@@<from>-<to>` for a span. Both forms target an inclusive served range; a successful call returns a diff whose modified and context rows carry fresh anchors:
76
+ Copy only the build-width characters before `│` (3 by default; 4 in a 4-char build). `edit` passes them as `anchor_from`, plus `anchor_to` only when the range spans more than one line; `apply_patch` writes them as `@@<anchor>` for one row or `@@<from>-<to>` for a span. Both forms target an inclusive served range; a successful call returns a diff whose modified and context rows carry fresh anchors:
77
77
 
78
78
  ```text
79
79
  - szJ│ let total = 0;
@@ -177,17 +177,16 @@ The anchored range writer. One call targets one file and carries one ordered `ed
177
177
  {
178
178
  "file": "src/config.ts",
179
179
  "edits": [
180
- { "anchor_from": "szJ", "anchor_to": "szJ", "text": " retries: 5," },
180
+ { "anchor_from": "szJ", "text": " retries: 5," },
181
181
  {
182
182
  "anchor_from": "d2x",
183
- "anchor_to": "d2x",
184
183
  "text_ref": { "anchor_from": "a1b", "anchor_to": "a1b", "file": "src/defaults.ts", "mode": "copy" }
185
184
  }
186
185
  ]
187
186
  }
188
187
  ```
189
188
 
190
- Each item names two inclusive bare anchors and exactly one payload: `text` is the replacement content (`""` deletes the range), or `text_ref` is a served span read in `copy` or `cut` mode. Optional `at` is `in-place` by default; `before` / `after` insert at the boundary and require a single-line target. A `text_ref.file` may name another served file as the copy/cut source, and `cut` also retires those source lines; the call's own target remains one file. The retired item-level `file` field is not part of the payload — an old multi-file item shape is refused with `[E_BAD_PAYLOAD]`, and a different target file is a different call. The call commits as one transaction and writes one undo record for recovery; undo is not exposed as a model tool.
189
+ Each item names one inclusive bare anchor, `anchor_from`, and exactly one payload: `text` is the replacement content (`""` deletes the range), or `text_ref` is a served span read in `copy` or `cut` mode. A multi-line range adds the optional second anchor `anchor_to` (the last line, inclusive), so a single-line edit omits it and the target is the one line `anchor_from` names — spelling `anchor_from === anchor_to` still validates. A `text_ref` span always names both bounds. Optional `at` is `in-place` by default; `before` / `after` insert at the boundary and require a single-line target. A `text_ref.file` may name another served file as the copy/cut source, and `cut` also retires those source lines; the call's own target remains one file. The retired item-level `file` field is not part of the payload — an old multi-file item shape is refused with `[E_BAD_PAYLOAD]`, and a different target file is a different call. The call commits as one transaction and writes one undo record for recovery; undo is not exposed as a model tool.
191
190
 
192
191
  ## Shell view
193
192
 
@@ -278,7 +277,7 @@ Every refusal carries a bracketed code; `src/domain-errors.ts` is the source of
278
277
  | `[W_SERVED_PREFIX_MISMATCH]` | A served prefix does not match; fresh rows were served. |
279
278
  | `[W_UNICODE_LITERAL]` | A Unicode literal in the payload looks like a copied anchor. |
280
279
 
281
- 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.
280
+ Range-family rejections render their current-row evidence exactly once: the headline plus one `Current range (fresh read):` block. A single-line target — whether written as one anchor or as a pair with `anchor_from` equal to `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.
282
281
 
283
282
  ## Current limitations
284
283
 
package/lib/index.js CHANGED
@@ -6435,9 +6435,9 @@ function assertItem(edit) {
6435
6435
  message: '"text" must be a string with \\n line separators, not an array. Multiple lines belong in one string, such as "line1\\nline2". An empty string deletes a range. Nothing was written.'
6436
6436
  });
6437
6437
  }
6438
- if (typeof edit.anchor_from !== "string" || typeof edit.anchor_to !== "string") {
6438
+ if (typeof edit.anchor_from !== "string") {
6439
6439
  throw new DomainError("E_BAD_PAYLOAD", {
6440
- message: `The edit requires "anchor_from" and "anchor_to" anchor strings (bare ${HASH_LEN}-char hashes from served output). Nothing was written.`
6440
+ message: `The edit requires an "anchor_from" anchor string (a bare ${HASH_LEN}-char hash from served output). Nothing was written.`
6441
6441
  });
6442
6442
  }
6443
6443
  if ("placement" in edit && !isEditPlacement(edit.placement)) {
@@ -6467,7 +6467,7 @@ function firstHashFromBlock(block) {
6467
6467
  function resEdit(edit) {
6468
6468
  assertItem(edit);
6469
6469
  const editLines = parseText(edit.text);
6470
- const bounds = [edit.anchor_from, edit.anchor_to].map((ref) => {
6470
+ const bounds = [edit.anchor_from, edit.anchor_to ?? edit.anchor_from].map((ref) => {
6471
6471
  const trimmed = ref.trim();
6472
6472
  if (trimmed.includes("\n")) {
6473
6473
  const hash = firstHashFromBlock(trimmed);
@@ -15096,8 +15096,8 @@ function isRec(value) {
15096
15096
  function isNormalizedEdit(input) {
15097
15097
  return isRec(input) && input[normalizedEdit] === true;
15098
15098
  }
15099
- var ITEM_SHAPE = "an item is exactly { anchor_from, anchor_to, text[, at] } or { anchor_from, anchor_to, text_ref[, at] }";
15100
- var EDIT_PAYLOAD_HINT = `Edit must be called with exactly one payload per item, and each call edits ONE file. Use the canonical payload {"file": file, "edits": [{ "anchor_from": anchor_from, "anchor_to": anchor_to, "text": text }, ...], "mode"?: "general" | "literal"}: "file" is the text file to edit (a non-empty string, never a directory); each item names two inclusive bare-${HASH_LEN}-char anchors and exactly one payload \u2014 "text" (bare replacement content; an empty string deletes the range) or "text_ref" ({ anchor_from, anchor_to, file?, mode (required): "copy" | "cut" } \u2014 the served span's bytes, whose "file" may name another served file as the copy/cut source; optional "at" is "in-place" (default), "before" or "after" (single-line resolved target only); optional "mode" is "general" (default, reproduced served rows are refused) or "literal" (declared literal content).`;
15099
+ var ITEM_SHAPE = "an item is exactly { anchor_from, anchor_to?, text[, at] } or { anchor_from, anchor_to?, text_ref[, at] }";
15100
+ var EDIT_PAYLOAD_HINT = `Edit must be called with exactly one payload per item, and each call edits ONE file. Use the canonical payload {"file": file, "edits": [{ "anchor_from": anchor_from, "anchor_to": anchor_to, "text": text }, ...], "mode"?: "general" | "literal"}: "file" is the text file to edit (a non-empty string, never a directory); each item names the bare-${HASH_LEN}-char anchor "anchor_from" (the first line of the range, and the whole range of a single-line edit), an optional second bare anchor "anchor_to" (the last line of a multi-line range; omit it to edit "anchor_from" alone) and exactly one payload \u2014 "text" (bare replacement content; an empty string deletes the range) or "text_ref" ({ anchor_from, anchor_to, file?, mode (required): "copy" | "cut" } \u2014 the served span's bytes, whose two bounds are always required, and whose "file" may name another served file as the copy/cut source); optional "at" is "in-place" (default), "before" or "after" (single-line resolved target only); optional "mode" is "general" (default, reproduced served rows are refused) or "literal" (declared literal content).`;
15101
15101
  function describeReceived(input) {
15102
15102
  if (input === void 0) return "Received no arguments.";
15103
15103
  if (input === null) return "Received null.";
@@ -15147,9 +15147,13 @@ function sanitizePath(value) {
15147
15147
  }
15148
15148
  var ITEM_KEY_SETS = [
15149
15149
  ["anchor_from", "anchor_to", "text"],
15150
+ ["anchor_from", "text"],
15150
15151
  ["anchor_from", "anchor_to", "at", "text"],
15152
+ ["anchor_from", "at", "text"],
15151
15153
  ["anchor_from", "anchor_to", "text_ref"],
15152
- ["anchor_from", "anchor_to", "at", "text_ref"]
15154
+ ["anchor_from", "text_ref"],
15155
+ ["anchor_from", "anchor_to", "at", "text_ref"],
15156
+ ["anchor_from", "at", "text_ref"]
15153
15157
  ];
15154
15158
  function keySetEquals(keys, shape) {
15155
15159
  if (keys.size !== shape.length) return false;
@@ -15164,7 +15168,7 @@ function isAbsentValue(value) {
15164
15168
  }
15165
15169
  function foldAbsentSlots(item) {
15166
15170
  const folded = { ...item };
15167
- for (const key of ["text", "text_ref", "at"]) {
15171
+ for (const key of ["text", "text_ref", "at", "anchor_to"]) {
15168
15172
  if (isAbsentValue(folded[key])) delete folded[key];
15169
15173
  }
15170
15174
  if (isRec(folded.text_ref)) {
@@ -15187,7 +15191,7 @@ function analyzeItem(value, index) {
15187
15191
  }
15188
15192
  const payloadKeys = /* @__PURE__ */ new Set(["anchor_from", "anchor_to", "at", "text", "text_ref"]);
15189
15193
  const offending = [...keys].filter((key) => !payloadKeys.has(key));
15190
- const missing = ["anchor_from", "anchor_to"].filter((key) => !keys.has(key));
15194
+ const missing = ["anchor_from"].filter((key) => !keys.has(key));
15191
15195
  const clauses = [];
15192
15196
  if (offending.length > 0) clauses.push(`unsupported field(s) ${quoted(offending)}`);
15193
15197
  if (missing.length > 0) clauses.push(`missing required field(s) ${quoted(missing)}`);
@@ -15198,8 +15202,11 @@ function analyzeItem(value, index) {
15198
15202
  return `edit[${index}] has ${clauses.join(";")} (${ITEM_SHAPE}).`;
15199
15203
  }
15200
15204
  const { anchor_from, anchor_to, at, text, text_ref } = value;
15201
- if (typeof anchor_from !== "string" || typeof anchor_to !== "string") {
15202
- return `edit[${index}] "anchor_from"/"anchor_to" must be bare ${HASH_LEN}-char hash anchor strings copied from served output (before \u2502): both anchors are required, so null is not a value here.`;
15205
+ if (typeof anchor_from !== "string") {
15206
+ return `edit[${index}] "anchor_from" must be a bare ${HASH_LEN}-char hash anchor copied from served output (before \u2502): it is the one anchor every item needs \u2014 an omitted "anchor_to" makes it the whole single-line target.`;
15207
+ }
15208
+ if (anchor_to !== void 0 && typeof anchor_to !== "string") {
15209
+ return `edit[${index}] "anchor_to" must be a bare ${HASH_LEN}-char hash anchor copied from served output (before \u2502) or omitted to target the single line "anchor_from" names.`;
15203
15210
  }
15204
15211
  if (!isAbsentValue(at)) {
15205
15212
  if (at === "in_place") {
@@ -15308,8 +15315,12 @@ function analyzeRequest(input) {
15308
15315
  function normalizedItemFrom(item) {
15309
15316
  const at = item.at ?? "in-place";
15310
15317
  const payload = item.text_ref !== void 0 ? { kind: "reference", span: item.text_ref, mode: item.text_ref.mode } : item.text === "" ? { kind: "empty" } : { kind: "literal", text: item.text ?? "" };
15318
+ const target = {
15319
+ anchor_from: item.anchor_from,
15320
+ anchor_to: item.anchor_to ?? item.anchor_from
15321
+ };
15311
15322
  return {
15312
- target: { anchor_from: item.anchor_from, anchor_to: item.anchor_to },
15323
+ target,
15313
15324
  at,
15314
15325
  payload
15315
15326
  };
@@ -15579,9 +15590,13 @@ var EDIT_PARAMETERS = {
15579
15590
  description: "Bare hash anchor of the first range line (inclusive)"
15580
15591
  },
15581
15592
  anchor_to: {
15582
- type: "string",
15583
- required: true,
15584
- description: "Bare hash anchor of the last range line (inclusive)"
15593
+ oneOf: [
15594
+ {
15595
+ type: "string",
15596
+ description: "Bare hash anchor of the last range line (inclusive); omit it to edit the single line anchor_from names"
15597
+ },
15598
+ { type: "null" }
15599
+ ]
15585
15600
  },
15586
15601
  at: {
15587
15602
  oneOf: [
@@ -120,7 +120,8 @@ export interface NEdit {
120
120
  export type HTEdit = {
121
121
  text: string;
122
122
  anchor_from: string;
123
- anchor_to: string;
123
+ /** Last line of the target range; omitted means a single-line target — the line `anchor_from` names. */
124
+ anchor_to?: string;
124
125
  placement?: EditPlacement;
125
126
  source?: {
126
127
  anchor_from: string;
@@ -28,7 +28,11 @@ export declare const _placementVocabularyAgreement: [
28
28
  Placement extends EditPlacement ? true : never,
29
29
  EditPlacement extends Placement ? true : never
30
30
  ];
31
- /** The anchor pair an item targets — placement and payload are relative to its resolved span. */
31
+ /**
32
+ * The anchor pair an item targets — placement and payload are relative to its resolved span. A
33
+ * single-line target names its one line in both bounds (`anchor_from === anchor_to`): the engine
34
+ * keeps the closed pair so nothing downstream has to branch on an absent bound.
35
+ */
32
36
  type AnchorSpan = {
33
37
  anchor_from: string;
34
38
  anchor_to: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-hashline-edit",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
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,7 +1,7 @@
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
2
  - 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"`) or `text_ref` (with required non-null `mode`: `"copy"` re-inserts the served span's bytes, `"cut"` also deletes the source lines); never both, never neither.
3
3
  - 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
- - edit: anchors are strictly the bare `{{HASH_LEN}}` characters before `│` in served `HASH│content` rows — never a line number, full row, or null. Both `anchor_from` and `anchor_to` are required and inclusive; for a single-line target (mandatory when `at` is `"before"` or `"after"`), pass the identical hash for both (`anchor_from === anchor_to`).
4
+ - edit: anchors are strictly the bare `{{HASH_LEN}}` characters before `│` in served `HASH│content` rows — never a line number, 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.
5
5
  - edit: change only what the task changes — one item per intended range, keeping unchanged boundary rows and `HASH│` prefixes out of `text`.
6
6
  - edit: a stale or unknown anchor, or an overlapping range, rejects the whole call and writes nothing. A `text` payload echoing served rows in default top-level `mode: "general"` is refused (`E_SUSPICIOUS_TEXT`); prefer `text_ref` to duplicate or move served spans, or set top-level `mode: "literal"` when `text` must intentionally reproduce served lines.
7
7
  - edit: anchors already in context (from `read`, an auto-read, or an intercepted shell view that output `HASH│content` rows) need no re-read; an anchor rejection serves the current `HASH│content` rows back, so repair directly from those rows instead of re-reading or guessing.
package/prompts/edit.md CHANGED
@@ -1 +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 requires two inclusive bare `{{HASH_LEN}}`-character anchors from before `│` in served rows (`anchor_from`, `anchor_to`; pass `anchor_from === anchor_to` for a single line), 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" }`, 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.
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.
@@ -207,7 +207,8 @@ export interface NEdit {
207
207
  export type HTEdit = {
208
208
  text: string;
209
209
  anchor_from: string;
210
- anchor_to: string;
210
+ /** Last line of the target range; omitted means a single-line target — the line `anchor_from` names. */
211
+ anchor_to?: string;
211
212
  placement?: EditPlacement;
212
213
  source?: { anchor_from: string; anchor_to: string; retire: boolean };
213
214
  };
@@ -371,9 +372,9 @@ function assertItem(edit: Record<string, unknown>): void {
371
372
  '"text" must be a string with \\n line separators, not an array. Multiple lines belong in one string, such as "line1\\nline2". An empty string deletes a range. Nothing was written.',
372
373
  });
373
374
  }
374
- if (typeof edit.anchor_from !== "string" || typeof edit.anchor_to !== "string") {
375
+ if (typeof edit.anchor_from !== "string") {
375
376
  throw new DomainError("E_BAD_PAYLOAD", {
376
- message: `The edit requires "anchor_from" and "anchor_to" anchor strings (bare ${HASH_LEN}-char hashes from served output). Nothing was written.`,
377
+ message: `The edit requires an "anchor_from" anchor string (a bare ${HASH_LEN}-char hash from served output). Nothing was written.`,
377
378
  });
378
379
  }
379
380
  // SAFETY: (ticket-04 item (iii)) this is the ONLY fail-closed check on the internal placement
@@ -425,7 +426,10 @@ export function resEdit(edit: HTEdit): HEdit {
425
426
  assertItem(edit as Record<string, unknown>);
426
427
 
427
428
  const editLines = parseText(edit.text);
428
- const bounds = [edit.anchor_from, edit.anchor_to].map((ref) => {
429
+ // WHY: `anchor_to` is optional: an absent bound makes the target the single line `anchor_from`
430
+ // WHY: names, which is what a single-line edit always meant — the closed pair is built here so
431
+ // WHY: `hash_bounds` stays a total two-element tuple for every consumer.
432
+ const bounds = [edit.anchor_from, edit.anchor_to ?? edit.anchor_from].map((ref) => {
429
433
  const trimmed = ref.trim();
430
434
  if (trimmed.includes("\n")) {
431
435
  const hash = firstHashFromBlock(trimmed);
@@ -26,7 +26,8 @@ type SpanRef = {
26
26
  */
27
27
  type EditItem = {
28
28
  anchor_from: string;
29
- anchor_to: string;
29
+ /** Last line of the target range. Omitted (or null) means a single-line target: the range is "anchor_from" alone. */
30
+ anchor_to?: string;
30
31
  at?: "in-place" | "before" | "after";
31
32
  text?: string;
32
33
  text_ref?: SpanRef;
@@ -54,7 +55,11 @@ export const _placementVocabularyAgreement: [
54
55
  EditPlacement extends Placement ? true : never,
55
56
  ] = [true, true];
56
57
 
57
- /** The anchor pair an item targets — placement and payload are relative to its resolved span. */
58
+ /**
59
+ * The anchor pair an item targets — placement and payload are relative to its resolved span. A
60
+ * single-line target names its one line in both bounds (`anchor_from === anchor_to`): the engine
61
+ * keeps the closed pair so nothing downstream has to branch on an absent bound.
62
+ */
58
63
  type AnchorSpan = { anchor_from: string; anchor_to: string };
59
64
 
60
65
  type DesiredContent =
@@ -97,16 +102,18 @@ function isNormalizedEdit(input: unknown): input is Record<string, unknown> {
97
102
  }
98
103
 
99
104
  const ITEM_SHAPE =
100
- "an item is exactly { anchor_from, anchor_to, text[, at] } or { anchor_from, anchor_to, text_ref[, at] }";
105
+ "an item is exactly { anchor_from, anchor_to?, text[, at] } or { anchor_from, anchor_to?, text_ref[, at] }";
101
106
 
102
107
  const EDIT_PAYLOAD_HINT =
103
108
  "Edit must be called with exactly one payload per item, and each call edits ONE file. Use the canonical payload " +
104
109
  '{"file": file, "edits": [{ "anchor_from": anchor_from, "anchor_to": anchor_to, "text": text }, ...], "mode"?: "general" | "literal"}: ' +
105
- '"file" is the text file to edit (a non-empty string, never a directory); each item names two inclusive ' +
106
- `bare-${HASH_LEN}-char anchors and exactly one payload — "text" (bare replacement content; an empty string deletes the ` +
107
- 'range) or "text_ref" ({ anchor_from, anchor_to, file?, mode (required): "copy" | "cut" } — the served span\'s bytes, ' +
108
- 'whose "file" may name another served file as the copy/cut source; optional "at" is "in-place" (default), ' +
109
- '"before" or "after" (single-line resolved target only); optional "mode" is "general" (default, reproduced ' +
110
+ '"file" is the text file to edit (a non-empty string, never a directory); each item names the bare-' +
111
+ `${HASH_LEN}-char anchor "anchor_from" (the first line of the range, and the whole range of a single-line edit), an optional ` +
112
+ 'second bare anchor "anchor_to" (the last line of a multi-line range; omit it to edit "anchor_from" alone) and exactly one ' +
113
+ 'payload — "text" (bare replacement content; an empty string deletes the range) or "text_ref" ' +
114
+ '({ anchor_from, anchor_to, file?, mode (required): "copy" | "cut" } — the served span\'s bytes, whose two bounds are ' +
115
+ 'always required, and whose "file" may name another served file as the copy/cut source); optional "at" is "in-place" ' +
116
+ '(default), "before" or "after" (single-line resolved target only); optional "mode" is "general" (default, reproduced ' +
110
117
  'served rows are refused) or "literal" (declared literal content).';
111
118
  function describeReceived(input: unknown): string {
112
119
  if (input === undefined) return "Received no arguments.";
@@ -165,15 +172,21 @@ function sanitizePath(value: unknown): string | null {
165
172
  }
166
173
 
167
174
  // WHY: (ticket-04 §3) the finite key-set gate: an item is legal only when its key set is EXACTLY
168
- // WHY: one of S1 {anchor_from, anchor_to, text}, S2 = S1 + at, S3 {anchor_from, anchor_to,
169
- // WHY: text_ref}, S4 = S3 + at — set EQUALITY, never superset, so a legacy key, an `op` field,
170
- // WHY: both payloads or neither payload all refuse with the offending keys named. The vocabulary
171
- // WHY: stays "two anchors, one payload, optional placement" and one call edits one file.
175
+ // WHY: one of the eight shapes — { anchor_from, anchor_to?, text } and { anchor_from, anchor_to?,
176
+ // WHY: text_ref }, each optionally plus `at` — set EQUALITY, never superset, so a legacy key, an
177
+ // WHY: `op` field, both payloads or neither payload all refuse with the offending keys named.
178
+ // WHY: (ADR-0024) `anchor_to` is optional in every shape: one anchor means a single-line target.
179
+ // WHY: The vocabulary stays "anchor_from plus an optional closing anchor_to, one payload, optional
180
+ // WHY: placement" and one call edits one file.
172
181
  const ITEM_KEY_SETS: readonly (readonly string[])[] = [
173
182
  ["anchor_from", "anchor_to", "text"],
183
+ ["anchor_from", "text"],
174
184
  ["anchor_from", "anchor_to", "at", "text"],
185
+ ["anchor_from", "at", "text"],
175
186
  ["anchor_from", "anchor_to", "text_ref"],
187
+ ["anchor_from", "text_ref"],
176
188
  ["anchor_from", "anchor_to", "at", "text_ref"],
189
+ ["anchor_from", "at", "text_ref"],
177
190
  ];
178
191
 
179
192
  function keySetEquals(keys: Set<string>, shape: readonly string[]): boolean {
@@ -190,9 +203,9 @@ const AT_SPELLINGS = ["in-place", "before", "after"] as const satisfies readonly
190
203
 
191
204
  // WHY: (ticket-67) strict structured-output harnesses spell "absent" as an explicit `null`
192
205
  // WHY: (every property required). Key existence alone then lies: `{ text: "…", text_ref: null }`
193
- // WHY: was refused as carrying both. `null`/`undefined` in the four optional slots (`text`,
194
- // WHY: `text_ref`, `at`, root `mode`) reads as ABSENT wherever presence is decided — one
195
- // WHY: predicate, so the gate, the validators and the normalizers cannot disagree.
206
+ // WHY: was refused as carrying both. `null`/`undefined` in the optional slots (`text`,
207
+ // WHY: `text_ref`, `at`, `anchor_to`, root `mode`) reads as ABSENT wherever presence is decided —
208
+ // WHY: one predicate, so the gate, the validators and the normalizers cannot disagree.
196
209
  // WHY: (ticket-75) the nested reference's optional `file` is the same slot one level down: a
197
210
  // WHY: harness that must spell an omitted optional property emits `"file": null`, and reading it
198
211
  // WHY: as present refused a call no retry could satisfy — the #67 class, one object deeper.
@@ -205,7 +218,7 @@ function isAbsentValue(value: unknown): value is null | undefined {
205
218
  // WHY: shape `analyzeRequest` stores and nothing downstream can see an absent value as present.
206
219
  function foldAbsentSlots(item: Record<string, unknown>): Record<string, unknown> {
207
220
  const folded: Record<string, unknown> = { ...item };
208
- for (const key of ["text", "text_ref", "at"] as const) {
221
+ for (const key of ["text", "text_ref", "at", "anchor_to"] as const) {
209
222
  if (isAbsentValue(folded[key])) delete folded[key];
210
223
  }
211
224
  if (isRec(folded.text_ref)) {
@@ -237,7 +250,9 @@ function analyzeItem(value: unknown, index: number): string | undefined {
237
250
  // WHY: list alone renders blank there, so the refusal must name the missing keys too.
238
251
  const payloadKeys = new Set(["anchor_from", "anchor_to", "at", "text", "text_ref"]);
239
252
  const offending = [...keys].filter((key) => !payloadKeys.has(key));
240
- const missing = ["anchor_from", "anchor_to"].filter((key) => !keys.has(key));
253
+ // WHY: `anchor_to` is optional at the wire — a single-line target needs no second bound — so a
254
+ // WHY: missing `anchor_to` is not a refusal; the normalizer folds it onto `anchor_from`.
255
+ const missing = ["anchor_from"].filter((key) => !keys.has(key));
241
256
  const clauses: string[] = [];
242
257
  if (offending.length > 0) clauses.push(`unsupported field(s) ${quoted(offending)}`);
243
258
  if (missing.length > 0) clauses.push(`missing required field(s) ${quoted(missing)}`);
@@ -251,8 +266,11 @@ function analyzeItem(value: unknown, index: number): string | undefined {
251
266
  return `edit[${index}] has ${clauses.join(";")} (${ITEM_SHAPE}).`;
252
267
  }
253
268
  const { anchor_from, anchor_to, at, text, text_ref } = value;
254
- if (typeof anchor_from !== "string" || typeof anchor_to !== "string") {
255
- return `edit[${index}] "anchor_from"/"anchor_to" must be bare ${HASH_LEN}-char hash anchor strings copied from served output (before │): both anchors are required, so null is not a value here.`;
269
+ if (typeof anchor_from !== "string") {
270
+ return `edit[${index}] "anchor_from" must be a bare ${HASH_LEN}-char hash anchor copied from served output (before │): it is the one anchor every item needs — an omitted "anchor_to" makes it the whole single-line target.`;
271
+ }
272
+ if (anchor_to !== undefined && typeof anchor_to !== "string") {
273
+ return `edit[${index}] "anchor_to" must be a bare ${HASH_LEN}-char hash anchor copied from served output (before │) or omitted to target the single line "anchor_from" names.`;
256
274
  }
257
275
  if (!isAbsentValue(at)) {
258
276
  if (at === "in_place") {
@@ -390,8 +408,15 @@ function normalizedItemFrom(item: EditItem): NormalizedEditItem {
390
408
  : item.text === ""
391
409
  ? { kind: "empty" }
392
410
  : { kind: "literal", text: item.text ?? "" };
411
+ // WHY: the wire may omit `anchor_to`; the target is then the single line `anchor_from` names.
412
+ // WHY: The engine always receives a closed pair, so this one defaulting point keeps every
413
+ // WHY: downstream consumer shape-stable and nothing has to test for an absent bound.
414
+ const target: AnchorSpan = {
415
+ anchor_from: item.anchor_from,
416
+ anchor_to: item.anchor_to ?? item.anchor_from,
417
+ };
393
418
  return {
394
- target: { anchor_from: item.anchor_from, anchor_to: item.anchor_to },
419
+ target,
395
420
  at,
396
421
  payload,
397
422
  };