dsh-hashline-edit 0.3.5 → 0.3.7

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, registers `apply_patch` as the only file-mutation entry point, and adds `undo_last_edit`. The native `write`/`edit`/`str_replace_editor` 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. An `apply_patch` hunk either names served anchors or matches file content; the model never re-types existing code. Anchors for unchanged lines stay stable across edits, and every successful `apply_patch` call 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, registers `apply_patch` for precise and batch text changes, and adds `undo_last_edit`. The host's built-in `write` stays visible and is integrated by the write hook; the native `edit`/`str_replace_editor` 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. An `apply_patch` hunk either names served anchors or matches file content; the model never re-types existing code. Anchors for unchanged lines stay stable across edits, and every successful `apply_patch` call 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
 
@@ -107,7 +107,8 @@ read({
107
107
 
108
108
  ### `apply_patch`
109
109
 
110
- The only file-mutation entry point. One call carries one Codex patch document and commits the whole
110
+ The precise and batch file-mutation entry point; the host's built-in `write` stays
111
+ available for whole-file rewrites. One call carries one Codex patch document and commits the whole
111
112
  batch as one correlated transaction (pre-mirror, undo rows, deterministic member order, all-or-nothing
112
113
  rollback, then per-file store commits).
113
114
 
package/lib/index.js CHANGED
@@ -1376,8 +1376,8 @@ function assertRange(offset, length) {
1376
1376
  }
1377
1377
 
1378
1378
  // dsh/hide.ts
1379
- var NATIVE_WRITE_TOOLS = ["write", "edit", "str_replace_editor"];
1380
- var GUIDANCE_SECTIONS = /* @__PURE__ */ new Set(["tool:write", "tool:edit"]);
1379
+ var NATIVE_EDITOR_TOOLS = ["edit", "str_replace_editor"];
1380
+ var GUIDANCE_SECTIONS = /* @__PURE__ */ new Set(["tool:edit"]);
1381
1381
  function readBooleanSource(value, fallback) {
1382
1382
  if (typeof value === "boolean") return value;
1383
1383
  if (typeof value === "function") {
@@ -1404,7 +1404,7 @@ function sanitizeHiddenToolNames(config) {
1404
1404
  return names;
1405
1405
  }
1406
1406
  function hiddenNames(config) {
1407
- const names = readBooleanSource(config.hideNativeWriteTools, true) ? [...NATIVE_WRITE_TOOLS] : [];
1407
+ const names = readBooleanSource(config.hideNativeWriteTools, true) ? [...NATIVE_EDITOR_TOOLS] : [];
1408
1408
  const seen = new Set(names);
1409
1409
  for (const name2 of sanitizeHiddenToolNames(config)) {
1410
1410
  if (!seen.has(name2)) {
@@ -1414,8 +1414,8 @@ function hiddenNames(config) {
1414
1414
  }
1415
1415
  return names.filter((name2) => name2 !== config.toolName);
1416
1416
  }
1417
- function nativeWriteDenial(toolName, name2) {
1418
- return `\`${name2}\` is disabled in this profile: precise and batch text changes go through \`${toolName}\` operations. Collect every planned file change into one call. Reading stays with \`read\`, \`glob\`, and \`grep\`; whole-file replacement is one \`*** Update File:\` identity hunk spanning every served line.`;
1417
+ function nativeEditorDenial(toolName, name2) {
1418
+ return `\`${name2}\` is disabled in this profile: precise and batch text changes go through \`${toolName}\` operations. Collect every planned file change into one call. Reading stays with \`read\`, \`glob\`, and \`grep\`; whole-file replacement is one \`*** Update File:\` identity hunk spanning every served line; the built-in \`write\` remains available for whole-file rewrites.`;
1419
1419
  }
1420
1420
  function transformAssembly(assembly, hidden) {
1421
1421
  if (hidden.size === 0) return;
@@ -1555,7 +1555,7 @@ function registerNativeToolHiding(rootCtx, agentCtx, config) {
1555
1555
  });
1556
1556
  if (disposeAssemble !== void 0) disposers.push(disposeAssemble);
1557
1557
  const disposeGuard = tools?.guard?.(
1558
- (execution) => hidden.has(execution.name) ? nativeWriteDenial(config.toolName, execution.name) : void 0
1558
+ (execution) => hidden.has(execution.name) ? nativeEditorDenial(config.toolName, execution.name) : void 0
1559
1559
  );
1560
1560
  if (disposeGuard !== void 0) disposers.push(disposeGuard);
1561
1561
  return () => {
@@ -13567,8 +13567,10 @@ function installAgentTools(rootCtx, agent, metrics, config = {}) {
13567
13567
  disposers.push(agentTools.register(buildUndoTool(deps)));
13568
13568
  }
13569
13569
  disposers.push(registerGuidanceSections(rootCtx, agent.ctx, switches));
13570
- if (switches.read) {
13570
+ if (switches.read || switches.applyPatch) {
13571
13571
  disposers.push(registerWriteHook(rootCtx, agent.ctx, io, bridge?.observations));
13572
+ }
13573
+ if (switches.read) {
13572
13574
  disposers.push(registerShellHook(rootCtx, agent.ctx, deps));
13573
13575
  }
13574
13576
  disposers.push(registerToolObserver(agent.ctx, metrics));
@@ -13640,9 +13642,13 @@ function apply(rootCtx, config = {}) {
13640
13642
  const disposers = [];
13641
13643
  try {
13642
13644
  if (switches.read) {
13643
- disposers.push(rootCtx.tools.register(buildReadTool(rootDeps, {
13644
- spanProvider: createDefaultReadSpanProvider(rootDeps.coreIo)
13645
- })));
13645
+ disposers.push(
13646
+ rootCtx.tools.register(
13647
+ buildReadTool(rootDeps, {
13648
+ spanProvider: createDefaultReadSpanProvider(rootDeps.coreIo)
13649
+ })
13650
+ )
13651
+ );
13646
13652
  }
13647
13653
  if (switches.applyPatch) {
13648
13654
  disposers.push(rootCtx.tools.register(buildApplyPatchTool(rootDeps)));
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Hide the native file-mutation tools so every text change goes through
3
- * `apply_patch` — the one mutation entry point of the v4 surface.
2
+ * Hide the native editor tools so precise and batch text changes go through
3
+ * `apply_patch`; the host's built-in `write` stays visible for whole-file rewrites.
4
4
  *
5
5
  * DSH 0.2.2-rc.1 owns tool declarations in the tool registry, not in the
6
6
  * `system-prompt/assemble` waterfall: the waterfall receives sections, contexts
@@ -20,15 +20,16 @@
20
20
  * 3. `tools.guard` is the monotonic execution backstop for a stale schema or
21
21
  * any residual binding.
22
22
  *
23
- * `write` is hidden with `edit`/`str_replace_editor`. A whole-file replacement
24
- * is one `*** Update File:` identity hunk spanning every served line with `+`
25
- * lines for the new content, so no native mutation tool has to stay visible.
23
+ * Only `edit`/`str_replace_editor` are hidden. `apply_patch` still owns
24
+ * whole-file replacement as one `*** Update File:` identity hunk spanning every
25
+ * served line with `+` lines for the new content; the built-in `write` remains
26
+ * the profile's own whole-file rewrite path, integrated by `write-hook.ts`.
26
27
  * The native `apply_patch` name is also denied in the inherited/preset layer
27
28
  * when it exists; the plugin's own scoped registration shadows it otherwise.
28
29
  *
29
30
  * The layer is installed only when `apply_patch` actually registered: hiding
30
- * the native mutation tools while owning no replacement would leave the
31
- * profile with no way to change a file.
31
+ * the native editors without the replacement would leave the profile with no
32
+ * precise-edit entry point.
32
33
  *
33
34
  * @module dsh-hashline-edit/hide
34
35
  */
@@ -38,7 +39,7 @@ type BooleanSource = boolean | (() => boolean);
38
39
  export interface NativeHideConfig {
39
40
  /** The registered replacement tool name, protected from `hiddenToolNames`. */
40
41
  readonly toolName: string;
41
- /** Hide `write`/`edit`/`str_replace_editor`; defaults to true. */
42
+ /** Hide `edit`/`str_replace_editor`; defaults to true. The host's `write` stays visible. */
42
43
  readonly hideNativeWriteTools?: BooleanSource;
43
44
  /** Extra global tool names to hide alongside the native set. */
44
45
  readonly hiddenToolNames?: readonly string[];
@@ -4,10 +4,10 @@
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 `write`, `edit` and
8
- * `str_replace_editor` schemas are hidden on the same scope so `apply_patch`
9
- * is the only file-mutation entry point; the write hook still integrates a
10
- * built-in `write` when a profile chooses to keep it visible.
7
+ * when the agent is disposed. The native `edit` and `str_replace_editor`
8
+ * schemas are hidden on the same scope, so `apply_patch` owns precise and
9
+ * batch text changes. The host's built-in `write` stays visible and is
10
+ * integrated by the write hook.
11
11
  *
12
12
  * `inject` deliberately lists only `tools` and `systemPrompt`: the read-path
13
13
  * `ctx.fs` bridge is optional and resolved with `ctx.get`, so a minimal
@@ -49,8 +49,8 @@ export interface PluginConfig {
49
49
  read?: boolean;
50
50
  /**
51
51
  * Expose the hashline `apply_patch` tool and hide the native
52
- * `edit`/`write`/`apply_patch`/`str_replace_editor` tools. Defaults to true;
53
- * off keeps every native mutation tool.
52
+ * `edit`/`apply_patch`/`str_replace_editor` tools. Defaults to true;
53
+ * off keeps every native editor tool. The host's `write` is never hidden.
54
54
  */
55
55
  applyPatch?: boolean;
56
56
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-hashline-edit",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
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,4 +1,5 @@
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
3
  - 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.
3
4
  - apply_patch: a rejection writes nothing; retry from the served `HASH│content` rows without another `read`.
4
5
  - apply_patch: success returns fresh anchors for changed lines; whole-file replacement is one identity hunk over every served line.
@@ -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`.
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,4 +1,5 @@
1
1
  - apply_patch:一次调用 = 一个事务;把相关改动成批处理,只有当先前的结果决定下一步时才拆分。
2
+ - apply_patch:优先使用指向已服务 `HASH│` 锚点的身份 hunk;片段 hunk 仅用于本会话从未服务过的目标。
2
3
  - apply_patch:各 hunk 按顺序针对调用前的文件校验(重叠范围会拒绝整批);片段 hunk 必须恰好匹配一次——补充上下文以消歧,绝不猜测——身份 hunk 定位已服务的行,陈旧或未知锚点会被拒绝;两者都会回送当前行。
3
4
  - apply_patch:拒绝时不写入任何内容;从回送的 `HASH│content` 行重试,无需再次 `read`。
4
5
  - apply_patch:成功时返回改动行的新锚点;整文件替换是用一个身份 hunk 覆盖每一行已服务的行。
@@ -1 +1 @@
1
- 用单个事务补丁创建、更新、删除、移动、复制或剪切 UTF-8 文本文件;当改动跨多个文件或分散区域时,优先于多次单文件编辑。把完整补丁作为 `input` 传入。
1
+ 用单个事务补丁创建、更新、删除、移动、复制或剪切 UTF-8 文本文件;当改动跨多个文件或分散区域时,优先于多次单文件编辑。把完整补丁作为 `input` 传入。优先使用指向已服务 `HASH│` 锚点的身份 hunk(`@@<anchor>`),而不是按文件文本匹配的片段 hunk;仅当改动处没有已服务的行时才用片段 hunk。