@discovery-tree/runner 0.1.12 → 0.1.13

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/dist/cli.js +84 -13
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -61,6 +61,7 @@ var RUNNER_SESSION_ID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-
61
61
  function isRunnerSessionId(value) {
62
62
  return typeof value === "string" && RUNNER_SESSION_ID_RE.test(value);
63
63
  }
64
+ var RUNNER_DELIVERABLE_FILE = "DELIVERABLE.md";
64
65
  var RUNNER_COMPLETION_MAX_TEXT = 2e5;
65
66
 
66
67
  // ../contracts/src/agent-permissions.ts
@@ -109,7 +110,7 @@ function toolGrantRepositoryKey(url) {
109
110
  }
110
111
 
111
112
  // src/version.ts
112
- var RUNNER_VERSION = true ? "0.1.12" : "0.0.0-dev";
113
+ var RUNNER_VERSION = true ? "0.1.13" : "0.0.0-dev";
113
114
  var RUNNER_PLATFORM = `${process.platform}-${process.arch}`;
114
115
 
115
116
  // src/api.ts
@@ -1432,7 +1433,7 @@ function resolveConfig(file, overrides = {}, env = process.env, paths = runnerPa
1432
1433
  }
1433
1434
 
1434
1435
  // src/daemon.ts
1435
- import { join as join9 } from "node:path";
1436
+ import { join as join10 } from "node:path";
1436
1437
 
1437
1438
  // src/backoff.ts
1438
1439
  function backoffDelay(attempt, baseMs = 1e3, maxMs = 6e4) {
@@ -1555,7 +1556,8 @@ function reportableSessionIds(ids, onDropped = () => void 0) {
1555
1556
  }
1556
1557
 
1557
1558
  // src/session-manager.ts
1558
- import { mkdir as mkdir6, rm as rm6 } from "node:fs/promises";
1559
+ import { mkdir as mkdir6, rm as rm6, writeFile as writeFile4 } from "node:fs/promises";
1560
+ import { join as join9 } from "node:path";
1559
1561
 
1560
1562
  // src/fsutil.ts
1561
1563
  import { mkdir as mkdir4, readFile as readFile3, rename as rename2, writeFile as writeFile3 } from "node:fs/promises";
@@ -2013,7 +2015,7 @@ var PermissionRelay = class {
2013
2015
  };
2014
2016
 
2015
2017
  // src/tool-grants.ts
2016
- import { dirname as dirname4, join as join7 } from "node:path";
2018
+ import { dirname as dirname4, join as join7, posix } from "node:path";
2017
2019
  var isGrantableDenial = isGrantableToolDenial;
2018
2020
  var FILE_TOOLS = /* @__PURE__ */ new Set(["Read", "Edit", "MultiEdit", "Write", "NotebookEdit"]);
2019
2021
  var EDIT_TOOLS = /* @__PURE__ */ new Set(["Edit", "MultiEdit", "Write", "NotebookEdit"]);
@@ -2071,8 +2073,16 @@ function bashRules(command, allowedTools) {
2071
2073
  head.push(w[1]);
2072
2074
  if (RUNNER_WORDS.has(w[1]) && w[2] && WORD.test(w[2]) && !w[2].includes("/")) head.push(w[2]);
2073
2075
  }
2074
- const once = segment.length <= 400 ? `Bash(${segment})` : `Bash(${head.join(" ")} *)`;
2075
- return { suggestedRule: `Bash(${head.join(" ")} *)`, onceRule: once };
2076
+ const prefix = `Bash(${head.join(" ")} *)`;
2077
+ const allAllowed = segments.every(
2078
+ (s) => allowedTools.some((rule) => ruleAllows(rule, "Bash", { command: s }))
2079
+ );
2080
+ const exact = command.trim();
2081
+ if ((allAllowed || !grantsCover([prefix], allowedTools, "Bash", { command })) && exact.length <= 400 && !/[\r\n]/.test(exact)) {
2082
+ return same(`Bash(${exact})`);
2083
+ }
2084
+ const once = segment.length <= 400 ? `Bash(${segment})` : prefix;
2085
+ return { suggestedRule: prefix, onceRule: once };
2076
2086
  }
