toolroll 0.9.108 → 0.9.110

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 (187) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/dist/advanced-view.js +0 -1
  3. package/dist/agent-detect.js +244 -0
  4. package/dist/agent-fence.js +47 -5
  5. package/dist/agent-state.js +5 -2
  6. package/dist/agentconfig.js +2 -2
  7. package/dist/approval-summary.js +344 -0
  8. package/dist/assignment-ui.js +5 -5
  9. package/dist/assignment.js +5 -2
  10. package/dist/attest.js +2 -2
  11. package/dist/browser/terminal.js +1 -1
  12. package/dist/browser/workspace.css +2 -2
  13. package/dist/browser/workspace.js +37 -34
  14. package/dist/browser-crew.js +4 -4
  15. package/dist/browser-workspace.js +4 -11
  16. package/dist/builder.js +45 -3
  17. package/dist/chat-actions.js +24 -17
  18. package/dist/chat-controls.js +6 -5
  19. package/dist/chat-core.js +3 -1
  20. package/dist/chat-decide.js +102 -47
  21. package/dist/chat-delivery-state.js +2 -0
  22. package/dist/chat-delivery.js +3 -2
  23. package/dist/chat-live.js +2 -1
  24. package/dist/chat-quiet.js +3 -3
  25. package/dist/chat-task-actions.js +6 -0
  26. package/dist/chat-voice.js +2 -2
  27. package/dist/check-report.js +1 -1
  28. package/dist/cli-help.js +12 -13
  29. package/dist/cli.js +6 -3
  30. package/dist/console-chrome.js +10 -3
  31. package/dist/console-instance.js +10 -1
  32. package/dist/contracts/console-api.js +14 -8
  33. package/dist/contracts/engine-api.js +271 -0
  34. package/dist/contracts/handoff.js +4 -0
  35. package/dist/coordinator.js +2 -2
  36. package/dist/decision.js +17 -0
  37. package/dist/demo-chat.js +1 -1
  38. package/dist/demo.js +6 -0
  39. package/dist/design/kit.js +4 -3
  40. package/dist/discord-api.js +4 -3
  41. package/dist/discord-chat.js +3 -1
  42. package/dist/dispatch.js +3 -8
  43. package/dist/easy-start-args.js +7 -3
  44. package/dist/easy-start.js +25 -0
  45. package/dist/egress.js +72 -10
  46. package/dist/engine-handoff.js +34 -0
  47. package/dist/engine-reads.js +261 -0
  48. package/dist/eval-world.js +3 -2
  49. package/dist/evidence.js +2 -0
  50. package/dist/fast-start.js +55 -14
  51. package/dist/fast-terms.js +2 -2
  52. package/dist/first-run.js +10 -2
  53. package/dist/flexible-agents.js +234 -0
  54. package/dist/flexible-answers-schema.js +61 -0
  55. package/dist/flexible-answers.js +889 -0
  56. package/dist/flexible-available.js +1 -0
  57. package/dist/flexible-custody.js +494 -0
  58. package/dist/flexible-import.js +782 -0
  59. package/dist/flexible-launch-schema.js +72 -0
  60. package/dist/flexible-launch.js +331 -0
  61. package/dist/flexible-launcher.js +88 -0
  62. package/dist/flexible-levels.js +34 -0
  63. package/dist/flexible-merge-guard.js +47 -0
  64. package/dist/flexible-refs.js +47 -0
  65. package/dist/flexible-relay-cancel.js +19 -0
  66. package/dist/flexible-relay-schema.js +55 -0
  67. package/dist/flexible-relay-upstreams.js +36 -0
  68. package/dist/flexible-relay.js +1032 -0
  69. package/dist/flexible-schema.js +32 -0
  70. package/dist/flexible-session.js +732 -0
  71. package/dist/flexible-ship-schema.js +81 -0
  72. package/dist/flexible-ship.js +694 -0
  73. package/dist/flexible-start.js +80 -0
  74. package/dist/flexible-thread-schema.js +30 -0
  75. package/dist/flexible-thread.js +676 -0
  76. package/dist/flexible-turns-schema.js +69 -0
  77. package/dist/flexible-turns.js +490 -0
  78. package/dist/flexible-ui.js +44 -0
  79. package/dist/flexible.js +368 -0
  80. package/dist/flow-actions.js +6 -4
  81. package/dist/flow-steps.js +1 -1
  82. package/dist/flows-cli.js +2 -1
  83. package/dist/git-views.js +44 -41
  84. package/dist/guides.js +11 -10
  85. package/dist/install-mode.js +225 -0
  86. package/dist/keymap.js +1 -1
  87. package/dist/lead-context.js +1 -1
  88. package/dist/lead-doors.js +7 -1
  89. package/dist/limits-ui.js +8 -1
  90. package/dist/live-bus.js +70 -13
  91. package/dist/live-reply.js +6 -0
  92. package/dist/live-terminal.js +425 -29
  93. package/dist/local-owner.js +6 -0
  94. package/dist/model-choices.js +12 -6
  95. package/dist/needs-you.js +3 -3
  96. package/dist/nightly-github.js +2 -2
  97. package/dist/notification-delivery.js +11 -0
  98. package/dist/operate.js +185 -33
  99. package/dist/outbound-privacy.js +204 -0
  100. package/dist/passwordless.js +2 -1
  101. package/dist/project-delete-ui.js +2 -1
  102. package/dist/project-delete.js +15 -0
  103. package/dist/provider-auth.js +1 -1
  104. package/dist/provider-connection.js +5 -3
  105. package/dist/publish.js +5 -0
  106. package/dist/pull-request-flow.js +26 -7
  107. package/dist/push.js +5 -1
  108. package/dist/release-card.js +11 -3
  109. package/dist/release.js +11 -1
  110. package/dist/result-actions.js +3 -0
  111. package/dist/result-evidence-readers.js +8 -2
  112. package/dist/result-review.js +20 -9
  113. package/dist/route-store.js +2 -2
  114. package/dist/sandbox-launch.js +32 -8
  115. package/dist/sandbox-runtime.js +16 -7
  116. package/dist/sandbox-tools.js +176 -0
  117. package/dist/scope.js +12 -36
  118. package/dist/scout-net.js +7 -2
  119. package/dist/serve.js +90 -40
  120. package/dist/server/chat.js +9 -9
  121. package/dist/server/chrome.js +19 -17
  122. package/dist/server/console.css +33 -6
  123. package/dist/server/engine-api.js +378 -0
  124. package/dist/server/flows.js +2 -2
  125. package/dist/server/guards.js +10 -4
  126. package/dist/server/home.js +37 -5
  127. package/dist/server/http.js +11 -2
  128. package/dist/server/in-place.js +5 -4
  129. package/dist/server/kit.js +2 -2
  130. package/dist/server/link-redemption.js +52 -0
  131. package/dist/server/live.js +100 -10
  132. package/dist/server/mutation-key.js +21 -7
  133. package/dist/server/pages.js +129 -74
  134. package/dist/server/people-tokens.js +17 -41
  135. package/dist/server/render-chat.js +2 -1
  136. package/dist/server/render-history.js +18 -4
  137. package/dist/server/render-new-task.js +4 -4
  138. package/dist/server/render-pages.js +21 -39
  139. package/dist/server/render-people.js +2 -2
  140. package/dist/server/render-projects.js +5 -5
  141. package/dist/server/render-results.js +30 -14
  142. package/dist/server/render-tasks.js +155 -155
  143. package/dist/server/retired-routes.js +37 -4
  144. package/dist/server/route-policy.js +8 -0
  145. package/dist/server/route-table.js +43 -5
  146. package/dist/server/settings-computers.js +140 -0
  147. package/dist/server/settings-scripts.js +15 -0
  148. package/dist/server/settings-section-table.js +59 -0
  149. package/dist/server/settings-sections.js +291 -0
  150. package/dist/server/settings.js +247 -28
  151. package/dist/server/task-views.js +55 -15
  152. package/dist/server/tasks.js +168 -98
  153. package/dist/server/terminals.js +181 -28
  154. package/dist/server/welcome.js +40 -14
  155. package/dist/settings-groups-ui.js +26 -107
  156. package/dist/settings-proofs.js +18 -11
  157. package/dist/slack-api.js +4 -3
  158. package/dist/slack-chat.js +5 -3
  159. package/dist/spend.js +46 -12
  160. package/dist/sqlite-telemetry.js +70 -21
  161. package/dist/status-probe.js +343 -0
  162. package/dist/store.js +206 -10
  163. package/dist/task-link.js +64 -0
  164. package/dist/teams-api.js +4 -3
  165. package/dist/teams-chat.js +4 -2
  166. package/dist/telegram-lead.js +2 -1
  167. package/dist/telegram-live.js +2 -1
  168. package/dist/telegram-team.js +2 -1
  169. package/dist/telegram.js +17 -5
  170. package/dist/trusted-path.js +162 -0
  171. package/dist/tui/darwin-arm64/toolroll-tui +0 -0
  172. package/dist/tui/darwin-x64/toolroll-tui +0 -0
  173. package/dist/tui/linux-arm64/toolroll-tui +0 -0
  174. package/dist/tui/linux-x64/toolroll-tui +0 -0
  175. package/dist/tui-launch.js +282 -0
  176. package/dist/tui-source.js +5 -3
  177. package/dist/tui.js +2 -2
  178. package/dist/typed-words-schema.js +18 -0
  179. package/dist/webhooks.js +8 -4
  180. package/dist/welcome-facts.js +25 -17
  181. package/dist/work-index.js +126 -29
  182. package/dist/work-reads.js +279 -0
  183. package/dist/workspace-ui.js +5 -0
  184. package/package.json +4 -2
  185. package/scripts/crash-canary.mjs +1 -1
  186. package/scripts/pilot.mjs +1 -1
  187. package/scripts/provider-canary.mjs +5 -3
