toolroll 0.9.110 → 0.9.111

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +5 -1
  3. package/THIRD_PARTY_NOTICES.md +30 -0
  4. package/dist/agent-detect.js +1 -1
  5. package/dist/agent-said-schema.js +4 -0
  6. package/dist/agent-said.js +23 -0
  7. package/dist/approval-summary.js +39 -8
  8. package/dist/browser/THIRD_PARTY_NOTICES.txt +30 -0
  9. package/dist/builder.js +6 -1
  10. package/dist/claim.js +28 -13
  11. package/dist/cli-help.js +1 -1
  12. package/dist/codex-limits.js +21 -8
  13. package/dist/console-instance.js +2 -1
  14. package/dist/contracts/console-api.js +3 -2
  15. package/dist/contracts/engine-api.js +15 -3
  16. package/dist/contracts/route.js +1 -0
  17. package/dist/dispatch.js +1 -1
  18. package/dist/dispose.js +15 -9
  19. package/dist/easy-start.js +15 -1
  20. package/dist/engine-reads.js +79 -2
  21. package/dist/fast-start.js +20 -11
  22. package/dist/flexible-start.js +1 -1
  23. package/dist/integrations.js +6 -1
  24. package/dist/local-owner.js +1 -0
  25. package/dist/needs-you.js +2 -0
  26. package/dist/operate.js +55 -8
  27. package/dist/phase-routing.js +3 -1
  28. package/dist/plane-review.js +1 -1
  29. package/dist/proposal.js +2 -2
  30. package/dist/provider-connection.js +14 -2
  31. package/dist/route-store.js +1 -1
  32. package/dist/serve.js +5 -3
  33. package/dist/server/pages.js +4 -1
  34. package/dist/server/render-tasks.js +5 -2
  35. package/dist/server/route-table.js +2 -0
  36. package/dist/server/settings-section-table.js +3 -0
  37. package/dist/server/settings-sections.js +36 -0
  38. package/dist/server/settings.js +36 -0
  39. package/dist/server/tasks.js +31 -4
  40. package/dist/settings-proofs.js +1 -0
  41. package/dist/store.js +83 -11
  42. package/dist/task-sizing-schema.js +14 -0
  43. package/dist/task-sizing.js +76 -10
  44. package/dist/toolroll-update.js +3 -1
  45. package/dist/tui/darwin-arm64/toolroll-tui +0 -0
  46. package/dist/tui/darwin-x64/toolroll-tui +0 -0
  47. package/dist/tui/linux-arm64/toolroll-tui +0 -0
  48. package/dist/tui/linux-x64/toolroll-tui +0 -0
  49. package/dist/webhooks.js +8 -2
  50. package/dist/work-index.js +2 -2
  51. package/package.json +1 -1
