toolroll 0.9.129 → 0.9.131

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 (155) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/dist/agent-fence.js +0 -2
  3. package/dist/agent-state.js +1 -1
  4. package/dist/agents-board.js +0 -3
  5. package/dist/assignment.js +4 -3
  6. package/dist/backup-ui.js +6 -3
  7. package/dist/bounded-spawn.js +0 -1
  8. package/dist/browser/manifest.json +57 -0
  9. package/dist/browser/terminal.4d1cf20c32ad7c2099df657358d540d5fd92bb55195a88121e74b28467238b42.css.br +0 -0
  10. package/dist/browser/terminal.4d1cf20c32ad7c2099df657358d540d5fd92bb55195a88121e74b28467238b42.css.gz +0 -0
  11. package/dist/browser/{terminal.js → terminal.8978c8cbb268e1006f4b0be371c2401b58078e6d9f1380f4a5c2a12da843909f.js} +1 -1
  12. package/dist/browser/terminal.8978c8cbb268e1006f4b0be371c2401b58078e6d9f1380f4a5c2a12da843909f.js.br +0 -0
  13. package/dist/browser/terminal.8978c8cbb268e1006f4b0be371c2401b58078e6d9f1380f4a5c2a12da843909f.js.gz +0 -0
  14. package/dist/browser/{workspace.js → workspace.4f5935dc80574baadf1adafd39a08c567fb1fac1323052ca355546622f9b06d2.js} +25 -25
  15. package/dist/browser/workspace.4f5935dc80574baadf1adafd39a08c567fb1fac1323052ca355546622f9b06d2.js.br +0 -0
  16. package/dist/browser/workspace.4f5935dc80574baadf1adafd39a08c567fb1fac1323052ca355546622f9b06d2.js.gz +0 -0
  17. package/dist/browser/{workspace.css → workspace.a0752f935cfeaf16758d1085fe8f3e1719a7cd525b91a9c9943c789d65879a54.css} +1 -1
  18. package/dist/browser/workspace.a0752f935cfeaf16758d1085fe8f3e1719a7cd525b91a9c9943c789d65879a54.css.br +0 -0
  19. package/dist/browser/workspace.a0752f935cfeaf16758d1085fe8f3e1719a7cd525b91a9c9943c789d65879a54.css.gz +0 -0
  20. package/dist/browser-shell.js +271 -25
  21. package/dist/builder-restart.js +13 -4
  22. package/dist/builder.js +4 -1
  23. package/dist/canvas-freshness.js +122 -0
  24. package/dist/canvas-fs.js +273 -0
  25. package/dist/canvas-reads.js +747 -0
  26. package/dist/canvas-state-key.js +45 -0
  27. package/dist/canvas-state-worker.js +12 -0
  28. package/dist/central-recovery-stage.js +3 -3
  29. package/dist/chat-actions.js +26 -0
  30. package/dist/chat-channel.js +4 -3
  31. package/dist/chat-follow.js +4 -0
  32. package/dist/chat-task-actions.js +1 -1
  33. package/dist/chat-warmth.js +0 -1
  34. package/dist/check-report.js +0 -6
  35. package/dist/commit-extract.js +79 -40
  36. package/dist/companion/access.js +1 -0
  37. package/dist/companion/actions.js +79 -16
  38. package/dist/companion/canvas.js +141 -0
  39. package/dist/companion/chat-origin.js +92 -0
  40. package/dist/companion/chat.js +571 -0
  41. package/dist/companion/daemon.js +46 -5
  42. package/dist/companion/finish.js +51 -0
  43. package/dist/companion/reads.js +5 -1
  44. package/dist/companion/schema.js +64 -0
  45. package/dist/companion/service.js +1 -0
  46. package/dist/companion/store.js +1 -0
  47. package/dist/companion/webauthn.js +11 -2
  48. package/dist/console-instance.js +0 -4
  49. package/dist/contracts/console-api.js +1 -1
  50. package/dist/converse.js +0 -1
  51. package/dist/coordinator.js +1 -1
  52. package/dist/db-tuning.js +16 -0
  53. package/dist/desktop-config.js +156 -0
  54. package/dist/desktop-host.js +6 -152
  55. package/dist/desktop-update.js +1 -1
  56. package/dist/discord.js +9 -3
  57. package/dist/dispatch.js +32 -4
  58. package/dist/doctor.js +30 -0
  59. package/dist/evidence.js +49 -3
  60. package/dist/exec.js +3 -0
  61. package/dist/finished-task-sql.js +14 -0
  62. package/dist/flexible-answers.js +0 -1
  63. package/dist/git-views.js +7 -1
  64. package/dist/github-read.js +41 -0
  65. package/dist/guides.js +4 -3
  66. package/dist/invoke.js +12 -2
  67. package/dist/lead-doors.js +50 -3
  68. package/dist/lead-queue-runtime.js +18 -6
  69. package/dist/lead-queue.js +25 -0
  70. package/dist/lead-status.js +3 -3
  71. package/dist/live-backup-change.js +93 -0
  72. package/dist/live-backup.js +75 -31
  73. package/dist/live-bus.js +3 -2
  74. package/dist/live-records.js +0 -1
  75. package/dist/local-owner.js +0 -1
  76. package/dist/loop-recovery.js +40 -0
  77. package/dist/maintenance.js +29 -1
  78. package/dist/model-choices.js +0 -11
  79. package/dist/needs-you.js +2 -0
  80. package/dist/nightly-check.js +0 -3
  81. package/dist/nightly-github.js +1 -2
  82. package/dist/notification-retention.js +119 -0
  83. package/dist/observations.js +0 -1
  84. package/dist/operate.js +393 -56
  85. package/dist/planner.js +4 -1
  86. package/dist/pull-request-flow.js +56 -15
  87. package/dist/qr.js +0 -25
  88. package/dist/query-index-schema.js +10 -0
  89. package/dist/read-executor-worker.js +9 -7
  90. package/dist/read-executor.js +18 -1
  91. package/dist/read-worker-connection.js +7 -0
  92. package/dist/release-adapters.js +63 -48
  93. package/dist/release-auto.js +17 -13
  94. package/dist/release-card.js +0 -4
  95. package/dist/release-cli.js +58 -10
  96. package/dist/release-next.js +1 -1
  97. package/dist/release-stops.js +71 -0
  98. package/dist/release-supersede.js +125 -0
  99. package/dist/release-supervise.js +90 -0
  100. package/dist/release.js +265 -42
  101. package/dist/restore-retirement.js +4 -1
  102. package/dist/result-review.js +0 -3
  103. package/dist/retention-ui.js +1 -1
  104. package/dist/retention.js +14 -21
  105. package/dist/review-context.js +0 -5
  106. package/dist/route-rules.js +1 -5
  107. package/dist/runner.js +36 -1
  108. package/dist/sandbox-runtime.js +0 -1
  109. package/dist/scope.js +1 -13
  110. package/dist/scout.js +4 -7
  111. package/dist/serve.js +122 -12
  112. package/dist/server/kit.js +1 -0
  113. package/dist/server/live.js +9 -2
  114. package/dist/server/pages.js +3 -2
  115. package/dist/server/phone-engine-api.js +22 -2
  116. package/dist/server/render-pages.js +1 -11
  117. package/dist/server/render-results.js +0 -1
  118. package/dist/server/render-tasks.js +0 -68
  119. package/dist/server/route-table.js +1 -1
  120. package/dist/server/settings-phone.js +32 -9
  121. package/dist/server/settings-scripts.js +1 -1
  122. package/dist/server/settings-section-table.js +0 -3
  123. package/dist/server/settings-sections.js +4 -2
  124. package/dist/server/settings.js +20 -5
  125. package/dist/server/terminals.js +2 -1
  126. package/dist/shutdown-proof.js +29 -0
  127. package/dist/slack.js +9 -3
  128. package/dist/sqlite-telemetry.js +26 -14
  129. package/dist/statement-cache.js +137 -0
  130. package/dist/store.js +86 -14
  131. package/dist/structured-output.js +0 -1
  132. package/dist/style-asset.js +20 -7
  133. package/dist/tailnet.js +0 -3
  134. package/dist/task-control.js +5 -0
  135. package/dist/task-sizing.js +0 -1
  136. package/dist/task-status.js +1 -1
  137. package/dist/teams.js +9 -3
  138. package/dist/teardown-git.js +10 -1
  139. package/dist/telegram.js +4 -1
  140. package/dist/toolroll-update-cli.js +19 -3
  141. package/dist/toolroll-update-ui.js +2 -2
  142. package/dist/toolroll-update.js +95 -15
  143. package/dist/up-processes.js +16 -1
  144. package/dist/up-role-child.js +2 -0
  145. package/dist/wake-hub.js +15 -6
  146. package/dist/work-index.js +101 -44
  147. package/dist/work-reads.js +53 -9
  148. package/dist/work-snapshots.js +185 -0
  149. package/dist/worker-statement-cache.js +83 -0
  150. package/dist/workspace-revision.js +145 -21
  151. package/package.json +1 -1
  152. package/dist/companion/webauthn-test-support.js +0 -44
  153. package/dist/contracts/contract-test.js +0 -55
  154. package/dist/unfenced-test-support.js +0 -6
  155. /package/dist/browser/{terminal.css → terminal.4d1cf20c32ad7c2099df657358d540d5fd92bb55195a88121e74b28467238b42.css} +0 -0
