toolroll 0.9.109 → 0.9.111

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 +73 -0
  2. package/README.md +5 -1
  3. package/THIRD_PARTY_NOTICES.md +30 -0
  4. package/dist/agent-detect.js +244 -0
  5. package/dist/agent-fence.js +12 -1
  6. package/dist/agent-said-schema.js +4 -0
  7. package/dist/agent-said.js +23 -0
  8. package/dist/agentconfig.js +2 -2
  9. package/dist/approval-summary.js +375 -0
  10. package/dist/attest.js +2 -2
  11. package/dist/browser/THIRD_PARTY_NOTICES.txt +30 -0
  12. package/dist/browser/workspace.css +2 -2
  13. package/dist/browser/workspace.js +27 -27
  14. package/dist/builder.js +42 -3
  15. package/dist/chat-actions.js +24 -17
  16. package/dist/chat-core.js +3 -1
  17. package/dist/chat-decide.js +101 -46
  18. package/dist/chat-delivery-state.js +2 -0
  19. package/dist/chat-delivery.js +3 -2
  20. package/dist/chat-live.js +2 -1
  21. package/dist/chat-task-actions.js +6 -0
  22. package/dist/check-report.js +1 -1
  23. package/dist/claim.js +28 -13
  24. package/dist/cli-help.js +1 -1
  25. package/dist/cli.js +2 -0
  26. package/dist/codex-limits.js +21 -8
  27. package/dist/console-instance.js +11 -1
  28. package/dist/contracts/console-api.js +13 -7
  29. package/dist/contracts/engine-api.js +283 -0
  30. package/dist/contracts/route.js +1 -0
  31. package/dist/coordinator.js +2 -2
  32. package/dist/discord-api.js +4 -3
  33. package/dist/discord-chat.js +3 -1
  34. package/dist/dispatch.js +1 -1
  35. package/dist/dispose.js +15 -9
  36. package/dist/easy-start-args.js +7 -3
  37. package/dist/easy-start.js +40 -1
  38. package/dist/egress.js +72 -10
  39. package/dist/engine-handoff.js +34 -0
  40. package/dist/engine-reads.js +338 -0
  41. package/dist/eval-world.js +3 -2
  42. package/dist/evidence.js +2 -0
  43. package/dist/fast-start.js +68 -18
  44. package/dist/fast-terms.js +2 -2
  45. package/dist/first-run.js +10 -2
  46. package/dist/flexible-agents.js +234 -0
  47. package/dist/flexible-answers-schema.js +61 -0
  48. package/dist/flexible-answers.js +889 -0
  49. package/dist/flexible-custody.js +494 -0
  50. package/dist/flexible-import.js +782 -0
  51. package/dist/flexible-launch-schema.js +72 -0
  52. package/dist/flexible-launch.js +331 -0
  53. package/dist/flexible-launcher.js +88 -0
  54. package/dist/flexible-levels.js +34 -0
  55. package/dist/flexible-merge-guard.js +47 -0
  56. package/dist/flexible-refs.js +47 -0
  57. package/dist/flexible-relay-cancel.js +19 -0
  58. package/dist/flexible-relay-schema.js +55 -0
  59. package/dist/flexible-relay-upstreams.js +36 -0
  60. package/dist/flexible-relay.js +1032 -0
  61. package/dist/flexible-session.js +732 -0
  62. package/dist/flexible-ship-schema.js +81 -0
  63. package/dist/flexible-ship.js +694 -0
  64. package/dist/flexible-start.js +80 -0
  65. package/dist/flexible-thread.js +175 -25
  66. package/dist/flexible-turns-schema.js +69 -0
  67. package/dist/flexible-turns.js +490 -0
  68. package/dist/flexible.js +10 -1
  69. package/dist/flow-actions.js +6 -4
  70. package/dist/flow-steps.js +1 -1
  71. package/dist/flows-cli.js +2 -1
  72. package/dist/git-views.js +6 -3
  73. package/dist/install-mode.js +225 -0
  74. package/dist/integrations.js +6 -1
  75. package/dist/lead-doors.js +7 -1
  76. package/dist/limits-ui.js +7 -0
  77. package/dist/live-reply.js +6 -0
  78. package/dist/live-terminal.js +425 -29
  79. package/dist/local-owner.js +7 -0
  80. package/dist/model-choices.js +12 -6
  81. package/dist/needs-you.js +2 -0
  82. package/dist/notification-delivery.js +11 -0
  83. package/dist/operate.js +128 -37
  84. package/dist/outbound-privacy.js +204 -0
  85. package/dist/passwordless.js +2 -1
  86. package/dist/phase-routing.js +3 -1
  87. package/dist/plane-review.js +1 -1
  88. package/dist/project-delete.js +14 -0
  89. package/dist/proposal.js +2 -2
  90. package/dist/provider-connection.js +19 -5
  91. package/dist/publish.js +5 -0
  92. package/dist/pull-request-flow.js +26 -7
  93. package/dist/push.js +5 -1
  94. package/dist/release-card.js +11 -3
  95. package/dist/release.js +10 -1
  96. package/dist/route-store.js +3 -3
  97. package/dist/sandbox-launch.js +32 -8
  98. package/dist/sandbox-runtime.js +16 -7
  99. package/dist/sandbox-tools.js +176 -0
  100. package/dist/scope.js +12 -36
  101. package/dist/scout-net.js +7 -2
  102. package/dist/serve.js +62 -13
  103. package/dist/server/chrome.js +3 -1
  104. package/dist/server/console.css +33 -6
  105. package/dist/server/engine-api.js +378 -0
  106. package/dist/server/flows.js +2 -2
  107. package/dist/server/http.js +7 -0
  108. package/dist/server/link-redemption.js +52 -0
  109. package/dist/server/mutation-key.js +21 -7
  110. package/dist/server/pages.js +72 -40
  111. package/dist/server/people-tokens.js +17 -41
  112. package/dist/server/render-chat.js +1 -0
  113. package/dist/server/render-new-task.js +3 -3
  114. package/dist/server/render-results.js +4 -4
  115. package/dist/server/render-tasks.js +133 -139
  116. package/dist/server/route-table.js +32 -1
  117. package/dist/server/settings-section-table.js +6 -0
  118. package/dist/server/settings-sections.js +69 -0
  119. package/dist/server/settings.js +120 -10
  120. package/dist/server/task-views.js +8 -2
  121. package/dist/server/tasks.js +56 -12
  122. package/dist/server/terminals.js +181 -28
  123. package/dist/server/welcome.js +35 -10
  124. package/dist/settings-groups-ui.js +2 -2
  125. package/dist/settings-proofs.js +14 -9
  126. package/dist/slack-api.js +4 -3
  127. package/dist/slack-chat.js +5 -3
  128. package/dist/spend.js +46 -12
  129. package/dist/status-probe.js +343 -0
  130. package/dist/store.js +181 -12
  131. package/dist/task-sizing-schema.js +14 -0
  132. package/dist/task-sizing.js +76 -10
  133. package/dist/teams-api.js +4 -3
  134. package/dist/teams-chat.js +4 -2
  135. package/dist/telegram-lead.js +2 -1
  136. package/dist/telegram-live.js +2 -1
  137. package/dist/telegram-team.js +2 -1
  138. package/dist/telegram.js +17 -5
  139. package/dist/toolroll-update.js +3 -1
  140. package/dist/trusted-path.js +162 -0
  141. package/dist/tui/darwin-arm64/toolroll-tui +0 -0
  142. package/dist/tui/darwin-x64/toolroll-tui +0 -0
  143. package/dist/tui/linux-arm64/toolroll-tui +0 -0
  144. package/dist/tui/linux-x64/toolroll-tui +0 -0
  145. package/dist/tui-launch.js +282 -0
  146. package/dist/tui-source.js +5 -3
  147. package/dist/tui.js +1 -1
  148. package/dist/webhooks.js +14 -4
  149. package/dist/welcome-facts.js +22 -15
  150. package/dist/work-index.js +2 -2
  151. package/dist/workspace-ui.js +5 -0
  152. package/package.json +1 -1
  153. package/scripts/crash-canary.mjs +1 -1
  154. package/scripts/pilot.mjs +1 -1
  155. package/scripts/provider-canary.mjs +5 -3
