dsh-hashline-edit 0.4.0 → 0.4.2

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
@@ -2,7 +2,7 @@
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` with hash-anchored output and offers two write tools over the same served rows: `apply_patch` for Codex patch documents and `edit` for anchored range edits. The host's built-in `write` stays visible and is integrated by the write hook; while either plugin write tool is registered, the native `edit`/`str_replace_editor`/`apply_patch` surface is hidden. There is no pi host support, because this package targets DeepSeek Harness only. Every line a served read shows carries a stable 3- or 4-character base62 anchor (`A–Z`, `a–z`, `0–9`; the width is a build-time setting, see [Anchor width](#anchor-width)) derived from the file's canonical path and the line's content. `apply_patch` hunks either name served anchors or match file content; every `edit` item names served anchors. The model never re-types existing code. Anchors for unchanged lines stay stable across edits, and every successful mutation returns fresh anchors for the changed lines, so chained calls need no re-read.
5
+ `dsh-hashline-edit` is a dsh bundle that shadows the host's built-in `read` with hash-anchored output and offers two write tools over the same served rows: `apply_patch` for Codex patch documents and `edit` for anchored range edits. The host's built-in `write` stays visible and is integrated by the write hook; each replacement hides only its own native counterpart — registering `apply_patch` hides the native `apply_patch`, and registering `edit` hides the native `edit`/`str_replace_editor`. There is no pi host support, because this package targets DeepSeek Harness only. Every line a served read shows carries a stable 3- or 4-character base62 anchor (`A–Z`, `a–z`, `0–9`; the width is a build-time setting, see [Anchor width](#anchor-width)) derived from the file's canonical path and the line's content. `apply_patch` hunks either name served anchors or match file content; every `edit` item names served anchors. The model never re-types existing code. Anchors for unchanged lines stay stable across edits, and every successful mutation returns fresh anchors for the changed lines, so chained calls need no re-read.
6
6
 
7
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
 
@@ -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.2-rc.1` (host packages are declared as peer dependencies) |
16
+ | DeepSeek Harness | plugin-capable build; developed and tested against **DSH 0.2.2-rc.3**; host packages are declared as peer dependencies with range `>=0.2.2-rc.1 <0.2.3-0` |
17
17
 
18
18
  ### Anchor width (3 or 4)
19
19
 
@@ -57,7 +57,7 @@ pnpm pack
57
57
  dsh plugin add ./dsh-hashline-edit-0.2.1.tgz
58
58
  ```
59
59
 
60
- The bundle ships `lib/index.js` plus `lib/types/**`; `prompts/` must sit next to `lib/` in the installed package (it is in `files`). Guidance text is bundled with the package and injected statically — there is no runtime override file.
60
+ The bundle ships `lib/index.js` plus `lib/types/**`; `prompts/` must sit next to `lib/` in the installed package (it is in `files`). Prompt prose is read from `prompts/*.md` when the plugin loads, so editing those files and loading the rebuilt plugin changes what the model reads — there is no separate override file.
61
61
 
62
62
  ## The anchored model
63
63
 
package/cordis.patch.yml CHANGED
@@ -2,9 +2,10 @@
2
2
  # Installed via `dsh plugin --profile <name> add dsh-hashline-edit` (or a
3
3
  # profile's bundle list). The row carries three feature switches, edited on the
4
4
  # Plugins page: `read` shadows the built-in read, `applyPatch` exposes the
5
- # `apply_patch` tool, `edit` exposes the anchored range `edit` tool. Either
6
- # mutation tool hides the native write/editor surface (`edit`, `apply_patch`,
7
- # `str_replace_editor`) for the agent and leaves the built-in `write` visible;
5
+ # `apply_patch` tool, `edit` exposes the anchored range `edit` tool. `edit` hides
6
+ # the native `edit`/`str_replace_editor` (and, in an edit-only profile, the native
7
+ # `apply_patch`); `apply_patch` hides only the native `apply_patch`; the built-in
8
+ # `write` stays visible;
8
9
  # both may be on at once. Each toggles live: the host reloads this row and the
9
10
  # plugin re-mounts every live agent. Defaults: read on, apply_patch on, edit off.
10
11
  - insert:
package/lib/index.js CHANGED
@@ -1391,7 +1391,7 @@ function assertRange(offset, length) {
1391
1391
  }
1392
1392
 
1393
1393
  // dsh/hide.ts
1394
- var NATIVE_WRITE_TOOLS = ["edit", "str_replace_editor", "apply_patch"];
1394
+ var EDIT_FAMILY_NATIVE = ["edit", "str_replace_editor"];
1395
1395
  function readBooleanSource(value, fallback) {
1396
1396
  if (typeof value === "boolean") return value;
1397
1397
  if (typeof value === "function") {
@@ -1418,14 +1418,24 @@ function sanitizeHiddenToolNames(config) {
1418
1418
  return names;
1419
1419
  }
1420
1420
  function hiddenNames(config) {
1421
- const names = readBooleanSource(config.hideNativeWriteTools, true) ? [...NATIVE_WRITE_TOOLS] : [];
1422
- const seen = new Set(names);
1423
- for (const name2 of sanitizeHiddenToolNames(config)) {
1424
- if (!seen.has(name2)) {
1421
+ const names = [];
1422
+ const seen = /* @__PURE__ */ new Set();
1423
+ if (readBooleanSource(config.hideNativeWriteTools, true) && config.toolNames.includes("edit")) {
1424
+ for (const name2 of EDIT_FAMILY_NATIVE) {
1425
+ if (seen.has(name2)) continue;
1425
1426
  seen.add(name2);
1426
1427
  names.push(name2);
1427
1428
  }
1428
1429
  }
