dsh-hashline-edit 0.4.1 → 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
@@ -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
@@ -1427,6 +1427,10 @@ function hiddenNames(config) {
1427
1427
  names.push(name2);
1428
1428
  }
1429
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
+ }
1430
1434
  for (const name2 of sanitizeHiddenToolNames(config)) {
1431
1435
  if (seen.has(name2)) continue;
1432
1436
  seen.add(name2);
@@ -1910,42 +1914,8 @@ function commandOf(args) {
1910
1914
  return typeof command === "string" && command.length > 0 ? command : void 0;
1911
1915
  }
1912
1916
 
1913
- // src/prompts-bundled.ts
1914
- var BUNDLED_PROMPTS = {
1915
- "apply-patch-guidelines.md": `- apply_patch: one call = one transaction; batch related changes and split only when an earlier RESULT decides the next.
1916
- - 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\`.
1917
- - 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.
1918
- - 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.
1919
- - 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.
1920
- - 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.
1921
- - 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.
1922
- - 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.
1923
- - apply_patch: a rejection writes nothing; retry from the served \`HASH\u2502content\` rows without another \`read\`.
1924
- - 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\`.`,
1925
- "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.`,
1926
- "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.
1927
- - 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.
1928
- - edit: anchors are the bare \`{{HASH_LEN}}\` characters before \`\u2502\` in served output \u2014 never the whole row, never a line number.
1929
- - 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.
1930
- - 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.
1931
- - 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.
1932
- - edit: change only what the task changes \u2014 one item per intended range, and unchanged rows stay out of the payload.
1933
- - 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.
1934
- - edit: \`write\` is the whole-file path \u2014 a new file or an every-line rewrite stays with \`write\`, never an edit item.`,
1935
- "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.`,
1936
- "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.
1937
- - 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.
1938
- - 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.
1939
- - 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.
1940
- - read: read several files with parallel \`read\` calls, one file per call.
1941
- - read: PNG/JPG/GIF/WebP files return as an image attachment for multimodal models; binary files and directories are refused.`,
1942
- "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\`).`,
1943
- "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.
1944
- - write: never paste served \`HASH\u2502\` rows into the content; a line that reproduces a served row is refused as a served hash echo.`,
1945
- "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.`
1946
- };
1947
-
1948
1917
  // src/prompts.ts
1918
+ import { readFileSync } from "node:fs";
1949
1919
  function applyReplacements(content, replacements) {
1950
1920
  let out = content;
1951
1921
  if (replacements) {
@@ -1955,27 +1925,19 @@ function applyReplacements(content, replacements) {
1955
1925
  }
1956
1926
  return out.split("{{HASH_LEN}}").join(String(HASH_LEN));
1957
1927
  }
1958
- function bundled(relativePath2) {
1959
- const name2 = relativePath2.slice(relativePath2.lastIndexOf("/") + 1);
1960
- const body = BUNDLED_PROMPTS[name2];
1961
- if (body === void 0) {
1962
- throw new Error(
1963
- `unknown bundled prompt: ${relativePath2} (bundled: ${Object.keys(BUNDLED_PROMPTS).join(", ")})`
1964
- );
1965
- }
1966
- return body;
1967
- }
1968
1928
  function loadP(relativePath2, replacements) {
1969
- return applyReplacements(bundled(relativePath2).trim(), replacements);
1929
+ const content = readFileSync(new URL(relativePath2, import.meta.url), "utf-8").trim();
1930
+ return applyReplacements(content, replacements);
1970
1931
  }
1971
1932
  function loadGuide(relativePath2, replacements) {
1972
- 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));
1973
1935
  }
1974
1936
 
1975
1937
  // dsh/guidance.ts