package/dist/claim.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import { randomUUID } from "node:crypto";
2
+ import { INFRASTRUCTURE_TERMINALS } from "./route-store.js";
3
+ import { RUN_REASON_WORDS } from "./needs-you.js";
2
4
  import { authenticate, drainOf } from "./runner.js";
3
5
  import { pauseForAuth } from "./provider-auth.js";
4
6
  import { DEFAULT_MAX_OPEN_DECISIONS, missingCapability, scopeApprovedForDispatch, taskReadinessBlocker, } from "./dispatch.js";
@@ -542,7 +544,7 @@ function sealFailure(store, leaseId, args) {
542
544
  if (failureClass !== "commit-failure" && run.terminalClass === "auth-expired") {
543
545
  return { ok: true, ...sealAuthExpired(store, run, taskId, now) };
544
546
  }
545
- if (failureClass === "unknown") {
547
+ if (failureClass === "unknown" || failureClass === "agent-error") {
546
548
  const moved = moveOnIfExhausted(store, runId, taskId, now);
547
549
  if (moved !== null) {
548
550
  store.finishRun(runId, { outcome: "failed", reason: "usage-exhausted", now });
@@ -566,12 +568,13 @@ function sealFailure(store, leaseId, args) {
566
568
  pushClass: "attention",
567
569
  link: `/r/${runId}`,
568
570
  subject: `${taskId}: the commit itself failed`,
569
- body: `${oneLine(message, 200)}\nThe work is preserved, uncommitted, in ${args.worktree}. Prove it and \`toolroll task requeue ${taskId}\`.`,
571
+ body: `The commit itself failed. The work is preserved, uncommitted, in the task's checkout. Prove it and \`toolroll task requeue ${taskId}\`.`,
570
572
  }, now);
571
573
  return { ok: true, disposition: "commit-incident", incidentId };
572
574
  }
573
575
  const strikes = store.addStrike(run.taskRef);
574
- if (strikes >= MAX_STRIKES) {
576
+ const agentStopped = failureClass === "agent-error" && !INFRASTRUCTURE_TERMINALS.has(run.terminalClass ?? "");
577
+ if (strikes >= MAX_STRIKES || agentStopped) {
575
578
  const closedState = exhaustUnlessClosed(store, run, taskId, now);
576
579
  if (closedState !== null)
577
580
  return { ok: true, disposition: "closed", strikes, state: closedState };
@@ -580,7 +583,8 @@ function sealFailure(store, leaseId, args) {
580
583
  taskRef: run.taskRef,
581
584
  ownerKind: "incident",
582
585
  ownerId: String(incidentId),
583
- reason: `attempts-exhausted — ${strikes} consecutive failures, last: ${failureClass}`,
586
+ reason: agentStopped ? "agent-error — the agent stopped with an error; it isn't retried on its own"
587
+ : `attempts-exhausted — ${strikes} consecutive failures, last: ${failureClass}`,
584
588
  until: null,
585
589
  }, now);
586
590
  store.enqueueNotification({
@@ -589,8 +593,10 @@ function sealFailure(store, leaseId, args) {
589
593
  kind: "attempts-exhausted",
590
594
  pushClass: "attention",
591
595
  link: `/r/${runId}`,
592
- subject: `${taskId} stalled after ${strikes} straight failures`,
593
- body: `Last failure (${failureClass}): ${oneLine(message, 200)}\nIt will not be retried. Read the runs, then \`toolroll task requeue ${taskId}\`.`,
596
+ subject: agentStopped ? `${taskId} stopped: the agent stopped with an error` : `${taskId} stalled after ${strikes} straight failures`,
597
+ body: agentStopped
598
+ ? `${outboundFailureWords(failureClass)}.\nIt isn't retried on its own. Read what the agent said on the task, then Retry (\`toolroll task requeue ${taskId}\`).`
599
+ : `Last failure (${failureClass}): ${outboundFailureWords(failureClass)}.\nIt will not be retried. Read the runs, then \`toolroll task requeue ${taskId}\`.`,
594
600
  }, now);
595
601
  return { ok: true, disposition: "stalled", strikes, incidentId };
596
602
  }
@@ -612,7 +618,7 @@ function sealFailure(store, leaseId, args) {
612
618
  subject: failureClass === "no-handoff"
613
619
  ? `${taskId}: the agent stopped before handing off; its work was kept, retry ${strikes}/${MAX_STRIKES}`
614
620
  : `${taskId}: attempt failed (${failureClass}), retry ${strikes}/${MAX_STRIKES}`,
615
- body: `${oneLine(message, 200)}\nNext attempt no earlier than ${until.toISOString()}.`,
621
+ body: `${outboundFailureWords(failureClass)}.\nNext attempt no earlier than ${until.toISOString()}.`,
616
622
  }, now);
617
623
  return { ok: true, disposition: "backoff", strikes, until: until.toISOString() };
618
624
  }
@@ -855,6 +861,8 @@ function sealPlanFailure(store, leaseId, args) {
855
861
  const malformedKind = args.malformed === "decision" ? "malformed-decision" : "malformed-plan";
856
862
  store.finishRun(runId, { outcome: "failed", reason: kind === "malformed" ? malformedKind : oneLine(message, 120), now });
857
863
  if (kind === "malformed") {
864
+ if (message.trim() !== "")
865
+ store.recordOutcomeFacts(runId, { handoff: message });
858
866
  const incidentId = store.createIncident({ run: runId, kind: malformedKind }, now);
859
867
  store.holdOwned({
860
868
  taskRef: run.taskRef,
@@ -870,7 +878,7 @@ function sealPlanFailure(store, leaseId, args) {
870
878
  pushClass: "attention",
871
879
  link: `/r/${runId}`,
872
880
  subject: `${taskId}: the planner's ${args.malformed === "decision" ? "question" : "plan"} failed validation`,
873
- body: `${oneLine(message, 300)}\nResolve the incident to let planning retry.`,
881
+ body: `The planner's ${args.malformed === "decision" ? "question" : "plan"} failed its checks; what it wrote is on the task.\nResolve the incident to let planning retry.`,
874
882
  }, now);
875
883
  return { ok: true, disposition: "malformed-incident", incidentId };
876
884
  }
@@ -891,7 +899,7 @@ function sealPlanFailure(store, leaseId, args) {
891
899
  pushClass: "attention",
892
900
  link: `/r/${runId}`,
893
901
  subject: `${taskId}: planning stalled after ${strikes} straight failures`,
894
- body: `Last failure: ${oneLine(message, 200)}\nResolve the incident to let planning retry, or write the scope yourself.`,
902
+ body: `${OUTBOUND_ATTEMPT_WORDS.plan}\nResolve the incident to let planning retry, or write the scope yourself.`,
895
903
  }, now);
896
904
  return { ok: true, disposition: "exhausted", incidentId, strikes };
897
905
  }
@@ -909,7 +917,7 @@ function sealPlanFailure(store, leaseId, args) {
909
917
  dedupeKey: `plan-run:${runId}:failed`,
910
918
  kind: "plan-failed",
911
919
  subject: `${taskId}: planning attempt failed, retry ${strikes}/${MAX_PLAN_STRIKES}`,
912
- body: `${oneLine(message, 200)}\nNext attempt no earlier than ${until.toISOString()}.`,
920
+ body: `${OUTBOUND_ATTEMPT_WORDS.plan}\nNext attempt no earlier than ${until.toISOString()}.`,
913
921
  }, now);