package/dist/retention.js CHANGED
@@ -2,7 +2,8 @@ import { reclaimDatabase } from "./database-reclaim.js";
2
2
  import { existsSync, lstatSync, readdirSync, rmSync, writeFileSync } from "node:fs";
3
3
  import { join } from "node:path";
4
4
  import { RETENTION_NOTE } from "./evidence.js";
5
- import { COMPLETION_ACTION } from "./result-completion.js";
5
+ import { finishedTask } from "./finished-task-sql.js";
6
+ import { lifecycleWords, NOTIFICATION_RETENTION_WORDS, sweepNotificationLifecycle, UNDER_LIFECYCLE_KEY } from "./notification-retention.js";
6
7
  import { bytesWords, treeBytes } from "./storage.js";
7
8
  import { RETENTION_DAYS, retentionDaysSchema, retentionKindSchema } from "./contracts/retention.js";
8
9
  const KEPT_QUEUE_ROW = (message) => `lead_queue lq WHERE lq.message = ${message}
@@ -38,7 +39,7 @@ export const RETENTION_KINDS = [
38
39
  { kind: "evidence", label: "Run evidence and logs", detail: "Diffs, check logs, screenshots and reports saved for each run" },
39
40
  { kind: "checkouts", label: "Finished checkout records", detail: "Records of build checkouts that were let go and are no longer on disk" },
40
41
  { kind: "chat", label: "Chat messages", detail: "Messages in lead and team chats" },
41
- { kind: "notifications", label: "Notifications", detail: "Resolved notifications" },
42
+ { kind: "notifications", label: "Notifications", detail: `Resolved notifications. ${NOTIFICATION_RETENTION_WORDS}` },
42
43
  ];
43
44
  const LONG_CHOICES = [30, 90, 180, 365, 730, null];
44
45
  export const PERIOD_CHOICES = {
@@ -82,19 +83,6 @@ export function periodLabel(kind, days, chosen) {
82
83
  return `${label} (default)`;
83
84
  return PERIOD_CHOICES[kind].includes(days) ? label : `${label} (custom)`;
84
85
  }
85
- function finishedTask(r) {
86
- return `EXISTS (SELECT 1 FROM task t WHERE t.id = ${r}.external_id AND ${r}.backend = 'built-in' AND (t.state = 'cancelled' OR (t.state = 'done' AND EXISTS (
87
- SELECT 1 FROM action_ledger a WHERE a.action = '${COMPLETION_ACTION}' AND (a.task_id = ${r}.external_id OR a.run_id IN (SELECT id FROM run WHERE task_ref = ${r}.id))))))
88
- AND NOT EXISTS (SELECT 1 FROM hold h WHERE h.task_ref = ${r}.id)
89
- AND NOT EXISTS (SELECT 1 FROM run live WHERE live.task_ref = ${r}.id AND live.finished_at IS NULL)
90
- AND NOT EXISTS (SELECT 1 FROM task_scope s WHERE s.task_id = ${r}.external_id AND s.candidate IS NOT NULL)
91
- AND NOT EXISTS (WITH RECURSIVE family(ext) AS (
92
- SELECT rv.external_id FROM task_ref rv WHERE rv.revision_of = ${r}.external_id
93
- UNION SELECT rv.external_id FROM task_ref rv JOIN family ON rv.revision_of = family.ext)
94
- SELECT 1 FROM family JOIN task tv ON tv.id = family.ext
95
- WHERE NOT (tv.state = 'cancelled' OR (tv.state = 'done' AND EXISTS (SELECT 1 FROM action_ledger a WHERE a.action = '${COMPLETION_ACTION}'
96
- AND (a.task_id = family.ext OR a.run_id IN (SELECT run.id FROM run JOIN task_ref x ON x.id = run.task_ref WHERE x.external_id = family.ext))))))`;
97
- }
98
86
  function cutoff(now, days) {
99
87
  return new Date(now.getTime() - days * DAY_MS).toISOString();
100
88
  }
@@ -153,7 +141,7 @@ export function retentionPlan(store, evidenceRoot, now, periods = store.retentio
153
141
  }
154
142
  if (periods.notifications !== null) {
155
143
  const rows = db.prepare(`SELECT n.id AS id, length(n.subject) + length(n.body) + 64 AS bytes FROM notification n
156
- WHERE n.created_at < ? AND n.resolved_at IS NOT NULL
144
+ WHERE n.created_at < ? AND n.resolved_at IS NOT NULL AND NOT ${UNDER_LIFECYCLE_KEY("n")}
157
145
  AND NOT EXISTS (SELECT 1 FROM notification_delivery d WHERE d.notification = n.id AND d.claim_owner IS NOT NULL AND d.claim_expires_at > ?)
158
146
  AND NOT (n.resolved_at IS NULL AND n.task_ref IS NOT NULL AND NOT EXISTS (SELECT 1 FROM task_ref r WHERE r.id = n.task_ref AND ${finishedTask("r")}))
