dsh-hashline-edit 0.3.7 → 0.3.9

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
@@ -19,17 +19,17 @@ The semantic core is the [pi-better-edit](https://github.com/Rianico/pi-better-e
19
19
 
20
20
  The anchor width is baked into the build. Set `PI_BETTER_EDIT_ANCHOR_WIDTH` when you build or pack:
21
21
 
22
- - `PI_BETTER_EDIT_ANCHOR_WIDTH=3 pnpm run build` (and `pnpm pack`) produces a fully 3-char artifact.
23
- - unset or `4` builds the 4-char default.
22
+ - unset builds the 3-char default.
23
+ - `PI_BETTER_EDIT_ANCHOR_WIDTH=4 pnpm run build` (and `pnpm pack`) produces a fully 4-char artifact.
24
24
 
25
25
  | Value | Anchor width | Usable space | Anchor generation |
26
26
  | --- | --- | --- | --- |
27
- | unset or `4` (default) | 4 chars | 14,766,336 | 1 |
28
- | `3` | 3 chars | 237,328 | 2 |
27
+ | unset (default) | 3 chars | 237,328 | 2 |
28
+ | `4` | 4 chars | 14,766,336 | 1 |
29
29
 
30
30
  The value is inlined into the bundle at build time (`esbuild define`), so the installed plugin never reads an environment variable at runtime — a 3-char build stays 3-char. The persisted store is keyed by the anchor generation, so changing the build width is a hard cache miss (served rows are simply re-read), never a cross-width hit. Width 4 keeps generation 1, so existing stores keep working unchanged.
31
31
 
32
- Measured on the DeepSeek-V4.1 tokenizer, a 3-char anchor averages ~2.3 tokens and a 4-char anchor ~3.0 tokens per served line, and neither collapses to one token (see [ADR-0020](docs/adr/0020-configurable-anchor-width-3-4.md)). The default stays 4 to preserve the existing persisted contract; build with `PI_BETTER_EDIT_ANCHOR_WIDTH=3` to ship 3-char.
32
+ Measured on the DeepSeek-V4.1 tokenizer, a 3-char anchor averages ~2.3 tokens and a 4-char anchor ~3.0 tokens per served line, and neither collapses to one token (see [ADR-0020](docs/adr/0020-configurable-anchor-width-3-4.md)). The default is 3; build with `PI_BETTER_EDIT_ANCHOR_WIDTH=4` to ship the 4-char artifact, whose generation-1 store keeps existing rows valid.
33
33
 
34
34
  ## Install
35
35
 
@@ -55,7 +55,7 @@ pnpm pack
55
55
  dsh plugin add ./dsh-hashline-edit-0.2.1.tgz
56
56
  ```
57
57
 
58
- The bundle ships `lib/index.js` plus `lib/types/**`; `prompts/` must sit next to `lib/` in the installed package (it is in `files`). Guidance override files are materialized under `<DSH_HOME>/plugins/dsh-hashline-edit/guidance/` and are shared between profiles.
58
+ 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.
59
59
 
60
60
  ## The anchored model
61
61
 
package/lib/index.js CHANGED
@@ -48,7 +48,7 @@ import {
48
48
  import { dirname as dirname2, join as join4, parse, resolve, sep } from "node:path";
49
49
 
50
50
  // src/hashline/alphabet.ts
51
- var HASH_LEN = true ? 4 : resolveAnchorWidth(process.env);
51
+ var HASH_LEN = true ? 3 : resolveAnchorWidth(process.env);
52
52
  var ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
53
53
  var ALPHA_SAFE = ALPHA.replace(/-/g, "\\-");
54
54
  var ALPHA_RE = new RegExp(`^[${ALPHA_SAFE}]+$`);
@@ -1917,6 +1917,12 @@ var GUIDANCE_SECTIONS2 = [
1917
1917
  orderName: "TOOL_READ",
1918
1918
  renderDefault: () => guidanceText(loadP("../prompts/read.md"), loadGuide("../prompts/read-guidelines.md"))
1919
1919
  },
1920
+ {
1921
+ name: "tool:write",
1922
+ defaultOrder: 1300,
1923
+ orderName: "TOOL_WRITE",
1924
+ renderDefault: () => guidanceText(loadP("../prompts/write.md"), loadGuide("../prompts/write-guidelines.md"))
1925
+ },
1920
1926
  {
1921
1927
  name: "tool:apply_patch",
1922
1928
  defaultOrder: 1350,
@@ -1961,10 +1967,23 @@ function orderResolver(registry) {
1961
1967
  function sectionEnabled(name2, toggles) {
1962
1968
  if (toggles === void 0) return true;
1963
1969
  if (name2 === "tool:read") return toggles.read;
1970
+ if (name2 === "tool:write") return toggles.applyPatch;
1964
1971
  if (name2 === "tool:apply_patch") return toggles.applyPatch;
1965
1972
  if (name2 === "tool:undo_last_edit") return toggles.undo;
1966
1973
  return true;
1967
1974
  }
1975
+ function toolVisible(agentCtx, name2) {
1976
+ const candidate = agentCtx.tools;
1977
+ if (candidate === void 0 || typeof candidate.get !== "function") return void 0;
1978
+ try {
1979
+ return candidate.get(name2) !== void 0;
1980
+ } catch {
1981
+ return void 0;
1982
+ }
1983
+ }
1984
+ function sectionText(section, agentCtx) {
1985
+ return section.name === "tool:write" && toolVisible(agentCtx, "write") === false ? "" : section.renderDefault();
1986
+ }
1968
1987
  function registerGuidanceSections(rootCtx, agentCtx, enabled) {
1969
1988
  const registry = registryFor(agentCtx) ?? registryFor(rootCtx);
1970
1989
  if (registry === void 0) {
@@ -1981,7 +2000,7 @@ function registerGuidanceSections(rootCtx, agentCtx, enabled) {
1981
2000
  registry.section({
1982
2001
  name: section.name,
1983
2002
  order: orderFor(section),
1984
- text: section.renderDefault()
2003
+ text: sectionText(section, agentCtx)
1985
2004
  })
1986
2005
  );
1987
2006
  } catch (error) {
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * Hashline guidance sections for the dsh host layer.
3
3
  *
4
- * Three prompt sections are owned here — `tool:read`, `tool:apply_patch` and
5
- * `tool:undo_last_edit` — because the hashline tools shadow the preset's
4
+ * Four prompt sections are owned here — `tool:read`, `tool:write`,
5
+ * `tool:apply_patch` and `tool:undo_last_edit` — because the hashline tools
6
+ * shadow the preset's built-ins and must bring their own brief.
6
7
  * built-ins and must bring their own brief. The compiled default text IS the
7
8
  * pi-side guidance (`prompts/*.md`) loaded through `src/prompts.ts`, so the dsh
8
9
  * and pi hosts cannot drift about the tool contract.
@@ -23,11 +24,11 @@ export interface GuidanceSection {
23
24
  /** Order used when the harness registry names no slot for this section. */
24
25
  readonly defaultOrder: number;
25
26
  /** The `systemPrompt.getSectionOrder` slot this section shadows, when one exists. */
26
- readonly orderName?: "TOOL_READ" | "TOOL_EDIT" | "TOOL_APPLY_PATCH";
27
+ readonly orderName?: "TOOL_READ" | "TOOL_WRITE" | "TOOL_EDIT" | "TOOL_APPLY_PATCH";
27
28
  /** The compiled default text. */
28
29
  renderDefault(): string;
29
30
  }