package/dist/serve.js CHANGED
@@ -1012,7 +1012,8 @@ export function createDecisionServer(options) {
1012
1012
  return localSignInChecking;
1013
1013
  const ask = (again) => Promise.all(LOCAL_AGENTS.map(one => connectionCheck(one, again).catch(() => null)));
1014
1014
  localSignInChecking = ask(fresh)
1015
- .then(first => first.some(one => one !== null && SIGNED_IN_STATES.has(one.state)) || !first.some(one => one === null || one.state === "unverified") ? first : ask(true))
1015
+ .then(first => first.some(one => one !== null && SIGNED_IN_STATES.has(one.state)) || !first.some(one => one === null || one.state === "unverified") ? first
1016
+ : Promise.all(LOCAL_AGENTS.map((one, index) => { const was = first[index] ?? null; return was === null || was.state === "unverified" ? connectionCheck(one, true).catch(() => null) : was; })))
1016
1017
  .then(async (answers) => {
1017
1018
  const at = clock().getTime();
1018
1019
  const [claudeSeen, codexSeen] = answers.map((value, index) => heldSignIn(LOCAL_AGENTS[index], value, at));
@@ -1768,8 +1769,9 @@ export function createDecisionServer(options) {
1768
1769
  waits.push(lastChecks.run(`project-mcp:${repo}`, async () => { const looked = await lookProjectMcp(repo); if (looked.ok)
1769
1770
  savedProjectMcp.set(repo, looked.value); return looked.ok; }));
1770
1771
  }
1771
- if (lastChecks.due(`codex-tools:${repo}`, 10 * 60_000))
1772
- waits.push(lastChecks.run(`codex-tools:${repo}`, () => codexServers(repo)));
1772
+ if (SIGNED_IN_STATES.has(knownConnections.get("codex")?.state ?? "") && lastChecks.due(`codex-tools:${repo}`, 10 * 60_000)) {
1773
+ waits.push(lastChecks.run(`codex-tools:${repo}`, async () => SIGNED_IN_STATES.has((await connectionCheck("codex", true)).state) ? codexServers(repo) : null));
1774
+ }
1773
1775
  }
1774
1776
  if (databaseFile !== null && lastChecks.due("storage", 30 * 60_000)) {
1775
1777
  waits.push(lastChecks.run("storage", () => checkoutPlan(store, storagePool(databaseFile), clock(), { manual: true })));
@@ -79,6 +79,7 @@ import { flowAsks, NO_HOME_ASKS, releaseAsks, setupAsks } from "./home-asks.js";
79
79
  import { workIndexPage } from "../work-index.js";
80
80
  import { checkEngineResponse, ENGINE_API_VERSION } from "../contracts/engine-api.js";
81
81
  import { readRunLive } from "./engine-api.js";
82
+ import { waitingForTasks } from "../engine-reads.js";
82
83
  export function createPagesHandlers(runtime, work) {
83
84
  const { identities, clock, lastChecks, store, visible, consoleProjects, restricted, ceiling, options, projectFamilyPeek, sendScreen, chromeFor, unscopedMode, admissionList, taskRepoOf, taskViewData, runVisible, evidenceRoot, workAccess, identify, liveCeiling, sessions, deletedRepos, authenticateApprover, authenticateCredential, consumeApprovalNonce, projectOf, lookupSession, firstRunStepsNow, chatEnablement, leadPrincipal, leadConversationRows, outsideAdmissions } = runtime;
84
85
  async function projectsBrowse(ctx) {
@@ -1249,10 +1250,12 @@ export function createPagesHandlers(runtime, work) {
1249
1250
  })();
1250
1251
  const needOf = (row) => ({ id: row.id, title: row.title, href: row.href, project: row.project, age: row.age, state: row.state, ask: row.ask,
1251
1252
  ...(row.group === undefined ? {} : { group: row.group }), reason: row.reason, line: row.line, action: row.action, question: row.question });
1253
+ const waiting = waitingForTasks(store, list.rows.map(row => row.id), now);
1252
1254
  const body = {
1253
1255
  version: ENGINE_API_VERSION, project: view.project, projectName: view.projectName, needsCount: view.needsCount, groups: list.groups,
1254
1256
  rows: list.rows.map(row => ({ id: row.id, title: row.title, href: row.href, project: row.project, age: row.age, status: row.status, word: row.word, ask: row.ask,
1255
- chip: row.chip, group: row.group, rank: row.rank, detail: row.detail, problem: row.problem, need: row.need === undefined ? null : needOf(row.need) })),
1257
+ chip: row.chip, group: row.group, rank: row.rank, detail: row.detail, problem: row.problem, need: row.need === undefined ? null : needOf(row.need),
1258
+ waiting: waiting.get(row.id) ?? null })),
1256
1259
  needs: view.needs.map(group => ({ key: group.key, label: group.label, count: group.count, rows: group.rows.map(needOf) })),
1257
1260
  next: list.pages.next, room: "workspace", spend,
1258
1261
  };
@@ -471,7 +471,7 @@ export function summaryWarningsHtml(summary) {
471
471
  export function summaryUsualHtml(summary) {
472
472
  if (summary.usual.length === 0)
473
473
  return html ``;
474
- return html `<details class="approval-details terms-usual" data-terms-usual><summary>${summary.usualLabel}</summary><dl class="approval-rows">${summary.usual.map(one => html `<div class="approval-row"><dt>${one.label}</dt><dd><p>${one.words}</p></dd></div>`)}</dl></details>`;
474
+ return html `<details class="approval-details terms-usual" data-terms-usual><summary>${summary.usualSummary === "" ? summary.usualLabel : `${summary.usualLabel}: ${summary.usualSummary}`}</summary><dl class="approval-rows">${summary.usual.map(one => html `<div class="approval-row"><dt>${one.label}</dt><dd><p>${one.words}</p></dd></div>`)}</dl></details>`;
475
475
  }
476
476
  export const EVIDENCE_SHEET = Object.fromEntries(Object.entries(EVIDENCE_WORDS).map(([kind, words]) => [kind, `${words.charAt(0).toUpperCase()}${words.slice(1)}`]));
477
477
  export function earlierVersionsWords(active, running) {
@@ -1759,7 +1759,7 @@ export function taskBodyParts(data) {
1759
1759
  ? postForm(`${taskHref(task.id)}/cancel`, joinHtml([
1760
1760
  data.coordinator == null ? "" : html `<label>Reason for cancellation<textarea name="reason" rows="3" maxlength="500" required>${data.cancelDraft ?? ""}</textarea></label>`,
1761
1761
  html `<button type="submit" class="danger">Confirm cancellation</button>`,
1762
- ]))
1762
+ ]), { hidden: cancelPinsOf(task.state, data.runs) })
1763
1763
  : "";
1764
1764
  const cancelAct = cancelForm === "" ? "" : html `<details class="arm-danger"${data.cancelDraft === undefined ? "" : html ` open`}><summary>Cancel task</summary>${cancelForm}</details>`;
1765
1765
  const sectionParts = [];
@@ -2327,3 +2327,6 @@ export function planVersionDetailsHtml(digest) {
2327
2327
  function agentlessRoute(dispatch, route) {
2328
2328
  return dispatch?.summary === NO_AGENT_TITLE && route?.kind === "unreadable" && (route.problem ?? "").includes("has no exact model");
2329
2329
  }
2330
+ export function cancelPinsOf(state, runs) {
2331
+ return { state, run: runs.length === 0 ? "none" : String(Math.max(...runs.map(one => one.id))) };
2332
+ }
@@ -87,6 +87,7 @@ const LOCAL_POSTS = Object.freeze({
87
87
  "settings.knowledge-note": "memory-review",
88
88
  "settings.knowledge-tidy": "memory-review",
89
89
  "settings.advanced": "view-preference",
90
+ "settings.task-sizing": "task-sizing-switch",
90
91
  "agents.seen": "mark-seen",
91
92
  "agents.watch": "watch-agent",
92
93
  });
@@ -416,6 +417,7 @@ post("tasks", "sweep.cancel-rest", "^\\/sweeps\\/[1-9][0-9]{0,9}\\/cancel-rest$"
416
417
  get("settings", "settings.passwordless", "/settings/passwordless", { ...free, ...operator("An instance operator sets Passwordless.", "/settings") });
417
418
  post("settings", "settings.passwordless-send", "/settings/passwordless", { callers: ["cookie"], ...operator("An instance operator sets Passwordless.", "/settings") });
418
419
  post("settings", "settings.local-mode-off", "/settings/local-mode/off", { callers: ["cookie"], scope: "step-up", ...operator("An instance operator turns off local mode.", "/settings/general?section=local-mode") });
420
+ post("settings", "settings.task-sizing", "/settings/task-sizing", { scope: "step-up", limited: "deny", ...operator("An instance operator chooses how tasks are sized.", "/settings/general?section=task-sizing") });
419
421
  post("settings", "settings.just-me", "/settings/install-mode/solo", { callers: ["cookie"], scope: "step-up", ...operator("An instance operator says it's just them.", "/settings/general?section=install-mode") });
420
422
  post("settings", "settings.release-approval-send", "/settings/release-approval", { callers: ["cookie"], ...approver("An approver sets how releases are approved.", "/settings/approval") });
421
423
  post("pages", "ledger.checkpoint", "/ledger/checkpoint", operator("An instance operator makes ledger checkpoints.", "/ledger"));
@@ -17,6 +17,9 @@ export const SETTINGS_SECTIONS = Object.freeze([
17
17
  { id: "install-mode", area: "general", title: "Solo or team", pinnedFrom: "settings.group-general", policy: GROUP_PAGE,
18
18
  read: [], scope: {}, act: { "just-me": ["full-session", "operator"] }, changes: [{ id: "just-me", act: "just-me", proof: "install-solo" }],
19
19
  opens: false, scripts: [], oldIds: [] },
20
+ { id: "task-sizing", area: "general", title: "Size tasks with a quick model call (Claude Haiku, on your plan)", pinnedFrom: "settings.group-general", policy: GROUP_PAGE,
21
+ read: ["installation"], scope: {}, act: { switch: ["cookie-session", "operator"] }, changes: [{ id: "task-sizing", act: "switch", proof: "task-sizing" }],
22
+ opens: false, scripts: [], oldIds: [] },
20
23
  { id: "advanced", area: "general", title: "Show advanced features", pinnedFrom: "settings.group-advanced", policy: GROUP_PAGE,
21
24
  read: [], scope: { "operator-pages": ["operator"] }, act: { switch: ["cookie-session"] }, changes: [], opens: true, scripts: [], oldIds: ["show-advanced"] },
22
25
  { id: "local-mode", area: "general", title: "Local mode", pinnedFrom: "settings.group-access", policy: GROUP_PAGE,
@@ -269,6 +269,41 @@ function installModeSection(deps) {
269
269
  },
270
270
  };
271
271
  }
272
+ export const TASK_SIZING_OFF_WORDS = "Off: no model call before you approve; uncertain tasks get a plan first.";
273
+ const SIZER_NAME = { claude: "Claude Haiku, on your plan", jev: "Jev via OpenRouter, your credit" };
274
+ const SIZER_SHORT = { claude: "Claude Haiku", jev: "Jev via OpenRouter" };
275
+ function taskSizingSection(deps) {
276
+ return {
277
+ loadSummary: ctx => {
278
+ const read = deps.taskSizing();
279
+ return { on: read.on && !read.byEnv, byEnv: read.byEnv, canSwitch: ctx.can["switch"] === true, sizer: read.sizer, available: read.available, moved: read.chosen && !read.on };
280
+ },
281
+ render: ({ summary, attrs }) => settingsSection({ id: "task-sizing", title: `Size tasks with a quick model call (${SIZER_NAME[summary.on && summary.sizer !== null ? summary.sizer : summary.available]})`, state: summary.on ? " · on" : " · off", attrs,
282
+ lead: summary.byEnv ? "Off: TOOLROLL_NO_TASK_CLASSIFIER is set on this computer, so no model call happens before you approve; uncertain tasks get a plan first."
283
+ : summary.on ? `On: before you approve, a quick call to ${SIZER_SHORT[summary.sizer]} sizes each new task, and the plan names it.`
284
+ : summary.moved && summary.sizer !== null ? `Off: you turned it on for ${SIZER_SHORT[summary.sizer]}, but ${SIZER_SHORT[summary.available]} is the one available now, so nothing is sent. Turn it on again to choose it. Uncertain tasks get a plan first.`
285
+ : TASK_SIZING_OFF_WORDS,
286
+ ...(summary.canSwitch && !summary.byEnv ? { right: btn(summary.on ? "Turn off" : "Turn on", { sm: true, href: "/settings/change/task-sizing" }) } : {}), body: html `` }),
287
+ refusal: "An instance operator changes how tasks are sized.",
288
+ renderChange: ({ declaration, summary, problem }) => {
289
+ const home = sectionHref(declaration);
290
+ const on = summary?.on === true;
291
+ const choice = summary === null ? "claude" : on && summary.sizer !== null ? summary.sizer : summary.available;
292
+ const title = `Size tasks with a quick model call (${SIZER_NAME[choice]})`;
293
+ const words = summary === null || summary.byEnv
294
+ ? html `${infoLine("TOOLROLL_NO_TASK_CLASSIFIER is set on this computer, so task sizing stays off.")}<div class="k-acts">${btn("Back to General", { href: home })}</div>`
295
+ : joinHtml([
296
+ html `<p>${on ? `Turn it off. ${TASK_SIZING_OFF_WORDS}` : choice === "jev"
297
+ ? "Turn it on. Before you approve, each new task's words go to Jev through your OpenRouter key (your credit) to size it: small ones build at once on a fast model, risky ones plan first, and the plan names the model that sized it. Only Jev is asked; if the key goes, sizing turns itself off."
298
+ : "Turn it on. Before you approve, a quick call to Claude Haiku on your own plan sizes each new task: small ones build at once on a fast model, risky ones plan first, and the plan names the model that sized it. Only Claude is asked; if an OpenRouter key is saved later, sizing turns itself off until you choose again."}</p>`,
299
+ problem === null ? "" : notice(problem),
300
+ kitSectionForm({ proof: "task-sizing", action: "/settings/task-sizing", id: "task-sizing-form", native: true, save: { label: on ? "Turn off" : "Turn on" }, confirm: on ? "Turn off task sizing" : "Turn on task sizing", hidden: { enabled: on ? "off" : "on", sizer: choice }, body: html `` }),
301
+ html `<div class="k-acts">${btn("Cancel", { variant: "ghost", href: home })}</div>`,
302
+ ]);
303
+ return { title, body: html `<div data-kit-page>${phoneHeader(title, { back: home })}${doc(docHeader({ title, back: [home, "General"], same: true }), words)}</div>` };
304
+ },
305
+ };
306
+ }
272
307
  export function generalSections(deps) {
273
308
  return {
274
309
  appearance: appearanceSection(),
@@ -276,6 +311,7 @@ export function generalSections(deps) {
276
311
  "your-password": yourPasswordSection(deps),
277
312
  version: versionSection(deps),
278
313
  "install-mode": installModeSection(deps),
314
+ "task-sizing": taskSizingSection(deps),
279
315
  advanced: advancedSection(),
280
316
  "local-mode": localModeSection(deps),
281
317
  };
@@ -150,6 +150,8 @@ import { sweepSchedule } from "../storage-sweep-schedule.js";
150
150
  import { storageHtml } from "../storage-ui.js";
151
151
  import { landedSummary } from "../landed-cleanup.js";
152
152
  import { bytesWords, parseCleanup, parseIdle } from "../storage.js";
153
+ import { setTaskSizing, taskSizingSetting } from "../task-sizing.js";
154
+ import { localActNow } from "../local-owner.js";
153
155
  import { checkoutIdle, isDigestTime, leadQuickAnswersOn, liveBackupState, setCheckoutIdle, localModeOf, RESULT_SCREENSHOTS, setLeadQuickAnswers, setLiveBackupSettings, setLocalModeOff } from "../store.js";
154
156
  import { defaultLiveFolder, liveFolderOf, liveFolderProblem } from "../live-backup.js";
155
157
  import { LIVE_EVERY } from "../backup-ui.js";
@@ -2763,6 +2765,7 @@ ${postForm("/settings/chat-approval/save", html `\
2763
2765
  "settings.lead-identity": leadIdentity,
2764
2766
  "settings.lead-about": leadAbout,
2765
2767
  "settings.lead-quick": leadQuick,
2768
+ "settings.task-sizing": taskSizingAct,
2766
2769
  "settings.lead-promise-cancel": leadPromiseCancel,
2767
2770
  "settings.lead-on": leadOn,
2768
2771
  "settings.code-map": codeMapAct("switch"),
@@ -2985,6 +2988,38 @@ ${postForm("/settings/chat-approval/save", html `\
2985
2988
  return back("problem", turned.reason === "not-on" ? "Local mode is already off." : "Only an instance operator can turn off local mode.");
2986
2989
  return done("said", "Local mode is off. This computer's browser signs in with your password now.");
2987
2990
  }
2991
+ async function taskSizingAct(ctx) {
2992
+ const { response, now, posted } = ctx;
2993
+ const who = browserCaller(ctx.who);
2994
+ const body = readForm(posted, CONSOLE_FORMS.taskSizing);
2995
+ const done = sayTo(response, "/settings/general?section=task-sizing");
2996
+ const back = sayTo(response, "/settings/change/task-sizing");
2997
+ if (["password", "enabled", "sizer"].some(field => body.sent.getAll(field).length > 1))
2998
+ return back("problem", "That form was sent twice over. Nothing changed.");
2999
+ const wanted = body.get("enabled");
3000
+ if (wanted !== "on" && wanted !== "off")
3001
+ return back("problem", "Choose on or off.");
3002
+ const shown = body.get("sizer");
3003
+ const saved = store.transact(() => {
3004
+ if (!store.isInstanceOperator(who.name))
3005
+ return "proof";
3006
+ if (who.authority !== "full" && localActNow(store, "task-sizing-switch") === null)
3007
+ return "proof";
3008
+ if (!authenticateApprover(who, body.get("password") ?? "").ok)
3009
+ return "proof";
3010
+ const available = taskSizingSetting(store).available;
3011
+ if (wanted === "on" && shown !== available)
3012
+ return "moved";
3013
+ setTaskSizing(store, wanted === "on" ? available : false, who.name, now);
3014
+ return "ok";
3015
+ });
3016
+ if (saved === "proof")
3017
+ return back("problem", "Enter your Toolroll password to change task sizing.");
3018
+ if (saved === "moved")
3019
+ return back("problem", "Which model would size your tasks changed since you looked. Nothing changed; look again.");
3020
+ const read = taskSizingSetting(store);
3021
+ return done("said", wanted === "on" ? `Task sizing is on. Each new task is sized by ${read.available === "jev" ? "Jev through your OpenRouter key" : "a quick call to Claude Haiku on your plan"} before you approve.` : "Task sizing is off. No model call before you approve; uncertain tasks get a plan first.");
3022
+ }
2988
3023
  async function justMe(ctx) {
2989
3024
  const { response, now, posted } = ctx;
2990
3025
  const who = browserCaller(ctx.who);
@@ -3163,6 +3198,7 @@ ${postForm("/settings/chat-approval/save", html `\
3163
3198
  passwordless: () => sessionStandsIn(store),
3164
3199
  localModeOn: () => localModeOf(store)?.enabled === true,
3165
3200
  installMode: () => installModeNow(store),
3201
+ taskSizing: () => taskSizingSetting(store),
3166
3202
  });
3167
3203
  const computersDeps = {
3168
3204
  computers: (now, manage) => computersOf(store, now, visible, manage),
@@ -1604,7 +1604,16 @@ export function createTasksHandlers(runtime) {
1604
1604
  return redirect(response, taskHref(taskId));
1605
1605
  }
1606
1606
  case "unhold": {
1607
- store.unhold(ref.id);
1607
+ const shown = readForm(posted, CONSOLE_FORMS.taskUnhold).get("hold");
1608
+ if (shown !== null && !/^[1-9][0-9]{0,15}$/.test(shown))
1609
+ return taskScreen(response, who, taskId, "not resumed: name the hold that was shown", 400);
1610
+ const ended = store.getTask(taskId)?.state;
1611
+ if (ended === "cancelled" || ended === "done") {
1612
+ return taskScreen(response, who, taskId, ended === "cancelled" ? "This task was cancelled, so there is nothing to resume." : "This task is finished, so there is nothing to resume.", 409);
1613
+ }
1614
+ const released = store.unhold(ref.id, {}, now, shown === null ? undefined : Number(shown));
1615
+ if (shown !== null && !released)
1616
+ return taskScreen(response, who, taskId, "This task's hold changed since it was shown — look again before resuming.", 409);
1608
1617
  return redirect(response, taskHref(taskId));
1609
1618
  }
1610
1619
  case "stop-carrying": {
@@ -1632,9 +1641,16 @@ export function createTasksHandlers(runtime) {
1632
1641
  replayed = retried.replayed;
1633
1642
  }
1634
1643
  else {
1635
- const requeued = store.requeueTask(taskId, who.name, now);
1644
+ const sentRun = body.get("run") ?? null, sentDigest = body.get("digest") ?? null;
1645
+ let pins;
1646
+ if (sentRun !== null || sentDigest !== null) {
1647
+ if (sentRun === null || !/^[1-9][0-9]{0,14}$/.test(sentRun) || sentDigest === null || !/^[a-f0-9]{32}$/.test(sentDigest))
1648
+ return taskScreen(response, who, taskId, TASK_CHANGED_SINCE, 409);
1649
+ pins = { run: Number(sentRun), digest: sentDigest };
1650
+ }
1651
+ const requeued = store.requeueTask(taskId, who.name, now, undefined, pins);
1636
1652
  if (!requeued.ok) {
1637
- return taskScreen(response, who, taskId, `not requeued: ${requeued.reason}`, 409);
1653
+ return taskScreen(response, who, taskId, requeued.reason === "stale" ? TASK_CHANGED_SINCE : `not requeued: ${requeued.reason}`, 409);
1638
1654
  }
1639
1655
  }
1640
1656
  if (note !== "" && !replayed) {
@@ -1777,7 +1793,17 @@ export function createTasksHandlers(runtime) {
1777
1793
  case "cancel": {
1778
1794
  const body = readForm(posted, CONSOLE_FORMS.taskCancel);
1779
1795
  const reason = body.get("reason") ?? undefined;
1780
- const cancelled = withActor({ account: who.name, lead: false }, () => store.cancelTask(taskId, now, reason));
1796
+ const seenState = body.get("state"), seenRun = body.get("run");
1797
+ if ((seenState === null) !== (seenRun === null) || (seenRun !== null && !/^(?:none|[1-9][0-9]{0,15})$/.test(seenRun))) {
1798
+ return taskScreen(response, who, taskId, "not cancelled: name both the state and the build that were shown", 400);
1799
+ }
1800
+ if (who.via === "cookie" && seenState === null)
1801
+ return taskScreen(response, who, taskId, "not cancelled: name both the state and the build that were shown", 400);
1802
+ const seen = seenState === null || seenRun === null ? undefined : { state: seenState, run: seenRun === "none" ? null : Number(seenRun) };
1803
+ const cancelled = withActor({ account: who.name, lead: false }, () => store.cancelTask(taskId, now, reason, seen));
1804
+ if (!cancelled.ok && cancelled.reason === "changed") {
1805
+ return taskScreen(response, who, taskId, "This task changed since it was shown — look again before cancelling.", 409);
1806
+ }
1781
1807
  if (!cancelled.ok) {
1782
1808
  if (cancelled.reason === "reason-required" || cancelled.reason === "bad-reason") {
1783
1809
  return taskScreen(response, who, taskId, cancelled.reason === "reason-required"
@@ -2915,3 +2941,4 @@ export const YOU_SAID_CAP = 8;
2915
2941
  export function answerTermsInPlace(response, offer) {
2916
2942
  respond(response, 200, "application/json; charset=utf-8", JSON.stringify({ outcome: "terms", preview: offer.preview, digest: offer.digest, terms: offer.terms.map(([label, words]) => ({ label, words })) }));
2917
2943
  }
2944
+ export const TASK_CHANGED_SINCE = "This task changed since you looked. Review it again.";
@@ -55,6 +55,7 @@ export const PROOF_INVENTORY = [
55
55
  { id: "mode-sign-chat-approve", action: "Sign an operating mode that lets your chat app approve", routes: ["/mode/sign"], select: { field: "chat-approve", value: "1" }, form: "mode", field: "token", proof: "credential", ...CREDENTIAL, role: "any", handlerRole: "an approver of the project", secrets: [], terms: MODE_TERMS },
56
56
  { id: "mode-sign-repair", action: "Sign an operating mode that repairs failed checks by itself", routes: ["/mode/sign"], select: { field: "repair-auto", value: "1" }, form: "mode", field: "token", proof: "credential", ...CREDENTIAL, role: "any", handlerRole: "an approver of the project", secrets: [], terms: MODE_TERMS },
57
57
  { id: "install-solo", action: "Say it's just you", routes: ["/settings/install-mode/solo"], form: "justMe", field: "password", proof: "credential", ...CREDENTIAL, role: "operator", handlerRole: "a full session (never the local owner)", secrets: [], terms: [] },
58
+ { id: "task-sizing", action: "Turn task sizing by a quick model call on or off", routes: ["/settings/task-sizing"], form: "taskSizing", field: "password", proof: "step-up", ...ACCEPT, role: "operator", secrets: [], terms: ["enabled", "sizer"] },
58
59
  { id: "provider-key", action: "Save an AI provider key", routes: ["/settings/provider-key"], form: "providerKey", field: "password", proof: "credential", ...CREDENTIAL, role: "any", secrets: ["value"], terms: [] },
59
60
  { id: "telegram-token", action: "Save the Telegram bot token", routes: ["/settings/telegram-token"], form: "telegramToken", field: "password", proof: "credential", ...CREDENTIAL, role: "any", secrets: ["token"], notProof: ["token"], terms: [] },
60
61
  { id: "email", action: "Set up email", routes: ["/settings/email"], form: "email", field: "token", proof: "credential", ...CREDENTIAL, role: "any", secrets: ["password"], notProof: ["password"], terms: [] },
package/dist/store.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { verifyResultImage } from "./chat-evidence.js";
2
2
  import { parseFeedbackImage } from "./result-review.js";
3
+ import { agentSaidTail } from "./agent-said.js";
3
4
  import { mintSecret } from "./secret-mint.js";
4
5
  import { WRITES_DEFAULT } from "./writes-mode.js";
5
6
  import { checkAccessOf, widerThan } from "./check-access.js";
@@ -25,6 +26,8 @@ import { V165_OBJECTS, V165_SCHEMA, V165_STEPS } from "./flexible-launch-schema.
25
26
  import { V166_OBJECTS, V166_SCHEMA, V166_STEPS } from "./flexible-relay-schema.js";
26
27
  import { V167_OBJECTS, V167_SCHEMA, V167_STEPS } from "./flexible-answers-schema.js";
27
28
  import { V168_OBJECTS, V168_SCHEMA, V168_STEPS } from "./flexible-ship-schema.js";
29
+ import { V169_ADDED_COLUMNS, V169_SCHEMA, V169_STEPS } from "./task-sizing-schema.js";
30
+ import { V170_ADDED_COLUMNS, V170_STEPS } from "./agent-said-schema.js";
28
31
  import { endLapsedFlexible } from "./flexible.js";
29
32
  import { refArchived, taskArchived, taskCancelled } from "./task-archive.js";
30
33
  export { refArchived, taskArchived } from "./task-archive.js";
@@ -829,7 +832,7 @@ export function checkSuitesOf(value) {
829
832
  }
830
833
  }
831
834
  const REGISTERED_AT_FILING = "again, as it was filed";
832
- export const SCHEMA_VERSION = 168;
835
+ export const SCHEMA_VERSION = 170;
833
836
  export const V118_MERGED_TABLES = Object.freeze({ api_token: "person", coordinator_credential: "coordinator", lead_credential: "lead" });
834
837
  const V118_REFERENCES = /REFERENCES (?:coordinator_credential\(cid\)|api_token\(id\))/g;
835
838
  const V118_COORDINATOR_COLUMNS = [["task_ref", "coordinator_cid"], ["coordinator_event", "cid"], ["mcp_idempotency", "cid"], ["coordinator_proposal", "cid"]];
@@ -894,7 +897,7 @@ export const V115_DROPPED_TABLES = Object.freeze([
894
897
  "fallback_config", "fallback_cycle", "fallback_transition",
895
898
  ]);
896
899
  const V115_DROPPED_REFERENCES = /\s+REFERENCES (?:contestant|contest|tournament_terms|session_turn|attended_authorization|held_session|fallback_cycle|fallback_config|fallback_transition|routine|routine_fire)\(id\)(?: ON DELETE CASCADE)?/g;
897
- export const UPDATE_SAFE_MIGRATIONS = Object.freeze([108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168]);
900
+ export const UPDATE_SAFE_MIGRATIONS = Object.freeze([108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170]);
898
901
  export const V119_ADDED_COLUMNS = Object.freeze({
899
902
  task_ref: { planning_generation: { definition: "INTEGER NOT NULL DEFAULT 0", saved: "0" } },
900
903
  run: { planning_generation: { definition: "INTEGER NOT NULL DEFAULT 0", saved: "0" } },
@@ -1437,7 +1440,7 @@ export { V156_STEPS };
1437
1440
  export { V157_STEPS };
1438
1441
  export { V158_STEPS };
1439
1442
  export { V159_STEPS };
1440
- export { V160_STEPS, V161_STEPS, V162_STEPS, V163_STEPS, V164_STEPS, V165_STEPS, V166_STEPS, V167_STEPS, V168_STEPS };
1443
+ export { V160_STEPS, V161_STEPS, V162_STEPS, V163_STEPS, V164_STEPS, V165_STEPS, V166_STEPS, V167_STEPS, V168_STEPS, V169_STEPS, V170_STEPS };
1441
1444
  export const RELEASE_ONCE_SCHEMA = `
1442
1445
  CREATE TABLE IF NOT EXISTS release_authority (
1443
1446
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -4215,7 +4218,7 @@ function initializeStore(db, file, options = {}) {
4215
4218
  throw new Error(`${file}: ${problem}; refusing to move chat history it cannot name`);
4216
4219
  }
4217
4220
  if (preflight === SCHEMA_VERSION && !findingSourcesStale(db)) {
4218
- const missing = codeMapShapeProblem(db) ?? viewPreferenceShapeProblem(db) ?? flexibleTermsShapeProblem(db) ?? flexibleThreadShapeProblem(db) ?? typedByPersonShapeProblem(db) ?? flexibleTurnsShapeProblem(db) ?? flexibleLaunchShapeProblem(db) ?? flexibleRelayShapeProblem(db) ?? flexibleAnswersShapeProblem(db) ?? flexibleShipShapeProblem(db);
4221
+ const missing = codeMapShapeProblem(db) ?? viewPreferenceShapeProblem(db) ?? flexibleTermsShapeProblem(db) ?? flexibleThreadShapeProblem(db) ?? typedByPersonShapeProblem(db) ?? flexibleTurnsShapeProblem(db) ?? flexibleLaunchShapeProblem(db) ?? flexibleRelayShapeProblem(db) ?? flexibleAnswersShapeProblem(db) ?? flexibleShipShapeProblem(db) ?? taskSizingShapeProblem(db) ?? agentSaidShapeProblem(db);
4219
4222
  if (missing !== null)
4220
4223
  throw new Error(`${file}: refusing to open — ${missing}, though the schema says v${SCHEMA_VERSION}`);
4221
4224
  db.exec("PRAGMA journal_mode = WAL; PRAGMA foreign_keys = ON;");
@@ -4597,6 +4600,19 @@ CREATE INDEX IF NOT EXISTS run_checkpoint_by_task ON run_checkpoint (task_ref, i
4597
4600
  if (shipDamaged !== null)
4598
4601
  throw new Error(`${file}: refusing to open — ${shipDamaged}`);
4599
4602
  step("flexible-ship");
4603
+ db.exec(V169_SCHEMA);
4604
+ for (const [table, columns] of Object.entries(V169_ADDED_COLUMNS))
4605
+ for (const [column, { definition }] of Object.entries(columns))
4606
+ addColumn(db, table, column, definition);
4607
+ const sizingDamaged = taskSizingShapeProblem(db);
4608
+ if (sizingDamaged !== null)
4609
+ throw new Error(`${file}: refusing to open — ${sizingDamaged}`);
4610
+ step("task-sizing-setting");
4611
+ step("task-sizing-columns");
4612
+ for (const [table, columns] of Object.entries(V170_ADDED_COLUMNS))
4613
+ for (const [column, { definition }] of Object.entries(columns))
4614
+ addColumn(db, table, column, definition);
4615
+ step("agent-said-column");
4600
4616
  if (!fresh)
4601
4617
  reclaimDatabase(db, "migration");
4602
4618
  const expectedMarker = preflight < 0 ? preflight : -preflight;
@@ -5458,7 +5474,9 @@ function sizingOfRow(row) {
5458
5474
  const source = row["size_source"];
5459
5475
  if (source !== "classifier" && source !== "heuristic" && source !== "person")
5460
5476
  return null;
5461
- return { size: row["size"], risky: Number(row["size_risky"] ?? 0) === 1, source, reason: row["size_reason"] == null ? "" : String(row["size_reason"]) };
5477
+ const by = row["size_by"];
5478
+ return { size: row["size"], risky: Number(row["size_risky"] ?? 0) === 1, source, reason: row["size_reason"] == null ? "" : String(row["size_reason"]),
5479
+ ...(source === "classifier" && typeof by === "string" && /^[A-Za-z0-9][A-Za-z0-9 .:/~()_-]{0,79}$/.test(by) ? { by } : {}) };
5462
5480
  }
5463
5481
  function addColumn(db, table, column, definition) {
5464
5482
  if (hasColumn(db, table, column))
@@ -6140,8 +6158,11 @@ export class Store {
6140
6158
  link: chatControlHref("recovery", taskId),
6141
6159
  }, now);
6142
6160
  }
6143
- unhold(taskRef, mutation = {}, now) {
6161
+ unhold(taskRef, mutation = {}, now, seenHold) {
6144
6162
  return this.once(mutation, "unhold", () => this.transact(() => {
6163
+ if (seenHold !== undefined && this.db.prepare("SELECT 1 AS hit FROM hold WHERE id = ? AND task_ref = ? AND owner_kind = 'operator'")
6164
+ .get(seenHold, taskRef) === undefined)
6165
+ return false;
6145
6166
  const { changes } = this.db
6146
6167
  .prepare("DELETE FROM hold WHERE task_ref = ? AND (owner_kind = 'operator' OR (owner_kind = 'backoff' AND owner_id = 'storage:' || task_ref))")
6147
6168
  .run(taskRef);
@@ -9582,7 +9603,7 @@ export class Store {
9582
9603
  return "published";
9583
9604
  return null;
9584
9605
  }
9585
- requeueTask(taskId, by, now, expect) {
9606
+ requeueTask(taskId, by, now, expect, pins) {
9586
9607
  return this.transact(() => {
9587
9608
  const eligible = requeueEligibility(this, taskId, now);
9588
9609
  if (!eligible.ok)
@@ -9594,6 +9615,13 @@ export class Store {
9594
9615
  scope["approved_digest"] !== scope["digest"])
9595
9616
  return { ok: false, reason: "moved" };
9596
9617
  }
9618
+ if (pins !== undefined) {
9619
+ const latest = this.lastBuilderRun(taskRef);
9620
+ const scope = this.db.prepare("SELECT digest FROM task_scope WHERE task_id = ?").get(taskId);
9621
+ if (latest === null || latest.id !== pins.run || scope === undefined || String(scope["digest"]) !== pins.digest ||
9622
+ this.db.prepare("SELECT 1 AS hit FROM run WHERE task_ref = ? AND id > ? LIMIT 1").get(taskRef, pins.run) !== undefined)
9623
+ return { ok: false, reason: "stale" };
9624
+ }
9597
9625
  for (const incident of incidents)
9598
9626
  this.resolveIncidentLocked(incident, by, now);
9599
9627
  this.resetStrikes(taskRef);
@@ -9614,13 +9642,20 @@ export class Store {
9614
9642
  return { ok: true, resolvedIncidents: incidents.length, rejectedRun };
9615
9643
  });
9616
9644
  }
9617
- cancelTask(taskId, now, reason) {
9645
+ cancelTask(taskId, now, reason, seen) {
9618
9646
  return this.transact(() => {
9619
9647
  const ref = this.db
9620
9648
  .prepare("SELECT id FROM task_ref WHERE backend = ? AND external_id = ?")
9621
9649
  .get(BUILT_IN, taskId);
9622
9650
  if (ref === undefined)
9623
9651
  return { ok: false, reason: "unknown-task" };
9652
+ if (seen !== undefined) {
9653
+ const state = this.db.prepare("SELECT state FROM task WHERE id = ?").get(taskId)?.["state"];
9654
+ const last = this.db.prepare("SELECT MAX(id) AS id FROM run WHERE task_ref = ?").get(Number(ref["id"]))?.["id"];
9655
+ const run = last === null || last === undefined ? null : Number(last);
9656
+ if (String(state) !== seen.state || run !== seen.run)
9657
+ return { ok: false, reason: "changed" };
9658
+ }
9624
9659
  if (this.hasLiveClaim(Number(ref["id"]), now))
9625
9660
  return { ok: false, reason: "claimed" };
9626
9661
  const done = this.applyCancellation(taskId, { kind: "operator", text: reason ?? null }, now, ["queued", "failed", "running"]);
@@ -10127,8 +10162,8 @@ export class Store {
10127
10162
  }
10128
10163
  writeSizing(taskRef, sizing) {
10129
10164
  this.db
10130
- .prepare("UPDATE task_ref SET size = ?, size_risky = ?, size_source = ?, size_reason = ? WHERE id = ?")
10131
- .run(sizing.size, sizing.risky ? 1 : 0, sizing.source, sizing.reason.slice(0, 300), taskRef);
10165
+ .prepare("UPDATE task_ref SET size = ?, size_risky = ?, size_source = ?, size_reason = ?, size_by = ? WHERE id = ?")
10166
+ .run(sizing.size, sizing.risky ? 1 : 0, sizing.source, sizing.reason.slice(0, 300), sizing.by ?? null, taskRef);
10132
10167
  }
10133
10168
  planToSizing(taskRef, now) {
10134
10169
  const ref = this.refForId(taskRef);
@@ -10159,7 +10194,7 @@ export class Store {
10159
10194
  if (scope !== null && scope.approvedAt !== null && scope.approvedDigest === scope.digest)
10160
10195
  return { ok: false, reason: "approved" };
10161
10196
  const before = ref.sizing ?? null;
10162
- if (before !== null && before.size === sizing.size && before.risky === sizing.risky && before.source === sizing.source && before.reason === sizing.reason) {
10197
+ if (before !== null && before.size === sizing.size && before.risky === sizing.risky && before.source === sizing.source && before.reason === sizing.reason && before.by === sizing.by) {
10163
10198
  return { ok: true, changed: false, planning: null };
10164
10199
  }
10165
10200
  this.writeSizing(ref.id, sizing);
@@ -18889,3 +18924,40 @@ function flexibleShipShapeProblem(db) {
18889
18924
  }
18890
18925
  return null;
18891
18926
  }
18927
+ function taskSizingShapeProblem(db) {
18928
+ const row = db.prepare("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'task_sizing_setting'").get();
18929
+ if (row === undefined)
18930
+ return "the task sizing table is missing";
18931
+ if (canonicalDdl(String(row["sql"]).replace(/;$/, "")).trim() !== canonicalDdl(V169_SCHEMA.trim().replace(/;$/, "")).trim())
18932
+ return "the task sizing table has an unknown shape";
18933
+ if (!hasColumn(db, "task_ref", "size_by"))
18934
+ return "task_ref.size_by is missing";
18935
+ return null;
18936
+ }
18937
+ function agentSaidShapeProblem(db) {
18938
+ return hasColumn(db, "run", "agent_said_json") ? null : "run.agent_said_json is missing";
18939
+ }
18940
+ export function recordAgentSaid(store, runId, lines) {
18941
+ const kept = agentSaidTail(lines.join("\n"));
18942
+ while (kept.length > 0 && JSON.stringify(kept).length > 4096)
18943
+ kept.shift();
18944
+ if (kept.length === 0)
18945
+ return;
18946
+ store.handle.prepare("UPDATE run SET agent_said_json = ? WHERE id = ? AND agent_said_json IS NULL").run(JSON.stringify(kept), runId);
18947
+ }
18948
+ export function agentSaidOf(store, runId) {
18949
+ const row = store.handle.prepare("SELECT agent_said_json FROM run WHERE id = ?").get(runId);
18950
+ const raw = row?.["agent_said_json"];
18951
+ if (typeof raw !== "string")
18952
+ return null;
18953
+ try {
18954
+ const value = JSON.parse(raw);
18955
+ if (!Array.isArray(value) || value.length === 0)
18956
+ return null;
18957
+ const lines = agentSaidTail(value.filter((one) => typeof one === "string").join("\n"));
18958
+ return lines.length === 0 ? null : lines;
18959
+ }
18960
+ catch {
18961
+ return null;
18962
+ }
18963
+ }
@@ -0,0 +1,14 @@
1
+ export const V169_SCHEMA = `
2
+ CREATE TABLE IF NOT EXISTS task_sizing_setting (
3
+ id INTEGER PRIMARY KEY CHECK (id = 1),
4
+ enabled INTEGER NOT NULL CHECK (enabled IN (0,1)),
5
+ sizer TEXT CHECK (sizer IN ('claude','jev')),
6
+ updated_by TEXT NOT NULL,
7
+ updated_at TEXT NOT NULL
8
+ );
9
+ `;
10
+ export const V169_ADDED_COLUMNS = Object.freeze({
11
+ task_ref: { size_by: { definition: "TEXT", saved: "NULL" } },
12
+ });
13
+ export const V169_TABLES = Object.freeze(["task_sizing_setting"]);
14
+ export const V169_STEPS = Object.freeze(["task-sizing-setting", "task-sizing-columns"]);