toolroll 0.9.108 → 0.9.110

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/dist/advanced-view.js +0 -1
  3. package/dist/agent-detect.js +244 -0
  4. package/dist/agent-fence.js +47 -5
  5. package/dist/agent-state.js +5 -2
  6. package/dist/agentconfig.js +2 -2
  7. package/dist/approval-summary.js +344 -0
  8. package/dist/assignment-ui.js +5 -5
  9. package/dist/assignment.js +5 -2
  10. package/dist/attest.js +2 -2
  11. package/dist/browser/terminal.js +1 -1
  12. package/dist/browser/workspace.css +2 -2
  13. package/dist/browser/workspace.js +37 -34
  14. package/dist/browser-crew.js +4 -4
  15. package/dist/browser-workspace.js +4 -11
  16. package/dist/builder.js +45 -3
  17. package/dist/chat-actions.js +24 -17
  18. package/dist/chat-controls.js +6 -5
  19. package/dist/chat-core.js +3 -1
  20. package/dist/chat-decide.js +102 -47
  21. package/dist/chat-delivery-state.js +2 -0
  22. package/dist/chat-delivery.js +3 -2
  23. package/dist/chat-live.js +2 -1
  24. package/dist/chat-quiet.js +3 -3
  25. package/dist/chat-task-actions.js +6 -0
  26. package/dist/chat-voice.js +2 -2
  27. package/dist/check-report.js +1 -1
  28. package/dist/cli-help.js +12 -13
  29. package/dist/cli.js +6 -3
  30. package/dist/console-chrome.js +10 -3
  31. package/dist/console-instance.js +10 -1
  32. package/dist/contracts/console-api.js +14 -8
  33. package/dist/contracts/engine-api.js +271 -0
  34. package/dist/contracts/handoff.js +4 -0
  35. package/dist/coordinator.js +2 -2
  36. package/dist/decision.js +17 -0
  37. package/dist/demo-chat.js +1 -1
  38. package/dist/demo.js +6 -0
  39. package/dist/design/kit.js +4 -3
  40. package/dist/discord-api.js +4 -3
  41. package/dist/discord-chat.js +3 -1
  42. package/dist/dispatch.js +3 -8
  43. package/dist/easy-start-args.js +7 -3
  44. package/dist/easy-start.js +25 -0
  45. package/dist/egress.js +72 -10
  46. package/dist/engine-handoff.js +34 -0
  47. package/dist/engine-reads.js +261 -0
  48. package/dist/eval-world.js +3 -2
  49. package/dist/evidence.js +2 -0
  50. package/dist/fast-start.js +55 -14
  51. package/dist/fast-terms.js +2 -2
  52. package/dist/first-run.js +10 -2
  53. package/dist/flexible-agents.js +234 -0
  54. package/dist/flexible-answers-schema.js +61 -0
  55. package/dist/flexible-answers.js +889 -0
  56. package/dist/flexible-available.js +1 -0
  57. package/dist/flexible-custody.js +494 -0
  58. package/dist/flexible-import.js +782 -0
  59. package/dist/flexible-launch-schema.js +72 -0
  60. package/dist/flexible-launch.js +331 -0
  61. package/dist/flexible-launcher.js +88 -0
  62. package/dist/flexible-levels.js +34 -0
  63. package/dist/flexible-merge-guard.js +47 -0
  64. package/dist/flexible-refs.js +47 -0
  65. package/dist/flexible-relay-cancel.js +19 -0
  66. package/dist/flexible-relay-schema.js +55 -0
  67. package/dist/flexible-relay-upstreams.js +36 -0
  68. package/dist/flexible-relay.js +1032 -0
  69. package/dist/flexible-schema.js +32 -0
  70. package/dist/flexible-session.js +732 -0
  71. package/dist/flexible-ship-schema.js +81 -0
  72. package/dist/flexible-ship.js +694 -0
  73. package/dist/flexible-start.js +80 -0
  74. package/dist/flexible-thread-schema.js +30 -0
  75. package/dist/flexible-thread.js +676 -0
  76. package/dist/flexible-turns-schema.js +69 -0
  77. package/dist/flexible-turns.js +490 -0
  78. package/dist/flexible-ui.js +44 -0
  79. package/dist/flexible.js +368 -0
  80. package/dist/flow-actions.js +6 -4
  81. package/dist/flow-steps.js +1 -1
  82. package/dist/flows-cli.js +2 -1
  83. package/dist/git-views.js +44 -41
  84. package/dist/guides.js +11 -10
  85. package/dist/install-mode.js +225 -0
  86. package/dist/keymap.js +1 -1
  87. package/dist/lead-context.js +1 -1
  88. package/dist/lead-doors.js +7 -1
  89. package/dist/limits-ui.js +8 -1
  90. package/dist/live-bus.js +70 -13
  91. package/dist/live-reply.js +6 -0
  92. package/dist/live-terminal.js +425 -29
  93. package/dist/local-owner.js +6 -0
  94. package/dist/model-choices.js +12 -6
  95. package/dist/needs-you.js +3 -3
  96. package/dist/nightly-github.js +2 -2
  97. package/dist/notification-delivery.js +11 -0
  98. package/dist/operate.js +185 -33
  99. package/dist/outbound-privacy.js +204 -0
  100. package/dist/passwordless.js +2 -1
  101. package/dist/project-delete-ui.js +2 -1
  102. package/dist/project-delete.js +15 -0
  103. package/dist/provider-auth.js +1 -1
  104. package/dist/provider-connection.js +5 -3
  105. package/dist/publish.js +5 -0
  106. package/dist/pull-request-flow.js +26 -7
  107. package/dist/push.js +5 -1
  108. package/dist/release-card.js +11 -3
  109. package/dist/release.js +11 -1
  110. package/dist/result-actions.js +3 -0
  111. package/dist/result-evidence-readers.js +8 -2
  112. package/dist/result-review.js +20 -9
  113. package/dist/route-store.js +2 -2
  114. package/dist/sandbox-launch.js +32 -8
  115. package/dist/sandbox-runtime.js +16 -7
  116. package/dist/sandbox-tools.js +176 -0
  117. package/dist/scope.js +12 -36
  118. package/dist/scout-net.js +7 -2
  119. package/dist/serve.js +90 -40
  120. package/dist/server/chat.js +9 -9
  121. package/dist/server/chrome.js +19 -17
  122. package/dist/server/console.css +33 -6
  123. package/dist/server/engine-api.js +378 -0
  124. package/dist/server/flows.js +2 -2
  125. package/dist/server/guards.js +10 -4
  126. package/dist/server/home.js +37 -5
  127. package/dist/server/http.js +11 -2
  128. package/dist/server/in-place.js +5 -4
  129. package/dist/server/kit.js +2 -2
  130. package/dist/server/link-redemption.js +52 -0
  131. package/dist/server/live.js +100 -10
  132. package/dist/server/mutation-key.js +21 -7
  133. package/dist/server/pages.js +129 -74
  134. package/dist/server/people-tokens.js +17 -41
  135. package/dist/server/render-chat.js +2 -1
  136. package/dist/server/render-history.js +18 -4
  137. package/dist/server/render-new-task.js +4 -4
  138. package/dist/server/render-pages.js +21 -39
  139. package/dist/server/render-people.js +2 -2
  140. package/dist/server/render-projects.js +5 -5
  141. package/dist/server/render-results.js +30 -14
  142. package/dist/server/render-tasks.js +155 -155
  143. package/dist/server/retired-routes.js +37 -4
  144. package/dist/server/route-policy.js +8 -0
  145. package/dist/server/route-table.js +43 -5
  146. package/dist/server/settings-computers.js +140 -0
  147. package/dist/server/settings-scripts.js +15 -0
  148. package/dist/server/settings-section-table.js +59 -0
  149. package/dist/server/settings-sections.js +291 -0
  150. package/dist/server/settings.js +247 -28
  151. package/dist/server/task-views.js +55 -15
  152. package/dist/server/tasks.js +168 -98
  153. package/dist/server/terminals.js +181 -28
  154. package/dist/server/welcome.js +40 -14
  155. package/dist/settings-groups-ui.js +26 -107
  156. package/dist/settings-proofs.js +18 -11
  157. package/dist/slack-api.js +4 -3
  158. package/dist/slack-chat.js +5 -3
  159. package/dist/spend.js +46 -12
  160. package/dist/sqlite-telemetry.js +70 -21
  161. package/dist/status-probe.js +343 -0
  162. package/dist/store.js +206 -10
  163. package/dist/task-link.js +64 -0
  164. package/dist/teams-api.js +4 -3
  165. package/dist/teams-chat.js +4 -2
  166. package/dist/telegram-lead.js +2 -1
  167. package/dist/telegram-live.js +2 -1
  168. package/dist/telegram-team.js +2 -1
  169. package/dist/telegram.js +17 -5
  170. package/dist/trusted-path.js +162 -0
  171. package/dist/tui/darwin-arm64/toolroll-tui +0 -0
  172. package/dist/tui/darwin-x64/toolroll-tui +0 -0
  173. package/dist/tui/linux-arm64/toolroll-tui +0 -0
  174. package/dist/tui/linux-x64/toolroll-tui +0 -0
  175. package/dist/tui-launch.js +282 -0
  176. package/dist/tui-source.js +5 -3
  177. package/dist/tui.js +2 -2
  178. package/dist/typed-words-schema.js +18 -0
  179. package/dist/webhooks.js +8 -4
  180. package/dist/welcome-facts.js +25 -17
  181. package/dist/work-index.js +126 -29
  182. package/dist/work-reads.js +279 -0
  183. package/dist/workspace-ui.js +5 -0
  184. package/package.json +4 -2
  185. package/scripts/crash-canary.mjs +1 -1
  186. package/scripts/pilot.mjs +1 -1
  187. package/scripts/provider-canary.mjs +5 -3
