toolroll 0.9.110 → 0.9.112

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 (68) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/README.md +5 -1
  3. package/THIRD_PARTY_NOTICES.md +30 -0
  4. package/dist/action-ledger.js +13 -0
  5. package/dist/agent-detect.js +1 -1
  6. package/dist/agent-said-schema.js +4 -0
  7. package/dist/agent-said.js +77 -0
  8. package/dist/approval-summary.js +39 -8
  9. package/dist/bin.js +5 -1
  10. package/dist/browser/THIRD_PARTY_NOTICES.txt +30 -0
  11. package/dist/browser/terminal.js +1 -1
  12. package/dist/browser/workspace.js +1 -1
  13. package/dist/builder.js +6 -1
  14. package/dist/chat-channel.js +10 -0
  15. package/dist/claim.js +28 -13
  16. package/dist/cli-help.js +7 -1
  17. package/dist/cli.js +2 -0
  18. package/dist/codex-limits.js +21 -8
  19. package/dist/console-instance.js +2 -1
  20. package/dist/contracts/console-api.js +3 -2
  21. package/dist/contracts/engine-api.js +15 -3
  22. package/dist/contracts/lead-tools.js +28 -0
  23. package/dist/contracts/route.js +1 -0
  24. package/dist/dispatch.js +1 -1
  25. package/dist/dispose.js +15 -9
  26. package/dist/easy-start.js +19 -3
  27. package/dist/engine-reads.js +79 -2
  28. package/dist/evidence.js +6 -6
  29. package/dist/fast-start.js +20 -11
  30. package/dist/flexible-start.js +1 -1
  31. package/dist/integrations.js +6 -1
  32. package/dist/lead-tools.js +107 -1
  33. package/dist/lead.js +1 -1
  34. package/dist/ledger-view.js +2 -1
  35. package/dist/local-owner.js +1 -0
  36. package/dist/needs-you.js +12 -2
  37. package/dist/operate.js +57 -9
  38. package/dist/outbound-privacy.js +6 -1
  39. package/dist/phase-routing.js +3 -1
  40. package/dist/plain-words.js +1 -1
  41. package/dist/plane-review.js +1 -1
  42. package/dist/proposal.js +2 -2
  43. package/dist/provider-connection.js +14 -2
  44. package/dist/release.js +1 -0
  45. package/dist/route-store.js +1 -1
  46. package/dist/serve.js +6 -4
  47. package/dist/server/chat.js +6 -1
  48. package/dist/server/pages.js +4 -1
  49. package/dist/server/render-history.js +2 -1
  50. package/dist/server/render-tasks.js +5 -2
  51. package/dist/server/route-table.js +2 -0
  52. package/dist/server/settings-section-table.js +3 -0
  53. package/dist/server/settings-sections.js +36 -0
  54. package/dist/server/settings.js +36 -0
  55. package/dist/server/tasks.js +31 -4
  56. package/dist/settings-proofs.js +1 -0
  57. package/dist/store.js +83 -11
  58. package/dist/task-sizing-schema.js +14 -0
  59. package/dist/task-sizing.js +76 -10
  60. package/dist/toolroll-update.js +3 -1
  61. package/dist/tui/darwin-arm64/toolroll-tui +0 -0
  62. package/dist/tui/darwin-x64/toolroll-tui +0 -0
  63. package/dist/tui/linux-arm64/toolroll-tui +0 -0
  64. package/dist/tui/linux-x64/toolroll-tui +0 -0
  65. package/dist/view-tools.js +94 -0
  66. package/dist/webhooks.js +8 -2
  67. package/dist/work-index.js +4 -4
  68. package/package.json +2 -1
@@ -1,3 +1,6 @@
1
+ import { agentSaidOf } from "./store.js";
2
+ import { failedAttemptSentence, latestFinishedAttempt, stopSuggestionOf } from "./needs-you.js";
3
+ import { retryPinsOf } from "./local-owner-acts.js";
1
4
  import { assignmentOf, owedAcceptance, personCompletionRefusal } from "./assignment.js";
2
5
  import { assignmentCardOf } from "./assignment-ui.js";
3
6
  import { assignmentStageOf, stageOfCode } from "./task-status.js";
@@ -14,6 +17,7 @@ import { agentSetupOf, detectionLines, NO_AGENT_YET, npmRegistryOf } from "./age
14
17
  import { scanPatchForSecrets } from "./evidence.js";
15
18
  import { fastCompletionProblem } from "./fast-start.js";
16
19
  import { viewedGitSync } from "./teardown-git.js";
20
+ import { wasInterrupted } from "./run-ending.js";
17
21
  export const isResultRun = (run) => run.finishedAt !== null && (run.role === "builder" || run.role === "scout");
18
22
  const AUTOMATIC = new Set(["auto-check", "auto-green"]);
19
23
  export function stepCardsOf({ store, family, now, access, evidenceRoot, viewer = null }) {
@@ -58,7 +62,7 @@ export function stepCardsOf({ store, family, now, access, evidenceRoot, viewer =
58
62
  rows: [...summary.revisionChanges, ...summary.decisions, ...(summary.why === null ? [] : [{ label: "Why model", words: summary.why }]), ...summary.differs].map(one => ({ label: one.label, words: one.words, lines: "lines" in one ? [...(one.lines ?? [])] : [] })),
59
63
  warnings: summary.warnings.map(one => one.words), usualLabel: summary.usualLabel, usual: summary.usual.map(one => ({ label: one.label, words: one.words })) };
60
64
  })();