159
147
  ORDER BY n.id LIMIT ?`).all(cutoff(now, periods.notifications), now.toISOString(), SWEEP_BATCH + 1);
@@ -176,8 +164,10 @@ function folderBytes(dir) {
176
164
  export function sweepRetention(store, evidenceRoot, now, actor = "worker") {
177
165
  const periods = store.retentionPeriods();
178
166
  store.setServiceCursor(SWEEP_CURSOR, now.getTime(), now);
179
- if (RETENTION_KINDS.every(({ kind }) => periods[kind] === null))
180
- return { at: now.toISOString(), counts: [], freed: 0, ledgerId: null };
167
+ const lifecycle = sweepNotificationLifecycle(store, now);
168
+ const lifecycleDid = lifecycle.settled + lifecycle.pings + lifecycle.legacyCleared + lifecycle.deferred.families > 0;
169
+ if (!lifecycleDid && RETENTION_KINDS.every(({ kind }) => periods[kind] === null))
170
+ return { at: now.toISOString(), counts: [], freed: 0, ledgerId: null, lifecycle };
181
171
  const plan = retentionPlan(store, evidenceRoot, now, periods);
182
172
  const db = store.handle;
183
173
  const done = { evidence: { count: 0, bytes: 0 }, checkouts: { count: 0, bytes: 0 }, chat: { count: 0, bytes: 0 }, notifications: { count: 0, bytes: 0 } };
@@ -262,10 +252,13 @@ export function sweepRetention(store, evidenceRoot, now, actor = "worker") {
262
252
  }
263
253
  });
264
254
  const counts = plan.counts.map(one => ({ ...one, count: done[one.kind].count, bytes: done[one.kind].bytes }));
265
- const freed = counts.reduce((sum, one) => sum + one.bytes, 0);
266
- const ledgerId = store.recordAction({ at: now.toISOString(), actor, repo: null, taskId: null, runId: null, action: "retention sweep", outcome: freed > 0 || counts.some(one => one.count > 0) ? "removed" : "nothing due", source: "policy", detail: sweepWords(counts, freed) });
255
+ const freed = counts.reduce((sum, one) => sum + one.bytes, 0) + lifecycle.bytes;
256
+ const removed = freed > 0 || counts.some(one => one.count > 0) || lifecycle.pings + lifecycle.legacyCleared > 0;
257
+ const what = [counts.filter(one => one.count > 0).map(countWords).join(", "), lifecycleWords(lifecycle)].filter(Boolean).join("; ");
258
+ const detail = what === "" ? "nothing was due" : freed > 0 ? `${what}; about ${bytesWords(freed)} freed` : what;
259
+ const ledgerId = store.recordAction({ at: now.toISOString(), actor, repo: null, taskId: null, runId: null, action: "retention sweep", outcome: removed ? "removed" : lifecycle.settled > 0 ? "changed" : "nothing due", source: "policy", detail });
267
260
  reclaimDatabase(store.handle, "retention");
268
- return { at: now.toISOString(), counts, freed, ledgerId };
261
+ return { at: now.toISOString(), counts, freed, ledgerId, lifecycle };
269
262
  }
270
263
  export function retentionDue(store, now) {
271
264
  return now.getTime() - store.serviceCursor(SWEEP_CURSOR) >= SWEEP_EVERY_MS;
@@ -20,11 +20,6 @@ export const REVIEW_CONTEXT_LIMITS = {
20
20
  aggregateBytes: 32 * 1024 * 1024,
21
21
  items: 200,
22
22
  };
23
- export function reviewContextFileName(id) {
24
- if (!ITEM_ID.test(id))
25
- throw new Error("invalid context item id");
26
- return `REVIEW-CONTEXT-${id}.txt`;
27
- }
28
23
  const CONTEXT_INPUT_KINDS = new Set(["terminal-diff", "diff-stat", "proof", "check-log", "screenshot", "review-context"]);
29
24
  function usableReviewInput(root, artifact) {
30
25
  return artifact.captureStatus !== "failed" && (!artifact.truncated || artifact.kind === "check-log") && readVerifiedArtifact(root, artifact).ok;
@@ -5,7 +5,7 @@ import { REASON_WORDS } from "./contracts/route-results.js";
5
5
  import { checkScope, effectiveRoutes } from "./model-choices.js";
6
6
  import { seenModel, seenModels } from "./model-catalog.js";
7
7
  import { exactModelId, legOf, routeFromJson } from "./phase-routing.js";
8
- import { endRuleByDoor, endRuleByPlane, endTrialByDoor, insertEarnedRule, insertTrial, keepPausedRule, liveEarnedRules, liveTrialFor, modelsGenerationOf, proveRuleDoor, recordNotNow, ruleHoldOf, trialOrdinalOf, trialPlaceLive, trialPlacesOf, writeSuggestModels, } from "./route-store.js";
8
+ import { endRuleByDoor, endRuleByPlane, endTrialByDoor, insertEarnedRule, insertTrial, keepPausedRule, liveEarnedRules, modelsGenerationOf, proveRuleDoor, recordNotNow, ruleHoldOf, trialOrdinalOf, trialPlaceLive, trialPlacesOf, writeSuggestModels, } from "./route-store.js";
9
9
  import { BUILT_IN } from "./store.js";
10
10
  export const ROUTING_POLICY_VERSION = 1;
11
11
  const DAY = 24 * 60 * 60_000;
@@ -670,7 +670,3 @@ function trialEvidenceWords(store, selection) {
670
670
  const state = trial.state === "trialling" || trial.state === "finished" ? "" : ` The trial is ${trial.state === "paused" ? "paused" : "over"} now; approving keeps ${name}.`;
671
671
  return `Trying a cheaper model: ${name}, ${which}. A person approves each trial task; you can pick another model before approving.${state}`;
672
672
  }
673
- export function liveTrialOf(store, repo, size) {
674
- const live = liveTrialFor(store, repo, size);
675
- return live === null ? null : ruleById(store, live.id);
676
- }
package/dist/runner.js CHANGED
@@ -5,13 +5,14 @@ import { inspectAcpAgent, inspectionWords } from "./acp-inspect.js";
5
5
  import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
6
6
  import { resolve } from "node:path";
7
7
  import { canonicalProject } from "./project.js";
8
- import { lifecycleOf, reportLifecycle } from "./store.js";
8
+ import { lifecycleOf, reportLifecycle, reviveWatchLease, watchLeaseRow } from "./store.js";
9
9
  import { ALL_CREDENTIAL_ENV, PROVIDER_IDS, inspectionOf } from "./provider.js";
10
10
  import { attestationOf, versionInRange } from "./attest.js";
11
11
  import { IDENTITY_FAILED_PROBE, LOGIN_PROBE, PATH_PROBE } from "./phase-routing.js";
12
12
  import { homedir } from "node:os";
13
13
  import { readAuthMode } from "./keys.js";
14
14
  import { signInFacts } from "./provider-connection.js";
15
+ import { updateAdmissionPaused } from "./desktop-update-gate.js";
15
16
  export function canonicalRepos(repos) {
16
17
  return repos.map(repo => canonicalProject(repo) ?? resolve(repo));
17
18
  }
@@ -327,3 +328,37 @@ export function drainOf(store, runner, now) {
327
328
  return null;
328
329
  return { until: row.drainUntil, ended: Date.parse(row.drainUntil) <= now.getTime() };
329
330
  }
331
+ export function renewWatchLeaseAuthed(store, args, now) {
332
+ return store.transact(() => {
333
+ const auth = authenticate(store, args.runner, args.token);
334
+ if (!auth.ok)
335
+ return { ok: false, reason: auth.reason };
336
+ if (store.heartbeatWatchLease(args.runner, args.repo, args.owner, args.ttlMs, now)) {
337
+ store.touchRunner(args.runner, now);
338
+ return { ok: true, lateMs: 0 };
339
+ }
340
+ const row = watchLeaseRow(store, args.runner, args.repo);
341
+ if (row === null)
342
+ return { ok: false, reason: "missing" };
343
+ if (row.owner !== args.owner)
344
+ return { ok: false, reason: "taken" };
345
+ if (!boundTo(auth.runner, args.repo))
346
+ return { ok: false, reason: "unbound" };
347
+ if (updateAdmissionPaused(store.raw()) || drainOf(store, auth.runner, now) !== null)
348
+ return { ok: false, reason: "paused" };
349
+ if (!reviveWatchLease(store, args.runner, args.repo, args.owner, row.generation, args.ttlMs, now))
350
+ return { ok: false, reason: "taken" };
351
+ store.touchRunner(args.runner, now);
352
+ return { ok: true, lateMs: Math.max(0, now.getTime() - Date.parse(row.expiresAt)) };
353
+ });
354
+ }
355
+ function boundTo(runner, repo) {
356
+ if (runner.repos.includes(repo))
357
+ return true;
358
+ try {
359
+ return runner.repos.includes(canonicalProject(repo) ?? resolve(repo));
360
+ }
361
+ catch {
362
+ return false;
363
+ }
364
+ }
@@ -172,7 +172,6 @@ export function missingLinuxSandboxTools(path = process.env["PATH"] ?? "") {
172
172
  export function linuxSandboxInstallLine(packages = LINUX_SANDBOX_TOOLS.map(tool => tool.package), system = packageSystem()) {
173
173
  return installLine(packages, system);
174
174
  }
175
- export const linuxSandboxToolsWords = () => toolWords(LINUX_SANDBOX_TOOLS.map(tool => tool.package));
176
175
  export function missingSandboxToolsWords(missing) {
177
176
  return [
178
177
  `Toolroll needs ${toolWords(missing)} to run agents in a sandbox on this computer.`,
package/dist/scope.js CHANGED
@@ -36,7 +36,7 @@ import { readAcceptance, readScopeTerms, storedRubricSchema } from "./contracts/
36
36
  import { taskArchived, taskCancelled } from "./task-archive.js";
37
37
  import { releaseCiHoldOf, releaseCiHoldWords } from "./release-ci-hold.js";
38
38
  import { releaseApprovalRefusal } from "./release-refusal.js";
39
- import { NO_READINESS, exactModelId, legOf, projectRoute, routeDigestOf, routeFromJson, routeJsonProblem, routeWords, } from "./phase-routing.js";
39
+ import { exactModelId, legOf, routeDigestOf, routeFromJson, routeJsonProblem, } from "./phase-routing.js";
40
40
  function mintToken() {
41
41
  return mintSecret(32);
42
42
  }
@@ -1007,18 +1007,6 @@ export function scopeAuthorityOf(scope, env = {}) {
1007
1007
  }
1008
1008
  return { ok: true, profile, route, digest, authMode, ...(chain === null ? {} : { chain }) };
1009
1009
  }
1010
- export function acceptanceWords(criteria) {
1011
- if (criteria.length === 0)
1012
- return [];
1013
- return [
1014
- ` done when ${criteria[0].id}: ${criteria[0].statement} [shown by: ${criteria[0].evidence.join(", ")}]`,
1015
- ...criteria.slice(1).map(c => ` ${c.id}: ${c.statement} [shown by: ${c.evidence.join(", ")}]`),
1016
- ];
1017
- }
1018
- export function scopeRouteWords(scope, readiness = NO_READINESS) {
1019
- const route = routeFromJson(scope.proposedRouteJson ?? null);
1020
- return route === null ? [] : routeWords(projectRoute(route, readiness));
1021
- }
1022
1010
  export function releaseTermsSentence(terms) {
1023
1011
  if (!terms.policy.carry)
1024
1012
  return `Release ${terms.packageVersion} from pull request #${terms.pr} at ${terms.approvedSha.slice(0, 7)}. Every later commit asks for your approval again.`;