@@ -1245,6 +1245,12 @@
1245
1245
  .approval-detail p, .approval-detail ul, .approval-detail dl { margin: var(--so-space-xs) 0; }
1246
1246
  .approval-detail ul { padding-left: 1.25rem; }
1247
1247
  .approval-detail .revision-card { margin: 0; padding: 0; border: 0; background: none; }
1248
+ /* The approval summary's usual settings, one tap away (approval-summary.ts). */
1249
+ details.terms-usual > summary { color: var(--muted-foreground); }
1250
+ details.terms-usual > .approval-rows { margin: var(--so-space-sm) 0 0; gap: var(--so-space-sm); }
1251
+ details.terms-usual .approval-row dt { font: var(--so-typography-caption); color: var(--so-muted); }
1252
+ details.terms-usual .approval-row dd p, .plan-sheet details.terms-usual .approval-row dd p { font-size: var(--so-typography-body-font-size); line-height: 1.5; color: var(--so-ink); }
1253
+ .approval-revision-plain { max-width: 75ch; margin: 0; font-size: 14px; line-height: 1.6; }
1248
1254
  .approval-roles { display: grid; gap: var(--so-space-sm); }
1249
1255
  .approval-roles > div { display: grid; grid-template-columns: 6rem minmax(0, 1fr); gap: var(--so-space-md); }
1250
1256
  .approval-roles dt { color: var(--muted-foreground); font-weight: 500; }
@@ -1253,14 +1259,35 @@
1253
1259
  .chat-plan .approval-sheet { padding: 0; border: 0; background: none; }
1254
1260
  /* The plan sheet (task page, docs/plans/task-page-steps.md): the same terms read top to bottom — one lead sentence,
1255
1261
  Steps, Done when, Will change / Won't touch, Worth knowing, the agent — every part open, small muted headings. */
1256
- .plan-sheet { display: grid; gap: 22px; margin: 0; min-width: 0; color: var(--so-ink); }
1262
+ /* The plan sheet (the terms diet, DESIGN.md Signal): three groups under hairlines — the plan, before you approve, what
1263
+ it may do — 24px above each hairline and 16px below; 20px between parts, 8px from a heading to its body. */
1264
+ .plan-sheet { display: grid; gap: 0; margin: 0; min-width: 0; color: var(--so-ink); }
1265
+ .plan-sheet > .approval-note { margin: 0 0 var(--so-space-lg); }
1266
+ .plan-group { display: grid; gap: var(--so-space-xl); min-width: 0; }
1267
+ .plan-group + .plan-group { margin-top: var(--so-space-2xl); padding-top: var(--so-space-lg); border-top: 1px solid var(--so-line); }
1268
+ .plan-notice { display: grid; gap: var(--so-space-sm); padding: var(--so-space-md) var(--so-space-lg); border-radius: var(--so-radius-md); background: var(--so-raised); color: var(--so-ink); }
1269
+ .plan-notice > *, .plan-notice p { margin: 0; }
1270
+ .plan-sheet .approval-revision.plan-sheet-revision { margin: 0; font-size: var(--so-typography-body-reading-font-size); font-weight: 500; line-height: 1.6; }
1271
+ .plan-sheet .plan-sheet-brief { color: var(--so-ink); }
1272
+ .plan-sheet-foot { margin: 0; font: var(--so-typography-caption); font-weight: 400; color: var(--so-muted); }
1273
+ .plan-sheet-foot .mono { font: var(--so-typography-mono); }
1274
+ .plan-sheet .approval-path { font: var(--so-typography-mono); color: var(--so-ink); overflow-wrap: anywhere; }
1275
+ details.plan-sheet-full { margin: 0; }
1276
+ details.plan-sheet-full > summary { min-height: 32px; font: var(--so-typography-label); color: var(--so-ink); cursor: pointer; }
1277
+ details.plan-sheet-full[open] { display: grid; gap: var(--so-space-xl); }
1257
1278
  .plan-sheet > * { margin: 0; }
1258
- .plan-sheet-lead { max-width: 66ch; font-size: 17px; line-height: 1.5; letter-spacing: -.01em; overflow-wrap: anywhere; }
1259
- .plan-sheet-lead-long { font-size: 15px; line-height: 1.6; letter-spacing: 0; }
1279
+ .plan-sheet-lead { max-width: 66ch; font-size: 16px; font-weight: 500; line-height: 1.5; letter-spacing: -.01em; color: var(--so-ink); overflow-wrap: anywhere; }
1280
+ .plan-sheet-lead-long { font-size: var(--so-typography-title-font-size); font-weight: 400; line-height: 1.6; letter-spacing: 0; }
1260
1281
  .plan-sheet-text { max-width: 66ch; font-size: 14px; line-height: 1.65; overflow-wrap: anywhere; white-space: pre-wrap; }
