@discovery-tree/runner 0.1.11 → 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 +90 -18
  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
@@ -69,6 +70,11 @@ var AGENT_PERMISSION_INPUT_SUMMARY_MAX_LENGTH = 2e3;
69
70
  var RUNNER_PERMISSION_REQUEST_TIMEOUT_MS = 30 * 6e4;
70
71
 
71
72
  // ../contracts/src/agent-tool-grants.ts
73
+ var GRANTABLE_DENIAL = /permission for this tool use was denied|no approval surface|haven'?t granted it yet|permission prompts are not answered on this runner|permission for this tool call was not granted/i;
74
+ var NOT_GRANTABLE = /the person denied permission|has been denied by a (deny )?rule|matches a deny rule/i;
75
+ function isGrantableToolDenial(text) {
76
+ return !!text && GRANTABLE_DENIAL.test(text) && !NOT_GRANTABLE.test(text);
77
+ }
72
78
  var TOOL_GRANT_RULE_MAX_LENGTH = 500;
73
79
  var RUNNER_TOOL_GRANTS_MAX = 500;
74
80
  var RULE_SHAPE = /^([A-Za-z][A-Za-z0-9_.-]*)(?:\(([\s\S]*)\))?$/;
@@ -104,7 +110,7 @@ function toolGrantRepositoryKey(url) {
104
110
  }
105
111
 
106
112
  // src/version.ts
107
- var RUNNER_VERSION = true ? "0.1.11" : "0.0.0-dev";
113
+ var RUNNER_VERSION = true ? "0.1.13" : "0.0.0-dev";
108
114
  var RUNNER_PLATFORM = `${process.platform}-${process.arch}`;
109
115
 
110
116
  // src/api.ts
@@ -1427,7 +1433,7 @@ function resolveConfig(file, overrides = {}, env = process.env, paths = runnerPa
1427
1433
  }
1428
1434
 
1429
1435
  // src/daemon.ts
1430
- import { join as join9 } from "node:path";
1436
+ import { join as join10 } from "node:path";
1431
1437
 
1432
1438
  // src/backoff.ts
1433
1439
  function backoffDelay(attempt, baseMs = 1e3, maxMs = 6e4) {
@@ -1550,7 +1556,8 @@ function reportableSessionIds(ids, onDropped = () => void 0) {
1550
1556
  }
1551
1557
 
1552
1558
  // src/session-manager.ts
1553
- 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";
1554
1561
 
1555
1562
  // src/fsutil.ts
1556
1563
  import { mkdir as mkdir4, readFile as readFile3, rename as rename2, writeFile as writeFile3 } from "node:fs/promises";
@@ -2008,12 +2015,8 @@ var PermissionRelay = class {
2008
2015
  };
2009
2016
 
2010
2017
  // src/tool-grants.ts
2011
- import { dirname as dirname4, join as join7 } from "node:path";
2012
- var GRANTABLE_DENIAL = /permission for this tool use was denied|no approval surface|haven'?t granted it yet|permission prompts are not answered on this runner|permission for this tool call was not granted/i;
2013
- var NOT_GRANTABLE = /the person denied permission|has been denied by a (deny )?rule|matches a deny rule/i;
2014
- function isGrantableDenial(text) {
2015
- return !!text && GRANTABLE_DENIAL.test(text) && !NOT_GRANTABLE.test(text);
2016
- }
2018
+ import { dirname as dirname4, join as join7, posix } from "node:path";
2019
+ var isGrantableDenial = isGrantableToolDenial;
2017
2020
  var FILE_TOOLS = /* @__PURE__ */ new Set(["Read", "Edit", "MultiEdit", "Write", "NotebookEdit"]);
2018
2021
  var EDIT_TOOLS = /* @__PURE__ */ new Set(["Edit", "MultiEdit", "Write", "NotebookEdit"]);
2019
2022
  function suggestRules(toolName, input, allowedTools = []) {
@@ -2070,8 +2073,16 @@ function bashRules(command, allowedTools) {
2070
2073
  head.push(w[1]);
2071
2074
  if (RUNNER_WORDS.has(w[1]) && w[2] && WORD.test(w[2]) && !w[2].includes("/")) head.push(w[2]);
2072
2075
  }
2073
- const once = segment.length <= 400 ? `Bash(${segment})` : `Bash(${head.join(" ")} *)`;
2074
- 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 };
2075
2086
  }