30
- /** The three sections, in default-order sequence. */
31
+ /** The four sections, in default-order sequence. */
31
32
  export declare const GUIDANCE_SECTIONS: readonly GuidanceSection[];
32
33
  /** Render the compiled default text for one section. */
33
34
  export declare function renderSectionDefault(name: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-hashline-edit",
3
- "version": "0.3.7",
3
+ "version": "0.3.9",
4
4
  "description": "Hash-anchored read/apply_patch 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 is the only file-mutation entry point and commits one patch batch per transaction. Undo persists across restarts.",
5
5
  "keywords": [
6
6
  "anchors",
@@ -1,5 +1,7 @@
1
1
  - apply_patch: one call = one transaction; batch related changes and split only when an earlier RESULT decides the next.
2
- - apply_patch: prefer identity hunks that name served `HASH│` anchors; a fragment hunk is only for targets the session never served.
2
+ - apply_patch: an identity anchor is the bare `{{HASH_LEN}}` characters before `│` in a served row — never the whole row, never a line number.
3
+ - apply_patch: prefer identity hunks that name served `HASH│` anchors; a fragment hunk is only for text this session never served.
4
+ - 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.
3
5
  - apply_patch: hunks are validated against the pre-call file in order (overlapping ranges reject the batch); a fragment hunk must match exactly once — add context to disambiguate, never guess — while identity hunks target served rows and a stale or unknown anchor is rejected; both serve the current rows back.
4
6
  - apply_patch: a rejection writes nothing; retry from the served `HASH│content` rows without another `read`.
5
- - apply_patch: success returns fresh anchors for changed lines; whole-file replacement is one identity hunk over every served line.
7
+ - apply_patch: success returns fresh anchors for the changed lines; a patch carries only the changed rows, so a whole-file rewrite stays with `write`.
@@ -1 +1 @@
1
- Create, update, delete, move, copy, or cut UTF-8 text files with a single transactional patch; prefer it over multiple single-file edits when a change spans files or separated regions. Pass the complete patch as `input`. Prefer identity hunks that target served `HASH│` anchors (`@@<anchor>`) over fragment hunks matched by file text; use a fragment hunk only where no served row covers the change.
1
+ Change, create, delete, move, copy or cut UTF-8 text files with a single transactional patch; this is the default for every change to an existing file, including a one-line change, and `write` is only for a new file or a whole-file rewrite. Pass the complete patch as `input`. Prefer identity hunks that target served `HASH│` anchors (`@@<anchor>`) over fragment hunks matched by file text; prefer a fragment hunk only for text this session never served.
package/prompts/read.md CHANGED
@@ -1 +1 @@
1
- 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. 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`).
1
+ 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`).
@@ -0,0 +1,2 @@
1
+ - 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.
2
+ - write: never paste served `HASH│` rows into the content; a line that reproduces a served row is refused as a served hash echo.
@@ -0,0 +1 @@
1
+ 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.
@@ -1,5 +1,6 @@
1
1
  - apply_patch:一次调用 = 一个事务;把相关改动成批处理,只有当先前的结果决定下一步时才拆分。
2
- - apply_patch:优先使用指向已服务 `HASH│` 锚点的身份 hunk;片段 hunk 仅用于本会话从未服务过的目标。
2
+ - apply_patch:身份锚点是已服务行中 `│` 之前的 {{HASH_LEN}} 个字符——不是整行,也不是行号。
3
+ - apply_patch:对已服务文件的单行或单区域改动,一个身份 hunk 就是整次调用;不要因为文件内容已在上下文里就改用 `write`。
3
4
  - apply_patch:各 hunk 按顺序针对调用前的文件校验(重叠范围会拒绝整批);片段 hunk 必须恰好匹配一次——补充上下文以消歧,绝不猜测——身份 hunk 定位已服务的行,陈旧或未知锚点会被拒绝;两者都会回送当前行。
4
5
  - apply_patch:拒绝时不写入任何内容;从回送的 `HASH│content` 行重试,无需再次 `read`。
5
- - apply_patch:成功时返回改动行的新锚点;整文件替换是用一个身份 hunk 覆盖每一行已服务的行。
6
+ - apply_patch:成功时返回改动行的新锚点;补丁只携带改动的行,整文件重写留给 `write`。
@@ -1 +1 @@
1
- 用单个事务补丁创建、更新、删除、移动、复制或剪切 UTF-8 文本文件;当改动跨多个文件或分散区域时,优先于多次单文件编辑。把完整补丁作为 `input` 传入。优先使用指向已服务 `HASH│` 锚点的身份 hunk(`@@<anchor>`),而不是按文件文本匹配的片段 hunk;仅当改动处没有已服务的行时才用片段 hunk。
1
+ 用单个事务补丁修改、创建、删除、移动、复制或剪切 UTF-8 文本文件。对已有文件的每一处改动都默认用它,包括只改一行;`write` 只用于新建文件或整文件重写。把完整补丁作为 `input` 传入。优先使用指向已服务 `HASH│` 锚点的身份 hunk(`@@<anchor>`),而不是按文件文本匹配的片段 hunk;片段 hunk 仅用于本会话从未服务过的文本。
@@ -0,0 +1,2 @@
1
+ - write:内容必须是完整文件;局部改动应使用已服务行上的 `apply_patch` 身份 hunk,即使整份文件已在上下文中。
2
+ - write:不要把已服务的 `HASH│` 行粘进内容;复现已服务行的提交会作为已服务行回显被拒绝。
@@ -0,0 +1 @@
1
+ 用 `write` 覆盖文件前先读取它。`write` 替换整个文件:用于新建文件,或每一行都改变的重写。要改已有文件的一部分,改用已服务行上的 `apply_patch` 身份 hunk。