1261
- .plan-sheet-part { display: grid; align-content: start; gap: var(--so-space-sm); min-width: 0; max-width: 75ch; font-size: 14px; line-height: 1.6; overflow-wrap: anywhere; }
1282
+ .plan-sheet-part { display: grid; align-content: start; gap: var(--so-space-sm); min-width: 0; max-width: 75ch; font-size: var(--so-typography-body-reading-font-size); line-height: 1.6; color: var(--so-ink); overflow-wrap: anywhere; }
1262
1283
  .plan-sheet-part > *, .plan-sheet-part p, .plan-sheet-part ul, .plan-sheet-part ol, .plan-sheet-part dl { margin: 0; }
1263
- .plan-sheet-h { margin: 0; font-size: 12px; font-weight: 500; line-height: 1.5; letter-spacing: 0; text-transform: none; color: var(--so-muted); }
1284
+ /* Section headings read as headings (Title, ink), beating the workspace's generic h3 (.so-native-region :where(h3)). */
1285
+ .plan-sheet .plan-sheet-h { margin: 0; font: var(--so-typography-title); letter-spacing: var(--so-typography-title-letter-spacing); text-transform: none; color: var(--so-ink); }
1286
+ .plan-sheet .approval-goal { font-size: var(--so-typography-body-reading-font-size); line-height: 1.6; color: var(--so-ink); }
1287
+ .plan-sheet .approval-rows { gap: var(--so-space-md); }
1288
+ .plan-sheet .approval-row { grid-template-columns: 120px minmax(0, 1fr); }
1289
+ .plan-sheet .approval-row dt { font: var(--so-typography-caption); color: var(--so-muted); }
1290
+ .plan-sheet .approval-row dd, .plan-sheet .approval-row dd p { font-size: var(--so-typography-body-reading-font-size); line-height: 1.6; color: var(--so-ink); }
1264
1291
  .plan-sheet-sub { color: var(--so-muted); font-size: 12.5px; }
1265
1292
  .plan-sheet-steps { display: grid; gap: var(--so-space-sm); padding: 0; list-style: none; counter-reset: plan-step; }
1266
1293
  .plan-sheet-steps > li { display: flex; gap: var(--so-space-md); counter-increment: plan-step; }
@@ -1270,7 +1297,7 @@
1270
1297
  .plan-sheet-done > li { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--so-space-xs) var(--so-space-md); padding: var(--so-space-sm) 0; border-bottom: 1px solid var(--so-line); }
1271
1298
  .plan-sheet-done > li:last-child { border-bottom: 0; }
1272
1299
  .plan-sheet-done > li > span:first-child { flex: 1 1 260px; min-width: 0; }
1273
- .plan-sheet-how { flex: none; font-size: 12.5px; color: var(--so-muted); }
1300
+ .plan-sheet-how { flex: none; font: var(--so-typography-caption); font-weight: 400; color: var(--so-muted); }
1274
1301
  .plan-sheet-pair { display: flex; flex-wrap: wrap; gap: var(--so-space-lg) 40px; }
1275
1302
  .plan-sheet-pair > .plan-sheet-part { flex: 1 1 220px; }
1276
1303
  .plan-sheet .approval-paths li { color: var(--so-ink); font-size: 13px; line-height: 1.7; }
