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.
- package/CHANGELOG.md +54 -0
- package/dist/agent-state-words.js +1 -1
- package/dist/assignment-ui.js +1 -1
- package/dist/browser/terminal.css +1 -1
- package/dist/browser/terminal.js +1 -1
- package/dist/browser/workspace.css +2 -2
- package/dist/browser/workspace.js +29 -28
- package/dist/chat-controls.js +1 -1
- package/dist/chat-quiet.js +2 -2
- package/dist/chat-voice.js +3 -3
- package/dist/check-levels.js +1 -1
- package/dist/claim.js +7 -2
- package/dist/cli.js +1 -0
- package/dist/code-map-cli.js +2 -1
- package/dist/coding-shipping-ui.js +2 -1
- package/dist/console-instance.js +21 -1
- package/dist/contracts/console-api.js +6 -2
- package/dist/contracts/engine-api.js +32 -4
- package/dist/demo-chat.js +1 -1
- package/dist/design/kit.css +3 -0
- package/dist/design/kit.js +1 -1
- package/dist/dispatch.js +19 -2
- package/dist/easy-start.js +23 -11
- package/dist/engine-reads.js +98 -7
- package/dist/export.js +16 -4
- package/dist/flexible-authority-end.js +94 -0
- package/dist/flexible-everyday-schema.js +76 -0
- package/dist/flexible-interactive-schema.js +133 -0
- package/dist/flexible-interactive.js +94 -0
- package/dist/flexible-laptop.js +38 -0
- package/dist/flexible-relay.js +9 -3
- package/dist/flexible-session.js +430 -10
- package/dist/flexible-ship.js +77 -12
- package/dist/flexible-sign-in.js +16 -1
- package/dist/flexible-start.js +17 -2
- package/dist/flexible-thread.js +1 -1
- package/dist/flexible-turns.js +9 -0
- package/dist/flexible-ui.js +3 -2
- package/dist/flexible.js +13 -0
- package/dist/flow-card-task.js +1 -1
- package/dist/home-groups.js +1 -1
- package/dist/lead-status.js +5 -3
- package/dist/lead-tools.js +1 -0
- package/dist/local-owner-acts.js +44 -1
- package/dist/local-owner.js +10 -0
- package/dist/needs-you.js +18 -6
- package/dist/operate-remote-arguments.js +1 -1
- package/dist/operate.js +250 -32
- package/dist/plan-problems-schema.js +4 -0
- package/dist/planner.js +17 -6
- package/dist/release-cli.js +2 -2
- package/dist/result-actions.js +1 -2
- package/dist/retention-ui.js +1 -1
- package/dist/scope.js +18 -7
- package/dist/server/chat.js +3 -3
- package/dist/server/console.css +15 -10
- package/dist/server/engine-api.js +161 -15
- package/dist/server/flows.js +4 -3
- package/dist/server/home.js +1 -1
- package/dist/server/kit.js +2 -2
- package/dist/server/render-chat.js +1 -1
- package/dist/server/render-pages.js +1 -1
- package/dist/server/render-tasks.js +21 -12
- package/dist/server/route-table.js +16 -0
- package/dist/server/settings-sections.js +6 -2
- package/dist/server/settings.js +22 -8
- package/dist/server/task-views.js +10 -4
- package/dist/server/tasks.js +51 -4
- package/dist/settings-kit.js +3 -3
- package/dist/skills-ui.js +3 -2
- package/dist/spend-report.js +2 -2
- package/dist/spend.js +3 -3
- package/dist/store.js +202 -7
- package/dist/subagent-admin.js +23 -10
- package/dist/subagent-backup-schema.js +36 -0
- package/dist/subagent-backup.js +92 -0
- package/dist/subagent-week.js +2 -2
- package/dist/subagent-work.js +70 -47
- package/dist/subagents-ui.js +6 -2
- package/dist/subagents.js +5 -2
- package/dist/subscription-chat.js +4 -0
- package/dist/surface.js +8 -1
- package/dist/task-status.js +13 -13
- package/dist/telegram-status.js +3 -3
- package/dist/terminal-safety.js +114 -0
- package/dist/toolroll-update.js +2 -1
- package/dist/tui/darwin-arm64/toolroll-tui +0 -0
- package/dist/tui/darwin-x64/toolroll-tui +0 -0
- package/dist/tui/linux-arm64/toolroll-tui +0 -0
- package/dist/tui/linux-x64/toolroll-tui +0 -0
- package/dist/tui-launch.js +20 -1
- package/dist/tui.js +1 -1
- package/dist/work-index.js +23 -10
- package/dist/workspace-ui.js +5 -5
- package/dist/youiyoux-intake.js +1 -1
- package/package.json +2 -2
package/dist/chat-controls.js
CHANGED
|
@@ -2,7 +2,7 @@ import { taskLinkOf } from "./task-link.js";
|
|
|
2
2
|
export const CHAT_CONTROLS = {
|
|
3
3
|
task: { label: "Open task", target: "task" },
|
|
4
4
|
approval: { label: "Review & start", target: "task" },
|
|
5
|
-
planning: { label: "
|
|
5
|
+
planning: { label: "Review plan", target: "task" },
|
|
6
6
|
recovery: { label: "Review recovery options", target: "task" },
|
|
7
7
|
cancel: { label: "Cancel task", target: "task" },
|
|
8
8
|
result: { label: "Open result", target: "task" },
|
package/dist/chat-quiet.js
CHANGED
|
@@ -184,7 +184,7 @@ export function eveningDigestText(store, account, now, root) {
|
|
|
184
184
|
catch {
|
|
185
185
|
headline = null;
|
|
186
186
|
}
|
|
187
|
-
if (headline === "Ready
|
|
187
|
+
if (headline === "Ready" || headline === "Needs you")
|
|
188
188
|
waits.set(taskId, `${title(taskId)} · ${headline}`);
|
|
189
189
|
else if (headline === "Failed")
|
|
190
190
|
failed.set(taskId, title(taskId));
|
|
@@ -192,7 +192,7 @@ export function eveningDigestText(store, account, now, root) {
|
|
|
192
192
|
if (finished.size + failed.size + waits.size === 0)
|
|
193
193
|
return null;
|
|
194
194
|
const section = (name, items) => items.size === 0 ? [] : ["", `${name} (${items.size})`, ...[...items.values()].slice(0, 12).map(one => `• ${one}`), ...(items.size > 12 ? [`• and ${items.size - 12} more`] : [])];
|
|
195
|
-
return [...section("
|
|
195
|
+
return [...section("Ready", finished), ...section("Waiting for you", waits), ...section("Failed", failed)].slice(1).join("\n");
|
|
196
196
|
}
|
|
197
197
|
export function enqueueEveningDigests(store, now, root) {
|
|
198
198
|
const day = localDay(now), time = localTime(now);
|
package/dist/chat-voice.js
CHANGED
|
@@ -32,7 +32,7 @@ export function inSentence(summary) {
|
|
|
32
32
|
}
|
|
33
33
|
export const READY_ACTIONS = { merge: "Merge", complete: "Accept", look: "Look first" };
|
|
34
34
|
export function asksToFinish(fact) {
|
|
35
|
-
return fact.update == null && fact.headline === "Ready
|
|
35
|
+
return fact.update == null && fact.headline === "Ready" && !fact.report;
|
|
36
36
|
}
|
|
37
37
|
export function finishedLine(fact) {
|
|
38
38
|
if (fact.update != null)
|
|
@@ -42,7 +42,7 @@ export function finishedLine(fact) {
|
|
|
42
42
|
if (fact.leadOnIt === true && (fact.headline === "Needs you" || fact.headline === "Waiting" || fact.headline === "Stopped"))
|
|
43
43
|
return `${name}: ${leadOnIt(fact.leadName)}`;
|
|
44
44
|
switch (fact.headline) {
|
|
45
|
-
case "Ready
|
|
45
|
+
case "Ready":
|
|
46
46
|
if (fact.report)
|
|
47
47
|
return fact.lead === true ? `I wrote up ${lower}. The report is ready to read.` : `${name}: the report is ready to read.`;
|
|
48
48
|
if (fact.checks === "passed")
|
|
@@ -77,7 +77,7 @@ function phraseOf(fact) {
|
|
|
77
77
|
if (fact.update != null)
|
|
78
78
|
return `${name} ${fact.update.phrase}`;
|
|
79
79
|
switch (fact.headline) {
|
|
80
|
-
case "Ready
|
|
80
|
+
case "Ready": return `${name} is ready`;
|
|
81
81
|
case "Failed": return `${name} failed`;
|
|
82
82
|
case "Complete": return `${name} is done`;
|
|
83
83
|
case "Needs you": return `${name} needs you`;
|
package/dist/check-levels.js
CHANGED
|
@@ -7,7 +7,7 @@ export const CHECK_LEVEL_WORDS = { quick: "Quick", full: "Full", off: "Off" };
|
|
|
7
7
|
export const CHECK_LEVEL_HINTS = {
|
|
8
8
|
quick: "A fast check while building: typecheck and the tests near the change.",
|
|
9
9
|
full: "The project's full check after every build.",
|
|
10
|
-
off: "No check. Results are Ready
|
|
10
|
+
off: "No check. Results are Ready, and say no check ran.",
|
|
11
11
|
};
|
|
12
12
|
export const PROJECT_LEVEL_ACTION = "check level changed";
|
|
13
13
|
export const TASK_LEVEL_ACTION = "task checks chosen";
|
package/dist/claim.js
CHANGED
|
@@ -4,7 +4,7 @@ import { RUN_REASON_WORDS } from "./needs-you.js";
|
|
|
4
4
|
import { authenticate, drainOf } from "./runner.js";
|
|
5
5
|
import { pauseForAuth } from "./provider-auth.js";
|
|
6
6
|
import { DEFAULT_MAX_OPEN_DECISIONS, missingCapability, scopeApprovedForDispatch, taskReadinessBlocker, } from "./dispatch.js";
|
|
7
|
-
import { BUILT_IN, checkCleanupTaskOf, isClosedState, refArchived, taskStateForClaim, } from "./store.js";
|
|
7
|
+
import { BUILT_IN, checkCleanupTaskOf, isClosedState, recordAgentSaid, recordPlanProblems, refArchived, taskStateForClaim, } from "./store.js";
|
|
8
8
|
import { digestOf } from "./scope.js";
|
|
9
9
|
import { parseExecutionPlanDocument } from "./plan.js";
|
|
10
10
|
import { sealUnchangedPlanUnderMode } from "./plan-auto.js";
|
|
@@ -859,7 +859,12 @@ function sealPlanFailure(store, leaseId, args) {
|
|
|
859
859
|
if (kind === "failure" && run.terminalClass === "auth-expired")
|
|
860
860
|
return { ok: true, ...sealAuthExpired(store, run, taskId, now) };
|
|
861
861
|
const malformedKind = args.malformed === "decision" ? "malformed-decision" : "malformed-plan";
|
|
862
|
-
|
|
862
|
+
const code = args.code === "agent" ? "agent-error" : args.code === "timeout" || args.code === "provider-init" ? args.code : null;
|
|
863
|
+
store.finishRun(runId, { outcome: "failed", reason: kind === "malformed" ? malformedKind : code ?? oneLine(message, 120), now });
|
|
864
|
+
if (kind === "malformed" && args.problems !== undefined)
|
|
865
|
+
recordPlanProblems(store, runId, args.problems);
|
|
866
|
+
if (args.agentSaid !== undefined)
|
|
867
|
+
recordAgentSaid(store, runId, args.agentSaid);
|
|
863
868
|
if (kind === "malformed") {
|
|
864
869
|
if (message.trim() !== "")
|
|
865
870
|
store.recordOutcomeFacts(runId, { handoff: message });
|
package/dist/cli.js
CHANGED
package/dist/code-map-cli.js
CHANGED
|
@@ -5,6 +5,7 @@ import { codeMapReport, NOT_ENOUGH, reportRows } from "./code-map-report.js";
|
|
|
5
5
|
import { requestRefresh } from "./code-map-store.js";
|
|
6
6
|
import { canonicalProject } from "./project.js";
|
|
7
7
|
import { envelopeJson } from "./envelope.js";
|
|
8
|
+
import { plural } from "./design/kit.js";
|
|
8
9
|
const jsonFlag = { name: "json", takesValue: false, meaning: "answer with one machine envelope on stdout" };
|
|
9
10
|
const repoFlag = { name: "repo", takesValue: true, meaning: "which project" };
|
|
10
11
|
const pageFlags = [jsonFlag, repoFlag, { name: "cursor", takesValue: true, meaning: "the next page, from the answer before it" }];
|
|
@@ -86,7 +87,7 @@ export async function runMapCommand(positional, options, context) {
|
|
|
86
87
|
return ok({ map: answer, state: status.state }, []);
|
|
87
88
|
const opened = openMap(store, wanted, answer.version);
|
|
88
89
|
const rows = opened.ok ? areaRows(opened.map) : [];
|
|
89
|
-
return ok({}, [`Code map · main at ${answer.commit.slice(0, 7)} · ${status.words}`, answer.label, "", ...rows.slice(0, 60).map(one => printable(`${one.id} · ${one.files
|
|
90
|
+
return ok({}, [`Code map · main at ${answer.commit.slice(0, 7)} · ${status.words}`, answer.label, "", ...rows.slice(0, 60).map(one => printable(`${one.id} · ${plural(one.files, "file", "files")} · ${one.languages.join(", ") || "no code"}${one.uses.length === 0 ? "" : ` · uses ${one.uses.slice(0, 3).map(use => use.id).join(", ")}`}`)), ...(rows.length > 60 ? [`${rows.length - 60} more: use --json with --cursor.`] : [])]);
|
|
90
91
|
}
|
|
91
92
|
const view = action;
|
|
92
93
|
const query = positional.slice(1).join(" ");
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { html, postForm } from './html.js';
|
|
2
|
+
import { plural } from "./design/kit.js";
|
|
2
3
|
export function codingShippingHtml(preview, values, error) {
|
|
3
4
|
const goal = values?.get('goal') ?? preview.title;
|
|
4
5
|
const criteria = values?.get('acceptance') ?? '';
|
|
5
6
|
const notice = error?.startsWith('Review screenshots are not ready.')
|
|
6
7
|
? html `<p class="coding-notice" role="alert">Screenshots needed. Ask Codex to capture and commit them, then try again.</p><details><summary>Technical details</summary><p>${error}</p></details>`
|
|
7
8
|
: error ? html `<p class="coding-notice" role="alert">${error}</p>` : '';
|
|
8
|
-
const form = postForm(`/code/${preview.sessionId}/ship`, html `<label>Outcome<textarea name="goal" rows="4" required maxlength="16000">${goal}</textarea></label><label>Checks for review<textarea name="acceptance" rows="4" required maxlength="16000" placeholder="One observable result per line">${criteria}</textarea></label><label class="coding-check"><input type="checkbox" name="visual" value="yes"${values?.get('visual') === 'yes' ? html ` checked` : ''}>Include desktop and phone screenshots</label><details><summary>${preview.changedPaths.length
|
|
9
|
+
const form = postForm(`/code/${preview.sessionId}/ship`, html `<label>Outcome<textarea name="goal" rows="4" required maxlength="16000">${goal}</textarea></label><label>Checks for review<textarea name="acceptance" rows="4" required maxlength="16000" placeholder="One observable result per line">${criteria}</textarea></label><label class="coding-check"><input type="checkbox" name="visual" value="yes"${values?.get('visual') === 'yes' ? html ` checked` : ''}>Include desktop and phone screenshots</label><details><summary>${plural(preview.changedPaths.length, "changed file", "changed files")} · commit ${preview.candidate.slice(0, 8)}</summary><ul>${preview.changedPaths.map(path => html `<li><code>${path}</code></li>`)}</ul><p class="coding-meta">Review covers the complete change from ${preview.base} to ${preview.candidate}.</p></details><p class="coding-terms">Verification and publication use this project’s existing approval process.</p><button type="submit">Create review task</button>`, { attrs: { class: 'coding-start' }, hidden: { base: preview.base, candidate: preview.candidate, title: preview.title } });
|
|
9
10
|
return html `<section class="coding-workspace coding-handoff" data-coding-session=""><h1>Review for shipping</h1><p>${preview.title}</p>${notice}${form}<p><a href="/code/${preview.sessionId}">Back to coding</a></p></section>`;
|
|
10
11
|
}
|
|
11
12
|
export const CODING_SHIPPING_CSS = `.coding-workspace.coding-handoff{display:block;max-width:780px}.coding-handoff h1{margin-bottom:12px}.coding-handoff>p{margin-top:12px}.coding-workspace .coding-check{display:flex;align-items:center;gap:10px;min-height:44px}.coding-workspace .coding-check input{width:20px;height:20px;flex:0 0 20px}`;
|
package/dist/console-instance.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
|
|
2
2
|
import { lstatSync, mkdirSync, realpathSync } from "node:fs";
|
|
3
3
|
import { createConnection, createServer } from "node:net";
|
|
4
|
+
import { homedir, userInfo } from "node:os";
|
|
4
5
|
import { basename, dirname, join } from "node:path";
|
|
5
6
|
export const CONSOLE_INSTANCE_SCHEMA = `
|
|
6
7
|
CREATE TABLE IF NOT EXISTS console_instance (
|
|
@@ -107,7 +108,26 @@ export function instanceSocketTooLong(databaseFile) {
|
|
|
107
108
|
if (needs <= SOCKET_PATH_MAX)
|
|
108
109
|
return null;
|
|
109
110
|
const folderMax = SOCKET_PATH_MAX - Buffer.byteLength(`/${INSTANCE_DIR}/0123456789abcdef.sock`);
|
|
110
|
-
return `the database's folder is too deep for Toolroll's socket (${needs} of at most ${SOCKET_PATH_MAX} bytes)
|
|
111
|
+
return `the database's folder is too deep for Toolroll's socket (${needs} of at most ${SOCKET_PATH_MAX} bytes). Put it in a short folder only you can write (at most ${folderMax} bytes long), for example: ${shortFolderSuggestion(folderMax)}`;
|
|
112
|
+
}
|
|
113
|
+
function shortFolderSuggestion(folderMax) {
|
|
114
|
+
let home = homedir();
|
|
115
|
+
try {
|
|
116
|
+
home = realpathSync(home);
|
|
117
|
+
}
|
|
118
|
+
catch { }
|
|
119
|
+
if (home !== "" && Buffer.byteLength(join(home, ".tr")) <= folderMax) {
|
|
120
|
+
return "`mkdir -m 700 ~/.tr`, then run `TOOLROLL_DB=~/.tr/orders.db toolroll`";
|
|
121
|
+
}
|
|
122
|
+
let name = "you";
|
|
123
|
+
try {
|
|
124
|
+
const user = userInfo().username;
|
|
125
|
+
if (/^[A-Za-z_][A-Za-z0-9_.-]{0,31}$/.test(user))
|
|
126
|
+
name = user;
|
|
127
|
+
}
|
|
128
|
+
catch { }
|
|
129
|
+
const folder = `/opt/toolroll-${name}`;
|
|
130
|
+
return `\`sudo mkdir -m 700 ${folder} && sudo chown ${name} ${folder}\`, then run \`TOOLROLL_DB=${folder}/orders.db toolroll\``;
|
|
111
131
|
}
|
|
112
132
|
export function socketPathProblem(path) {
|
|
113
133
|
if (!SOCKET_NAME.test(basename(path)))
|
|
@@ -59,13 +59,17 @@ export const CONSOLE_FORMS = {
|
|
|
59
59
|
projectFlexible: formContract("POST /settings/project/flexible", ["repo", "action", "max", "digest", "password"]),
|
|
60
60
|
threadAnswer: formContract("POST /agents/live/thread/<id>/answer", ["request", "card", "decision", "question", "answer"]),
|
|
61
61
|
threadStart: formContract("POST /agents/live/thread", ["repo", "message", "model", "terms", "password", "agent"]),
|
|
62
|
+
threadTurn: formContract("POST /agents/live/thread/<id>/turn", ["message", "key", "password"]),
|
|
63
|
+
threadShip: formContract("POST /agents/live/thread/<id>/ship", ["terms", "digest"]),
|
|
64
|
+
threadSendBack: formContract("POST /agents/live/thread/<id>/ship/send-back", ["feedback", "key", "password"]),
|
|
65
|
+
threadClose: formContract("POST /agents/live/thread/<id>/stop, /agents/live/thread/<id>/end, /agents/live/thread/<id>/ship/cancel", []),
|
|
62
66
|
term: formContract("POST /term/start, /term/<terminal>/close, /term/<terminal>/remove", ["repo", "program", "password", "task", "run"]),
|
|
63
67
|
termAgent: formContract("POST /term/agent/sign-in, /term/agent/install", ["agent", "password", "confirm"]),
|
|
64
68
|
agentsCheck: formContract("POST /engine/agents/check", []),
|
|
65
69
|
skillsRevise: formContract("POST /settings/skills/revise", ["run", "repo", "feedback", "nonce"]),
|
|
66
70
|
skillsChange: formContract("POST /settings/skills/import, /settings/skills/change", ["repo", "identity", "revision", "method", "content", "files", "url", "action", "sha", "sample", "nonce", "restore"]),
|
|
67
71
|
kit: formContract("POST /kits/<kit>/<act>", ["repo", "password"]),
|
|
68
|
-
subagents: formContract("POST /settings/lead/subagents/new, /settings/lead/subagents/<id>/<part>, /settings/lead/subagents/questions/<id>/answer", ["choice", "text", "repo", "template", "name", "soul", "op", "id", "schedule", "tool", "state", "note", "model", "dailyTurns", "manager", "password"], { prefixes: ["use.", "undo.", "field.", "over."] }),
|
|
72
|
+
subagents: formContract("POST /settings/lead/subagents/new, /settings/lead/subagents/<id>/<part>, /settings/lead/subagents/questions/<id>/answer", ["choice", "text", "repo", "template", "name", "soul", "op", "id", "schedule", "tool", "state", "note", "model", "dailyTurns", "manager", "password", "backupPresent", "codexBackupModel"], { prefixes: ["use.", "undo.", "field.", "over."] }),
|
|
69
73
|
galleryUse: formContract("POST /flows/new/<template>", ["repo", "send-result", "name", "intent", "previewed", "password"], { dynamic: true }),
|
|
70
74
|
flows: formContract("POST /flows/new, /flows/example, /flows/import, /flows/<id>/<act>, /flows/<id>/cards/<card>/<act>, /flows/<id>/triggers/<trigger>/<act>", ["repo", "document", "url", "confirm", "previewed", "template", "name", "answers", "password", "secret", "sender", "project", "team", "trigger", "approve", "remove", "about", "body", "timeoutMinutes", "language", "file", "address", "key", "definition", "owner", "revision", "value", "title", "description", "stage", "decision", "note", "draft", "choice", "entry", "label", "watching", "days", "budget", "runs", "include", "schedules", "digest", "version"], { prefixes: ["param."] }),
|
|
71
75
|
spendBudget: formContract("POST /spend/budget", ["password", "target", "action", "usd", "stop"]),
|
|
@@ -191,7 +195,7 @@ export const CONSOLE_FORMS = {
|
|
|
191
195
|
taskNext: formContract("POST /t/<task>/next", ["undo"]),
|
|
192
196
|
taskReopen: formContract("POST /t/<task>/reopen", ["token"]),
|
|
193
197
|
taskRequeue: formContract("POST /t/<task>/requeue", ["context", "note", "return", "run", "digest"]),
|
|
194
|
-
taskPlan: formContract("POST /t/<task>/plan", ["source"]),
|
|
198
|
+
taskPlan: formContract("POST /t/<task>/plan", ["source", "incident"]),
|
|
195
199
|
taskFollowUp: formContract("POST /t/<task>/follow-up", ["index"]),
|
|
196
200
|
taskPlanEdit: formContract("POST /t/<task>/plan-edit", ["saw-plan", "plan-document"]),
|
|
197
201
|
taskRevision: formContract("POST /t/<task>/accept-revision|reject-revision", ["revision-id", "token"]),
|
|
@@ -35,14 +35,31 @@ const threadQuestionSchema = z.object({
|
|
|
35
35
|
answerable: z.boolean(),
|
|
36
36
|
parts: z.array(z.object({ id: z.string(), question: z.string(), options: z.array(z.string()) })),
|
|
37
37
|
});
|
|
38
|
+
export const threadTerminalSchema = z.strictObject({
|
|
39
|
+
available: z.boolean(),
|
|
40
|
+
launch: hex32,
|
|
41
|
+
generation: z.number().int().positive(),
|
|
42
|
+
lifecycle: z.enum(["starting", "live", "stopping", "exited", "unresolved"]),
|
|
43
|
+
viewing: z.enum(["detached", "viewing"]),
|
|
44
|
+
control: z.enum(["none", "self", "other"]),
|
|
45
|
+
protocol: z.literal(1),
|
|
46
|
+
cols: z.number().int().min(2).max(500),
|
|
47
|
+
rows: z.number().int().min(2).max(500),
|
|
48
|
+
});
|
|
38
49
|
export const threadFactsSchema = z.object({
|
|
39
50
|
version: z.string().regex(/^[0-9a-f]{16}$/),
|
|
40
51
|
title: z.string(),
|
|
41
52
|
project: z.string().nullable(),
|
|
42
53
|
level: flexibleLevelSchema.nullable(),
|
|
43
54
|
agent: z.object({ provider: z.string(), model: z.string() }).nullable(),
|
|
44
|
-
turn: z.object({ seq: z.number().int(), status: z.string(), costUsd: z.number().nullable(), costBasis: z.enum(["measured", "estimated", "unknown"]).nullable()
|
|
55
|
+
turn: z.object({ seq: z.number().int(), status: z.string(), costUsd: z.number().nullable(), costBasis: z.enum(["measured", "estimated", "unknown"]).nullable(),
|
|
56
|
+
endWords: z.string().optional(),
|
|
57
|
+
billing: z.enum(["subscription", "api-key"]).optional() }).nullable(),
|
|
45
58
|
questions: z.array(threadQuestionSchema),
|
|
59
|
+
runtime: z.enum(["stream-json", "interactive"]).optional(),
|
|
60
|
+
terminal: threadTerminalSchema.optional(),
|
|
61
|
+
ended: z.object({ words: z.string(), stopPending: z.boolean() }).optional(),
|
|
62
|
+
ship: z.object({ seq: z.number().int(), state: z.string(), words: z.string() }).optional(),
|
|
46
63
|
});
|
|
47
64
|
export const liveSessionWindowSchema = z.object({
|
|
48
65
|
version,
|
|
@@ -61,7 +78,11 @@ export const liveThreadsSchema = z.object({
|
|
|
61
78
|
version,
|
|
62
79
|
on: z.boolean().optional(),
|
|
63
80
|
threads: z.array(z.object({ id: hex32, title: z.string(), project: z.string().nullable(), level: flexibleLevelSchema.nullable(), live: z.boolean(), waiting: z.number().int(),
|
|
64
|
-
costUsd: z.number().nullable()
|
|
81
|
+
costUsd: z.number().nullable(),
|
|
82
|
+
turn: z.string().nullable(), ended: z.boolean(), stopPending: z.boolean(),
|
|
83
|
+
ship: z.string().nullable(),
|
|
84
|
+
turnSeq: z.number().int().nullable(),
|
|
85
|
+
shipSeq: z.number().int().nullable() })),
|
|
65
86
|
});
|
|
66
87
|
const workAskSchema = z.enum(["release", "approve", "answer", "flow", "wrong", "review", "setup", "other"]);
|
|
67
88
|
const needRowSchema = z.object({
|
|
@@ -74,7 +95,8 @@ const needRowSchema = z.object({
|
|
|
74
95
|
question: z.object({ id: z.number().int(), text: z.string(), recap: z.string(),
|
|
75
96
|
options: z.array(z.object({ id: z.string(), label: z.string(), consequence: z.string(), recommended: z.boolean() })) }).nullable(),
|
|
76
97
|
});
|
|
77
|
-
export const waitingSchema = z.object({ retryAt: iso.nullable(), lastFailure: z.string().nullable()
|
|
98
|
+
export const waitingSchema = z.object({ retryAt: iso.nullable(), lastFailure: z.string().nullable(),
|
|
99
|
+
attempt: z.enum(["build", "plan"]) });
|
|
78
100
|
export const WORK_ROW_GROUPS = ["decide", "review", "unblock", "building", "rest"];
|
|
79
101
|
export const WORK_STATUS_TONES = ["attention", "problem", "live", "ready", "done", "muted", "neutral"];
|
|
80
102
|
export const WORK_WORD_TONES = ["", "needs", "ask", "live", "done", "failed"];
|
|
@@ -143,6 +165,11 @@ export const stepCardsSchema = z.object({
|
|
|
143
165
|
waiting: waitingSchema.extend({ agentSaid: z.array(z.string()).max(8).nullable() }).nullable(),
|
|
144
166
|
held: z.object({ id: z.number().int(), reason: z.string(), lastFailure: z.string().nullable() }).nullable(),
|
|
145
167
|
retry: z.object({ run: z.number().int(), digest: z.string() }).nullable(),
|
|
168
|
+
planStopped: z.object({ incident: z.number().int(), kind: z.enum(["plan", "question", "stalled"]), line: z.string(),
|
|
169
|
+
problems: z.array(z.string()).max(8).nullable(), agentSaid: z.array(z.string()).max(8).nullable(),
|
|
170
|
+
again: z.object({ source: z.string().regex(/^[0-9a-f]{64}$/) }).nullable() }).nullable(),
|
|
171
|
+
plan: z.object({ source: z.string().regex(/^[0-9a-f]{64}$/) }).nullable(),
|
|
172
|
+
planQueued: z.boolean(),
|
|
146
173
|
approval: z.object({ by: z.string(), you: z.boolean(), automatic: z.boolean() }).nullable(),
|
|
147
174
|
room: z.string(),
|
|
148
175
|
});
|
|
@@ -172,7 +199,8 @@ export const resultDiffFileSchema = z.object({
|
|
|
172
199
|
task: z.string(),
|
|
173
200
|
run: z.number().int(),
|
|
174
201
|
file: z.object({ file: z.number().int(), path: z.string(), oldPath: z.string().nullable(), meta: z.array(z.string()),
|
|
175
|
-
hunks: z.array(z.object({ header: z.string(), lines: z.array(diffLineSchema) }))
|
|
202
|
+
hunks: z.array(z.object({ header: z.string(), lines: z.array(diffLineSchema) })),
|
|
203
|
+
lineCount: z.number().int().nonnegative().nullable() }),
|
|
176
204
|
linesTruncated: z.boolean(),
|
|
177
205
|
});
|
|
178
206
|
export const DIFF_CONTEXT_MAX = 100;
|
package/dist/demo-chat.js
CHANGED
|
@@ -35,7 +35,7 @@ function resultCard(exchange, result) {
|
|
|
35
35
|
const passed = result.checks.status === "passed";
|
|
36
36
|
const headline = headlineOf({ stage: exchange.state === "complete" ? "complete" : exchange.state === "sent-back" ? "building" : "finished",
|
|
37
37
|
checks: { status: passed ? "passed" : "failed", exitCode: null, head: null } });
|
|
38
|
-
const status = html `<span class="badge${headline === "Complete" ? " demo-complete" : headline === "Ready
|
|
38
|
+
const status = html `<span class="badge${headline === "Complete" ? " demo-complete" : headline === "Ready" ? " demo-ready" : ""}" data-headline="${headline}">${headline}</span>`;
|
|
39
39
|
const summary = html `${result.files} file${result.files === 1 ? "" : "s"} changed · +${result.additions} −${result.deletions} · <span class="${passed ? "demo-pass" : "demo-fail"}">${result.checks.detail}</span>`;
|
|
40
40
|
const actions = exchange.state === "ready"
|
|
41
41
|
? html `<div class="demo-actions">${postForm(`/chat/demo/${exchange.id}/complete`, html `<button type="submit" class="demo-primary">Complete</button>`)}<details class="demo-more"><summary>Request changes</summary>${postForm(`/chat/demo/${exchange.id}/revise`, html `<label for="demo-revise-${exchange.id}">What should change?</label><textarea id="demo-revise-${exchange.id}" name="note" rows="2" maxlength="500" required></textarea><button type="submit">Send back</button>`)}</details></div>`
|
package/dist/design/kit.css
CHANGED
|
@@ -484,6 +484,8 @@ html:not(.k-js) .k-composer:focus-within, html.k-kbd .k-composer:focus-within {
|
|
|
484
484
|
.k-crow-i .k-wd { width: 9px; height: 9px; border-radius: 50%; background: var(--so-needs); }
|
|
485
485
|
.k-crow-i svg { width: 14px; height: 14px; }
|
|
486
486
|
.k-crow.ok .k-crow-i { color: var(--so-success); }
|
|
487
|
+
.k-crow.history .k-crow-w { overflow-wrap: anywhere; }
|
|
488
|
+
.k-crow.history .k-crow-i { color: var(--so-muted); }
|
|
487
489
|
.k-crow.bad .k-crow-i { color: var(--so-danger); }
|
|
488
490
|
.k-crow-n { min-width: 0; white-space: normal; line-height: 1.3; }
|
|
489
491
|
.k-crow-n .k-crow-sub { display: block; font-size: 11.5px; color: var(--so-muted); font-weight: 400; }
|
|
@@ -496,6 +498,7 @@ html:not(.k-js) .k-composer:focus-within, html.k-kbd .k-composer:focus-within {
|
|
|
496
498
|
.k-crow-bar { position: absolute; top: 4px; height: 6px; border-radius: 3px; background: var(--so-info); min-width: 3px; transition: width var(--m-base) linear, background-color var(--m-slow) var(--m-ease); }
|
|
497
499
|
.k-crow.ok .k-crow-bar { background: var(--so-success); }
|
|
498
500
|
.k-crow.bad .k-crow-bar { background: var(--so-danger); }
|
|
501
|
+
.k-crow.waiting .k-crow-bar, .k-crow.history .k-crow-bar { background: var(--so-muted); }
|
|
499
502
|
.k-crow.wait .k-crow-bar { background: var(--so-needs); }
|
|
500
503
|
.k-crow-s { text-align: right; color: var(--so-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
|
|
501
504
|
|
package/dist/design/kit.js
CHANGED
|
@@ -76,7 +76,7 @@ export function dur(seconds) {
|
|
|
76
76
|
return `${Math.floor(n / 3600)}h ${String(Math.floor((n % 3600) / 60)).padStart(2, "0")}m`;
|
|
77
77
|
}
|
|
78
78
|
export const plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
|
|
79
|
-
export const TIMING_WORDS = { ok: "Done", run: "Now", q: "Queued", bad: "Failed", wait: "Needs you" };
|
|
79
|
+
export const TIMING_WORDS = { ok: "Done", run: "Now", q: "Queued", bad: "Failed", wait: "Needs you", waiting: "Waiting", history: "Stopped earlier; went on" };
|
|
80
80
|
export function timingBars(rows, scale) {
|
|
81
81
|
const sc = scale ?? Math.max(1, ...rows.map(row => row.start + (row.st === "q" ? 0 : row.dur))) * 1.02;
|
|
82
82
|
return rows.map(row => row.st === "q" ? null : { left: (Math.max(0, row.start) / sc) * 100, width: (Math.max(row.dur, sc / 400) / sc) * 100 });
|
package/dist/dispatch.js
CHANGED
|
@@ -14,7 +14,7 @@ import { buildReviewOf } from "./review-switch.js";
|
|
|
14
14
|
import { vanishedStopOf, vanishedStopSentence } from "./vanished-retry.js";
|
|
15
15
|
import { routeChangeOf } from "./route-change.js";
|
|
16
16
|
import { wasInterrupted } from "./run-ending.js";
|
|
17
|
-
import { BUILT_IN, refArchived, parseCapabilityKey } from "./store.js";
|
|
17
|
+
import { BUILT_IN, PLANNER_INCIDENT_KINDS, refArchived, parseCapabilityKey } from "./store.js";
|
|
18
18
|
import { shortWhen, viewerZone } from "./when-html.js";
|
|
19
19
|
export const DEFAULT_MAX_OPEN_DECISIONS = 5;
|
|
20
20
|
export function taskReadinessBlocker(store, taskRef, now) {
|
|
@@ -33,7 +33,7 @@ export function taskReadinessBlocker(store, taskRef, now) {
|
|
|
33
33
|
if (state !== "queued")
|
|
34
34
|
return { code: "state", state, message: `state is ${state}, not queued` };
|
|
35
35
|
const hold = db
|
|
36
|
-
.prepare(`SELECT owner_kind, until, reason FROM hold
|
|
36
|
+
.prepare(`SELECT owner_kind, owner_id, until, reason FROM hold
|
|
37
37
|
WHERE task_ref = ? AND (until IS NULL OR until > ?)
|
|
38
38
|
ORDER BY owner_kind = 'backoff', held_at, id LIMIT 1`)
|
|
39
39
|
.get(taskRef, stamp);
|
|
@@ -41,6 +41,7 @@ export function taskReadinessBlocker(store, taskRef, now) {
|
|
|
41
41
|
return {
|
|
42
42
|
code: "hold",
|
|
43
43
|
ownerKind: String(hold["owner_kind"]),
|
|
44
|
+
ownerId: String(hold["owner_id"] ?? ""),
|
|
44
45
|
until: hold["until"] === null || hold["until"] === undefined ? null : String(hold["until"]),
|
|
45
46
|
message: `held: ${String(hold["reason"])}`,
|
|
46
47
|
};
|
|
@@ -225,6 +226,9 @@ export function diagnoseTaskDispatch(store, taskId, now, readableRepos = null) {
|
|
|
225
226
|
const when = local.until === null ? "" : ` It tries again on its own ${retryWhenWords(local.until, now)}.`;
|
|
226
227
|
return answer("storage-blocked", "waiting", "Needs macOS permission", `${local.message.slice(`held: ${STORAGE_HOLD_PREFIX}`.length)}${when}`, { action: "unhold", nextAt: local.until });
|
|
227
228
|
}
|
|
229
|
+
if (local.ownerKind === "backoff" && (local.ownerId ?? "").startsWith("plan:")) {
|
|
230
|
+
return answer("plan-retry", "retrying", "Retry scheduled", local.until === null ? "The plan is tried again soon." : `The plan is tried again ${retryWhenWords(local.until, now)}.`, { nextAt: local.until });
|
|
231
|
+
}
|
|
228
232
|
if (local.ownerKind === "backoff") {
|
|
229
233
|
const last = store.runsFor(ref.id).find(one => one.role === "builder" && one.finishedAt !== null);
|
|
230
234
|
const when = local.until === null ? "" : ` It tries again ${retryWhenWords(local.until, now)}.`;
|
|
@@ -234,6 +238,11 @@ export function diagnoseTaskDispatch(store, taskId, now, readableRepos = null) {
|
|
|
234
238
|
}
|
|
235
239
|
if (local.ownerKind === "decision")
|
|
236
240
|
return answer("waiting-decision", "waiting", "Waiting on your answer", "An agent parked a question; answering it resumes the task.", { action: "answer-decision" });
|
|
241
|
+
const planning = local.ownerKind === "incident" ? plannerIncident(store, local.ownerId) : null;
|
|
242
|
+
if (planning === "stalled")
|
|
243
|
+
return answer("planning-stopped", "waiting", "Planning stopped", "Planning stopped after repeated failures. Plan again, or edit the task.");
|
|
244
|
+
if (planning === "invalid")
|
|
245
|
+
return answer("plan-stopped", "waiting", "Plan didn't pass", "The plan didn't pass its checks. Plan again, or edit the task.");
|
|
237
246
|
if (local.ownerKind === "incident")
|
|
238
247
|
return answer("waiting-incident", "waiting", "Needs a retry", "The last attempts failed the same way. Retry, or change the plan.", { action: "retry-task" });
|
|
239
248
|
if (local.ownerKind === "stop")
|
|
@@ -384,3 +393,11 @@ export function resetWhenWords(at, now, zone = viewerZone()) {
|
|
|
384
393
|
return "now";
|
|
385
394
|
return `on ${words}`;
|
|
386
395
|
}
|
|
396
|
+
function plannerIncident(store, ownerId) {
|
|
397
|
+
if (ownerId === undefined || !/^[1-9][0-9]*$/.test(ownerId))
|
|
398
|
+
return null;
|
|
399
|
+
const row = store.handle.prepare("SELECT incident.kind, run.role FROM incident JOIN run ON run.id = incident.run WHERE incident.id = ?").get(Number(ownerId));
|
|
400
|
+
if (row === undefined || row["role"] !== "planner" || !PLANNER_INCIDENT_KINDS.has(String(row["kind"])))
|
|
401
|
+
return null;
|
|
402
|
+
return row["kind"] === "plan-attempts-exhausted" ? "stalled" : "invalid";
|
|
403
|
+
}
|
package/dist/easy-start.js
CHANGED
|
@@ -314,22 +314,34 @@ export function defaultEasyStartSeams(options) {
|
|
|
314
314
|
if (choice.notice !== undefined)
|
|
315
315
|
options.write(`${choice.notice}.`);
|
|
316
316
|
let why = choice.ok ? null : choice.why;
|
|
317
|
-
|
|
317
|
+
for (let opened = 0; choice.ok && opened < 5; opened++) {
|
|
318
318
|
const reader = openStoreReadOnly(file);
|
|
319
319
|
const link = reader === null ? { ok: false, message: "Toolroll's database can't be read" }
|
|
320
320
|
: await requestLocalLink(file, reader, options.build).finally(() => reader.close());
|
|
321
|
-
if (!link.ok)
|
|
321
|
+
if (!link.ok) {
|
|
322
|
+
if (opened > 0) {
|
|
323
|
+
options.write("Toolroll can't sign this screen in again here. Sign in with your password in the browser.");
|
|
324
|
+
return "leave";
|
|
325
|
+
}
|
|
322
326
|
why = `the terminal workbench couldn't sign in (${link.message})`;
|
|
323
|
-
|
|
324
|
-
const { checkoutTop } = await import("./teardown-git.js");
|
|
325
|
-
const end = await runTuiBinary({ binary: choice.binary, identity: choice.identity, link: link.url, session, project: checkoutTop(cwd), cwd });
|
|
326
|
-
if (end === "changed")
|
|
327
|
-
why = "the terminal workbench changed after it was checked";
|
|
328
|
-
else if (end !== "classic")
|
|
329
|
-
return end;
|
|
330
|
-
else
|
|
331
|
-
why = null;
|
|
327
|
+
break;
|
|
332
328
|
}
|
|
329
|
+
const { checkoutTop } = await import("./teardown-git.js");
|
|
330
|
+
const end = await runTuiBinary({ binary: choice.binary, identity: choice.identity, link: link.url, session, project: checkoutTop(cwd), cwd });
|
|
331
|
+
if (end === "ended") {
|
|
332
|
+
const { askLineOrEof, reopenAfterSignOut } = await import("./tui-launch.js");
|
|
333
|
+
const terminal = process.stdin.isTTY === true && process.stdout.isTTY === true;
|
|
334
|
+
if (opened < 4 && await reopenAfterSignOut({ terminal, agent: underAgent(process.env), ask: askLineOrEof }))
|
|
335
|
+
continue;
|
|
336
|
+
return "leave";
|
|
337
|
+
}
|
|
338
|
+
if (end === "changed")
|
|
339
|
+
why = "the terminal workbench changed after it was checked";
|
|
340
|
+
else if (end !== "classic")
|
|
341
|
+
return end;
|
|
342
|
+
else
|
|
343
|
+
why = null;
|
|
344
|
+
break;
|
|
333
345
|
}
|
|
334
346
|
if (why !== null)
|
|
335
347
|
options.write(`Opening the classic screen: ${why}.`);
|
package/dist/engine-reads.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { agentSaidOf } from "./store.js";
|
|
1
|
+
import { agentSaidOf, planProblemsOf } from "./store.js";
|
|
2
2
|
import { failedAttemptSentence, latestFinishedAttempt, stopSuggestionOf } from "./needs-you.js";
|
|
3
|
-
import { retryPinsOf } from "./local-owner-acts.js";
|
|
3
|
+
import { planSourceOf, retryPinsOf } from "./local-owner-acts.js";
|
|
4
4
|
import { assignmentOf, owedAcceptance, personCompletionRefusal } from "./assignment.js";
|
|
5
5
|
import { assignmentCardOf } from "./assignment-ui.js";
|
|
6
6
|
import { assignmentStageOf, stageOfCode } from "./task-status.js";
|
|
@@ -55,7 +55,7 @@ export function stepCardsOf({ store, family, now, access, evidenceRoot, viewer =
|
|
|
55
55
|
const rows = stepRowsOf(facts);
|
|
56
56
|
const builds = runs.filter(run => run.role === "builder" || run.role === "scout" || run.role === "repair");
|
|
57
57
|
const reviews = runs.filter(run => run.role === "reviewer");
|
|
58
|
-
const behind = { plan: plannerRuns, approve: [], build: builds, checks: [], review: reviews, ready: [] };
|
|
58
|
+
const behind = { plan: plannerRuns.filter(run => run.parentRun === null), approve: [], build: builds, checks: [], review: reviews, ready: [] };
|
|
59
59
|
const terms = scope === null || approved ? null : (() => {
|
|
60
60
|
const summary = approvalSummaryOf(scope, summaryContextOf(store, current.id, scope, now));
|
|
61
61
|
return { key: summary.key, revision: summary.revision,
|
|
@@ -95,11 +95,14 @@ export function stepCardsOf({ store, family, now, access, evidenceRoot, viewer =
|
|
|
95
95
|
const waiting = waitingOf(store, current.id, now);
|
|
96
96
|
if (waiting === null)
|
|
97
97
|
return null;
|
|
98
|
-
const last = latestFinishedAttempt(builds);
|
|
98
|
+
const last = waiting.attempt === "plan" ? latestFinishedPlanner(plannerRuns) : latestFinishedAttempt(builds);
|
|
99
99
|
return { ...waiting, agentSaid: last !== null && last.outcome === "failed" ? agentSaidOf(store, last.id) : null };
|
|
100
100
|
})(),
|
|
101
101
|
held: current.state === "cancelled" || current.state === "done" ? null : heldOf(store, ref?.id ?? null, builds, now),
|
|
102
102
|
retry: current.state === "failed" ? (() => { const pins = retryPinsOf(store, current.id); return pins === null ? null : { run: pins.run, digest: pins.digest }; })() : null,
|
|
103
|
+
planStopped: planStoppedOf(store, current.id, ref?.id ?? null, plannerRuns),
|
|
104
|
+
plan: planAskOf(store, current.id, current.state, ref, scope, live !== null, now),
|
|
105
|
+
planQueued: planQueuedOf(store, current.state, ref, scope, live !== null, now),
|
|
103
106
|
approval: scope !== null && approved && scope.approvedBy !== null
|
|
104
107
|
? { by: scope.approvedBy, you: viewer !== null && scope.approvedBy === viewer, automatic: AUTOMATIC.has(String(scope.approvalBasis ?? "")) } : null,
|
|
105
108
|
room: `task:${encodeURIComponent(root.id)}`,
|
|
@@ -160,8 +163,9 @@ export function waitingForTasks(store, taskIds, now) {
|
|
|
160
163
|
const rows = store.handle.prepare(`SELECT task.id AS task,
|
|
161
164
|
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,
|
|
162
165
|
(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,
|
|
163
|
-
(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,
|
|
164
|
-
(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
|
|
166
|
+
(SELECT run.outcome FROM run WHERE run.task_ref = task_ref.id AND run.role IN ('builder', 'scout', 'repair', 'planner') AND NOT (run.role = 'planner' AND run.parent_run IS NOT NULL) AND (run.finished_at IS NOT NULL OR run.outcome IS NOT NULL) ORDER BY run.id DESC LIMIT 1) AS outcome,
|
|
167
|
+
(SELECT run.reason FROM run WHERE run.task_ref = task_ref.id AND run.role IN ('builder', 'scout', 'repair', 'planner') AND NOT (run.role = 'planner' AND run.parent_run IS NOT NULL) AND (run.finished_at IS NOT NULL OR run.outcome IS NOT NULL) ORDER BY run.id DESC LIMIT 1) AS reason,
|
|
168
|
+
(SELECT run.role FROM run WHERE run.task_ref = task_ref.id AND run.role IN ('builder', 'scout', 'repair', 'planner') AND NOT (run.role = 'planner' AND run.parent_run IS NOT NULL) AND (run.finished_at IS NOT NULL OR run.outcome IS NOT NULL) ORDER BY run.id DESC LIMIT 1) AS role
|
|
165
169
|
FROM task JOIN task_ref ON task_ref.backend = 'built-in' AND task_ref.external_id = task.id
|
|
166
170
|
WHERE task.state = 'queued' AND task.id IN (${ids.map(() => "?").join(", ")})
|
|
167
171
|
-- A person's hold (Stop retrying, a pause, a question, an incident) means it isn't waiting to try again.
|
|
@@ -174,6 +178,7 @@ export function waitingForTasks(store, taskIds, now) {
|
|
|
174
178
|
out.set(String(row["task"]), {
|
|
175
179
|
retryAt: held && row["until"] != null ? String(row["until"]) : null,
|
|
176
180
|
lastFailure: failed ? failedAttemptSentence(row["reason"] == null ? null : String(row["reason"])).replace(/[.\s]+$/, "") : null,
|
|
181
|
+
attempt: row["role"] === "planner" ? "plan" : "build",
|
|
177
182
|
});
|
|
178
183
|
}
|
|
179
184
|
return out;
|
|
@@ -241,7 +246,7 @@ export function resultDiffFileOf(store, evidenceRoot, taskId, run, file) {
|
|
|
241
246
|
const one = parsed.files[0];
|
|
242
247
|
if (one === undefined)
|
|
243
248
|
return null;
|
|
244
|
-
return { version: ENGINE_API_VERSION, task: taskId, run: run.id, file: { file, path: one.path, oldPath: one.oldPath, meta: one.meta, hunks: one.hunks }, linesTruncated: parsed.linesTruncated };
|
|
249
|
+
return { version: ENGINE_API_VERSION, task: taskId, run: run.id, file: { file, path: one.path, oldPath: one.oldPath, meta: one.meta, hunks: one.hunks, lineCount: patchLineCount(one.hunks) }, linesTruncated: parsed.linesTruncated };
|
|
245
250
|
}
|
|
246
251
|
function acceptFactsOf(store, assignment, viewer, evidenceRoot) {
|
|
247
252
|
const receipt = assignment.receipt;
|
|
@@ -354,3 +359,89 @@ export function agentsReadOf(detection, view = "full", home = null, claudeNote =
|
|
|
354
359
|
}
|
|
355
360
|
return { version: ENGINE_API_VERSION, checkedAt: detection?.checkedAt ?? null, agents, firstTask, lines: detectionLines(detection) };
|
|
356
361
|
}
|
|
362
|
+
export const PLANNER_INCIDENTS = Object.freeze({
|
|
363
|
+
"malformed-plan": "plan", "malformed-decision": "question", "plan-attempts-exhausted": "stalled",
|
|
364
|
+
});
|
|
365
|
+
function latestFinishedPlanner(planners) {
|
|
366
|
+
let latest = null;
|
|
367
|
+
for (const run of planners)
|
|
368
|
+
if (run.parentRun === null && (run.finishedAt !== null || (run.outcome ?? null) !== null) && (latest === null || run.id > latest.id))
|
|
369
|
+
latest = run;
|
|
370
|
+
return latest;
|
|
371
|
+
}
|
|
372
|
+
export function planStoppedLine(kind, strikes, reason) {
|
|
373
|
+
if (kind === "plan")
|
|
374
|
+
return "The plan didn't pass its checks.";
|
|
375
|
+
if (kind === "question")
|
|
376
|
+
return "The planner's question didn't pass its checks.";
|
|
377
|
+
const why = failedAttemptSentence(reason).replace(/[.\s]+$/, "").replace(/^./, first => first.toLowerCase());
|
|
378
|
+
return `Planning stopped after ${Math.max(strikes, 1)} failed attempts in a row: ${why}.`;
|
|
379
|
+
}
|
|
380
|
+
function planStoppedOf(store, taskId, taskRef, planners) {
|
|
381
|
+
if (taskRef === null)
|
|
382
|
+
return null;
|
|
383
|
+
const row = store.handle.prepare(`SELECT incident.id, incident.kind, incident.run FROM incident JOIN run ON run.id = incident.run
|
|
384
|
+
WHERE run.task_ref = ? AND run.role = 'planner' AND incident.resolved_at IS NULL ORDER BY incident.id DESC LIMIT 1`).get(taskRef);
|
|
385
|
+
if (row === undefined)
|
|
386
|
+
return null;
|
|
387
|
+
const kind = PLANNER_INCIDENTS[String(row["kind"])];
|
|
388
|
+
if (kind === undefined)
|
|
389
|
+
return null;
|
|
390
|
+
const run = Number(row["run"]);
|
|
391
|
+
const reason = planners.find(one => one.id === run)?.reason ?? null;
|
|
392
|
+
const strikes = Number(store.handle.prepare("SELECT plan_strikes FROM task_ref WHERE id = ?").get(taskRef)?.["plan_strikes"] ?? 0);
|
|
393
|
+
const source = planSourceOf(store, taskId);
|
|
394
|
+
const plan = store.handle.prepare("SELECT plan FROM task_ref WHERE id = ?").get(taskRef)?.["plan"];
|
|
395
|
+
return {
|
|
396
|
+
incident: Number(row["id"]), kind, line: planStoppedLine(kind, strikes, reason),
|
|
397
|
+
problems: planProblemsOf(store, run), agentSaid: agentSaidOf(store, run),
|
|
398
|
+
again: source !== null && plan === "requested" ? { source } : null,
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
function planAskOf(store, taskId, state, ref, scope, live, now) {
|
|
402
|
+
if (ref === null || ref.plan !== null || state !== "queued" || live || store.hasLiveClaim(ref.id, now))
|
|
403
|
+
return null;
|
|
404
|
+
if (scope !== null && approvalOf(scope).approved)
|
|
405
|
+
return null;
|
|
406
|
+
if (store.coordinatorProvenanceOf(taskId) !== null)
|
|
407
|
+
return null;
|
|
408
|
+
const source = planSourceOf(store, taskId);
|
|
409
|
+
return source === null ? null : { source };
|
|
410
|
+
}
|
|
411
|
+
export function planStoppedFor(store, taskId) {
|
|
412
|
+
const ref = store.lookupRef(taskId);
|
|
413
|
+
return ref === null ? null : planStoppedOf(store, taskId, ref.id, store.runsFor(ref.id).filter(run => run.role === "planner"));
|
|
414
|
+
}
|
|
415
|
+
export function patchLineCount(hunks) {
|
|
416
|
+
if (hunks.length !== 1)
|
|
417
|
+
return null;
|
|
418
|
+
const header = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/.exec(hunks[0].header);
|
|
419
|
+
if (header === null)
|
|
420
|
+
return null;
|
|
421
|
+
const [oldStart, oldCount, newStart, newCount] = [header[1], header[2] ?? "1", header[3], header[4] ?? "1"].map(Number);
|
|
422
|
+
if (oldStart === 0 && oldCount === 0)
|
|
423
|
+
return newStart === 1 || newCount === 0 ? newCount : null;
|
|
424
|
+
if (newStart === 0 && newCount === 0)
|
|
425
|
+
return 0;
|
|
426
|
+
return null;
|
|
427
|
+
}
|
|
428
|
+
export function planBackoffFor(store, taskId, now) {
|
|
429
|
+
const waiting = waitingOf(store, taskId, now);
|
|
430
|
+
if (waiting === null || waiting.attempt !== "plan")
|
|
431
|
+
return null;
|
|
432
|
+
const ref = store.lookupRef(taskId);
|
|
433
|
+
if (ref === null)
|
|
434
|
+
return null;
|
|
435
|
+
const last = latestFinishedPlanner(store.runsFor(ref.id).filter(run => run.role === "planner"));
|
|
436
|
+
return {
|
|
437
|
+
line: waiting.lastFailure === null ? "Toolroll tries the plan again soon." : `Last plan attempt failed · ${waiting.lastFailure}. Toolroll tries the plan again soon.`,
|
|
438
|
+
agentSaid: last !== null && last.outcome === "failed" ? agentSaidOf(store, last.id) : null,
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
function planQueuedOf(store, state, ref, scope, live, now) {
|
|
442
|
+
if (ref === null || ref.plan !== "requested" || state !== "queued" || live || store.hasLiveClaim(ref.id, now))
|
|
443
|
+
return false;
|
|
444
|
+
if (scope !== null && approvalOf(scope).approved)
|
|
445
|
+
return false;
|
|
446
|
+
return store.activeHolds(ref.id, now).length === 0;
|
|
447
|
+
}
|