toolroll 0.9.125 → 0.9.127
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 +64 -0
- package/README.md +1 -1
- package/dist/agent-detect.js +23 -3
- package/dist/assignment.js +14 -4
- package/dist/bounded-spawn.js +5 -36
- package/dist/browser/workspace.css +1 -1
- package/dist/browser/workspace.js +29 -29
- package/dist/browser-open.js +49 -0
- package/dist/chat-acceptance.js +1 -1
- package/dist/check-only.js +1 -1
- package/dist/cli.js +2 -2
- package/dist/connect-cli.js +2 -8
- package/dist/contracts/engine-api.js +8 -0
- package/dist/direct-chat.js +26 -18
- package/dist/doctor.js +30 -3
- package/dist/easy-start.js +44 -17
- package/dist/engine-reads.js +34 -1
- package/dist/evals.js +17 -19
- package/dist/first-run.js +5 -1
- package/dist/flexible-conversation.js +79 -1
- package/dist/flexible-import.js +162 -4
- package/dist/flexible-save.js +51 -4
- package/dist/flexible-session.js +34 -8
- package/dist/flexible-start.js +2 -1
- package/dist/flow-code.js +2 -2
- package/dist/invoke.js +4 -4
- package/dist/landed-rows.js +138 -0
- package/dist/laptop-background.js +2 -11
- package/dist/linux-packages.js +46 -0
- package/dist/local-landing.js +46 -7
- package/dist/merge-checklist.js +62 -8
- package/dist/operate.js +90 -33
- package/dist/preflight.js +14 -0
- package/dist/process-identity.js +155 -0
- package/dist/quick-start.js +6 -1
- package/dist/release.js +8 -0
- package/dist/result-follow-ups.js +8 -1
- package/dist/revision-catch-up.js +98 -0
- package/dist/runner-process.js +9 -25
- package/dist/sandbox-launch.js +3 -2
- package/dist/sandbox-runtime.js +115 -15
- package/dist/sandbox-tools.js +91 -6
- package/dist/server/direct-chat.js +4 -3
- package/dist/server/engine-api.js +13 -8
- package/dist/server/merge-ready-view.js +4 -2
- package/dist/server/pages.js +5 -2
- package/dist/server/render-pages.js +1 -0
- package/dist/server/render-results.js +9 -7
- package/dist/server/render-tasks.js +2 -2
- package/dist/server/task-views.js +16 -9
- package/dist/server/tasks.js +2 -2
- package/dist/shown-text.js +14 -0
- package/dist/skill-library.js +2 -12
- package/dist/status-probe.js +32 -0
- package/dist/task-base.js +13 -2
- package/dist/task-status.js +18 -8
- package/dist/teardown-git.js +6 -0
- package/dist/telegram-status.js +1 -1
- package/dist/toolroll-update-cli.js +2 -1
- package/dist/toolroll-update.js +4 -0
- package/dist/trust-repair.js +187 -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/unreachable.js +15 -0
- package/dist/work-index.js +51 -3
- package/dist/workspace-ui.js +4 -2
- package/package.json +1 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
const set = (env, name) => (env[name] ?? "") !== "";
|
|
3
|
+
export function noBrowserReason(env = process.env, platform = process.platform) {
|
|
4
|
+
if (chosenCommand(env) !== null || (platform !== "darwin" && platform !== "win32" && browserEntry(env) !== null))
|
|
5
|
+
return null;
|
|
6
|
+
const display = set(env, "DISPLAY") || set(env, "WAYLAND_DISPLAY");
|
|
7
|
+
if ((set(env, "SSH_CONNECTION") || set(env, "SSH_TTY")) && !display)
|
|
8
|
+
return "this is an SSH session";
|
|
9
|
+
if (platform !== "darwin" && platform !== "win32" && !display)
|
|
10
|
+
return "there is no display here";
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
function chosenCommand(env) {
|
|
14
|
+
for (const name of ["TOOLROLL_BROWSER_COMMAND", "STANDING_ORDERS_BROWSER_COMMAND"])
|
|
15
|
+
if (set(env, name))
|
|
16
|
+
return env[name];
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
function browserEntry(env) {
|
|
20
|
+
const first = (env["BROWSER"] ?? "").split(":")[0].trim();
|
|
21
|
+
return first !== "" && /^[A-Za-z0-9._/+-]+$/.test(first) ? first : null;
|
|
22
|
+
}
|
|
23
|
+
export function browserCommand(url, env = process.env, platform = process.platform) {
|
|
24
|
+
const chosen = chosenCommand(env);
|
|
25
|
+
if (chosen !== null)
|
|
26
|
+
return [chosen, url];
|
|
27
|
+
if (platform === "darwin")
|
|
28
|
+
return ["open", url];
|
|
29
|
+
if (platform === "win32")
|
|
30
|
+
return ["cmd", "/c", "start", "", url];
|
|
31
|
+
return [browserEntry(env) ?? "xdg-open", url];
|
|
32
|
+
}
|
|
33
|
+
export function openAddress(url, options = {}) {
|
|
34
|
+
const [command, ...args] = browserCommand(url, options.env ?? process.env, options.platform ?? process.platform);
|
|
35
|
+
return startOpener(command, args, options);
|
|
36
|
+
}
|
|
37
|
+
export function startOpener(command, args, options = {}) {
|
|
38
|
+
if (noBrowserReason(options.env, options.platform) !== null)
|
|
39
|
+
return false;
|
|
40
|
+
try {
|
|
41
|
+
const child = (options.spawn ?? spawn)(command, [...args], { detached: true, stdio: "ignore" });
|
|
42
|
+
child.on("error", () => { });
|
|
43
|
+
child.unref();
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
package/dist/chat-acceptance.js
CHANGED
|
@@ -10,7 +10,7 @@ export function acceptanceStatus(proof, accepted, check) {
|
|
|
10
10
|
if (manualReviewOnly(proof))
|
|
11
11
|
return "You check the remaining requirements";
|
|
12
12
|
if (proof?.verdict === "verified" && check !== "passed") {
|
|
13
|
-
return check === undefined ? "Open the result to see its checks" : check === "failed" ? "Checks failed" : check === "running" ? "Checks running" : "The check result couldn't be read";
|
|
13
|
+
return check === undefined ? "Open the result to see its checks" : check === "failed" ? "Checks failed" : check === "running" ? "Checks running" : check === "stale" ? "The check command changed since they ran" : "The check result couldn't be read";
|
|
14
14
|
}
|
|
15
15
|
return proof === null ? "No checks recorded" : ({ verified: "Checks passed", attested: "Checks reported by the agent", short: "Some required material is missing", refuted: "Saved result doesn't match the approved plan" }[proof.verdict] ?? "Some required material is missing");
|
|
16
16
|
}
|
package/dist/check-only.js
CHANGED
|
@@ -77,7 +77,7 @@ export function requestMissingRechecks(store, root, now) {
|
|
|
77
77
|
if (run === null || run.finishedAt === null)
|
|
78
78
|
return 0;
|
|
79
79
|
const state = approvedCheckStateOf(assignmentChecksForRun(store, root, auth.run, now));
|
|
80
|
-
if (state === "not-run" || state === "unreadable")
|
|
80
|
+
if (state === "not-run" || state === "unreadable" || state === "stale")
|
|
81
81
|
return claimRecheck(store, auth.id, now) === null ? 0 : 1;
|
|
82
82
|
if (state !== "running" && checkOnlyRecoveryProblem(store, auth.run) === null) {
|
|
83
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);
|
package/dist/cli.js
CHANGED
|
@@ -383,6 +383,7 @@ async function dispatch(argv, write, mainOptions) {
|
|
|
383
383
|
enrolled: async (repo) => { const loaded = await loadRepos(registryBeside(databaseFile)); return !("error" in loaded) && loaded.repos.includes(repo); },
|
|
384
384
|
admit: repo => runReposCommand(["add", repo], write, mainOptions.onboard),
|
|
385
385
|
startUp: () => runOperate("up", [], write, mainOptions.operate ?? {}),
|
|
386
|
+
setUp: async () => { const mode = (await import("./easy-start.js")).localModeRead(databaseFile); return mode === "on" || mode === "off"; },
|
|
386
387
|
openBrowser: async (url) => { (await import("./operate.js")).openBrowser(url); },
|
|
387
388
|
...mainOptions.quickStart,
|
|
388
389
|
});
|
|
@@ -1454,8 +1455,7 @@ async function runRemoteTuiCommand(argv, write, connectOptions) {
|
|
|
1454
1455
|
const origin = profile.origin;
|
|
1455
1456
|
const openUrl = async (path) => {
|
|
1456
1457
|
const target = new URL(path, origin).href;
|
|
1457
|
-
(await import("./operate.js")).openBrowser(target)
|
|
1458
|
-
return `Opened ${target} in your browser.`;
|
|
1458
|
+
return (await import("./operate.js")).openBrowser(target) ? `Opened ${target} in your browser.` : `Open ${target} in a browser.`;
|
|
1459
1459
|
};
|
|
1460
1460
|
const ended = await runTuiBinary({
|
|
1461
1461
|
binary: chosen.binary,
|
package/dist/connect-cli.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { openAddress } from './browser-open.js';
|
|
2
2
|
import { constants, closeSync, existsSync, fstatSync, fsyncSync, lstatSync, mkdirSync, openSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { request as httpRequest } from 'node:http';
|
|
4
4
|
import { request as httpsRequest } from 'node:https';
|
|
@@ -347,13 +347,7 @@ function pairPostJson(origin, path, body) {
|
|
|
347
347
|
});
|
|
348
348
|
}
|
|
349
349
|
function launchBrowserUrl(url) {
|
|
350
|
-
|
|
351
|
-
const args = process.platform === 'win32' ? ['/c', 'start', '', url] : [url];
|
|
352
|
-
try {
|
|
353
|
-
const child = spawn(cmd, args, { stdio: 'ignore', detached: true });
|
|
354
|
-
child.unref();
|
|
355
|
-
}
|
|
356
|
-
catch { }
|
|
350
|
+
openAddress(url);
|
|
357
351
|
}
|
|
358
352
|
async function pairViaBrowser(origin, stderr, options) {
|
|
359
353
|
const started = await pairPostJson(origin, '/api/connect/pair/start');
|
|
@@ -110,6 +110,8 @@ const workRowSchema = z.object({
|
|
|
110
110
|
chip: z.string().nullable(),
|
|
111
111
|
group: z.enum(WORK_ROW_GROUPS),
|
|
112
112
|
rank: z.number().int(),
|
|
113
|
+
check: z.enum(["failed", "stale", "unreadable"]).optional(),
|
|
114
|
+
landed: z.string().optional(),
|
|
113
115
|
detail: z.string().nullable(),
|
|
114
116
|
problem: z.string().nullable(),
|
|
115
117
|
need: needRowSchema.nullable(),
|
|
@@ -162,6 +164,7 @@ export const stepCardsSchema = z.object({
|
|
|
162
164
|
headline: z.string().nullable(),
|
|
163
165
|
liveRun: z.number().int().nullable(),
|
|
164
166
|
latestRun: z.number().int().nullable(),
|
|
167
|
+
familyBuilds: z.array(z.number().int()).optional(),
|
|
165
168
|
models: z.array(z.object({ phase: z.string(), provider: z.string(), model: z.string(), chosen: z.enum(["recommended", "override", "pinned"]) })).nullable(),
|
|
166
169
|
cards: z.array(stepCardSchema).nullable(),
|
|
167
170
|
review: z.object({ run: z.number().int(), receipt: z.string().regex(/^[0-9a-f]{64}$/), source: z.string(),
|
|
@@ -183,6 +186,10 @@ export const stepCardsSchema = z.object({
|
|
|
183
186
|
agentChoices: z.object({ plan: z.array(z.object({ provider: z.string(), model: z.string() })), build: z.array(z.object({ provider: z.string(), model: z.string() })) }).nullable(),
|
|
184
187
|
pendingAgentChange: z.object({ phase: z.enum(["plan", "build"]), provider: z.string(), model: z.string(), when: z.enum(["next-run", "restart"]), by: z.string(), at: z.string(),
|
|
185
188
|
problem: z.string().nullable() }).nullable(),
|
|
189
|
+
landing: z.object({ words: z.string(), reverted: z.boolean() }).nullable(),
|
|
190
|
+
check: z.enum(["failed", "stale", "unreadable"]).optional(),
|
|
191
|
+
runChecks: z.object({ run: z.number().int(), level: z.enum(["quick", "full"]) }).optional(),
|
|
192
|
+
behindMain: z.object({ run: z.number().int(), receipt: z.string().regex(/^[0-9a-f]{64}$/), source: z.string(), main: z.string(), behind: z.number().int(), note: z.string() }).optional(),
|
|
186
193
|
room: z.string(),
|
|
187
194
|
});
|
|
188
195
|
export const approvalCardSchema = z.object({
|
|
@@ -485,6 +492,7 @@ export const directChatDetailSchema = z.object({
|
|
|
485
492
|
changedFiles: z.array(z.string()),
|
|
486
493
|
diffText: z.string(),
|
|
487
494
|
dirty: z.boolean(),
|
|
495
|
+
unread: z.literal(true).optional(),
|
|
488
496
|
}),
|
|
489
497
|
});
|
|
490
498
|
export const directChatShipPreviewSchema = z.object({
|
package/dist/direct-chat.js
CHANGED
|
@@ -599,12 +599,29 @@ async function defaultPrepareCloneAsync(input) {
|
|
|
599
599
|
mainDirtyFiles: cloned.mainDirtyFiles.map(sanitizeLine),
|
|
600
600
|
};
|
|
601
601
|
}
|
|
602
|
+
const UNREAD_DIFF = Object.freeze({ changedFiles: [], diffText: "", dirty: false, unread: true });
|
|
603
|
+
function diffCacheOf(raw) {
|
|
604
|
+
if (typeof raw !== "string" || raw === "")
|
|
605
|
+
return { changedFiles: [], diffText: "", dirty: false };
|
|
606
|
+
try {
|
|
607
|
+
const parsed = JSON.parse(raw);
|
|
608
|
+
return {
|
|
609
|
+
changedFiles: Array.isArray(parsed.changedFiles) ? parsed.changedFiles.filter((x) => typeof x === "string") : [],
|
|
610
|
+
diffText: typeof parsed.diffText === "string" ? parsed.diffText : "",
|
|
611
|
+
dirty: parsed.dirty === true,
|
|
612
|
+
...(parsed.unread === true ? { unread: true } : {}),
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
catch {
|
|
616
|
+
return { changedFiles: [], diffText: "", dirty: false };
|
|
617
|
+
}
|
|
618
|
+
}
|
|
602
619
|
function defaultReadDiff(input) {
|
|
603
620
|
if (!existsSync(input.binding.clonePath))
|
|
604
|
-
return {
|
|
621
|
+
return { ...UNREAD_DIFF };
|
|
605
622
|
const verified = assertTrustedCloneGit(input.binding);
|
|
606
623
|
if (!verified.ok)
|
|
607
|
-
return {
|
|
624
|
+
return { ...UNREAD_DIFF };
|
|
608
625
|
try {
|
|
609
626
|
const statusLines = runTrustedCloneGit(input.binding, ["status", "--porcelain"])
|
|
610
627
|
.split("\n")
|
|
@@ -633,7 +650,7 @@ function defaultReadDiff(input) {
|
|
|
633
650
|
};
|
|
634
651
|
}
|
|
635
652
|
catch {
|
|
636
|
-
return {
|
|
653
|
+
return { ...UNREAD_DIFF };
|
|
637
654
|
}
|
|
638
655
|
}
|
|
639
656
|
function snapshotCloneTree(binding) {
|
|
@@ -882,7 +899,11 @@ export class DirectChatHost {
|
|
|
882
899
|
}
|
|
883
900
|
refreshDiffCache(thread) {
|
|
884
901
|
const binding = this.bindingOf(thread);
|
|
885
|
-
const
|
|
902
|
+
const read = binding === null ? thread.isLegacy ? null : { ...UNREAD_DIFF } : this.readDiffFn({ binding, baseSha: thread.baseSha });
|
|
903
|
+
const saved = diffCacheOf(this.store.handle.prepare(`SELECT diff_cache_json FROM direct_chat_thread WHERE id = ?`).get(thread.id)?.["diff_cache_json"]);
|
|
904
|
+
if (read === null)
|
|
905
|
+
return saved;
|
|
906
|
+
const diff = read.unread === true ? { ...saved, unread: true } : { changedFiles: read.changedFiles, diffText: read.diffText, dirty: read.dirty };
|
|
886
907
|
this.store.handle
|
|
887
908
|
.prepare(`UPDATE direct_chat_thread SET diff_cache_json = ? WHERE id = ?`)
|
|
888
909
|
.run(JSON.stringify(diff), thread.id);
|
|
@@ -2039,20 +2060,7 @@ export class DirectChatHost {
|
|
|
2039
2060
|
mainDirtyFiles = [];
|
|
2040
2061
|
}
|
|
2041
2062
|
}
|
|
2042
|
-
|
|
2043
|
-
if (typeof raw["diff_cache_json"] === "string" && raw["diff_cache_json"] !== "") {
|
|
2044
|
-
try {
|
|
2045
|
-
const parsed = JSON.parse(raw["diff_cache_json"]);
|
|
2046
|
-
diffCache = {
|
|
2047
|
-
changedFiles: Array.isArray(parsed.changedFiles) ? parsed.changedFiles.filter((x) => typeof x === "string") : [],
|
|
2048
|
-
diffText: typeof parsed.diffText === "string" ? parsed.diffText : "",
|
|
2049
|
-
dirty: parsed.dirty === true,
|
|
2050
|
-
};
|
|
2051
|
-
}
|
|
2052
|
-
catch {
|
|
2053
|
-
diffCache = { changedFiles: [], diffText: "", dirty: false };
|
|
2054
|
-
}
|
|
2055
|
-
}
|
|
2063
|
+
const diffCache = diffCacheOf(raw["diff_cache_json"]);
|
|
2056
2064
|
return {
|
|
2057
2065
|
id: String(raw["id"]),
|
|
2058
2066
|
owner: String(raw["owner"]),
|
package/dist/doctor.js
CHANGED
|
@@ -7,8 +7,23 @@ import { envelopeJson } from "./envelope.js";
|
|
|
7
7
|
import { GIT_FLOOR_WORDS, installedGitFloorProblem } from "./git-floor.js";
|
|
8
8
|
import { run as runCommand } from "./exec.js";
|
|
9
9
|
import { OWN_KEY_ENV } from "./keys.js";
|
|
10
|
+
import { processIdentityProblem } from "./process-identity.js";
|
|
10
11
|
import { ALL_CREDENTIAL_ENV } from "./provider.js";
|
|
11
|
-
import { SANDBOX_RUNTIME,
|
|
12
|
+
import { SANDBOX_RUNTIME, sandboxAdviceLines, sandboxRuntimeDiagnosis, sandboxRuntimeWords, UNCONFINED_OPT_IN } from "./sandbox-runtime.js";
|
|
13
|
+
async function agentTrustProblems(env, uid) {
|
|
14
|
+
const { excludedFolders, statusBinaryDiagnosis } = await import("./status-probe.js");
|
|
15
|
+
const { agentTrustWords } = await import("./agent-detect.js");
|
|
16
|
+
const { platformAcl } = await import("./trusted-path.js");
|
|
17
|
+
const untrusted = await excludedFolders({}) ?? [];
|
|
18
|
+
const path = (env["PATH"] ?? "").split(":").filter(one => one.startsWith("/")).join(":");
|
|
19
|
+
const found = [];
|
|
20
|
+
for (const [binary, name] of [["claude", "Claude Code"], ["codex", "Codex"]]) {
|
|
21
|
+
const words = agentTrustWords(statusBinaryDiagnosis(binary, { path, uid, untrusted, acl: platformAcl() }));
|
|
22
|
+
if (words !== null)
|
|
23
|
+
found.push({ name, problem: words });
|
|
24
|
+
}
|
|
25
|
+
return found;
|
|
26
|
+
}
|
|
12
27
|
const CREDENTIAL_NAME = /(?:^|_)(?:API_?KEY|ACCESS_?KEY|PRIVATE_?KEY|SECRET|SECRET_?KEY|TOKEN|AUTH_?TOKEN|PASSWORD|PASSWD|CREDENTIALS?|PAT)(?:_|$)/i;
|
|
13
28
|
const POINTER_NAME = /(?:_FILE|_PATH|_DIR|_SOCK|_URL|_HOST)$/i;
|
|
14
29
|
const CREDENTIAL_FLAG = /^--?(?:token|api-?key|key|secret|password|auth-token)$/i;
|
|
@@ -343,6 +358,8 @@ export function doctorLines(report) {
|
|
|
343
358
|
const lines = [];
|
|
344
359
|
if (report.git?.problem != null)
|
|
345
360
|
lines.push(`Git: ${report.git.problem}`, "");
|
|
361
|
+
if (report.processIdentity?.problem != null)
|
|
362
|
+
lines.push(`Processes: ${report.processIdentity.problem}. Toolroll's worker won't start until it can.`, "");
|
|
346
363
|
if (report.findings.length === 0 && report.unreadable.length === 0)
|
|
347
364
|
lines.push("No secrets found in Toolroll's service. A build can't read a key from it.");
|
|
348
365
|
else if (report.findings.length > 0)
|
|
@@ -359,8 +376,13 @@ export function doctorLines(report) {
|
|
|
359
376
|
}
|
|
360
377
|
for (const note of report.notes)
|
|
361
378
|
lines.push("", `Note: ${note}`);
|
|
379
|
+
const optIn = report.sandbox?.repair?.includes(UNCONFINED_OPT_IN) === true;
|
|
362
380
|
if (report.sandbox !== undefined)
|
|
363
|
-
lines.push("", `Sandbox: ${sandboxRuntimeWords()}${report.sandbox.problem === null ? ", working here." : `, not available here: ${report.sandbox.problem}. Builds don't start unless an instance operator allows unconfined agents
|
|
381
|
+
lines.push("", `Sandbox: ${sandboxRuntimeWords()}${report.sandbox.problem === null ? ", working here." : `, not available here: ${report.sandbox.problem}. Builds don't start ${optIn ? "here." : "unless an instance operator allows unconfined agents."}`}`);
|
|
382
|
+
if (report.sandbox?.repair !== undefined && report.sandbox.repair.length > 0)
|
|
383
|
+
lines.push(...report.sandbox.repair, ...report.sandbox.kind === "trust" ? ["Then run `toolroll doctor` again."] : []);
|
|
384
|
+
for (const agent of report.agents ?? [])
|
|
385
|
+
lines.push("", `${agent.name}: ${agent.problem}`);
|
|
364
386
|
if (report.checked.length > 0)
|
|
365
387
|
lines.push("", "Checked:", ...report.checked.map(one => ` ${one}`));
|
|
366
388
|
return lines;
|
|
@@ -378,10 +400,15 @@ export async function runDoctorCommand(argv, write, deps = {}) {
|
|
|
378
400
|
return 2;
|
|
379
401
|
}
|
|
380
402
|
const report = await auditServiceEnvironment(deps);
|
|
381
|
-
|
|
403
|
+
const diagnosis = sandboxRuntimeDiagnosis();
|
|
404
|
+
report.sandbox = { engine: SANDBOX_RUNTIME.name, version: SANDBOX_RUNTIME.version, problem: diagnosis.ok ? null : diagnosis.why, ...(diagnosis.ok ? {} : { kind: diagnosis.kind, repair: sandboxAdviceLines(diagnosis) }) };
|
|
405
|
+
report.agents = await (deps.agentProblems ?? (() => agentTrustProblems(deps.env ?? process.env, deps.uid ?? process.getuid?.() ?? -1)))();
|
|
382
406
|
report.git = { floor: GIT_FLOOR_WORDS, problem: deps.gitFloorProblem === undefined ? installedGitFloorProblem() : deps.gitFloorProblem };
|
|
383
407
|
if (report.git.problem !== null)
|
|
384
408
|
report.ok = false;
|
|
409
|
+
report.processIdentity = { problem: deps.processIdentityProblem === undefined ? processIdentityProblem() : deps.processIdentityProblem };
|
|
410
|
+
if (report.processIdentity.problem !== null)
|
|
411
|
+
report.ok = false;
|
|
385
412
|
if (json)
|
|
386
413
|
write(envelopeJson({ command: "doctor", ...report }));
|
|
387
414
|
else
|
package/dist/easy-start.js
CHANGED
|
@@ -60,9 +60,33 @@ export async function runEasyStart(mode, args, seams) {
|
|
|
60
60
|
if (refusedTooDeep())
|
|
61
61
|
return EXIT.refused;
|
|
62
62
|
const sandbox = await seams.sandbox();
|
|
63
|
+
const others = await (seams.prerequisites?.() ?? Promise.resolve({ blockers: [], advisories: [] }));
|
|
64
|
+
const blockers = [];
|
|
65
|
+
let passwordInstead = false;
|
|
63
66
|
if (sandbox.missing.length > 0) {
|
|
64
67
|
const { missingSandboxToolsWords } = await import("./sandbox-runtime.js");
|
|
65
|
-
|
|
68
|
+
blockers.push(missingSandboxToolsWords(sandbox.missing));
|
|
69
|
+
}
|
|
70
|
+
else if (sandbox.problem !== null) {
|
|
71
|
+
const { UNCONFINED_OPT_IN } = await import("./sandbox-runtime.js");
|
|
72
|
+
blockers.push([`Agents can't run in a sandbox here: ${sandbox.problem}.`, ...(sandbox.repair ?? []).filter(line => line !== UNCONFINED_OPT_IN)]);
|
|
73
|
+
passwordInstead = others.blockers.length === 0;
|
|
74
|
+
}
|
|
75
|
+
blockers.push(...others.blockers);
|
|
76
|
+
if (blockers.length > 0) {
|
|
77
|
+
if (blockers.length === 1) {
|
|
78
|
+
for (const line of blockers[0])
|
|
79
|
+
write(line);
|
|
80
|
+
if (sandbox.missing.length === 0 && sandbox.problem !== null)
|
|
81
|
+
write("Then run toolroll again.");
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
write("Toolroll can't start on this computer yet. Fix these, then run toolroll again:");
|
|
85
|
+
blockers.forEach((lines, index) => lines.forEach((line, at) => write(at === 0 ? `${index + 1}. ${line}` : ` ${line}`)));
|
|
86
|
+
}
|
|
87
|
+
if (passwordInstead)
|
|
88
|
+
write("To start now with a password instead, run `toolroll up`. Agents then run only once the sandbox works, or if an instance operator lets them run without OS confinement (`toolroll config unconfined-agents allow`).");
|
|
89
|
+
for (const line of others.advisories)
|
|
66
90
|
write(line);
|
|
67
91
|
return EXIT.refused;
|
|
68
92
|
}
|
|
@@ -147,9 +171,12 @@ export async function runEasyStart(mode, args, seams) {
|
|
|
147
171
|
return EXIT.ok;
|
|
148
172
|
};
|
|
149
173
|
if (seams.localMode() !== "on") {
|
|
150
|
-
const problem =
|
|
174
|
+
const { problem, repair } = await seams.sandbox();
|
|
151
175
|
if (problem !== null)
|
|
152
176
|
write(`Toolroll can't start without a password here: ${problem}.`);
|
|
177
|
+
if (problem !== null)
|
|
178
|
+
for (const line of repair ?? [])
|
|
179
|
+
write(line);
|
|
153
180
|
const saved = seams.savedLogin();
|
|
154
181
|
write(saved === null ? `Toolroll is on ${url}. Sign in with your password.` : `Toolroll is on ${url}. Your password: run \`cat -- '${saved.replaceAll("'", "'\\''")}'\``);
|
|
155
182
|
await seams.openBrowser(url);
|
|
@@ -159,6 +186,7 @@ export async function runEasyStart(mode, args, seams) {
|
|
|
159
186
|
const opened = await seams.openSignedIn();
|
|
160
187
|
if (!opened.ok) {
|
|
161
188
|
write(`Toolroll is on ${url}, but it couldn't sign you in: ${opened.message}.`);
|
|
189
|
+
write(`Run \`toolroll\` to use it in this terminal.${opened.message.includes("toolroll password set") ? "" : " To use a browser, run `toolroll password set` and sign in with that password."}`);
|
|
162
190
|
const child = ownedNow();
|
|
163
191
|
if (child !== null)
|
|
164
192
|
stopOwned(child);
|
|
@@ -193,17 +221,14 @@ export async function runEasyStart(mode, args, seams) {
|
|
|
193
221
|
const target = new URL(setup ? "/password/set" : `${page}#agents`, url);
|
|
194
222
|
if (setup)
|
|
195
223
|
target.searchParams.set("next", page);
|
|
196
|
-
await seams.openBrowser(target.href);
|
|
197
|
-
return "In the browser, open Agents → Change agents and save the new builder.";
|
|
224
|
+
const opened = await seams.openBrowser(target.href);
|
|
225
|
+
return opened === false ? `Open ${target.href} in a browser, then Agents → Change agents and save the new builder.` : "In the browser, open Agents → Change agents and save the new builder.";
|
|
198
226
|
},
|
|
199
227
|
openBrowser: async (page) => {
|
|
200
|
-
if (page === "projects") {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (page === "lead-providers") {
|
|
205
|
-
await seams.openBrowser(new URL("/settings/lead#lead-config", url).href);
|
|
206
|
-
return "Opened Lead settings in your browser.";
|
|
228
|
+
if (page === "projects" || page === "lead-providers") {
|
|
229
|
+
const href = new URL(page === "projects" ? "/projects" : "/settings/lead#lead-config", url).href;
|
|
230
|
+
const opened = await seams.openBrowser(href);
|
|
231
|
+
return opened === false ? `Open ${href} in a browser.` : `Opened ${page === "projects" ? "Projects" : "Lead settings"} in your browser.`;
|
|
207
232
|
}
|
|
208
233
|
const opened = await seams.openSignedIn(page);
|
|
209
234
|
return opened.ok ? "Opened in your browser." : `The browser couldn't be opened: ${opened.message}.`;
|
|
@@ -287,12 +312,14 @@ export function defaultEasyStartSeams(options) {
|
|
|
287
312
|
remote: (await import("./local-owner.js")).localOwnerRequested(),
|
|
288
313
|
}),
|
|
289
314
|
sandbox: async () => {
|
|
290
|
-
const { missingLinuxSandboxTools,
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
315
|
+
const { missingLinuxSandboxTools, sandboxAdviceLines, sandboxRuntimeDiagnosis } = await import("./sandbox-runtime.js");
|
|
316
|
+
const missing = process.platform === "linux" ? missingLinuxSandboxTools() : [];
|
|
317
|
+
if (missing.length > 0)
|
|
318
|
+
return { missing, problem: null };
|
|
319
|
+
const diagnosis = sandboxRuntimeDiagnosis();
|
|
320
|
+
return diagnosis.ok ? { missing, problem: null } : { missing, problem: diagnosis.why, repair: sandboxAdviceLines(diagnosis) };
|
|
295
321
|
},
|
|
322
|
+
prerequisites: async () => (await import("./preflight.js")).startPrerequisites(),
|
|
296
323
|
passwordByLaptopStart: () => {
|
|
297
324
|
const store = openStoreReadOnly(file);
|
|
298
325
|
if (store === null)
|
|
@@ -323,7 +350,7 @@ export function defaultEasyStartSeams(options) {
|
|
|
323
350
|
},
|
|
324
351
|
spawnUp: args => spawnOwnedUp(args, { cwd, databaseFile: file }),
|
|
325
352
|
runUpForeground: async (args) => (await import("./operate.js")).runOperate("up", [...args, "--db", file], options.write, options.operate ?? {}),
|
|
326
|
-
openBrowser: async (url) =>
|
|
353
|
+
openBrowser: async (url) => (await import("./operate.js")).openBrowser(url),
|
|
327
354
|
openSignedIn: page => openLocalSignIn(file, options.build, page === undefined ? {} : { then: page }),
|
|
328
355
|
openTui: async (session) => {
|
|
329
356
|
const { chooseTuiBinary, runTuiBinary } = await import("./tui-launch.js");
|
package/dist/engine-reads.js
CHANGED
|
@@ -3,6 +3,9 @@ import { codexOfflineDependencySuggestion, failedAttemptSentence, latestFinished
|
|
|
3
3
|
import { pendingAgentChangeOf, 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
|
+
import { behindMainOf, landedNowOf, upToDateNote } from "./merge-checklist.js";
|
|
7
|
+
import { publishesThroughPullRequests } from "./local-landing.js";
|
|
8
|
+
import { liveQuickCommand } from "./check-levels.js";
|
|
6
9
|
import { assignmentStageOf, stageOfCode } from "./task-status.js";
|
|
7
10
|
import { taskRoad } from "./first-run.js";
|
|
8
11
|
import { stepRowsOf } from "./workspace-ui.js";
|
|
@@ -121,9 +124,39 @@ export function stepCardsOf({ store, family, now, access, evidenceRoot, viewer =
|
|
|
121
124
|
scopeDigest: scope?.digest ?? null,
|
|
122
125
|
agentChoices: scope === null || !withChoices ? null : agentChoicesOf(store, current.id, ref, now),
|
|
123
126
|
pendingAgentChange: ref === null ? null : pendingAgentChangeOf(store, ref.id),
|
|
127
|
+
landing: assignment === null ? null : landedNowOf(store, assignment),
|
|
128
|
+
...(card?.status.check === "failed" || card?.status.check === "stale" || card?.status.check === "unreadable" ? { check: card.status.check } : {}),
|
|
129
|
+
...(() => { const offer = runChecksOfferOf(store, assignment, card?.status.check ?? null); return offer === null ? {} : { runChecks: offer }; })(),
|
|
130
|
+
...(() => { const offer = assignment === null || assignment.receipt?.taskId !== current.id ? null : behindMainOfferOf(store, assignment, scope?.digest ?? null); return offer === null ? {} : { behindMain: offer }; })(),
|
|
131
|
+
familyBuilds: familyBuildsOf(store, family, current.refId, runs),
|
|
124
132
|
room: `task:${encodeURIComponent(root.id)}`,
|
|
125
133
|
};
|
|
126
134
|
}
|
|
135
|
+
function familyBuildsOf(store, family, currentRef, currentRuns) {
|
|
136
|
+
const isBuild = (run) => run.role === "builder" || run.role === "scout" || run.role === "repair";
|
|
137
|
+
return family.versions.flatMap(version => version.refId === currentRef ? currentRuns : store.runsFor(version.refId))
|
|
138
|
+
.filter(isBuild).map(run => run.id).sort((a, b) => b - a);
|
|
139
|
+
}
|
|
140
|
+
function runChecksOfferOf(store, assignment, check) {
|
|
141
|
+
if (check !== "failed" && check !== "stale" && check !== "unreadable" && check !== "not-run")
|
|
142
|
+
return null;
|
|
143
|
+
const receipt = assignment?.receipt ?? null;
|
|
144
|
+
if (receipt === null || receipt.head === null || receipt.completionKind === "research-report" || assignment.repo === null || store.isDemo())
|
|
145
|
+
return null;
|
|
146
|
+
const level = store.liveVerifyCommand(assignment.repo) !== null ? "full" : liveQuickCommand(store, assignment.repo) !== null ? "quick" : null;
|
|
147
|
+
return level === null ? null : { run: receipt.runId, level };
|
|
148
|
+
}
|
|
149
|
+
function behindMainOfferOf(store, assignment, scopeDigest) {
|
|
150
|
+
const receipt = assignment.receipt;
|
|
151
|
+
if (assignment.state !== "complete" || receipt === null || receipt.head === null || receipt.completionKind === "research-report" || assignment.repo === null || store.isDemo())
|
|
152
|
+
return null;
|
|
153
|
+
if (publishesThroughPullRequests(store, assignment.repo) || landedNowOf(store, assignment) !== null)
|
|
154
|
+
return null;
|
|
155
|
+
const standing = behindMainOf(store, assignment, undefined);
|
|
156
|
+
if (standing === null || standing.main === null || standing.behind === null || standing.behind === 0 || standing.conflict !== null)
|
|
157
|
+
return null;
|
|
158
|
+
return { run: receipt.runId, receipt: receipt.digest, source: revisionSourceOf(scopeDigest), main: standing.main, behind: standing.behind, note: upToDateNote(standing.main) };
|
|
159
|
+
}
|
|
127
160
|
export const SHELL_NO_RESULT = "This build has no saved result yet. Wait for it to finish (or stop it), then open the build shell.";
|
|
128
161
|
export const SHELL_NO_COMMIT = "This build has no saved commit to open a terminal on.";
|
|
129
162
|
function shellOf(store, family, runId) {
|
|
@@ -610,7 +643,7 @@ export function threadDiffOf(thread, turn, changes, seen = {}) {
|
|
|
610
643
|
if (!changes.ok)
|
|
611
644
|
return empty(`This thread's changes can't be read: ${cleanLiveText(changes.message)}`);
|
|
612
645
|
if ("none" in changes && seen.edited === true)
|
|
613
|
-
return empty("The agent has uncommitted edits. Ask it to commit them
|
|
646
|
+
return empty("The agent has uncommitted edits. Ask it to commit them, or end the thread and save it as a branch: that saves them too.");
|
|
614
647
|
if ("none" in changes)
|
|
615
648
|
return empty("No committed changes yet. Ask the agent to commit its work: Ship sends committed work only.");
|
|
616
649
|
const files = patchFiles(changes.patch).map((text, index) => {
|
package/dist/evals.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { identityProvider, lstartToIso, processIdentity } from "./process-identity.js";
|
|
1
2
|
import { execFileSync, spawn } from "node:child_process";
|
|
2
3
|
import { createHash, randomBytes } from "node:crypto";
|
|
3
4
|
import { closeSync, constants, lstatSync, mkdirSync, mkdtempSync, openSync, readdirSync, realpathSync, rmSync, writeSync } from "node:fs";
|
|
@@ -785,33 +786,30 @@ export function recoverEvalCampaigns(store, now, options = {}) {
|
|
|
785
786
|
return out;
|
|
786
787
|
}
|
|
787
788
|
export function processStartOf(pid) {
|
|
788
|
-
if (
|
|
789
|
+
if (!Number.isSafeInteger(pid) || pid <= 0)
|
|
789
790
|
return null;
|
|
790
|
-
|
|
791
|
-
const raw = execFileSync("/bin/ps", ["-p", String(pid), "-o", "lstart="], {
|
|
792
|
-
encoding: "utf8", env: { PATH: "/usr/bin:/bin", LC_ALL: "C", TZ: "UTC" }, stdio: ["ignore", "pipe", "ignore"], maxBuffer: 1024, timeout: 2_000, killSignal: "SIGKILL",
|
|
793
|
-
}).trim().replace(/ +/g, " ");
|
|
794
|
-
return /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{1,2} \d{2}:\d{2}:\d{2} \d{4}$/.test(raw) ? raw : null;
|
|
795
|
-
}
|
|
796
|
-
catch {
|
|
797
|
-
return null;
|
|
798
|
-
}
|
|
791
|
+
return processIdentity(pid);
|
|
799
792
|
}
|
|
800
793
|
export function runnerMayBeAlive(pid, started) {
|
|
801
794
|
if (!processMayBeAlive(pid, false))
|
|
802
795
|
return false;
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
const
|
|
796
|
+
if (started === null)
|
|
797
|
+
return true;
|
|
798
|
+
const provider = identityProvider(started);
|
|
799
|
+
if (provider === null)
|
|
800
|
+
return true;
|
|
801
|
+
const now = processIdentity(pid, provider);
|
|
802
|
+
if (now === null)
|
|
803
|
+
return true;
|
|
804
|
+
if (provider === "proc")
|
|
805
|
+
return now === started;
|
|
806
|
+
const was = startMs(started), is = startMs(now);
|
|
806
807
|
return was === null || is === null || Math.abs(is - was) <= 2_000;
|
|
807
808
|
}
|
|
808
809
|
function startMs(raw) {
|
|
809
|
-
const
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
const utc = `${match[1]}, ${match[3].padStart(2, "0")} ${match[2]} ${match[5]} ${match[4]} GMT`;
|
|
813
|
-
const ms = Date.parse(utc);
|
|
814
|
-
return Number.isFinite(ms) && new Date(ms).toUTCString() === utc ? ms : null;
|
|
810
|
+
const iso = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(raw) ? raw : lstartToIso(raw);
|
|
811
|
+
const ms = iso === null ? NaN : Date.parse(iso);
|
|
812
|
+
return Number.isFinite(ms) ? ms : null;
|
|
815
813
|
}
|
|
816
814
|
export function abandonEvalCampaign(store, input) {
|
|
817
815
|
return store.transact(() => {
|
package/dist/first-run.js
CHANGED
|
@@ -2,6 +2,7 @@ import { run } from "./exec.js";
|
|
|
2
2
|
import { hardenedGit } from "./teardown-git.js";
|
|
3
3
|
import { githubIssues } from "./issues.js";
|
|
4
4
|
import { START_BUILDER_HREF } from "./needs-you.js";
|
|
5
|
+
import { CHECKS_OUT_OF_DATE } from "./task-status.js";
|
|
5
6
|
import { firstRunAgentLines, firstTaskOf, withNext } from "./agent-detect.js";
|
|
6
7
|
export const SIGN_IN_COMMAND = "claude auth login";
|
|
7
8
|
export const SANDBOX_COMMAND = "npx toolroll demo";
|
|
@@ -144,6 +145,7 @@ export function taskRoad(read, approved, built, facts) {
|
|
|
144
145
|
case "running": return { ...step, state: "current", say: "Checks running" };
|
|
145
146
|
case "failed": return { ...step, say: "Checks failed" };
|
|
146
147
|
case "unreadable": return { ...step, say: "Checks unreadable" };
|
|
148
|
+
case "stale": return { ...step, say: CHECKS_OUT_OF_DATE };
|
|
147
149
|
default: return step;
|
|
148
150
|
}
|
|
149
151
|
}
|
|
@@ -152,7 +154,8 @@ export function taskRoad(read, approved, built, facts) {
|
|
|
152
154
|
if (step.state === "current")
|
|
153
155
|
return facts.checks === "failed" ? { ...step, state: "stuck", say: "Checks failed" }
|
|
154
156
|
: facts.checks === "unreadable" ? { ...step, state: "stuck", say: "Checks unreadable" }
|
|
155
|
-
: facts.checks === "
|
|
157
|
+
: facts.checks === "stale" ? { ...step, state: "stuck", say: CHECKS_OUT_OF_DATE }
|
|
158
|
+
: facts.checks === "running" ? { ...step, say: "Checks running" } : step;
|
|
156
159
|
switch (facts.checks ?? null) {
|
|
157
160
|
case "passed": return step;
|
|
158
161
|
case "running": return { ...step, state: "current", say: "Checks running" };
|
|
@@ -160,6 +163,7 @@ export function taskRoad(read, approved, built, facts) {
|
|
|
160
163
|
case "not-run": return { ...step, state: "skipped", say: "Checks not run" };
|
|
161
164
|
case "off": return { ...step, state: "skipped", say: "Checks at release" };
|
|
162
165
|
case "unreadable": return { ...step, state: "stuck", say: "Checks unreadable", ...(complete ? {} : { needsYou: true }) };
|
|
166
|
+
case "stale": return { ...step, state: "stuck", say: CHECKS_OUT_OF_DATE, ...(complete ? {} : { needsYou: true }) };
|
|
163
167
|
default: return { ...step, state: "skipped" };
|
|
164
168
|
}
|
|
165
169
|
});
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { closeSync, constants as fsConstants, fstatSync, lstatSync, mkdirSync, openSync, readSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { basename, dirname, join } from "node:path";
|
|
1
3
|
import { fence } from "./brief-fence.js";
|
|
2
|
-
import { cleanLiveText, HIDDEN_LINE, liveSecretHit } from "./live-records.js";
|
|
4
|
+
import { cleanLiveText, HIDDEN_LINE, liveSecretHit, parseLiveRecords, serializeLiveRecord } from "./live-records.js";
|
|
3
5
|
const ID = /^[0-9a-f]{32}$/;
|
|
4
6
|
const SHA = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
|
|
5
7
|
export const FLEXIBLE_REPLY_KEPT = 20_000;
|
|
@@ -54,6 +56,82 @@ export function recordFlexibleFiles(store, input) {
|
|
|
54
56
|
files = files.slice(0, Math.floor(files.length / 2));
|
|
55
57
|
store.handle.prepare("UPDATE flexible_turn_said SET files = ? WHERE turn = ? AND files IS NULL").run(JSON.stringify(files), input.turn);
|
|
56
58
|
}
|
|
59
|
+
export const TURN_RECORDS_DIR = "turns";
|
|
60
|
+
export const TURN_RECORDS_BYTES = 512 * 1024;
|
|
61
|
+
const TURN_KINDS = new Set(["say", "step", "done", "cut", "cap"]);
|
|
62
|
+
function privateFolder(path) {
|
|
63
|
+
try {
|
|
64
|
+
const held = lstatSync(path);
|
|
65
|
+
const uid = process.getuid?.();
|
|
66
|
+
return held.isDirectory() && !held.isSymbolicLink() && (uid === undefined || held.uid === uid) && (held.mode & 0o077) === 0;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export function keepFlexibleTurnRecords(folder, turn, records) {
|
|
73
|
+
if (!ID.test(turn) || basename(folder) === "" || !privateFolder(folder) || !privateFolder(dirname(folder)))
|
|
74
|
+
return;
|
|
75
|
+
const lines = [];
|
|
76
|
+
const size = (line) => Buffer.byteLength(line, "utf8") + 1;
|
|
77
|
+
let bytes = 0;
|
|
78
|
+
for (const record of records) {
|
|
79
|
+
if (!TURN_KINDS.has(record.k))
|
|
80
|
+
continue;
|
|
81
|
+
const line = serializeLiveRecord(record);
|
|
82
|
+
const cap = serializeLiveRecord({ k: "cap", at: record.at });
|
|
83
|
+
if (bytes + size(line) + size(cap) > TURN_RECORDS_BYTES) {
|
|
84
|
+
lines.push(cap);
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
lines.push(line);
|
|
88
|
+
bytes += size(line);
|
|
89
|
+
}
|
|
90
|
+
if (lines.length === 0)
|
|
91
|
+
return;
|
|
92
|
+
const dir = join(folder, TURN_RECORDS_DIR);
|
|
93
|
+
try {
|
|
94
|
+
try {
|
|
95
|
+
mkdirSync(dir, { mode: 0o700 });
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
if (error.code !== "EEXIST")
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (!privateFolder(dir))
|
|
102
|
+
return;
|
|
103
|
+
writeFileSync(join(dir, `${turn}.jsonl`), `${lines.join("\n")}\n`, { mode: 0o600, flag: "wx" });
|
|
104
|
+
}
|
|
105
|
+
catch { }
|
|
106
|
+
}
|
|
107
|
+
export function flexibleTurnRecordsOf(folder, turn) {
|
|
108
|
+
if (!ID.test(turn) || !privateFolder(folder) || !privateFolder(join(folder, TURN_RECORDS_DIR)))
|
|
109
|
+
return [];
|
|
110
|
+
let fd;
|
|
111
|
+
try {
|
|
112
|
+
fd = openSync(join(folder, TURN_RECORDS_DIR, `${turn}.jsonl`), fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return [];
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
const held = fstatSync(fd);
|
|
119
|
+
if (!held.isFile() || held.size > TURN_RECORDS_BYTES)
|
|
120
|
+
return [];
|
|
121
|
+
const bytes = Buffer.alloc(held.size);
|
|
122
|
+
const read = readSync(fd, bytes, 0, bytes.length, 0);
|
|
123
|
+
return parseLiveRecords(bytes.subarray(0, read).toString("utf8")).filter(one => TURN_KINDS.has(one.k));
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
finally {
|
|
129
|
+
closeSync(fd);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
export function sayTextOf(records) {
|
|
133
|
+
return records.flatMap(one => one.k === "say" ? one.t : []).join("\n");
|
|
134
|
+
}
|
|
57
135
|
export function flexibleConversationOf(store, thread) {
|
|
58
136
|
if (!ID.test(thread))
|
|
59
137
|
return [];
|