@@ -0,0 +1,378 @@
1
+ import { homedir } from "node:os";
2
+ import { randomBytes } from "node:crypto";
3
+ import { boardRunOf } from "../agent-board.js";
4
+ import { checkEngineResponse, DIFF_CONTEXT_MAX, ENGINE_API_VERSION, ENGINE_RESPONSES, engineContractDigest, linkRedemptionRequestSchema } from "../contracts/engine-api.js";
5
+ import { CONSOLE_FORMS, readForm } from "../contracts/console-api.js";
6
+ import { FLEXIBLE_AVAILABLE } from "../flexible-available.js";
7
+ import { FLEXIBLE_UNAVAILABLE } from "../flexible.js";
8
+ import { admitFlexibleThreadOwner, answerFlexibleRequest, closeFlexibleSessions, flexibleThreadChangeOf, flexibleThreadLiveOf, flexibleThreadsOf, FLEXIBLE_WAIT_MS, openFlexibleSessions, recoverFlexibleHolders, startFlexibleThread, tickFlexibleSessions, waitFlexibleThreadChange } from "../flexible-session.js";
9
+ import { createFlexibleLauncher } from "../flexible-launcher.js";
10
+ import { flexibleStartCard } from "../flexible-start.js";
11
+ import { summaryLines } from "../approval-summary.js";
12
+ import { localActNow } from "../local-owner.js";
13
+ import { authenticateApprover } from "../scope.js";
14
+ import { defaultChainOf, installModeNow } from "../install-mode.js";
15
+ import { packageVersion } from "../monitoring.js";
16
+ import { readChildWindow } from "../live-children-read.js";
17
+ import { readMainWindow } from "../live-main-read.js";
18
+ import { runLiveCommands } from "../store.js";
19
+ import { agentsReadOf, resultDiffContextOf, resultDiffFileOf, resultDiffOf, resultRunsOf, stepCardsOf } from "../engine-reads.js";
20
+ import { handlersOf } from "./handler-registry.js";
21
+ import { matchTaskPath, respond } from "./http.js";
22
+ import { rereadBrowser } from "./live.js";
23
+ import { admitLink, saveLinkSession, spendLink } from "./link-redemption.js";
24
+ import { agentInventoryOf } from "./welcome.js";
25
+ import { SESSION_COOKIE, sessionWithinLifetime } from "./session.js";
26
+ const json = (response, status, value) => respond(response, status, "application/json", JSON.stringify(value));
27
+ const sendChecked = (response, status, name, value) => json(response, status, checkEngineResponse(name, value));
28
+ const refusal = (response, status, error) => sendChecked(response, status, "refusal", { error });
29
+ export function readRunLive(runtime, request, who, runId, file, cursor, key) {
30
+ const { store, options } = runtime;
31
+ const allowed = () => {
32
+ if (rereadBrowser(runtime, request, who) === null)
33
+ return false;
34
+ const run = store.getRun(runId);
35
+ const repo = run === null ? null : runtime.taskRepoOf(run.taskRef);
36
+ return run !== null && repo !== null && runtime.runVisible(run) && store.accountCanAccess(who.name, repo);
37
+ };
38
+ if (!allowed())
39
+ return { ok: false };
40
+ const local = () => options.localRunner !== undefined && store.getRun(runId)?.runner === options.localRunner;
41
+ if (!local())
42
+ return allowed() ? { ok: true, run: store.getRun(runId), window: null } : { ok: false };
43
+ const read = { key, commands: runLiveCommands(store, runId) };
44
+ const window = file === "sub" ? readChildWindow(runtime.evidenceRoot, runId, cursor, read) : readMainWindow(runtime.evidenceRoot, runId, cursor, read);
45
+ if (!allowed() || !local())
46
+ return { ok: false };
47
+ return { ok: true, run: store.getRun(runId), window };
48
+ }
49
+ export function liveQueryOf(url) {
50
+ const file = url.searchParams.get("file") ?? "main";
51
+ if ((file !== "main" && file !== "sub") || [...url.searchParams.keys()].some(key => key !== "file" && key !== "cursor")
52
+ || url.searchParams.getAll("file").length > 1 || url.searchParams.getAll("cursor").length > 1)
53
+ return null;
54
+ return { file, cursor: url.searchParams.get("cursor") };
55
+ }
56
+ export function createEngineHandlers(runtime) {
57
+ const { store, clock, evidenceRoot } = runtime;
58
+ const cursorKey = randomBytes(32);
59
+ let contract = null;
60
+ async function hello(ctx) {
61
+ const { url, response } = ctx;
62
+ if ([...url.searchParams.keys()].length > 0)
63
+ return refusal(response, 400, "request");
64
+ contract ??= engineContractDigest();
65
+ const mode = installModeNow(store).mode;
66
+ return sendChecked(response, 200, "hello", { version: ENGINE_API_VERSION, toolroll: packageVersion(), contract, responses: Object.keys(ENGINE_RESPONSES), mode, defaultChain: defaultChainOf(mode) });
67
+ }
68
+ async function agents(ctx) {
69
+ const { url, who, response } = ctx;
70
+ if (who.via !== "cookie")
71
+ return refusal(response, 403, "session");
72
+ if ([...url.searchParams.keys()].length > 0)
73
+ return refusal(response, 400, "request");
74
+ const view = agentInventoryOf(who, store);
75
+ return sendChecked(response, 200, "agents", agentsReadOf(runtime.localAgents, view === "full" ? "full" : "summary", view === "full" ? process.env["HOME"] ?? homedir() : null));
76
+ }
77
+ async function agentsCheck(ctx) {
78
+ const { who, response } = ctx;
79
+ if (who.via !== "cookie")
80
+ return refusal(response, 403, "session");
81
+ if (Date.now() - runtime.leadRecheckedAt > 4_000) {
82
+ runtime.leadRecheckedAt = Date.now();
83
+ let timer;
84
+ await Promise.race([runtime.checkLocalAgents(true), new Promise(done => { timer = setTimeout(done, 8_000); timer.unref?.(); })]).finally(() => clearTimeout(timer));
85
+ }
86
+ const view = agentInventoryOf(who, store);
87
+ return sendChecked(response, 200, "agents", agentsReadOf(runtime.localAgents, view === "full" ? "full" : "summary", view === "full" ? process.env["HOME"] ?? homedir() : null));
88
+ }
89
+ async function liveRun(ctx) {
90
+ const { url, who, request, response } = ctx;
91
+ if (who.via !== "cookie")
92
+ return refusal(response, 403, "session");
93
+ const query = liveQueryOf(url);
94
+ if (query === null)
95
+ return refusal(response, 400, "request");
96
+ const runId = Number(url.pathname.slice("/agents/live/run/".length));
97
+ const read = readRunLive(runtime, request, who, runId, query.file, query.cursor, cursorKey);
98
+ if (!read.ok)
99
+ return refusal(response, 404, "run");
100
+ const ref = store.refForId(read.run.taskRef);
101
+ const body = {
102
+ version: ENGINE_API_VERSION,
103
+ session: { kind: "run", id: read.run.id, task: ref !== null && ref.backend === "built-in" ? ref.externalId : null },
104
+ room: `agent:${boardRunOf(store, read.run.id)}`,
105
+ live: read.run.finishedAt === null,
106
+ file: query.file,
107
+ window: read.window === null ? { ok: false, reason: "off" } : read.window.ok
108
+ ? { ok: true, records: read.window.records, cursor: read.window.cursor, restarted: read.window.restarted, earlier: read.window.earlier,
109
+ quarantined: read.window.quarantined, skipped: read.window.skipped, more: read.window.more }
110
+ : { ok: false, reason: read.window.reason },
111
+ };
112
+ return sendChecked(response, 200, "liveSessionWindow", body);
113
+ }
114
+ const flexible = (() => {
115
+ if (!FLEXIBLE_AVAILABLE)
116
+ return null;
117
+ const opened = openFlexibleSessions(store);
118
+ if (!opened.ok)
119
+ return null;
120
+ void recoverFlexibleHolders(store, opened.sessions).catch(() => { });
121
+ return opened.sessions;
122
+ })();
123
+ const launcher = (() => {
124
+ if (!FLEXIBLE_AVAILABLE || flexible === null)
125
+ return null;
126
+ const made = createFlexibleLauncher(store);
127
+ return "prepare" in made ? made : null;
128
+ })();
129
+ const ownedThread = (request, who, sessions, thread) => {
130
+ if (rereadBrowser(runtime, request, who) === null)
131
+ return null;
132
+ const admitted = admitFlexibleThreadOwner(store, sessions, { thread, viewer: { name: who.name }, canAccess: repo => store.accountCanAccess(who.name, repo) });
133
+ return admitted.ok ? admitted.repo : null;
134
+ };
135
+ const acted = (response, status, outcome, words) => json(response, status, { outcome, words });
136
+ async function liveThread(ctx) {
137
+ const { url, who, request, response } = ctx;
138
+ if (who.via !== "cookie")
139
+ return refusal(response, 403, "session");
140
+ if (!FLEXIBLE_AVAILABLE || flexible === null)
141
+ return refusal(response, 404, "not-available");
142
+ const known = url.searchParams.get("known"), wait = url.searchParams.get("wait");
143
+ const plain = new URL(url.href);
144
+ plain.searchParams.delete("known");
145
+ plain.searchParams.delete("wait");
146
+ const query = url.searchParams.getAll("known").length > 1 || (known !== null && !/^[0-9a-f]{16}$/.test(known))
147
+ || url.searchParams.getAll("wait").length > 1 || (wait !== null && (wait !== "1" || known === null || !url.searchParams.has("cursor"))) ? null : liveQueryOf(plain);
148
+ if (query === null)
149
+ return refusal(response, 400, "request");
150
+ const id = url.pathname.slice("/agents/live/thread/".length);
151
+ if (ownedThread(request, who, flexible, id) === null)
152
+ return refusal(response, 404, "thread");
153
+ const since = flexibleThreadChangeOf(flexible, { thread: id });
154
+ let read = flexibleThreadLiveOf(store, flexible, { thread: id, viewer: { name: who.name }, file: query.file, cursor: query.cursor });
155
+ if (!read.ok || ownedThread(request, who, flexible, id) === null)
156
+ return refusal(response, 404, "thread");
157
+ if (wait === "1" && since.ok && read.facts.version === known && read.window.ok && read.window.records.length === 0 && !read.window.restarted && !read.window.more) {
158
+ const waited = waitFlexibleThreadChange(flexible, { thread: id, since: since.change, ms: FLEXIBLE_WAIT_MS, abandoned: stop => { response.once("close", stop); } });
159
+ if ("then" in waited)
160
+ await waited;
161
+ if (response.destroyed || response.writableEnded)
162
+ return;
163
+ if (ownedThread(request, who, flexible, id) === null)
164
+ return refusal(response, 404, "thread");
165
+ read = flexibleThreadLiveOf(store, flexible, { thread: id, viewer: { name: who.name }, file: query.file, cursor: query.cursor });
166
+ if (!read.ok || ownedThread(request, who, flexible, id) === null)
167
+ return refusal(response, 404, "thread");
168
+ }
169
+ const body = { version: ENGINE_API_VERSION, session: { kind: "thread", id, task: null }, room: `thread:${id}`, live: read.live, file: query.file, window: read.window,
170
+ ...(known === read.facts.version ? {} : { thread: read.facts }) };
171
+ return sendChecked(response, 200, "liveSessionWindow", body);
172
+ }
173
+ async function liveThreads(ctx) {
174
+ const { url, who, request, response } = ctx;
175
+ if (who.via !== "cookie")
176
+ return refusal(response, 403, "session");
177
+ if (!FLEXIBLE_AVAILABLE || flexible === null)
178
+ return refusal(response, 404, "not-available");
179
+ if ([...url.searchParams.keys()].length > 0)
180
+ return refusal(response, 400, "request");
181
+ if (rereadBrowser(runtime, request, who) === null)
182
+ return refusal(response, 403, "session");
183
+ const read = flexibleThreadsOf(store, flexible, { owner: who.name });
184
+ if (!read.ok)
185
+ return refusal(response, 404, "not-available");
186
+ const body = { version: ENGINE_API_VERSION, threads: read.threads.filter(one => store.accountCanAccess(who.name, one.repo))
187
+ .map(one => ({ id: one.id, title: one.title, project: one.project, level: one.level, live: one.live, waiting: one.waiting, costUsd: one.turn?.costUsd ?? null })) };
188
+ return sendChecked(response, 200, "liveThreads", body);
189
+ }
190
+ async function threadAnswer(ctx) {
191
+ const { url, who, request, response, posted } = ctx;
192
+ if (!FLEXIBLE_AVAILABLE || flexible === null)
193
+ return acted(response, 404, "refused", FLEXIBLE_UNAVAILABLE);
194
+ if (who.via !== "cookie")
195
+ return acted(response, 403, "refused", "Only a person signed in here can answer an agent.");
196
+ const id = url.pathname.slice("/agents/live/thread/".length, -"/answer".length);
197
+ if (ownedThread(request, who, flexible, id) === null)
198
+ return acted(response, 404, "refused", "There's no such thread.");
199
+ const body = readForm(posted, CONSOLE_FORMS.threadAnswer);
200
+ const decision = body.get("decision"), question = body.get("question"), answer = body.get("answer");
201
+ const choice = decision === "accept" || decision === "decline" ? { decision } : question !== null && answer !== null && decision === null ? { question, answer } : null;
202
+ if (choice === null)
203
+ return acted(response, 400, "refused", "That answer isn't one Toolroll can read. Nothing was sent.");
204
+ const sessionHash = runtime.sessions.hashOf(who.session);
205
+ const admitted = sessionHash === null ? null : store.webSession(sessionHash);
206
+ if (admitted === null || admitted.account !== who.name)
207
+ return acted(response, 403, "refused", "Only a person signed in here can answer an agent.");
208
+ const held = () => {
209
+ const saved = store.webSession(admitted.idHash), account = store.accountOf(who.name);
210
+ return saved !== null && saved.idHash === admitted.idHash && saved.account === admitted.account && saved.generation === admitted.generation && saved.role === admitted.role
211
+ && saved.authority === admitted.authority && saved.localGeneration === admitted.localGeneration && saved.keyEpoch === admitted.keyEpoch && saved.keyHash === admitted.keyHash
212
+ && saved.createdAt === admitted.createdAt && sessionWithinLifetime(saved, Date.now()) && runtime.sessions.holds(who.session)
213
+ && account !== null && account.revokedAt === null && account.generation === saved.generation && account.generation === who.session.generation && account.role === saved.role
214
+ && admitFlexibleThreadOwner(store, flexible, { thread: id, viewer: { name: who.name }, canAccess: repo => store.accountCanAccess(who.name, repo) }).ok;
215
+ };
216
+ const done = await answerFlexibleRequest(store, flexible, { thread: id, request: body.get("request") ?? "", shownDigest: body.get("card") ?? "",
217
+ by: { kind: "person", name: who.name, generation: who.session.generation }, choice, held });
218
+ return done.ok ? acted(response, 200, "done", "Sent to the agent.") : acted(response, 409, "refused", done.message);
219
+ }
220
+ async function threadStart(ctx) {
221
+ const { who, request, response, posted } = ctx;
222
+ if (!FLEXIBLE_AVAILABLE || flexible === null)
223
+ return acted(response, 404, "refused", FLEXIBLE_UNAVAILABLE);
224
+ if (who.via !== "cookie" || rereadBrowser(runtime, request, who) === null)
225
+ return acted(response, 403, "refused", "Only a person signed in here can start a thread.");
226
+ if (launcher === null)
227
+ return acted(response, 409, "refused", "This console can't give a thread its network, so no thread was started.");
228
+ const body = readForm(posted, CONSOLE_FORMS.threadStart);
229
+ const repo = body.get("repo") ?? "", message = body.get("message") ?? "";
230
+ if (!store.accountCanAccess(who.name, repo))
231
+ return acted(response, 403, "refused", "That project is outside your access.");
232
+ const by = { name: who.name, generation: who.session.generation };
233
+ const made = flexibleStartCard(store, { repo, by, model: body.get("model"), message });
234
+ if (!made.ok)
235
+ return acted(response, 409, "refused", made.message);
236
+ const card = made.card;
237
+ const shown = body.get("terms");
238
+ if (shown === null || shown === "") {
239
+ const rows = [...card.summary.decisions, ...card.summary.differs].map(row => ({ label: row.label, words: row.words, lines: row.lines ?? [] }));
240
+ return json(response, 200, { outcome: "thread-terms", key: card.summary.key, terms: rows, notes: card.summary.warnings.map(note => note.words), lines: summaryLines(card.summary) });
241
+ }
242
+ if (shown !== card.summary.key)
243
+ return acted(response, 409, "refused", "The terms changed since they were shown. Read them again before starting. Nothing was started.");
244
+ const proved = authenticateApprover(store, who.name, body.get("password") ?? "", repo);
245
+ if (!proved.ok || !START_PROOFS.has(proved.method))
246
+ return acted(response, 403, "refused", "Starting a thread needs your password here. Nothing was started.");
247
+ if (proved.method === "local-owner" && localActNow(store, "start-thread") === null)
248
+ return acted(response, 403, "refused", "Starting a thread needs your password here. Nothing was started.");
249
+ const started = await startFlexibleThread(store, flexible, { repo, by, digest: card.digest, message, model: card.model, billing: card.billing, startKey: card.summary.key, launcher,
250
+ freshProof: FRESH_PROOFS.has(proved.method), expectNetwork: card.network });
251
+ if (!started.ok)
252
+ return acted(response, 409, "refused", started.message);
253
+ return acted(response, 200, "done", started.replayed ? "This thread already started." : "The thread started.");
254
+ }
255
+ function familyAt(url, verb) {
256
+ const task = matchTaskPath(url.pathname, `/${verb}$`);
257
+ const family = task === null ? null : runtime.familyOf(task.taskId);
258
+ return family === null || family.problem !== null ? null : family;
259
+ }
260
+ async function taskSteps(ctx) {
261
+ const { url, response, who } = ctx;
262
+ if ([...url.searchParams.keys()].length > 0)
263
+ return refusal(response, 400, "request");
264
+ const family = familyAt(url, "steps");
265
+ if (family === null)
266
+ return refusal(response, 404, "task");
267
+ return sendChecked(response, 200, "stepCards", stepCardsOf({ store, family, now: clock(), access: runtime.workAccess(), evidenceRoot, viewer: who.name }));
268
+ }
269
+ async function taskDiff(ctx) {
270
+ const { url, response } = ctx;
271
+ const params = url.searchParams, runParam = params.get("run"), fileParam = params.get("file"), fromParam = params.get("from"), countParam = params.get("count");
272
+ if ([...params.keys()].some(key => key !== "run" && key !== "file" && key !== "from" && key !== "count")
273
+ || ["run", "file", "from", "count"].some(key => params.getAll(key).length > 1)
274
+ || (runParam !== null && !/^[1-9][0-9]{0,14}$/.test(runParam)) || (fileParam !== null && !/^(0|[1-9][0-9]{0,5})$/.test(fileParam))
275
+ || (fileParam !== null && runParam === null)
276
+ || (fromParam === null) !== (countParam === null) || (fromParam !== null && fileParam === null)
277
+ || (fromParam !== null && !/^[1-9][0-9]{0,6}$/.test(fromParam)) || (countParam !== null && (!/^[1-9][0-9]{0,2}$/.test(countParam) || Number(countParam) > DIFF_CONTEXT_MAX))) {
278
+ return refusal(response, 400, "request");
279
+ }
280
+ const family = familyAt(url, "diff");
281
+ if (family === null)
282
+ return refusal(response, 404, "task");
283
+ const results = resultRunsOf(store, family).filter(run => runtime.runVisible(run));
284
+ const run = runParam === null ? results[0] ?? null : results.find(one => one.id === Number(runParam)) ?? null;
285
+ if (runParam !== null && run === null)
286
+ return refusal(response, 404, "run");
287
+ if (fileParam === null)
288
+ return sendChecked(response, 200, "resultDiff", resultDiffOf(store, evidenceRoot, family.root.id, run));
289
+ if (fromParam !== null && countParam !== null) {
290
+ const context = resultDiffContextOf(store, evidenceRoot, family.root.id, run, Number(fileParam), Number(fromParam), Number(countParam), runtime.taskRepoOf(run.taskRef));
291
+ return context === null ? refusal(response, 404, "file") : sendChecked(response, 200, "resultDiffContext", context);
292
+ }
293
+ const one = resultDiffFileOf(store, evidenceRoot, family.root.id, run, Number(fileParam));
294
+ return one === null ? refusal(response, 404, "file") : sendChecked(response, 200, "resultDiffFile", one);
295
+ }
296
+ async function redeemLink(ctx) {
297
+ const { request, response } = ctx;
298
+ response.setHeader("Pragma", "no-cache");
299
+ const raw = await bodyOf(request, 1024);
300
+ let code = null;
301
+ if (raw !== null) {
302
+ try {
303
+ const read = linkRedemptionRequestSchema.safeParse(JSON.parse(raw));
304
+ code = read.success ? read.data.code : null;
305
+ }
306
+ catch {
307
+ code = null;
308
+ }
309
+ }
310
+ const held = spendLink(runtime, code);
311
+ const refused = (status, error, why) => {
312
+ if (why !== undefined && held !== undefined)
313
+ runtime.recordSignIn(held.account, "sign-in refused", "one-time link (terminal)", why);
314
+ return refusal(response, status, error);
315
+ };
316
+ const headers = request.headers;
317
+ if (headers.origin !== undefined || Object.keys(headers).some(name => name.startsWith("sec-fetch-")))
318
+ return refused(403, "browser", "opened by a browser page");
319
+ if (!/^application\/json(?:;\s*charset=utf-8)?$/i.test(String(headers["content-type"] ?? "")) || headers["x-toolroll-client"] !== "terminal")
320
+ return refused(400, "request");
321
+ if (code === null)
322
+ return refused(400, "request");
323
+ const admitted = admitLink(runtime, request, held, "terminal");
324
+ if (!admitted.ok)
325
+ return refusal(response, admitted.refusal.status, admitted.refusal.why);
326
+ const fields = { keyEpoch: null, keyHash: null };
327
+ const key = runtime.browserKeys.issueForClient(fields, request);
328
+ if (key === null)
329
+ return refused(403, "host", "not this console's own address");
330
+ const id = randomBytes(32).toString("hex"), csrf = randomBytes(32).toString("hex");
331
+ if (!saveLinkSession(runtime, request, admitted.held, "terminal", { id, csrf, keys: fields }))
332
+ return refusal(response, 410, "used");
333
+ const body = { version: ENGINE_API_VERSION, account: admitted.held.account, cookie: { name: SESSION_COOKIE, value: id }, csrf, key, epoch: runtime.keyEpoch };
334
+ return sendChecked(response, 200, "linkRedemption", body);
335
+ }
336
+ return {
337
+ upkeep: () => { if (flexible !== null) {
338
+ try {
339
+ tickFlexibleSessions(store, flexible);
340
+ }
341
+ catch { }
342
+ } },
343
+ close: async () => {
344
+ try {
345
+ if (flexible !== null)
346
+ await closeFlexibleSessions(store, flexible);
347
+ }
348
+ finally {
349
+ await launcher?.close();
350
+ }
351
+ },
352
+ registrations: [
353
+ ...handlersOf("pages", { "engine.hello": hello, "engine.agents": agents, "engine.agents-check": agentsCheck, "agents.live.run": liveRun, "agents.live.thread": liveThread, "agents.live.threads": liveThreads,
354
+ "agents.live.thread.answer": threadAnswer, "agents.live.thread.start": threadStart }),
355
+ ...handlersOf("tasks", { "task.steps": taskSteps, "task.diff": taskDiff }),
356
+ ...handlersOf("people", {}, { "edge.login-link-json": redeemLink }),
357
+ ],
358
+ };
359
+ }
360
+ const START_PROOFS = new Set(["password-now", "sso-now", "fresh-password", "fresh-sso", "session", "local-owner"]);
361
+ const FRESH_PROOFS = new Set(["password-now", "sso-now", "fresh-password", "fresh-sso", "local-owner"]);
362
+ function bodyOf(request, cap) {
363
+ return new Promise(resolve => {
364
+ const chunks = [];
365
+ let size = 0, over = false;
366
+ request.on("data", (chunk) => {
367
+ size += chunk.length;
368
+ if (size > cap) {
369
+ over = true;
370
+ chunks.length = 0;
371
+ return;
372
+ }
373
+ chunks.push(chunk);
374
+ });
375
+ request.on("end", () => resolve(over ? null : Buffer.concat(chunks).toString("utf8")));
376
+ request.on("error", () => resolve(null));
377
+ });
378
+ }
@@ -610,7 +610,7 @@ export function createFlowsHandlers(runtime) {
610
610
  removeLinearKey(dir);
611
611
  return settle("Linear key removed.");
612
612
  }
