dsh-hashline-edit 0.3.4 → 0.3.5

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.
Files changed (2) hide show
  1. package/lib/index.js +82 -9
  2. package/package.json +1 -1
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}]+$`);
@@ -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,7 +1554,7 @@ 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?.(
1557
+ const disposeGuard = tools?.guard?.(
1543
1558
  (execution) => hidden.has(execution.name) ? nativeWriteDenial(config.toolName, execution.name) : void 0
1544
1559
  );
1545
1560
  if (disposeGuard !== void 0) disposers.push(disposeGuard);
@@ -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,7 +13564,7 @@ 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
13570
  if (switches.read) {
@@ -13550,8 +13583,10 @@ function installAgentTools(rootCtx, agent, metrics, config = {}) {
13550
13583
  }
13551
13584
  function registerApplyPatchTool(rootCtx, agent, deps) {
13552
13585
  try {
13586
+ const agentTools = toolsOfAgent(agent);
13587
+ if (agentTools === void 0) throw new Error("agent tools registry is unavailable");
13553
13588
  const definition = buildApplyPatchTool(deps);
13554
- return { name: definition.name, dispose: agent.ctx.tools.register(definition) };
13589
+ return { name: definition.name, dispose: agentTools.register(definition) };
13555
13590
  } catch (error) {
13556
13591
  warnVia3(
13557
13592
  rootCtx,
@@ -13572,13 +13607,20 @@ function warnVia3(rootCtx, message) {
13572
13607
  var pluginStates = /* @__PURE__ */ new WeakMap();
13573
13608
  function liveAgentsFrom(rootCtx) {
13574
13609
  try {
13575
- const service = rootCtx.get("agents");
13610
+ const service = rootCtx.agents ?? rootCtx.get("agents");
13576
13611
  return typeof service?.list === "function" ? service.list() : [];
13577
13612
  } catch {
13578
13613
  return [];
13579
13614
  }
13580
13615
  }
13581
13616
  function apply(rootCtx, config = {}) {
13617
+ const switches = resolveSwitches(config);
13618
+ if (typeof rootCtx.systemPrompt?.section === "function") {
13619
+ rootCtx.effect(
13620
+ () => registerGuidanceSections(rootCtx, rootCtx, switches),
13621
+ "dsh-hashline-edit: root guidance"
13622
+ );
13623
+ }
13582
13624
  const metrics = createToolMetrics(
13583
13625
  metricSinkFromEnv(process.env, (error) => {
13584
13626
  rootCtx.logger.warn(
@@ -13586,6 +13628,37 @@ function apply(rootCtx, config = {}) {
13586
13628
  );
13587
13629
  })
13588
13630
  );
13631
+ if (typeof rootCtx.tools?.register === "function") {
13632
+ const rootIo = createLocalFileIO();
13633
+ const rootDeps = {
13634
+ io: rootIo,
13635
+ sandbox: new FsSandboxController(rootCtx),
13636
+ coreIo: createCoreReadIo(rootIo),
13637
+ ...metrics === void 0 ? {} : { metrics }
13638
+ };
13639
+ rootCtx.effect(() => {
13640
+ const disposers = [];
13641
+ try {
13642
+ if (switches.read) {
13643
+ disposers.push(rootCtx.tools.register(buildReadTool(rootDeps, {
13644
+ spanProvider: createDefaultReadSpanProvider(rootDeps.coreIo)
13645
+ })));
13646
+ }
13647
+ if (switches.applyPatch) {
13648
+ disposers.push(rootCtx.tools.register(buildApplyPatchTool(rootDeps)));
13649
+ }
13650
+ if (switches.undo) {
13651
+ disposers.push(rootCtx.tools.register(buildUndoTool(rootDeps)));
13652
+ }
13653
+ } catch (error) {
13654
+ disposeReverse(disposers);
13655
+ rootCtx.logger.warn(
13656
+ `dsh-hashline-edit: root tool registration failed: ${error instanceof Error ? error.message : String(error)}`
13657
+ );
13658
+ }
13659
+ return () => disposeReverse(disposers);
13660
+ }, "dsh-hashline-edit: root tools");
13661
+ }
13589
13662
  let state = pluginStates.get(rootCtx);
13590
13663
  if (state === void 0) {
13591
13664
  state = { agents: /* @__PURE__ */ new Set(), installs: /* @__PURE__ */ new Map() };
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.5",
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",