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
@@ -7,6 +7,7 @@ import { LIMITS } from "./decision.js";
7
7
  import { callName, callOutcome, callWords, inputProblem, makeCall, offeredTools, refreshGrants, ruleFor } from "./subagent-tools.js";
8
8
  import { ACCEPT, answerSuggestion, considerSuggestion, memoriesFor, remember } from "./subagent-memory.js";
9
9
  import { replyToAsker } from "./subagent-desk.js";
10
+ import { subagentAttemptWithBackup } from "./subagent-backup.js";
10
11
  import { claudeMachineBilling } from "./spend.js";
11
12
  export const ASKED = "9999-12-31T00:00:00.000Z";
12
13
  const CARRY_ON = "Carry on";
@@ -87,15 +88,18 @@ export async function subagentTurn(store, flow, definition, stage, card, mate, n
87
88
  const tools = spent ? [] : offeredTools(store, mate);
88
89
  const context = { ...contextOf(store, flow, definition, stage, card, mate, tools, spent && made > 0), ...(shorten === undefined ? {} : { shorten }) };
89
90
  const asked = Date.now();
90
- const reply = await (io.turn ?? claudeTurnRunner())({ model, prompt: turnPrompt(context), timeoutMs: TURN_TIMEOUT_MS });
91
- store.addSubagentTurn({ subagent: mate.id, card: card.id, model, ok: reply.ok, ms: reply.ok ? reply.ms : Date.now() - asked, costUsd: reply.costUsd ?? null, tokensIn: reply.tokensIn ?? null, tokensOut: reply.tokensOut ?? null }, now);
91
+ const attempt = io.turn === undefined && store.getSubagent(mate.id)?.codexBackupModel != null
92
+ ? await subagentAttemptWithBackup(store, mate, card, { model, prompt: turnPrompt(context), timeoutMs: TURN_TIMEOUT_MS, flowRevision: flow.revision }) : null;
93
+ const reply = attempt?.reply ?? await (io.turn ?? claudeTurnRunner())({ model, prompt: turnPrompt(context), timeoutMs: TURN_TIMEOUT_MS });
94
+ if (attempt === null)
95
+ store.addSubagentTurn({ subagent: mate.id, card: card.id, model, ok: reply.ok, ms: reply.ok ? reply.ms : Date.now() - asked, costUsd: reply.costUsd ?? null, tokensIn: reply.tokensIn ?? null, tokensOut: reply.tokensOut ?? null }, now);
92
96
  if (!reply.ok)
93
97
  return { state: "retry", said: reply.said, ...(log.length === 0 ? {} : { log: log.join("\n\n") }) };
94
98
  const read = readTurn(reply.value, context);
95
99
  if (!read.ok)
96
100
  return { state: "retry", said: `${context.name}'s answer wasn't one this zone allows.`, log: [...log, read.issues.map(issue => issue.line).join("\n"), JSON.stringify(reply.value).slice(0, 4000)].join("\n\n") };
97
101
  const answer = read.value;
98
- const header = `${context.name} (${model}) · ${(reply.ms / 1000).toFixed(1)} s`;
102
+ const header = `${context.name} (${attempt?.backup ? `Codex backup · ${attempt.model}` : model}) · ${(reply.ms / 1000).toFixed(1)} s`;
99
103
  const over = turnOverruns(answer);
100
104
  if (over.length > 0 && !shortened) {
101
105
  shortened = true;
@@ -105,60 +109,79 @@ export async function subagentTurn(store, flow, definition, stage, card, mate, n
105
109
  continue;
106
110
  }
107
111
  shorten = undefined;
108
- if (answer.remember !== "")
109
- remember(store, mate, answer.remember, { source: "subagent", card: card.id, by: subagentActor({ name: context.name }) }, now);
110
- if (answer.action !== "use_tool") {
111
- const outcome = carryOut(store, flow, definition, stage, card, mate, context, answer, now, io, header);
112
+ const accepted = store.transact(() => {
113
+ const problem = attempt?.authorize();
114
+ if (problem != null)
115
+ return { refused: { state: "retry", said: problem } };
116
+ if (answer.remember !== "")
117
+ remember(store, mate, answer.remember, { source: "subagent", card: card.id, by: subagentActor({ name: context.name }) }, now);
118
+ return answer.action === "use_tool" ? {} : { outcome: carryOut(store, flow, definition, stage, card, mate, context, answer, now, io, header) };
119
+ });
120
+ if (accepted.refused !== undefined)
121
+ return accepted.refused;
122
+ if (accepted.outcome !== undefined) {
123
+ const outcome = accepted.outcome;
112
124
  return log.length === 0 ? outcome : { ...outcome, log: `${log.join("\n\n")}\n\n${outcome.log ?? ""}`.trim() };
113
125
  }
114
126
  log.push(`${header}\n\n${JSON.stringify(answer)}`);
115
- const waiting = await useTool(store, flow, stage, card, mate, context, answer, io, now);
127
+ const waiting = await useTool(store, flow, stage, card, mate, context, answer, io, now, attempt?.authorize);
116
128
  if (waiting !== null)
117
129
  return { ...waiting, log: log.join("\n\n") };
118
130
  }
119
131
  }
120
- async function useTool(store, flow, stage, card, mate, context, answer, io, now) {
121
- const split = answer.tool.indexOf(".");
122
- const tool = split < 0 ? answer.tool : answer.tool.slice(0, split), action = split < 0 ? "" : answer.tool.slice(split + 1);
123
- const receipt = { subagent: mate.id, card: card.id, entry: card.entry, tool: tool.slice(0, 40), action: action.slice(0, 64) || "(none)", why: answer.reason };
124
- const refuse = (input, said) => { store.addSubagentCall({ ...receipt, input, rule: "never", state: "refused", result: said }, now); return null; };
125
- if (!(context.tools ?? []).some(one => one.name === answer.tool))
126
- return refuse({}, `There's no ${answer.tool} among the tools you may use.`);
127
- let input;
128
- try {
129
- const parsed = JSON.parse(answer.input === "" ? "{}" : answer.input);
130
- if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
132
+ async function useTool(store, flow, stage, card, mate, context, answer, io, now, authorize) {
133
+ const prepared = store.transact(() => {
134
+ const authorityProblem = authorize?.();
135
+ if (authorityProblem != null)
136
+ return { outcome: { state: "retry", said: authorityProblem } };
137
+ const split = answer.tool.indexOf(".");
138
+ const tool = split < 0 ? answer.tool : answer.tool.slice(0, split), action = split < 0 ? "" : answer.tool.slice(split + 1);
139
+ const receipt = { subagent: mate.id, card: card.id, entry: card.entry, tool: tool.slice(0, 40), action: action.slice(0, 64) || "(none)", why: answer.reason };
140
+ const refuse = (input, said) => { store.addSubagentCall({ ...receipt, input, rule: "never", state: "refused", result: said }, now); return { outcome: null }; };
141
+ if (!(context.tools ?? []).some(one => one.name === answer.tool))
142
+ return refuse({}, `There's no ${answer.tool} among the tools you may use.`);
143
+ let input;
144
+ try {
145
+ const parsed = JSON.parse(answer.input === "" ? "{}" : answer.input);
146
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
147
+ return refuse({}, "Its input wasn't a JSON object.");
148
+ input = parsed;
149
+ }
150
+ catch {
131
151
  return refuse({}, "Its input wasn't a JSON object.");
132
- input = parsed;
133
- }
134
- catch {
135
- return refuse({}, "Its input wasn't a JSON object.");
136
- }
137
- const grant = store.subagentGrant(mate.id, tool);
138
- const info = grant.actions.find(one => one.name === action);
139
- const problem = inputProblem(info, input);
140
- if (problem !== null)
141
- return refuse(input, problem);
142
- const rule = ruleFor(grant, action, input);
143
- if (rule.use === "never")
144
- return refuse(input, rule.why);
145
- if (rule.use === "free") {
146
- const id = store.addSubagentCall({ ...receipt, input, rule: "free", state: "running" }, now);
147
- await makeCall(store, store.subagentCall(id), flow.repo, io, now);
152
+ }
153
+ const grant = store.subagentGrant(mate.id, tool);
154
+ const info = grant?.actions.find(one => one.name === action);
155
+ if (grant === null || info === undefined)
156
+ return refuse(input, "This tool action is no longer available.");
157
+ const problem = inputProblem(info, input);
158
+ if (problem !== null)
159
+ return refuse(input, problem);
160
+ const rule = ruleFor(grant, action, input);
161
+ if (rule.use === "never")
162
+ return refuse(input, rule.why);
163
+ if (rule.use === "free") {
164
+ const id = store.addSubagentCall({ ...receipt, input, rule: "free", state: "running" }, now);
165
+ return { call: id };
166
+ }
167
+ const soul = { name: context.name, role: context.role };
168
+ const id = store.addSubagentCall({ ...receipt, input, rule: "ask", state: "asked", result: rule.why }, now);
169
+ const words = callWords(tool, action, input, 480);
170
+ const question = store.openSubagentQuestion({ subagent: mate.id, card: card.id, entry: card.entry, question: `Use ${words}?`, options: [{ id: APPROVE, label: "Approve" }, { id: DENY, label: "Deny" }], askedOf: context.person, toolCall: id }, now);
171
+ if (question === null)
172
+ return { outcome: { state: "failed", said: "It asked to make the same call twice." } };
173
+ notifyPeople(store, card, [context.person], null, { key: `teammate-q:${question}`, attention: true, subject: `${subagentLabel(soul)} asks to use ${action} on “${card.title}”`,
174
+ body: `${words}\n\n${answer.reason === "" ? "" : `Why: ${answer.reason}\n`}(${rule.why})\n\nApprove makes exactly this call. Deny stops it. Or answer in words to tell ${context.name} what to do instead.`,
175
+ }, now);
176
+ if (stage.kind !== "approval")
177
+ store.updateFlowCard(card.id, { waiting: `${context.name} asked ${context.person} to approve: ${words}`.slice(0, 300) }, now);
178
+ return { outcome: { state: "waiting", said: `Asked ${context.person} to approve ${action}`, nextAt: ASKED } };
179
+ });
180
+ if ("call" in prepared) {
181
+ await makeCall(store, store.subagentCall(prepared.call), flow.repo, io, now);
148
182
  return null;
149
183
  }
150
- const soul = { name: context.name, role: context.role };
151
- const id = store.addSubagentCall({ ...receipt, input, rule: "ask", state: "asked", result: rule.why }, now);
152
- const words = callWords(tool, action, input, 480);
153
- const question = store.openSubagentQuestion({ subagent: mate.id, card: card.id, entry: card.entry, question: `Use ${words}?`, options: [{ id: APPROVE, label: "Approve" }, { id: DENY, label: "Deny" }], askedOf: context.person, toolCall: id }, now);
154
- if (question === null)
155
- return { state: "failed", said: "It asked to make the same call twice." };
156
- notifyPeople(store, card, [context.person], null, { key: `teammate-q:${question}`, attention: true, subject: `${subagentLabel(soul)} asks to use ${action} on “${card.title}”`,
157
- body: `${words}\n\n${answer.reason === "" ? "" : `Why: ${answer.reason}\n`}(${rule.why})\n\nApprove makes exactly this call. Deny stops it. Or answer in words to tell ${context.name} what to do instead.`,
158
- }, now);
159
- if (stage.kind !== "approval")
160
- store.updateFlowCard(card.id, { waiting: `${context.name} asked ${context.person} to approve: ${words}`.slice(0, 300) }, now);
161
- return { state: "waiting", said: `Asked ${context.person} to approve ${action}`, nextAt: ASKED };
184
+ return prepared.outcome;
162
185
  }
163
186
  function keptWhole(store, flow, card, author, text, limit, holds, what, now) {
164
187
  const kept = passOn(text, limit, { label: "the card's discussion", href: flowCardHref(flow.id, card.id) }, holds);
@@ -1,3 +1,4 @@
1
+ import { field, input, btn } from "./server/kit.js";
1
2
  import { labelOf, nameOf, summaryOf, SUBAGENT_MODELS, zonesOf } from "./subagent-admin.js";
2
3
  import { SUBAGENT_TEMPLATES } from "./subagents.js";
3
4
  import { projectToolsOf } from "./project-tools.js";
@@ -122,6 +123,9 @@ export function subagentPageHtml(store, mate, viewer, projectName, canManage, ap
122
123
  const soul = html `<details class="card"${canManage && html ` open`}><summary>Soul file</summary><p class="meta">Who ${name} is and its rules, read every turn. Version ${mate.version}${latest !== undefined && ` · saved by ${latest.savedBy}, ${when(latest.savedAt)}`} · <a href="/settings/lead/subagents/${mate.id}/soul.md" download>Download</a></p>${canManage
123
124
  ? postForm(`/settings/lead/subagents/${mate.id}/soul`, html `<label class="sr-only" for="subagent-soul">Soul file</label><textarea id="subagent-soul" name="soul" rows="24" class="mono" maxlength="12000" spellcheck="false">${notice.soulDraft ?? mate.soul}</textarea><button>Save</button>`, { attrs: { "data-soul-form": true } })
124
125
  : html `<pre class="mono">${mate.soul}</pre>`}</details>`;
125
- const settings = canManage && html `<details class="card"><summary>Settings</summary>${postForm(`/settings/lead/subagents/${mate.id}/settings`, html `<label>Model<select name="model">${SUBAGENT_MODELS.map(one => html `<option value="${one}"${(mate.model ?? "default") === one && html ` selected`}>${one === "default" ? "The lead chat's model" : one[0].toUpperCase() + one.slice(1)}</option>`)}</select></label><label>Turns a day, at most<input type="number" name="dailyTurns" min="1" max="2000" value="${mate.dailyTurns}"></label><label>Reports to<select name="manager">${[...new Set([mate.manager, ...approvers])].map(one => html `<option value="${one}"${one === mate.manager && html ` selected`}>${one}</option>`)}</select></label><button>Save settings</button>`)}${postForm(`/settings/lead/subagents/${mate.id}/state`, html `<button class="danger">Remove ${name} from the team</button>`, { attrs: { class: "danger-zone" }, hidden: { state: "removed" } })}</details>`;
126
- return html `${notice.problem && html `<p class="problem" role="alert">${notice.problem}</p>`}${notice.said && html `<p class="said" role="status">${notice.said}</p>`}<p class="meta">${projectName(mate.repo)} · ${mate.state === "active" ? "Working" : "Paused: its decisions go to people"} · reports to ${mate.manager}</p>${manage}${questions.length > 0 && html `<section><h2>Questions</h2>${asked}</section>`}<section class="card"><h2>Today</h2><p class="subagent-summary">${lines(summaryOf(store, mate, startOfDay()).said)}</p></section>${weekSection(store, mate, canManage)}<section class="card"><h2>Works on</h2>${where}</section>${toolsSection(store, mate, canManage)}${deskSection(store, mate, canManage)}${memorySection(store, mate, canManage, notice.query ?? null)}${soul}<details class="card"><summary>What ${name} did</summary>${activity}</details>${settings}`;
126
+ const backupProblem = notice.problem?.includes("Codex backup") === true;
127
+ const backupPasswordProblem = backupProblem && notice.problem?.startsWith("Enter your Toolroll password") === true;
128
+ const backup = html `<input type="hidden" name="backupPresent" value="1"><details class="k-disclose" id="backup"${(backupProblem || mate.codexBackupModel !== null) && html ` open`}><summary>Codex backup · ${mate.codexBackupModel === null ? "Off" : "On"}</summary><p class="meta">When Claude hits its limit or isn't installed, send this teammate's card, memory and tool results to Codex through your ChatGPT sign-in. Tool approvals stay the same.</p>${field({ id: "subagent-backup-model", label: "Codex model", hint: "Leave blank to turn off. Each Claude or Codex attempt counts toward the daily limit.", error: backupProblem && !backupPasswordProblem ? notice.problem ?? null : null, control: input({ id: "subagent-backup-model", name: "codexBackupModel", value: notice.backupDraft ?? mate.codexBackupModel ?? "", hint: true, error: backupProblem && !backupPasswordProblem, attrs: { autocomplete: "off", spellcheck: "false" } }) })}${reauth(field({ id: "subagent-backup-password", label: "Password to enable or change backup", error: backupPasswordProblem ? notice.problem ?? null : null, control: input({ id: "subagent-backup-password", name: "password", type: "password", error: backupPasswordProblem, attrs: { autocomplete: "current-password" } }) }))}</details>`;
129
+ const settings = canManage && html `<details class="card"${backupProblem && html ` open`}><summary>Settings</summary>${postForm(`/settings/lead/subagents/${mate.id}/settings`, html `<label>Model<select name="model">${SUBAGENT_MODELS.map(one => html `<option value="${one}"${(mate.model ?? "default") === one && html ` selected`}>${one === "default" ? "The lead chat's model" : one[0].toUpperCase() + one.slice(1)}</option>`)}</select></label><label>Turns a day, at most<input type="number" name="dailyTurns" min="1" max="2000" value="${mate.dailyTurns}"></label><label>Reports to<select name="manager">${[...new Set([mate.manager, ...approvers])].map(one => html `<option value="${one}"${one === mate.manager && html ` selected`}>${one}</option>`)}</select></label>${backup}${btn("Save settings", { type: "submit" })}`)}${postForm(`/settings/lead/subagents/${mate.id}/state`, html `<button class="danger">Remove ${name} from the team</button>`, { attrs: { class: "danger-zone mt-3" }, hidden: { state: "removed" } })}</details>`;
130
+ return html `${notice.problem && !backupProblem && html `<p class="problem" role="alert">${notice.problem}</p>`}${notice.said && html `<p class="said" role="status">${notice.said}</p>`}<p class="meta">${projectName(mate.repo)} · ${mate.state === "active" ? "Working" : "Paused: its decisions go to people"} · reports to ${mate.manager}</p>${manage}${questions.length > 0 && html `<section><h2>Questions</h2>${asked}</section>`}<section class="card"><h2>Today</h2><p class="subagent-summary">${lines(summaryOf(store, mate, startOfDay()).said)}</p></section>${weekSection(store, mate, canManage)}<section class="card"><h2>Works on</h2>${where}</section>${toolsSection(store, mate, canManage)}${deskSection(store, mate, canManage)}${memorySection(store, mate, canManage, notice.query ?? null)}${soul}<details class="card"><summary>What ${name} did</summary>${activity}</details>${settings}`;
127
131
  }
package/dist/subagents.js CHANGED
@@ -189,13 +189,16 @@ export function claudeTurnRunner(runner = run) {
189
189
  "-p", "--output-format", "json", "--json-schema", JSON.stringify(TURN_MODEL_SCHEMA), ...CLAUDE_NO_TOOLS_ARGS, ...claudeModelArgs(request.model),
190
190
  ], { cwd: dir, stdin: request.prompt, timeoutMs: request.timeoutMs, maxBuffer: 512 * 1024, omitEnv: ALL_CREDENTIAL_ENV, processGroup: true });
191
191
  if (result.notFound)
192
- return { ok: false, said: "Claude isn't installed on this computer." };
192
+ return { ok: false, said: "Claude isn't installed on this computer.", backupReason: "unavailable" };
193
193
  if (result.timedOut)
194
194
  return { ok: false, said: "Claude took too long to decide." };
195
195
  const body = claudeJsonBody(result.stdout, 512 * 1024);
196
196
  if (result.code !== 0 || body === null || body["is_error"] === true || body["subtype"] !== "success") {
197
197
  const why = typeof body?.["subtype"] === "string" && body["subtype"] !== "success" ? ` (${String(body["subtype"]).replace(/_/g, " ").slice(0, 60)})` : result.code !== 0 ? ` (exit ${result.code})` : "";
198
- return { ok: false, said: CLAUDE_SIGNED_OUT.test(`${result.stdout}${result.stderr}`) ? "Claude isn't signed in on this computer." : `Claude couldn't decide${why}.` };
198
+ const backupReason = result.code !== 0 && body?.["type"] === "result" && body["is_error"] === true
199
+ && body["api_error_status"] === 429 && ["usage_limit_reached", "rate_limit_error"].includes(String(body["api_error"])) ? "usage-limit" : undefined;
200
+ return { ok: false, said: backupReason === "usage-limit" ? "Claude reached its usage limit." : CLAUDE_SIGNED_OUT.test(`${result.stdout}${result.stderr}`) ? "Claude isn't signed in on this computer." : `Claude couldn't decide${why}.`,
201
+ ...costOf(body ?? {}), ...(backupReason === undefined ? {} : { backupReason }) };
199
202
  }
200
203
  const cost = costOf(body);
201
204
  if (body["structured_output"] !== undefined && body["structured_output"] !== null)
@@ -38,6 +38,10 @@ function outputSchema(tools) {
38
38
  };
39
39
  }
40
40
  export function composeSubscriptionLeadPrompt(request) {
41
+ if (request.outputSchema !== undefined)
42
+ return [request.system,
43
+ "STRUCTURED RESPONSE PROTOCOL: Return only the JSON object required by the supplied output schema. Do not use any harness tools or inspect the computer. DATA and CONVERSATION below are the only context.",
44
+ `DATA:\n${request.dataDocument}`, `CONVERSATION:\n${JSON.stringify(request.history)}`].join("\n\n");
41
45
  return [
42
46
  request.system,
43
47
  "SUBSCRIPTION HARNESS PROTOCOL:",
package/dist/surface.js CHANGED
@@ -276,7 +276,8 @@ const GUIDE_ROWS = [
276
276
  flags: [jsonFlag, dbFlag, keyFlag,
277
277
  { name: "provider", takesValue: true, meaning: "pin which provider plans THIS task (plan phase only)" },
278
278
  { name: "model", takesValue: true, meaning: "the pinned plan model, riding --provider" },
279
- { name: "digest", takesValue: true, meaning: "the terminal's local owner: the exact planning source read; required there, and --provider/--model are refused" }],
279
+ { name: "digest", takesValue: true, meaning: "the terminal's local owner: the exact planning source read; required there, and --provider/--model are refused" },
280
+ { name: "incident", takesValue: true, meaning: "the terminal's local owner: plan again after this planning incident (the plan failed its checks)" }],
280
281
  notableReasons: ["unknown-task"] },
281
282
  { invocation: "task hold", synopsis: "park a task with a reason", audience: "agent", agentMayInvoke: true, mutation: "keyed",
282
283
  positionals: [{ name: "id", required: true, meaning: "the task" }],
@@ -425,6 +426,11 @@ const GUIDE_ROWS = [
425
426
  operator("mode revoke", "revoke a repository's mode — one click, every act it covered falls back to its own ceremony"),
426
427
  operator("config set", "set phase or spend configuration"),
427
428
  operator("config clear", "clear phase or spend configuration"),
429
+ operatorRead("thread list", "your own interactive agent threads: each one's title, project and where it stands"),
430
+ operatorRead("thread show", "one of your threads: its latest turn, its end and its Ship, in Toolroll's words"),
431
+ operator("thread end", "end one of your threads for good (its agent stops; its work can still be shipped for a week)"),
432
+ operator("thread remove", "remove one of your threads' working copy (refused while its agent may run or a Ship is open)"),
433
+ operator("thread ship", "ship one of your threads' committed work: shows its terms, asks, then takes your password typed now"),
428
434
  operator("setup clear", "clear installation setup"),
429
435
  operator("verify set", "approve the one shell command the plane re-runs after every future commit (--quick \"<cmd>\" approves the fast check Quick runs); --self-heal binds one approved-setup replay when a required project executable is missing"),
430
436
  operator("verify clear", "revoke a repository's approved verification command; --level quick revokes only the quick command"),
@@ -473,6 +479,7 @@ const REMOTE_NO = [
473
479
  "models results",
474
480
  "models suggestions", "models accept", "models dismiss", "models turn-off", "models keep", "models try", "models stop",
475
481
  "map on", "map off", "map holdout end", "map report",
482
+ "thread list", "thread show", "thread end", "thread remove", "thread ship",
476
483
  "publish", "publish status", "publish merge", "publish refire", "publish unblock", "publish rearm", "publish grant", "publish revoke",
477
484
  "enroll", "revoke",
478
485
  "flows import", "flows trigger check", "flows script save",
@@ -4,16 +4,16 @@ import { FAILED_CHECK } from "./result-acts.js";
4
4
  import { CODE_READING, NEEDS, needSentence, waitSentence } from "./needs-you.js";
5
5
  export const replacedWords = (successor) => `Replaced by ${successor}`;
6
6
  const REPLACED = /^Replaced by \S+/;
7
- export const HEADLINES = ["Queued", "Planning", "Needs you", "Waiting", "Building", "Ready for review", "Complete", "Failed", "Stopped"];
7
+ export const HEADLINES = ["Queued", "Planning", "Needs you", "Waiting", "Building", "Ready", "Complete", "Failed", "Stopped"];
8
8
  export const HEADLINE_TONE = {
9
9
  Queued: "neutral", Planning: "live", "Needs you": "attention", Waiting: "neutral", Building: "live",
10
- "Ready for review": "ready", Complete: "success", Failed: "danger", Stopped: "neutral",
10
+ "Ready": "ready", Complete: "success", Failed: "danger", Stopped: "neutral",
11
11
  };
12
12
  export const CHECKS_LABEL = "Project checks";
13
13
  export const PR_CI_LABEL = "PR CI";
14
14
  export const OPEN_RESULT = "Open result";
15
15
  export const MACHINE_CHECK_RUNNING = "Running the check on the prepared version.";
16
- export const CHECKED_AT_RELEASE = "Checked at release";
16
+ export const CHECKED_AT_RELEASE = "Checks deferred to release";
17
17
  export function releaseStateOf(checks) {
18
18
  if (checks?.level !== "off" || checks.status === "passed" || checks.status === "failed")
19
19
  return undefined;
@@ -107,12 +107,12 @@ export function headlineOf(facts) {
107
107
  case "reviewing": return "Building";
108
108
  case "finished":
109
109
  if (facts.report)
110
- return "Ready for review";
110
+ return "Ready";
111
111
  if (facts.checks?.status === "failed")
112
112
  return "Failed";
113
113
  if (resultAsk(facts) !== null)
114
114
  return "Needs you";
115
- return "Ready for review";
115
+ return "Ready";
116
116
  case "complete": return "Complete";
117
117
  case "failed": return "Failed";
118
118
  case "stopped": return "Stopped";
@@ -129,13 +129,13 @@ function sentenceOf(headline, facts) {
129
129
  case "Building": return facts.stage === "checking" ? "Checks are running on the change."
130
130
  : facts.stage === "reviewing" ? "Reviewing the change before it reaches you."
131
131
  : facts.machine === true ? MACHINE_CHECK_RUNNING : reason ?? "An agent is working on it.";
132
- case "Ready for review":
132
+ case "Ready":
133
133
  if (facts.report)
134
134
  return "The report is ready to read. Read it, then accept it.";
135
135
  if (releaseStateOf(facts.checks) === "covered")
136
- return `Checked at release on ${short(facts.checks.release.head) ?? "its release"}. Review the change, then accept it.`;
136
+ return `Release checks passed on ${short(facts.checks.release.head) ?? "its release"}. Review the change, then accept it.`;
137
137
  if (facts.checks?.level === "off" && facts.checks.status !== "passed")
138
- return "Checked at release. Review the change, then accept it.";
138
+ return "Checks deferred to release. Review the change, then accept it.";
139
139
  if (facts.checks?.status === "passed") {
140
140
  const peers = facts.checks.batch?.state === "together" ? facts.checks.batch.peers.length : 0;
141
141
  if (peers > 0)
@@ -196,7 +196,7 @@ function detailsOf(headline, facts) {
196
196
  else if (checks.status === "running")
197
197
  row("checks", CHECKS_LABEL, "Running", "running");
198
198
  else if (checks.level === "off" && checks.release != null)
199
- row("checks", CHECKS_LABEL, `Passed at release on ${short(checks.release.head) ?? `build #${checks.release.run}`}`, "ok", { href: checksHref });
199
+ row("checks", CHECKS_LABEL, `Release checks passed on ${short(checks.release.head) ?? `build #${checks.release.run}`}`, "ok", { href: checksHref });
200
200
  else if (checks.level === "off")
201
201
  row("checks", CHECKS_LABEL, CHECKED_AT_RELEASE, "none", runChecks === null ? {} : { action: runChecks });
202
202
  else if (checks.status === "not-run")
@@ -256,7 +256,7 @@ function detailsOf(headline, facts) {
256
256
  }
257
257
  export const leadOnIt = (name = DEFAULT_LEAD_NAME) => `${name} is on it.`;
258
258
  export const leadLapsed = (name = DEFAULT_LEAD_NAME) => `${name} hasn't acted on this for 2 hours, so it's back with you.`;
259
- const LEAD_HEADLINES = new Set(["Needs you", "Failed", "Ready for review", "Stopped"]);
259
+ const LEAD_HEADLINES = new Set(["Needs you", "Failed", "Ready", "Stopped"]);
260
260
  function leadSentence(headline, facts) {
261
261
  const sha = short(facts.checks?.head ?? null);
262
262
  if (headline === "Failed" && facts.checks?.status === "failed")
@@ -277,7 +277,7 @@ export function statusOf(facts) {
277
277
  }
278
278
  export const taskStatusOf = statusOf;
279
279
  const ALWAYS_NEEDS = new Set(["planner-source", "signed-out", "needs-approval", "waiting-decision", "decision-queue"]);
280
- const QUEUED_REASONS = new Set(["worker-at-capacity", "waiting-dependency", "retry-scheduled", "updating", "planning-ready", "scouting-ready", "provider-quota"]);
280
+ const QUEUED_REASONS = new Set(["worker-at-capacity", "waiting-dependency", "retry-scheduled", "plan-retry", "updating", "planning-ready", "scouting-ready", "provider-quota"]);
281
281
  export function plainReasonOf(stage, code, detail) {
282
282
  if (stage === "building" || stage === "checking" || stage === "reviewing" || stage === "planning")
283
283
  return null;
@@ -489,7 +489,7 @@ export function workToneOf(headline) {
489
489
  case "Failed": return "problem";
490
490
  case "Building":
491
491
  case "Planning": return "live";
492
- case "Ready for review": return "ready";
492
+ case "Ready": return "ready";
493
493
  case "Complete": return "done";
494
494
  default: return "muted";
495
495
  }
@@ -499,7 +499,7 @@ export function statusDetailLines(status) {
499
499
  return status.details.map(one => `${icon[one.mark]} ${one.label} · ${one.text}${one.action === null ? "" : ` — ${one.action.label}`}`);
500
500
  }
501
501
  export function headlineEmoji(headline) {
502
- return { Queued: "🕓", Planning: "📝", "Needs you": "👋", Waiting: "⏸", Building: "⏳", "Ready for review": "✅", Complete: "✅", Failed: "❌", Stopped: "⏹" }[headline];
502
+ return { Queued: "🕓", Planning: "📝", "Needs you": "👋", Waiting: "⏸", Building: "⏳", "Ready": "✅", Complete: "✅", Failed: "❌", Stopped: "⏹" }[headline];
503
503
  }
504
504
  const ICON_PATHS = {
505
505
  ok: html `<path d="M20 6 9 17l-5-5"/>`,
@@ -62,7 +62,7 @@ function groupOf(d) {
62
62
  if (d.code === "cancelled")
63
63
  return d.summary.startsWith("Replaced by ") ? "Replaced" : "Cancelled";
64
64
  if (d.code === "complete")
65
- return "Finished";
65
+ return "Complete";
66
66
  if (d.code === "review-pending" || d.action === null)
67
67
  return "Waiting / next up";
68
68
  return "Needs attention";
@@ -99,7 +99,7 @@ export function phoneStatus(store, repos, now, focused = null, root) {
99
99
  lines.push("Newest 60 tasks only — older work may still need attention.", "");
100
100
  if (snapshot.tasks.length === 0)
101
101
  lines.push("No tasks are recorded in these projects.");
102
- for (const group of ["Needs attention", "Working", "Waiting / next up", "Finished", "Replaced", "Cancelled"]) {
102
+ for (const group of ["Needs attention", "Working", "Waiting / next up", "Complete", "Replaced", "Cancelled"]) {
103
103
  const rows = snapshot.tasks.filter(t => t.dispatch !== null && t.dispatch !== undefined && groupOf(t.dispatch) === group);
104
104
  if (rows.length === 0)
105
105
  continue;
@@ -115,7 +115,7 @@ export function phoneStatus(store, repos, now, focused = null, root) {
115
115
  return lines.join("\n");
116
116
  });
117
117
  }
118
- const PICK_GROUPS = ["Needs attention", "Working", "Waiting / next up", "Finished"];
118
+ const PICK_GROUPS = ["Needs attention", "Working", "Waiting / next up", "Complete"];
119
119
  export function phoneTaskChoices(store, repos, now, query = null, limit = 8, root) {
120
120
  if (repos.length === 0)
121
121
  return [];
@@ -0,0 +1,114 @@
1
+ import { StringDecoder } from "node:string_decoder";
2
+ export class TerminalSafetyFilter {
3
+ decoder = new StringDecoder("utf8");
4
+ state = "text";
5
+ sequence = "";
6
+ osc = false;
7
+ ended = false;
8
+ write(bytes) {
9
+ if (this.ended)
10
+ throw new Error("Terminal safety filter already finished");
11
+ return this.parse(this.decoder.write(Buffer.from(bytes)));
12
+ }
13
+ finish() {
14
+ if (this.ended)
15
+ return "";
16
+ const out = this.parse(this.decoder.end());
17
+ this.ended = true;
18
+ this.sequence = "";
19
+ this.state = "text";
20
+ return out;
21
+ }
22
+ parse(text) {
23
+ const out = [];
24
+ for (const char of text) {
25
+ const code = char.codePointAt(0);
26
+ if (this.state === "string" || this.state === "string-escape") {
27
+ if (code === 0x9c || (this.osc && code === 7) || (this.state === "string-escape" && char === "\\")) {
28
+ this.state = "text";
29
+ }
30
+ else
31
+ this.state = char === "\x1b" ? "string-escape" : "string";
32
+ continue;
33
+ }
34
+ if (char === "\x1b") {
35
+ this.state = "escape";
36
+ this.sequence = "";
37
+ continue;
38
+ }
39
+ if ([0x90, 0x98, 0x9d, 0x9e, 0x9f].includes(code)) {
40
+ this.osc = code === 0x9d;
41
+ this.state = "string";
42
+ this.sequence = "";
43
+ continue;
44
+ }
45
+ if (code === 0x9b) {
46
+ this.state = "csi";
47
+ this.sequence = "";
48
+ continue;
49
+ }
50
+ if (code === 0x18 || code === 0x1a) {
51
+ this.state = "text";
52
+ this.sequence = "";
53
+ continue;
54
+ }
55
+ if (this.state === "escape") {
56
+ if (char === "[") {
57
+ this.state = "csi";
58
+ continue;
59
+ }
60
+ if ("]PX^_".includes(char)) {
61
+ this.osc = char === "]";
62
+ this.state = "string";
63
+ continue;
64
+ }
65
+ if (code >= 0x20 && code <= 0x2f) {
66
+ this.state = "escape-intermediate";
67
+ continue;
68
+ }
69
+ if ("78DEM=>".includes(char))
70
+ out.push(`\x1b${char}`);
71
+ this.state = "text";
72
+ continue;
73
+ }
74
+ if (this.state === "escape-intermediate") {
75
+ if (code >= 0x30 && code <= 0x7e)
76
+ this.state = "text";
77
+ continue;
78
+ }
79
+ if (this.state === "csi") {
80
+ if (code >= 0x40 && code <= 0x7e) {
81
+ if (allowedCsi(this.sequence, char))
82
+ out.push(`\x1b[${this.sequence}${char}`);
83
+ this.sequence = "";
84
+ this.state = "text";
85
+ }
86
+ else if (this.sequence.length < 256 && code >= 0x20 && code <= 0x3f) {
87
+ this.sequence += char;
88
+ }
89
+ else {
90
+ this.sequence = "!";
91
+ }
92
+ continue;
93
+ }
94
+ if ((code >= 0x20 && !(code >= 0x7f && code <= 0x9f)) || "\b\t\n\r".includes(char))
95
+ out.push(char);
96
+ }
97
+ return out.join("");
98
+ }
99
+ }
100
+ function allowedCsi(params, final) {
101
+ if (params.length > 256 || params.includes("!"))
102
+ return false;
103
+ if (final === "h" || final === "l") {
104
+ const privateMode = params.startsWith("?");
105
+ const body = privateMode ? params.slice(1) : params;
106
+ const modes = privateMode ? [1, 6, 7, 25, 47, 1000, 1002, 1003, 1004, 1005, 1006, 1047, 1048, 1049, 2004] : [4, 20];
107
+ return /^\d+(;\d+)*$/.test(body) && body.split(";").every(n => modes.includes(Number(n)));
108
+ }
109
+ if (final === "m")
110
+ return /^[\d;:]*$/.test(params);
111
+ if ("ABCDEFGHIZ`adefJKLMPSTXrsu".includes(final))
112
+ return /^[\d;]*$/.test(params);
113
+ return final === "q" && /^[0-6]? $/.test(params);
114
+ }
@@ -23,6 +23,7 @@ import { V158_ADDED_COLUMNS } from "./lead-latency-schema.js";
23
23
  import { V169_ADDED_COLUMNS } from "./task-sizing-schema.js";
24
24
  import { V170_ADDED_COLUMNS } from "./agent-said-schema.js";
25
25
  import { V172_ADDED_COLUMNS } from "./flexible-sign-in-schema.js";
26
+ import { V173_ADDED_COLUMNS } from "./plan-problems-schema.js";
26
27
  import { V159_ADDED_COLUMNS } from "./one-step-chat-schema.js";
27
28
  import { isNewer, REGISTRY } from "./releases.js";
28
29
  import { markNeverIndex } from "./never-index.js";
@@ -327,7 +328,7 @@ const HISTORY_RULES = {
327
328
  ...Object.fromEntries(Object.entries(V117_RENAMED_TABLES).map(([old, now]) => [old, { moved: { into: now, where: "1" } }])),
328
329
  ...Object.fromEntries(V117_RENAMED_COLUMNS.filter(([table]) => !Object.values(V117_RENAMED_TABLES).includes(table)).map(([table, from, to]) => [table, { renamed: { [from]: to } }])),
329
330
  ...Object.fromEntries(Object.entries(V118_MERGED_TABLES).map(([table, kind]) => [table, { moved: { into: "credential", where: `kind = '${kind}'` } }])),
330
- ...Object.fromEntries(Object.entries(addedColumns(V119_ADDED_COLUMNS, V120_ADDED_COLUMNS, V121_ADDED_COLUMNS, V122_ADDED_COLUMNS, V123_ADDED_COLUMNS, V125_ADDED_COLUMNS, V126_ADDED_COLUMNS, V128_ADDED_COLUMNS, V129_ADDED_COLUMNS, V134_ADDED_COLUMNS, V135_ADDED_COLUMNS, V138_ADDED_COLUMNS, V143_ADDED_COLUMNS, V147_ADDED_COLUMNS, V148_ADDED_COLUMNS, V150_ADDED_COLUMNS, V151_ADDED_COLUMNS, V152_ADDED_COLUMNS, V153_ADDED_COLUMNS, V158_ADDED_COLUMNS, V159_ADDED_COLUMNS, V169_ADDED_COLUMNS, V170_ADDED_COLUMNS, V172_ADDED_COLUMNS))
331
+ ...Object.fromEntries(Object.entries(addedColumns(V119_ADDED_COLUMNS, V120_ADDED_COLUMNS, V121_ADDED_COLUMNS, V122_ADDED_COLUMNS, V123_ADDED_COLUMNS, V125_ADDED_COLUMNS, V126_ADDED_COLUMNS, V128_ADDED_COLUMNS, V129_ADDED_COLUMNS, V134_ADDED_COLUMNS, V135_ADDED_COLUMNS, V138_ADDED_COLUMNS, V143_ADDED_COLUMNS, V147_ADDED_COLUMNS, V148_ADDED_COLUMNS, V150_ADDED_COLUMNS, V151_ADDED_COLUMNS, V152_ADDED_COLUMNS, V153_ADDED_COLUMNS, V158_ADDED_COLUMNS, V159_ADDED_COLUMNS, V169_ADDED_COLUMNS, V170_ADDED_COLUMNS, V172_ADDED_COLUMNS, V173_ADDED_COLUMNS))
331
332
  .map(([table, rule]) => [table, { ...EARLIER_RULES[table], ...rule }])),
332
333
  };
333
334
  export const RETIRED_TABLES = Object.freeze(Object.keys(HISTORY_RULES).filter(name => HISTORY_RULES[name].retired));
Binary file
Binary file
Binary file
Binary file
@@ -6,7 +6,7 @@ import { spawnHoldingLink } from "./engine-handoff.js";
6
6
  import { trustedBinary } from "./trusted-path.js";
7
7
  export { aclVerdictOf, trustedBinary } from "./trusted-path.js";
8
8
  import { isTuiPage } from "./tui-contract.js";
9
- export const TUI_EXIT = { leave: 0, stop: 40, keep: 41, classic: 42, unprotected: 43 };
9
+ export const TUI_EXIT = { leave: 0, ended: 1, stop: 40, keep: 41, classic: 42, unprotected: 43 };
10
10
  export const TUI_PACKAGES = Object.freeze({
11
11
  "darwin-arm64": "@toolroll/tui-darwin-arm64", "darwin-x64": "@toolroll/tui-darwin-x64",
12
12
  "linux-x64": "@toolroll/tui-linux-x64", "linux-arm64": "@toolroll/tui-linux-arm64",
@@ -278,7 +278,26 @@ export async function runTuiBinary(input) {
278
278
  return "stop";
279
279
  if (code === TUI_EXIT.keep)
280
280
  return "keep";
281
+ if (code === TUI_EXIT.ended)
282
+ return "ended";
281
283
  if (code === TUI_EXIT.classic || code === TUI_EXIT.unprotected || code === -1)
282
284
  return "classic";
283
285
  return "leave";
284
286
  }
287
+ export const REOPEN_PROMPT = "This screen was signed out. Open Toolroll again? Enter opens it · q stops Toolroll ";
288
+ export async function reopenAfterSignOut(input) {
289
+ if (!input.terminal || input.agent)
290
+ return false;
291
+ const answer = await input.ask(REOPEN_PROMPT);
292
+ return answer !== null && answer.trim() === "";
293
+ }
294
+ export async function askLineOrEof(prompt) {
295
+ const { createInterface } = await import("node:readline");
296
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
297
+ return await new Promise(resolve => {
298
+ let answered = false;
299
+ rl.once("close", () => { if (!answered)
300
+ resolve(null); });
301
+ rl.question(prompt, answer => { answered = true; rl.close(); resolve(answer); });
302
+ });
303
+ }