61
- const cards = rows === null ? null : rows.map(row => ({
65
+ const cards = current.state === "cancelled" ? cancelledCards(builds, current.updatedAt ?? null) : rows === null ? null : rows.map(row => ({
62
66
  key: row.key, label: row.label, state: row.state, mark: row.mark, sentence: row.sentence, at: row.at, needsYou: row.needsYou,
63
67
  inChain: !(justCode && (row.key === "plan" || row.key === "approve")),
64
68
  ...runFacts(behind[row.key]),
@@ -78,21 +82,94 @@ export function stepCardsOf({ store, family, now, access, evidenceRoot, viewer =
78
82
  version: ENGINE_API_VERSION,
79
83
  task: { id: current.id, root: root.id, title: root.title, state: current.state, project: current.repo },
80
84
  chain: justCode ? "just-code" : "plan-first",
81
- headline: card?.status.headline ?? null,
85
+ headline: current.state === "cancelled" ? "Cancelled" : card?.status.headline ?? null,
82
86
  liveRun: live?.id ?? null,
83
87
  cards,
84
88
  review: assignment !== null && assignment.state === "ready-to-check" && assignment.receipt !== null && assignment.receipt.taskId === current.id
85
89
  ? { run: assignment.receipt.runId, receipt: assignment.receipt.digest, source: revisionSourceOf(scope?.digest ?? null),
86
90
  accept: acceptFactsOf(store, assignment, viewer, evidenceRoot) } : null,
91
+ failure: current.state === "failed" ? failureOf(store, ref?.id ?? null, builds) : null,
92
+ waiting: (() => {
93
+ const waiting = waitingOf(store, current.id, now);
94
+ if (waiting === null)
95
+ return null;
96
+ const last = latestFinishedAttempt(builds);
97
+ return { ...waiting, agentSaid: last !== null && last.outcome === "failed" ? agentSaidOf(store, last.id) : null };
98
+ })(),
99
+ held: current.state === "cancelled" || current.state === "done" ? null : heldOf(store, ref?.id ?? null, builds, now),
100
+ retry: current.state === "failed" ? (() => { const pins = retryPinsOf(store, current.id); return pins === null ? null : { run: pins.run, digest: pins.digest }; })() : null,
101
+ approval: scope !== null && approved && scope.approvedBy !== null
102
+ ? { by: scope.approvedBy, you: viewer !== null && scope.approvedBy === viewer, automatic: AUTOMATIC.has(String(scope.approvalBasis ?? "")) } : null,
87
103
  room: `task:${encodeURIComponent(root.id)}`,
88
104
  };
89
105
  }
106
+ function failureOf(store, taskRef, builds) {
107
+ const last = latestFinishedAttempt(builds);
108
+ const failedInARow = taskRef === null ? 0
109
+ : Number(store.handle.prepare("SELECT strikes FROM task_ref WHERE id = ?").get(taskRef)?.["strikes"] ?? 0);
110
+ return { line: failedAttemptSentence(last?.reason), failedInARow, suggestion: last === null ? null : stopSuggestionOf(last.reason),
111
+ agentSaid: last === null ? null : agentSaidOf(store, last.id) };
112
+ }
113
+ function cancelledCards(builds, at) {
114
+ const out = [];
115
+ const latest = builds[0] ?? null;
116
+ if (latest !== null) {
117
+ const failed = latest.outcome === "failed" || latest.outcome === "refused" || wasInterrupted(latest);
118
+ out.push({ key: "build", label: "Build", state: failed ? "stuck" : "done", mark: failed ? "stuck" : "done",
119
+ sentence: failed ? failedAttemptSentence(latest.reason).replace(/[.\s]+$/, "") : "The build finished", at: latest.finishedAt,
120
+ needsYou: false, inChain: true, ...runFacts(builds) });
121
+ }
122
+ out.push({ key: "ready", label: "Cancelled", state: "skipped", mark: "skipped", sentence: "Cancelled: nothing else will run for this task.",
123
+ at, needsYou: false, inChain: true, ...runFacts([]) });
124
+ return out;
125
+ }
126
+ function heldOf(store, taskRef, builds, now) {
127
+ if (taskRef === null)
128
+ return null;
129
+ const hold = store.activeHolds(taskRef, now).find(one => one.ownerKind === "operator") ?? null;
130
+ if (hold === null)
131
+ return null;
132
+ const last = latestFinishedAttempt(builds);
133
+ return { id: hold.id, reason: hold.reason,
134
+ lastFailure: last !== null && last.outcome === "failed" ? failedAttemptSentence(last.reason).replace(/[.\s]+$/, "") : null };
135
+ }
136
+ export function waitingOf(store, taskId, now) {
137
+ return waitingForTasks(store, [taskId], now).get(taskId) ?? null;
138
+ }
139
+ export function waitingForTasks(store, taskIds, now) {
140
+ const out = new Map();
141
+ const ids = [...new Set(taskIds)];
142
+ if (ids.length === 0)
143
+ return out;
144
+ const at = now.toISOString();
145
+ const rows = store.handle.prepare(`SELECT task.id AS task,
146
+ EXISTS (SELECT 1 FROM hold WHERE hold.task_ref = task_ref.id AND hold.owner_kind = 'backoff' AND (hold.until IS NULL OR hold.until > ?)) AS held,
147
+ (SELECT hold.until FROM hold WHERE hold.task_ref = task_ref.id AND hold.owner_kind = 'backoff' AND (hold.until IS NULL OR hold.until > ?) ORDER BY hold.held_at, hold.id LIMIT 1) AS until,
148
+ (SELECT run.outcome FROM run WHERE run.task_ref = task_ref.id AND run.role IN ('builder', 'scout', 'repair') AND (run.finished_at IS NOT NULL OR run.outcome IS NOT NULL) ORDER BY run.id DESC LIMIT 1) AS outcome,
149
+ (SELECT run.reason FROM run WHERE run.task_ref = task_ref.id AND run.role IN ('builder', 'scout', 'repair') AND (run.finished_at IS NOT NULL OR run.outcome IS NOT NULL) ORDER BY run.id DESC LIMIT 1) AS reason
150
+ FROM task JOIN task_ref ON task_ref.backend = 'built-in' AND task_ref.external_id = task.id
151
+ WHERE task.state = 'queued' AND task.id IN (${ids.map(() => "?").join(", ")})
152
+ -- A person's hold (Stop retrying, a pause, a question, an incident) means it isn't waiting to try again.
153
+ AND NOT EXISTS (SELECT 1 FROM hold WHERE hold.task_ref = task_ref.id AND hold.owner_kind <> 'backoff' AND (hold.until IS NULL OR hold.until > ?))`).all(at, at, ...ids, at);
154
+ for (const row of rows) {
155
+ const failed = row["outcome"] === "failed";
156
+ const held = Number(row["held"]) === 1;
157
+ if (!failed && !held)
158
+ continue;
159
+ out.set(String(row["task"]), {
160
+ retryAt: held && row["until"] != null ? String(row["until"]) : null,
161
+ lastFailure: failed ? failedAttemptSentence(row["reason"] == null ? null : String(row["reason"])).replace(/[.\s]+$/, "") : null,
162
+ });
163
+ }
164
+ return out;
165
+ }
90
166
  function runFacts(runs) {
91
167
  const latest = runs[0] ?? null;
92
168
  const costs = runs.map(run => run.costUsd).filter((one) => typeof one === "number" && Number.isFinite(one));
93
169
  return {
94
170
  agent: latest === null ? null : { provider: latest.provider, model: latest.modelReported ?? latest.model ?? null },
95
171
  startedAt: runs.at(-1)?.startedAt ?? null,
172
+ latestStartedAt: latest?.startedAt ?? null,
96
173
  finishedAt: latest?.finishedAt ?? null,
97
174
  costUsd: costs.length === 0 ? null : Math.round(costs.reduce((sum, one) => sum + one, 0) * 1e6) / 1e6,
98
175
  runs: runs.map(run => run.id),
package/dist/evidence.js CHANGED
@@ -499,14 +499,14 @@ export const SECRET_PATTERNS = [
499
499
  { name: "private-key", pattern: /-----BEGIN [A-Z ]*PRIVATE KEY-----/ },
500
500
  { name: "aws-access-key", pattern: /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/ },
501
501
  { name: "github-token", pattern: /\b(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{36}\b|github_pat_[A-Za-z0-9_]{22,}/ },
502
- { name: "slack-token", pattern: /\bxox[baprs]-[A-Za-z0-9-]{10,}\b/ },
502
+ { name: "slack-token", pattern: /\bxox[baprs]-[A-Za-z0-9-]{10,}(?:\b|(?![\w-]))/ },
503
503
  { name: "npm-auth-token", pattern: /_authToken\s*=\s*[^\s$][^\s]*/ },
504
- { name: "openai-key", pattern: /\bsk-[A-Za-z0-9_-]{32,}\b/ },
504
+ { name: "openai-key", pattern: /\bsk-[A-Za-z0-9_-]{32,}(?:\b|(?![\w-]))/ },
505
505
  { name: "stripe-key", pattern: /\b(?:sk|rk)_(?:live|test)_[A-Za-z0-9]{24,}\b|\bwhsec_[A-Za-z0-9]{24,}\b/ },
506
- { name: "google-api-key", pattern: /\bAIza[0-9A-Za-z_-]{35}\b/ },
507
- { name: "gitlab-token", pattern: /\bglpat-[A-Za-z0-9_-]{20,}\b/ },
508
- { name: "telegram-bot-token", pattern: /\b\d{8,10}:AA[A-Za-z0-9_-]{33}\b/ },
509
- { name: "discord-bot-token", pattern: /\b[MN][A-Za-z\d]{23,25}\.[\w-]{6}\.[\w-]{27,}\b/ },
506
+ { name: "google-api-key", pattern: /\bAIza[0-9A-Za-z_-]{35}(?:\b|(?![\w-]))/ },
507
+ { name: "gitlab-token", pattern: /\bglpat-[A-Za-z0-9_-]{20,}(?:\b|(?![\w-]))/ },
508
+ { name: "telegram-bot-token", pattern: /\b\d{8,10}:AA[A-Za-z0-9_-]{33}(?:\b|(?![\w-]))/ },
509
+ { name: "discord-bot-token", pattern: /\b[MN][A-Za-z\d]{23,25}\.[\w-]{6}\.[\w-]{27,}(?:\b|(?![\w-]))/ },
510
510
  { name: "password-in-url", pattern: /\b[a-z][a-z0-9+.-]*:\/\/[^\s:@/]+:[^\s:@/]{3,}@[^\s/]/i },
511
511
  { name: "putty-private-key", pattern: /PuTTY-User-Key-File-\d+:/ },
512
512
  { name: "aws-secret-key", pattern: /\b(?:aws_secret_access_key|SecretAccessKey)\b["']?\s*[=:]\s*["']?[A-Za-z0-9/+]{40}/i },
@@ -11,7 +11,8 @@ import { COMPLETION_ACTION, COMPLETION_BY_PERSON } from "./result-completion.js"
11
11
  import { approvalSummaryOf, summaryContextOf } from "./approval-summary.js";
12
12
  import { deployGateScope, machineActing, propose, releaseCheckScope } from "./scope.js";
13
13
  import { BUILT_IN, withdrawApproval } from "./store.js";
14
- import { classifyTask, filingSizer, heuristicSizing } from "./task-sizing.js";
14
+ import { classifyTask, filingSizer, filingSizing, heuristicSizing, SIZING_OFF_REASON, taskSizingOn } from "./task-sizing.js";
15
+ const JUST_CODE_SIZING_OFF = `${SIZING_OFF_REASON}; Just code, as you chose`;
15
16
  import { issueImported } from "./task-source.js";
16
17
  import { titleWithin } from "./task-text.js";
17
18
  import { viewedGitSync } from "./teardown-git.js";
@@ -28,6 +29,7 @@ const FAST_WORDS = {
28
29
  setting: "Small tasks don't start right away in this project.",
29
30
  size: "This looks bigger than a small change.",
30
31
  classifier: "Toolroll couldn't confirm this is a small change.",
32
+ "sizing-off": "Quick start needs task sizing, which is off.",
31
33
  plan: "This needs a plan first.",
32
34
  quality: "Strict checks need a plan first.",
33
35
  rules: "This project's approval rules need a plan first.",
@@ -77,11 +79,12 @@ export function fastStartRules(store, input, now) {
77
79
  const account = store.accountOf(input.actor);
78
80
  if (account === null || account.revokedAt !== null || account.role !== "approver" || !store.accountCanAccess(input.actor, input.repo))
79
81
  return no("rules");
80
- if (!solo && heuristicSizing({ title: input.title, goal: input.title }).size !== "small")
82
+ const sizingOff = !solo && !taskSizingOn(store);
83
+ if (!solo && !sizingOff && heuristicSizing({ title: input.title, goal: input.title }).size !== "small")
81
84
  return no("size");
82
- if (!solo && input.sizing.source !== "classifier")
85
+ if (!solo && !sizingOff && input.sizing.source !== "classifier")
83
86
  return no("classifier");
84
- if (!solo && (input.sizing.size !== "small" || input.sizing.risky))
87
+ if (!solo && !sizingOff && (input.sizing.size !== "small" || input.sizing.risky))
85
88
  return no("size");
86
89
  const scope = store.getScope(input.taskId);
87
90
  if (scope === null)
@@ -93,7 +96,7 @@ export function fastStartRules(store, input, now) {
93
96
  const route = routeFromJson(scope.proposedRouteJson ?? null);
94
97
  if (route === null)
95
98
  return no("agents");
96
- if (!solo && !makesNoPlan(input.sizing, route.risk))
99
+ if (!solo && !sizingOff && !makesNoPlan(input.sizing, route.risk))
97
100
  return no("plan");
98
101
  if ((scope.qualityMode ?? "default") !== "default")
99
102
  return no("quality");
@@ -104,6 +107,8 @@ export function fastStartRules(store, input, now) {
104
107
  return no("rules");
105
108
  if (isProtectedWork(rules, scope.touches))
106
109
  return no("protected");
110
+ if (sizingOff)
111
+ return no("sizing-off");
107
112
  const gate = store.approvalGate(input.taskId, input.actor, "person");
108
113
  if (gate.verdict !== "seal" || gate.protectedWork)
109
114
  return no("rules");
@@ -172,15 +177,17 @@ export async function prepareFastStart(store, input, now) {
172
177
  return { eligible: false, reason: "rules" };
173
178
  if (!fastStartOn(store, input.repo))
174
179
  return { eligible: false, reason: "setting" };
175
- const small = heuristicSizing({ title: input.title, goal: input.title }).size === "small";
180
+ const small = filingSizing(store, { title: input.title, goal: input.title }).size === "small";
176
181
  const solo = input.planFirst !== true && soloNow(store);
177
182
  if (!small && !solo)
178
- return { eligible: false, reason: "size" };
183
+ return { eligible: false, reason: taskSizingOn(store) ? "size" : "sizing-off" };
179
184
  const mode = store.activeMode(input.repo, now);
180
185
  if (mode !== null && /"autoApproveFiling":true/.test(mode.termsJson))
181
186
  return { eligible: false, reason: "mode" };
182
- const sizer = filingSizer();
183
- const sizing = small ? await classifyTask({ title: input.title, goal: input.title }, sizer.sizer, sizer.budget) : heuristicSizing({ title: input.title, goal: input.title });
187
+ const sizer = filingSizer(store);
188
+ const words = filingSizing(store, { title: input.title, goal: input.title });
189
+ const sizing = small && !sizer.off ? await classifyTask({ title: input.title, goal: input.title }, sizer.sizer, sizer.budget)
190
+ : sizer.off && words.size !== "small" ? { ...words, reason: JUST_CODE_SIZING_OFF } : words;
184
191
  const taskId = `task-${randomBytes(8).toString("hex")}`;
185
192
  const readUnder = (rule) => dryRun(store, () => {
186
193
  const filed = fileIt(store, taskId, { ...input, sizing }, now);
@@ -190,7 +197,7 @@ export async function prepareFastStart(store, input, now) {
190
197
  });
191
198
  let rule = small ? "small" : "solo";
192
199
  let read = readUnder(rule);
193
- if (!read.ok && rule === "small" && solo && (read.reason === "size" || read.reason === "classifier" || read.reason === "plan"))
200
+ if (!read.ok && rule === "small" && solo && (read.reason === "size" || read.reason === "classifier" || read.reason === "sizing-off" || read.reason === "plan"))
194
201
  read = readUnder(rule = "solo");
195
202
  if (!read.ok)
196
203
  return { eligible: false, reason: read.reason };
@@ -431,12 +438,14 @@ export async function prepareChatStart(store, input, now) {
431
438
  return { eligible: false, reason: "rules" };
432
439
  if (!fastStartOn(store, input.repo))
433
440
  return { eligible: false, reason: "setting" };
441
+ if (!taskSizingOn(store))
442
+ return { eligible: false, reason: "sizing-off" };
434
443
  if (heuristicSizing({ title: input.title, goal: input.title }).size !== "small")
435
444
  return { eligible: false, reason: "size" };
436
445
  const mode = store.activeMode(input.repo, now);
437
446
  if (mode !== null && /"autoApproveFiling":true/.test(mode.termsJson))
438
447
  return { eligible: false, reason: "mode" };
439
- const sizer = filingSizer();
448
+ const sizer = filingSizer(store);
440
449
  const sizing = await classifyTask({ title: input.title, goal: input.title }, sizer.sizer, sizer.budget);
441
450
  const taskId = `task-${randomBytes(8).toString("hex")}`;
442
451
  const filing = { actor: input.actor, repo: input.repo, title: input.title };
@@ -75,6 +75,6 @@ export function flexibleStartCard(store, input) {
75
75
  const networkDigest = flexibleNetworkDigest(network);
76
76
  const key = createHash("sha256").update(JSON.stringify({ v: 1, kind: "standing-orders:flexible-start", digest: standing.digest, repo: input.repo, by: input.by, model, level: "full", billing,
77
77
  network: networkDigest, message: digestOfMessage, decisions, warnings }), "utf8").digest("hex").slice(0, 32);
78
- const summary = { revision: null, revisionNotes: [], revisionChanges: [], decisions, why: null, differs: [], warnings, usual: [], usualLabel: "Other settings", key };
78
+ const summary = { revision: null, revisionNotes: [], revisionChanges: [], decisions, why: null, differs: [], warnings, usual: [], usualLabel: "Other settings", usualSummary: "", key };
79
79
  return { ok: true, card: { summary, digest: standing.digest, network: networkDigest, model, level: "full", billing, terms } };
80
80
  }
@@ -285,7 +285,7 @@ async function probeAgent(io, provider) {
285
285
  case "key-works":
286
286
  case "key-present": return { outcome: "ok", account, detail };
287
287
  case "not-installed": return { outcome: "absent", problem: `The ${name} CLI isn't installed on this computer.` };
288
- case "signed-out": return { outcome: "failed", account, problem: `${name} isn't signed in. Run ${command}.`, fix: { command } };
288
+ case "signed-out": return { outcome: "absent", problem: agentSignedOutWords(command) };
289
289
  case "missing-key": return { outcome: "failed", problem: `${name} is set to use an API key, and none is saved. Run ${command}.`, fix: { command } };
290
290
  case "key-refused": return { outcome: "failed", problem: `${name} refused the saved API key. Save a new one with ${command}.`, fix: { command } };
291
291
  default: return { outcome: "ok", account, detail: "Signed in; the account couldn't be read" };
@@ -479,6 +479,11 @@ export async function checkIntegrations(io, keys) {
479
479
  }));
480
480
  return integrationsNow(io);
481
481
  }
482
+ export const agentSignedOutWords = (command) => `signed out (run \`${command}\`)`;
483
+ const SIGNED_OUT_DETAIL = /^signed out \(run `[^`]+`\)$/;
484
+ export function agentsSignedOutLines(list) {
485
+ return list.filter(one => one.group === "agents" && one.state === "not-set-up" && one.detail !== null && SIGNED_OUT_DETAIL.test(one.detail)).map(one => `${one.name} · ${one.detail}`);
486
+ }
482
487
  export function integrationsBrokenLine(list) {
483
488
  const broken = list.filter(one => one.state === "broken").map(one => one.name);
484
489
  if (broken.length === 0)
@@ -71,6 +71,8 @@ import { aboutYouOf, checkAboutYouLine } from "./lead-about.js";
71
71
  import { steerStandingWords } from "./steer-status.js";
72
72
  import { agentQuestion, openAgentQuestions } from "./agent-board.js";
73
73
  import { utcMinute } from "./when-html.js";
74
+ import { RECORD_WHOLE_MAX, recordActionWhole } from "./action-ledger.js";
75
+ import { VIEW_CHANGES_PER_MINUTE, VIEW_LEDGER_ACTION } from "./view-tools.js";
74
76
  const REPO_ID = /^r[0-9]{1,3}$/;
75
77
  const TASK_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
76
78
  const ISO_STAMP = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?Z$/;
@@ -334,6 +336,8 @@ export const LEAD_CORE_TOOLS = new Set([
334
336
  "get_agents", "propose_dependency_repair",
335
337
  ]);
336
338
  const LEAD_TOOL_KEYWORDS = {
339
+ toolroll_view_read: ["workbench", "theme", "colours", "colors", "look", "restyle", "style", "terminal", "dark", "light"],
340
+ toolroll_view_set: ["workbench", "theme", "colours", "colors", "look", "restyle", "style", "density", "glyphs", "columns", "make it look"],
337
341
  show_card: ["findings", "handover", "card", "table", "chart", "graph", "report", "summary", "numbers", "data", "spend", "projects", "builders", "workers", "integrations", "show", "dashboard"],
338
342
  propose_flow: ["flow", "automation", "workflow", "schedule", "trigger", "every", "when", "email", "inbox", "sort", "follow-up", "nudge"],
339
343
  get_findings: ["finding", "findings", "review", "handover", "follow-through", "failed check", "send back"],
@@ -383,6 +387,54 @@ function summaryLine(description) {
383
387
  const first = /^(.+?[.!?])(\s|$)/.exec(description)?.[1] ?? description;
384
388
  return first.length <= 160 ? first : `${first.slice(0, 157).trimEnd()}…`;
385
389
  }
390
+ function viewRefusal(ctx) {
391
+ if (ctx.view === undefined || teamRoomOf(ctx.store, ctx.thread) !== null) {
392
+ return { ok: false, message: "Restyling the workbench is for the person's own conversation in the console on this computer: ask there, or they can edit tui.toml themselves." };
393
+ }
394
+ return null;
395
+ }
396
+ const VIEW_HISTORY_SCAN = 200;
397
+ function viewHistory(ctx) {
398
+ const rows = ctx.store.handle.prepare("SELECT id, at, outcome, detail FROM action_ledger WHERE actor = ? AND action = ? ORDER BY id DESC LIMIT ?")
399
+ .all(ctx.who.name, VIEW_LEDGER_ACTION, VIEW_HISTORY_SCAN).reverse();
400
+ const parsed = (text) => {
401
+ if (typeof text !== "string")
402
+ return null;
403
+ try {
404
+ const value = JSON.parse(text);
405
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
406
+ }
407
+ catch {
408
+ return null;
409
+ }
410
+ };
411
+ const pending = [];
412
+ const byId = new Map();
413
+ for (const row of rows) {
414
+ const detail = parsed(row["detail"]);
415
+ if (row["outcome"] === "pending") {
416
+ const change = detail?.["change"];
417
+ const one = { id: Number(row["id"]), at: String(row["at"]), change: typeof change === "object" && change !== null ? change : null, final: null };
418
+ pending.push(one);
419
+ byId.set(one.id, one);
420
+ }
421
+ else if (row["outcome"] === "done" || row["outcome"] === "failed" || row["outcome"] === "uncertain") {
422
+ const of = byId.get(Number(detail?.["pending"]));
423
+ if (of !== undefined && of.final === null)
424
+ of.final = row["outcome"];
425
+ }
426
+ }
427
+ return pending;
428
+ }
429
+ const VIEW_UNCONFIRMED_MS = 60_000;
430
+ export const VIEW_UNCERTAIN_WORDS = "This change may or may not have applied: the workbench never confirmed it.";
431
+ function settleViewChanges(ctx) {
432
+ const stale = ctx.now.getTime() - VIEW_UNCONFIRMED_MS;
433
+ for (const one of viewHistory(ctx).filter(row => row.final === null && Date.parse(row.at) < stale)) {
434
+ recordActionWhole(ctx.store.handle, { at: ctx.now.toISOString(), actor: ctx.who.name, repo: null, taskId: null, runId: null, action: VIEW_LEDGER_ACTION,
435
+ outcome: "uncertain", source: "request" }, { pending: one.id, said: VIEW_UNCERTAIN_WORDS });
436
+ }
437
+ }
386
438
  function controlTarget(ctx, args) {
387
439
  const control = args["control"];
388
440
  if (!isChatControl(control))
@@ -2205,6 +2257,60 @@ const LEAD_TOOL_HANDLERS = {
2205
2257
  return { ok: true, body: { proposal: proposalId, kind: "answer", decision: id, option: chosen.id, awaiting: chosen.reversible ? "the operator's confirmation" : "the operator's explicit confirmation — this option is irreversible" } };
2206
2258
  },
2207
2259
  },
2260
+ toolroll_view_read: {
2261
+ description: "Read the person's terminal workbench look before restyling it: its settings, what may be changed and to what, the theme roles (what each colours), the built-in and saved themes, and a short styling guide. Only in the person's own conversation on this computer.",
2262
+ handle: ctx => {
2263
+ const refused = viewRefusal(ctx);
2264
+ if (refused !== null)
2265
+ return refused;
2266
+ const read = ctx.view("read");
2267
+ if (!read.ok)
2268
+ return { ok: false, message: read.why };
2269
+ settleViewChanges(ctx);
2270
+ const body = read.body;
2271
+ return { ok: true, body: { settings: body["settings"], colors: body["colors"], allowed: body["allowed"], roles: body["roles"], themes: body["themes"], guide: body["guide"] } };
2272
+ },
2273
+ },
2274
+ toolroll_view_set: {
2275
+ description: "Restyle the person's terminal workbench (tui.toml) when they ask: a theme (built-in or saved), a saved theme of your own (save_theme: name, base, role colours; use: true switches to it, so 'make it look like X' is reusable), role colours (never a status's), density, glyphs, list columns (add only), list side, reduced motion, key bar, costs, notifications (on only: turning anything off is the person's). Read toolroll_view_read first. Contrast is enforced on every colour pair drawn: a change that makes text too faint is refused with the reason. Keys are never changed here (the person changes them). The running workbench repaints within a second; the person can undo with `toolroll view reset`.",
2276
+ handle: (ctx, args) => {
2277
+ const refused = viewRefusal(ctx);
2278
+ if (refused !== null)
2279
+ return refused;
2280
+ const raw = args;
2281
+ if ("keys" in raw)
2282
+ return { ok: false, message: "Keys can't be changed by an agent: they stay with the person (tui.toml's [keys], or the workbench's Settings screen), so an accept or a cancel never becomes a one-key accident." };
2283
+ const allowed = new Set(Object.keys(LEAD_TOOL_INPUTS.toolroll_view_set.shape));
2284
+ const unknown = Object.keys(raw).filter(key => !allowed.has(key));
2285
+ if (unknown.length > 0)
2286
+ return { ok: false, message: `toolroll_view_set takes ${[...allowed].join(", ")}; not ${unknown.slice(0, 3).map(one => redactForLead(one.slice(0, 32), { repos: [], names: [] })).join(", ")}.` };
2287
+ const change = Object.fromEntries(Object.entries(raw).filter(([, value]) => value !== undefined));
2288
+ if (Object.keys(change).length === 0)
2289
+ return { ok: false, message: "Nothing to change: name at least one setting." };
2290
+ const text = JSON.stringify(change);
2291
+ if (text.length > RECORD_WHOLE_MAX - 64)
2292
+ return { ok: false, message: "That change is too large: change a few settings at a time." };
2293
+ settleViewChanges(ctx);
2294
+ const since = ctx.now.getTime() - 60_000;
2295
+ const recent = viewHistory(ctx).filter(one => Date.parse(one.at) > since && one.final !== "failed").length;
2296
+ if (recent >= VIEW_CHANGES_PER_MINUTE)
2297
+ return { ok: false, message: `That's ${VIEW_CHANGES_PER_MINUTE} workbench changes in a minute; wait a moment before the next.` };
2298
+ const entry = { at: ctx.now.toISOString(), actor: ctx.who.name, repo: null, taskId: null, runId: null, action: VIEW_LEDGER_ACTION, source: "request" };
2299
+ const pending = recordActionWhole(ctx.store.handle, { ...entry, outcome: "pending" }, { change });
2300
+ const set = ctx.view("set", text);
2301
+ if (!set.ok) {
2302
+ if (set.unsure === true) {
2303
+ recordActionWhole(ctx.store.handle, { ...entry, outcome: "uncertain" }, { pending, said: VIEW_UNCERTAIN_WORDS, why: set.why.slice(0, 200) });
2304
+ return { ok: false, message: `${set.why}. This change may or may not have applied: read the workbench's settings before trying again.` };
2305
+ }
2306
+ recordActionWhole(ctx.store.handle, { ...entry, outcome: "failed" }, { pending, why: set.why.slice(0, 500) });
2307
+ return { ok: false, message: set.why };
2308
+ }
2309
+ const changed = Array.isArray(set.body["changed"]) ? set.body["changed"].filter((one) => typeof one === "string").slice(0, 40) : [];
2310
+ recordActionWhole(ctx.store.handle, { ...entry, outcome: "done" }, { pending, changed });
2311
+ return { ok: true, body: { changed, said: "Saved to tui.toml; the running workbench shows it within a second. `toolroll view reset` undoes it (the previous file is kept as tui.toml.bak)." } };
2312
+ },
2313
+ },
2208
2314
  propose_cancel: {
2209
2315
  description: "Propose task cancellation/reason; operator must arm and confirm.",
2210
2316
  handle: (ctx, args) => {
@@ -2223,7 +2329,7 @@ const LEAD_TOOL_HANDLERS = {
2223
2329
  };
2224
2330
  export const LEAD_TOOLS = Object.keys(LEAD_TOOL_INPUTS).map((name) => {
2225
2331
  const input = LEAD_TOOL_INPUTS[name];
2226
- const reader = name === "propose_flow" ? LEAD_TOOL_READ_INPUTS[name] : name === "propose_action" ? LEAD_TOOL_READ_INPUTS[name].loose() : LEAD_TOOL_READ_INPUTS[name].strip();
2332
+ const reader = name === "propose_flow" ? LEAD_TOOL_READ_INPUTS[name] : name === "propose_action" || name === "toolroll_view_set" ? LEAD_TOOL_READ_INPUTS[name].loose() : LEAD_TOOL_READ_INPUTS[name].strip();
2227
2333
  const handler = LEAD_TOOL_HANDLERS[name];
2228
2334
  return {
2229
2335
  name,
package/dist/lead.js CHANGED
@@ -523,7 +523,7 @@ export async function runLeadTurn(input) {
523
523
  }
524
524
  const progressId = `${turnId}:${steps}:${index}`;
525
525
  progress({ kind: "tool", turn: turnId, step: steps, id: progressId, label: leadToolLabel(call.name) });
526
- const toolContext = () => ({ store, who, now: clock(), draft, selectEvidence, ...(input.replyImage === undefined ? {} : { replyImage: input.replyImage }), step: steps, readDecisions, readResults, searchedMemory, checkedCapabilities, ask, findTools, ...(input.integrations === undefined ? {} : { integrations: input.integrations }), thread: thread.id, turn: turnId, ...(promiseChannelOfTurn(input.channel) === undefined ? {} : { channel: promiseChannelOfTurn(input.channel) }), ...(input.evidenceRoot === undefined ? {} : { evidenceRoot: input.evidenceRoot }), ...(input.mediaDelivery === undefined ? {} : { mediaDelivery: input.mediaDelivery }) });
526
+ const toolContext = () => ({ store, who, now: clock(), draft, selectEvidence, ...(input.replyImage === undefined ? {} : { replyImage: input.replyImage }), step: steps, readDecisions, readResults, searchedMemory, checkedCapabilities, ask, findTools, ...(input.integrations === undefined ? {} : { integrations: input.integrations }), thread: thread.id, turn: turnId, ...(promiseChannelOfTurn(input.channel) === undefined ? {} : { channel: promiseChannelOfTurn(input.channel) }), ...(input.evidenceRoot === undefined ? {} : { evidenceRoot: input.evidenceRoot }), ...(input.mediaDelivery === undefined ? {} : { mediaDelivery: input.mediaDelivery }), ...(input.view === undefined ? {} : { view: input.view }) });
527
527
  let startPrepared;
528
528
  if (call.name === "propose_start" && advertisedNames.has(call.name)) {
529
529
  const checked = startInputOf(toolContext(), call.args);
@@ -1,3 +1,4 @@
1
+ import { detailShown } from "./action-ledger.js";
1
2
  import { projectName } from "./project.js";
2
3
  import { exactWhenHtml } from "./when-html.js";
3
4
  import { html, postForm } from "./html.js";
@@ -44,7 +45,7 @@ ${text("ledger-outcome", "Outcome", "outcome", "Any outcome")}${text("ledger-tas
44
45
  const byActor = new URLSearchParams(kept);
45
46
  byActor.set("actor", row.actor);
46
47
  return html `<article class="h-audit" data-ledger-id="${row.id}"><span class="h-audit-time k-num">${exactWhenHtml(row.at)}</span>\
47
- <span class="h-audit-what"><a class="h-actor" href="/ledger?${byActor.toString()}" title="Only this actor's actions">${row.actor}</a> ${row.action}${row.detail === null ? "" : html `<span class="h-audit-detail">${row.detail}</span>`}</span>\
48
+ <span class="h-audit-what"><a class="h-actor" href="/ledger?${byActor.toString()}" title="Only this actor's actions">${row.actor}</a> ${row.action}${row.detail === null ? "" : html `<span class="h-audit-detail">${detailShown(row.detail)}</span>`}</span>\
48
49
  <span class="h-audit-place">${row.repo === null ? "Instance" : projectName(row.repo)} ${subject}</span><span class="h-audit-out">${row.outcome} · ${row.source}</span></article>`;
49
50
  })}</div>`;
50
51
  const paging = kept.has("before") || params.has("before") || more
@@ -36,6 +36,7 @@ export const LOCAL_OWNER_ACTS = Object.freeze([
36
36
  "agent-sign-in",
37
37
  "agent-install",
38
38
  "change-models",
39
+ "task-sizing-switch",
39
40
  ]);
40
41
  const ACT_SET = new Set(LOCAL_OWNER_ACTS);
41
42
  export function localOwnerAct(value) {
package/dist/needs-you.js CHANGED
@@ -3,7 +3,8 @@ export const START_BUILDER_HREF = "/settings/computers?section=start";
3
3
  export const startBuilderHref = (taskId) => taskId === null ? START_BUILDER_HREF : `/settings/computers?task=${encodeURIComponent(taskId)}&section=start`;
4
4
  export const START_BUILDER_COMMAND = "toolroll up";
5
5
  const always = () => true;
6
- const build = (context) => context.build == null ? "the last build" : `build #${context.build}`;
6
+ const build = (context) => context.build == null ? "the last build"
7
+ : context.attempt == null ? `build #${context.build}` : `attempt ${context.attempt} (build #${context.build})`;
7
8
  const Build = (context) => context.build == null ? "The last build" : `Build #${context.build}`;
8
9
  export const NEEDS = {
9
10
  approval: { sentence: () => "Review the plan and approve it to start.", action: { code: "approve-scope", label: "Approve plan" } },
@@ -102,7 +103,9 @@ export const WAITS = {
102
103
  "plan-next": () => "Waiting to plan.",
103
104
  "research-next": () => "Waiting to research.",
104
105
  "builders-busy": () => "Waiting its turn: builders are busy.",
105
- "retry-later": context => `Waiting: Toolroll retries ${build(context)} ${context.retry ?? "soon"}.`,
106
+ "retry-later": context => context.attempt != null && context.build != null
107
+ ? `Waiting: Toolroll tries attempt ${context.attempt + 1} ${context.retry ?? "soon"}, after attempt ${context.attempt} (build #${context.build}).`
108
+ : `Waiting: Toolroll retries ${build(context)} ${context.retry ?? "soon"}.`,
106
109
  "app-update": () => "Waiting: Toolroll is updating. New work starts after it.",
107
110
  "other-task": context => context.task == null ? "Waiting for another task to finish first." : `Waiting for ${context.task} to finish first.`,
108
111
  };
@@ -216,6 +219,7 @@ export const RUN_REASON_WORDS = {
216
219
  interrupted: "the attempt was interrupted",
217
220
  orphaned: "the attempt lost its builder",
218
221
  "retryable-infra": "a temporary problem on the machine stopped it",
222
+ "agent-error": "the agent stopped with an error",
219
223
  unknown: "the attempt stopped unexpectedly",
220
224
  "spawn-failed": "the agent process could not start",
221
225
  "provider-protocol": "the agent's reply could not be read",
@@ -286,6 +290,7 @@ const STOP_SUGGESTIONS = {
286
290
  "moved-head": "Retry: the next attempt starts from where the branch is now.",
287
291
  "moved-branch": "Retry: the next attempt starts from where the branch is now.",
288
292
  "retryable-infra": "Retry as it is.",
293
+ "agent-error": "Read what the agent said, change what it needs, then retry.",
289
294
  interrupted: "Retry as it is.",
290
295
  orphaned: "Retry as it is.",
291
296
  capability: "Add what the project is missing, then retry.",
@@ -318,3 +323,8 @@ export function retryNoteOf(suggestion) {
318
323
  return plain;
319
324
  return `${plain.slice(0, RETRY_NOTE_LIMIT - 1).replace(/\s+\S*$/, "").replace(/[,;:\s]+$/, "")}…`;
320
325
  }
326
+ export function runWords(runs, id) {
327
+ const builds = runs.filter(one => one.role === "builder" || one.role === "scout" || one.role === "repair").map(one => one.id).sort((a, b) => a - b);
328
+ const at = builds.indexOf(id);
329
+ return at < 0 ? `build #${id}` : `attempt ${at + 1} (build #${id})`;
330
+ }