914
922
  return { ok: true, disposition: "backoff", strikes };
915
923
  }
@@ -952,6 +960,8 @@ function sealScoutFailure(store, leaseId, args) {
952
960
  const malformedKind = args.malformed === "decision" ? "malformed-decision" : "malformed-report";
953
961
  store.finishRun(runId, { outcome: "failed", reason: kind === "malformed" ? malformedKind : oneLine(message, 120), now });
954
962
  if (kind === "malformed") {
963
+ if (message.trim() !== "")
964
+ store.recordOutcomeFacts(runId, { handoff: message });
955
965
  const incidentId = store.createIncident({ run: runId, kind: malformedKind }, now);
956
966
  store.holdOwned({
957
967
  taskRef: run.taskRef,
@@ -967,7 +977,7 @@ function sealScoutFailure(store, leaseId, args) {
967
977
  pushClass: "attention",
968
978
  link: `/r/${runId}`,
969
979
  subject: `${taskId}: the scout's ${args.malformed === "decision" ? "question" : "report"} failed validation`,
970
- body: `${oneLine(message, 300)}\nResolve the incident to let scouting retry.`,
980
+ body: `The scout's ${args.malformed === "decision" ? "question" : "report"} failed its checks; what it wrote is on the task.\nResolve the incident to let scouting retry.`,
971
981
  }, now);
972
982
  return { ok: true, disposition: "malformed-incident", incidentId };
973
983
  }
@@ -991,7 +1001,7 @@ function sealScoutFailure(store, leaseId, args) {
991
1001
  pushClass: "attention",
992
1002
  link: `/r/${runId}`,
993
1003
  subject: `${taskId} stalled after ${strikes} straight scouting failures`,
994
- body: `Last failure: ${oneLine(message, 200)}\nIt will not be retried. Read the runs, then \`toolroll task requeue ${taskId}\`.`,
1004
+ body: `${OUTBOUND_ATTEMPT_WORDS.scout}\nIt will not be retried. Read the runs, then \`toolroll task requeue ${taskId}\`.`,
995
1005
  }, now);
996
1006
  return { ok: true, disposition: "stalled", incidentId, strikes };
997
1007
  }
@@ -1009,7 +1019,7 @@ function sealScoutFailure(store, leaseId, args) {
1009
1019
  dedupeKey: `run:${runId}:failed`,
1010
1020
  kind: "scout-failed",
1011
1021
  subject: `${taskId}: scouting attempt failed, retry ${strikes}/${MAX_STRIKES}`,
1012
- body: `${oneLine(message, 200)}\nNext attempt no earlier than ${until.toISOString()}.`,
1022
+ body: `${OUTBOUND_ATTEMPT_WORDS.scout}\nNext attempt no earlier than ${until.toISOString()}.`,
1013
1023
  }, now);
1014
1024
  return { ok: true, disposition: "backoff", strikes };
1015
1025
  }
@@ -1081,3 +1091,8 @@ export function acquireForCheckCleanup(store, checkId, attempt, runner, options)
1081
1091
  return acquireLocked(store, bound, runner, options, "refuse");
1082
1092
  });
1083
1093
  }