2076
2087
  function hostOf(url) {
2077
2088
  if (!url) return null;
@@ -2101,14 +2112,63 @@ function ruleAllows(rule, toolName, input) {
2101
2112
  if (parsed.spec === null) return toolName !== "Bash";
2102
2113
  if (toolName === "Bash") {
2103
2114
  const command = typeof i.command === "string" ? i.command.trim() : "";
2115
+ if (command && parsed.spec.trim() === command) return true;
2104
2116
  const segments = shellSegments(command);
2105
2117
  return segments.length > 0 && segments.every((s) => shellPatternMatches(parsed.spec, s));
2106
2118
  }
2107
2119
  if (toolName === "WebFetch" && parsed.spec.startsWith("domain:")) {
2108
2120
  return hostOf(typeof i.url === "string" ? i.url : null) === parsed.spec.slice(7).toLowerCase();
2109
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
+ }
2110
2126
  return false;
2111
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
+ }
2112
2172
  function shellPatternMatches(spec, command) {
2113
2173
  let pattern = spec.trim();
2114
2174
  if (pattern.endsWith(":*")) pattern = `${pattern.slice(0, -2)} *`;
@@ -2566,8 +2626,13 @@ var AgentSession = class {
2566
2626
  this.record.alwaysAllowedTools = [...this.record.alwaysAllowedTools ?? [], tool];
2567
2627
  void this.deps.store.save(this.record).catch(() => void 0);
2568
2628
  },
2569
- grantedByRule: (tool, input) => [...this.record.grantRules ?? [], ...this.savedRulesNow].some(
2570
- (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
2571
2636
  ),
2572
2637
  // Only with a repository to save a rule for.
2573
2638
  suggestRule: (tool, input) => toolGrantRepositoryKey(this.record.repository) ? suggestRules(tool, input, this.deps.allowedTools)?.suggestedRule ?? null : null,
@@ -3623,6 +3688,10 @@ var SessionManager = class {
3623
3688
  resume ? safeWorktreeKey(resume.worktreeKey, cmd.sessionId) : cmd.sessionId
3624
3689
  );
3625
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
+ }
3626
3695
  }
3627
3696
  if (resume) {
3628
3697
  record.claudeSessionId = resume.claudeSessionId?.trim() || null;
@@ -3917,8 +3986,9 @@ function safeWorktreeKey(key, fallback) {
3917
3986
  function continuationPreface(cmd) {
3918
3987
  const branch = cmd.repository?.workBranch;
3919
3988
  const task = cmd.prompt.trim();
3989
+ const deliverable = !branch && !!cmd.resume?.deliverable?.trim();
3920
3990
  return [
3921
- 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.",
3922
3992
  task ? `The original task was:
3923
3993
 
3924
3994
  ${task.slice(0, 2e4)}` : "",
@@ -4079,7 +4149,9 @@ var RunnerDaemon = class {
4079
4149
  // And relays Claude Code's permission prompts (`relayPermissionRequests`).
4080
4150
  relaysPermissionRequests: true,
4081
4151
  // And reports denied tool calls, takes grants on them, and keeps saved rules.
4082
- grantsToolPermissions: true
4152
+ grantsToolPermissions: true,
4153
+ // And keeps a continued non-code run's deliverable whole (`resume.deliverable`).
4154
+ receivesDeliverable: true
4083
4155
  },
4084
4156
  activeSessionIds: this.heartbeatSessionIds(),
4085
4157
  maxConcurrentSessions: this.opts.config.maxSessions,
@@ -4188,7 +4260,7 @@ var RunnerDaemon = class {
4188
4260
  if (this.droppedSessionIds.has(id)) return;
4189
4261
  this.droppedSessionIds.add(id);
4190
4262
  this.opts.logger.warn(
4191
- `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)})`
4192
4264
  );
4193
4265
  });
4194
4266
  }
@@ -4417,9 +4489,9 @@ function formatChecks(checks) {
4417
4489
 
4418
4490
  // src/lock.ts
4419
4491
  import { mkdir as mkdir7, open, readFile as readFile4, rm as rm7 } from "node:fs/promises";
4420
- import { join as join10 } from "node:path";
4492
+ import { join as join11 } from "node:path";
4421
4493
  function lockFile(stateDir) {
4422
- return join10(stateDir, "daemon.pid");
4494
+ return join11(stateDir, "daemon.pid");
4423
4495
  }
4424
4496
  function pidAlive(pid) {
4425
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.11",
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": {