toolroll 0.9.109 → 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 (135) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/agent-detect.js +244 -0
  3. package/dist/agent-fence.js +12 -1
  4. package/dist/agentconfig.js +2 -2
  5. package/dist/approval-summary.js +344 -0
  6. package/dist/attest.js +2 -2
  7. package/dist/browser/workspace.css +2 -2
  8. package/dist/browser/workspace.js +27 -27
  9. package/dist/builder.js +36 -2
  10. package/dist/chat-actions.js +24 -17
  11. package/dist/chat-core.js +3 -1
  12. package/dist/chat-decide.js +101 -46
  13. package/dist/chat-delivery-state.js +2 -0
  14. package/dist/chat-delivery.js +3 -2
  15. package/dist/chat-live.js +2 -1
  16. package/dist/chat-task-actions.js +6 -0
  17. package/dist/check-report.js +1 -1
  18. package/dist/cli.js +2 -0
  19. package/dist/console-instance.js +10 -1
  20. package/dist/contracts/console-api.js +10 -5
  21. package/dist/contracts/engine-api.js +271 -0
  22. package/dist/coordinator.js +2 -2
  23. package/dist/discord-api.js +4 -3
  24. package/dist/discord-chat.js +3 -1
  25. package/dist/easy-start-args.js +7 -3
  26. package/dist/easy-start.js +25 -0
  27. package/dist/egress.js +72 -10
  28. package/dist/engine-handoff.js +34 -0
  29. package/dist/engine-reads.js +261 -0
  30. package/dist/eval-world.js +3 -2
  31. package/dist/evidence.js +2 -0
  32. package/dist/fast-start.js +55 -14
  33. package/dist/fast-terms.js +2 -2
  34. package/dist/first-run.js +10 -2
  35. package/dist/flexible-agents.js +234 -0
  36. package/dist/flexible-answers-schema.js +61 -0
  37. package/dist/flexible-answers.js +889 -0
  38. package/dist/flexible-custody.js +494 -0
  39. package/dist/flexible-import.js +782 -0
  40. package/dist/flexible-launch-schema.js +72 -0
  41. package/dist/flexible-launch.js +331 -0
  42. package/dist/flexible-launcher.js +88 -0
  43. package/dist/flexible-levels.js +34 -0
  44. package/dist/flexible-merge-guard.js +47 -0
  45. package/dist/flexible-refs.js +47 -0
  46. package/dist/flexible-relay-cancel.js +19 -0
  47. package/dist/flexible-relay-schema.js +55 -0
  48. package/dist/flexible-relay-upstreams.js +36 -0
  49. package/dist/flexible-relay.js +1032 -0
  50. package/dist/flexible-session.js +732 -0
  51. package/dist/flexible-ship-schema.js +81 -0
  52. package/dist/flexible-ship.js +694 -0
  53. package/dist/flexible-start.js +80 -0
  54. package/dist/flexible-thread.js +175 -25
  55. package/dist/flexible-turns-schema.js +69 -0
  56. package/dist/flexible-turns.js +490 -0
  57. package/dist/flexible.js +10 -1
  58. package/dist/flow-actions.js +6 -4
  59. package/dist/flow-steps.js +1 -1
  60. package/dist/flows-cli.js +2 -1
  61. package/dist/git-views.js +6 -3
  62. package/dist/install-mode.js +225 -0
  63. package/dist/lead-doors.js +7 -1
  64. package/dist/limits-ui.js +7 -0
  65. package/dist/live-reply.js +6 -0
  66. package/dist/live-terminal.js +425 -29
  67. package/dist/local-owner.js +6 -0
  68. package/dist/model-choices.js +12 -6
  69. package/dist/notification-delivery.js +11 -0
  70. package/dist/operate.js +74 -30
  71. package/dist/outbound-privacy.js +204 -0
  72. package/dist/passwordless.js +2 -1
  73. package/dist/project-delete.js +14 -0
  74. package/dist/provider-connection.js +5 -3
  75. package/dist/publish.js +5 -0
  76. package/dist/pull-request-flow.js +26 -7
  77. package/dist/push.js +5 -1
  78. package/dist/release-card.js +11 -3
  79. package/dist/release.js +10 -1
  80. package/dist/route-store.js +2 -2
  81. package/dist/sandbox-launch.js +32 -8
  82. package/dist/sandbox-runtime.js +16 -7
  83. package/dist/sandbox-tools.js +176 -0
  84. package/dist/scope.js +12 -36
  85. package/dist/scout-net.js +7 -2
  86. package/dist/serve.js +58 -11
  87. package/dist/server/chrome.js +3 -1
  88. package/dist/server/console.css +33 -6
  89. package/dist/server/engine-api.js +378 -0
  90. package/dist/server/flows.js +2 -2
  91. package/dist/server/http.js +7 -0
  92. package/dist/server/link-redemption.js +52 -0
  93. package/dist/server/mutation-key.js +21 -7
  94. package/dist/server/pages.js +69 -40
  95. package/dist/server/people-tokens.js +17 -41
  96. package/dist/server/render-chat.js +1 -0
  97. package/dist/server/render-new-task.js +3 -3
  98. package/dist/server/render-results.js +4 -4
  99. package/dist/server/render-tasks.js +129 -138
  100. package/dist/server/route-table.js +30 -1
  101. package/dist/server/settings-section-table.js +3 -0
  102. package/dist/server/settings-sections.js +33 -0
  103. package/dist/server/settings.js +84 -10
  104. package/dist/server/task-views.js +8 -2
  105. package/dist/server/tasks.js +25 -8
  106. package/dist/server/terminals.js +181 -28
  107. package/dist/server/welcome.js +35 -10
  108. package/dist/settings-groups-ui.js +2 -2
  109. package/dist/settings-proofs.js +13 -9
  110. package/dist/slack-api.js +4 -3
  111. package/dist/slack-chat.js +5 -3
  112. package/dist/spend.js +46 -12
  113. package/dist/status-probe.js +343 -0
  114. package/dist/store.js +102 -5
  115. package/dist/teams-api.js +4 -3
  116. package/dist/teams-chat.js +4 -2
  117. package/dist/telegram-lead.js +2 -1
  118. package/dist/telegram-live.js +2 -1
  119. package/dist/telegram-team.js +2 -1
  120. package/dist/telegram.js +17 -5
  121. package/dist/trusted-path.js +162 -0
  122. package/dist/tui/darwin-arm64/toolroll-tui +0 -0
  123. package/dist/tui/darwin-x64/toolroll-tui +0 -0
  124. package/dist/tui/linux-arm64/toolroll-tui +0 -0
  125. package/dist/tui/linux-x64/toolroll-tui +0 -0
  126. package/dist/tui-launch.js +282 -0
  127. package/dist/tui-source.js +5 -3
  128. package/dist/tui.js +1 -1
  129. package/dist/webhooks.js +8 -4
  130. package/dist/welcome-facts.js +22 -15
  131. package/dist/workspace-ui.js +5 -0
  132. package/package.json +1 -1
  133. package/scripts/crash-canary.mjs +1 -1
  134. package/scripts/pilot.mjs +1 -1
  135. package/scripts/provider-canary.mjs +5 -3
