toolroll 0.9.115 → 0.9.117
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 +55 -0
- package/README.md +43 -26
- package/dist/acp-agents.js +14 -1
- package/dist/acp-client.js +19 -1
- package/dist/agent-change-check.js +60 -0
- package/dist/agent-change-schema.js +19 -0
- package/dist/agent-detect.js +11 -1
- package/dist/agent-fence.js +39 -10
- package/dist/agent-network-request.js +108 -0
- package/dist/agent-requests.js +105 -0
- package/dist/approval-summary.js +3 -3
- package/dist/backup.js +17 -1
- package/dist/batch-checks.js +81 -18
- package/dist/browser/terminal.js +41 -41
- package/dist/browser/workspace.css +2 -2
- package/dist/browser/workspace.js +36 -36
- package/dist/builder.js +3 -1
- package/dist/candidate-materialize.js +119 -0
- package/dist/central-enrollment-contract.js +156 -0
- package/dist/central-recovery-stage.js +329 -0
- package/dist/chat-actions.js +101 -2
- package/dist/chat-channel.js +40 -0
- package/dist/check-only-standing.js +13 -0
- package/dist/check-only.js +25 -13
- package/dist/check-recovery-hold.js +199 -0
- package/dist/check-recovery-index-schema.js +3 -0
- package/dist/check-screenshots.js +83 -0
- package/dist/cli.js +125 -6
- package/dist/codex-limits.js +4 -0
- package/dist/connect-cli.js +257 -11
- package/dist/contracts/chat-actions.js +4 -0
- package/dist/contracts/console-api.js +15 -4
- package/dist/contracts/engine-api.js +344 -2
- package/dist/contracts/lead-tools.js +56 -2
- package/dist/contracts/provider.js +1 -1
- package/dist/contracts/route.js +1 -1
- package/dist/contracts/terminal-connection.js +50 -0
- package/dist/converse.js +80 -4
- package/dist/device-pair.js +280 -0
- package/dist/direct-chat-artifacts.js +347 -0
- package/dist/direct-chat-catalog.js +311 -0
- package/dist/direct-chat-fence.js +96 -0
- package/dist/direct-chat-git.js +343 -0
- package/dist/direct-chat-laptop.js +19 -0
- package/dist/direct-chat-schema.js +181 -0
- package/dist/direct-chat-ship.js +861 -0
- package/dist/direct-chat-workspace.js +389 -0
- package/dist/direct-chat.js +2107 -0
- package/dist/doctor.js +1 -1
- package/dist/easy-start.js +18 -0
- package/dist/egress.js +25 -4
- package/dist/engine-chat.js +454 -0
- package/dist/engine-reads.js +141 -13
- package/dist/exec.js +4 -3
- package/dist/flexible-agents.js +8 -16
- package/dist/flexible-authority-end.js +2 -0
- package/dist/flexible-interactive-schema.js +133 -0
- package/dist/flexible-interactive.js +94 -0
- package/dist/flexible-session.js +117 -49
- package/dist/flexible-ship.js +87 -7
- package/dist/flexible-sign-in.js +10 -0
- package/dist/flexible-start.js +21 -3
- package/dist/flexible-thread.js +2 -3
- package/dist/flexible-turns.js +26 -5
- package/dist/flexible.js +13 -0
- package/dist/flow-triggers.js +13 -4
- package/dist/flows-ui.js +54 -20
- package/dist/handoff-cli.js +630 -0
- package/dist/invoke.js +55 -13
- package/dist/lead-contract.js +5 -4
- package/dist/lead-doors.js +80 -1
- package/dist/lead-progress.js +9 -0
- package/dist/lead-tools.js +682 -10
- package/dist/lead.js +37 -9
- package/dist/live-bus.js +11 -0
- package/dist/live-terminal.js +132 -12
- package/dist/local-handoff.js +363 -0
- package/dist/local-owner-acts.js +264 -2
- package/dist/local-owner.js +16 -1
- package/dist/multiplayer-handoff.js +528 -0
- package/dist/multiplayer-presence.js +471 -0
- package/dist/names.js +17 -4
- package/dist/needs-you.js +10 -0
- package/dist/operate.js +280 -19
- package/dist/policy.js +2 -2
- package/dist/project-delete-ui.js +18 -11
- package/dist/project-delete.js +65 -4
- package/dist/project-tools.js +1 -1
- package/dist/prompt.js +1 -1
- package/dist/provider-connection.js +2 -0
- package/dist/provider-home.js +251 -8
- package/dist/provider.js +3 -2
- package/dist/publish.js +119 -64
- package/dist/pull-request-flow.js +35 -14
- package/dist/read-executor-worker.js +1 -1
- package/dist/read-executor.js +95 -1
- package/dist/restore-retirement.js +152 -0
- package/dist/result-follow-ups.js +116 -37
- package/dist/route-change.js +44 -4
- package/dist/scope.js +62 -5
- package/dist/serve.js +49 -5
- package/dist/server/chat.js +94 -13
- package/dist/server/console.css +9 -9
- package/dist/server/direct-chat.js +583 -0
- package/dist/server/engine-api.js +219 -21
- package/dist/server/flows.js +47 -13
- package/dist/server/found-repos.js +25 -0
- package/dist/server/guards.js +20 -6
- package/dist/server/live.js +81 -23
- package/dist/server/pages.js +67 -13
- package/dist/server/people-tokens.js +47 -6
- package/dist/server/remote.js +29 -0
- package/dist/server/render-results.js +6 -2
- package/dist/server/render-settings.js +4 -2
- package/dist/server/render-tasks.js +18 -17
- package/dist/server/route-table.js +69 -2
- package/dist/server/settings.js +22 -7
- package/dist/server/task-views.js +15 -3
- package/dist/server/tasks.js +39 -2
- package/dist/server/terminals.js +185 -11
- package/dist/settings-proofs.js +1 -1
- package/dist/spend-report.js +2 -2
- package/dist/spend.js +3 -3
- package/dist/store.js +600 -59
- 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 +36 -5
- package/dist/subscription-usage.js +233 -0
- package/dist/task-live.js +2 -1
- package/dist/teardown-git.js +34 -4
- package/dist/terminal-connection.js +159 -0
- package/dist/terminal-safety.js +114 -0
- 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-contract.js +1 -1
- package/dist/tui-launch.js +32 -1
- package/dist/workspace-identity-schema.js +21 -0
- package/package.json +4 -2
package/dist/chat-actions.js
CHANGED
|
@@ -163,6 +163,10 @@ export const CHAT_ACTIONS = {
|
|
|
163
163
|
task_cancel: { label: "Cancel task", protected: true, password: false },
|
|
164
164
|
task_resume: { label: "Resume task", protected: true, password: false },
|
|
165
165
|
task_start: { label: "Start work", protected: true, password: false },
|
|
166
|
+
direct_chat_start: { label: "Start Direct Chat", protected: false, password: false },
|
|
167
|
+
direct_chat_reply: { label: "Send to Direct Chat", protected: false, password: false },
|
|
168
|
+
direct_chat_promote: { label: "Promote to Task", protected: false, password: false },
|
|
169
|
+
direct_chat_ship: { label: "Open Ship preview", protected: false, password: false },
|
|
166
170
|
};
|
|
167
171
|
const CREDENTIAL_ACTIONS = new Set(["tool_add", "flow_browser"]);
|
|
168
172
|
const SAME_ACTIONS = true;
|
|
@@ -302,7 +306,7 @@ export function prepareSharedAction(store, who, operation, input, root, now = ne
|
|
|
302
306
|
const stamp = hash({ operation, request, repo: "", state, terms, actor: who.name, generation: who.generation, ceiling: who.ceilingDigest });
|
|
303
307
|
return { version: SHARED_ACTION_VERSION, operation, request, repo: "", title, terms, stamp, state };
|
|
304
308
|
}
|
|
305
|
-
const task = operation === "mode_revoke" || operation === "memory_decide" || operation === "incident_resolve" || operation === "finding_resend" || operation.startsWith("code_map_") || operation.startsWith("skill_") || operation.startsWith("knowledge_") || operation.startsWith("decision_") || operation.startsWith("tool_") || operation.startsWith("flow_") || operation.startsWith("subagent_") || operation.startsWith("kit_") || operation.startsWith("sweep_") || operation.startsWith("suggestion_") || operation.startsWith("trial_") || operation === "task_start"
|
|
309
|
+
const task = operation === "mode_revoke" || operation === "memory_decide" || operation === "incident_resolve" || operation === "finding_resend" || operation.startsWith("code_map_") || operation.startsWith("skill_") || operation.startsWith("knowledge_") || operation.startsWith("decision_") || operation.startsWith("tool_") || operation.startsWith("flow_") || operation.startsWith("subagent_") || operation.startsWith("kit_") || operation.startsWith("sweep_") || operation.startsWith("suggestion_") || operation.startsWith("trial_") || operation === "task_start" || operation.startsWith("direct_chat_")
|
|
306
310
|
? null
|
|
307
311
|
: text(input, "task", 64);
|
|
308
312
|
const flowTarget = operation.startsWith("flow_") && operation !== "flow_create" && operation !== "flow_script_save" && operation !== "flow_starter" ? flowTargetOf(store, input) : null;
|
|
@@ -322,7 +326,63 @@ export function prepareSharedAction(store, who, operation, input, root, now = ne
|
|
|
322
326
|
requireActor(store, who, repo);
|
|
323
327
|
const request = structuredClone(input), terms = [];
|
|
324
328
|
let state, title = CHAT_ACTIONS[operation].label;
|
|
325
|
-
if (
|
|
329
|
+
if (operation.startsWith("direct_chat_")) {
|
|
330
|
+
if (operation === "direct_chat_start") {
|
|
331
|
+
const provider = text(input, "provider", 40);
|
|
332
|
+
const model = text(input, "model", 120);
|
|
333
|
+
const prompt = text(input, "prompt", 4000);
|
|
334
|
+
const effort = typeof input["effort"] === "string" ? input["effort"] : null;
|
|
335
|
+
if (scanForSecrets(prompt).length > 0)
|
|
336
|
+
throw Error("Direct Chat prompt cannot contain credentials.");
|
|
337
|
+
state = { repo };
|
|
338
|
+
title = `Start ${provider} Direct Chat`;
|
|
339
|
+
terms.push(`Agent: ${provider} · ${model}${effort ? ` (${effort} effort)` : ""}`, `Prompt: ${prompt.slice(0, 280)}${prompt.length > 280 ? "…" : ""}`, "Runs inside an isolated local clone with no remote until you press Ship.");
|
|
340
|
+
}
|
|
341
|
+
else if (operation === "direct_chat_reply") {
|
|
342
|
+
const chat = text(input, "chat", 80);
|
|
343
|
+
const prompt = text(input, "prompt", 4000);
|
|
344
|
+
if (scanForSecrets(prompt).length > 0)
|
|
345
|
+
throw Error("Direct Chat message cannot contain credentials.");
|
|
346
|
+
const row = store.handle.prepare("SELECT id, title, repo, provider, model_id FROM direct_chat_thread WHERE id = ? AND owner = ?").get(chat, who.name);
|
|
347
|
+
if (row === undefined || String(row["repo"]) !== repo)
|
|
348
|
+
throw Error("That Direct Chat is not available in this project.");
|
|
349
|
+
state = { chat, repo };
|
|
350
|
+
title = `Send to "${String(row["title"]).slice(0, 60)}"`;
|
|
351
|
+
terms.push(`Direct Chat: ${String(row["title"])} (${String(row["provider"])} · ${String(row["model_id"])})`, `Message: ${prompt.slice(0, 280)}${prompt.length > 280 ? "…" : ""}`);
|
|
352
|
+
}
|
|
353
|
+
else if (operation === "direct_chat_ship") {
|
|
354
|
+
const chat = text(input, "chat", 80);
|
|
355
|
+
const mode = input["mode"] === "keep-branch" ? "keep-branch" : "ship";
|
|
356
|
+
const row = store.handle.prepare("SELECT id, title, repo, branch, diff_cache_json FROM direct_chat_thread WHERE id = ? AND owner = ? AND archived_at IS NULL").get(chat, who.name);
|
|
357
|
+
if (row === undefined || String(row["repo"]) !== repo)
|
|
358
|
+
throw Error("That Direct Chat is not available in this project.");
|
|
359
|
+
let changedCount = 0;
|
|
360
|
+
try {
|
|
361
|
+
const parsed = typeof row["diff_cache_json"] === "string" ? JSON.parse(row["diff_cache_json"]) : null;
|
|
362
|
+
if (Array.isArray(parsed?.changedFiles))
|
|
363
|
+
changedCount = parsed.changedFiles.length;
|
|
364
|
+
}
|
|
365
|
+
catch { }
|
|
366
|
+
state = { chat, repo };
|
|
367
|
+
const chatTitle = String(row["title"] ?? "Direct Chat").slice(0, 60);
|
|
368
|
+
title = `Ship "${chatTitle}"`;
|
|
369
|
+
terms.push(`Direct Chat: ${chatTitle} (branch ${String(row["branch"] ?? "")})`, changedCount > 0 ? `Changes: ${changedCount} ${changedCount === 1 ? "file" : "files"} changed` : "Inspect current clone changes in the Ship preview.", mode === "keep-branch" ? "Mode: Keep branch on this Mac." : "Mode: Ship (runs project check before merging).", "Opens the Ship preview so you can review and confirm before anything is pushed or merged.");
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
const chat = text(input, "chat", 80);
|
|
373
|
+
const taskTitle = text(input, "title", 200);
|
|
374
|
+
const goal = text(input, "goal", 8000);
|
|
375
|
+
if ([taskTitle, goal].some(s => scanForSecrets(s).length > 0))
|
|
376
|
+
throw Error("Task text cannot contain credentials.");
|
|
377
|
+
const row = store.handle.prepare("SELECT id, title, repo, branch FROM direct_chat_thread WHERE id = ? AND owner = ?").get(chat, who.name);
|
|
378
|
+
if (row === undefined || String(row["repo"]) !== repo)
|
|
379
|
+
throw Error("That Direct Chat is not available in this project.");
|
|
380
|
+
state = { chat, repo };
|
|
381
|
+
title = `Promote "${String(row["title"]).slice(0, 50)}" to Task`;
|
|
382
|
+
terms.push(`Task title: ${taskTitle}`, `Goal: ${goal.slice(0, 280)}${goal.length > 280 ? "…" : ""}`, `Source Direct Chat branch: ${String(row["branch"] ?? "")}`, "Files an ordinary task. Building still requires your approval.");
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
else if (PARITY_ACTIONS.has(operation)) {
|
|
326
386
|
const made = parityAction(store, who, operation, input, repo, flowTarget?.flow ?? null, now, request, root);
|
|
327
387
|
state = made.state;
|
|
328
388
|
title = made.title;
|
|
@@ -1208,6 +1268,45 @@ export function executeSharedAction(store, who, id, payload, now, options) {
|
|
|
1208
1268
|
return runLateApproval(store, who, payload, repo => approvalBy(store, who, repo, now, options, drafted), approvalRoad(options), now);
|
|
1209
1269
|
if (PARITY_ACTIONS.has(payload.operation) || OWNER_PARITY.has(payload.operation))
|
|
1210
1270
|
return runParityAction(store, who, payload, now, options.root);
|
|
1271
|
+
if (payload.operation === "direct_chat_promote") {
|
|
1272
|
+
const taskTitle = String(req["title"] ?? "").trim();
|
|
1273
|
+
const goal = String(req["goal"] ?? "").trim();
|
|
1274
|
+
const planning = req["planning"] === "required" || req["planning"] === "skip" ? req["planning"] : "auto";
|
|
1275
|
+
const filed = fileTaskProposal(store, {
|
|
1276
|
+
title: taskTitle,
|
|
1277
|
+
repo,
|
|
1278
|
+
goal,
|
|
1279
|
+
outOfScope: null,
|
|
1280
|
+
touches: [],
|
|
1281
|
+
acceptance: [{ id: "c1", statement: taskTitle, evidence: ["manual-review"] }],
|
|
1282
|
+
planning,
|
|
1283
|
+
filedVia: "mate",
|
|
1284
|
+
filedBy: { name: actor, kind: "person" },
|
|
1285
|
+
proposedVia: "mate",
|
|
1286
|
+
admittedRepos: [...who.repos],
|
|
1287
|
+
}, now);
|
|
1288
|
+
if (!filed.ok)
|
|
1289
|
+
throw Error(`Not filed: ${filed.message}`);
|
|
1290
|
+
return {
|
|
1291
|
+
ok: true,
|
|
1292
|
+
taskId: filed.id,
|
|
1293
|
+
said: `Promoted Direct Chat to task ${filed.id}. Review and approve its plan to start.`,
|
|
1294
|
+
href: `/tasks/${encodeURIComponent(filed.id)}`,
|
|
1295
|
+
};
|
|
1296
|
+
}
|
|
1297
|
+
if (payload.operation === "direct_chat_start") {
|
|
1298
|
+
return { ok: true, taskId: null, said: "Direct Chat confirmed." };
|
|
1299
|
+
}
|
|
1300
|
+
if (payload.operation === "direct_chat_reply") {
|
|
1301
|
+
const chatId = String(req["chat"] ?? "");
|
|
1302
|
+
return { ok: true, taskId: null, said: "Message queued for Direct Chat.", href: `/direct-chats/${encodeURIComponent(chatId)}` };
|
|
1303
|
+
}
|
|
1304
|
+
if (payload.operation === "direct_chat_ship") {
|
|
1305
|
+
const chatId = String(req["chat"] ?? "");
|
|
1306
|
+
const row = store.handle.prepare("SELECT title FROM direct_chat_thread WHERE id = ? AND owner = ?").get(chatId, actor);
|
|
1307
|
+
const label = typeof row?.["title"] === "string" && row["title"].trim() !== "" ? row["title"].trim() : "Direct Chat";
|
|
1308
|
+
return { ok: true, taskId: null, said: `Ready to ship "${label}". Review and confirm in the Ship sheet.`, href: `/direct-chats/${encodeURIComponent(chatId)}/ship` };
|
|
1309
|
+
}
|
|
1211
1310
|
if (payload.operation === "lead_about_you") {
|
|
1212
1311
|
const next = withAboutYouLine(aboutYouOf(store, actor), String(req["line"]), Number(req["replaces"] ?? 0));
|
|
1213
1312
|
if (!next.ok)
|
package/dist/chat-channel.js
CHANGED
|
@@ -681,6 +681,46 @@ export const CHAT_ACTION_PARITY = {
|
|
|
681
681
|
how: "Refused on the phone by design: the workbench's look is the person's own conversation in the console on this computer (view-tools.ts); the tool answers in words and nothing is read or written.",
|
|
682
682
|
gap: "No phone path by design: restyle from the console on this computer, or edit tui.toml.",
|
|
683
683
|
},
|
|
684
|
+
list_direct_chats: {
|
|
685
|
+
support: "direct",
|
|
686
|
+
how: "Read during a turn: lists active Direct Chat threads in admitted projects with model, effort, status, and token usage.",
|
|
687
|
+
gap: null,
|
|
688
|
+
},
|
|
689
|
+
get_direct_chat: {
|
|
690
|
+
support: "direct",
|
|
691
|
+
how: "Read during a turn: reads one Direct Chat's full turn transcript, tool history, and token usage from SQLite.",
|
|
692
|
+
gap: null,
|
|
693
|
+
},
|
|
694
|
+
get_direct_chat_diff: {
|
|
695
|
+
support: "direct",
|
|
696
|
+
how: "Read during a turn: inspects a Direct Chat's changed files, bounded patch, and Ship readiness.",
|
|
697
|
+
gap: null,
|
|
698
|
+
},
|
|
699
|
+
manage_direct_chat: {
|
|
700
|
+
support: "missing",
|
|
701
|
+
how: "Refused on the phone by design: instant Direct Chat controls require the owner's local solo console session on this computer.",
|
|
702
|
+
gap: "No phone path by design: stop, rename, switch model, or archive Direct Chats from the local Mac app or console.",
|
|
703
|
+
},
|
|
704
|
+
get_usage_limits: {
|
|
705
|
+
support: "direct",
|
|
706
|
+
how: "Read during a turn: reports live Claude, Codex, and Gemini subscription windows and monthly spend budgets.",
|
|
707
|
+
gap: null,
|
|
708
|
+
},
|
|
709
|
+
get_recent_updates: {
|
|
710
|
+
support: "direct",
|
|
711
|
+
how: "Read during a turn: aggregates Ready results, completions, failures, updated Direct Chats, open decisions, and recent actions.",
|
|
712
|
+
gap: null,
|
|
713
|
+
},
|
|
714
|
+
propose_direct_chat: {
|
|
715
|
+
support: "handoff",
|
|
716
|
+
how: "Drafts a confirmation card to start, reply to, or promote a Direct Chat; promote files a Task on confirm while start and reply execute only on the local solo console.",
|
|
717
|
+
gap: "Incomplete phone action: starting or replying to a local Direct Chat clone runs in the local console or Mac app.",
|
|
718
|
+
},
|
|
719
|
+
propose_report_followups: {
|
|
720
|
+
support: "direct",
|
|
721
|
+
how: "Batch-drafts standard Task confirmation cards from a verified Scout Report's follow-up recommendations through the shared door.",
|
|
722
|
+
gap: null,
|
|
723
|
+
},
|
|
684
724
|
};
|
|
685
725
|
export function parityGaps() {
|
|
686
726
|
return LEAD_TOOL_SCHEMAS.map((tool) => tool.name).filter((name) => CHAT_ACTION_PARITY[name] === undefined);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CHECK_RECOVERY_HELD, readCheckRecoveryHoldsForRun } from "./check-recovery-hold.js";
|
|
1
2
|
import { authorityStandsSql } from "./approval-authority.js";
|
|
2
3
|
import { checkAccessOf } from "./check-access.js";
|
|
3
4
|
import { refArchived } from "./task-archive.js";
|
|
@@ -13,6 +14,9 @@ export function approvedScopeStands(store, taskRef, scopeDigest, now) {
|
|
|
13
14
|
AND ${authorityStandsSql("task_scope", "task_ref.repo", "?")}`).get(taskRef, scopeDigest, stamp, stamp, stamp, stamp) !== undefined;
|
|
14
15
|
}
|
|
15
16
|
export function authorizationProblem(store, auth, input, now) {
|
|
17
|
+
const held = checkOnlyRecoveryProblem(store, auth.run);
|
|
18
|
+
if (held !== null)
|
|
19
|
+
return held;
|
|
16
20
|
if (auth.candidate !== input.head)
|
|
17
21
|
return "The commit changed.";
|
|
18
22
|
if (auth.commandDigest !== input.digest)
|
|
@@ -24,6 +28,9 @@ export function authorizationProblem(store, auth, input, now) {
|
|
|
24
28
|
return null;
|
|
25
29
|
}
|
|
26
30
|
export function recheckStanding(store, input) {
|
|
31
|
+
const held = checkOnlyRecoveryProblem(store, input.runId);
|
|
32
|
+
if (held !== null)
|
|
33
|
+
return { ok: false, problem: held };
|
|
27
34
|
const row = store.handle.prepare("SELECT * FROM check_authorization WHERE used_request = ? AND run = ?").get(input.request, input.runId);
|
|
28
35
|
if (row === undefined)
|
|
29
36
|
return { ok: false, problem: "Its authorization couldn't be read." };
|
|
@@ -31,3 +38,9 @@ export function recheckStanding(store, input) {
|
|
|
31
38
|
const problem = authorizationProblem(store, auth, input, new Date());
|
|
32
39
|
return problem === null ? { ok: true, access: auth.access } : { ok: false, problem };
|
|
33
40
|
}
|
|
41
|
+
export function checkOnlyRecoveryProblem(store, runId) {
|
|
42
|
+
if (store.handle.prepare("SELECT 1 FROM action_ledger WHERE action = ? LIMIT 1").get(CHECK_RECOVERY_HELD) === undefined)
|
|
43
|
+
return null;
|
|
44
|
+
const evidence = readCheckRecoveryHoldsForRun(store, runId);
|
|
45
|
+
return evidence.kind === "no-evidence" ? null : "Checks are on hold after recovery. Earlier execution is unverified.";
|
|
46
|
+
}
|
package/dist/check-only.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assignmentChecksForRun } from "./assignment.js";
|
|
2
2
|
import { runCheckLevel, repoOfRun, checkCommandFor } from "./check-levels.js";
|
|
3
|
-
import { approvedScopeStands, authorizationProblem, readAuthorization } from "./check-only-standing.js";
|
|
3
|
+
import { approvedScopeStands, authorizationProblem, readAuthorization, checkOnlyRecoveryProblem } from "./check-only-standing.js";
|
|
4
4
|
import { requestFollowUpChecks } from "./result-follow-ups.js";
|
|
5
5
|
import { releaseCheckScope } from "./scope.js";
|
|
6
6
|
import { refArchived } from "./task-archive.js";
|
|
@@ -9,6 +9,8 @@ export const CHECK_ONLY_WINDOW_MS = 24 * 60 * 60_000;
|
|
|
9
9
|
export const RECHECK_ACTOR = "Toolroll";
|
|
10
10
|
export function authorizeCheckOnly(store, runId, now) {
|
|
11
11
|
return store.transact(() => {
|
|
12
|
+
if (checkOnlyRecoveryProblem(store, runId) !== null)
|
|
13
|
+
return null;
|
|
12
14
|
const run = store.getRun(runId);
|
|
13
15
|
if (run === null || run.role !== "builder" || run.outcome !== "built" || run.headRevision === null || !/^[a-f0-9]{40}$/.test(run.headRevision))
|
|
14
16
|
return null;
|
|
@@ -40,6 +42,8 @@ export function claimRecheck(store, authorization, now) {
|
|
|
40
42
|
if (row === undefined)
|
|
41
43
|
return null;
|
|
42
44
|
const auth = readAuthorization(row);
|
|
45
|
+
if (checkOnlyRecoveryProblem(store, auth.run) !== null)
|
|
46
|
+
return null;
|
|
43
47
|
const run = store.getRun(auth.run);
|
|
44
48
|
const repo = repoOfRun(store, auth.run);
|
|
45
49
|
if (run === null || repo === null || store.lastBuilderRun(auth.taskRef)?.id !== auth.run || store.hasLiveClaim(auth.taskRef, now))
|
|
@@ -50,6 +54,8 @@ export function claimRecheck(store, authorization, now) {
|
|
|
50
54
|
const asked = requestFollowUpChecks(store, { runId: auth.run, level: auth.level, actor: RECHECK_ACTOR, why: "recheck" }, now);
|
|
51
55
|
if (!asked.ok || asked.existing)
|
|
52
56
|
return null;
|
|
57
|
+
if (checkOnlyRecoveryProblem(store, auth.run) !== null)
|
|
58
|
+
return null;
|
|
53
59
|
const spent = store.handle.prepare("UPDATE check_authorization SET used_at = ?, used_request = ? WHERE id = ? AND used_at IS NULL").run(now.toISOString(), asked.request, auth.id);
|
|
54
60
|
if (Number(spent.changes) !== 1)
|
|
55
61
|
throw new Error("the recheck's authorization moved inside its own transaction");
|
|
@@ -60,18 +66,24 @@ export function requestMissingRechecks(store, root, now) {
|
|
|
60
66
|
const open = store.handle.prepare("SELECT * FROM check_authorization WHERE used_at IS NULL AND closed_at IS NULL AND expires_at > ? ORDER BY id").all(now.toISOString());
|
|
61
67
|
let asked = 0;
|
|
62
68
|
for (const row of open) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
asked += store.transact(() => {
|
|
70
|
+
const current = store.handle.prepare("SELECT * FROM check_authorization WHERE id = ? AND used_at IS NULL AND closed_at IS NULL AND expires_at > ?").get(row["id"], now.toISOString());
|
|
71
|
+
if (current === undefined)
|
|
72
|
+
return 0;
|
|
73
|
+
const auth = readAuthorization(current);
|
|
74
|
+
if (checkOnlyRecoveryProblem(store, auth.run) !== null)
|
|
75
|
+
return 0;
|
|
76
|
+
const run = store.getRun(auth.run);
|
|
77
|
+
if (run === null || run.finishedAt === null)
|
|
78
|
+
return 0;
|
|
79
|
+
const state = approvedCheckStateOf(assignmentChecksForRun(store, root, auth.run, now));
|
|
80
|
+
if (state === "not-run" || state === "unreadable")
|
|
81
|
+
return claimRecheck(store, auth.id, now) === null ? 0 : 1;
|
|
82
|
+
if (state !== "running" && checkOnlyRecoveryProblem(store, auth.run) === null) {
|
|
83
|
+
store.handle.prepare("UPDATE check_authorization SET closed_at = ? WHERE id = ? AND used_at IS NULL AND closed_at IS NULL").run(now.toISOString(), auth.id);
|
|
84
|
+
}
|
|
85
|
+
return 0;
|
|
86
|
+
});
|
|
75
87
|
}
|
|
76
88
|
return asked;
|
|
77
89
|
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { RECOVERY_GENERATION_PATTERN } from "./workspace-identity-schema.js";
|
|
4
|
+
export const CHECK_RECOVERY_HELD = "checks recovery held";
|
|
5
|
+
const REQUESTED = "checks requested", FAMILY_LIMIT = 256;
|
|
6
|
+
const id = z.number().int().positive().max(Number.MAX_SAFE_INTEGER);
|
|
7
|
+
const text = z.string().max(4096);
|
|
8
|
+
const requestSchema = z.object({ id, repo: text.nullable(), runId: id, taskId: z.string().min(1).max(512),
|
|
9
|
+
action: z.literal(REQUESTED), outcome: z.enum(["quick", "full"]), detail: z.string().min(1).max(4096),
|
|
10
|
+
}).strict();
|
|
11
|
+
const detailSchema = z.object({ v: z.literal(1), q: z.string().regex(/^[0-9a-f]{64}$/),
|
|
12
|
+
g: z.string().regex(RECOVERY_GENERATION_PATTERN), r: id,
|
|
13
|
+
}).strict();
|
|
14
|
+
export function representCheckHoldDetail(input) {
|
|
15
|
+
const parsed = detailSchema.safeParse(input);
|
|
16
|
+
return parsed.success ? JSON.stringify(parsed.data) : null;
|
|
17
|
+
}
|
|
18
|
+
export function parseCheckHoldDetail(raw) {
|
|
19
|
+
if (typeof raw !== "string" || Buffer.byteLength(raw, "utf8") > 300)
|
|
20
|
+
return null;
|
|
21
|
+
try {
|
|
22
|
+
const parsed = detailSchema.safeParse(JSON.parse(raw));
|
|
23
|
+
return parsed.success && JSON.stringify(parsed.data) === raw ? parsed.data : null;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function checkRequestDigest(input) {
|
|
30
|
+
const parsed = requestSchema.safeParse(input);
|
|
31
|
+
if (!parsed.success)
|
|
32
|
+
return null;
|
|
33
|
+
const q = parsed.data, parts = q.detail.split(" · ");
|
|
34
|
+
if ((parts.length !== 3 && parts.length !== 4) || !/^[0-9a-f]{40}$/.test(parts[0])
|
|
35
|
+
|| !["person", "pull-request", "batch", "recheck"].includes(parts[1]) || !/^(?:[0-9a-f]{16}|[0-9a-f]{64})$/.test(parts[2])
|
|
36
|
+
|| (parts.length === 4 && (parts[1] !== "batch" || (parts[3] !== "" && !/^[0-9a-f]{40}$/.test(parts[3])))))
|
|
37
|
+
return null;
|
|
38
|
+
return createHash("sha256").update(JSON.stringify([1, q.id, q.repo, q.runId, q.taskId, q.action, q.outcome, q.detail])).digest("hex");
|
|
39
|
+
}
|
|
40
|
+
const whole = (value) => typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
41
|
+
function refOf(row) {
|
|
42
|
+
if (row === undefined || !whole(row["id"]) || row["backend"] !== "built-in" || typeof row["external_id"] !== "string"
|
|
43
|
+
|| (row["repo"] !== null && typeof row["repo"] !== "string") || (row["revision_of"] !== null && typeof row["revision_of"] !== "string")
|
|
44
|
+
|| (row["revision_brief_artifact"] !== null && !whole(row["revision_brief_artifact"])))
|
|
45
|
+
return null;
|
|
46
|
+
return row;
|
|
47
|
+
}
|
|
48
|
+
function family(store, seed) {
|
|
49
|
+
const refs = new Map(), pending = [seed];
|
|
50
|
+
const byId = (n) => refOf(store.handle.prepare("SELECT * FROM task_ref WHERE id = ?").get(n));
|
|
51
|
+
const byName = (name) => {
|
|
52
|
+
const rows = store.handle.prepare("SELECT * FROM task_ref WHERE backend = 'built-in' AND external_id = ? LIMIT 2").all(name);
|
|
53
|
+
return rows.length === 1 ? refOf(rows[0]) : null;
|
|
54
|
+
};
|
|
55
|
+
const revision = (child, parent) => {
|
|
56
|
+
if (child.repo !== parent.repo || child.revision_of !== parent.external_id || child.revision_brief_artifact === null)
|
|
57
|
+
return false;
|
|
58
|
+
const proof = store.handle.prepare("SELECT a.kind, r.task_ref FROM artifact a JOIN run r ON r.id = a.run WHERE a.id = ?").get(child.revision_brief_artifact);
|
|
59
|
+
return proof?.["kind"] === "revision-brief" && proof["task_ref"] === parent.id;
|
|
60
|
+
};
|
|
61
|
+
while (pending.length > 0) {
|
|
62
|
+
const at = pending.pop();
|
|
63
|
+
if (refs.has(at.id))
|
|
64
|
+
continue;
|
|
65
|
+
if (refs.size >= FAMILY_LIMIT)
|
|
66
|
+
return { problem: "family-bound-exceeded" };
|
|
67
|
+
if (at.repo !== seed.repo || store.handle.prepare("SELECT 1 FROM task WHERE id = ?").get(at.external_id) === undefined)
|
|
68
|
+
return { problem: "family-scope-mismatch" };
|
|
69
|
+
refs.set(at.id, at);
|
|
70
|
+
if (at.revision_of !== null) {
|
|
71
|
+
const parent = byName(at.revision_of);
|
|
72
|
+
if (parent === null || !revision(at, parent))
|
|
73
|
+
return { problem: "invalid-revision-lineage" };
|
|
74
|
+
pending.push(parent);
|
|
75
|
+
}
|
|
76
|
+
for (const row of store.handle.prepare("SELECT * FROM task_ref WHERE backend = 'built-in' AND revision_of = ? LIMIT ?").all(at.external_id, FAMILY_LIMIT + 1)) {
|
|
77
|
+
const child = refOf(row);
|
|
78
|
+
if (child === null || !revision(child, at))
|
|
79
|
+
return { problem: "invalid-revision-lineage" };
|
|
80
|
+
pending.push(child);
|
|
81
|
+
}
|
|
82
|
+
for (const row of store.handle.prepare("SELECT task_ref, successor FROM task_replacement WHERE task_ref = ? OR successor = ? LIMIT ?").all(at.id, at.external_id, FAMILY_LIMIT + 1)) {
|
|
83
|
+
const predecessor = whole(row["task_ref"]) ? byId(row["task_ref"]) : null;
|
|
84
|
+
const successor = typeof row["successor"] === "string" ? byName(row["successor"]) : null;
|
|
85
|
+
if (predecessor === null || successor === null || predecessor.repo !== successor.repo)
|
|
86
|
+
return { problem: "invalid-replacement-lineage" };
|
|
87
|
+
pending.push(predecessor, successor);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const edges = new Map();
|
|
91
|
+
for (const at of refs.values()) {
|
|
92
|
+
if (at.revision_of !== null) {
|
|
93
|
+
const parent = [...refs.values()].find(r => r.external_id === at.revision_of);
|
|
94
|
+
if (parent === undefined)
|
|
95
|
+
return { problem: "missing-family-parent" };
|
|
96
|
+
edges.set(at.id, [...(edges.get(at.id) ?? []), parent.id]);
|
|
97
|
+
}
|
|
98
|
+
for (const row of store.handle.prepare("SELECT successor FROM task_replacement WHERE task_ref = ?").all(at.id)) {
|
|
99
|
+
const successor = [...refs.values()].find(r => r.external_id === row["successor"]);
|
|
100
|
+
if (successor === undefined)
|
|
101
|
+
return { problem: "missing-replacement" };
|
|
102
|
+
edges.set(successor.id, [...(edges.get(successor.id) ?? []), at.id]);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const done = new Set(), visiting = new Set();
|
|
106
|
+
const cycle = (n) => {
|
|
107
|
+
if (visiting.has(n))
|
|
108
|
+
return true;
|
|
109
|
+
if (done.has(n))
|
|
110
|
+
return false;
|
|
111
|
+
visiting.add(n);
|
|
112
|
+
if ((edges.get(n) ?? []).some(cycle))
|
|
113
|
+
return true;
|
|
114
|
+
visiting.delete(n);
|
|
115
|
+
done.add(n);
|
|
116
|
+
return false;
|
|
117
|
+
};
|
|
118
|
+
if ([...refs.keys()].some(cycle))
|
|
119
|
+
return { problem: "cyclic-family" };
|
|
120
|
+
return { refs: [...refs.values()].sort((a, b) => a.id - b.id) };
|
|
121
|
+
}
|
|
122
|
+
function result(kind, reason, refs = [], holds = []) {
|
|
123
|
+
return Object.freeze({ kind, reason, familyRefs: Object.freeze([...refs]), holds: Object.freeze([...holds]),
|
|
124
|
+
runtimeProtection: false, retirementSupported: false, nativeStopProof: false });
|
|
125
|
+
}
|
|
126
|
+
export function readCheckRecoveryHoldsForRun(store, runId) {
|
|
127
|
+
if (!whole(runId))
|
|
128
|
+
return result("invalid-evidence", "invalid-run-id");
|
|
129
|
+
try {
|
|
130
|
+
return readSnapshot(store, () => {
|
|
131
|
+
const run = store.handle.prepare("SELECT task_ref FROM run WHERE id = ?").get(runId);
|
|
132
|
+
const seed = run !== undefined && whole(run["task_ref"]) ? refOf(store.handle.prepare("SELECT * FROM task_ref WHERE id = ?").get(run["task_ref"])) : null;
|
|
133
|
+
if (seed === null)
|
|
134
|
+
return result("invalid-evidence", "missing-run-ref");
|
|
135
|
+
return readCheckRecoveryHoldsAtRef(store, seed.id);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return result("invalid-evidence", "unreadable-evidence");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function readSnapshot(store, body) {
|
|
143
|
+
store.handle.exec("SAVEPOINT ch0_check_hold_read");
|
|
144
|
+
try {
|
|
145
|
+
return body();
|
|
146
|
+
}
|
|
147
|
+
finally {
|
|
148
|
+
store.handle.exec("RELEASE SAVEPOINT ch0_check_hold_read");
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
export function readCheckRecoveryHoldsForTaskRef(store, taskRefId) {
|
|
152
|
+
if (!whole(taskRefId))
|
|
153
|
+
return result("invalid-evidence", "invalid-task-ref");
|
|
154
|
+
try {
|
|
155
|
+
return readSnapshot(store, () => readCheckRecoveryHoldsAtRef(store, taskRefId));
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return result("invalid-evidence", "unreadable-evidence");
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function readCheckRecoveryHoldsAtRef(store, taskRefId) {
|
|
162
|
+
const seed = refOf(store.handle.prepare("SELECT * FROM task_ref WHERE id = ?").get(taskRefId));
|
|
163
|
+
if (seed === null)
|
|
164
|
+
return result("invalid-evidence", "missing-task-ref");
|
|
165
|
+
const found = family(store, seed);
|
|
166
|
+
if ("problem" in found)
|
|
167
|
+
return result("invalid-evidence", found.problem);
|
|
168
|
+
const ids = found.refs.map(r => r.id), serialized = JSON.stringify(ids), names = JSON.stringify(found.refs.map(r => r.external_id));
|
|
169
|
+
const events = store.handle.prepare(`SELECT h.* FROM action_ledger h WHERE h.action = ? AND
|
|
170
|
+
(h.run_id IN (SELECT id FROM run WHERE task_ref IN (SELECT value FROM json_each(?)))
|
|
171
|
+
OR h.task_id IN (SELECT value FROM json_each(?))
|
|
172
|
+
OR (CASE WHEN json_valid(h.detail) THEN json_extract(h.detail, '$.r') ELSE NULL END) IN (SELECT value FROM json_each(?))
|
|
173
|
+
OR EXISTS (SELECT 1 FROM action_ledger q WHERE q.id = CAST(h.outcome AS INTEGER) AND CAST(q.id AS TEXT) = h.outcome AND
|
|
174
|
+
(q.task_id IN (SELECT value FROM json_each(?)) OR q.run_id IN
|
|
175
|
+
(SELECT id FROM run WHERE task_ref IN (SELECT value FROM json_each(?)))))) ORDER BY h.id`)
|
|
176
|
+
.all(CHECK_RECOVERY_HELD, serialized, names, serialized, names, serialized);
|
|
177
|
+
const holds = [];
|
|
178
|
+
for (const event of events) {
|
|
179
|
+
if (typeof event["outcome"] !== "string" || !/^[1-9][0-9]*$/.test(event["outcome"]))
|
|
180
|
+
return result("invalid-evidence", "invalid-request-id", ids);
|
|
181
|
+
const requestId = Number(event["outcome"]), detail = parseCheckHoldDetail(event["detail"]);
|
|
182
|
+
if (!whole(requestId) || detail === null || !whole(event["id"]) || event["id"] <= requestId
|
|
183
|
+
|| event["source"] !== "work" || event["actor"] !== "toolroll")
|
|
184
|
+
return result("invalid-evidence", "invalid-hold-event", ids);
|
|
185
|
+
const q = store.handle.prepare("SELECT * FROM action_ledger WHERE id = ?").get(requestId);
|
|
186
|
+
if (q === undefined || !whole(q["run_id"]))
|
|
187
|
+
return result("invalid-evidence", "missing-request", ids);
|
|
188
|
+
const actual = { id: q["id"], repo: q["repo"], runId: q["run_id"], taskId: q["task_id"], action: q["action"], outcome: q["outcome"], detail: q["detail"] };
|
|
189
|
+
const hashed = checkRequestDigest(actual);
|
|
190
|
+
const qrun = store.handle.prepare("SELECT task_ref FROM run WHERE id = ?").get(q["run_id"]);
|
|
191
|
+
const ref = found.refs.find(r => r.id === qrun?.["task_ref"]);
|
|
192
|
+
if (hashed === null || hashed !== detail.q || ref === undefined || detail.r !== ref.id || ref.repo !== q["repo"] || ref.external_id !== q["task_id"]
|
|
193
|
+
|| event["run_id"] !== q["run_id"] || event["repo"] !== q["repo"] || event["task_id"] !== q["task_id"])
|
|
194
|
+
return result("invalid-evidence", "hold-binding-mismatch", ids);
|
|
195
|
+
holds.push(Object.freeze({ event: event["id"], request: requestId, run: q["run_id"], taskRef: ref.id, repo: ref.repo,
|
|
196
|
+
recoveryGeneration: detail.g, admission: "blocked", priorExecution: "unverified" }));
|
|
197
|
+
}
|
|
198
|
+
return result(holds.length === 0 ? "no-evidence" : "held-evidence", holds.length === 0 ? "no-hold-evidence" : "recognized-only-not-enforced", ids, holds);
|
|
199
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { lstatSync, readdirSync, realpathSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { readMailbox, SCREENSHOT_BYTE_CAP, storeEvidence, validateScreenshotBytes } from "./evidence.js";
|
|
4
|
+
export const CHECK_SHOTS_DIR = "evidence/checks";
|
|
5
|
+
export const CHECK_SHOTS_MAX = 8;
|
|
6
|
+
const IMAGE_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}\.(?:png|jpe?g)$/i;
|
|
7
|
+
const FOLDER_PROBLEM = "the folder isn't a plain folder inside the checkout";
|
|
8
|
+
export const checkScreenshotCapture = (path, commit, kind) => `check screenshot at ${path} of ${commit} (validated ${kind})`;
|
|
9
|
+
export const CHECK_SCREENSHOT_CAPTURE = /^check screenshot at (evidence\/checks\/[^ ]+) of ([a-f0-9]{40}) \(validated (?:png|jpeg)\)$/;
|
|
10
|
+
export function collectCheckScreenshots(checkout) {
|
|
11
|
+
let root;
|
|
12
|
+
try {
|
|
13
|
+
root = realpathSync(checkout);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return { files: [], problems: [] };
|
|
17
|
+
}
|
|
18
|
+
const folder = join(root, CHECK_SHOTS_DIR);
|
|
19
|
+
for (const at of [join(root, "evidence"), folder]) {
|
|
20
|
+
let held;
|
|
21
|
+
try {
|
|
22
|
+
held = lstatSync(at);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return { files: [], problems: [] };
|
|
26
|
+
}
|
|
27
|
+
if (!held.isDirectory() || held.isSymbolicLink())
|
|
28
|
+
return { files: [], problems: [{ path: CHECK_SHOTS_DIR, problem: FOLDER_PROBLEM }] };
|
|
29
|
+
}
|
|
30
|
+
let real;
|
|
31
|
+
try {
|
|
32
|
+
real = realpathSync(folder);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return { files: [], problems: [{ path: CHECK_SHOTS_DIR, problem: FOLDER_PROBLEM }] };
|
|
36
|
+
}
|
|
37
|
+
if (real !== folder)
|
|
38
|
+
return { files: [], problems: [{ path: CHECK_SHOTS_DIR, problem: FOLDER_PROBLEM }] };
|
|
39
|
+
let names;
|
|
40
|
+
try {
|
|
41
|
+
names = readdirSync(folder).filter(name => IMAGE_NAME.test(name)).sort();
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return { files: [], problems: [{ path: CHECK_SHOTS_DIR, problem: "the folder couldn't be listed" }] };
|
|
45
|
+
}
|
|
46
|
+
const out = { files: [], problems: [] };
|
|
47
|
+
for (const name of names) {
|
|
48
|
+
const path = `${CHECK_SHOTS_DIR}/${name}`;
|
|
49
|
+
if (out.files.length >= CHECK_SHOTS_MAX) {
|
|
50
|
+
out.problems.push({ path, problem: `only the first ${CHECK_SHOTS_MAX} screenshots are kept` });
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const read = readMailbox(join(folder, name), SCREENSHOT_BYTE_CAP);
|
|
54
|
+
if (!read.ok) {
|
|
55
|
+
out.problems.push({ path, problem: read.problem });
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const valid = validateScreenshotBytes(read.raw);
|
|
59
|
+
if (!valid.ok) {
|
|
60
|
+
out.problems.push({ path, problem: valid.problem });
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
out.files.push({ path, raw: read.raw, kind: valid.kind });
|
|
64
|
+
}
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
export function keepCheckScreenshots(store, root, runId, checkout, commit, now) {
|
|
68
|
+
if (!/^[a-f0-9]{40}$/.test(commit))
|
|
69
|
+
return [];
|
|
70
|
+
const shots = collectCheckScreenshots(checkout);
|
|
71
|
+
try {
|
|
72
|
+
shots.files.forEach((one, at) => {
|
|
73
|
+
storeEvidence(store, root, runId, "screenshot", `check-shot-${at + 1}.${one.kind === "png" ? "png" : "jpg"}`, one.raw, checkScreenshotCapture(one.path, commit, one.kind), now, { captureStatus: "ok" });
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
return [`The screenshots in ${CHECK_SHOTS_DIR} couldn't be kept: ${error instanceof Error ? error.message : String(error)}.`];
|
|
78
|
+
}
|
|
79
|
+
return [
|
|
80
|
+
...(shots.files.length === 0 ? [] : [`Kept ${shots.files.length} screenshot${shots.files.length === 1 ? "" : "s"} from ${CHECK_SHOTS_DIR}.`]),
|
|
81
|
+
...shots.problems.map(one => `Not kept: ${one.path}: ${one.problem}.`),
|
|
82
|
+
];
|
|
83
|
+
}
|