1430
+ if (readBooleanSource(config.hideNativeWriteTools, true) && config.toolNames.includes("edit") && !config.toolNames.includes("apply_patch") && !seen.has("apply_patch")) {
1431
+ seen.add("apply_patch");
1432
+ names.push("apply_patch");
1433
+ }
1434
+ for (const name2 of sanitizeHiddenToolNames(config)) {
1435
+ if (seen.has(name2)) continue;
1436
+ seen.add(name2);
1437
+ names.push(name2);
1438
+ }
1429
1439
  return names.filter((name2) => !config.toolNames.includes(name2));
1430
1440
  }
1431
1441
  function nativeEditorDenial(toolNames, name2) {
@@ -1542,7 +1552,7 @@ function registerNativeToolHiding(rootCtx, agentCtx, config) {
1542
1552
  configured.filter((name2) => toolExists(rootCtx, agentCtx, name2, config.scope))
1543
1553
  );
1544
1554
  const disposers = [];
1545
- if (restrictable.size > 0 || configured.length > 0) {
1555
+ if (restrictable.size > 0 || config.toolNames.length > 0) {
1546
1556
  let restrictError;
1547
1557
  const attemptRestrict = (names) => {
1548
1558
  if (names.length === 0) return void 0;
@@ -1904,42 +1914,8 @@ function commandOf(args) {
1904
1914
  return typeof command === "string" && command.length > 0 ? command : void 0;
1905
1915
  }
1906
1916
 
1907
- // src/prompts-bundled.ts
1908
- var BUNDLED_PROMPTS = {
1909
- "apply-patch-guidelines.md": `- apply_patch: one call = one transaction; batch related changes and split only when an earlier RESULT decides the next.
1910
- - apply_patch: an identity hunk is \`@@<anchor>\` or \`@@<from>-<to>\` followed by \`+\` lines; an empty body deletes every row of the span. Minimal shape: \`*** Begin Patch\` / \`*** Update File: <path>\` / \`@@<anchor>\` / \`+<new line>\` / \`*** End Patch\`.
1911
- - apply_patch: an identity anchor is the bare \`{{HASH_LEN}}\` characters before \`\u2502\` in a served row \u2014 never the whole row, never a line number; syntax is \`@@\` plus the anchor with no space between them.
1912
- - apply_patch: served beats text \u2014 when this session served the file, an identity hunk is REQUIRED, not preferred; a fragment hunk is limited to a file or region this session never served, and a text match never licenses one.
1913
- - apply_patch: anchors in hand mean no re-read \u2014 apply the identity hunk to the served rows instead of reading the file again; a rejection already serves the current rows back.
1914
- - apply_patch: change only what the task changes \u2014 an identity hunk carries \`+\` lines for the edited region and no unchanged rows, so a small edit stays a small patch.
1915
- - apply_patch: for a one-line or single-region change to a served file, one identity hunk is the whole call; do not switch to \`write\` because the file content is already in context.
1916
- - apply_patch: hunks are validated against the pre-call file in order (overlapping ranges reject the batch); a fragment hunk must match exactly once \u2014 \`E_UNIQUE_MATCH\` writes nothing \u2014 while a stale or unknown anchor is rejected; both serve the current rows back.
1917
- - apply_patch: a rejection writes nothing; retry from the served \`HASH\u2502content\` rows without another \`read\`.
1918
- - apply_patch: success returns fresh anchors for the changed lines; a patch carries only the changed rows, so a new file or an every-line rewrite stays with \`write\`.`,
1919
- "apply-patch.md": `Change an existing file with \`apply_patch\`; it is the default for every change to an existing file, including a one-line change. \`write\` is only for a new file or for a rewrite where every line changes; a partial change is never a whole-file replacement. Pass the complete patch as \`input\`. When this session already served the file \u2014 through \`read\`, \`grep\`, a \`bash\` view, or a previous \`apply_patch\` result \u2014 every hunk MUST be an identity hunk on a served row: reuse the bare anchor before \`\u2502\` (\`@@<anchor>\` to replace that row, \`@@<from>-<to>\` to replace a span whose anchors you hold), and add only the changed \`+\` lines rather than re-emitting rows you are not changing. Anchors already in hand need no re-read: patch them directly instead of calling \`read\` again. A fragment hunk (\`@@\` or \`@@ <context>\` matched by file text) is legal only for a file or region this session never served; if the file was served, a fragment hunk is the wrong tool even when the text matches, because it discards the anchor check that proves you edited the version you actually saw.`,
1920
- "edit-guidelines.md": `- edit: one call = one file and one transaction; N changes in that file are N items in the same call, and a different file is a different call.
1921
- - edit: every item carries exactly one payload \u2014 \`text\` (literal content; \`""\` deletes the range) or \`text_ref\` (\`mode: "copy"\` or \`"cut"\`); never both, never neither.
1922
- - edit: anchors are the bare \`{{HASH_LEN}}\` characters before \`\u2502\` in served output \u2014 never the whole row, never a line number.
1923
- - edit: both anchors are inclusive; \`at\` is \`in-place\` by default, while \`before\`/\`after\` insert at the boundary and require a single-line resolved target.
1924
- - edit: \`text_ref\` copies a served span's bytes; \`"cut"\` also retires the source lines, and \`text_ref.file\` may name another served file as that source.
1925
- - edit: anchors already in hand need no re-read \u2014 a rejection serves the current rows back, so repair from the \`HASH\u2502content\` rows instead of guessing.
1926
- - edit: change only what the task changes \u2014 one item per intended range, and unchanged rows stay out of the payload.
1927
- - edit: a stale or unknown anchor, an overlapping range, or a payload reproducing served rows in \`general\` mode rejects the whole call and writes nothing; \`mode: "literal"\` declares reproduced rows as intended content.
1928
- - edit: \`write\` is the whole-file path \u2014 a new file or an every-line rewrite stays with \`write\`, never an edit item.`,
1929
- "edit.md": `Change a range of lines in one text file with hash anchors: pass \`file\` plus \`edits\`, one item per change. Each item names two inclusive bare anchors from served rows (\`anchor_from\`, \`anchor_to\`), exactly one payload \u2014 \`text\` for the replacement content (\`""\` deletes the range) or \`text_ref\` for a served span (\`mode: "copy"\` re-inserts its bytes, \`"cut"\` also retires them) \u2014 and optional \`at\` (\`in-place\` by default, \`before\`/\`after\` for a single-line target). One call edits one file; \`text_ref.file\` may name another served file as the copy/cut source. Anchors are the bare \`{{HASH_LEN}}\` characters before \`\u2502\` in served output. A rejected call writes nothing.`,
1930
- "read-guidelines.md": `- read: call it for content the tool has never served you; a bash view or an auto-read already served the file, so \`apply_patch\` can use those rows.
1931
- - read: batch several disjoint ranges in ONE call with \`windows\` \u2014 an offset/limit range, or \`around_anchor\` plus \`radius\` around a line this session served.
1932
- - read: pass \`mode: "verbatim"\` when you will not \`apply_patch\` the file (config, docs, a README, skill files); otherwise omit it so the rows carry anchors.
1933
- - read: a window of 61 lines or fewer may widen to its enclosing block; widened rows carry a \`[widened \u2026]\` note. Caps are 80 lines for code/Markdown and 40 for plain text.
1934
- - read: read several files with parallel \`read\` calls, one file per call.
1935
- - read: PNG/JPG/GIF/WebP files return as an image attachment for multimodal models; binary files and directories are refused.`,
1936
- "read.md": `Reads a UTF-8 file as \`HASH\u2502content\` rows in served mode; each row's anchor is the \`apply_patch\` identity anchor for that line, and only the \`{{HASH_LEN}}\` characters before \`\u2502\` are the anchor. Pass \`mode: "verbatim"\` for plain text with no anchors when you will not apply_patch; verbatim is not capped by line budget. Batch disjoint ranges in one call with \`windows\` (offset/limit or \`around_anchor\`).`,
1937
- "write-guidelines.md": `- write: the content is the complete file; a partial change stays an \`apply_patch\` identity hunk, even when the whole file is already in context.
1938
- - write: never paste served \`HASH\u2502\` rows into the content; a line that reproduces a served row is refused as a served hash echo.`,
1939
- "write.md": `Read a file before overwriting it with \`write\`. \`write\` replaces the whole file: use it for a new file, or for a rewrite where every line changes. For a change to part of an existing file, use \`apply_patch\` identity hunks on the served rows instead.`
1940
- };
1941
-
1942
1917
  // src/prompts.ts
1918
+ import { readFileSync } from "node:fs";
1943
1919
  function applyReplacements(content, replacements) {
1944
1920
  let out = content;
1945
1921
  if (replacements) {
@@ -1949,27 +1925,19 @@ function applyReplacements(content, replacements) {
1949
1925
  }
1950
1926
  return out.split("{{HASH_LEN}}").join(String(HASH_LEN));
1951
1927
  }
1952
- function bundled(relativePath2) {
1953
- const name2 = relativePath2.slice(relativePath2.lastIndexOf("/") + 1);
1954
- const body = BUNDLED_PROMPTS[name2];
1955
- if (body === void 0) {
1956
- throw new Error(
1957
- `unknown bundled prompt: ${relativePath2} (bundled: ${Object.keys(BUNDLED_PROMPTS).join(", ")})`
1958
- );
1959
- }
1960
- return body;
1961
- }
1962
1928
  function loadP(relativePath2, replacements) {
1963
- return applyReplacements(bundled(relativePath2).trim(), replacements);
1929
+ const content = readFileSync(new URL(relativePath2, import.meta.url), "utf-8").trim();
1930
+ return applyReplacements(content, replacements);
1964
1931
  }
1965
1932
  function loadGuide(relativePath2, replacements) {
1966
- return applyReplacements(bundled(relativePath2), replacements).split("\n").map((line) => line.trim()).filter((line) => line.startsWith("- ")).map((line) => line.slice(2));
1933
+ const content = readFileSync(new URL(relativePath2, import.meta.url), "utf-8");
1934
+ return applyReplacements(content, replacements).split("\n").map((line) => line.trim()).filter((line) => line.startsWith("- ")).map((line) => line.slice(2));
1967
1935
  }
1968
1936
 
1969
1937
  // dsh/guidance.ts
1970
1938
  function guidanceText(intro, lines) {
1971
1939
  const bullets = lines.map((line) => `- ${line}`).join("\n");
1972
- return `${intro}
1940
+ return intro.trim() === "" ? bullets : `${intro}
1973
1941
 
1974
1942
  ${bullets}`;
1975
1943
  }
@@ -1978,28 +1946,25 @@ var GUIDANCE_SECTIONS = [
1978
1946
  name: "tool:read",
1979
1947
  defaultOrder: 1100,
1980
1948
  orderName: "TOOL_READ",
1981
- renderDefault: () => guidanceText(loadP("../prompts/read.md"), loadGuide("../prompts/read-guidelines.md"))
1949
+ renderDefault: () => guidanceText("", loadGuide("../prompts/read-guidelines.md"))
1982
1950
  },
1983
1951
  {
1984
1952
  name: "tool:write",
1985
1953
  defaultOrder: 1300,
1986
1954
  orderName: "TOOL_WRITE",
1987
- renderDefault: () => guidanceText(loadP("../prompts/write.md"), loadGuide("../prompts/write-guidelines.md"))
1955
+ renderDefault: () => guidanceText("", loadGuide("../prompts/write-guidelines.md"))
1988
1956
  },
1989
1957
  {
1990
1958
  name: "tool:apply_patch",
1991
1959
  defaultOrder: 1350,
1992
1960
  orderName: "TOOL_APPLY_PATCH",
1993
- renderDefault: () => guidanceText(
1994
- loadP("../prompts/apply-patch.md"),
1995
- loadGuide("../prompts/apply-patch-guidelines.md")
1996
- )
1961
+ renderDefault: () => guidanceText("", loadGuide("../prompts/apply-patch-guidelines.md"))
1997
1962
  },
1998
1963
  {
1999
1964
  name: "tool:edit",
2000
1965
  defaultOrder: 1360,
2001
1966
  orderName: "TOOL_EDIT",
2002
- renderDefault: () => guidanceText(loadP("../prompts/edit.md"), loadGuide("../prompts/edit-guidelines.md"))
1967
+ renderDefault: () => guidanceText("", loadGuide("../prompts/edit-guidelines.md"))
2003
1968
  }
2004
1969
  ];
2005
1970
  var SECTION_BY_NAME = new Map(GUIDANCE_SECTIONS.map((section) => [section.name, section]));
@@ -8413,7 +8378,7 @@ function findEnclosingScope(root, requestedStart, requestedEnd, scopeKinds) {
8413
8378
 
8414
8379
  // src/read-expansion/grammar-cache.ts
8415
8380
  import { createHash } from "node:crypto";
8416
- import { existsSync as existsSync3, mkdirSync as mkdirSync5, readFileSync, renameSync as renameSync4, rmSync, writeFileSync as writeFileSync2 } from "node:fs";
8381
+ import { existsSync as existsSync3, mkdirSync as mkdirSync5, readFileSync as readFileSync2, renameSync as renameSync4, rmSync, writeFileSync as writeFileSync2 } from "node:fs";
8417
8382
  import { dirname as dirname7, join as join8 } from "node:path";
8418
8383
 
8419
8384
  // src/read-expansion/grammar-manifest.ts
@@ -8508,7 +8473,7 @@ function readVerifiedCache(path, expected) {
8508
8473
  if (!existsSync3(path)) return void 0;
8509
8474
  let bytes;
8510
8475
  try {
8511
- bytes = readFileSync(path);
8476
+ bytes = readFileSync2(path);
8512
8477
  } catch {
8513
8478
  discardCachedGrammar(path);
8514
8479
  return void 0;
@@ -9788,7 +9753,7 @@ import {
9788
9753
  constants as constants5,
9789
9754
  existsSync as existsSync4,
9790
9755
  mkdirSync as mkdirSync6,
9791
- readFileSync as readFileSync2,
9756
+ readFileSync as readFileSync3,
9792
9757
  renameSync as renameSync5,
9793
9758
  unlinkSync as unlinkSync2,
9794
9759
  writeFileSync as writeFileSync3
@@ -9860,7 +9825,7 @@ function reasonOf2(error) {
9860
9825
  function readConfigObject(path, onWarn) {
9861
9826
  let raw;
9862
9827
  try {
9863
- raw = readFileSync2(path, "utf-8");
9828
+ raw = readFileSync3(path, "utf-8");
9864
9829
  } catch (error) {
9865
9830
  if (!isMissingFile(error)) onWarn?.(`cannot read config ${path}: ${reasonOf2(error)}`);
9866
9831
  return void 0;
@@ -10011,7 +9976,7 @@ async function publishPluginWrites(deps, requestPaths, ctx, exec) {
10011
9976
 
10012
9977
  // dsh/tools/read.ts
10013
9978
  var READ_TOOL_NAME = "read";
10014
- var READ_DESCRIPTION = 'Read a UTF-8 text file as hash-anchored `HASH\u2502content` rows; each anchor is the `apply_patch` identity for that line. Served mode is the default; `mode: "verbatim"` returns plain text with no anchors. Supports offset/limit pages and `windows` (offset/limit or around_anchor).';
9979
+ var READ_DESCRIPTION = loadP("../prompts/read-description.md");
10015
9980
  var RENDER_MODES = ["served", "verbatim"];
10016
9981
  function createDefaultReadSpanProvider(io) {
10017
9982
  const readTextFile = io === void 0 ? void 0 : async (path) => {
@@ -16094,7 +16059,10 @@ function installAgentTools(rootCtx, agent, metrics, config = {}) {
16094
16059
  disposers.push(
16095
16060
  registerNativeToolHiding(rootCtx, agent.ctx, {
16096
16061
  toolNames: registered,
16097
- guidanceToClear: registered.includes("edit") ? [] : ["tool:edit"],
16062
+ // WHY: never empty `tool:edit`: the native `edit` is hidden only while this
16063
+ // WHY: plugin registers its own `edit` brief, and stays visible (with its
16064
+ // WHY: brief) otherwise, so the section is never a stale native leftover.
16065
+ guidanceToClear: [],
16098
16066
  scope: agent
16099
16067
  })
16100
16068
  );
@@ -7,10 +7,10 @@
7
7
  * pi-side guidance (`prompts/*.md`) loaded through `src/prompts.ts`, so the dsh
8
8
  * and pi hosts cannot drift about the tool contract.
9
9
  *
10
- * Injection is STATIC: each section registers its bundled default text once, the
10
+ * Injection is STATIC: each section registers its prompt text once, the
11
11
  * same way the agent-teams plugin registers its constant `systemPrompt` section.
12
12
  * There are no runtime user-override files and no per-step re-resolution — the
13
- * guidance a session sees is exactly what the installed bundle ships, so the
13
+ * guidance a session sees is exactly what the installed package ships, so the
14
14
  * single control point is `prompts/*.md` + a rebuild/upgrade.
15
15
  *
16
16
  * @module dsh-hashline-edit/guidance
@@ -4,10 +4,11 @@
4
4
  * On every `agent/created`, install the hashline tools on the AGENT's
5
5
  * own scope layer so they shadow the preset's built-in `read` for that
6
6
  * agent (nearest layer wins in dsh's tool registry) and unwind automatically
7
- * when the agent is disposed. The native `edit`, `str_replace_editor` and
8
- * native `apply_patch` names are hidden on the same scope once the plugin's own
9
- * replacement registers, so this plugin's `apply_patch` and `edit` tools own
10
- * precise and batch text changes. The host's built-in `write` stays visible and
7
+ * when the agent is disposed. The native `edit`/`str_replace_editor` are hidden
8
+ * only while this plugin's own `edit` registers, and the native `apply_patch`
9
+ * only while this plugin's own `apply_patch` registers — in an edit-only profile
10
+ * the native `apply_patch` is hidden too — so the plugin's own tools own precise
11
+ * and batch text changes; the host's built-in `write` stays visible and
11
12
  * is integrated by the write hook.
12
13
  *
13
14
  * `inject` deliberately lists only `tools` and `systemPrompt`: the read-path
@@ -49,9 +50,12 @@ export interface PluginConfig {
49
50
  */
50
51
  read?: boolean;
51
52
  /**
52
- * Expose the hashline `apply_patch` tool. Defaults to true. With either
53
- * mutation tool on, the native `edit`/`apply_patch`/`str_replace_editor`
54
- * names are hidden for the agent; the host's `write` is never hidden.
53
+ * Expose the hashline `apply_patch` tool. Defaults to true. Registering it
54
+ * hides only the native `apply_patch` (by the same-name probe); the native
55
+ * `edit`/`str_replace_editor` stay visible unless this plugin's `edit` is on.
56
+ * With it off while `edit` is on, the hide layer also denies the native
57
+ * `apply_patch`, so the edit-only profile has no apply_patch surface. The
58
+ * host's `write` is never hidden.
55
59
  */
56
60
  applyPatch?: boolean;
57
61
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-hashline-edit",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
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",
@@ -30,6 +30,7 @@
30
30
  "files": [
31
31
  "lib",
32
32
  "cordis.patch.yml",
33
+ "prompts",
33
34
  "src",
34
35
  "README.md",
35
36
  "LICENSE"
@@ -60,8 +61,6 @@
60
61
  "format:fix": "oxfmt .",
61
62
  "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.dsh.json",
62
63
  "build": "node scripts/build-dsh.mjs",
63
- "prompts:gen": "node scripts/gen-prompts.mjs",
64
- "prompts:check": "node scripts/gen-prompts.mjs --check",
65
64
  "prepublishOnly": "node scripts/build-dsh.mjs && pnpm run typecheck && pnpm run lint && pnpm run test:win",
66
65
  "canon:audit": "node scripts/canon-churn-audit.mjs",
67
66
  "prepack": "node scripts/build-dsh.mjs",
@@ -0,0 +1,10 @@
1
+ - apply_patch: one call = one transaction; batch related changes and split only when an earlier RESULT decides the next.
2
+ - apply_patch: an identity hunk is `@@<anchor>` or `@@<from>-<to>` followed by `+` lines; an empty body deletes every row of the span. Minimal shape: `*** Begin Patch` / `*** Update File: <path>` / `@@<anchor>` / `+<new line>` / `*** End Patch`.
3
+ - apply_patch: an identity anchor is the bare `{{HASH_LEN}}` characters before `│` in a served row — never the whole row, never a line number; syntax is `@@` plus the anchor with no space between them.
4
+ - apply_patch: served beats text — when this session served the file, an identity hunk is REQUIRED, not preferred; a fragment hunk is limited to a file or region this session never served, and a text match never licenses one.
5
+ - apply_patch: anchors in hand mean no re-read — apply the identity hunk to the served rows instead of reading the file again; a rejection already serves the current rows back.
6
+ - apply_patch: change only what the task changes — an identity hunk carries `+` lines for the edited region and no unchanged rows, so a small edit stays a small patch.
7
+ - apply_patch: for a one-line or single-region change to a served file, one identity hunk is the whole call; do not switch to `write` because the file content is already in context.
8
+ - apply_patch: hunks are validated against the pre-call file in order (overlapping ranges reject the batch); a fragment hunk must match exactly once — `E_UNIQUE_MATCH` writes nothing — while a stale or unknown anchor is rejected; both serve the current rows back.
9
+ - apply_patch: a rejection writes nothing; retry from the served `HASH│content` rows without another `read`.
10
+ - apply_patch: success returns fresh anchors for the changed lines; a patch carries only the changed rows, so a new file or an every-line rewrite stays with `write`.
@@ -0,0 +1 @@
1
+ Change an existing file with `apply_patch`; it is the default for every change to an existing file, including a one-line change. `write` is only for a new file or for a rewrite where every line changes; a partial change is never a whole-file replacement. Pass the complete patch as `input`. When this session already served the file — through `read`, `grep`, a `bash` view, or a previous `apply_patch` result — every hunk MUST be an identity hunk on a served row: reuse the bare anchor before `│` (`@@<anchor>` to replace that row, `@@<from>-<to>` to replace a span whose anchors you hold), and add only the changed `+` lines rather than re-emitting rows you are not changing. Anchors already in hand need no re-read: patch them directly instead of calling `read` again. A fragment hunk (`@@` or `@@ <context>` matched by file text) is legal only for a file or region this session never served; if the file was served, a fragment hunk is the wrong tool even when the text matches, because it discards the anchor check that proves you edited the version you actually saw.
@@ -0,0 +1,8 @@
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: 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
+ - 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`).
5
+ - edit: change only what the task changes — one item per intended range, keeping unchanged boundary rows and `HASH│` prefixes out of `text`.
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
+ - 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.
8
+ - edit: `write` is the whole-file path — use `write` to create a new file or replace every line, never `edit`.
@@ -0,0 +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.
@@ -0,0 +1 @@
1
+ Read a UTF-8 text file as hash-anchored `HASH│content` rows. Each anchor is the `edit` identity for that line, and only the bare `{{HASH_LEN}}` characters before `│` are the anchor. Served mode is the default; `mode: "verbatim"` returns plain text with no anchors and no line-budget cap (and does not register anchors for `edit`). Supports `offset`/`limit` paging and `windows` to batch up to 16 disjoint ranges (`offset`/`limit`, or `around_anchor` + `radius` for an anchor already served in this session) in one call. Image, binary, and directory paths are refused (`E_UNSUPPORTED_FILE`).
@@ -0,0 +1,5 @@
1
+ - read: call it only for spans not yet served as `HASH│content` rows in this session; an intercepted shell view (`cat`, `rg`, `Get-Content`, `Select-String`, etc.) or write-hook auto-read that output `HASH│content` rows already served the file for `edit`, whereas raw unanchored stdout is not served.
2
+ - read: batch up to 16 disjoint ranges of a file in ONE call with `windows` — each using `offset`/`limit`, or `around_anchor` plus `radius` around an anchor already served in this session (unserved anchors are omitted with a warning). Read multiple files with parallel `read` calls, one file per call.
3
+ - read: keep requested windows compact (61 lines or fewer) — the tool automatically widens compact windows to their enclosing syntax block (capped at 80 lines for code/Markdown and 40 for plain text, noted `[widened …]`), so do not manually pad `offset`/`limit` margins. Single-page output is also bounded by a byte budget.
4
+ - read: omit `mode` for any file you might later edit (code, configs, READMEs) so rows carry anchors; pass `mode: "verbatim"` only for strictly read-only reference files (e.g., skill files), as `verbatim` is uncapped and records no anchors for `edit`.
5
+ - read: `read` accepts UTF-8 text files only — images, binary files, and directories are refused (`E_UNSUPPORTED_FILE`).
@@ -0,0 +1,3 @@
1
+ - write: read the file before overwriting it; `write` replaces the whole file, so use it for a new file or a rewrite where every line changes.
2
+ - write: a partial change is not a whole-file rewrite even when the whole file is already in context — use `edit` on the served rows instead.
3
+ - write: never paste served `HASH│` rows into the content; a line that reproduces a served row is refused as a served hash echo.
package/src/prompts.ts CHANGED
@@ -1,5 +1,6 @@
1
+ import { readFileSync } from "node:fs";
2
+
1
3
  import { HASH_LEN } from "./hashline/alphabet.js";
2
- import { BUNDLED_PROMPTS } from "./prompts-bundled.js";
3
4
 
4
5
  /**
5
6
  * Resolve template variables in shipped prompt prose. Beyond caller-supplied replacements, the
@@ -16,30 +17,14 @@ function applyReplacements(content: string, replacements?: Record<string, string
16
17
  return out.split("{{HASH_LEN}}").join(String(HASH_LEN));
17
18
  }
18
19
 
19
- /**
20
- * Resolve one prompt path to its bundled body.
21
- *
22
- * WHY a path rather than a bare name: callers have always named the prompt by its `prompts/`
23
- * path, and that argument IS the lookup key, so a typo fails at the call site instead of
24
- * silently serving an empty prompt. Nothing is read from disk — see `prompts-bundled.ts`.
25
- */
26
- function bundled(relativePath: string): string {
27
- const name = relativePath.slice(relativePath.lastIndexOf("/") + 1);
28
- const body = BUNDLED_PROMPTS[name];
29
- if (body === undefined) {
30
- throw new Error(
31
- `unknown bundled prompt: ${relativePath} (bundled: ${Object.keys(BUNDLED_PROMPTS).join(", ")})`,
32
- );
33
- }
34
- return body;
35
- }
36
-
37
20
  export function loadP(relativePath: string, replacements?: Record<string, string>): string {
38
- return applyReplacements(bundled(relativePath).trim(), replacements);
21
+ const content = readFileSync(new URL(relativePath, import.meta.url), "utf-8").trim();
22
+ return applyReplacements(content, replacements);
39
23
  }
40
24
 
41
25
  export function loadGuide(relativePath: string, replacements?: Record<string, string>): string[] {
42
- return applyReplacements(bundled(relativePath), replacements)
26
+ const content = readFileSync(new URL(relativePath, import.meta.url), "utf-8");
27
+ return applyReplacements(content, replacements)
43
28
  .split("\n")
44
29
  .map((line) => line.trim())
45
30
  .filter((line) => line.startsWith("- "))
@@ -1,11 +0,0 @@
1
- /**
2
- * GENERATED FILE — do not edit by hand.
3
- *
4
- * Source of truth: `prompts/*.md`. Regenerate with `node scripts/gen-prompts.mjs`
5
- * (`pnpm run build` runs it first). The prose lives inline so reinstalling the plugin is
6
- * the only way — and the only needed way — to change what the model reads.
7
- *
8
- * @module dsh-hashline-edit/prompts-bundled
9
- */
10
- /** Every shipped prompt body, keyed by its `prompts/<name>.md` basename. */
11
- export declare const BUNDLED_PROMPTS: Readonly<Record<string, string>>;
@@ -1,44 +0,0 @@
1
- /**
2
- * GENERATED FILE — do not edit by hand.
3
- *
4
- * Source of truth: `prompts/*.md`. Regenerate with `node scripts/gen-prompts.mjs`
5
- * (`pnpm run build` runs it first). The prose lives inline so reinstalling the plugin is
6
- * the only way — and the only needed way — to change what the model reads.
7
- *
8
- * @module dsh-hashline-edit/prompts-bundled
9
- */
10
-
11
- /** Every shipped prompt body, keyed by its `prompts/<name>.md` basename. */
12
- export const BUNDLED_PROMPTS: Readonly<Record<string, string>> = {
13
- "apply-patch-guidelines.md": `- apply_patch: one call = one transaction; batch related changes and split only when an earlier RESULT decides the next.
14
- - apply_patch: an identity hunk is \`@@<anchor>\` or \`@@<from>-<to>\` followed by \`+\` lines; an empty body deletes every row of the span. Minimal shape: \`*** Begin Patch\` / \`*** Update File: <path>\` / \`@@<anchor>\` / \`+<new line>\` / \`*** End Patch\`.
15
- - apply_patch: an identity anchor is the bare \`{{HASH_LEN}}\` characters before \`│\` in a served row — never the whole row, never a line number; syntax is \`@@\` plus the anchor with no space between them.
16
- - apply_patch: served beats text — when this session served the file, an identity hunk is REQUIRED, not preferred; a fragment hunk is limited to a file or region this session never served, and a text match never licenses one.
17
- - apply_patch: anchors in hand mean no re-read — apply the identity hunk to the served rows instead of reading the file again; a rejection already serves the current rows back.
18
- - apply_patch: change only what the task changes — an identity hunk carries \`+\` lines for the edited region and no unchanged rows, so a small edit stays a small patch.
19
- - apply_patch: for a one-line or single-region change to a served file, one identity hunk is the whole call; do not switch to \`write\` because the file content is already in context.
20
- - apply_patch: hunks are validated against the pre-call file in order (overlapping ranges reject the batch); a fragment hunk must match exactly once — \`E_UNIQUE_MATCH\` writes nothing — while a stale or unknown anchor is rejected; both serve the current rows back.
21
- - apply_patch: a rejection writes nothing; retry from the served \`HASH│content\` rows without another \`read\`.
22
- - apply_patch: success returns fresh anchors for the changed lines; a patch carries only the changed rows, so a new file or an every-line rewrite stays with \`write\`.`,
23
- "apply-patch.md": `Change an existing file with \`apply_patch\`; it is the default for every change to an existing file, including a one-line change. \`write\` is only for a new file or for a rewrite where every line changes; a partial change is never a whole-file replacement. Pass the complete patch as \`input\`. When this session already served the file — through \`read\`, \`grep\`, a \`bash\` view, or a previous \`apply_patch\` result — every hunk MUST be an identity hunk on a served row: reuse the bare anchor before \`│\` (\`@@<anchor>\` to replace that row, \`@@<from>-<to>\` to replace a span whose anchors you hold), and add only the changed \`+\` lines rather than re-emitting rows you are not changing. Anchors already in hand need no re-read: patch them directly instead of calling \`read\` again. A fragment hunk (\`@@\` or \`@@ <context>\` matched by file text) is legal only for a file or region this session never served; if the file was served, a fragment hunk is the wrong tool even when the text matches, because it discards the anchor check that proves you edited the version you actually saw.`,
24
- "edit-guidelines.md": `- edit: one call = one file and one transaction; N changes in that file are N items in the same call, and a different file is a different call.
25
- - edit: every item carries exactly one payload — \`text\` (literal content; \`""\` deletes the range) or \`text_ref\` (\`mode: "copy"\` or \`"cut"\`); never both, never neither.
26
- - edit: anchors are the bare \`{{HASH_LEN}}\` characters before \`│\` in served output — never the whole row, never a line number.
27
- - edit: both anchors are inclusive; \`at\` is \`in-place\` by default, while \`before\`/\`after\` insert at the boundary and require a single-line resolved target.
28
- - edit: \`text_ref\` copies a served span's bytes; \`"cut"\` also retires the source lines, and \`text_ref.file\` may name another served file as that source.
29
- - edit: anchors already in hand need no re-read — a rejection serves the current rows back, so repair from the \`HASH│content\` rows instead of guessing.
30
- - edit: change only what the task changes — one item per intended range, and unchanged rows stay out of the payload.
31
- - edit: a stale or unknown anchor, an overlapping range, or a payload reproducing served rows in \`general\` mode rejects the whole call and writes nothing; \`mode: "literal"\` declares reproduced rows as intended content.
32
- - edit: \`write\` is the whole-file path — a new file or an every-line rewrite stays with \`write\`, never an edit item.`,
33
- "edit.md": `Change a range of lines in one text file with hash anchors: pass \`file\` plus \`edits\`, one item per change. Each item names two inclusive bare anchors from served rows (\`anchor_from\`, \`anchor_to\`), exactly one payload — \`text\` for the replacement content (\`""\` deletes the range) or \`text_ref\` for a served span (\`mode: "copy"\` re-inserts its bytes, \`"cut"\` also retires them) — and optional \`at\` (\`in-place\` by default, \`before\`/\`after\` for a single-line target). One call edits one file; \`text_ref.file\` may name another served file as the copy/cut source. Anchors are the bare \`{{HASH_LEN}}\` characters before \`│\` in served output. A rejected call writes nothing.`,
34
- "read-guidelines.md": `- read: call it for content the tool has never served you; a bash view or an auto-read already served the file, so \`apply_patch\` can use those rows.
35
- - read: batch several disjoint ranges in ONE call with \`windows\` — an offset/limit range, or \`around_anchor\` plus \`radius\` around a line this session served.
36
- - read: pass \`mode: "verbatim"\` when you will not \`apply_patch\` the file (config, docs, a README, skill files); otherwise omit it so the rows carry anchors.
37
- - read: a window of 61 lines or fewer may widen to its enclosing block; widened rows carry a \`[widened …]\` note. Caps are 80 lines for code/Markdown and 40 for plain text.
38
- - read: read several files with parallel \`read\` calls, one file per call.
39
- - read: PNG/JPG/GIF/WebP files return as an image attachment for multimodal models; binary files and directories are refused.`,
40
- "read.md": `Reads a UTF-8 file as \`HASH│content\` rows in served mode; each row's anchor is the \`apply_patch\` identity anchor for that line, and only the \`{{HASH_LEN}}\` characters before \`│\` are the anchor. Pass \`mode: "verbatim"\` for plain text with no anchors when you will not apply_patch; verbatim is not capped by line budget. Batch disjoint ranges in one call with \`windows\` (offset/limit or \`around_anchor\`).`,
41
- "write-guidelines.md": `- write: the content is the complete file; a partial change stays an \`apply_patch\` identity hunk, even when the whole file is already in context.
42
- - write: never paste served \`HASH│\` rows into the content; a line that reproduces a served row is refused as a served hash echo.`,
43
- "write.md": `Read a file before overwriting it with \`write\`. \`write\` replaces the whole file: use it for a new file, or for a rewrite where every line changes. For a change to part of an existing file, use \`apply_patch\` identity hunks on the served rows instead.`,
44
- };