package/dist/egress.js CHANGED
@@ -37,6 +37,28 @@ export function hostAllowed(host, hosts) {
37
37
  return false;
38
38
  return hosts.some(entry => entry === name || (entry.startsWith("*.") && name.endsWith(entry.slice(1))));
39
39
  }
40
+ export function untilClosed(signal, work) {
41
+ if (signal.aborted)
42
+ return Promise.resolve(null);
43
+ return new Promise((resolve, reject) => {
44
+ const aborted = () => resolve(null);
45
+ signal.addEventListener("abort", aborted, { once: true });
46
+ let pending;
47
+ try {
48
+ pending = work();
49
+ }
50
+ catch (error) {
51
+ signal.removeEventListener("abort", aborted);
52
+ reject(error);
53
+ return;
54
+ }
55
+ pending.then(value => { signal.removeEventListener("abort", aborted); resolve(value); }, error => { signal.removeEventListener("abort", aborted); reject(error); });
56
+ });
57
+ }
58
+ function anyHostByName(host) {
59
+ const name = normalizeHost(host);
60
+ return name !== null && !name.startsWith("*.");
61
+ }
40
62
  export const PROVIDER_HOSTS = {
41
63
  claude: ["api.anthropic.com", "console.anthropic.com", "platform.claude.com"],
42
64
  codex: ["api.openai.com", "chatgpt.com", "auth.openai.com"],
@@ -156,16 +178,24 @@ export function projectNetworkFromValue(value) {
156
178
  return null;
157
179
  return { mode: v["mode"], hosts: [...new Set(hosts)].sort(), loopback: v["loopback"] };
158
180
  }
159
- export function networkWords(network) {
181
+ export function unaccountedHosts(network, provider) {
182
+ const full = Object.values(REGISTRY_HOSTS).filter(hosts => hosts.every(one => network.hosts.includes(one)));
183
+ const own = PROVIDER_HOSTS[provider] ?? [];
184
+ const known = new Set([...(own.length > 0 && own.every(one => network.hosts.includes(one)) ? own : []), ...full.flat()]);
185
+ return network.hosts.filter(one => !known.has(one));
186
+ }
187
+ export function networkWords(network, provider) {
160
188
  if (network === null)
161
189
  return "Network: approved before network rules (provider and package registries only)";
162
190
  if (network.mode === "open")
163
191
  return `Network: open — any host${network.loopback === "proxy-only" ? "" : ", and every local service on this Mac"}`;
164
- const registries = Object.entries(REGISTRY_HOSTS)
165
- .filter(([, hosts]) => hosts.every(one => network.hosts.includes(one))).map(([name]) => REGISTRY_NAMES[name]);
166
- const known = new Set([...Object.values(REGISTRY_HOSTS).flat(), ...Object.values(PROVIDER_HOSTS).flat()]);
192
+ const full = Object.entries(REGISTRY_HOSTS).filter(([, hosts]) => hosts.every(one => network.hosts.includes(one)));
193
+ const own = PROVIDER_HOSTS[provider] ?? [];
194
+ const named = own.length > 0 && own.every(one => network.hosts.includes(one));
195
+ const known = new Set([...(named ? own : []), ...full.flatMap(([, hosts]) => hosts)]);
167
196
  const added = network.hosts.filter(one => !known.has(one));
168
- return `Network: the agent's provider${registries.length === 0 ? "" : `, ${registries.join(", ")}`}${added.length === 0 ? "" : `, and ${added.join(", ")}`}`
197
+ const parts = [...(named ? ["the agent's provider"] : []), ...full.map(([name]) => REGISTRY_NAMES[name])];
198
+ return `Network: ${parts.length === 0 && added.length === 0 ? "no hosts" : [parts.join(", "), added.length === 0 ? "" : `${parts.length === 0 ? "" : "and "}${added.join(", ")}`].filter(Boolean).join(", ")}`
169
199
  + (network.loopback === "any" ? "; and every local service on this Mac" : "");
170
200
  }
171
201
  const REGISTRY_NAMES = { npm: "npm", python: "PyPI", rust: "crates.io", go: "the Go proxy", ruby: "RubyGems", jvm: "Maven and Gradle" };
@@ -217,6 +247,9 @@ export async function startEgressProxy(options) {
217
247
  const addressAllowed = options.addressAllowed ?? isPublicAddress;
218
248
  const upstreamPort = options.upstreamPort ?? ((port) => port);
219
249
  const lookup = options.lookup ?? (async (host) => (await dnsLookup(host, { all: true, verbatim: true })).map(one => one.address));
250
+ const connectUpstream = options.connect ?? ((addresses, port, signal) => connectFirst(addresses, port, undefined, signal));
251
+ const closing = new AbortController();
252
+ const isClosed = () => closing.signal.aborted;
220
253
  const secret = randomBytes(24).toString("base64url");
221
254
  const expected = Buffer.from(secret);
222
255
  const sockets = new Set();
@@ -259,11 +292,14 @@ export async function startEgressProxy(options) {
259
292
  const admit = async (host, port, wantPort) => {
260
293
  if (port !== wantPort)
261
294
  return { ok: false, why: `port ${port} is not allowed` };
262
- if (!hostAllowed(host, options.hosts))
295
+ if (options.open === true ? !anyHostByName(host) : !hostAllowed(host, options.hosts))
263
296
  return { ok: false, why: "not an approved host" };
264
297
  let addresses;
265
298
  try {
266
- addresses = await lookup(normalizeHost(host));
299
+ const found = await untilClosed(closing.signal, () => lookup(normalizeHost(host)));
300
+ if (found === null || isClosed())
301
+ return { ok: false, why: "the proxy closed" };
302
+ addresses = found;
267
303
  }
268
304
  catch {
269
305
  return { ok: false, why: "the host does not resolve" };
@@ -296,12 +332,21 @@ export async function startEgressProxy(options) {
296
332
  return;
297
333
  }
298
334
  const reached = await admit(url.hostname, Number(url.port || 80), 80);
335
+ if (isClosed()) {
336
+ incoming.socket.destroy();
337
+ return;
338
+ }
299
339
  if (!reached.ok) {
300
340
  count(url.hostname, false, reached.why);
301
341
  outgoing.writeHead(403, { "content-type": "text/plain" }).end(`Toolroll: ${url.hostname} is not one of this build's approved hosts.`);
302
342
  return;
303
343
  }
304
- const upstream = await connectFirst(reached.addresses, upstreamPort(80));
344
+ const upstream = await connectUpstream(reached.addresses, upstreamPort(80), closing.signal);
345
+ if (isClosed()) {
346
+ upstream?.destroy();
347
+ incoming.socket.destroy();
348
+ return;
349
+ }
305
350
  if (upstream === null) {
306
351
  outgoing.writeHead(502).end();
307
352
  return;
@@ -332,12 +377,21 @@ export async function startEgressProxy(options) {
332
377
  }
333
378
  const match = /^([^:[\]\s]+):(\d{1,5})$/.exec(incoming.url ?? "");
334
379
  const reached = match === null ? { ok: false, why: "not a host name and port" } : await admit(match[1], Number(match[2]), 443);
380
+ if (isClosed()) {
381
+ client.destroy();
382
+ return;
383
+ }
335
384
  if (!reached.ok) {
336
385
  count(match?.[1] ?? String(incoming.url ?? ""), false, reached.why);
337
386
  client.end("HTTP/1.1 403 Forbidden\r\nContent-Length: 0\r\n\r\n");
338
387
  return;
339
388
  }
340
- const upstream = await connectFirst(reached.addresses, upstreamPort(443));
389
+ const upstream = await connectUpstream(reached.addresses, upstreamPort(443), closing.signal);
390
+ if (isClosed()) {
391
+ upstream?.destroy();
392
+ client.destroy();
393
+ return;
394
+ }
341
395
  if (upstream === null) {
342
396
  if (!client.destroyed)
343
397
  client.end("HTTP/1.1 502 Bad Gateway\r\nContent-Length: 0\r\n\r\n");
@@ -354,7 +408,14 @@ export async function startEgressProxy(options) {
354
408
  client.pipe(upstream);
355
409
  })();
356
410
  });
357
- server.on("connection", socket => { sockets.add(socket); socket.on("close", () => sockets.delete(socket)); });
411
+ server.on("connection", socket => {
412
+ if (isClosed()) {
413
+ socket.destroy();
414
+ return;
415
+ }
416
+ sockets.add(socket);
417
+ socket.on("close", () => sockets.delete(socket));
418
+ });
358
419
  await new Promise((done, fail) => {
359
420
  server.once("error", fail);
360
421
  server.listen(0, "127.0.0.1", () => { server.off("error", fail); done(); });
@@ -367,6 +428,7 @@ export async function startEgressProxy(options) {
367
428
  port,
368
429
  counts: () => ({ connections, refused, hosts: [...byHost].map(([host, one]) => ({ host, ...one })).sort((a, b) => b.connections + b.refused - (a.connections + a.refused) || a.host.localeCompare(b.host)), otherHosts }),
369
430
  close: () => new Promise(done => {
431
+ closing.abort();
370
432
  for (const socket of sockets)
371
433
  socket.destroy();
372
434
  server.close(() => done());
@@ -0,0 +1,34 @@
1
+ import { spawn } from "node:child_process";
2
+ export const LINK_FD = 3;
3
+ const LINK = /^http:\/\/(?:127\.0\.0\.1|\[::1\]):[0-9]{1,5}\/login\/once\/[A-Za-z0-9_-]{43}$/;
4
+ export function spawnWithLink(command, args, link, options = {}) {
5
+ const held = spawnHoldingLink(command, args, link, options);
6
+ held.send();
7
+ return held.child;
8
+ }
9
+ export function spawnHoldingLink(command, args, link, options = {}) {
10
+ if (!LINK.test(link))
11
+ throw new Error("not a local one-time sign-in link");
12
+ const code = link.slice(link.lastIndexOf("/") + 1);
13
+ const env = options.env ?? process.env;
14
+ if (args.some(one => one.includes(code)) || Object.entries(env).some(([name, value]) => name.includes(code) || (value ?? "").includes(code))) {
15
+ throw new Error("the sign-in link goes only over the pipe, never in arguments or the environment");
16
+ }
17
+ const [stdin, stdout, stderr] = options.stdio ?? ["inherit", "inherit", "inherit"];
18
+ const child = spawn(command, [...args], { cwd: options.cwd, env, stdio: options.control === true ? [stdin, stdout, stderr, "pipe", "pipe"] : [stdin, stdout, stderr, "pipe"] });
19
+ const pipe = child.stdio[LINK_FD];
20
+ if (pipe === null || pipe === undefined || !("write" in pipe)) {
21
+ child.kill();
22
+ throw new Error("no pipe for the sign-in link");
23
+ }
24
+ pipe.on("error", () => { });
25
+ let sent = false;
26
+ const send = () => {
27
+ if (sent || child.exitCode !== null || child.signalCode !== null)
28
+ return false;
29
+ sent = true;
30
+ pipe.end(`${link}\n`);
31
+ return true;
32
+ };
33
+ return { child, send };
34
+ }
@@ -0,0 +1,261 @@
1
+ import { assignmentOf, owedAcceptance, personCompletionRefusal } from "./assignment.js";
2
+ import { assignmentCardOf } from "./assignment-ui.js";
3
+ import { assignmentStageOf, stageOfCode } from "./task-status.js";
4
+ import { taskRoad } from "./first-run.js";
5
+ import { stepRowsOf } from "./workspace-ui.js";
6
+ import { approvalOf } from "./scope.js";
7
+ import { approvalSummaryOf, summaryContextOf } from "./approval-summary.js";
8
+ import { taskWorkSummaryOf } from "./work-summary.js";
9
+ import { terminalDiffView } from "./result-evidence-readers.js";
10
+ import { parseReviewDiff } from "./server/render-results.js";
11
+ import { revisionSourceOf } from "./result-review.js";
12
+ import { DIFF_CONTEXT_MAX, ENGINE_API_VERSION } from "./contracts/engine-api.js";
13
+ import { agentSetupOf, detectionLines, NO_AGENT_YET, npmRegistryOf } from "./agent-detect.js";
14
+ import { scanPatchForSecrets } from "./evidence.js";
15
+ import { fastCompletionProblem } from "./fast-start.js";
16
+ import { viewedGitSync } from "./teardown-git.js";
17
+ export const isResultRun = (run) => run.finishedAt !== null && (run.role === "builder" || run.role === "scout");
18
+ const AUTOMATIC = new Set(["auto-check", "auto-green"]);
19
+ export function stepCardsOf({ store, family, now, access, evidenceRoot, viewer = null }) {
20
+ const current = family.current, root = family.root;
21
+ const ref = store.lookupRef(current.id);
22
+ const scope = store.getScope(current.id);
23
+ const runs = ref === null ? [] : store.runsFor(ref.id);
24
+ const assignment = assignmentOf(store, current.id, now, access, evidenceRoot);
25
+ const item = taskWorkSummaryOf(store, current.id, now, access);
26
+ const live = runs.find(run => run.finishedAt === null) ?? null;
27
+ const planning = live?.role === "planner";
28
+ const card = assignment === null || item === null ? null : assignmentCardOf(assignment, { workStatus: item.status, planning });
29
+ const approval = approvalOf(scope);
30
+ const approved = approval.approved;
31
+ const report = ref?.deliverable === "report";
32
+ const plannerRuns = runs.filter(run => run.role === "planner");
33
+ const justCode = plannerRuns.length === 0 && (ref?.plan ?? null) === null && approved;
34
+ const journey = current.state === "cancelled" || item === null ? null : (() => {
35
+ const read = assignment !== null ? assignmentStageOf(assignment, { token: item.status.token, views: item.status.views }, planning) : stageOfCode(item.status.token, { planning });
36
+ const checks = card?.status.check ?? null;
37
+ return taskRoad(read, approved, current.state === "done", { checks, report });
38
+ })();
39
+ const facts = {
40
+ journey,
41
+ scout: report,
42
+ status: card === null ? null : { status: { headline: card.status.headline }, attempts: card.attempts },
43
+ approved: scope !== null && approved && scope.approvedBy !== null && scope.approvedAt !== null
44
+ ? { by: scope.approvedBy, at: scope.approvedAt, automatic: AUTOMATIC.has(String(scope.approvalBasis ?? "")), rule: null } : null,
45
+ approve: null,
46
+ plan: plannerRuns.length === 0 && ref?.plan == null ? null
47
+ : { lead: null, by: plannerRuns[0]?.provider ?? null, at: plannerRuns.find(run => run.finishedAt !== null)?.finishedAt ?? null, planning },
48
+ result: assignment?.receipt == null ? null : { selected: assignment.receipt },
49
+ thread: runs.filter(isResultRun).map(run => ({ kind: "result", at: run.finishedAt })),
50
+ };
51
+ const rows = stepRowsOf(facts);
52
+ const builds = runs.filter(run => run.role === "builder" || run.role === "scout" || run.role === "repair");
53
+ const reviews = runs.filter(run => run.role === "reviewer");
54
+ const behind = { plan: plannerRuns, approve: [], build: builds, checks: [], review: reviews, ready: [] };
55
+ const terms = scope === null || approved ? null : (() => {
56
+ const summary = approvalSummaryOf(scope, summaryContextOf(store, current.id, scope, now));
57
+ return { key: summary.key, revision: summary.revision,
58
+ rows: [...summary.revisionChanges, ...summary.decisions, ...(summary.why === null ? [] : [{ label: "Why model", words: summary.why }]), ...summary.differs].map(one => ({ label: one.label, words: one.words, lines: "lines" in one ? [...(one.lines ?? [])] : [] })),
59
+ warnings: summary.warnings.map(one => one.words), usualLabel: summary.usualLabel, usual: summary.usual.map(one => ({ label: one.label, words: one.words })) };
60
+ })();
61
+ const cards = rows === null ? null : rows.map(row => ({
62
+ key: row.key, label: row.label, state: row.state, mark: row.mark, sentence: row.sentence, at: row.at, needsYou: row.needsYou,
63
+ inChain: !(justCode && (row.key === "plan" || row.key === "approve")),
64
+ ...runFacts(behind[row.key]),
65
+ ...(row.key === "approve" && terms !== null ? { terms } : {}),
66
+ }));
67
+ if (cards !== null && reviews.length > 0) {
68
+ const latest = reviews[0];
69
+ const state = latest.finishedAt === null ? "current" : latest.outcome === "failed" || latest.outcome === "refused" ? "stuck" : "done";
70
+ const at = cards.findIndex(one => one.key === "ready");
71
+ cards.splice(at === -1 ? cards.length : at, 0, {
72
+ key: "review", label: "Review", state, mark: state === "current" ? "live" : state === "stuck" ? "stuck" : "done",
73
+ sentence: state === "current" ? "Reviewing now" : state === "stuck" ? "The review didn't finish" : "Reviewed",
74
+ at: latest.finishedAt, needsYou: false, inChain: true, ...runFacts(reviews),
75
+ });
76
+ }
77
+ return {
78
+ version: ENGINE_API_VERSION,
79
+ task: { id: current.id, root: root.id, title: root.title, state: current.state, project: current.repo },
80
+ chain: justCode ? "just-code" : "plan-first",
81
+ headline: card?.status.headline ?? null,
82
+ liveRun: live?.id ?? null,
83
+ cards,
84
+ review: assignment !== null && assignment.state === "ready-to-check" && assignment.receipt !== null && assignment.receipt.taskId === current.id
85
+ ? { run: assignment.receipt.runId, receipt: assignment.receipt.digest, source: revisionSourceOf(scope?.digest ?? null),
86
+ accept: acceptFactsOf(store, assignment, viewer, evidenceRoot) } : null,
87
+ room: `task:${encodeURIComponent(root.id)}`,
88
+ };
89
+ }
90
+ function runFacts(runs) {
91
+ const latest = runs[0] ?? null;
92
+ const costs = runs.map(run => run.costUsd).filter((one) => typeof one === "number" && Number.isFinite(one));
93
+ return {
94
+ agent: latest === null ? null : { provider: latest.provider, model: latest.modelReported ?? latest.model ?? null },
95
+ startedAt: runs.at(-1)?.startedAt ?? null,
96
+ finishedAt: latest?.finishedAt ?? null,
97
+ costUsd: costs.length === 0 ? null : Math.round(costs.reduce((sum, one) => sum + one, 0) * 1e6) / 1e6,
98
+ runs: runs.map(run => run.id),
99
+ };
100
+ }
101
+ export function resultRunsOf(store, family) {
102
+ return family.versions.flatMap(version => store.runsFor(version.refId)).filter(isResultRun).sort((a, b) => b.id - a.id);
103
+ }
104
+ export function patchFiles(text) {
105
+ return text.replace(/\r\n/g, "\n").split(/^(?=diff --git )/m).filter(part => part.startsWith("diff --git ")).map(part => part.replace(/\n$/, ""));
106
+ }
107
+ function diffSourceOf(store, evidenceRoot, run) {
108
+ const view = terminalDiffView(store.artifactsFor(run.id), evidenceRoot);
109
+ if (view === null)
110
+ return { ok: false, problem: "This result recorded no changes." };
111
+ if (view.patch === null)
112
+ return { ok: false, problem: "This result's changes weren't saved." };
113
+ if ("problem" in view.patch)
114
+ return { ok: false, problem: `This result's changes can't be shown: ${view.patch.problem}.` };
115
+ return { ok: true, patch: view.patch.text, truncated: view.patch.truncated, stat: view };
116
+ }
117
+ export function resultDiffOf(store, evidenceRoot, taskId, run) {
118
+ const empty = (problem) => ({ version: ENGINE_API_VERSION, task: taskId, run: run?.id ?? null, totals: null, files: [], patchTruncated: false, problem });
119
+ if (run === null)
120
+ return empty("No result yet.");
121
+ const source = diffSourceOf(store, evidenceRoot, run);
122
+ if (!source.ok)
123
+ return empty(source.problem);
124
+ const files = patchFiles(source.patch).map((text, index) => {
125
+ const parsed = parseReviewDiff(text).files[0];
126
+ let additions = 0, deletions = 0;
127
+ for (const line of text.split("\n")) {
128
+ if (line.startsWith("+") && !line.startsWith("+++"))
129
+ additions += 1;
130
+ else if (line.startsWith("-") && !line.startsWith("---"))
131
+ deletions += 1;
132
+ }
133
+ const binary = /^(?:Binary files .* differ|GIT binary patch)$/m.test(text);
134
+ return { file: index, path: parsed?.path ?? "changed file", oldPath: parsed?.oldPath ?? null, additions, deletions, binary, hunks: parsed?.hunks.length ?? 0 };
135
+ });
136
+ const stat = source.stat?.stat;
137
+ const totals = stat == null || "problem" in stat ? null
138
+ : { files: stat.fileCount, additions: stat.additions, deletions: stat.deletions, binary: stat.binaryCount, filesTruncated: stat.filesTruncated };
139
+ return { version: ENGINE_API_VERSION, task: taskId, run: run.id, totals, files, patchTruncated: source.truncated, problem: null };
140
+ }
141
+ export function resultDiffFileOf(store, evidenceRoot, taskId, run, file) {
142
+ const source = diffSourceOf(store, evidenceRoot, run);
143
+ if (!source.ok)
144
+ return null;
145
+ const text = patchFiles(source.patch)[file];
146
+ if (text === undefined)
147
+ return null;
148
+ const parsed = parseReviewDiff(text);
149
+ const one = parsed.files[0];
150
+ if (one === undefined)
151
+ return null;
152
+ return { version: ENGINE_API_VERSION, task: taskId, run: run.id, file: { file, path: one.path, oldPath: one.oldPath, meta: one.meta, hunks: one.hunks }, linesTruncated: parsed.linesTruncated };
153
+ }
154
+ function acceptFactsOf(store, assignment, viewer, evidenceRoot) {
155
+ const receipt = assignment.receipt;
156
+ const blockers = assignment.readiness?.blockers ?? [];
157
+ const rules = assignment.repo === null ? null : store.approvalRules(assignment.repo);
158
+ const guarded = rules !== null && (rules.protectProject || rules.protectedPaths.length > 0);
159
+ return {
160
+ owed: owedAcceptance(receipt, blockers),
161
+ blockers: blockers.map(one => one.message),
162
+ needs: guarded ? personCompletionRefusal(store, receipt.taskId, receipt.runId, viewer, evidenceRoot) : fastCompletionProblem(store, receipt.taskId, receipt.runId, viewer),
163
+ };
164
+ }
165
+ const CONTEXT_FILE_BYTES = 2 * 1024 * 1024;
166
+ const CONTEXT_LINE_CHARS = 2_000;
167
+ function keyMaterialIn(content) {
168
+ if (/-----BEGIN [A-Z ]*PRIVATE KEY-----/.test(content) || /PuTTY-User-Key-File-\d+:/.test(content))
169
+ return true;
170
+ if (/\b(?:aws_secret_access_key|SecretAccessKey)\b["']?\s*[=:]/i.test(content))
171
+ return true;
172
+ return /"d"\s*:\s*"[^"]{8,}"/.test(content) && /"(?:kty|crv|n)"\s*:/.test(content);
173
+ }
174
+ export function resultDiffContextOf(store, evidenceRoot, taskId, run, file, from, count, repo) {
175
+ const source = diffSourceOf(store, evidenceRoot, run);
176
+ if (!source.ok)
177
+ return null;
178
+ const text = patchFiles(source.patch)[file];
179
+ if (text === undefined)
180
+ return null;
181
+ const one = parseReviewDiff(text).files[0];
182
+ if (one === undefined)
183
+ return null;
184
+ const answer = (lines, lineCount, problem) => ({ version: ENGINE_API_VERSION, task: taskId, run: run.id, file, from, lines, lineCount, problem });
185
+ const unread = "The rest of this file can't be read here. Press w to see it in the browser.";
186
+ if (!Number.isSafeInteger(from) || from < 1 || !Number.isSafeInteger(count) || count < 1 || count > DIFF_CONTEXT_MAX)
187
+ return answer([], null, unread);
188
+ if (/^deleted file mode /m.test(text) || /^\+\+\+ \/dev\/null$/m.test(text))
189
+ return answer([], 0, "This file was removed by the change.");
190
+ const stat = source.stat?.stat;
191
+ const head = run.headRevision;
192
+ if (repo === null || head === null || !/^[0-9a-f]{40}(?:[0-9a-f]{24})?$/.test(head) || stat == null || "problem" in stat || stat.head !== head)
193
+ return answer([], null, unread);
194
+ const path = stat.files.map(changed => changed.path).find(changed => changed === one.path) ?? null;
195
+ if (path === null || path === "" || path.startsWith("/") || path.split("/").some(part => part === ".." || part === "." || part === "")
196
+ || /[\u0000-\u001f\u007f]/.test(path))
197
+ return answer([], null, unread);
198
+ let bytes;
199
+ try {
200
+ const listed = viewedGitSync(repo, ["--no-replace-objects", "--literal-pathspecs", "ls-tree", "-z", "-l", "--full-tree", head, "--", path], { timeoutMs: 10_000, maxBuffer: 64 * 1024, binding: { repo } });
201
+ if (listed.status !== 0)
202
+ return answer([], null, unread);
203
+ const entry = listed.stdout.split("\0").map(row => /^(\d{6}) (\w+) ([0-9a-f]{40,64}) +(\d+|-)\t(.+)$/s.exec(row)).find(match => match !== null && match[5] === path);
204
+ if (entry == null)
205
+ return answer([], 0, "This file isn't in the result's commit.");
206
+ const [, mode, kind, oid, sized] = entry;
207
+ if (kind !== "blob" || (mode !== "100644" && mode !== "100755") || sized === "-")
208
+ return answer([], null, "This file isn't text.");
209
+ const size = Number(sized);
210
+ if (size > CONTEXT_FILE_BYTES)
211
+ return answer([], null, "This file is too large to show here. Press w to see it in the browser.");
212
+ const read = viewedGitSync(repo, ["--no-replace-objects", "cat-file", "blob", oid], { timeoutMs: 10_000, maxBuffer: size + 1024, binding: { repo }, buffer: true });
213
+ if (read.status !== 0 || read.stdout.length !== size)
214
+ return answer([], null, unread);
215
+ bytes = read.stdout;
216
+ }
217
+ catch {
218
+ return answer([], null, unread);
219
+ }
220
+ let content;
221
+ try {
222
+ if (bytes.includes(0))
223
+ throw new Error("binary");
224
+ content = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
225
+ }
226
+ catch {
227
+ return answer([], null, "This file isn't text.");
228
+ }
229
+ if (keyMaterialIn(content))
230
+ return answer([], null, "This file holds what looks like a private key or secret, so its hidden lines aren't shown here.");
231
+ const all = content.split("\n");
232
+ if (all.at(-1) === "")
233
+ all.pop();
234
+ const lineCount = all.length;
235
+ const whole = all.slice(from - 1, from - 1 + count).map(line => line.replace(/\r$/, ""));
236
+ const hits = new Map(scanPatchForSecrets(["diff --git a/f b/f", `@@ -0,0 +1,${whole.length} @@`, ...whole.map(line => `+${line}`)].join("\n")).map(hit => [hit.line - 3, hit.name]));
237
+ const lines = whole.map((line, index) => {
238
+ const name = hits.get(index);
239
+ return { newLine: from + index, text: name === undefined ? line.slice(0, CONTEXT_LINE_CHARS) : `[redacted: ${name} detected on this line]` };
240
+ });
241
+ return answer(lines, lineCount, null);
242
+ }
243
+ export function setupOf(id, home = null) {
244
+ const setup = agentSetupOf(id);
245
+ if (setup === null)
246
+ return { install: null, canInstall: false, signIn: null, canSignIn: false, key: null, check: null, note: null, registry: null, registryUnsure: false };
247
+ const pkg = setup.installRun?.binary === "npm" ? setup.installRun.args[2] ?? null : null;
248
+ const registry = pkg === null || home === null ? { url: null, unsure: false } : npmRegistryOf(home, pkg);
249
+ return { install: setup.install, canInstall: setup.installRun !== null, signIn: setup.signIn, canSignIn: setup.signInRun !== null, key: setup.key, check: setup.check, note: setup.note,
250
+ registry: registry.url, registryUnsure: registry.unsure };
251
+ }
252
+ export function agentsReadOf(detection, view = "full", home = null) {
253
+ const agents = (detection?.agents ?? []).map(one => ({ id: one.id, name: one.name, state: one.state, how: one.how, signIn: one.signIn, ready: one.ready, next: one.next, setup: setupOf(one.id, home) }));
254
+ const first = detection?.firstTask ?? null;
255
+ const firstTask = first === null ? null : { id: first, name: agents.find(one => one.id === first)?.name ?? first };
256
+ if (view === "summary") {
257
+ const lines = firstTask !== null ? [`Your first task goes to ${firstTask.name}.`] : detection === null ? detectionLines(null) : [NO_AGENT_YET];
258
+ return { version: ENGINE_API_VERSION, checkedAt: detection?.checkedAt ?? null, agents: [], firstTask, lines };
259
+ }
260
+ return { version: ENGINE_API_VERSION, checkedAt: detection?.checkedAt ?? null, agents, firstTask, lines: detectionLines(detection) };
261
+ }
@@ -61,9 +61,10 @@ export async function runEvalWorld(one, input) {
61
61
  "--not", "Changing package or dependency files, or anything the goal doesn't ask for."]);
62
62
  const shown = await say(["task", "show", "work"]);
63
63
  const digest = shown["scope"]?.["digest"];
64
- if (typeof digest !== "string")
64
+ const terms = shown["approvalTerms"];
65
+ if (typeof digest !== "string" || typeof terms !== "string")
65
66
  throw new Error("the world's task has no scope to approve");
66
- await say(["task", "approve", "work", "--yes", "--digest", digest, ...auth]);
67
+ await say(["task", "approve", "work", "--yes", "--digest", digest, "--terms", terms, ...auth]);
67
68
  writeNew(join(dirname(databaseFile), "worker-token"), String(registered["token"]), 0o600);
68
69
  }
69
70
  catch (error) {
package/dist/evidence.js CHANGED
@@ -508,6 +508,8 @@ export const SECRET_PATTERNS = [
508
508
  { name: "telegram-bot-token", pattern: /\b\d{8,10}:AA[A-Za-z0-9_-]{33}\b/ },
509
509
  { name: "discord-bot-token", pattern: /\b[MN][A-Za-z\d]{23,25}\.[\w-]{6}\.[\w-]{27,}\b/ },
510
510
  { name: "password-in-url", pattern: /\b[a-z][a-z0-9+.-]*:\/\/[^\s:@/]+:[^\s:@/]{3,}@[^\s/]/i },
511
+ { name: "putty-private-key", pattern: /PuTTY-User-Key-File-\d+:/ },
512
+ { name: "aws-secret-key", pattern: /\b(?:aws_secret_access_key|SecretAccessKey)\b["']?\s*[=:]\s*["']?[A-Za-z0-9/+]{40}/i },
511
513
  ];
512
514
  export function scanForSecrets(text) {
513
515
  const hits = [];