package/dist/scout.js CHANGED
@@ -9,6 +9,7 @@ import { dirname, join, relative, isAbsolute } from "node:path";
9
9
  import { run } from "./exec.js";
10
10
  import { checkoutGit } from "./teardown-git.js";
11
11
  import { auditOf } from "./provider.js";
12
+ import { isDatabaseBusy } from "./store.js";
12
13
  import { currentClaim, heartbeat } from "./claim.js";
13
14
  import { heartbeat as runnerHeartbeat, RUNNER_HEARTBEAT_MS } from "./runner.js";
14
15
  import { parseDecision } from "./decision.js";
@@ -249,7 +250,9 @@ async function scoutWith(store, request, outputDir) {
249
250
  if (!answer.ok)
250
251
  fencedMidScout = true;
251
252
  }
252
- catch {
253
+ catch (error) {
254
+ if (isDatabaseBusy(error))
255
+ return;
253
256
  fencedMidScout = true;
254
257
  }
255
258
  if (fencedMidScout && pulseTimer !== undefined)
@@ -717,12 +720,6 @@ function scrubbedImageNames(images) {
717
720
  return [one.file, name];
718
721
  }));
719
722
  }
720
- function withoutEnv(env, names) {
721
- const kept = { ...env };
722
- for (const name of names)
723
- delete kept[name];
724
- return kept;
725
- }
726
723
  function cleanup(worktree, names) {
727
724
  for (const name of names) {
728
725
  try {
package/dist/serve.js CHANGED
@@ -27,7 +27,7 @@ const LOCAL_AGENTS_EVERY_MS = 2 * 60_000;
27
27
  const LOCAL_AGENTS = ["claude", "codex"];
28
28
  const SIGNED_IN_STATES = new Set(["connected", "key-works", "key-present"]);
29
29
  const SIGNED_IN_HOLD_MS = 10 * 60_000;
30
- import { browserCrewFromIndex, browserCrewOf, browserNavigationOf, browserProjectsOf, needsYouLabelOf } from './browser-workspace.js';
30
+ import { boundProjectSummary, browserCrewFromIndex, browserCrewOf, browserNavigationOf, browserProjectsOf, needsYouLabelOf } from './browser-workspace.js';
31
31
  import { PAGE_WORK_HEADER, PAGE_WORK_VERSION } from './page-work-contract.js';
32
32
  import { sharedActionPayload } from './chat-actions.js';
33
33
  import { prepareCodingContext } from './coding-context.js';
@@ -62,7 +62,8 @@ import { createTeamRuntime } from './team-runtime.js';
62
62
  import { createPersonalQueueRuntime } from './lead-queue-runtime.js';
63
63
  import {} from "./tools-ui.js";
64
64
  import { WORK_INDEX_MAX_LIMIT, workCountsByProject, workIndexPage } from "./work-index.js";
65
- import { withWorkReads } from "./work-reads.js";
65
+ import { askedPages, prefetchedPage, providePages, withWorkReads } from "./work-reads.js";
66
+ import { WorkSnapshots } from "./work-snapshots.js";
66
67
  import { createEngineHandlers } from "./server/engine-api.js";
67
68
  import { enterRehearsal } from "./rehearsal.js";
68
69
  import { WORKSPACE_MOTION_SCRIPT } from "./workspace-motion.js";
@@ -124,7 +125,9 @@ import { createPagesHandlers } from './server/pages.js';
124
125
  import { createPhoneSettingsHandlers } from './server/settings-phone.js';
125
126
  import { createPhoneAccess, workspaceLabelOf } from './companion/access.js';
126
127
  import { createCompanionReads } from './companion/reads.js';
128
+ import { withCompanionCanvas } from './companion/canvas.js';
127
129
  import { createCompanionActions } from './companion/actions.js';
130
+ import { createCompanionChat } from './companion/chat.js';
128
131
  import { createPeopleHandlers } from './server/people-tokens.js';
129
132
  import { createSettingsHandlers } from './server/settings.js';
130
133
  import { readPurpose, requestContext } from "./server/request-context.js";
@@ -248,6 +251,8 @@ function buildDecisionServer(options, leaveRehearsal) {
248
251
  };
249
252
  const workspaceRevision = prepareWorkspaceRevision(store);
250
253
  const chromeReads = new RevisionCache(workspaceRevision, clock);
254
+ const snapshots = reads === null ? null : new WorkSnapshots(workspaceRevision, clock, job => reads.snapshot(job));
255
+ const learnedPages = new Map();
251
256
  const workspaceIncarnation = randomBytes(16).toString('hex');
252
257
  const workspaceValidators = new WorkspaceValidatorCache();
253
258
  const providerHome = options.connectionHome ?? homedir();
@@ -582,6 +587,8 @@ function buildDecisionServer(options, leaveRehearsal) {
582
587
  }
583
588
  });
584
589
  });