@@ -71,6 +71,9 @@ export function projectRunning(store, repo, now) {
71
71
  const merges = count(`SELECT COUNT(*) AS n FROM merge_intent WHERE state IN ('claimed','firing') AND publication IN (SELECT id FROM publication WHERE task_ref IN (SELECT value FROM json_each(?)))`, json(d.refs))
72
72
  + count("SELECT COUNT(*) AS n FROM merge_in_flight WHERE at > ? AND task_ref IN (SELECT value FROM json_each(?))", new Date(now.getTime() - 15 * 60_000).toISOString(), json(d.refs));
73
73
  const checkouts = count("SELECT COUNT(*) AS n FROM worktree WHERE repo = ? AND runner IS NOT NULL AND released_at IS NULL", repo);
74
+ const threads = tableExists(db, "flexible_thread") ? count("SELECT COUNT(*) AS n FROM flexible_thread WHERE repo = ? AND state IN ('preparing', 'ready', 'removing')", repo) : 0;
75
+ const agents = tableExists(db, "flexible_thread_launch")
76
+ ? count("SELECT COUNT(*) AS n FROM flexible_thread_launch WHERE state <> 'exited' AND thread IN (SELECT id FROM flexible_thread WHERE repo = ?)", repo) : 0;
74
77
  return [
75
78
  ...(building > 0 ? [`${plural(building, "task")} ${building === 1 ? "is" : "are"} being built`] : []),
76
79
  ...(slots > 0 ? ["an agent is working"] : []),
@@ -79,6 +82,8 @@ export function projectRunning(store, repo, now) {
79
82
  ...(calls > 0 ? ["a subagent is working"] : []),
80
83
  ...(merges > 0 ? ["a merge is in progress"] : []),
81
84
  ...(checkouts > 0 && building === 0 ? [`${plural(checkouts, "checkout")} ${checkouts === 1 ? "is" : "are"} in use`] : []),
85
+ ...(agents > 0 ? ["a Flexible thread's agent is still running"] : []),
86
+ ...(threads > 0 ? [`${plural(threads, "Flexible thread")} ${threads === 1 ? "is" : "are"} still open (remove ${threads === 1 ? "it" : "them"} first)`] : []),
82
87
  ];
83
88
  }
84
89
  const inside = (root, path) => { const rel = relative(resolve(root), resolve(path)); return rel !== "" && !rel.startsWith("..") && !isAbsolute(rel); };
@@ -294,6 +299,15 @@ function deleteRows(store, repo, d, now) {
294
299
  for (const table of ["knowledge_change", "project_identity_carry", "project_skill_change", "memory_gap", "memory_proposal", "memory_rejection", "memory_session", "memory_search", "mode_rail", "side_spend", "watch_episode", "worktree", "coordinator_proposal", "lead_commitment"])
295
300
  del(table, "repo = ?", repo);
296
301
  del("watch_lease", "repo = ? AND expires_at <= ?", repo, now.toISOString());
302
+ const flexibleThreads = `thread IN (SELECT id FROM flexible_thread WHERE repo = ? AND state IN ('removed', 'failed'))`;
303
+ del("thread_decision", flexibleThreads, repo);
304
+ del("thread_relay_call", flexibleThreads, repo);
305
+ del("thread_relay_pending", flexibleThreads, repo);
306
+ del("flexible_relay_grant", flexibleThreads, repo);
307
+ del("thread_turn", flexibleThreads, repo);
308
+ del("flexible_thread_launch", flexibleThreads, repo);
309
+ del("flexible_thread_level", flexibleThreads, repo);
310
+ del("flexible_thread", "repo = ? AND state IN ('removed', 'failed')", repo);
297
311
  del("project", "path = ?", repo);
298
312
  return rows;
299
313
  }
@@ -1,5 +1,6 @@
1
1
  import { homedir } from "node:os";
2
- import { run } from "./exec.js";
2
+ import {} from "./exec.js";
3
+ import { statusProbe } from "./status-probe.js";
3
4
  import { ALL_CREDENTIAL_ENV, inspectionOf } from "./provider.js";
4
5
  import { isAcpProvider } from "./acp-agents.js";
5
6
  import { keyStatus, PROVIDER_KEY_ENV, readAuthMode, readProviderKey, verifyProviderKey } from "./keys.js";
@@ -39,9 +40,10 @@ export function signInFacts(provider, result, now = new Date()) {
39
40
  return { ...base, state: "unverified" };
40
41
  }
41
42
  export function createConnectionChecker(options = {}) {
42
- const probe = options.probe ?? run;
43
- const verify = options.verify ?? ((provider, key) => verifyProviderKey(provider, key));
44
43
  const home = options.home ?? homedir();
44
+ const probe = options.probe ?? statusProbe({ ...(options.env === undefined ? {} : { env: options.env }), ...(options.store === undefined ? {} : { store: options.store }),
45
+ ...(options.databaseFile === undefined ? {} : { databaseFile: options.databaseFile }) });
46
+ const verify = options.verify ?? ((provider, key) => verifyProviderKey(provider, key));
45
47
  const clock = options.clock ?? (() => new Date());
46
48
  const cache = new Map();
47
49
  const pending = new Map();
package/dist/publish.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { flexibleMergeRefusal } from "./flexible-merge-guard.js";
1
2
  import { createHash } from "node:crypto";
2
3
  import { protectedPublicationHold } from "./result-completion.js";
3
4
  import { fastPublishProblem } from "./fast-start.js";
@@ -427,6 +428,10 @@ export async function sweepMerges(store, options) {
427
428
  continue;
428
429
  if (publication.githubRepo !== grant.githubRepo)
429
430
  continue;
431
+ if (flexibleMergeRefusal(store, ref.externalId, "publish-sweep") !== null) {
432
+ report.skipped++;
433
+ continue;
434
+ }
430
435
  const blocker = store.mergeBlockerFor(publication.id);
431
436
  if (blocker !== null) {
432
437
  report.skipped++;
@@ -1,6 +1,7 @@
1
1
  import { fastPublishProblem } from "./fast-start.js";
2
2
  import { createHash, randomUUID } from "node:crypto";
3
3
  import { run as execRun } from "./exec.js";
4
+ import { flexibleMergeRefusal } from "./flexible-merge-guard.js";
4
5
  import { bodyHashOf, publicationBody, publicationGrantOf } from "./publish.js";
5
6
  import { failingChecks, summarizeChecks } from "./pulls.js";
6
7
  import { assignmentOf, checkAssignmentAsOperator } from "./assignment.js";
@@ -254,6 +255,8 @@ export async function followPullRequests(store, seen, options) {
254
255
  const taskId = taskIdOf(store, publication);
255
256
  if (refArchived(store, publication.taskRef))
256
257
  continue;
258
+ if (flexibleMergeRefusal(store, taskId, "merge-when-green") !== null)
259
+ continue;
257
260
  if (one.remoteState === "MERGED") {
258
261
  updateFollow(store, publication.id, { merge_commit: one.mergeCommit ?? "", merged_by: "GitHub", merged_at: clock().toISOString() }, clock());
259
262
  continue;
@@ -363,6 +366,10 @@ export async function mergePullRequest(store, input) {
363
366
  return refuse("release", "This result belongs to a release; it merges only through `toolroll release`.");
364
367
  if (mergedTask !== null && autoReleaseSealed(store, mergedTask))
365
368
  return refuse("release", "This result was approved automatically for a release; it merges only through `toolroll release`.");
369
+ const flexibleAuthority = { ...(input.flexibleShip === undefined ? {} : { ship: input.flexibleShip }), ...(input.flexibleToken === undefined ? {} : { token: input.flexibleToken }), ...(input.anyway === true ? { anyway: true } : {}) };
370
+ const flexibleHold = flexibleMergeRefusal(store, mergedTask, "pull-request", flexibleAuthority);
371
+ if (flexibleHold !== null)
372
+ return refuse("flexible", flexibleHold);
366
373
  const fastHold = mergedTask === null ? null : fastPublishProblem(store, mergedTask, input.runId);
367
374
  if (fastHold !== null)
368
375
  return refuse("fast-start", fastHold);
@@ -370,7 +377,9 @@ export async function mergePullRequest(store, input) {
370
377
  const follow = publication === null ? null : followOf(store, publication.id);
371
378
  if (publication === null || follow === null || publication.prNumber === null)
372
379
  return refuse("no-pr", "This result has no open pull request to merge.");
373
- if (follow.mergeCommit !== null)
380
+ if (input.flexibleShip !== undefined && input.destination === undefined)
381
+ return refuse("flexible", "A Flexible merge must say where it may land.");
382
+ if (follow.mergeCommit !== null && input.destination === undefined)
374
383
  return { ok: true, commit: follow.mergeCommit || null };
375
384
  const ref = store.refById(publication.taskRef);
376
385
  const grant = ref?.repo == null ? null : store.publicationGrantFor(ref.repo);
@@ -379,13 +388,14 @@ export async function mergePullRequest(store, input) {
379
388
  const method = input.method ?? grant.mergeMethod ?? "squash";
380
389
  const pr = String(publication.prNumber);
381
390
  const view = async () => {
382
- const viewed = await exec("gh", ["pr", "view", pr, "--repo", publication.githubRepo, "--json", "state,isDraft,headRefOid,statusCheckRollup,mergeCommit"], { timeoutMs: EXEC_TIMEOUT_MS });
391
+ const viewed = await exec("gh", ["pr", "view", pr, "--repo", publication.githubRepo, "--json", "state,isDraft,headRefOid,statusCheckRollup,mergeCommit,baseRefName,url"], { timeoutMs: EXEC_TIMEOUT_MS });
383
392
  if (viewed.code !== 0)
384
393
  return null;
385
394
  try {
386
395
  const payload = JSON.parse(viewed.stdout);
387
396
  return { state: String(payload.state ?? "").toUpperCase(), draft: payload.isDraft === true, head: typeof payload.headRefOid === "string" ? payload.headRefOid : null,
388
- checks: summarizeChecks(payload.statusCheckRollup), commit: typeof payload.mergeCommit?.oid === "string" ? payload.mergeCommit.oid : null };
397
+ checks: summarizeChecks(payload.statusCheckRollup), commit: typeof payload.mergeCommit?.oid === "string" ? payload.mergeCommit.oid : null,
398
+ base: typeof payload.baseRefName === "string" ? payload.baseRefName : null, url: typeof payload.url === "string" ? payload.url : null };
389
399
  }
390
400
  catch {
391
401
  return null;
@@ -418,8 +428,12 @@ export async function mergePullRequest(store, input) {
418
428
  if (before === null)
419
429
  return fail("unread", "GitHub couldn't be read just now. Try again.");
420
430
  if (before.state === "MERGED") {
421
- record(before.commit, input.by);
422
- return { ok: true, commit: before.commit };
431
+ const landed = input.destination?.({ base: before.base, url: before.url, head: before.head }) ?? null;
432
+ if (landed !== null)
433
+ return refuse("elsewhere", landed);
434
+ if (follow.mergeCommit === null)
435
+ record(before.commit, input.by);
436
+ return { ok: true, commit: before.commit, ...(input.destination === undefined ? {} : { seen: { base: before.base, url: before.url, head: before.head } }) };
423
437
  }
424
438
  if (before.state !== "OPEN")
425
439
  return fail("closed", "This pull request is closed on GitHub.");
@@ -431,7 +445,9 @@ export async function mergePullRequest(store, input) {
431
445
  return fail("checks", before.checks === "failing" ? "Checks are failing, so it can't merge." : before.checks === "running" ? "Checks are still running. Merge once they pass." : "No checks have reported yet. Merge once they pass.");
432
446
  const token = randomUUID();
433
447
  const reserved = store.transact(() => {
434
- if (input.proceed?.() === false)
448
+ if (input.proceed?.({ base: before.base, url: before.url, head: before.head }) === false)
449
+ return "halted";
450
+ if (flexibleMergeRefusal(store, mergedTask, "pull-request", flexibleAuthority, "reserve") !== null)
435
451
  return "halted";
436
452
  if (refArchived(store, publication.taskRef))
437
453
  return "archived";
@@ -459,8 +475,11 @@ export async function mergePullRequest(store, input) {
459
475
  store.handle.prepare("DELETE FROM merge_in_flight WHERE publication = ? AND token = ?").run(publication.id, token);
460
476
  }
461
477
  if (after?.state === "MERGED") {
478
+ const landed = input.destination?.({ base: after.base, url: after.url, head: after.head }) ?? null;
479
+ if (landed !== null)
480
+ return refuse("elsewhere", landed);
462
481
  record(after.commit, input.by);
463
- return { ok: true, commit: after.commit };
482
+ return { ok: true, commit: after.commit, ...(input.destination === undefined ? {} : { seen: { base: after.base, url: after.url, head: after.head } }) };
464
483
  }
465
484
  if (merged.code === 4)
466
485
  return fail("gh-signed-out", "The GitHub CLI isn't signed in on this computer. Run gh auth login, then merge again.");
package/dist/push.js CHANGED
@@ -3,6 +3,7 @@ import { join } from "node:path";
3
3
  import { createCipheriv, createECDH, createPrivateKey, hkdfSync, randomBytes, createHash, sign as cryptoSign } from "node:crypto";
4
4
  import { isCheckProgressLine } from "./check-progress.js";
5
5
  import { RELEASE_PUSH_WORDS, releasePushOf, releaseReadyObsolete } from "./release-approval.js";
6
+ import { privateValue } from "./outbound-privacy.js";
6
7
  export const VAPID_FILE = "vapid-keys.json";
7
8
  const RECORD_SIZE = 4096;
8
9
  export const PLAINTEXT_CEILING = 3993;
@@ -190,8 +191,11 @@ export function pushLineOf(notification) {
190
191
  }
191
192
  return { body: PUSH_WORDS[pushClass].body, url: safePushLink(pushClass, notification.link) };
192
193
  }
194
+ export function privacySafeLine(line, pushClass) {
195
+ return privateValue(line) ? { body: PUSH_WORDS[pushClass].body, url: CLASS_FALLBACK[pushClass] } : line;
196
+ }
193
197
  export function buildPushPayload(notification, waiting = null, release = null) {
194
- const line = release !== null ? { body: PUSH_WORDS.release.body, url: safePushLink("release", release.link) } : pushLineOf(notification);
198
+ const line = privacySafeLine(release !== null ? { body: PUSH_WORDS.release.body, url: safePushLink("release", release.link) } : pushLineOf(notification), release !== null ? "release" : notification.pushClass ?? "attention");
195
199
  return JSON.stringify({
196
200
  title: "Toolroll",
197
201
  body: line.body,
@@ -93,11 +93,18 @@ const valueAt = (terms, path) => path.split(".").reduce((at, key) => at !== null
93
93
  export function approvalTermsOf(store, scope, words) {
94
94
  const ref = store.lookupRef(scope.taskId);
95
95
  const repo = ref?.repo ?? null;
96
+ const where = (path) => {
97
+ if (words.chat !== true)
98
+ return text(path);
99
+ const remote = store.projectRemote(path);
100
+ const slug = remote === null ? null : releaseRemote(remote)?.slug ?? null;
101
+ return slug ?? text(projectName(path));
102
+ };
96
103
  const filer = store.taskFiler(scope.taskId);
97
104
  const profile = scope.profile ?? null;
98
105
  const scopeValues = {
99
106
  title: said(store.getTask(scope.taskId)?.title),
100
- project: repo === null ? NONE : `${text(projectName(repo))} (${text(repo)})`,
107
+ project: repo === null ? NONE : `${text(projectName(repo))} (${where(repo)})`,
101
108
  filedBy: filer === null ? NONE : filer.name === null ? filer.kind : `${text(filer.name)}${filer.kind === "person" ? "" : ` (${filer.kind})`}`,
102
109
  goal: said(scope.goal),
103
110
  outOfScope: said(scope.outOfScope),
@@ -127,7 +134,7 @@ export function approvalTermsOf(store, scope, words) {
127
134
  if (terms === null && scope.releaseCheck != null) {
128
135
  const purpose = scope.releaseCheck;
129
136
  for (const path of schemaLeaves(releaseCheckPurposeSchema)) {
130
- const value = path === "pr" ? `#${purpose.pr}` : path === "purpose" ? "a release check: every later commit asks again" : said(valueAt(purpose, path));
137
+ const value = path === "pr" ? `#${purpose.pr}` : path === "purpose" ? "a release check: every later commit asks again" : path === "repo" ? where(purpose.repo) : said(valueAt(purpose, path));
131
138
  lines.push({ key: `releaseCheck.${path}`, label: RELEASE_CHECK_LABELS[path] ?? path, value });
132
139
  }
133
140
  return lines;
@@ -136,7 +143,8 @@ export function approvalTermsOf(store, scope, words) {
136
143
  const label = RELEASE_TERM_LABELS[path] ?? path;
137
144
  const value = terms === null ? NONE : path === "pr" ? `#${terms.pr}`
138
145
  : path === "policy.protectedPaths" && terms.policy.protectProject ? `the whole project (listed: ${said(terms.policy.protectedPaths)})`
139
- : path === "policy.unsandboxedCarry" && terms.policy.unsandboxedCarry === undefined ? "no (not set when sealed)" : said(valueAt(terms, path));
146
+ : path === "policy.unsandboxedCarry" && terms.policy.unsandboxedCarry === undefined ? "no (not set when sealed)"
147
+ : path === "repo" ? where(terms.repo) : said(valueAt(terms, path));
140
148
  lines.push({ key: `release.${path}`, label, value });
141
149
  }
142
150
  return lines;
package/dist/release.js CHANGED
@@ -37,8 +37,17 @@ export const ADVISORY_PR_CHECKS = {
37
37
  "install smoke · ubuntu-24.04": ".github/workflows/install-smoke.yml",
38
38
  "install smoke · macos-latest": ".github/workflows/install-smoke.yml",
39
39
  "wire budgets": ".github/workflows/wire-budgets.yml",
40
+ "rust · ubuntu-latest": ".github/workflows/rust.yml",
41
+ "rust · macos-latest": ".github/workflows/rust.yml",
42
+ "workbench bundle · ubuntu-24.04": ".github/workflows/tui-bundle.yml",
43
+ "workbench bundle · macos-latest": ".github/workflows/tui-bundle.yml",
44
+ "workbench bundle / binary · darwin-arm64": ".github/workflows/tui-bundle.yml",
45
+ "workbench bundle / binary · darwin-x64": ".github/workflows/tui-bundle.yml",
46
+ "workbench bundle / binary · linux-x64": ".github/workflows/tui-bundle.yml",
47
+ "workbench bundle / binary · linux-arm64": ".github/workflows/tui-bundle.yml",
48
+ "workbench bundle / assemble": ".github/workflows/tui-bundle.yml",
40
49
  };
41
- export const RELEASE_TAG_CHECKS = ["release proof", "publish"];
50
+ export const RELEASE_TAG_CHECKS = ["release proof", "package / binary · darwin-arm64", "package / binary · darwin-x64", "package / binary · linux-x64", "package / binary · linux-arm64", "package / assemble", "publish"];
42
51
  export const RELEASE_TAG_WORKFLOW = ".github/workflows/publish.yml";
43
52
  export const RELEASE_STEPS = ["gate", "approval", "check", "complete", "quiet", "deploy", "link", "ci", "merge", "tree", "tag", "publish", "homebrew", "done"];
44
53
  export const RELEASE_LIMITS = { gate: 60, approval: 24 * 60, check: 360, quiet: 60, deploy: 30, ci: 60, publish: 45, homebrew: 45 };
@@ -1,7 +1,7 @@
1
1
  import { isProtectedWork } from "./approval-policy.js";
2
2
  import { trialSealStandsSql } from "./approval-authority.js";
3
3
  import { currentLocalOwner, localOwnerInFlight, localOwnerStandsNow } from "./local-owner.js";
4
- import { passwordlessOn } from "./passwordless.js";
4
+ import { sessionStandsIn } from "./install-mode.js";
5
5
  import { machineActing } from "./scope.js";
6
6
  import { NOT_COUNTED_REASONS, RECORD_STATES, REJECT_REASONS, REVISION_ORIGINS } from "./contracts/route-results.js";
7
7
  import { BUILT_IN, nightlyTaskRef, releaseTaskRef } from "./store.js";
@@ -209,7 +209,7 @@ export function proveRuleDoor(store, door, act, repo) {
209
209
  return { ok: false, reason: "lead-refused" };
210
210
  const account = store.accountOf(person.actor);
211
211
  const proof = spec.raising
212
- ? RAISING_PROOFS.has(person.method) && ((person.method !== "session" && person.method !== "cli-login") || passwordlessOn(store))
212
+ ? RAISING_PROOFS.has(person.method) && ((person.method !== "session" && person.method !== "cli-login") || sessionStandsIn(store))
213
213
  : RAISING_PROOFS.has(person.method) || person.method === "local-owner";
214
214
  if (account === null || account.revokedAt !== null || account.generation !== person.generation || !store.isInstanceOperator(person.actor)
215
215
  || !store.accountCanAccess(person.actor, repo) || !person.live() || !proof)
@@ -1,13 +1,25 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { checkLinuxDependencies, cleanupBwrapMountPoints, getLinuxDependencyStatus, initializeLinuxNetworkBridge, wrapCommandWithSandboxLinux } from "@anthropic-ai/sandbox-runtime/dist/sandbox/linux-sandbox-utils.js";
3
3
  import { SANDBOX_LAUNCH_SPEC, shellQuote, withRuntimeTemp } from "./sandbox-runtime.js";
4
+ import { isLinuxSandboxTools, sandboxToolExclusions, verifyLinuxSandboxTools } from "./sandbox-tools.js";
4
5
  const REFUSED = 126;
5
6
  const STOPPED = 143;
6
- function missing() {
7
- const checked = checkLinuxDependencies();
7
+ const pathsOf = (tools) => ({ bwrapPath: tools.bwrap.real, socatPath: tools.socat.real, seccompConfig: { applyPath: tools.seccomp.real } });
8
+ function missing(tools, exclusions) {
9
+ const changed = verifyLinuxSandboxTools(tools, { exclusions });
10
+ if (changed !== null)
11
+ return changed;
12
+ const paths = pathsOf(tools);
13
+ const checked = checkLinuxDependencies(paths);
8
14
  if (checked.errors.length > 0)
9
15
  return checked.errors.join("; ");
10
- return getLinuxDependencyStatus().hasSeccompApply ? null : "the sandbox runtime's seccomp helper isn't available";
16
+ return getLinuxDependencyStatus(paths).hasSeccompApply ? null : "the sandbox runtime's seccomp helper isn't available";
17
+ }
18
+ function toolsProblem(spec) {
19
+ const tools = spec.tools;
20
+ if (!isLinuxSandboxTools(tools))
21
+ return "the sandbox's programs weren't given by checked paths";
22
+ return verifyLinuxSandboxTools(tools, { exclusions: sandboxToolExclusions(spec.terms, spec.cwd) });
11
23
  }
12
24
  async function main() {
13
25
  const raw = process.env[SANDBOX_LAUNCH_SPEC];
@@ -17,6 +29,15 @@ async function main() {
17
29
  return REFUSED;
18
30
  }
19
31
  const spec = JSON.parse(raw);
32
+ const problem = toolsProblem(spec);
33
+ if (problem !== null) {
34
+ process.stderr.write(`toolroll sandbox: nothing was started: ${problem}\n`);
35
+ return REFUSED;
36
+ }
37
+ const tools = spec.tools;
38
+ const exclusions = sandboxToolExclusions(spec.terms, spec.cwd);
39
+ const launchEnv = { ...process.env };
40
+ process.env["PATH"] = tools.whichFolder;
20
41
  process.chdir(spec.cwd);
21
42
  let stopping = false;
22
43
  let child = null;
@@ -49,7 +70,7 @@ async function main() {
49
70
  };
50
71
  try {
51
72
  if (network.kind === "proxy")
52
- bridge = await initializeLinuxNetworkBridge(network.httpPort, network.socksPort ?? network.httpPort);
73
+ bridge = await initializeLinuxNetworkBridge(network.httpPort, network.socksPort ?? network.httpPort, tools.socat.real);
53
74
  if (spec.temp !== undefined)
54
75
  process.env["CLAUDE_CODE_TMPDIR"] = spec.temp;
55
76
  else
@@ -58,7 +79,7 @@ async function main() {
58
79
  for (let attempt = 1;; attempt++) {
59
80
  if (stopping)
60
81
  return STOPPED;
61
- const gone = missing();
82
+ const gone = missing(tools, exclusions);
62
83
  if (gone !== null)
63
84
  throw new Error(`the sandbox can't be made here: ${gone}`);
64
85
  const command = await wrapCommandWithSandboxLinux({
@@ -71,12 +92,15 @@ async function main() {
71
92
  }),
72
93
  readConfig: spec.terms.readConfig,
73
94
  writeConfig: spec.terms.writeConfig,
95
+ ...pathsOf(tools),
96
+ binShell: tools.bash.real,
97
+ ripgrepConfig: { command: tools.rg.real },
74
98
  });
75
- if (!/\bbwrap\b/.test(command) || !command.includes("apply-seccomp"))
76
- throw new Error("the sandbox runtime returned a command without its sandbox or its seccomp filter");
99
+ if (!/\bbwrap\b/.test(command) || ![tools.bwrap.real, tools.seccomp.real, tools.bash.real].every(path => command.includes(path)) || !command.includes("apply-seccomp"))
100
+ throw new Error("the sandbox runtime returned a command without its sandbox, its seccomp filter or the programs it was handed");
77
101
  if (stopping)
78
102
  return STOPPED;
79
- const run = spawn("/bin/sh", ["-c", command], { stdio: ["inherit", "inherit", "pipe", "pipe"] });
103
+ const run = spawn("/bin/sh", ["-c", command], { stdio: ["inherit", "inherit", "pipe", "pipe"], env: launchEnv });
80
104
  child = run;
81
105
  let ran = false;
82
106
  const held = [];
@@ -5,6 +5,7 @@ import { delimiter, dirname, join } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import { wrapCommandWithSandboxMacOS } from "@anthropic-ai/sandbox-runtime/dist/sandbox/macos-sandbox-utils.js";
7
7
  import { checkLinuxDependencies, getLinuxDependencyStatus } from "@anthropic-ai/sandbox-runtime/dist/sandbox/linux-sandbox-utils.js";
8
+ import { linuxSandboxTools, sandboxToolExclusions } from "./sandbox-tools.js";
8
9
  const require = createRequire(import.meta.url);
9
10
  export const SANDBOX_RUNTIME = (() => {
10
11
  const name = "@anthropic-ai/sandbox-runtime";
@@ -30,14 +31,19 @@ export function sandboxRuntimeProblem(platform = process.platform) {
30
31
  const missing = missingLinuxSandboxTools();
31
32
  if (missing.length > 0)
32
33
  return `${toolWords(missing)} ${missing.length === 1 ? "is" : "are"} not installed (${linuxSandboxInstallLine(missing)})`;
33
- const checked = checkLinuxDependencies();
34
+ const resolved = linuxSandboxTools();
35
+ if (!resolved.ok)
36
+ return resolved.why;
37
+ const { tools } = resolved;
38
+ const paths = { bwrapPath: tools.bwrap.real, socatPath: tools.socat.real, seccompConfig: { applyPath: tools.seccomp.real } };
39
+ const checked = checkLinuxDependencies(paths);
34
40
  if (checked.errors.length > 0)
35
41
  return checked.errors.join("; ");
36
- if (!getLinuxDependencyStatus().hasSeccompApply)
42
+ if (!getLinuxDependencyStatus(paths).hasSeccompApply)
37
43
  return "the sandbox runtime's seccomp helper isn't available for this processor";
38
- if (spawnSync("rg", ["--version"], { timeout: 5_000, stdio: "ignore" }).status !== 0)
39
- return "ripgrep (rg) is not installed";
40
- const probe = spawnSync("bwrap", ["--ro-bind", "/", "/", "--unshare-pid", "--unshare-user", "--proc", "/proc", "--new-session", "--", "true"], { timeout: 5_000, stdio: "ignore" });
44
+ if (spawnSync(tools.rg.real, ["--version"], { timeout: 5_000, stdio: "ignore" }).status !== 0)
45
+ return `ripgrep (${tools.rg.real}) doesn't run`;
46
+ const probe = spawnSync(tools.bwrap.real, ["--ro-bind", "/", "/", "--unshare-pid", "--unshare-user", "--proc", "/proc", "--new-session", "--", "true"], { timeout: 5_000, stdio: "ignore" });
41
47
  return probe.status === 0 ? null : "bubblewrap can't start a sandbox here (unprivileged user namespaces may be off)";
42
48
  }
43
49
  return `the sandbox runtime has no sandbox for ${platform}`;
@@ -241,13 +247,16 @@ export const sandboxLaunchHelper = () => {
241
247
  const beside = fileURLToPath(new URL("./sandbox-launch.js", import.meta.url));
242
248
  return existsSync(beside) ? beside : fileURLToPath(new URL("../dist/sandbox-launch.js", import.meta.url));
243
249
  };
244
- export function srtSpawn(file, args, terms, cwd = process.cwd(), temp, platform = process.platform) {
250
+ export function srtSpawn(file, args, terms, cwd = process.cwd(), temp, platform = process.platform, tools = linuxSandboxTools) {
245
251
  if (platform === "darwin") {
246
252
  const command = srtMacosCommand(file, args, terms, cwd, temp);
247
253
  if (!command.includes(SANDBOX_EXEC))
248
254
  throw new Error("the sandbox runtime returned the command unsandboxed");
249
255
  return { file: "/usr/bin/perl", args: [...DETACH, "/bin/sh", "-c", command], env: {} };
250
256
  }
251
- const spec = { file, args: [...args], cwd, terms, ...(temp === undefined ? {} : { temp }) };
257
+ const resolved = tools(sandboxToolExclusions(terms, cwd));
258
+ if (!resolved.ok)
259
+ throw new Error(resolved.why);
260
+ const spec = { file, args: [...args], cwd, terms, tools: resolved.tools, ...(temp === undefined ? {} : { temp }) };
252
261
  return { file: process.execPath, args: [sandboxLaunchHelper()], env: { [SANDBOX_LAUNCH_SPEC]: JSON.stringify(spec) } };
253
262
  }
@@ -0,0 +1,176 @@
1
+ import { accessSync, constants as fsConstants, existsSync, lstatSync, realpathSync, statSync } from "node:fs";
2
+ import { createRequire } from "node:module";
3
+ import { dirname, join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { platformAcl, rootOwnedBinary, rootOwnedFolders } from "./trusted-path.js";
6
+ export const SANDBOX_TOOL_FOLDERS = ["/usr/bin", "/bin", "/usr/sbin", "/sbin", "/usr/local/bin", "/run/current-system/sw/bin"];
7
+ const SYSTEM_TOOLS = [
8
+ { key: "bwrap", command: "bwrap", words: "bubblewrap (bwrap)", install: "bubblewrap" },
9
+ { key: "socat", command: "socat", words: "socat", install: "socat" },
10
+ { key: "bash", command: "bash", words: "bash", install: "bash" },
11
+ { key: "rg", command: "rg", words: "ripgrep (rg)", install: "ripgrep" },
12
+ { key: "which", command: "which", words: "which", install: "which" },
13
+ ];
14
+ const KEYS = [...SYSTEM_TOOLS.map(tool => tool.key), "seccomp"];
15
+ const insideOrAt = (path, root) => path === root || path.startsWith(root.endsWith("/") ? root : `${root}/`);
16
+ const realOrSelf = (path) => { try {
17
+ return realpathSync(path);
18
+ }
19
+ catch {
20
+ return path;
21
+ } };
22
+ const require = createRequire(import.meta.url);
23
+ export function seccompHelperPath(arch = process.arch) {
24
+ const vendor = arch === "x64" ? "x64" : arch === "arm64" ? "arm64" : null;
25
+ if (vendor === null)
26
+ return null;
27
+ try {
28
+ return join(dirname(require.resolve("@anthropic-ai/sandbox-runtime")), "..", "vendor", "seccomp", vendor, "apply-seccomp");
29
+ }
30
+ catch {
31
+ return null;
32
+ }
33
+ }
34
+ function codeOwnerNow() {
35
+ try {
36
+ return lstatSync(realpathSync(fileURLToPath(import.meta.url))).uid;
37
+ }
38
+ catch {
39
+ return undefined;
40
+ }
41
+ }
42
+ const NO_EXCLUSIONS = { all: [] };
43
+ const withReal = (paths) => [...new Set(paths.flatMap(path => [path, realOrSelf(path)]))];
44
+ export function sandboxToolExclusions(terms, cwd) {
45
+ const write = terms.writeConfig;
46
+ const roots = (paths) => withReal(paths.map(path => path.replace(/\/?\*.*$/, "")).filter(path => path !== "" && path !== "/" && path.startsWith("/")));
47
+ const allow = withReal([...write.allowOnly, ...write.literalAllowOnly ?? []].map(path => path.includes("*") ? dirname(path.replace(/\*.*$/, "x")) : path).filter(path => path.startsWith("/")));
48
+ const deny = withReal([...write.denyWithinAllow, ...write.literalDenyWithinAllow ?? []].filter(path => path.startsWith("/") && !path.includes("*")));
49
+ return { all: roots([cwd, ...write.allowOnly, ...write.literalAllowOnly ?? [], ...write.denyWithinAllow, ...terms.readConfig.denyOnly]), writes: { allow, deny } };
50
+ }
51
+ const mayWrite = (writes, path) => writes.allow.some(root => insideOrAt(path, root)) && !writes.deny.some(root => insideOrAt(path, root));
52
+ const installWords = (pkg) => `install ${pkg} from your system package manager (sudo apt install ${pkg}; Fedora: sudo dnf install ${pkg})`;
53
+ function identify(real) {
54
+ try {
55
+ accessSync(real, fsConstants.X_OK);
56
+ const file = statSync(real, { bigint: true });
57
+ return { ok: true, tool: { real, id: `${file.dev}:${file.ino}:${file.ctimeNs}` } };
58
+ }
59
+ catch {
60
+ return { ok: false, why: `${real} can't be run` };
61
+ }
62
+ }
63
+ function checkSystem(path, trust, exclusions) {
64
+ const checked = rootOwnedBinary(path, trust.acl, trust.root);
65
+ if (!checked.ok)
66
+ return checked;
67
+ if (exclusions.all.some(root => insideOrAt(checked.real, root)))
68
+ return { ok: false, why: `${checked.real} is inside a project, worktree or Toolroll's own folder` };
69
+ return identify(checked.real);
70
+ }
71
+ export function checkSeccompHelper(path, exclusions, trust = {}) {
72
+ const t = trustOf(trust);
73
+ const owners = t.codeOwner === undefined ? t.root : [...t.root, t.codeOwner];
74
+ const checked = rootOwnedBinary(path, t.acl, owners, "root or Toolroll's own user");
75
+ if (!checked.ok)
76
+ return checked;
77
+ const writes = exclusions.writes;
78
+ if (writes !== undefined && !rootOwnedBinary(checked.real, t.acl, t.root).ok) {
79
+ if (mayWrite(writes, checked.real))
80
+ return { ok: false, why: `the launch may write ${checked.real}, and the helper isn't root's own` };
81
+ if (!writes.deny.some(root => insideOrAt(checked.real, root)))
82
+ return { ok: false, why: `the fence's install-tree write denies don't cover ${checked.real}` };
83
+ }
84
+ return identify(checked.real);
85
+ }
86
+ const trustOf = (trust) => ({ root: trust.root ?? [0], codeOwner: "codeOwner" in trust ? trust.codeOwner : codeOwnerNow(), acl: "acl" in trust ? trust.acl ?? null : platformAcl() });
87
+ export function resolveLinuxSandboxTools(options = {}) {
88
+ const folders = options.folders ?? SANDBOX_TOOL_FOLDERS;
89
+ const exclusions = options.exclusions ?? NO_EXCLUSIONS;
90
+ const trust = trustOf(options);
91
+ const found = {};
92
+ let whichFolder = null;
93
+ for (const tool of SYSTEM_TOOLS) {
94
+ const passedOver = [];
95
+ for (const folder of folders) {
96
+ const candidate = join(folder, tool.command);
97
+ if (!existsSync(candidate))
98
+ continue;
99
+ const checked = checkSystem(candidate, trust, exclusions);
100
+ if (!checked.ok) {
101
+ passedOver.push(`${candidate}: ${checked.why}`);
102
+ continue;
103
+ }
104
+ if (tool.key === "which") {
105
+ const dir = rootOwnedFolders(folder, trust.acl, trust.root);
106
+ if (!dir.ok) {
107
+ passedOver.push(`${candidate}: ${dir.why}`);
108
+ continue;
109
+ }
110
+ whichFolder = dir.real;
111
+ }
112
+ found[tool.key] = checked.tool;
113
+ break;
114
+ }
115
+ if (found[tool.key] === undefined) {
116
+ return { ok: false, why: `${tool.words} has no copy owned by root in ${folders.join(", ")}${passedOver.length === 0 ? "" : ` (${passedOver.join("; ")})`}: ${installWords(tool.install)}` };
117
+ }
118
+ }
119
+ const helper = "seccomp" in options ? options.seccomp ?? null : seccompHelperPath();
120
+ if (helper === null)
121
+ return { ok: false, why: `the sandbox runtime's seccomp helper isn't available for this processor (${process.arch})` };
122
+ const checked = checkSeccompHelper(helper, exclusions, options);
123
+ if (!checked.ok)
124
+ return { ok: false, why: `the sandbox runtime's seccomp helper (${helper}) can't be trusted: ${checked.why}` };
125
+ found.seccomp = checked.tool;
126
+ return { ok: true, tools: { ...found, whichFolder: whichFolder } };
127
+ }
128
+ export function verifyLinuxSandboxTools(tools, options = {}) {
129
+ const trust = trustOf(options);
130
+ const exclusions = options.exclusions ?? NO_EXCLUSIONS;
131
+ for (const key of KEYS) {
132
+ const tool = tools[key];
133
+ const checked = key === "seccomp" ? checkSeccompHelper(tool.real, exclusions, options) : checkSystem(tool.real, trust, exclusions);
134
+ if (!checked.ok)
135
+ return `${key} (${tool.real}): ${checked.why}`;
136
+ if (checked.tool.real !== tool.real || checked.tool.id !== tool.id)
137
+ return `${key} (${tool.real}) changed since it was checked`;
138
+ }
139
+ const helper = "seccomp" in options ? options.seccomp ?? null : seccompHelperPath();
140
+ if (helper === null || realOrSelf(helper) !== tools.seccomp.real)
141
+ return `the seccomp helper (${tools.seccomp.real}) isn't Toolroll's own sandbox-runtime's`;
142
+ const dir = rootOwnedFolders(tools.whichFolder, trust.acl, trust.root);
143
+ if (!dir.ok || dir.real !== tools.whichFolder)
144
+ return `which's folder (${tools.whichFolder}) ${dir.ok ? "changed" : dir.why}`;
145
+ if (realOrSelf(join(tools.whichFolder, "which")) !== tools.which.real)
146
+ return `which in ${tools.whichFolder} changed since it was checked`;
147
+ return null;
148
+ }
149
+ export function isLinuxSandboxTools(value) {
150
+ if (value === null || typeof value !== "object")
151
+ return false;
152
+ const record = value;
153
+ const path = (one) => typeof one === "string" && one.startsWith("/") && !/[\u0000-\u001f\u007f]/.test(one);
154
+ if (!path(record["whichFolder"]))
155
+ return false;
156
+ return KEYS.every(key => {
157
+ const tool = record[key];
158
+ return tool !== null && typeof tool === "object" && path(tool["real"]) && typeof tool["id"] === "string" && /^\d+:\d+:\d+$/.test(tool["id"]);
159
+ });
160
+ }
161
+ let discovered = null;
162
+ export function linuxSandboxTools(exclusions = NO_EXCLUSIONS) {
163
+ if (discovered === null) {
164
+ const found = resolveLinuxSandboxTools();
165
+ if (!found.ok)
166
+ return found;
167
+ discovered = found.tools;
168
+ }
169
+ const tools = discovered;
170
+ const why = verifyLinuxSandboxTools(tools, { exclusions });
171
+ if (why !== null) {
172
+ discovered = null;
173
+ return { ok: false, why: `a sandbox program failed its check right before the launch: ${why}` };
174
+ }
175
+ return { ok: true, tools };
176
+ }