1094
+ function outboundFailureWords(failureClass) {
1095
+ const words = RUN_REASON_WORDS[failureClass] ?? "the attempt stopped";
1096
+ return `${words.charAt(0).toUpperCase()}${words.slice(1)}`;
1097
+ }
1098
+ const OUTBOUND_ATTEMPT_WORDS = { plan: "The planning attempt stopped; what happened is on the task.", scout: "The scouting attempt stopped; what happened is on the task." };
package/dist/cli-help.js CHANGED
@@ -2,7 +2,7 @@ import { DEFAULT_MAX_DEPTH } from "./scan.js";
2
2
  export const HELP = `Toolroll — your agents build. You decide.
3
3
 
4
4
  toolroll start here, in this terminal (--web: in the browser)
5
- keys: n new task · a approve · c accept · b send back · ? all
5
+ keys: n new task · a accept · r send back · A agents · ? all keys
6
6
  toolroll demo try it first: sample tasks, no model calls, no cost
7
7
  toolroll repos add <folder> add another project
8
8
  toolroll task add "<change>" --repo .
package/dist/cli.js CHANGED
@@ -346,6 +346,8 @@ async function dispatch(argv, write, mainOptions) {
346
346
  databaseFile, write, build: (await import("./monitoring.js")).packageVersion(),
347
347
  ...(mainOptions.operate === undefined ? {} : { operate: mainOptions.operate }),
348
348
  admit: repo => runReposCommand(["add", repo], write, mainOptions.onboard),
349
+ ...(easyStartArgs(argv).screenReader === true ? { screenReader: true } : {}),
350
+ ...(easyStartArgs(argv).tuiBinary === undefined ? {} : { tuiBinary: easyStartArgs(argv).tuiBinary }),
349
351
  });
350
352
  return easy.runEasyStart("start", easyStartArgs(argv), { ...seams, ...mainOptions.easyStart?.seams });
351
353
  }
@@ -99,21 +99,16 @@ export function readCodexLimits(options = {}) {
99
99
  child.stdin?.write(`${JSON.stringify({ jsonrpc: "2.0", id: 1, method: "initialize", params: { clientInfo: { name: "toolroll", version: "1" } } })}\n`);
100
100
  });
101
101
  }
102
- export function startCodexLimits(store, everyMs = 5 * 60_000) {
102
+ export function startCodexLimits(store, signedIn, everyMs = 5 * 60_000) {
103
103
  if (process.env["VITEST"] !== undefined || envValue(process.env, "NO_PLAN_PROBE") !== undefined || store.isDemo())
104
104
  return () => { };
105
105
  let stopped = false, busy = false;
106
106
  const pass = async () => {
107
- if (stopped || busy || billingOf("codex") !== "subscription")
108
- return;
109
- const recent = new Date(Date.now() - 6 * 3_600_000).toISOString();
110
- if (store.handle.prepare("SELECT 1 AS live FROM run WHERE provider = 'codex' AND outcome IS NULL AND started_at > ? LIMIT 1").get(recent) !== undefined)
107
+ if (stopped || busy)
111
108
  return;
112
109
  busy = true;
113
110
  try {
114
- const reading = await readCodexLimits();
115
- if (reading !== null && !stopped)
116
- store.recordProviderLimits(reading, new Date());
111
+ await codexLimitsPass(store, { signedIn, stopped: () => stopped });
117
112
  }
118
113
  catch {
119
114
  }
@@ -127,3 +122,21 @@ export function startCodexLimits(store, everyMs = 5 * 60_000) {
127
122
  first.unref?.();
128
123
  return () => { stopped = true; clearInterval(timer); clearTimeout(first); };
129
124
  }
125
+ export async function codexLimitsPass(store, seams) {
126
+ if (billingOf("codex") !== "subscription")
127
+ return "skipped";
128
+ const recent = new Date(Date.now() - 6 * 3_600_000).toISOString();
129
+ if (store.handle.prepare("SELECT 1 AS live FROM run WHERE provider = 'codex' AND outcome IS NULL AND started_at > ? LIMIT 1").get(recent) !== undefined)
130
+ return "skipped";
131
+ if (!(await seams.signedIn()))
132
+ return "skipped";
133
+ const reading = await (seams.read ?? (() => readCodexLimits()))();
134
+ if (reading !== null && seams.stopped?.() !== true)
135
+ store.recordProviderLimits(reading, new Date());
136
+ return "read";
137
+ }
138
+ export async function codexSignedInNow(check) {
139
+ if ((await check("codex")).state !== "connected")
140
+ return false;
141
+ return (await check("codex", true)).state === "connected";
142
+ }
@@ -102,6 +102,13 @@ export function runDirProblem(dir, uid = process.getuid?.() ?? -1, mustExist = t
102
102
  return `${dir} is open to other users — Toolroll uses it only when it is yours alone (chmod 700)`;
103
103
  return null;
104
104
  }
105
+ export function instanceSocketTooLong(databaseFile) {
106
+ const needs = Buffer.byteLength(join(instanceRunDir(databaseFile), "0123456789abcdef.sock"));
107
+ if (needs <= SOCKET_PATH_MAX)
108
+ return null;
109
+ const folderMax = SOCKET_PATH_MAX - Buffer.byteLength(`/${INSTANCE_DIR}/0123456789abcdef.sock`);
110
+ return `the database's folder is too deep for Toolroll's socket (${needs} of at most ${SOCKET_PATH_MAX} bytes), so nothing can find a console started on it — move it to a shorter folder (at most ${folderMax} bytes long), or point TOOLROLL_DB at an orders.db in one: \`TOOLROLL_DB=/short/folder/orders.db toolroll\``;
111
+ }
105
112
  export function socketPathProblem(path) {
106
113
  if (!SOCKET_NAME.test(basename(path)))
107
114
  return `${path} isn't a console socket`;
@@ -151,6 +158,9 @@ export function askSocket(socketPath, request, timeoutMs = 2_000, connect = path
151
158
  });
152
159
  }