590
+ server.keepAliveTimeout = 65_000;
591
+ server.headersTimeout = 66_000;
585
592
  if (options.rehearsal !== true) {
586
593
  server.once('listening', () => store.telemetry.start());
587
594
  server.once('close', () => store.telemetry.stop());
@@ -878,7 +885,32 @@ function buildDecisionServer(options, leaveRehearsal) {
878
885
  facts.workspaceValidator = { key, revision, expiresAt,
879
886
  etag: '"' + createHash('sha256').update(`${key}:${revision}:${expiresAt}`).digest('hex') + '"' };
880
887
  }
881
- await prefetchChrome(route, url, who);
888
+ else if (facts?.workspaceRead && who.via === 'cookie' && EARLY_PAGES.has(route.id) && facts.freshWork !== true) {
889
+ const key = createHash('sha256').update(JSON.stringify([workspaceIncarnation, 'early', who.name,
890
+ who.session.generation, who.session.csrf, who.session.project, who.session.projectRevision,
891
+ admissionList(), url.pathname + url.search, localSignIn?.signedIn ?? null, facts.theme ?? null, facts.accent ?? null,
892
+ facts.updateSeen ?? null, facts.readPurpose ?? null, facts.appWork === true, facts.advanced ?? null, facts.passwordless ?? null])).digest('hex');
893
+ const revision = workspaceRevision.current(), now = clock();
894
+ const prior = workspaceValidators.get(key);
895
+ if (prior && prior.revision === revision && prior.expiresAt > now.getTime() && request.headers['if-none-match'] === prior.etag) {
896
+ response.setHeader('ETag', prior.etag);
897
+ return respond(response, 304, 'application/json; charset=utf-8', '');
898
+ }
899
+ facts.earlyValidator = { key, revision, expiresAt: Math.min(workspaceRevision.expiresAt(now), now.getTime() + EARLY_MAX_AGE_MS) };
900
+ }
901
+ const ahead = await prefetchChrome(route, url, who);
902
+ if (ahead?.snapshot !== undefined && facts !== undefined) {
903
+ const taken = ahead.snapshot, older = (revision) => revisionOrder(taken.revision) < revisionOrder(revision) ? taken.revision : revision;
904
+ if (facts.earlyValidator !== undefined)
905
+ facts.earlyValidator = { ...facts.earlyValidator,
906
+ revision: older(facts.earlyValidator.revision), expiresAt: Math.min(facts.earlyValidator.expiresAt, taken.expiresAt) };
907
+ const chat = facts.workspaceValidator;
908
+ if (chat !== undefined) {
909
+ const revision = older(chat.revision), expiresAt = Math.min(chat.expiresAt, taken.expiresAt);
910
+ facts.workspaceValidator = { key: chat.key, revision, expiresAt,
911
+ etag: '"' + createHash('sha256').update(`${chat.key}:${revision}:${expiresAt}`).digest('hex') + '"' };
912
+ }
913
+ }
882
914
  timeline.mark("chrome and worker reads");
883
915
  if (who.via === 'cookie') {
884
916
  const current = identify(request, false);
@@ -894,7 +926,17 @@ function buildDecisionServer(options, leaveRehearsal) {
894
926
  if (!projectRequestAllowed(route, route.project, url, who, request, response, null))
895
927
  return;
896
928
  }
897
- return withWorkReads(() => handleGet(route, url, who, request, response));
929
+ if (ahead === null)
930
+ return withWorkReads(() => handleGet(route, url, who, request, response));
931
+ return withWorkReads(async () => {
932
+ providePages(store, ahead.pages);
933
+ try {
934
+ return await handleGet(route, url, who, request, response);
935
+ }
936
+ finally {
937
+ learnPages(ahead.learn, askedPages());
938
+ }
939
+ });
898
940
  }
899
941
  return handlePost(route, url, who, request, response, body);
900
942
  };