1976
1938
  function guidanceText(intro, lines) {
1977
1939
  const bullets = lines.map((line) => `- ${line}`).join("\n");
1978
- return `${intro}
1940
+ return intro.trim() === "" ? bullets : `${intro}
1979
1941
 
1980
1942
  ${bullets}`;
1981
1943
  }
@@ -1984,28 +1946,25 @@ var GUIDANCE_SECTIONS = [
1984
1946
  name: "tool:read",
1985
1947
  defaultOrder: 1100,
1986
1948
  orderName: "TOOL_READ",
1987
- renderDefault: () => guidanceText(loadP("../prompts/read.md"), loadGuide("../prompts/read-guidelines.md"))
1949
+ renderDefault: () => guidanceText("", loadGuide("../prompts/read-guidelines.md"))
1988
1950
  },
1989
1951
  {
1990
1952
  name: "tool:write",
1991
1953
  defaultOrder: 1300,
1992
1954
  orderName: "TOOL_WRITE",
1993
- renderDefault: () => guidanceText(loadP("../prompts/write.md"), loadGuide("../prompts/write-guidelines.md"))
1955
+ renderDefault: () => guidanceText("", loadGuide("../prompts/write-guidelines.md"))
1994
1956
  },
1995
1957
  {
1996
1958
  name: "tool:apply_patch",
1997
1959
  defaultOrder: 1350,
1998
1960
  orderName: "TOOL_APPLY_PATCH",
1999
- renderDefault: () => guidanceText(
2000
- loadP("../prompts/apply-patch.md"),
2001
- loadGuide("../prompts/apply-patch-guidelines.md")
2002
- )
1961
+ renderDefault: () => guidanceText("", loadGuide("../prompts/apply-patch-guidelines.md"))
2003
1962
  },
2004
1963
  {
2005
1964
  name: "tool:edit",
2006
1965
  defaultOrder: 1360,
2007
1966
  orderName: "TOOL_EDIT",
2008
- renderDefault: () => guidanceText(loadP("../prompts/edit.md"), loadGuide("../prompts/edit-guidelines.md"))
1967
+ renderDefault: () => guidanceText("", loadGuide("../prompts/edit-guidelines.md"))
2009
1968
  }
2010
1969
  ];
2011
1970
  var SECTION_BY_NAME = new Map(GUIDANCE_SECTIONS.map((section) => [section.name, section]));
@@ -8419,7 +8378,7 @@ function findEnclosingScope(root, requestedStart, requestedEnd, scopeKinds) {
8419
8378
 
8420
8379
  // src/read-expansion/grammar-cache.ts
8421
8380
  import { createHash } from "node:crypto";
8422
- 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";
8423
8382
  import { dirname as dirname7, join as join8 } from "node:path";
8424
8383
 
8425
8384
  // src/read-expansion/grammar-manifest.ts
@@ -8514,7 +8473,7 @@ function readVerifiedCache(path, expected) {
8514
8473
  if (!existsSync3(path)) return void 0;
8515
8474
  let bytes;
8516
8475
  try {
8517
- bytes = readFileSync(path);
8476
+ bytes = readFileSync2(path);
8518
8477
  } catch {
8519
8478
  discardCachedGrammar(path);
8520
8479
  return void 0;
@@ -9794,7 +9753,7 @@ import {
9794
9753
  constants as constants5,
9795
9754
  existsSync as existsSync4,
9796
9755
  mkdirSync as mkdirSync6,
9797
- readFileSync as readFileSync2,
9756
+ readFileSync as readFileSync3,
9798
9757
  renameSync as renameSync5,
9799
9758
  unlinkSync as unlinkSync2,
9800
9759
  writeFileSync as writeFileSync3
@@ -9866,7 +9825,7 @@ function reasonOf2(error) {
9866
9825
  function readConfigObject(path, onWarn) {
9867
9826
  let raw;
9868
9827
  try {
9869
- raw = readFileSync2(path, "utf-8");
9828
+ raw = readFileSync3(path, "utf-8");
9870
9829
  } catch (error) {
9871
9830
  if (!isMissingFile(error)) onWarn?.(`cannot read config ${path}: ${reasonOf2(error)}`);
9872
9831
  return void 0;
@@ -10017,7 +9976,7 @@ async function publishPluginWrites(deps, requestPaths, ctx, exec) {
10017
9976
 
10018
9977
  // dsh/tools/read.ts
10019
9978
  var READ_TOOL_NAME = "read";
10020
- 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");
10021
9980
  var RENDER_MODES = ["served", "verbatim"];
10022
9981
  function createDefaultReadSpanProvider(io) {
10023
9982
  const readTextFile = io === void 0 ? void 0 : async (path) => {
@@ -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.1",
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
- };