2077
2087
  function hostOf(url) {
2078
2088
  if (!url) return null;
@@ -2102,14 +2112,63 @@ function ruleAllows(rule, toolName, input) {
2102
2112
  if (parsed.spec === null) return toolName !== "Bash";
2103
2113
  if (toolName === "Bash") {
2104
2114
  const command = typeof i.command === "string" ? i.command.trim() : "";
2115
+ if (command && parsed.spec.trim() === command) return true;
2105
2116
  const segments = shellSegments(command);
2106
2117
  return segments.length > 0 && segments.every((s) => shellPatternMatches(parsed.spec, s));
2107
2118
  }
2108
2119
  if (toolName === "WebFetch" && parsed.spec.startsWith("domain:")) {
2109
2120
  return hostOf(typeof i.url === "string" ? i.url : null) === parsed.spec.slice(7).toLowerCase();
2110
2121
  }
2122
+ if (FILE_TOOLS.has(toolName)) {
2123
+ const file = typeof i.file_path === "string" ? i.file_path : typeof i.notebook_path === "string" ? i.notebook_path : "";
2124
+ return filePatternMatches(parsed.spec, file);
2125
+ }
2111
2126
  return false;
2112
2127
  }
2128
+ function hasOpaqueShell(command) {
2129
+ const s = command.replace(/\d*>&\d+/g, " ").replace(/&>\s*\/dev\/null(?![^\s;&|)])/g, " ").replace(/\d*>>?\s*\/dev\/null(?![^\s;&|)])/g, " ").replace(/&&/g, " ");
2130
+ return /\$\(|`|<\(|>\(|>|&/.test(s);
2131
+ }
2132
+ function grantsCover(granted, base, toolName, input) {
2133
+ if (granted.length === 0) return false;
2134
+ if (toolName !== "Bash") return granted.some((rule) => ruleAllows(rule, toolName, input));
2135
+ const i = input && typeof input === "object" ? input : {};
2136
+ const command = typeof i.command === "string" ? i.command.trim() : "";
2137
+ if (!command) return false;
2138
+ const exact = granted.some((rule) => {
2139
+ const parsed = parseRule(rule);
2140
+ return parsed?.tool === "Bash" && parsed.spec !== null && parsed.spec.trim() === command;
2141
+ });
2142
+ if (exact) return true;
2143
+ if (hasOpaqueShell(command)) return false;
2144
+ const segments = shellSegments(command);
2145
+ if (segments.length === 0) return false;
2146
+ let byGrant = false;
2147
+ for (const segment of segments) {
2148
+ const call = { command: segment };
2149
+ if (granted.some((rule) => ruleAllows(rule, "Bash", call))) byGrant = true;
2150
+ else if (!base.some((rule) => ruleAllows(rule, "Bash", call))) return false;
2151
+ }
2152
+ return byGrant;
2153
+ }
2154
+ function filePatternMatches(spec, file) {
2155
+ if (!file) return false;
2156
+ const home = process.env.HOME || process.env.USERPROFILE || "";
2157
+ let pattern = spec.trim();
2158
+ if (pattern.startsWith("~/")) {
2159
+ if (!home) return false;
2160
+ pattern = rulePath(join7(home, pattern.slice(2)).replace(/\\/g, "/"));
2161
+ }
2162
+ if (!pattern.startsWith("//")) return false;
2163
+ const path = rulePath(file);
2164
+ if (!path.startsWith("//")) return false;
2165
+ const normalized = `/${posix.normalize(path.slice(1))}`;
2166
+ if (!normalized.startsWith("//")) return false;
2167
+ const re = pattern.split("**").map(
2168
+ (part) => part.split("*").map((p) => p.replace(/[.+?^${}()|[\]\\]/g, "\\$&")).join("[^/]*")
2169
+ ).join(".*");
2170
+ return new RegExp(`^${re}$`, "s").test(normalized);
2171
+ }
2113
2172
  function shellPatternMatches(spec, command) {
2114
2173
  let pattern = spec.trim();
2115
2174
  if (pattern.endsWith(":*")) pattern = `${pattern.slice(0, -2)} *`;
@@ -2567,8 +2626,13 @@ var AgentSession = class {
2567
2626
  this.record.alwaysAllowedTools = [...this.record.alwaysAllowedTools ?? [], tool];
2568
2627
  void this.deps.store.save(this.record).catch(() => void 0);
2569
2628
  },
2570
- grantedByRule: (tool, input) => [...this.record.grantRules ?? [], ...this.savedRulesNow].some(
2571
- (rule) => ruleAllows(rule, tool, input)
2629
+ // The call as a whole, with the runner's allow-list covering the parts it already
2630
+ // allows: Claude Code only asks about calls its own rules did not cover.
2631
+ grantedByRule: (tool, input) => grantsCover(
2632
+ [...this.record.grantRules ?? [], ...this.savedRulesNow],
2633
+ this.deps.allowedTools,
2634
+ tool,
2635
+ input
2572
2636
  ),
2573
2637
  // Only with a repository to save a rule for.
2574
2638
  suggestRule: (tool, input) => toolGrantRepositoryKey(this.record.repository) ? suggestRules(tool, input, this.deps.allowedTools)?.suggestedRule ?? null : null,
@@ -3624,6 +3688,10 @@ var SessionManager = class {
3624
3688
  resume ? safeWorktreeKey(resume.worktreeKey, cmd.sessionId) : cmd.sessionId
3625
3689
  );
3626
3690
  await mkdir6(record.cwd, { recursive: true });
3691
+ const deliverable = resume?.deliverable;
3692
+ if (typeof deliverable === "string" && deliverable.trim()) {
3693
+ await writeFile4(join9(record.cwd, RUNNER_DELIVERABLE_FILE), deliverable, "utf8");
3694
+ }
3627
3695
  }
3628
3696
  if (resume) {
3629
3697
  record.claudeSessionId = resume.claudeSessionId?.trim() || null;
@@ -3918,8 +3986,9 @@ function safeWorktreeKey(key, fallback) {
3918
3986
  function continuationPreface(cmd) {
3919
3987
  const branch = cmd.repository?.workBranch;
3920
3988
  const task = cmd.prompt.trim();
3989
+ const deliverable = !branch && !!cmd.resume?.deliverable?.trim();
3921
3990
  return [
3922
- branch ? `You are continuing earlier work on the branch ${branch}, which is checked out here with everything done so far. The earlier conversation could not be restored; read the branch's commits (git log, git diff against the base) for what was done.` : "You are continuing earlier work in this directory. The earlier conversation could not be restored.",
3991
+ branch ? `You are continuing earlier work on the branch ${branch}, which is checked out here with everything done so far. The earlier conversation could not be restored; read the branch's commits (git log, git diff against the base) for what was done.` : deliverable ? `You are continuing earlier work on this task. The earlier conversation could not be restored. What you delivered last is in ${RUNNER_DELIVERABLE_FILE} in this directory, in full: read all of it before you revise it.` : "You are continuing earlier work in this directory. The earlier conversation could not be restored.",
3923
3992
  task ? `The original task was:
3924
3993
 
3925
3994
  ${task.slice(0, 2e4)}` : "",
@@ -4080,7 +4149,9 @@ var RunnerDaemon = class {
4080
4149
  // And relays Claude Code's permission prompts (`relayPermissionRequests`).
4081
4150
  relaysPermissionRequests: true,
4082
4151
  // And reports denied tool calls, takes grants on them, and keeps saved rules.
4083
- grantsToolPermissions: true
4152
+ grantsToolPermissions: true,
4153
+ // And keeps a continued non-code run's deliverable whole (`resume.deliverable`).
4154
+ receivesDeliverable: true
4084
4155
  },
4085
4156
  activeSessionIds: this.heartbeatSessionIds(),
4086
4157
  maxConcurrentSessions: this.opts.config.maxSessions,
@@ -4189,7 +4260,7 @@ var RunnerDaemon = class {
4189
4260
  if (this.droppedSessionIds.has(id)) return;
4190
4261
  this.droppedSessionIds.add(id);
4191
4262
  this.opts.logger.warn(
4192
- `session ${id}: not a Discovery Tree session id, so it is left out of the heartbeat (its state is in ${join9(this.opts.config.stateDir, "sessions", id)})`
4263
+ `session ${id}: not a Discovery Tree session id, so it is left out of the heartbeat (its state is in ${join10(this.opts.config.stateDir, "sessions", id)})`
4193
4264
  );
4194
4265
  });
4195
4266
  }
@@ -4418,9 +4489,9 @@ function formatChecks(checks) {
4418
4489
 
4419
4490
  // src/lock.ts
4420
4491
  import { mkdir as mkdir7, open, readFile as readFile4, rm as rm7 } from "node:fs/promises";
4421
- import { join as join10 } from "node:path";
4492
+ import { join as join11 } from "node:path";
4422
4493
  function lockFile(stateDir) {
4423
- return join10(stateDir, "daemon.pid");
4494
+ return join11(stateDir, "daemon.pid");
4424
4495
  }
4425
4496
  function pidAlive(pid) {
4426
4497
  if (!Number.isInteger(pid) || pid <= 0) return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@discovery-tree/runner",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "dt-runner: run Discovery Tree agent sessions on your own computer with your own signed-in Claude Code",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {