toolroll 0.9.114 → 0.9.116

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 (96) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/dist/agent-state-words.js +1 -1
  3. package/dist/assignment-ui.js +1 -1
  4. package/dist/browser/terminal.css +1 -1
  5. package/dist/browser/terminal.js +1 -1
  6. package/dist/browser/workspace.css +2 -2
  7. package/dist/browser/workspace.js +29 -28
  8. package/dist/chat-controls.js +1 -1
  9. package/dist/chat-quiet.js +2 -2
  10. package/dist/chat-voice.js +3 -3
  11. package/dist/check-levels.js +1 -1
  12. package/dist/claim.js +7 -2
  13. package/dist/cli.js +1 -0
  14. package/dist/code-map-cli.js +2 -1
  15. package/dist/coding-shipping-ui.js +2 -1
  16. package/dist/console-instance.js +21 -1
  17. package/dist/contracts/console-api.js +6 -2
  18. package/dist/contracts/engine-api.js +32 -4
  19. package/dist/demo-chat.js +1 -1
  20. package/dist/design/kit.css +3 -0
  21. package/dist/design/kit.js +1 -1
  22. package/dist/dispatch.js +19 -2
  23. package/dist/easy-start.js +23 -11
  24. package/dist/engine-reads.js +98 -7
  25. package/dist/export.js +16 -4
  26. package/dist/flexible-authority-end.js +94 -0
  27. package/dist/flexible-everyday-schema.js +76 -0
  28. package/dist/flexible-interactive-schema.js +133 -0
  29. package/dist/flexible-interactive.js +94 -0
  30. package/dist/flexible-laptop.js +38 -0
  31. package/dist/flexible-relay.js +9 -3
  32. package/dist/flexible-session.js +430 -10
  33. package/dist/flexible-ship.js +77 -12
  34. package/dist/flexible-sign-in.js +16 -1
  35. package/dist/flexible-start.js +17 -2
  36. package/dist/flexible-thread.js +1 -1
  37. package/dist/flexible-turns.js +9 -0
  38. package/dist/flexible-ui.js +3 -2
  39. package/dist/flexible.js +13 -0
  40. package/dist/flow-card-task.js +1 -1
  41. package/dist/home-groups.js +1 -1
  42. package/dist/lead-status.js +5 -3
  43. package/dist/lead-tools.js +1 -0
  44. package/dist/local-owner-acts.js +44 -1
  45. package/dist/local-owner.js +10 -0
  46. package/dist/needs-you.js +18 -6
  47. package/dist/operate-remote-arguments.js +1 -1
  48. package/dist/operate.js +250 -32
  49. package/dist/plan-problems-schema.js +4 -0
  50. package/dist/planner.js +17 -6
  51. package/dist/release-cli.js +2 -2
  52. package/dist/result-actions.js +1 -2
  53. package/dist/retention-ui.js +1 -1
  54. package/dist/scope.js +18 -7
  55. package/dist/server/chat.js +3 -3
  56. package/dist/server/console.css +15 -10
  57. package/dist/server/engine-api.js +161 -15
  58. package/dist/server/flows.js +4 -3
  59. package/dist/server/home.js +1 -1
  60. package/dist/server/kit.js +2 -2
  61. package/dist/server/render-chat.js +1 -1
  62. package/dist/server/render-pages.js +1 -1
  63. package/dist/server/render-tasks.js +21 -12
  64. package/dist/server/route-table.js +16 -0
  65. package/dist/server/settings-sections.js +6 -2
  66. package/dist/server/settings.js +22 -8
  67. package/dist/server/task-views.js +10 -4
  68. package/dist/server/tasks.js +51 -4
  69. package/dist/settings-kit.js +3 -3
  70. package/dist/skills-ui.js +3 -2
  71. package/dist/spend-report.js +2 -2
  72. package/dist/spend.js +3 -3
  73. package/dist/store.js +202 -7
  74. package/dist/subagent-admin.js +23 -10
  75. package/dist/subagent-backup-schema.js +36 -0
  76. package/dist/subagent-backup.js +92 -0
  77. package/dist/subagent-week.js +2 -2
  78. package/dist/subagent-work.js +70 -47
  79. package/dist/subagents-ui.js +6 -2
  80. package/dist/subagents.js +5 -2
  81. package/dist/subscription-chat.js +4 -0
  82. package/dist/surface.js +8 -1
  83. package/dist/task-status.js +13 -13
  84. package/dist/telegram-status.js +3 -3
  85. package/dist/terminal-safety.js +114 -0
  86. package/dist/toolroll-update.js +2 -1
  87. package/dist/tui/darwin-arm64/toolroll-tui +0 -0
  88. package/dist/tui/darwin-x64/toolroll-tui +0 -0
  89. package/dist/tui/linux-arm64/toolroll-tui +0 -0
  90. package/dist/tui/linux-x64/toolroll-tui +0 -0
  91. package/dist/tui-launch.js +20 -1
  92. package/dist/tui.js +1 -1
  93. package/dist/work-index.js +23 -10
  94. package/dist/workspace-ui.js +5 -5
  95. package/dist/youiyoux-intake.js +1 -1
  96. package/package.json +2 -2
package/dist/scope.js CHANGED
@@ -3,6 +3,7 @@ import { flexibleCandidateChangeRefusal } from "./flexible-merge-guard.js";
3
3
  import { cardShowsScope, cardTermsDigest } from "./chat-terms.js";
4
4
  import { mintSecret } from "./secret-mint.js";
5
5
  import { sessionStandsIn } from "./install-mode.js";
6
+ import { laptopShipSealAllowed } from "./flexible-laptop.js";
6
7
  import { passwordlessOn } from "./passwordless.js";
7
8
  import { routeChangeProblem } from "./route-change-check.js";
8
9
  import { issueImported } from "./task-source.js";
@@ -10,7 +11,7 @@ import { currentPasswordSource, passwordGuardOf, provenPasswordAccount } from ".
10
11
  import { validateScopeText } from "./task-text.js";
11
12
  import { contractChangesOf } from "./contract-changes.js";
12
13
  import { AsyncLocalStorage } from "node:async_hooks";
13
- import { currentLocalOwner, localModeOn, localOwnerInFlight, localOwnerRefusal, localOwnerStandsNow } from "./local-owner.js";
14
+ import { currentLocalOwner, LOCAL_PASSWORD_ACTS, localModeOn, localOwnerInFlight, localOwnerRefusal, localOwnerStandsNow } from "./local-owner.js";
14
15
  import { projectAuthority } from "./project-access.js";
15
16
  import { activeRemote } from "./remote-run.js";
16
17
  import { claimActor, currentActor } from "./actor.js";