613
- if (!authenticateApprover(who, body.get("password") ?? "").ok)
613
+ if (!authenticateCredential(who, body.get("password") ?? "").ok)
614
614
  return answer(403, { ok: false, said: "Enter your Toolroll password to save a key." });
615
615
  const saved = saveLinearKey(dir, body.get("key") ?? "");
616
616
  return saved.ok ? settle("Linear key saved on this computer.") : answer(400, { ok: false, said: saved.message });
@@ -632,7 +632,7 @@ export function createFlowsHandlers(runtime) {
632
632
  return revokeUnattended(store, flow.id, who.name, now) ? settle("It no longer runs on its own. New cards wait for you.") : answer(409, { ok: false, said: "It wasn't running on its own." });
633
633
  }
634
634
  if (action === "browser") {
635
- const proved = authenticateApprover(who, body.get("password") ?? "", flow.repo);
635
+ const proved = authenticateCredential(who, body.get("password") ?? "", flow.repo);
636
636
  if (!proved.ok)
637
637
  return answer(403, { ok: false, said: "That password isn't right. Nothing was approved." });
638
638
  const signed = signFlowBrowser(store, { flow: flow.id, signer: who.name, proof: proved.method, sawDigest: body.get("digest") ?? "", console: { generation: who.via === "cookie" ? who.session.generation : -1 } }, now);
@@ -1,6 +1,7 @@
1
1
  import { syncProjectIdentities } from "../project-identity.js";
2
2
  import { OWNER_ACTIONS, sharedActionPayload } from '../chat-actions.js';
3
3
  import { CONSOLE_FORMS, readForm } from "../contracts/console-api.js";
4
+ import { accountAccessOf } from "../store.js";
4
5
  import { timingSafeEqual } from "node:crypto";
5
6
  import {} from "node:http";
6
7
  import { tokenLive, tokenProjects } from "../api-tokens.js";
@@ -41,9 +42,9 @@ export function createSharedGuards(runtime) {
41
42
  return rowVisible(runtime.liveCeiling(), repo) && (actor === undefined || runtime.store.accountCanAccess(actor, repo));
42
43
  };
43
44
  function codingProjectAllowed(repo) { return runtime.codingProjects().includes(repo); }
44
- const admissionList = () => restricted() ? [...(runtime.store.accountOf(requestContext.getStore().actor)?.projects ?? [])].filter(visible) : runtime.unscopedMode
45
+ const admissionList = () => restricted() ? [...(runtime.store.accountOf(requestContext.getStore().actor)?.projects ?? [])].filter(visibleNow()) : runtime.unscopedMode
45
46
  ? null
46
- : [...new Set([...runtime.managedRepos(), ...(runtime.ceiling.roots.length === 0 ? [] : runtime.store.knownRepos().filter(visible))])];
47
+ : [...new Set([...runtime.managedRepos(), ...(runtime.ceiling.roots.length === 0 ? [] : runtime.store.knownRepos().filter(visibleNow()))])];
47
48
  const taskRepoOf = (taskRef) => runtime.store.refForId(taskRef)?.repo ?? null;
48
49
  function authorizeMutation(request, who, body) {
49
50
  if (who.via === "bearer") {
@@ -217,7 +218,7 @@ export function createSharedGuards(runtime) {
217
218
  if (url.searchParams.get("view") === "order")
218
219
  url.searchParams.delete("view");
219
220
  }
220
- if (route.id === "tasks" && url.searchParams.get("view") === "order")
221
+ if ((route.id === "tasks" || route.id === "home") && url.searchParams.get("view") === "order")
221
222
  url.searchParams.set("view", "board");
222
223
  return true;
223
224
  }
@@ -326,5 +327,10 @@ export function createSharedGuards(runtime) {
326
327
  }
327
328
  function identities() { return runtime.identities ?? syncIdentities; }
328
329
  function savedIdentities() { return runtime.managedRepos(); }
329
- return { authenticateApprover, authenticateCredential, authorizeMutation, projectOf, resolveRouteProject, projectRequestAllowed, identify, lookupSession, restricted, visible, admissionList, codingActorAllowed, codingProjectAllowed, workAccess, familyOf, taskRepoOf, runVisible };
330
+ const visibleNow = () => {
331
+ const actor = requestContext.getStore()?.actor;
332
+ const ceiling = runtime.liveCeiling(), reaches = actor === undefined ? null : accountAccessOf(runtime.store, actor);
333
+ return repo => rowVisible(ceiling, repo) && (reaches === null || reaches(repo));
334
+ };
335
+ return { authenticateApprover, authenticateCredential, authorizeMutation, projectOf, resolveRouteProject, projectRequestAllowed, identify, lookupSession, restricted, visible, visibleNow, admissionList, codingActorAllowed, codingProjectAllowed, workAccess, familyOf, taskRepoOf, runVisible };
330
336
  }
@@ -4,6 +4,7 @@ import { projectName } from "../project.js";
4
4
  import { workIndexPage } from "../work-index.js";
5
5
  import { oneLineOf, relativeAge } from "./chrome.js";
6
6
  import { taskHref } from "./http.js";
7
+ import { taskLinkOf } from "../task-link.js";
7
8
  import { NO_HOME_ASKS, releaseSheetHref } from "./home-asks.js";
8
9
  export const HOME_NEEDS_SHOWN = 30;
9
10
  const HOME_RUNNING_SHOWN = 8;
@@ -38,13 +39,13 @@ export function startOfToday(now) {
38
39
  function rowOf(store, item, now, multi, canAnswer, closedDoor, state, release) {
39
40
  if (state === "needs" && item.askGroup === "release" && release !== null) {
40
41
  const href = releaseSheetHref(item.activeTaskId);
41
- return { id: item.rootId, title: item.title, href, state, ask: "release", reason: null,
42
+ return { id: item.rootId, title: item.title, href, state, ask: "release", group: "decide", reason: null,
42
43
  project: multi || item.repo === null ? (item.repo === null ? "Unplaced" : projectName(item.repo)) : null,
43
44
  age: relativeAge(item.updatedAt, now), line: release(item.activeTaskId), action: { label: "Review the release", href }, question: null };
44
45
  }
45
46
  const action = item.primaryAction;
46
47
  const href = action?.code === "open-result" && action.target.runId != null
47
- ? `/review?result=${encodeURIComponent(action.target.taskId)}&run=${action.target.runId}` : browserWorkActionHref(item);
48
+ ? taskLinkOf({ task: action.target.taskId, run: action.target.runId }) : browserWorkActionHref(item);
48
49
  const decisionId = action?.target.decisionId ?? null;
49
50
  const decision = decisionId === null ? null : store.getDecision(decisionId);
50
51
  const open = decision !== null && decision.state === "open" && decision.supersededReason === null;
@@ -58,13 +59,17 @@ function rowOf(store, item, now, multi, canAnswer, closedDoor, state, release) {
58
59
  const reason = ask === "wrong" ? oneLineOf((said !== null && said !== NO_REASON_RECORDED ? said : item.status.label).replace(/[.\s]+$/, ""), 120) : null;
59
60
  const door = state === "needs" && action?.code === "approve-scope" ? closedDoor(action.target.taskId) : null;
60
61
  return {
61
- id: item.rootId, title: item.title, href: taskHref(item.rootId), state, ask, reason,
62
+ id: item.rootId, title: item.title, href: taskHref(item.rootId), state, ask, ...(state === "needs" && item.ask !== null ? { group: item.ask } : {}), reason,
62
63
  project: multi || item.repo === null ? (item.repo === null ? "Unplaced" : projectName(item.repo)) : null,
63
64
  age: relativeAge(item.updatedAt, now), line: door === null ? line : door.title,
64
65
  action: door !== null ? { label: door.road === "agents" ? "Change the agents" : "Edit the plan", href: `${taskHref(action.target.taskId)}#${door.road === "agents" ? "agents" : "scope"}` }
65
66
  : href === null || action === null ? null : { label: action.label, href }, question,
66
67
  };
67
68
  }
69
+ function askRowOf(one, ask, multi, now) {
70
+ return { id: one.id, title: one.title, href: one.href, state: "needs", ask, group: WORK_GROUP_OF_ASK[ask], reason: null,
71
+ project: multi && one.repo !== null ? projectName(one.repo) : null, age: one.at === null ? "" : relativeAge(one.at, now), line: one.line, action: one.action, question: null };
72
+ }
68
73
  export function homeView(facts) {
69
74
  const { store, now, access, project } = facts;
70
75
  const read = (view, limit, completedSince) => workIndexPage(store, now, access, { view, limit, project, ...(completedSince === undefined ? {} : { completedSince }),
@@ -100,8 +105,7 @@ export function homeView(facts) {
100
105
  const multi = project === null && new Set([...yours, ...live, ...queued, ...done].map(one => one.repo ?? "").concat(extra.flatMap(one => one.repo === null ? [] : [one.repo]))).size > 1;
101
106
  const row = (item, state) => rowOf(store, item, now, multi, facts.canAnswer, facts.closedDoor, state, approver ? asks.release : null);
102
107
  const rows = yours.map(one => row(one, "needs"));
103
- const askRow = (one, ask) => ({ id: one.id, title: one.title, href: one.href, state: "needs", ask, reason: null,
104
- project: multi && one.repo !== null ? projectName(one.repo) : null, age: one.at === null ? "" : relativeAge(one.at, now), line: one.line, action: one.action, question: null });
108
+ const askRow = (one, ask) => askRowOf(one, ask, multi, now);
105
109
  const askTotals = {
106
110
  release: (approver ? needs.asks.release : 0) + held.length, approve: needs.asks.approve + (approver ? 0 : needs.asks.release), answer: needs.asks.answer,
107
111
  flow: flows.length, wrong: needs.asks.wrong, review: needs.asks.review, setup: setup.length, other: needs.asks.other,
@@ -136,3 +140,31 @@ export function homeView(facts) {
136
140
  empty: any || others > 0 ? null : { title: "No tasks yet", text: "Describe a change in a sentence; an agent writes a plan for you to approve." },
137
141
  };
138
142
  }
143
+ export const WORK_GROUP_OF_ASK = {
144
+ release: "decide", approve: "decide", answer: "decide", flow: "decide", review: "review", wrong: "unblock", setup: "unblock", other: "unblock",
145
+ };
146
+ export const WORK_GROUP_LABEL = { decide: "Decide", review: "Review", unblock: "Unblock" };
147
+ const WORK_GROUP_ORDER = ["decide", "review", "unblock"];
148
+ export function workNeeds(facts, page, filtered) {
149
+ const { store, now, project } = facts;
150
+ const yours = page.items.filter(one => one.status.views.includes("needs-you") && one.archived === undefined);
151
+ const approver = facts.approver ?? facts.canAnswer;
152
+ const asks = facts.asks ?? NO_HOME_ASKS;
153
+ const held = approver && !filtered ? asks.held : [], flows = approver && !filtered ? asks.flows : [];
154
+ const setup = approver && !filtered ? asks.setup.filter(one => one.key !== "builder" || page.builderWaits === 0) : [];
155
+ const multi = project === null && new Set(yours.map(one => one.repo ?? "").concat([...held, ...flows, ...setup].flatMap(one => one.repo === null ? [] : [one.repo]))).size > 1;
156
+ const rows = [
157
+ ...yours.map(one => rowOf(store, one, now, multi, facts.canAnswer, facts.closedDoor, "needs", approver ? asks.release : null)),
158
+ ...held.map(one => askRowOf(one, "release", multi, now)), ...flows.map(one => askRowOf(one, "flow", multi, now)), ...setup.map(one => askRowOf(one, "setup", multi, now)),
159
+ ];
160
+ const groupOf = (row) => row.group ?? WORK_GROUP_OF_ASK[row.ask ?? "other"];
161
+ const extra = { decide: held.length + flows.length, review: 0, unblock: setup.length };
162
+ const groups = WORK_GROUP_ORDER.flatMap(key => {
163
+ const listed = rows.filter(row => groupOf(row) === key);
164
+ const count = Math.max(page.groups[key] + extra[key], listed.length);
165
+ return count === 0 ? [] : [{ key, label: WORK_GROUP_LABEL[key], count, rows: listed }];
166
+ });
167
+ const tasks = page.totals["needs-you"];
168
+ const any = page.totals.all > 0 || page.totals.completed > 0 || (page.totals.archived ?? 0) > 0;
169
+ return { groups, total: tasks + held.length + flows.length + setup.length, tasks, any };
170
+ }
@@ -1,5 +1,6 @@
1
1
  import { html, htmlString, isHtml } from "../html.js";
2
2
  import { chatResultHref as sharedResultHref } from "../chat-controls.js";
3
+ import { taskLinkOf } from "../task-link.js";
3
4
  import {} from "../cli-http.js";
4
5
  import {} from "../coding-workspace.js";
5
6
  import { hasForbiddenControls } from "../decision.js";
@@ -19,6 +20,7 @@ import {} from "../toolroll-update.js";
19
20
  import { timingSafeEqual } from "node:crypto";
20
21
  import {} from "node:http";
21
22
  import { SIGN_IN_LINK_PATH } from "./session.js";
23
+ import { requestContext } from "./request-context.js";
22
24
  import { matchRoute } from "./route-table.js";
23
25
  import {} from "../folder-look.js";
24
26
  import {} from "../project-identity.js";
@@ -115,7 +117,7 @@ export function safeReturn(raw) {
115
117
  }
116
118
  return raw;
117
119
  }
118
- export const LOGIN_RETURN_PAGES = /^\/(oauth\/authorize|t\/[^/]+|r\/[1-9]\d*|code(?:\/[a-f0-9]{32}(?:\/ship)?)?|review|chat|tasks|work|board|projects|routines|recipes|fleet|settings(\/[a-z-]+)?|mode)$/;
120
+ export const LOGIN_RETURN_PAGES = /^\/(oauth\/authorize|t\/[^/]+|r\/[1-9]\d*|code(?:\/[a-f0-9]{32}(?:\/ship)?)?|review|chat|tasks|work|board|projects|routines|recipes|fleet|settings(\/[a-z-]+|\/change\/[a-z-]+)?|mode)$/;
119
121
  export function loginReturn(raw) {
120
122
  const safe = safeReturn(raw);
121
123
  if (safe === "/")
@@ -178,8 +180,9 @@ export function chatReturnWithSaid(back, said) {
178
180
  return `${back}${back.includes("?") ? "&" : "?"}said=${encodeURIComponent(said)}`;
179
181
  }
180
182
  export const chatReturnWithLatest = (back) => `${back}#latest`;
181
- export const reviewHref = (taskId, runId = null) => `/review?result=${encodeURIComponent(taskId)}${runId === null ? "" : `&run=${runId}`}`;
183
+ export const reviewHref = (taskId, runId = null) => taskLinkOf({ task: taskId, run: runId, result: true });
182
184
  export const chatResultHref = (taskId, runId, tab = "summary") => sharedResultHref(taskId, runId, tab);
185
+ export const chatPanelResultHref = (taskId, runId, tab = "summary") => `/chat?task=${encodeURIComponent(taskId)}&result=${runId}${tab === "summary" ? "" : `&tab=${tab}`}`;
183
186
  export async function form(request, cap = BODY_CAP) {
184
187
  const chunks = [];
185
188
  let size = 0;
@@ -241,3 +244,9 @@ export function refusalNext(method, url) {
241
244
  export function answersInPlace(request) {
242
245
  return request?.headers["x-toolroll-act"] === "in-place";
243
246
  }
247
+ export function refusedInPlace(response, status, words) {
248
+ if (requestContext.getStore()?.terminalAct !== true || status < 400 || response.headersSent)
249
+ return false;
250
+ respond(response, status, "application/json; charset=utf-8", JSON.stringify({ outcome: "refused", words }));
251
+ return true;
252
+ }