153
160
  export async function openInstanceSocket(databaseFile, facts, secret, link) {
161
+ const tooLong = instanceSocketTooLong(databaseFile);
162
+ if (tooLong !== null)
163
+ return { ok: false, problem: tooLong };
154
164
  const dir = instanceRunDir(databaseFile);
155
165
  const problem = prepareRunDir(dir);
156
166
  if (problem !== null)
@@ -306,7 +316,7 @@ export async function proveLiveConsole(databaseFile, store, build, seams = {}) {
306
316
  const restart = "stop it and run `toolroll up` again";
307
317
  const read = readInstanceState(store);
308
318
  if (read.state === "none")
309
- return { ok: false, state: "none", message: "no console is running" };
319
+ return { ok: false, state: "none", message: instanceSocketTooLong(databaseFile) ?? "no console is running" };
310
320
  if (read.state === "invalid")
311
321
  return { ok: false, state: "refused", message: `the console's record can't be read — ${restart}` };
312
322
  const record = read.record;
@@ -49,9 +49,15 @@ export const CONSOLE_FORMS = {
49
49
  sweep: formContract("POST /sweeps/<sweep>/cancel-rest", ["confirm", "snapshot"]),
50
50
  passwordless: formContract("POST /settings/passwordless", ["action", "password"]),
51
51
  localModeOff: formContract("POST /settings/local-mode/off", ["password"]),
52
+ justMe: formContract("POST /settings/install-mode/solo", ["password"]),
53
+ taskSizing: formContract("POST /settings/task-sizing", ["password", "enabled", "sizer"]),
52
54
  releaseApproval: formContract("POST /settings/release-approval", ["repo", "action", "password"]),
53
55
  projectFlexible: formContract("POST /settings/project/flexible", ["repo", "action", "max", "digest", "password"]),
54
- term: formContract("POST /term/start, /term/<terminal>/close, /term/<terminal>/remove", ["repo", "program", "password"]),
56
+ threadAnswer: formContract("POST /agents/live/thread/<id>/answer", ["request", "card", "decision", "question", "answer"]),
57
+ threadStart: formContract("POST /agents/live/thread", ["repo", "message", "model", "terms", "password"]),
58
+ term: formContract("POST /term/start, /term/<terminal>/close, /term/<terminal>/remove", ["repo", "program", "password", "task", "run"]),
59
+ termAgent: formContract("POST /term/agent/sign-in, /term/agent/install", ["agent", "password", "confirm"]),
60
+ agentsCheck: formContract("POST /engine/agents/check", []),
55
61
  skillsRevise: formContract("POST /settings/skills/revise", ["run", "repo", "feedback", "nonce"]),
56
62
  skillsChange: formContract("POST /settings/skills/import, /settings/skills/change", ["repo", "identity", "revision", "method", "content", "files", "url", "action", "sha", "sample", "nonce", "restore"]),
57
63
  kit: formContract("POST /kits/<kit>/<act>", ["repo", "password"]),
@@ -112,10 +118,10 @@ export const CONSOLE_FORMS = {
112
118
  pullRequestsCheck: formContract("POST /settings/pull-requests/check", ["repo"]),
113
119
  connectionCheck: formContract("POST /settings/connection/check", ["provider", "auth-mode", "value", "return"]),
114
120
  modelsRefresh: formContract("POST /control/models-refresh", ["repo", "nonce", "fingerprint", "token", "provider", "model", "command", "seconds", "task"]),
115
- providerKey: formContract("POST /settings/provider-key, /settings/provider-key-clear", ["provider", "auth-mode", "value"]),
116
- telegramToken: formContract("POST /settings/telegram-token", ["token"]),
117
- email: formContract("POST /settings/email, /settings/email-test, /settings/email-read-test", ["host", "port", "secure", "user", "from", "password", "imapHost", "imapPort"]),
118
- google: formContract("POST /settings/google, /settings/google/disconnect", ["clientId", "clientSecret"]),
121
+ providerKey: formContract("POST /settings/provider-key, /settings/provider-key-clear", ["provider", "auth-mode", "value", "password"]),
122
+ telegramToken: formContract("POST /settings/telegram-token", ["token", "password"]),
123
+ email: formContract("POST /settings/email, /settings/email-test, /settings/email-read-test", ["host", "port", "secure", "user", "from", "password", "imapHost", "imapPort", "token"]),
124
+ google: formContract("POST /settings/google, /settings/google/disconnect", ["clientId", "clientSecret", "password"]),
119
125
  projectsSelect: formContract("POST /projects/select", ["path", "return"]),
120
126
  projectsRemove: formContract("POST /projects/remove", ["repo"]),
121
127
  projectsOpen: formContract("POST /projects/open", ["path", "return", "via", "password"]),
@@ -175,6 +181,7 @@ export const CONSOLE_FORMS = {
175
181
  taskSteer: formContract("POST /t/<task>/steer", ["note", "return", "run", "key", "after", "request"]),
176
182
  taskReply: formContract("POST /t/<task>/reply", ["question", "answer"]),
177
183
  taskHold: formContract("POST /t/<task>/hold", ["reason"]),
184
+ taskUnhold: formContract("POST /t/<task>/unhold", ["hold"]),
178
185
  taskBlock: formContract("POST /t/<task>/block|unblock", ["on"]),
179
186
  taskRepairDependency: formContract("POST /t/<task>/repair-dependency", ["blocker", "operation", "replacement"]),
180
187
  taskNext: formContract("POST /t/<task>/next", ["undo"]),
@@ -184,7 +191,7 @@ export const CONSOLE_FORMS = {
184
191
  taskFollowUp: formContract("POST /t/<task>/follow-up", ["index"]),
185
192
  taskPlanEdit: formContract("POST /t/<task>/plan-edit", ["saw-plan", "plan-document"]),
186
193
  taskRevision: formContract("POST /t/<task>/accept-revision|reject-revision", ["revision-id", "token"]),
187
- taskCancel: formContract("POST /t/<task>/cancel", ["reason"]),
194
+ taskCancel: formContract("POST /t/<task>/cancel", ["reason", "state", "run"]),
188
195
  taskRoute: formContract("POST /t/<task>/route", ["size", "risky", "phase", "clear-phase", "agent", "provider", "model", "sawDigest", "return"]),
189
196
  taskScope: formContract("POST /t/<task>/scope", ["sawDigest", "permission-mode", "quality-mode", "budget-usd", "budget-microusd", "requirement", "requirement-new", "requirement-how", "requirement-new-how", "goal-brief", "goal", "not", "touches", "acceptance"]),
190
197
  taskApprove: formContract("POST /t/<task>/approve", ["return", "digest", "token", "nonce", "rebuild", "sheet"]),
@@ -203,7 +210,6 @@ export const BODILESS_POSTS = [
203
210
  "POST /settings/telegram/retry",
204
211
  "POST /providers/<provider>/resume",
205
212
  "POST /logout",
206
- "POST /t/<task>/unhold",
207
213
  "POST /t/<task>/stop-carrying",
208
214
  "POST /t/<task>/retry-review",
209
215
  "POST /settings/updates/check",
@@ -0,0 +1,283 @@
1
+ import { createHash } from "node:crypto";
2
+ import { z } from "zod";
3
+ import { parseContract } from "./contract.js";
4
+ export const ENGINE_API_VERSION = 1;
5
+ const version = z.literal(ENGINE_API_VERSION);
6
+ const iso = z.string();
7
+ const liveRecordSchema = z.union([
8
+ z.object({ k: z.literal("open"), at: iso, detail: z.enum(["base", "commands"]), s: z.number().int().optional() }),
9
+ z.object({ k: z.literal("start"), at: iso, s: z.number().int().optional() }),
10
+ z.object({ k: z.literal("say"), at: iso, t: z.array(z.string()), s: z.number().int().optional() }),
11
+ z.object({ k: z.literal("step"), at: iso, id: z.string(), kind: z.string(), target: z.string().optional(), once: z.literal(true).optional(), s: z.number().int().optional() }),
12
+ z.object({ k: z.literal("done"), at: iso, id: z.string(), ok: z.boolean().nullable(), out: z.array(z.string()).optional(), s: z.number().int().optional() }),
13
+ z.object({ k: z.literal("cut"), at: iso, s: z.number().int().optional() }),
14
+ z.object({ k: z.literal("cap"), at: iso.optional(), s: z.number().int().optional() }),
15
+ z.object({ k: z.literal("child"), s: z.number().int(), at: iso.optional(), parent: z.string().nullable(), via: z.number().int().optional(), desc: z.string().optional() }),
16
+ z.object({ k: z.literal("end"), s: z.number().int(), at: iso.optional(), ok: z.boolean().nullable() }),
17
+ z.object({ k: z.literal("over") }),
18
+ ]);
19
+ export const liveSessionRefSchema = z.discriminatedUnion("kind", [
20
+ z.object({ kind: z.literal("run"), id: z.number().int().positive(), task: z.string().nullable() }),
21
+ z.object({ kind: z.literal("thread"), id: z.string().regex(/^[0-9a-f]{32}$/), task: z.null() }),
22
+ ]);
23
+ const hex32 = z.string().regex(/^[0-9a-f]{32}$/);
24
+ const flexibleLevelSchema = z.enum(["supervised", "auto", "full"]);
25
+ const answerStateSchema = z.enum(["pending", "decided", "sending", "sent", "delivered", "not-sent", "uncertain", "withdrawn"]);
26
+ const threadQuestionSchema = z.object({
27
+ request: hex32,
28
+ kind: z.enum(["permission", "question"]),
29
+ title: z.string(),
30
+ detail: z.string().nullable(),
31
+ tool: z.string().nullable(),
32
+ complete: z.boolean(),
33
+ digest: z.string().regex(/^[0-9a-f]{64}$/),
34
+ state: answerStateSchema,
35
+ answerable: z.boolean(),
36
+ parts: z.array(z.object({ id: z.string(), question: z.string(), options: z.array(z.string()) })),
37
+ });
38
+ export const threadFactsSchema = z.object({
39
+ version: z.string().regex(/^[0-9a-f]{16}$/),
40
+ title: z.string(),
41
+ project: z.string().nullable(),
42
+ level: flexibleLevelSchema.nullable(),
43
+ agent: z.object({ provider: z.string(), model: z.string() }).nullable(),
44
+ turn: z.object({ seq: z.number().int(), status: z.string(), costUsd: z.number().nullable(), costBasis: z.enum(["measured", "estimated", "unknown"]).nullable() }).nullable(),
45
+ questions: z.array(threadQuestionSchema),
46
+ });
47
+ export const liveSessionWindowSchema = z.object({
48
+ version,
49
+ session: liveSessionRefSchema,
50
+ room: z.string(),
51
+ live: z.boolean(),
52
+ file: z.enum(["main", "sub"]),
53
+ window: z.discriminatedUnion("ok", [
54
+ z.object({ ok: z.literal(true), records: z.array(liveRecordSchema), cursor: z.string(), restarted: z.boolean(), earlier: z.boolean(),
55
+ quarantined: z.number().int(), skipped: z.number().int(), more: z.boolean() }),
56
+ z.object({ ok: z.literal(false), reason: z.enum(["missing", "unavailable", "off"]) }),
57
+ ]),
58
+ thread: threadFactsSchema.optional(),
59
+ });
60
+ export const liveThreadsSchema = z.object({
61
+ version,
62
+ threads: z.array(z.object({ id: hex32, title: z.string(), project: z.string().nullable(), level: flexibleLevelSchema.nullable(), live: z.boolean(), waiting: z.number().int(),
63
+ costUsd: z.number().nullable() })),
64
+ });
65
+ const workAskSchema = z.enum(["release", "approve", "answer", "flow", "wrong", "review", "setup", "other"]);
66
+ const needRowSchema = z.object({
67
+ id: z.string(), title: z.string(), href: z.string(), project: z.string().nullable(), age: z.string(),
68
+ state: z.enum(["needs", "running", "queued", "done"]),
69
+ ask: workAskSchema.nullable(),
70
+ group: z.enum(["decide", "review", "unblock"]).optional(),
71
+ reason: z.string().nullable(), line: z.string().nullable(),
72
+ action: z.object({ label: z.string(), href: z.string() }).nullable(),
73
+ question: z.object({ id: z.number().int(), text: z.string(), recap: z.string(),
74
+ options: z.array(z.object({ id: z.string(), label: z.string(), consequence: z.string(), recommended: z.boolean() })) }).nullable(),
75
+ });
76
+ export const waitingSchema = z.object({ retryAt: iso.nullable(), lastFailure: z.string().nullable() });
77
+ export const WORK_ROW_GROUPS = ["decide", "review", "unblock", "building", "rest"];
78
+ export const WORK_STATUS_TONES = ["attention", "problem", "live", "ready", "done", "muted", "neutral"];
79
+ export const WORK_WORD_TONES = ["", "needs", "ask", "live", "done", "failed"];
80
+ const workRowSchema = z.object({
81
+ id: z.string(), title: z.string(), href: z.string(), project: z.string().nullable(), age: z.string(),
82
+ status: z.object({ label: z.string(), tone: z.enum(WORK_STATUS_TONES), token: z.string() }),
83
+ word: z.object({ word: z.string(), tone: z.enum(WORK_WORD_TONES) }),
84
+ ask: z.string().nullable(),
85
+ chip: z.string().nullable(),
86
+ group: z.enum(WORK_ROW_GROUPS),
87
+ rank: z.number().int(),
88
+ detail: z.string().nullable(),
89
+ problem: z.string().nullable(),
90
+ need: needRowSchema.nullable(),
91
+ waiting: waitingSchema.nullable(),
92
+ });
93
+ export const workRowsSchema = z.object({
94
+ version,
95
+ project: z.string().nullable(),
96
+ projectName: z.string(),
97
+ needsCount: z.number().int(),
98
+ groups: z.array(z.object({ key: z.string(), label: z.string(), count: z.number().int() })).nullable(),
99
+ rows: z.array(workRowSchema),
100
+ needs: z.array(z.object({ key: z.enum(["decide", "review", "unblock"]), label: z.string(), count: z.number().int(), rows: z.array(needRowSchema) })),
101
+ next: z.string().nullable(),
102
+ room: z.literal("workspace"),
103
+ spend: z.object({ todayUsd: z.number(), planPercent: z.number().int().nullable() }).nullable(),
104
+ });
105
+ export const stepCardSchema = z.object({
106
+ key: z.enum(["plan", "approve", "build", "checks", "review", "ready"]),
107
+ label: z.string(),
108
+ state: z.enum(["done", "current", "stuck", "skipped", "todo"]),
109
+ mark: z.enum(["done", "needs", "live", "wait", "stuck", "skipped", "todo"]),
110
+ sentence: z.string(),
111
+ at: iso.nullable(),
112
+ needsYou: z.boolean(),
113
+ inChain: z.boolean(),
114
+ agent: z.object({ provider: z.string(), model: z.string().nullable() }).nullable(),
115
+ startedAt: iso.nullable(),
116
+ latestStartedAt: iso.nullable(),
117
+ finishedAt: iso.nullable(),
118
+ costUsd: z.number().nullable(),
119
+ runs: z.array(z.number().int()),
120
+ terms: z.object({
121
+ key: z.string(),
122
+ revision: z.string().nullable(),
123
+ rows: z.array(z.object({ label: z.string(), words: z.string(), lines: z.array(z.string()) })),
124
+ warnings: z.array(z.string()),
125
+ usualLabel: z.string(),
126
+ usual: z.array(z.object({ label: z.string(), words: z.string() })),
127
+ }).optional(),
128
+ });
129
+ export const stepCardsSchema = z.object({
130
+ version,
131
+ task: z.object({ id: z.string(), root: z.string(), title: z.string(), state: z.string(), project: z.string().nullable() }),
132
+ chain: z.enum(["plan-first", "just-code"]),
133
+ headline: z.string().nullable(),
134
+ liveRun: z.number().int().nullable(),
135
+ cards: z.array(stepCardSchema).nullable(),
136
+ review: z.object({ run: z.number().int(), receipt: z.string().regex(/^[0-9a-f]{64}$/), source: z.string(),
137
+ accept: z.object({ owed: z.enum(["person-check", "exception"]).nullable(), blockers: z.array(z.string()), needs: z.string().nullable() }),
138
+ }).nullable(),
139
+ failure: z.object({ line: z.string(), failedInARow: z.number().int(), suggestion: z.string().nullable(),
140
+ agentSaid: z.array(z.string()).max(8).nullable() }).nullable(),
141
+ waiting: waitingSchema.extend({ agentSaid: z.array(z.string()).max(8).nullable() }).nullable(),
142
+ held: z.object({ id: z.number().int(), reason: z.string(), lastFailure: z.string().nullable() }).nullable(),
143
+ retry: z.object({ run: z.number().int(), digest: z.string() }).nullable(),
144
+ approval: z.object({ by: z.string(), you: z.boolean(), automatic: z.boolean() }).nullable(),
145
+ room: z.string(),
146
+ });
147
+ const diffProblemSchema = z.string().nullable();
148
+ export const resultDiffSchema = z.object({
149
+ version,
150
+ task: z.string(),
151
+ run: z.number().int().nullable(),
152
+ totals: z.object({ files: z.number().int(), additions: z.number().int(), deletions: z.number().int(), binary: z.number().int(), filesTruncated: z.boolean() }).nullable(),
153
+ files: z.array(z.object({ file: z.number().int(), path: z.string(), oldPath: z.string().nullable(), additions: z.number().int(), deletions: z.number().int(), binary: z.boolean(),
154
+ hunks: z.number().int() })),
155
+ patchTruncated: z.boolean(),
156
+ problem: diffProblemSchema,
157
+ });
158
+ const diffLineSchema = z.object({ kind: z.enum(["context", "addition", "deletion", "meta"]), text: z.string(), oldLine: z.number().int().nullable(), newLine: z.number().int().nullable() });
159
+ export const resultDiffFileSchema = z.object({
160
+ version,
161
+ task: z.string(),
162
+ run: z.number().int(),
163
+ file: z.object({ file: z.number().int(), path: z.string(), oldPath: z.string().nullable(), meta: z.array(z.string()),
164
+ hunks: z.array(z.object({ header: z.string(), lines: z.array(diffLineSchema) })) }),
165
+ linesTruncated: z.boolean(),
166
+ });
167
+ export const DIFF_CONTEXT_MAX = 100;
168
+ export const resultDiffContextSchema = z.object({
169
+ version,
170
+ task: z.string(),
171
+ run: z.number().int(),
172
+ file: z.number().int(),
173
+ from: z.number().int(),
174
+ lines: z.array(z.object({ newLine: z.number().int(), text: z.string() })),
175
+ lineCount: z.number().int().nullable(),
176
+ problem: z.string().nullable(),
177
+ });
178
+ export const agentsReadSchema = z.object({
179
+ version,
180
+ checkedAt: iso.nullable(),
181
+ agents: z.array(z.object({
182
+ id: z.string(),
183
+ name: z.string(),
184
+ state: z.enum(["signed-in", "signed-out", "unknown", "not-installed"]),
185
+ how: z.string().nullable(),
186
+ signIn: z.string().nullable(),
187
+ ready: z.boolean(),
188
+ next: z.string().nullable(),
189
+ setup: z.object({
190
+ install: z.string().nullable(),
191
+ canInstall: z.boolean(),
192
+ signIn: z.string().nullable(),
193
+ canSignIn: z.boolean(),
194
+ key: z.string().nullable(),
195
+ check: z.string().nullable(),
196
+ note: z.string().nullable(),
197
+ registry: z.string().nullable(),
198
+ registryUnsure: z.boolean(),
199
+ }),
200
+ })),
201
+ firstTask: z.object({ id: z.string(), name: z.string() }).nullable(),
202
+ lines: z.array(z.string()),
203
+ });
204
+ export const modelsReadSchema = z.object({
205
+ version,
206
+ canChange: z.boolean(),
207
+ digest: z.string(),
208
+ problem: z.string().nullable(),
209
+ roles: z.array(z.object({
210
+ key: z.enum(["plan", "build", "review"]),
211
+ label: z.string(),
212
+ current: z.string(),
213
+ words: z.string(),
214
+ choices: z.array(z.object({ provider: z.string(), label: z.string(), models: z.array(z.object({ value: z.string(), label: z.string() })) })),
215
+ })),
216
+ defaultAgent: z.string().nullable(),
217
+ presets: z.array(z.object({ agent: z.string(), name: z.string(), words: z.string(),
218
+ fields: z.record(z.string(), z.string()) })),
219
+ });
220
+ export const termStateSchema = z.object({
221
+ available: z.boolean(),
222
+ problem: z.string().nullable(),
223
+ programs: z.array(z.enum(["claude", "codex", "shell"])),
224
+ projects: z.array(z.object({ path: z.string(), name: z.string() })),
225
+ sessions: z.array(z.object({
226
+ id: z.string().regex(/^[0-9a-f]{32}$/), repo: z.string(), project: z.string(), program: z.enum(["claude", "codex", "shell"]), branch: z.string(),
227
+ startedAt: iso, endedAt: iso.nullable(), exit: z.object({ code: z.number().int().nullable(), signal: z.number().int().nullable() }).nullable(),
228
+ cleanup: z.enum(["clean", "uncertain"]).nullable(), task: z.string().nullable(), run: z.number().int().nullable(),
229
+ })),
230
+ });
231
+ export const termStartedSchema = z.discriminatedUnion("ok", [
232
+ z.object({ ok: z.literal(true), id: z.string().regex(/^[0-9a-f]{32}$/) }),
233
+ z.object({ ok: z.literal(false), error: z.string() }),
234
+ ]);
235
+ export const linkRedemptionSchema = z.object({
236
+ version,
237
+ account: z.string(),
238
+ cookie: z.object({ name: z.string(), value: z.string().regex(/^[0-9a-f]{64}$/) }),
239
+ csrf: z.string().regex(/^[0-9a-f]{64}$/),
240
+ key: z.string().regex(/^[0-9a-f]{64}$/),
241
+ epoch: z.string(),
242
+ });
243
+ export const linkRedemptionRequestSchema = z.strictObject({ code: z.string().regex(/^[A-Za-z0-9_-]{43}$/) });
244
+ export const ENGINE_REQUESTS = {
245
+ linkRedemption: { route: "POST /login/once", schema: linkRedemptionRequestSchema },
246
+ };
247
+ export const engineRefusalSchema = z.object({ error: z.string() });
248
+ export const helloSchema = z.object({ version, toolroll: z.string(), contract: z.string().regex(/^[0-9a-f]{64}$/), responses: z.array(z.string()),
249
+ mode: z.enum(["solo", "team"]), defaultChain: z.enum(["just-code", "plan-first"]) });
250
+ export const ENGINE_RESPONSES = {
251
+ liveSessionWindow: { route: "GET /agents/live/<kind>/<id>", schema: liveSessionWindowSchema },
252
+ liveThreads: { route: "GET /agents/live/threads", schema: liveThreadsSchema },
253
+ workRows: { route: "GET /work/rows", schema: workRowsSchema },
254
+ stepCards: { route: "GET /t/<task>/steps", schema: stepCardsSchema },
255
+ resultDiff: { route: "GET /t/<task>/diff", schema: resultDiffSchema },
256
+ resultDiffFile: { route: "GET /t/<task>/diff?run=&file=", schema: resultDiffFileSchema },
257
+ resultDiffContext: { route: "GET /t/<task>/diff?run=&file=&from=&count=", schema: resultDiffContextSchema },
258
+ linkRedemption: { route: "POST /login/once", schema: linkRedemptionSchema },
259
+ refusal: { route: "every engine route's refusal", schema: engineRefusalSchema },
260
+ hello: { route: "GET /engine/hello", schema: helloSchema },
261
+ agents: { route: "GET /engine/agents", schema: agentsReadSchema },
262
+ models: { route: "GET /engine/models", schema: modelsReadSchema },
263
+ termState: { route: "GET /term/state", schema: termStateSchema },
264
+ termStarted: { route: "POST /term/start, /term/agent/sign-in, /term/agent/install", schema: termStartedSchema },
265
+ };
266
+ const toStderr = (route, issues) => process.stderr.write(`engine api: ${route} disagrees with its contract: ${issues.slice(0, 5).map(one => `${one.path} ${one.kind}`).join("; ")}\n`);
267
+ export function checkEngineResponse(name, payload, report = toStderr) {
268
+ const { route, schema } = ENGINE_RESPONSES[name];
269
+ const parsed = parseContract(schema, payload);
270
+ if (!parsed.ok)
271
+ report(route, parsed.issues);
272
+ return payload;
273
+ }
274
+ export function engineJsonSchemas() {
275
+ const json = (schema) => { const { $schema: _dialect, ...rest } = z.toJSONSchema(schema, { target: "draft-2020-12", unrepresentable: "throw" }); return rest; };
276
+ return {
277
+ responses: Object.fromEntries(Object.entries(ENGINE_RESPONSES).map(([name, one]) => [name, json(one.schema)])),
278
+ requests: Object.fromEntries(Object.entries(ENGINE_REQUESTS).map(([name, one]) => [name, json(one.schema)])),
279
+ };
280
+ }
281
+ export function engineContractDigest() {
282
+ return createHash("sha256").update(JSON.stringify({ version: ENGINE_API_VERSION, ...engineJsonSchemas() })).digest("hex");
283
+ }
@@ -19,6 +19,7 @@ export const taskSizingSchema = z.strictObject({
19
19
  risky: z.boolean(),
20
20
  source: z.enum(["classifier", "heuristic", "person"]),
21
21
  reason: limited("size reason", "sizeReason"),
22
+ by: z.string().regex(/^[A-Za-z0-9][A-Za-z0-9 .:/~()_-]{0,79}$/).optional(),
22
23
  });
23
24
  export const routeOverrideSchema = z.strictObject({ phase, provider, model, by: text, at: text });
24
25
  function legSchema(tiers) {
@@ -2,7 +2,7 @@ import { createHash } from "node:crypto";
2
2
  import { hashSecret, mintCredential } from "./api-tokens.js";
3
3
  import { canonicalRepos } from "./runner.js";
4
4
  import { fileTaskProposal } from "./proposal.js";
5
- import { describeScope } from "./scope.js";
5
+ import { describeScope, summaryContextOf } from "./approval-summary.js";
6
6
  import { reportSummaryFor } from "./lead-tools.js";
7
7
  import { claimedNowSql, markedRunningSql } from "./task-moves.js";
8
8
  import { taskWorkSummaryOf } from "./work-summary.js";
@@ -358,7 +358,7 @@ export function taskDetailFor(store, who, taskId, evidenceRoot, now = new Date()
358
358
  scope: {
359
359
  sealed: store.scopeSealed(taskId),
360
360
  goal: scope?.goal ?? null,
361
- words: scope === null ? [] : describeScope(scope),
361
+ words: scope === null ? [] : describeScope(scope, undefined, null, summaryContextOf(store, taskId, scope, now)),
362
362
  },
363
363
  waits,
364
364
  attempts,