dsh-hashline-edit 0.3.4 → 0.3.6

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
@@ -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 ? 3 : resolveAnchorWidth(process.env);
51
+ var HASH_LEN = true ? 4 : 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}]+$`);
@@ -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;
@@ -1484,6 +1484,20 @@ function skipPythonMember(lines, start) {
1484
1484
  while (index < lines.length && /^ {8,}\S/u.test(lines[index] ?? "")) index += 1;
1485
1485
  return index;
1486
1486
  }
1487
+ function toolsOfContext(context) {
1488
+ const direct = context?.tools;
1489
+ if (direct !== void 0 && (typeof direct.restrict === "function" || typeof direct.guard === "function" || typeof direct.get === "function")) {
1490
+ return direct;
1491
+ }
1492
+ try {
1493
+ const viaGet = context?.get?.("tools");
1494
+ if (viaGet !== void 0 && (typeof viaGet.restrict === "function" || typeof viaGet.guard === "function" || typeof viaGet.get === "function")) {
1495
+ return viaGet;
1496
+ }
1497
+ } catch {
1498
+ }
1499
+ return void 0;
1500
+ }
1487
1501
  function warn(rootCtx, message) {
1488
1502
  try {
1489
1503
  rootCtx.logger?.warn?.(`dsh-hashline-edit: ${message}`);
@@ -1493,7 +1507,7 @@ function warn(rootCtx, message) {
1493
1507
  function toolExists(rootCtx, agentCtx, name2, scope) {
1494
1508
  const visible = (context) => {
1495
1509
  try {
1496
- const tools = context.tools;
1510
+ const tools = toolsOfContext(context);
1497
1511
  if (typeof tools?.get !== "function") return false;
1498
1512
  return (scope === void 0 ? tools.get(name2) : tools.get(name2, scope)) !== void 0;
1499
1513
  } catch {
@@ -1506,6 +1520,7 @@ function registerNativeToolHiding(rootCtx, agentCtx, config) {
1506
1520
  if (!hideLayerEnabled(config)) return () => {
1507
1521
  };
1508
1522
  const agent = agentCtx;
1523
+ const tools = toolsOfContext(agent);
1509
1524
  const configured = hiddenNames(config);
1510
1525
  const hidden = new Set(configured);
1511
1526
  const restrictable = new Set(
@@ -1517,7 +1532,7 @@ function registerNativeToolHiding(rootCtx, agentCtx, config) {
1517
1532
  const attemptRestrict = (names) => {
1518
1533
  if (names.length === 0) return void 0;
1519
1534
  try {
1520
- const dispose2 = agent.tools?.restrict?.({ deny: [...names] });
1535
+ const dispose2 = tools?.restrict?.({ deny: [...names] });
1521
1536
  return dispose2 === void 0 ? void 0 : dispose2;
1522
1537
  } catch (error) {
1523
1538
  restrictError = error;
@@ -1539,8 +1554,8 @@ function registerNativeToolHiding(rootCtx, agentCtx, config) {
1539
1554
  return result;
1540
1555
  });
1541
1556
  if (disposeAssemble !== void 0) disposers.push(disposeAssemble);
1542
- const disposeGuard = agent.tools?.guard?.(
1543
- (execution) => hidden.has(execution.name) ? nativeWriteDenial(config.toolName, execution.name) : void 0
1557
+ const disposeGuard = tools?.guard?.(
1558
+ (execution) => hidden.has(execution.name) ? nativeEditorDenial(config.toolName, execution.name) : void 0
1544
1559
  );
1545
1560
  if (disposeGuard !== void 0) disposers.push(disposeGuard);
1546
1561
  return () => {
@@ -13471,7 +13486,7 @@ function registerWriteHook(rootCtx, agentCtx, io, observations) {
13471
13486
 
13472
13487
  // dsh/index.ts
13473
13488
  var name = "dsh-hashline-edit";
13474
- var inject = ["tools", "systemPrompt"];
13489
+ var inject = ["agents", "tools", "systemPrompt"];
13475
13490
  var Config = Schema.object({
13476
13491
  read: Schema.boolean().default(true).volatile(),
13477
13492
  applyPatch: Schema.boolean().default(true).volatile(),
@@ -13497,9 +13512,27 @@ function resolveSwitches(config = {}) {
13497
13512
  undo: switchValue(fields.undo, false)
13498
13513
  };
13499
13514
  }
13515
+ function toolsOfAgent(agent) {
13516
+ const direct = agent.ctx.tools;
13517
+ if (direct !== void 0 && typeof direct.register === "function") {
13518
+ return direct;
13519
+ }
13520
+ try {
13521
+ const viaGet = agent.ctx.get?.("tools");
13522
+ if (viaGet !== void 0 && typeof viaGet.register === "function") {
13523
+ return viaGet;
13524
+ }
13525
+ } catch {
13526
+ }
13527
+ return void 0;
13528
+ }
13500
13529
  function installAgentTools(rootCtx, agent, metrics, config = {}) {
13501
13530
  const switches = resolveSwitches(config);
13502
13531
  return agent.ctx.effect(() => {
13532
+ const agentTools = toolsOfAgent(agent);
13533
+ if (agentTools === void 0) {
13534
+ throw new Error("agent tools registry is unavailable; cannot register hashline tools");
13535
+ }
13503
13536
  const io = createLocalFileIO();
13504
13537
  const sandbox = new FsSandboxController(rootCtx);
13505
13538
  const fsService = rootCtx.get("fs");
@@ -13516,7 +13549,7 @@ function installAgentTools(rootCtx, agent, metrics, config = {}) {
13516
13549
  try {
13517
13550
  if (switches.read) {
13518
13551
  const spanProvider = createDefaultReadSpanProvider(coreIo);
13519
- disposers.push(agent.ctx.tools.register(buildReadTool(deps, { spanProvider })));
13552
+ disposers.push(agentTools.register(buildReadTool(deps, { spanProvider })));
13520
13553
  }
13521
13554
  if (switches.applyPatch) {
13522
13555
  const applyPatch = registerApplyPatchTool(rootCtx, agent, deps);
@@ -13531,11 +13564,13 @@ function installAgentTools(rootCtx, agent, metrics, config = {}) {
13531
13564
  }
13532
13565
  }
13533
13566
  if (switches.undo) {
13534
- disposers.push(agent.ctx.tools.register(buildUndoTool(deps)));
13567
+ disposers.push(agentTools.register(buildUndoTool(deps)));
13535
13568
  }
13536
13569
  disposers.push(registerGuidanceSections(rootCtx, agent.ctx, switches));
13537
- if (switches.read) {
13570
+ if (switches.read || switches.applyPatch) {
13538
13571
  disposers.push(registerWriteHook(rootCtx, agent.ctx, io, bridge?.observations));
13572
+ }
13573
+ if (switches.read) {
13539
13574
  disposers.push(registerShellHook(rootCtx, agent.ctx, deps));
13540
13575
  }
13541
13576
  disposers.push(registerToolObserver(agent.ctx, metrics));
@@ -13550,8 +13585,10 @@ function installAgentTools(rootCtx, agent, metrics, config = {}) {
13550
13585
  }
13551
13586
  function registerApplyPatchTool(rootCtx, agent, deps) {
13552
13587
  try {
13588
+ const agentTools = toolsOfAgent(agent);
13589
+ if (agentTools === void 0) throw new Error("agent tools registry is unavailable");
13553
13590
  const definition = buildApplyPatchTool(deps);
13554
- return { name: definition.name, dispose: agent.ctx.tools.register(definition) };
13591
+ return { name: definition.name, dispose: agentTools.register(definition) };
13555
13592
  } catch (error) {
13556
13593
  warnVia3(
13557
13594
  rootCtx,
@@ -13572,13 +13609,20 @@ function warnVia3(rootCtx, message) {
13572
13609
  var pluginStates = /* @__PURE__ */ new WeakMap();
13573
13610
  function liveAgentsFrom(rootCtx) {
13574
13611
  try {
13575
- const service = rootCtx.get("agents");
13612
+ const service = rootCtx.agents ?? rootCtx.get("agents");
13576
13613
  return typeof service?.list === "function" ? service.list() : [];
13577
13614
  } catch {
13578
13615
  return [];
13579
13616
  }
13580
13617
  }
13581
13618
  function apply(rootCtx, config = {}) {
13619
+ const switches = resolveSwitches(config);
13620
+ if (typeof rootCtx.systemPrompt?.section === "function") {
13621
+ rootCtx.effect(
13622
+ () => registerGuidanceSections(rootCtx, rootCtx, switches),
13623
+ "dsh-hashline-edit: root guidance"
13624
+ );
13625
+ }
13582
13626
  const metrics = createToolMetrics(
13583
13627
  metricSinkFromEnv(process.env, (error) => {
13584
13628
  rootCtx.logger.warn(
@@ -13586,6 +13630,41 @@ function apply(rootCtx, config = {}) {
13586
13630
  );
13587
13631
  })
13588
13632
  );
13633
+ if (typeof rootCtx.tools?.register === "function") {
13634
+ const rootIo = createLocalFileIO();
13635
+ const rootDeps = {
13636
+ io: rootIo,
13637
+ sandbox: new FsSandboxController(rootCtx),
13638
+ coreIo: createCoreReadIo(rootIo),
13639
+ ...metrics === void 0 ? {} : { metrics }
13640
+ };
13641
+ rootCtx.effect(() => {
13642
+ const disposers = [];
13643
+ try {
13644
+ if (switches.read) {
13645
+ disposers.push(
13646
+ rootCtx.tools.register(
13647
+ buildReadTool(rootDeps, {
13648
+ spanProvider: createDefaultReadSpanProvider(rootDeps.coreIo)
13649
+ })
13650
+ )
13651
+ );
13652
+ }
13653
+ if (switches.applyPatch) {
13654
+ disposers.push(rootCtx.tools.register(buildApplyPatchTool(rootDeps)));
13655
+ }
13656
+ if (switches.undo) {
13657
+ disposers.push(rootCtx.tools.register(buildUndoTool(rootDeps)));
13658
+ }
13659
+ } catch (error) {
13660
+ disposeReverse(disposers);
13661
+ rootCtx.logger.warn(
13662
+ `dsh-hashline-edit: root tool registration failed: ${error instanceof Error ? error.message : String(error)}`
13663
+ );
13664
+ }
13665
+ return () => disposeReverse(disposers);
13666
+ }, "dsh-hashline-edit: root tools");
13667
+ }
13589
13668
  let state = pluginStates.get(rootCtx);
13590
13669
  if (state === void 0) {
13591
13670
  state = { agents: /* @__PURE__ */ new Set(), installs: /* @__PURE__ */ new Map() };
@@ -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.4",
3
+ "version": "0.3.6",
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",