@@ -1497,6 +1539,9 @@ function buildDecisionServer(options, leaveRehearsal) {
1497
1539
  if (status === 200 && validator === undefined && path.pathname !== '/chat') {
1498
1540
  const etag = '"w' + createHash('sha256').update(body).digest('base64url') + '"';
1499
1541
  response.setHeader('ETag', etag);
1542
+ const early = requestFacts.earlyValidator;
1543
+ if (early !== undefined)
1544
+ workspaceValidators.set(early.key, { etag, revision: early.revision, expiresAt: early.expiresAt });
1500
1545
  if (requestFacts.workspaceIfNoneMatch === etag)
1501
1546
  return respond(response, 304, 'application/json; charset=utf-8', '');
1502
1547
  }
@@ -1557,13 +1602,31 @@ function buildDecisionServer(options, leaveRehearsal) {
1557
1602
  const projects = sidebarProjects();
1558
1603
  const actor = requestContext.getStore()?.actor ?? '';
1559
1604
  const access = workAccess();
1560
- return chromeRead(summaryKey(actor, access, projects), () => projectSummaryOf(store, clock(), access, actor, projects, evidenceRoot));
1605
+ const rows = chromeRead(summaryKey(actor, access, projects), () => projectSummaryOf(store, clock(), access, actor, projects, evidenceRoot));
1606
+ let counts;
1607
+ const held = requestContext.getStore()?.chromeReads?.get(countsKey(access));
1608
+ try {
1609
+ counts = held ?? projectCounts(clock());
1610
+ }
1611
+ catch {
1612
+ return rows;
1613
+ }
1614
+ const needsOf = (path) => counts.find(one => one.repo === path)?.totals['needs-you'] ?? 0;
1615
+ return boundProjectSummary(rows.map(one => one.others === true ? one : { ...one, needsYou: needsOf(one.path) }));
1561
1616
  }
1562
1617
  const projectScopeFor = (account) => store.accountOf(account) === null ? null : requestContext.run({ csrf: '', returnTo: '/', actor: account }, () => {
1563
1618
  const access = workAccess();
1564
1619
  return JSON.stringify({ projects: sidebarProjects().map(one => one.path).sort(), access: { ...access, repos: access.repos === null ? null : [...access.repos].sort() } });
1565
1620
  });
1566
- const projectSummaryFor = (account, scope) => projectScopeFor(account) !== scope ? null : requestContext.run({ csrf: '', returnTo: '/', actor: account }, () => withWorkReads(() => JSON.stringify(projectSummary())));
1621
+ const projectSummaryFor = (account, scope) => projectScopeFor(account) !== scope ? null : requestContext.run({ csrf: '', returnTo: '/', actor: account }, () => withWorkReads(() => {
1622
+ const states = JSON.stringify(projectSummary());
1623
+ try {
1624
+ return `${states}\n${needsYouCount(null).count}`;
1625
+ }
1626
+ catch {
1627
+ return states;
1628
+ }
1629
+ }));
1567
1630
  function chromeFor(project, active, listPane, scope) {
1568
1631
  if (restricted() && !visible(project))
1569
1632
  project = null;
@@ -1646,6 +1709,9 @@ function buildDecisionServer(options, leaveRehearsal) {
1646
1709
  function sharedIndexPage(access, options) {
1647
1710
  if (requestContext.getStore()?.freshWork === true)
1648
1711
  return workIndexPage(store, clock(), access, options);
1712
+ const ahead = prefetchedPage(store, access, options);
1713
+ if (ahead !== undefined)
1714
+ return ahead;
1649
1715
  return chromeRead(indexKey(access, options), () => workIndexPage(store, clock(), access, options));
1650
1716
  }
1651
1717
  function chromeRead(key, compute) {
@@ -1660,10 +1726,51 @@ function buildDecisionServer(options, leaveRehearsal) {
1660
1726
  }
1661
1727
  const chatHomeViews = () => ["all", "needs-you", "completed"]
1662
1728
  .map(view => ({ view, limit: WORK_INDEX_MAX_LIMIT, ...(evidenceRoot === undefined ? {} : { root: evidenceRoot }) }));
1729
+ const revisionOrder = (revision) => Number(/^v1:(\d+)$/.exec(revision)?.[1] ?? -1);
1730
+ const EARLY_PAGES = new Set(["home", "projects.page"]);
1731
+ const EARLY_MAX_AGE_MS = 30_000;
1732
+ const SNAPSHOT_PAGES = new Set(["spend", "people.page", "kit.page", "subagent.page", "routine.page", "sweep.page"]);
1663
1733
  const CHROME_PAGES = new Set(["home", "work", "board", "agents", "agents.live", "task.page", "run.page", "chat.page", "review", "tasks", "inbox",
1664
1734
  "next", "done", "projects.page", "flows.page", "flow.page", "settings.page", "decision.page", "menu"]);
1665
1735
  async function prefetchChrome(route, url, who) {
1666
- if (reads === null || who.via !== "cookie" || !CHROME_PAGES.has(route.id))
1736
+ if (reads === null || who.via !== "cookie" || !(CHROME_PAGES.has(route.id) || SNAPSHOT_PAGES.has(route.id) || route.id.startsWith("settings.")))
1737
+ return null;
1738
+ if (snapshots !== null && requestContext.getStore()?.freshWork !== true) {
1739
+ try {
1740
+ const facts = requestContext.getStore();
1741
+ const actor = facts?.actor ?? "";
1742
+ const access = workAccess(), projects = sidebarProjects();
1743
+ const query = new URLSearchParams(url.searchParams);
1744
+ query.delete("format");
1745
+ const learn = JSON.stringify([route.id, url.pathname, query.toString(), actor, accessKey(access)]);
1746
+ const job = { now: clock().toISOString(), chrome: { access, actor, projects, evidenceRoot: evidenceRoot ?? null }, pages: learnedPages.get(learn) ?? [] };
1747
+ const snapshot = await snapshots.take(job);
1748
+ if (snapshot !== null && facts !== undefined) {
1749
+ const held = facts.chromeReads ??= new Map();
1750
+ if (snapshot.counts !== null)
1751
+ held.set(countsKey(access), snapshot.counts);
1752
+ if (snapshot.summary !== null)
1753
+ held.set(summaryKey(actor, access, projects), snapshot.summary);
1754
+ const pages = new Map();
1755
+ snapshot.keys.forEach((one, at) => { const page = snapshot.pages[at]; if (page != null)
1756
+ pages.set(one, page); });
1757
+ return { pages, learn, snapshot: { revision: snapshot.revision, expiresAt: snapshot.expiresAt } };
1758
+ }
1759
+ return { pages: new Map(), learn };
1760
+ }
1761
+ catch { }
1762
+ }
1763
+ await prefetchChromeEach(route, url, who);
1764
+ return null;
1765
+ }
1766
+ function learnPages(key, asked) {
1767
+ learnedPages.delete(key);
1768
+ if (learnedPages.size >= 256)
1769
+ learnedPages.delete(learnedPages.keys().next().value);
1770
+ learnedPages.set(key, asked.slice(0, 16));
1771
+ }
1772
+ async function prefetchChromeEach(route, url, who) {
1773
+ if (reads === null)
1667
1774
  return;
1668
1775
  try {
1669
1776
  const actor = requestContext.getStore()?.actor ?? "";
@@ -1865,8 +1972,8 @@ function buildDecisionServer(options, leaveRehearsal) {
1865
1972
  directChatHandlers.close();
1866
1973
  detachReads();
1867
1974
  liveFollower.close();
1868
- void Promise.all([closeCoding(), terminalClosing.close?.().then(problem => { terminalClosing.problem = problem; }), bounded(team.close()), bounded(personalQueue.close()), bounded(leadMaintenance?.stop()), bounded(backgroundChecks?.stop()), bounded(reads?.close()), bounded(engineHandlers.close()), bounded(phoneAccessRef?.stop())])
1869
- .then(() => closeServer(error => callback?.(error ?? terminalClosing.problem ?? undefined))).catch(error => {
1975
+ void Promise.all([closeCoding(), terminalClosing.close?.().then(problem => { terminalClosing.problem = problem; }), bounded(team.close()), bounded(personalQueue.close()), bounded(leadMaintenance?.stop()), bounded(backgroundChecks?.stop()), bounded((snapshots?.close(), reads?.close())), bounded(engineHandlers.close()), bounded(phoneAccessRef?.stop())])
1976
+ .then(() => { const closing = closeServer(error => callback?.(error ?? terminalClosing.problem ?? undefined)); server.closeAllConnections?.(); return closing; }).catch(error => {
1870
1977
  if (callback)
1871
1978
  callback(error instanceof Error ? error : Error('Coding session shutdown failed.'));
1872
1979
  else
@@ -2035,15 +2142,18 @@ function buildDecisionServer(options, leaveRehearsal) {
2035
2142
  };
2036
2143
  const tasksHandlers = createTasksHandlers(handlerRuntime);
2037
2144
  const pagesHandlers = createPagesHandlers(handlerRuntime, { listFor: tasksHandlers.workListFor, showOrder: tasksHandlers.showOrder });
2038
- const companionReads = createCompanionReads({ runtime: handlerRuntime, readWorkRows: pagesHandlers.readWorkRows, subscribeBus: listener => liveBus.subscribe(() => listener()),
2039
- workspaceLabel: workspaceLabelOf, toolrollVersion: PACKAGE_VERSION });
2145
+ const companionReads = withCompanionCanvas(createCompanionReads({ runtime: handlerRuntime, readWorkRows: pagesHandlers.readWorkRows, subscribeBus: listener => liveBus.subscribe(() => listener()),
2146
+ workspaceLabel: workspaceLabelOf, toolrollVersion: PACKAGE_VERSION }), { runtime: handlerRuntime });
2040
2147
  const companionActions = createCompanionActions({ runtime: handlerRuntime, workspaceLabel: workspaceLabelOf,
2041
2148
  onMutated: () => liveBus.publish({ revision: `phone:${Date.now()}` }) });
2042
2149
  phoneReadsByServer.set(server, companionReads);
2150
+ const companionChat = createCompanionChat({ runtime: handlerRuntime, queue: personalQueue, liveTurns,
2151
+ subscribeBus: listener => liveBus.subscribe(() => listener()), demoLead: demoLeadHere });
2043
2152
  const phoneAccess = createPhoneAccess({
2044
2153
  store,
2045
2154
  reads: companionReads,
2046
2155
  actions: companionActions,
2156
+ chat: companionChat,
2047
2157
  log: line => console.error(line),
2048
2158
  consoleUrl: () => publicOrigin !== null ? publicOrigin.origin : servedPort() === null ? null : `http://127.0.0.1:${servedPort()}`,
2049
2159
  bonjour: options.rehearsal !== true,
@@ -2097,7 +2207,7 @@ function buildDecisionServer(options, leaveRehearsal) {
2097
2207
  get terminalHost() { return () => terminals.host; },
2098
2208
  };
2099
2209
  const liveHandlers = createLiveHandlers(handlerRuntime, { bus: liveBus, workspaceRevision, chatProjectOf: chatHandlers.chatProjectOf, projectSummaryFor, projectScopeFor });
2100
- liveTurnStarted = liveHandlers.turnStarted;
2210
+ liveTurnStarted = thread => { liveHandlers.turnStarted(thread); companionChat.turnStarted(thread); };
2101
2211
  const terminalHandlers = createTerminalHandlers(handlerRuntime, { ...terminals, bus: liveBus, allowedHost, publicOrigin, forwardedSourceOf, server,
2102
2212
  ...(options.agentCommandEnv === undefined ? {} : { agentEnv: options.agentCommandEnv }) });
2103
2213
  terminalClosing.close = terminalHandlers.close;
@@ -76,6 +76,7 @@ export function facts(rows) {
76
76
  export const note = (text) => html `<p class="k-note">${text}</p>`;
77
77
  export const notice = (text) => html `<p class="k-notice" role="alert">${icon("alert", true)}<span>${text}</span></p>`;
78
78
  export const infoLine = (text) => html `<p class="k-notice info">${text}</p>`;
79
+ export const codeWords = (text) => joinHtml(text.split("`").map((part, i) => i % 2 === 1 ? html `<code class="k-mono">${part}</code>` : html `${part}`));
79
80
  export function empty(options) {
80
81
  return html `<div class="k-empty"><p class="k-empty-t">${options.title}</p>${options.text ? html `<p class="k-empty-x">${options.text}</p>` : ""}${options.action ?? ""}</div>`;
81
82
  }
@@ -52,7 +52,14 @@ export const LIVE_ROOMS_PER_PAGE = 6;
52
52
  const ROOM_NAME = /^(workspace|task|flow|chat|team|agent|summary|agents-live|direct-chat)(?::([^?]{1,400}))?(?:\?([^#]{0,600}))?$/;
53
53
  const WORKSPACE_SETTLE_MS = 1_000;
54
54
  const TURN_SETTLE_MS = 80;
55
- function chatSnapshot(turn) {
55
+ export function summaryFrame(fingerprint) {
56
+ const cut = fingerprint?.indexOf("\n") ?? -1;
57
+ if (fingerprint === null || cut < 0)
58
+ return { at: fingerprint };
59
+ const count = Number(fingerprint.slice(cut + 1));
60
+ return { at: fingerprint.slice(0, cut), ...(Number.isInteger(count) && count >= 0 ? { needsYou: count } : {}) };
61
+ }
62
+ export function chatSnapshot(turn) {
56
63
  const view = turn.reply?.view() ?? { phase: "working", status: LIVE_STATUS.thinking };
57
64
  const steps = (turn.reply?.tools() ?? []).map(calls => ({ tools: calls.map(call => call.label), toolCalls: calls }));
58
65
  return { steps, phase: view.phase, status: turn.done ? "" : turn.reply?.status() ?? LIVE_STATUS.thinking, text: view.phase === "writing" ? view.text : "", done: turn.done, ok: turn.ok };
@@ -116,7 +123,7 @@ export function createLiveHandlers(runtime, live) {
116
123
  const summaryRooms = createLiveRooms(key => {
117
124
  const [account, scope] = JSON.parse(key);
118
125
  return live.projectSummaryFor(account, scope);
119
- }, null, { bus: live.bus, minIntervalMs: WORKSPACE_SETTLE_MS, readSettleMs: WORKSPACE_SETTLE_MS });
126
+ }, null, { bus: live.bus, minIntervalMs: WORKSPACE_SETTLE_MS, readSettleMs: WORKSPACE_SETTLE_MS, frame: summaryFrame });
120
127
  const teamActors = new Map();
121
128
  const teamRooms = createLiveRooms(key => {
122
129
  const actor = teamActors.get(key);
@@ -20,7 +20,7 @@ import { pipeline } from "node:stream/promises";
20
20
  import { setImmediate as yieldEventLoop } from "node:timers/promises";
21
21
  import { parseApiToken, tokenLive } from "../api-tokens.js";
22
22
  import { classify } from "../board.js";
23
- import { serveBrowserAsset } from '../browser-shell.js';
23
+ import { retainBrowserAssets, serveBrowserAsset } from '../browser-shell.js';
24
24
  import { projectCheckLevel } from '../check-levels.js';
25
25
  import { checkResponse, CONSOLE_FORMS, readForm } from "../contracts/console-api.js";
26
26
  import { hasForbiddenControls } from "../decision.js";
@@ -972,9 +972,10 @@ export function createPagesHandlers(runtime, work) {
972
972
  const { response, method } = ctx;
973
973
  return healthz(store, response, method === 'HEAD', options.draining?.() === true);
974
974
  }
975
+ const retainedAssets = options.browserAssetCache === undefined ? null : retainBrowserAssets(options.browserAssetCache);
975
976
  async function browserAsset(ctx) {
976
977
  const { request, response, url } = ctx;
977
- serveBrowserAsset(request, response, url.pathname);
978
+ serveBrowserAsset(request, response, url.pathname, retainedAssets);
978
979
  }
979
980
  async function workspaceStyle(ctx) {
980
981
  const { request, response, url } = ctx;
@@ -1,7 +1,7 @@
1
1
  import { listPhones as listPhoneRows, renamePhone as renamePhoneRow, revokePairedDeviceRecord, getPairedDevice, listAllAccountPasskeys, revokeAccountPasskey } from "../companion/store.js";
2
2
  import { passkeyApprovalWindowMinutes, setPasskeyApprovalWindowMinutes, parsePasskeyWindowMinutes, PASSKEY_WINDOW_OPTIONS, } from "../companion/passkey-gate.js";
3
+ import { cancelPhoneWork, PHONE_ORIGIN_GONE } from "../companion/chat-origin.js";
3
4
  export { parsePasskeyWindowMinutes, PASSKEY_WINDOW_OPTIONS };
4
- export const RETIRED_WINDOW_MS = 30 * 24 * 60 * 60 * 1000;
5
5
  export function pathStates(service) {
6
6
  const status = service.status();
7
7
  return { direct: status.direct, hosted: status.hosted };
@@ -30,7 +30,10 @@ export function removePhone(service, store, deviceId, accountName, now) {
30
30
  const device = getPairedDevice(store.handle, deviceId);
31
31
  if (device === null || device.accountName !== accountName || device.revokedAt !== null)
32
32
  return false;
33
- return revokePairedDeviceRecord(store.handle, deviceId, now, "removed");
33
+ const revoked = revokePairedDeviceRecord(store.handle, deviceId, now, "removed");
34
+ if (revoked)
35
+ cancelPhoneWork(store, { deviceId }, PHONE_ORIGIN_GONE, now);
36
+ return revoked;
34
37
  }
35
38
  export function listPasskeys(store, accountName) {
36
39
  const identity = store.workspaceIdentity();
@@ -57,3 +60,20 @@ export function savePasskeyWindow(store, minutes) {
57
60
  export function endPasskeyWindows(service) {
58
61
  service?.engine.actions?.clearFreshLeases();
59
62
  }
63
+ export function openPasskeySetupForPairedPhone(service, store, accountName, accountGeneration, deviceId) {
64
+ const actions = service.engine.actions;
65
+ const account = store.accountOf(accountName);
66
+ if (actions === null || actions === undefined || account === null)
67
+ return null;
68
+ if (account.role !== "approver" || account.revokedAt !== null || account.passwordSet !== true || account.generation !== accountGeneration)
69
+ return null;
70
+ const device = getPairedDevice(store.handle, deviceId);
71
+ if (device === null || device.accountName !== accountName || device.revokedAt !== null)
72
+ return null;
73
+ if (listPasskeys(store, accountName).some(one => one.revokedAt === null))
74
+ return null;
75
+ return actions.openEnrollmentWindow(accountName, deviceId);
76
+ }
77
+ export function closePasskeySetup(service, accountName, windowId) {
78
+ service?.engine.actions?.closeEnrollmentWindow(accountName, windowId);
79
+ }
@@ -8,7 +8,7 @@ import {} from "../dispatch.js";
8
8
  import {} from "../first-run.js";
9
9
  import {} from "../gaps.js";
10
10
  import { limitsHtml } from "../limits-ui.js";
11
- import { ASK_LABEL, ASKS, START_BUILDER_COMMAND } from "../needs-you.js";
11
+ import { ASK_LABEL, ASKS } from "../needs-you.js";
12
12
  import {} from "../peek.js";
13
13
  import { projectName } from "../project.js";
14
14
  import {} from "../proof.js";
@@ -29,16 +29,6 @@ import { taskLinkOf } from "../task-link.js";
29
29
  import { criterionMatrixSummary, incidentWords, PHASE_WORDS, phaseWords } from "./render-results.js";
30
30
  import { decisionAnswerCard, decisionAnswerScript, dispatchHeadline, statusLineHtml, workDiagnosticsHtml } from "./render-tasks.js";
31
31
  export const TASK_STATES = ["queued", "running", "done", "failed", "cancelled"];
32
- export function startBuilderHtml(data) {
33
- const where = data.project === null ? null : html ` to <strong>${data.project}</strong>`;
34
- const state = data.connected === null ? null
35
- : data.connected ? html `<p>A builder is connected${where}. Approved tasks there start on their own.</p>`
36
- : html `<p><strong>No builder is connected</strong>${where}. Tasks wait until one is.</p>`;
37
- const title = data.heading === "h1" ? html `<h1 id="builder-heading">Start a builder</h1>` : html `<h2 id="builder-heading">Start a builder</h2>`;
38
- return html `<section id="builder" aria-labelledby="builder-heading">${title}<div class="card">${state}<p>On the computer where ${data.project ?? "the project"} lives, open the project's folder in a terminal and run:</p><p><code class="start-builder-command" style="user-select:all">${START_BUILDER_COMMAND}</code></p>${data.managed
39
- ? html `<p class="meta">Keep it running. Approved tasks start on their own. The console alone (<code>toolroll serve</code>) doesn't build.</p>`
40
- : html `<p class="meta">Starting a builder takes someone who manages this Toolroll. Ask them to run it there; your tasks start on their own once it connects.</p>`}</div></section>`;
41
- }
42
32
  export const BUILD_STEPS = ["setting up", "writing", "checking and committing"];
43
33
  export function buildStepOf(claim) {
44
34
  if (claim.role === "planner" || claim.role === "reviewer" || claim.role === "scout")
@@ -32,7 +32,6 @@ import { taskLinkOf } from "../task-link.js";
32
32
  import { attributes, html, htmlString, joinHtml, postForm, reauth } from "../html.js";
33
33
  import { chip, facts } from "./kit.js";
34
34
  import { publicationFactsOf, statusActionHref, statusLineHtml } from "./render-tasks.js";
35
- export const RUNS_PAGE = 50;
36
35
  export function editorFileHref(worktree, path, line) {
37
36
  if (!worktree.startsWith("/") || /[\u0000-\u001f\u007f]/.test(worktree))
38
37
  return null;