@@ -620,6 +621,14 @@ export function ssoNowAvailable(by, now = Date.now()) {
620
621
  export function proveAccountNow(store, by, token, options = {}) {
621
622
  const now = Date.now();
622
623
  const local = activeRemote() === null && currentActor()?.lead !== true ? currentLocalOwner() : null;
624
+ if (local !== null && LOCAL_PASSWORD_ACTS.has(local.act)) {
625
+ if (local.account !== by || !localOwnerInFlight(local) || !localOwnerStandsNow(store, local) || token === "")
626
+ return { ok: false, reason: "not-an-approver" };
627
+ const typed = authenticateAccount(store, by, token);
628
+ if (!typed.ok)
629
+ return { ok: false, reason: typed.reason === "no-approvers" ? "no-approvers" : "not-an-approver" };
630
+ return { ok: true, method: "password-now", at: now };
631
+ }
623
632
  if (local !== null) {
624
633
  if (options.credential === true || local.account !== by || local.act === "read" || !localOwnerInFlight(local) || !localOwnerStandsNow(store, local))
625
634
  return { ok: false, reason: "not-an-approver" };
@@ -753,9 +762,11 @@ export function approve(store, taskId, by, now, sawDigest, token, mutation = {},
753
762
  return { ok: false, reason: "machine-proof" };
754
763
  const local = authenticated.method === "local-owner" ? currentLocalOwner() : null;
755
764
  if (authenticated.method === "local-owner") {
756
- if (local === null || (local.act !== "approve-plan" && !(local.act === "build-now" && fastStart !== undefined)))
765
+ const laptopShip = local !== null && local.act === "ship-thread" && chat === undefined && fastStart === undefined
766
+ && laptopShipSealAllowed(store, { by, taskId, candidate: store.getScope(taskId)?.candidate ?? null });
767
+ if (local === null || (local.act !== "approve-plan" && !(local.act === "build-now" && fastStart !== undefined) && !laptopShip))
757
768
  return { ok: false, reason: "policy", message: localOwnerRefusal(store.accountOf(by)?.passwordSet === true, "/").message };
758
- const eligible = localApprovalEligible(store, by, taskId);
769
+ const eligible = laptopShip ? localWorkEligible(store, by, taskId, { act: "ship" }) : localApprovalEligible(store, by, taskId);
759
770
  if (!eligible.ok)
760
771
  return { ok: false, reason: "policy", message: eligible.message };
761
772
  }
@@ -1231,7 +1242,7 @@ const LOCAL_REVISE_WORDS = {
1231
1242
  imported: "A task from outside needs your password to send back.",
1232
1243
  };
1233
1244
  export function localWorkEligible(store, by, taskId, purpose) {
1234
- const words = purpose.act === "approve" ? LOCAL_APPROVAL_WORDS : purpose.act === "complete" ? LOCAL_COMPLETION_WORDS : purpose.act === "revise" ? LOCAL_REVISE_WORDS
1245
+ const words = purpose.act === "approve" || purpose.act === "ship" ? LOCAL_APPROVAL_WORDS : purpose.act === "complete" ? LOCAL_COMPLETION_WORDS : purpose.act === "revise" ? LOCAL_REVISE_WORDS
1235
1246
  : purpose.act === "plan" ? LOCAL_PLAN_WORDS : LOCAL_RETRY_WORDS;
1236
1247
  const no = (reason) => ({ ok: false, reason, message: words[reason] });
1237
1248
  if (!localModeOn(store))
@@ -1240,14 +1251,14 @@ export function localWorkEligible(store, by, taskId, purpose) {
1240
1251
  if (owner !== by)
1241
1252
  return no("not-owner");
1242
1253
  const scope = store.getScope(taskId);
1243
- if ((purpose.act === "approve" || purpose.act === "retry") && scope === null)
1254
+ if ((purpose.act === "approve" || purpose.act === "retry" || purpose.act === "ship") && scope === null)
1244
1255
  return no("no-scope");
1245
- if (scope !== null && (deployGateScope(scope) || releaseCheckScope(scope)))
1256
+ if (scope !== null && ((purpose.act !== "ship" && deployGateScope(scope)) || releaseCheckScope(scope)))
1246
1257
  return no("release");
1247
1258
  if (purpose.act !== "approve" && (belongsToRelease(store, taskId) || releaseAuthorityOfTask(store, taskId) !== null))
1248
1259
  return no("release");
1249
1260
  const ref = store.handle.prepare("SELECT repo, coordinator_cid, permission_mode FROM task_ref WHERE backend = 'built-in' AND external_id = ?").get(taskId);
1250
- if (purpose.act === "approve" || purpose.act === "retry") {
1261
+ if (purpose.act === "approve" || purpose.act === "retry" || purpose.act === "ship") {
1251
1262
  const gate = store.approvalGate(taskId, by, "person");
1252
1263
  if (gate.verdict !== "seal" || gate.protectedWork)
1253
1264
  return no("protected");
@@ -1300,11 +1300,11 @@ export function createChatHandlers(runtime) {
1300
1300
  const weekAgo = new Date(now.getTime() - 7 * 86_400_000).toISOString();
1301
1301
  const counts = [
1302
1302
  { key: "working", label: "Working now", value: agents.length, href: "/?view=running" },
1303
- { key: "waiting", label: "Waiting on you", value: needs.items.filter(one => one.status.label !== "Ready for review").length, href: "/?view=needs-you" },
1304
- { key: "ready", label: "Ready to review", value: needs.items.filter(one => one.status.label === "Ready for review").length, href: "/?view=needs-you" },
1303
+ { key: "waiting", label: "Waiting on you", value: needs.items.filter(one => one.status.label !== "Ready").length, href: "/?view=needs-you" },
1304
+ { key: "ready", label: "Ready", value: needs.items.filter(one => one.status.label === "Ready").length, href: "/?view=needs-you" },
1305
1305
  { key: "done", label: "Done this week", value: done.items.filter(one => (one.completion?.at ?? one.updatedAt) >= weekAgo).length, href: "/?view=completed" },
1306
1306
  ];
1307
- const tabOf = (one) => one.assignmentState === "ready-to-check" ? one.status.label === "Ready for review" ? "ready" : "needs-you"
1307
+ const tabOf = (one) => one.assignmentState === "ready-to-check" ? one.status.label === "Ready" ? "ready" : "needs-you"
1308
1308
  : one.assignmentState === "needs-decision" ? "needs-you" : one.assignmentState === "working" || one.assignmentState === "checking" ? "running" : "finished";
1309
1309
  const catchUp = all.items.filter(one => tabOf(one) !== "finished" || one.updatedAt >= weekAgo).slice(0, 40).map(one => ({
1310
1310
  id: one.rootId, title: one.title, href: taskHref(one.rootId), project: one.repo === null ? null : projectName(one.repo), tab: tabOf(one),
@@ -370,7 +370,12 @@
370
370
  margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important;
371
371
  white-space: nowrap !important; border: 0 !important;
372
372
  }
373
- input[type=password] { font-family: var(--font-mono); }
373
+ /* A secret typed in a plain field reads in mono; the kit's own fields (sign-in, settings) keep one face for every field. */
374
+ input[type=password]:not(.k-input) { font-family: var(--font-mono); }
375
+ /* A browser's autofill paints its own background on one field and not the next: keep the field's own colours. */
376
+ input.k-input:-webkit-autofill, input.k-input:-webkit-autofill:hover, input.k-input:-webkit-autofill:focus {
377
+ -webkit-text-fill-color: var(--so-ink); -webkit-box-shadow: 0 0 0 1000px var(--so-field) inset; box-shadow: 0 0 0 1000px var(--so-field) inset;
378
+ }
374
379
  input:focus-visible, textarea:focus-visible, select:focus-visible {
375
380
  outline: 2px solid var(--so-ring); outline-offset: 1px; box-shadow: none;
376
381
  }
@@ -855,7 +860,7 @@
855
860
  background: var(--primary); color: var(--primary-foreground);
856
861
  border: 1px solid var(--primary);
857
862
  border-radius: calc(var(--radius) - 3px); padding: .525rem; margin: .75rem 0 .125rem;
858
- box-shadow: 0 10px 28px -18px rgb(255 255 255 / .5);
863
+ box-shadow: none;
859
864
  }
860
865
  @media (hover: hover) and (pointer: fine) { .side .new-task:hover { background: color-mix(in srgb, var(--primary) 85%, var(--background)); } }
861
866
  /* The same action link outside the sidebar reads as a real button. */
@@ -942,7 +947,7 @@
942
947
  @media (hover: hover) and (pointer: fine) { .demo-chat .demo-suggestions button:hover { color: var(--so-ink); border-color: var(--so-input-line); background: var(--so-soft); } }
943
948
  /* The composer: one card docked at the bottom, a borderless box that grows, the hint and a round send inside. */
944
949
  .demo-composer { position: sticky; bottom: 0; margin: 0; padding: .75rem 0 1rem; border: 0; border-radius: 0; box-shadow: none; background: linear-gradient(to bottom, transparent, var(--so-paper) 1.25rem); }
945
- .demo-composer-card { display: flex; flex-direction: column; gap: .35rem; padding: .7rem .7rem .55rem .9rem; border: 1px solid var(--so-input-line); border-radius: 1rem; background: var(--so-paper); box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04); transition: border-color .12s var(--so-ease-out), box-shadow .12s var(--so-ease-out); }
950
+ .demo-composer-card { display: flex; flex-direction: column; gap: .35rem; padding: .7rem .7rem .55rem .9rem; border: 1px solid var(--so-input-line); border-radius: 1rem; background: var(--so-paper); box-shadow: var(--so-pill-shadow); transition: border-color .12s var(--so-ease-out), box-shadow .12s var(--so-ease-out); }
946
951
  .demo-composer-card:focus-within { border-color: var(--so-muted); box-shadow: 0 0 0 3px var(--so-soft); }
947
952
  .demo-chat .demo-composer textarea { width: 100%; min-height: 1.6rem; max-height: 12rem; field-sizing: content; padding: .15rem 0; border: 0; border-radius: 0; background: none; box-shadow: none; resize: none; font-size: .9375rem; line-height: 1.55; }
948
953
  .demo-chat .demo-composer textarea:focus-visible { outline: 0; }
@@ -993,7 +998,7 @@
993
998
  font-size: .72rem; font-weight: 550; text-align: center; text-decoration: none;
994
999
  }
995
1000
  @media (hover: hover) and (pointer: fine) { .task-view-switch a:hover { color: var(--foreground); background: color-mix(in srgb, var(--muted) 70%, transparent); } }
996
- .task-view-switch a.active { color: var(--foreground); background: var(--glass-strong); box-shadow: 0 1px 5px rgb(0 0 0 / .1); }
1001
+ .task-view-switch a.active { color: var(--foreground); background: var(--glass-strong); box-shadow: var(--so-pill-shadow); }
997
1002
  .acts-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin: .75rem 0 .25rem; }
998
1003
  .acts-bar form.inline { margin: 0; display: inline-flex; align-items: center; gap: .375rem; }
999
1004
  .acts-bar form.inline button { width: auto; }
@@ -2121,7 +2126,7 @@
2121
2126
  }
2122
2127
  @media (hover: hover) and (pointer: fine) { .chat-project-card:hover {
2123
2128
  border-color: var(--glass-border); background: color-mix(in srgb, var(--muted) 82%, transparent);
2124
- box-shadow: 0 12px 28px -24px rgb(0 0 0 / .8);
2129
+ box-shadow: none;
2125
2130
  } }
2126
2131
  .chat-project-name { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: .45rem; }
2127
2132
  .chat-project-name strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .8125rem; }
@@ -2146,7 +2151,7 @@
2146
2151
  align-self: flex-end; max-width: min(82%, 40rem); padding: .75rem 1rem;
2147
2152
  border: 1px solid var(--glass-border); border-radius: 1.2rem 1.2rem .35rem 1.2rem;
2148
2153
  background: var(--user-message); color: var(--so-ink);
2149
- box-shadow: 0 10px 30px -24px rgb(0 0 0 / .9), 0 1px 0 rgb(255 255 255 / .07) inset;
2154
+ box-shadow: none;
2150
2155
  }
2151
2156
  .thread .msg.mate {
2152
2157
  position: relative; align-self: stretch; padding: .75rem .5rem .75rem 3.45rem;
@@ -2273,7 +2278,7 @@
2273
2278
  @media (hover: hover) and (pointer: fine) { .composer textarea:hover { border: 0; box-shadow: none; } }
2274
2279
  .composer button {
2275
2280
  flex: 0 0 2.75rem; width: 2.75rem; min-height: 2.75rem; padding: 0; border-radius: 999px;
2276
- font-size: 0; box-shadow: 0 10px 24px -16px rgb(255 255 255 / .65);
2281
+ font-size: 0; box-shadow: none;
2277
2282
  }
2278
2283
  .composer button::after { content: "↑"; font: 600 1.15rem/1 var(--font-sans); }
2279
2284
  .chat-main > details { margin-top: 1rem; background: color-mix(in srgb, var(--glass) 70%, transparent); }
@@ -2294,7 +2299,7 @@
2294
2299
  .chat-main { max-width: none; }
2295
2300
  .chat-projects { display: none; }
2296
2301
  .chat-workspace.projects-open::before {
2297
- content: ""; position: fixed; inset: 0 0 0 232px; z-index: 23; background: rgb(0 0 0 / .18);
2302
+ content: ""; position: fixed; inset: 0 0 0 232px; z-index: 23; background: var(--so-scrim);
2298
2303
  }
2299
2304
  .chat-workspace.projects-open .chat-projects {
2300
2305
  display: block; position: fixed; top: 4rem; left: calc(232px + 1.25rem); z-index: 25;
@@ -2316,7 +2321,7 @@
2316
2321
  .chat-workspace.projects-hidden .chat-projects, .chat-projects { display: none; }
2317
2322
  .chat-project-toggle { display: inline-flex; min-height: 2.75rem; }
2318
2323
  .chat-project-close { display: grid; place-items: center; min-height: 2.75rem; min-width: 2.75rem; }
2319
- .chat-workspace.projects-open::before { content: ""; position: fixed; inset: 0; z-index: 30; background: rgb(0 0 0 / .18); }
2324
+ .chat-workspace.projects-open::before { content: ""; position: fixed; inset: 0; z-index: 30; background: var(--so-scrim); }
2320
2325
  .chat-workspace.projects-open .chat-projects { display: block; position: fixed; top: 5rem; left: 1rem; right: 1rem; width: auto; max-height: calc(100dvh - 10rem); overflow-y: auto; overscroll-behavior: contain; z-index: 31; background: var(--card); }
2321
2326
  .chat-project-list { display: grid; gap: 0; padding: 0; }
2322
2327
  .chat-project-card {
@@ -2733,7 +2738,7 @@ html.so-nav-shallower::view-transition-new(so-page) { animation: so-page-shallow
2733
2738
  /* Board cards are panels in a frame: a hover fills them raised, never a shadow. */
2734
2739
  .decide-card:hover, .menu-row:hover {
2735
2740
 
2736
- box-shadow: 0 2px 8px -2px rgb(0 0 0 / .35);
2741
+ box-shadow: none;
2737
2742
  }
2738
2743
  }
2739
2744
  }
@@ -6,9 +6,10 @@ import { CONSOLE_FORMS, readForm } from "../contracts/console-api.js";
6
6
  import { realpathSync } from "node:fs";
7
7
  import { dirname } from "node:path";
8
8
  import { flexibleAvailable } from "../flexible-available.js";
9
+ import { laptopShipProblem } from "../flexible-laptop.js";
9
10
  import { threadsStatusNote, tidyFlexibleSignIns } from "../flexible-sign-in.js";
10
11
  import { FLEXIBLE_UNAVAILABLE } from "../flexible.js";
11
- import { admitFlexibleThreadOwner, answerFlexibleRequest, closeFlexibleSessions, flexibleThreadChangeOf, flexibleThreadLiveOf, flexibleThreadsOf, FLEXIBLE_WAIT_MS, flexibleThreadsExist, flexibleWorkOpen, openFlexibleSessions, recoverFlexibleHolders, startFlexibleThread, settleFlexibleStops, tickFlexibleSessions, waitFlexibleThreadChange } from "../flexible-session.js";
12
+ import { admitFlexibleThreadOwner, answerFlexibleRequest, cancelFlexibleThreadShip, closeFlexibleSessions, closeFlexibleThread, continueFlexibleThread, flexibleThreadShipTerms, latestFlexibleShip, sendBackFlexibleThread, shipFlexibleThread, tidyEndedFlexibleThreads, flexibleThreadChangeOf, flexibleThreadLiveOf, flexibleThreadsOf, FLEXIBLE_WAIT_MS, flexibleThreadsExist, flexibleWorkOpen, openFlexibleSessions, recoverFlexibleHolders, startFlexibleThread, settleFlexibleStops, tickFlexibleSessions, waitFlexibleThreadChange } from "../flexible-session.js";
12
13
  import { createFlexibleLauncher } from "../flexible-launcher.js";
13
14
  import { FLEXIBLE_NEXT_WORDS, flexibleReadiness, flexibleStartCard } from "../flexible-start.js";
14
15
  import { summaryLines } from "../approval-summary.js";
@@ -135,6 +136,7 @@ export function createEngineHandlers(runtime) {
135
136
  const threadsRead = () => flexible ?? (flexibleAvailable(store) || flexibleThreadsExist(store) ? openHost() : null);
136
137
  let stopping = false;
137
138
  let tidying = false;
139
+ let tidyingEnded = false;
138
140
  const ownedThread = (request, who, sessions, thread) => {
139
141
  if (rereadBrowser(runtime, request, who) === null)
140
142
  return null;
@@ -196,7 +198,9 @@ export function createEngineHandlers(runtime) {
196
198
  if (!read.ok)
197
199
  return refusal(response, 404, "thread");
198
200
  const body = { version: ENGINE_API_VERSION, on, threads: read.threads.filter(one => store.accountCanAccess(who.name, one.repo))
199
- .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 })) };
201
+ .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,
202
+ turn: one.turn?.status ?? null, ended: one.ended !== undefined, stopPending: one.stopPending, ship: one.ship?.state ?? null, turnSeq: one.turn?.seq ?? null,
203
+ shipSeq: one.ship?.seq ?? null })) };
200
204
  return sendChecked(response, 200, "liveThreads", body);
201
205
  }
202
206
  async function threadAnswer(ctx) {
@@ -214,18 +218,9 @@ export function createEngineHandlers(runtime) {
214
218
  const choice = decision === "accept" || decision === "decline" ? { decision } : question !== null && answer !== null && decision === null ? { question, answer } : null;
215
219
  if (choice === null)
216
220
  return acted(response, 400, "refused", "That answer isn't one Toolroll can read. Nothing was sent.");
217
- const sessionHash = runtime.sessions.hashOf(who.session);
218
- const admitted = sessionHash === null ? null : store.webSession(sessionHash);
219
- if (admitted === null || admitted.account !== who.name)
221
+ const held = sessionHeld(who, flexible, id);
222
+ if (held === null)
220
223
  return acted(response, 403, "refused", "Only a person signed in here can answer an agent.");
221
- const held = () => {
222
- const saved = store.webSession(admitted.idHash), account = store.accountOf(who.name);
223
- return saved !== null && saved.idHash === admitted.idHash && saved.account === admitted.account && saved.generation === admitted.generation && saved.role === admitted.role
224
- && saved.authority === admitted.authority && saved.localGeneration === admitted.localGeneration && saved.keyEpoch === admitted.keyEpoch && saved.keyHash === admitted.keyHash
225
- && saved.createdAt === admitted.createdAt && sessionWithinLifetime(saved, Date.now()) && runtime.sessions.holds(who.session)
226
- && account !== null && account.revokedAt === null && account.generation === saved.generation && account.generation === who.session.generation && account.role === saved.role
227
- && admitFlexibleThreadOwner(store, flexible, { thread: id, viewer: { name: who.name }, canAccess: repo => store.accountCanAccess(who.name, repo) }).ok;
228
- };
229
224
  const done = await answerFlexibleRequest(store, flexible, { thread: id, request: body.get("request") ?? "", shownDigest: body.get("card") ?? "",
230
225
  by: { kind: "person", name: who.name, generation: who.session.generation }, choice, held });
231
226
  return done.ok ? acted(response, 200, "done", "Sent to the agent.") : acted(response, 409, "refused", done.message);
@@ -270,7 +265,7 @@ export function createEngineHandlers(runtime) {
270
265
  freshProof: FRESH_PROOFS.has(proved.method), expectNetwork: card.network });
271
266
  if (!started.ok)
272
267
  return acted(response, 409, "refused", started.message);
273
- return acted(response, 200, "done", started.replayed ? "This thread already started." : "The thread started.");
268
+ return json(response, 200, { outcome: "done", words: started.replayed ? "This thread already started." : "The thread started.", thread: started.thread });
274
269
  }
275
270
  function familyAt(url, verb) {
276
271
  const task = matchTaskPath(url.pathname, `/${verb}$`);
@@ -377,6 +372,153 @@ export function createEngineHandlers(runtime) {
377
372
  const body = { version: ENGINE_API_VERSION, account: admitted.held.account, cookie: { name: SESSION_COOKIE, value: id }, csrf, key, epoch: runtime.keyEpoch };
378
373
  return sendChecked(response, 200, "linkRedemption", body);
379
374
  }
375
+ const sessionHeld = (who, flexible, id) => {
376
+ const sessionHash = runtime.sessions.hashOf(who.session);
377
+ const admitted = sessionHash === null ? null : store.webSession(sessionHash);
378
+ if (admitted === null || admitted.account !== who.name)
379
+ return null;
380
+ return () => {
381
+ const saved = store.webSession(admitted.idHash), account = store.accountOf(who.name);
382
+ return saved !== null && saved.idHash === admitted.idHash && saved.account === admitted.account && saved.generation === admitted.generation && saved.role === admitted.role
383
+ && saved.authority === admitted.authority && saved.localGeneration === admitted.localGeneration && saved.keyEpoch === admitted.keyEpoch && saved.keyHash === admitted.keyHash
384
+ && saved.createdAt === admitted.createdAt && sessionWithinLifetime(saved, Date.now()) && runtime.sessions.holds(who.session)
385
+ && account !== null && account.revokedAt === null && account.generation === saved.generation && account.generation === who.session.generation && account.role === saved.role
386
+ && admitFlexibleThreadOwner(store, flexible, { thread: id, viewer: { name: who.name }, canAccess: repo => store.accountCanAccess(who.name, repo) }).ok;
387
+ };
388
+ };
389
+ async function threadTurn(ctx) {
390
+ const { url, who, request, response, posted } = ctx;
391
+ const flexible = threadsOn();
392
+ if (flexible === null)
393
+ return acted(response, 404, "refused", FLEXIBLE_UNAVAILABLE);
394
+ if (who.via !== "cookie" || rereadBrowser(runtime, request, who) === null)
395
+ return acted(response, 403, "refused", "Only a person signed in here can reply to a thread.");
396
+ const id = url.pathname.slice("/agents/live/thread/".length, -"/turn".length);
397
+ const repo = ownedThread(request, who, flexible, id);
398
+ if (repo === null)
399
+ return acted(response, 404, "refused", "There's no such thread.");
400
+ if (launcher === null)
401
+ return acted(response, 409, "refused", "This console can't give a thread its network, so nothing was sent.");
402
+ const body = readForm(posted, CONSOLE_FORMS.threadTurn);
403
+ const message = body.get("message") ?? "", key = body.get("key") ?? "";
404
+ if (message.trim() === "" || !/^[0-9a-f]{32}$/.test(key))
405
+ return acted(response, 400, "refused", "That reply isn't one Toolroll can read. Nothing was sent.");
406
+ const proved = authenticateApprover(store, who.name, body.get("password") ?? "", repo);
407
+ if (!proved.ok || !START_PROOFS.has(proved.method))
408
+ return acted(response, 403, "refused", "Replying here needs your password. Nothing was sent.");
409
+ if (proved.method === "local-owner" && localActNow(store, "reply-thread") === null)
410
+ return acted(response, 403, "refused", "Replying here needs your password. Nothing was sent.");
411
+ const held = sessionHeld(who, flexible, id);
412
+ if (held === null)
413
+ return acted(response, 403, "refused", "Only a person signed in here can reply to a thread.");
414
+ const sent = await continueFlexibleThread(store, flexible, { thread: id, by: { name: who.name, generation: who.session.generation }, message, key, freshProof: FRESH_PROOFS.has(proved.method),
415
+ held, launcher });
416
+ if (!sent.ok)
417
+ return acted(response, 409, "refused", sent.message);
418
+ return json(response, 200, { outcome: "done", words: sent.replayed ? "That reply was already sent." : sent.fresh ? `Sent. Turn ${sent.seq} started with a fresh agent: it doesn't remember earlier turns.` : `Sent. Turn ${sent.seq} started.`,
419
+ turn: sent.turn });
420
+ }
421
+ const threadClose = (act) => async (ctx) => {
422
+ const { url, who, request, response } = ctx;
423
+ const flexible = threadsRead();
424
+ if (flexible === null)
425
+ return acted(response, 404, "refused", "There's no such thread.");
426
+ if (who.via !== "cookie" || rereadBrowser(runtime, request, who) === null)
427
+ return acted(response, 403, "refused", "Only a person signed in here can do that.");
428
+ const id = url.pathname.slice("/agents/live/thread/".length, -`/${act}`.length);
429
+ if (ownedThread(request, who, flexible, id) === null)
430
+ return acted(response, 404, "refused", "There's no such thread.");
431
+ if (who.authority === "local-owner" && localActNow(store, act === "end" ? "end-thread" : "stop-thread") === null)
432
+ return acted(response, 403, "refused", "Sign in with your password to do this.");
433
+ const held = sessionHeld(who, flexible, id);
434
+ if (held === null || !held())
435
+ return acted(response, 403, "refused", "Only a person signed in here can do that.");
436
+ const done = await closeFlexibleThread(store, flexible, { thread: id, by: { name: who.name, generation: who.session.generation }, act });
437
+ if (!done.ok)
438
+ return acted(response, 409, "refused", done.message);
439
+ const words = act === "end"
440
+ ? done.already ? "This thread had already ended." : done.stopPending ? "Ended. Stopping its agent…" : "Ended. You can still ship its work."
441
+ : done.stopPending ? "Stopping its agent…" : "Stopped. Reply to go on.";
442
+ return acted(response, 200, "done", words);
443
+ };
444
+ async function threadShip(ctx) {
445
+ const { url, who, request, response, posted } = ctx;
446
+ const flexible = threadsRead();
447
+ if (flexible === null)
448
+ return acted(response, 404, "refused", "There's no such thread.");
449
+ if (who.via !== "cookie" || rereadBrowser(runtime, request, who) === null)
450
+ return acted(response, 403, "refused", "Only a person signed in here can ship a thread's work.");
451
+ const id = url.pathname.slice("/agents/live/thread/".length, -"/ship".length);
452
+ if (ownedThread(request, who, flexible, id) === null)
453
+ return acted(response, 404, "refused", "There's no such thread.");
454
+ const by = { name: who.name, generation: who.session.generation };
455
+ const shown = await flexibleThreadShipTerms(store, { thread: id, by });
456
+ if (!shown.ok)
457
+ return acted(response, 409, "refused", shown.message);
458
+ const laptop = who.authority === "local-owner" && who.session.localGeneration !== null
459
+ && laptopShipProblem(store, { owner: who.name, localGeneration: who.session.localGeneration }) === null;
460
+ const command = `toolroll thread ship ${id} --key ${shown.summary.key}`;
461
+ const body = readForm(posted, CONSOLE_FORMS.threadShip);
462
+ const key = body.get("terms") ?? "";
463
+ if (key === "")
464
+ return json(response, 200, { outcome: "ship-terms", key: shown.summary.key, digest: shown.digest, lines: summaryLines(shown.summary), laptop, ...(laptop ? {} : { command }) });
465
+ if (!laptop)
466
+ return acted(response, 403, "refused", `Shipping needs your password typed now. Run \`${command}\` in a terminal. Nothing was shipped.`);
467
+ if (localActNow(store, "ship-thread") === null)
468
+ return acted(response, 403, "refused", "Shipping from here needs your own act at this computer. Nothing was shipped.");
469
+ const held = sessionHeld(who, flexible, id);
470
+ if (held === null || !held())
471
+ return acted(response, 403, "refused", "Only a person signed in here can ship a thread's work.");
472
+ const shipped = await shipFlexibleThread(store, flexible, { thread: id, by, proof: { kind: "local-owner", held }, shownDigest: body.get("digest") ?? "", shownKey: key, now: new Date() });
473
+ if (!shipped.ok)
474
+ return acted(response, 409, "refused", shipped.message);
475
+ const commit = latestFlexibleShip(store, id)?.candidate.slice(0, 12) ?? "";
476
+ return acted(response, 200, "done", `Shipping: checks run on commit ${commit}; Toolroll merges it once they pass.`);
477
+ }
478
+ async function threadShipCancel(ctx) {
479
+ const { url, who, request, response } = ctx;
480
+ const flexible = threadsRead();
481
+ if (flexible === null)
482
+ return acted(response, 404, "refused", "There's no such thread.");
483
+ if (who.via !== "cookie" || rereadBrowser(runtime, request, who) === null)
484
+ return acted(response, 403, "refused", "Only a person signed in here can do that.");
485
+ const id = url.pathname.slice("/agents/live/thread/".length, -"/ship/cancel".length);
486
+ if (ownedThread(request, who, flexible, id) === null)
487
+ return acted(response, 404, "refused", "There's no such thread.");
488
+ if (who.authority === "local-owner" && localActNow(store, "cancel-ship") === null)
489
+ return acted(response, 403, "refused", "Sign in with your password to do this.");
490
+ const done = cancelFlexibleThreadShip(store, { thread: id, by: { name: who.name, generation: who.session.generation }, now: new Date() });
491
+ return done.ok ? acted(response, 200, "done", "Ship stopped for good. Nothing more is merged from it.") : acted(response, 409, "refused", done.message);
492
+ }
493
+ async function threadShipSendBack(ctx) {
494
+ const { url, who, request, response, posted } = ctx;
495
+ const flexible = threadsOn();
496
+ if (flexible === null)
497
+ return acted(response, 404, "refused", FLEXIBLE_UNAVAILABLE);
498
+ if (who.via !== "cookie" || rereadBrowser(runtime, request, who) === null)
499
+ return acted(response, 403, "refused", "Only a person signed in here can do that.");
500
+ const id = url.pathname.slice("/agents/live/thread/".length, -"/ship/send-back".length);
501
+ const repo = ownedThread(request, who, flexible, id);
502
+ if (repo === null)
503
+ return acted(response, 404, "refused", "There's no such thread.");
504
+ const body = readForm(posted, CONSOLE_FORMS.threadSendBack);
505
+ const feedback = body.get("feedback") ?? "", key = body.get("key") ?? "";
506
+ if (feedback.trim() === "" || !/^[0-9a-f]{32}$/.test(key))
507
+ return acted(response, 400, "refused", "That note isn't one Toolroll can read. Nothing was sent.");
508
+ const proved = authenticateApprover(store, who.name, body.get("password") ?? "", repo);
509
+ if (!proved.ok || !START_PROOFS.has(proved.method))
510
+ return acted(response, 403, "refused", "Sending back here needs your password. Nothing was sent.");
511
+ if (proved.method === "local-owner" && localActNow(store, "reply-thread") === null)
512
+ return acted(response, 403, "refused", "Sending back here needs your password. Nothing was sent.");
513
+ const held = sessionHeld(who, flexible, id);
514
+ if (held === null)
515
+ return acted(response, 403, "refused", "Only a person signed in here can do that.");
516
+ const sent = await sendBackFlexibleThread(store, flexible, { thread: id, by: { name: who.name, generation: who.session.generation }, feedback, key, freshProof: FRESH_PROOFS.has(proved.method),
517
+ held, launcher, now: new Date() });
518
+ if (!sent.ok)
519
+ return acted(response, 409, "refused", sent.message);
520
+ return acted(response, 200, "done", `Sent back. Turn ${sent.seq} started${sent.fresh ? " with a fresh agent: it doesn't remember earlier turns" : ""}.`);
521
+ }
380
522
  return {
381
523
  upkeep: () => {
382
524
  if (!tidying) {
@@ -395,6 +537,10 @@ export function createEngineHandlers(runtime) {
395
537
  tickFlexibleSessions(store, host);
396
538
  }
397
539
  catch { }
540
+ if (!tidyingEnded) {
541
+ tidyingEnded = true;
542
+ void tidyEndedFlexibleThreads(store, { now: new Date() }).catch(() => { }).finally(() => { tidyingEnded = false; });
543
+ }
398
544
  if (stopping)
399
545
  return;
400
546
  stopping = true;
@@ -412,7 +558,7 @@ export function createEngineHandlers(runtime) {
412
558
  },
413
559
  registrations: [
414
560
  ...handlersOf("pages", { "engine.hello": hello, "engine.agents": agents, "engine.agents-check": agentsCheck, "agents.live.run": liveRun, "agents.live.thread": liveThread, "agents.live.threads": liveThreads,
415
- "agents.live.thread.answer": threadAnswer, "agents.live.thread.start": threadStart }),
561
+ "agents.live.thread.answer": threadAnswer, "agents.live.thread.start": threadStart, "agents.live.thread.turn": threadTurn, "agents.live.thread.stop": threadClose("stop"), "agents.live.thread.end": threadClose("end"), "agents.live.thread.ship": threadShip, "agents.live.thread.ship-cancel": threadShipCancel, "agents.live.thread.ship-send-back": threadShipSendBack }),
416
562
  ...handlersOf("tasks", { "task.steps": taskSteps, "task.approval": taskApproval, "task.diff": taskDiff }),
417
563
  ...handlersOf("people", {}, { "edge.login-link-json": redeemLink }),
418
564
  ],
@@ -208,7 +208,7 @@ export function createFlowsHandlers(runtime) {
208
208
  if (mate === null)
209
209
  return refuse(response, who, 404, "No such subagent in your projects.", "/settings/lead/subagents");
210
210
  const approvers = store.listApprovers().map(one => one.name).filter(name => store.accountCanAccess(name, mate.repo));
211
- return sendScreen(response, 200, screen(labelOf(mate), html `<p><a href="/settings/lead">Lead</a></p><h1>${labelOf(mate)}</h1>${(subagentPageHtml(store, mate, who.name, projectName, who.via === "cookie" && who.role === "approver", approvers, { said: url.searchParams.get("said"), problem: url.searchParams.get("problem"), query: url.searchParams.get("q") }))}`, { chrome: chromeFor(mate.repo, "settings") }));
211
+ return sendScreen(response, 200, screen(labelOf(mate), html `<p><a href="/settings/lead">Lead</a></p><h1>${labelOf(mate)}</h1>${(subagentPageHtml(store, mate, who.name, projectName, who.via === "cookie" && who.role === "approver", approvers, { said: url.searchParams.get("said"), problem: url.searchParams.get("problem"), backupDraft: url.searchParams.get("backupDraft"), query: url.searchParams.get("q") }))}`, { chrome: chromeFor(mate.repo, "settings") }));
212
212
  }
213
213
  async function subagentSoulFile(ctx) {
214
214
  const { url, who, response } = ctx;
@@ -419,11 +419,12 @@ export function createFlowsHandlers(runtime) {
419
419
  }
420
420
  const done = part === "state" ? setSubagentState(store, mate, body.get("state") === "removed" ? "removed" : body.get("state") === "paused" ? "paused" : "active", who.name, now)
421
421
  : part === "note" ? tellSubagent(store, mate, body.get("note") ?? "", who.name, now)
422
- : part === "settings" ? subagentSettings(store, mate, { model: body.get("model") ?? "default", dailyTurns: Number(body.get("dailyTurns")), manager: body.get("manager") ?? mate.manager }, who.name, now)
422
+ : part === "settings" ? subagentSettings(store, mate, { model: body.get("model") ?? "default", dailyTurns: Number(body.get("dailyTurns")), manager: body.get("manager") ?? mate.manager,
423
+ ...(body.get("backupPresent") === "1" ? { codexBackupModel: (body.get("codexBackupModel") ?? "").trim() || null } : {}) }, who.name, now, { proveBackup: () => authenticateApprover(who, body.get("password") ?? "", mate.repo).ok })
423
424
  : sendSubagentSummaries(store, mate.repo, now, mate.id) > 0 ? { ok: true, said: `Sent today's summary to ${mate.manager}.` } : { ok: false, said: "The summary couldn't be sent." };
424
425
  if (part === "state" && body.get("state") === "removed" && done.ok)
425
426
  return redirect(response, `/settings/lead/subagents?said=${encodeURIComponent(done.said)}`);
426
- return redirect(response, `${back}?${done.ok ? "said" : "problem"}=${encodeURIComponent(done.said)}${part === "note" ? "#memory" : ""}`);
427
+ return redirect(response, `${back}?${done.ok ? "said" : "problem"}=${encodeURIComponent(done.said)}${part === "settings" && !done.ok && body.get("backupPresent") === "1" ? `&backupDraft=${encodeURIComponent(body.get("codexBackupModel") ?? "")}` : ""}${part === "note" ? "#memory" : part === "settings" ? "#backup" : ""}`);
427
428
  };
428
429
  async function createFromGallery(ctx) {
429
430
  const { url, who, response, posted } = ctx;
@@ -84,7 +84,7 @@ export function homeView(facts) {
84
84
  { key: "needs", label: "Needs you", value: totals["needs-you"], href: `/tasks?${scopeQuery}view=needs-you` },
85
85
  { key: "running", label: "Running", value: totals.running, href: `/tasks?${scopeQuery}view=running` },
86
86
  { key: "queued", label: "Queued", value: totals.queued, href: `/tasks?${scopeQuery}view=queued` },
87
- { key: "finished", label: "Finished", value: totals.completed, href: `/tasks?${scopeQuery}view=completed` },
87
+ { key: "finished", label: "Complete", value: totals.completed, href: `/tasks?${scopeQuery}view=completed` },
88
88
  ];
89
89
  const seen = new Set();
90
90
  const take = (items, view) => items.filter(one => {
@@ -132,10 +132,10 @@ ${items.map(item => html `<div class="k-needs-item"><div><b>${item.title}</b>${i
132
132
  }
133
133
  export function timing(options) {
134
134
  const bars = timingBars(options.rows, options.scale);
135
- const mark = (st) => st === "wait" ? html `<span class="k-wd"></span>` : st === "q" ? html `<span class="k-qd"></span>` : st === "run" ? html `<span class="k-rund"></span>` : icon(st === "ok" ? "check" : "x", true);
135
+ const mark = (st) => st === "wait" ? html `<span class="k-wd"></span>` : (st === "q" || st === "waiting") ? html `<span class="k-qd"></span>` : st === "run" ? html `<span class="k-rund"></span>` : icon(st === "ok" ? "check" : "x", true);
136
136
  const rows = options.rows.map((row, index) => {
137
137
  const bar = bars[index];
138
- const now = row.st === "run" || row.st === "bad" || row.st === "wait";
138
+ const now = row.st === "run" || row.st === "bad" || row.st === "wait" || row.st === "waiting";
139
139
  return html `<div class="${cls("k-crow", row.st, now && "now")}"><span class="k-crow-i">${mark(row.st)}</span>\
140
140
  <span class="k-crow-n">${row.name}<span class="k-crow-sub">${row.sub ?? (row.st === "q" ? "not reached" : "")}</span></span>\
141
141
  <span class="k-crow-lane">${bar ? html `<i class="k-crow-bar" style="left:${bar.left.toFixed(2)}%;width:${bar.width.toFixed(2)}%"></i>` : ""}</span>\
@@ -105,7 +105,7 @@ export function taskChatLiveRegion(focus, csrf, fragment = false, inert = false,
105
105
  const approvalContent = (inert && focus.approval !== null && focus.plan !== "requested"
106
106
  ? html `<section class="card chat-action-card"><span class="eyebrow">approval ready</span><h2>Finish the current chat response first</h2><p class="meta">The secure approval step appears here as soon as this response lands.</p></section>`
107
107
  : fragment && focus.approval !== null && focus.plan !== "requested"
108
- ? html `<section class="card chat-action-card chat-refresh-action"><a class="button-link" href="${approvalHref}" data-primary-action>Approve plan</a></section>`
108
+ ? html `<section class="card chat-action-card chat-refresh-action"><a class="button-link" href="${approvalHref}" data-primary-action>Review plan</a></section>`
109
109
  : taskChatApproval(focus, csrf));
110
110
  const approvalLeads = focus.dispatch?.action === "approve-scope" ||
111
111
  (focus.assignment?.primaryAction?.code === "approve-scope" && focus.assignment.primaryAction.target.taskId === focus.executionId);
@@ -339,7 +339,7 @@ export function workPage(chrome, data) {
339
339
  ask: null, group: 'rest', rank: 4, action: null, detail: archivedWords(row.archived), problem: null, notes: [], tidy,
340
340
  };
341
341
  const actionHref = workActionHref(row);
342
- const needsYouDetail = (row.status.views.includes('needs-you') || row.status.label === 'Failed') && !['write-scope', 'approve-scope'].includes(row.primaryAction?.code ?? '') && row.status.label !== 'Ready for review' && row.status.detail !== row.status.label && row.status.detail !== row.familyProblem;
342
+ const needsYouDetail = (row.status.views.includes('needs-you') || row.status.label === 'Failed') && !['write-scope', 'approve-scope'].includes(row.primaryAction?.code ?? '') && row.status.label !== 'Ready' && row.status.detail !== row.status.label && row.status.detail !== row.familyProblem;
343
343
  return {
344
344
  id: row.rootId, title: row.title, href: taskHref(row.rootId), project: projectOf(row), age: relativeAge(row.updatedAt, data.now),
345
345
  status: { label: row.status.label, tone: row.status.tone, token: row.status.token }, chip: row.chip, word: chip,
@@ -1711,11 +1711,15 @@ export function taskBodyParts(data) {
1711
1711
  const decisions = data.decisions.length === 0
1712
1712
  ? ""
1713
1713
  : html `<h2>Decisions</h2>${joinHtml(data.decisions.map(decision => html `<p class="row"><a href="/d/${decision.id}">${decision.question}</a> <span class="meta">${decision.supersededReason !== null ? closedQuestionWords(decision.supersededReason) : decision.state}${isOverdue(decision, data.now) ? " · overdue" : ""}</span></p>`), "\n")}`;
1714
+ const planStoppedHtml = data.planStopped == null ? "" : html `<div class="card" data-plan-stopped><p><strong>${data.planStopped.line}</strong></p>${data.planStopped.problems === null ? "" : html `<p class="meta">Why the plan was refused</p><ul>${joinHtml(data.planStopped.problems.map(one => html `<li>${one}</li>`), "")}</ul>`}${data.planStopped.agentSaid === null ? "" : html `<details><summary>What the agent said</summary><pre class="mono">${data.planStopped.agentSaid.join("\n")}</pre></details>`}</div>`;
1715
+ const planBackoffHtml = data.planBackoff == null ? "" : html `<div class="card" data-plan-backoff><p>${data.planBackoff.line}</p>${data.planBackoff.agentSaid === null ? "" : html `<details><summary>What the agent said</summary><pre class="mono">${data.planBackoff.agentSaid.join("\n")}</pre></details>`}</div>`;
1714
1716
  const incidents = data.incidents.length === 0
1715
1717
  ? ""
1716
- : html `<h2>Incidents</h2>${joinHtml(data.incidents.map(one => one.resolvedAt === null
1717
- ? html `<p class="row">${incidentWords(one.kind)} ${postForm(`/i/${one.id}/resolve`, html `<button type="submit">Resolve</button>`, { attrs: { class: "inline" } })}</p>`
1718
- : html `<p class="row meta">${incidentWords(one.kind)} — resolved by ${one.resolvedBy ?? "?"}</p>`), "\n")}`;
1718
+ : html `<h2>Incidents</h2>${planStoppedHtml}${joinHtml(data.incidents.map(one => one.resolvedAt === null && data.planStopped?.incident === one.id
1719
+ ? html `<p class="row">${incidentWords(one.kind)} ${data.planStopped.again === null || data.csrf === "" ? "" : act("plan", "Plan again", { incident: String(one.id), source: data.planStopped.again.source })}</p>`
1720
+ : one.resolvedAt === null
1721
+ ? html `<p class="row">${incidentWords(one.kind)} ${postForm(`/i/${one.id}/resolve`, html `<button type="submit">Resolve</button>`, { attrs: { class: "inline" } })}</p>`
1722
+ : html `<p class="row meta">${incidentWords(one.kind)} — resolved by ${one.resolvedBy ?? "?"}</p>`), "\n")}`;
1719
1723
  const stalled = task.state === "failed" || data.incidents.some(one => one.resolvedAt === null);
1720
1724
  const dependencyChoiceNeeded = data.dispatch?.action === "repair-dependency";
1721
1725
  const waitsFor = data.waitsFor ?? [];
@@ -1729,15 +1733,18 @@ export function taskBodyParts(data) {
1729
1733
  : html `<h2>Waits for</h2>${waitRows === "" ? html `<p class="meta">Nothing. It starts when a builder is free.</p>` : waitRows}${waitAdd}`;
1730
1734
  const canPlan = data.plan === null && !approval.approved && !data.claimed && task.state === "queued" && (data.coordinator === null || data.coordinator === undefined);
1731
1735
  const cardRetries = task.state === "failed" && data.assignment != null && data.csrf !== "";
1732
- const primaryAct = stopControlsActive || cardRetries ? null : stalled && !data.claimed
1733
- ? { html: act("requeue", "Retry, keeping the branch and workspace", data.retryPins == null ? {} : { run: String(data.retryPins.run), digest: data.retryPins.digest }), why: "Clears the repeated failures and queues the task again. The branch and workspace are kept.", whyClass: "retry" }
1734
- : canPlan
1735
- ? { html: act("plan", "plan first", data.planSource == null ? {} : { source: data.planSource }), why: "plan first sends an agent to read the project, ask you questions and propose a plan. Nothing builds until you approve it.", whyClass: "plan" }
1736
- : data.plan === "requested"
1737
- ? null
1738
- : task.state === "queued" && !data.claimed && (data.position?.position ?? 1) > 1
1739
- ? { html: act("next", "build this next"), why: "moves it to the front of its queue: the next free builder takes it first. It still needs approval.", whyClass: "next" }
1740
- : null;
1736
+ const planAgainPins = data.planStopped?.again ?? null;
1737
+ const primaryAct = stopControlsActive || cardRetries ? null : planAgainPins !== null && data.planStopped != null && !data.claimed && data.csrf !== ""
1738
+ ? { html: act("plan", "Plan again", { incident: String(data.planStopped.incident), source: planAgainPins.source }), why: "The planner tries again. Nothing builds until you approve the plan.", whyClass: "plan" }
1739
+ : stalled && !data.claimed && data.planStopped == null
1740
+ ? { html: act("requeue", "Retry, keeping the branch and workspace", data.retryPins == null ? {} : { run: String(data.retryPins.run), digest: data.retryPins.digest }), why: "Clears the repeated failures and queues the task again. The branch and workspace are kept.", whyClass: "retry" }
1741
+ : canPlan
1742
+ ? { html: act("plan", "plan first", data.planSource == null ? {} : { source: data.planSource }), why: "plan first sends an agent to read the project, ask you questions and propose a plan. Nothing builds until you approve it.", whyClass: "plan" }
1743
+ : data.plan === "requested"
1744
+ ? null
1745
+ : task.state === "queued" && !data.claimed && (data.position?.position ?? 1) > 1
1746
+ ? { html: act("next", "build this next"), why: "moves it to the front of its queue: the next free builder takes it first. It still needs approval.", whyClass: "next" }
1747
+ : null;
1741
1748
  const holdAct = postForm(`${taskHref(task.id)}/hold`, html `<input type="text" name="reason" class="inline" placeholder="reason (optional)" aria-label="hold reason"><button type="submit">Hold the next attempt</button>`, { attrs: { class: "inline act-hold" } });
1742
1749
  const canHold = task.state === "queued" || task.state === "running" || task.state === "failed";
1743
1750
  const actsBar = joinHtml([
@@ -1833,6 +1840,7 @@ export function taskBodyParts(data) {
1833
1840
  const layoutTail = joinHtml([
1834
1841
  html `<div class="task-layout"><div class="task-main">`,
1835
1842
  attemptPanel,
1843
+ planBackoffHtml,
1836
1844
  data.coordinatorProposals == null || data.coordinatorProposals.rows.length === 0
1837
1845
  ? ""
1838
1846
  : section("proposals", html `<h2>Proposed by your lead</h2>${coordinatorProposalsSection(data.coordinatorProposals.rows, data.coordinatorProposals.decisions, data.coordinatorProposals.now, false, taskHref(data.task.id))}`, true, data.coordinatorProposals.rows.length),
@@ -2104,6 +2112,7 @@ export function taskBodyParts(data) {
2104
2112
  : statusCard.action !== null && rebuild === null && bareSelfLink(statusCard.action.href) ? { ...statusCard, action: null } : statusCard),
2105
2113
  statusHtml: data.archived != null ? "" : htmlString(statusHtml),
2106
2114
  failure: failedCard && data.failure != null ? { line: data.failure.line, evidence: data.failure.evidence, suggestion: data.failure.suggestion, link: data.failure.link } : null,
2115
+ planning: data.planBackoff ?? null,
2107
2116
  retry,
2108
2117
  runChecks,
2109
2118
  progress: progress === null ? null : { ...progress, steps: (data.milestoneProgress ?? []).map(one => ({ title: one.description, state: one.state })) },