toolroll 0.9.126 → 0.9.128
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 +47 -0
- package/README.md +2 -1
- package/dist/assignment.js +14 -4
- package/dist/browser/terminal.css +1 -1
- package/dist/browser/workspace.css +1 -1
- package/dist/browser/workspace.js +10 -10
- package/dist/contracts/engine-api.js +3 -0
- package/dist/demo.js +1 -1
- package/dist/design/kit.css +6 -3
- package/dist/easy-start.js +1 -0
- package/dist/engine-reads.js +21 -2
- package/dist/flexible-conversation.js +79 -1
- package/dist/flexible-import.js +159 -2
- package/dist/flexible-save.js +49 -4
- package/dist/flexible-session.js +33 -7
- package/dist/flexible-start.js +2 -1
- package/dist/landed-rows.js +138 -0
- package/dist/local-landing.js +20 -2
- package/dist/merge-checklist.js +33 -8
- package/dist/models-ui.js +5 -2
- package/dist/operate.js +95 -19
- package/dist/result-follow-ups.js +8 -1
- package/dist/revision-catch-up.js +98 -0
- package/dist/server/engine-api.js +13 -8
- package/dist/server/pages.js +5 -2
- package/dist/server/render-results.js +4 -2
- package/dist/server/settings.js +8 -2
- package/dist/server/task-views.js +4 -1
- package/dist/skill-library.js +2 -12
- package/dist/skills-ui.js +11 -6
- package/dist/spend-ui.js +3 -2
- package/dist/spend.js +8 -1
- package/dist/task-base.js +11 -0
- package/dist/task-status.js +11 -4
- package/dist/teardown-git.js +6 -0
- package/dist/toolroll-update-cli.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/unreachable.js +15 -0
- package/package.json +1 -1
|
@@ -111,6 +111,7 @@ const workRowSchema = z.object({
|
|
|
111
111
|
group: z.enum(WORK_ROW_GROUPS),
|
|
112
112
|
rank: z.number().int(),
|
|
113
113
|
check: z.enum(["failed", "stale", "unreadable"]).optional(),
|
|
114
|
+
landed: z.string().optional(),
|
|
114
115
|
detail: z.string().nullable(),
|
|
115
116
|
problem: z.string().nullable(),
|
|
116
117
|
need: needRowSchema.nullable(),
|
|
@@ -163,6 +164,7 @@ export const stepCardsSchema = z.object({
|
|
|
163
164
|
headline: z.string().nullable(),
|
|
164
165
|
liveRun: z.number().int().nullable(),
|
|
165
166
|
latestRun: z.number().int().nullable(),
|
|
167
|
+
familyBuilds: z.array(z.number().int()).optional(),
|
|
166
168
|
models: z.array(z.object({ phase: z.string(), provider: z.string(), model: z.string(), chosen: z.enum(["recommended", "override", "pinned"]) })).nullable(),
|
|
167
169
|
cards: z.array(stepCardSchema).nullable(),
|
|
168
170
|
review: z.object({ run: z.number().int(), receipt: z.string().regex(/^[0-9a-f]{64}$/), source: z.string(),
|
|
@@ -187,6 +189,7 @@ export const stepCardsSchema = z.object({
|
|
|
187
189
|
landing: z.object({ words: z.string(), reverted: z.boolean() }).nullable(),
|
|
188
190
|
check: z.enum(["failed", "stale", "unreadable"]).optional(),
|
|
189
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(),
|
|
190
193
|
room: z.string(),
|
|
191
194
|
});
|
|
192
195
|
export const approvalCardSchema = z.object({
|
package/dist/demo.js
CHANGED
|
@@ -921,7 +921,7 @@ export function createDemoSandbox(now) {
|
|
|
921
921
|
{ window: "seven_day", usedPercent: 83, windowMinutes: 10_080, resetsAt: later(62), reached: false },
|
|
922
922
|
] }, now);
|
|
923
923
|
store.recordProviderLimits({ provider: "codex", plan: "pro", windows: [{ window: "seven_day", usedPercent: 12, windowMinutes: 10_080, resetsAt: later(130), reached: false }] }, now);
|
|
924
|
-
store.setBudget({ scope: "project", key: repos.web, limitMicrousd: 25_000_000, hardStop: true }, seed.login.name, now);
|
|
924
|
+
store.setBudget({ scope: "project", key: realpathSync(repos.web), limitMicrousd: 25_000_000, hardStop: true }, seed.login.name, now);
|
|
925
925
|
const passwordFile = join(sandbox, "demo-login.txt");
|
|
926
926
|
writeFileSync(passwordFile, `name: ${seed.login.name}\npassword: ${seed.login.password}\n`, { mode: 0o600 });
|
|
927
927
|
const lead = createDemoLead({ store, repos, evidenceRoot, approver: seed.login.name, token: seed.login.password });
|
package/dist/design/kit.css
CHANGED
|
@@ -109,8 +109,9 @@
|
|
|
109
109
|
/* A native select in the same family, with the chevron: 36px (sm 28px in a toolbar). */
|
|
110
110
|
.k-selw { position: relative; display: inline-block; min-width: 0; max-width: 100%; }
|
|
111
111
|
.k-selw::after { content: ""; position: absolute; right: 13px; top: 50%; margin-top: -5px; width: 6px; height: 6px; border: solid var(--so-muted); border-width: 0 1.5px 1.5px 0; transform: rotate(45deg); pointer-events: none; }
|
|
112
|
-
.k-sel.k-sel { appearance: none; -webkit-appearance: none; height: 36px; min-height: 0; padding: 0 32px 0 12px; line-height:
|
|
113
|
-
.k-
|
|
112
|
+
.k-sel.k-sel { appearance: none; -webkit-appearance: none; -moz-appearance: none; background-image: none; height: 36px; min-height: 0; padding: 0 32px 0 12px; line-height: 34px; text-overflow: ellipsis; cursor: pointer; }
|
|
113
|
+
.k-sel.k-sel::picker-icon { display: none; }
|
|
114
|
+
.k-selw.sm .k-sel { height: 28px; border-radius: 999px; font: 500 12.5px/26px var(--so-font-sans); padding: 0 26px 0 11px; }
|
|
114
115
|
.k-selw.sm::after { right: 11px; }
|
|
115
116
|
.k-selw.wide { display: block; width: 100%; }
|
|
116
117
|
/* A select drawn as a pill chip (a composer's project): filled, no box, works without script. */
|
|
@@ -226,8 +227,9 @@
|
|
|
226
227
|
.k-tb-ctx > .k-seg + .k-seg { margin-left: 8px; }
|
|
227
228
|
/* Phone header: menu or back · title · one trailing action. Hidden at a desk. */
|
|
228
229
|
.k-ph { display: none; }
|
|
229
|
-
/* Reading pages: one 760px column,
|
|
230
|
+
/* Reading pages: one 760px column, expanding to 960px on wide desks when reviewing code diffs. */
|
|
230
231
|
.k-doc { box-sizing: border-box; width: 100%; max-width: 760px; margin: 0 auto; padding: 22px 28px 120px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px; align-content: start; }
|
|
232
|
+
@media (min-width: 1100px) { .k-doc:has(.diff-review) { max-width: 960px; } }
|
|
231
233
|
.k-backlink { display: inline-flex; align-items: center; gap: 6px; color: var(--so-muted); font: var(--so-typography-label); justify-self: start; min-height: 24px; text-decoration: none; }
|
|
232
234
|
.k-dh { display: flex; align-items: flex-start; gap: 6px; }
|
|
233
235
|
.k-dh > div { flex: 1; display: grid; gap: 6px; min-width: 0; }
|
|
@@ -564,6 +566,7 @@ html:not(.k-js) .k-composer:focus-within, html.k-kbd .k-composer:focus-within {
|
|
|
564
566
|
.k-btn-icon, .k-btn-sm.k-btn-icon { width: 44px; padding: 0; }
|
|
565
567
|
.k-input.k-input, .k-textarea.k-textarea, .k-sel.k-sel { font-size: 16px; }
|
|
566
568
|
.k-input.k-input, .k-pop .k-input.k-input, .k-sel.k-sel, .k-selw.sm .k-sel { height: 44px; }
|
|
569
|
+
.k-sel.k-sel, .k-selw.sm .k-sel { line-height: 42px; }
|
|
567
570
|
.k-selw::after { right: 13px; }
|
|
568
571
|
.k-seg > a, .k-seg > button { height: 44px; font-size: 13.5px; }
|
|
569
572
|
.k-seg.k-seg-icons > a, .k-seg.k-seg-icons > button { min-width: 44px; justify-content: center; }
|
package/dist/easy-start.js
CHANGED
|
@@ -186,6 +186,7 @@ export async function runEasyStart(mode, args, seams) {
|
|
|
186
186
|
const opened = await seams.openSignedIn();
|
|
187
187
|
if (!opened.ok) {
|
|
188
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."}`);
|
|
189
190
|
const child = ownedNow();
|
|
190
191
|
if (child !== null)
|
|
191
192
|
stopOwned(child);
|
package/dist/engine-reads.js
CHANGED
|
@@ -3,7 +3,8 @@ 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 { landedNowOf } from "./merge-checklist.js";
|
|
6
|
+
import { behindMainOf, landedNowOf, upToDateNote } from "./merge-checklist.js";
|
|
7
|
+
import { publishesThroughPullRequests } from "./local-landing.js";
|
|
7
8
|
import { liveQuickCommand } from "./check-levels.js";
|
|
8
9
|
import { assignmentStageOf, stageOfCode } from "./task-status.js";
|
|
9
10
|
import { taskRoad } from "./first-run.js";
|
|
@@ -126,9 +127,16 @@ export function stepCardsOf({ store, family, now, access, evidenceRoot, viewer =
|
|
|
126
127
|
landing: assignment === null ? null : landedNowOf(store, assignment),
|
|
127
128
|
...(card?.status.check === "failed" || card?.status.check === "stale" || card?.status.check === "unreadable" ? { check: card.status.check } : {}),
|
|
128
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),
|
|
129
132
|
room: `task:${encodeURIComponent(root.id)}`,
|
|
130
133
|
};
|
|
131
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
|
+
}
|
|
132
140
|
function runChecksOfferOf(store, assignment, check) {
|
|
133
141
|
if (check !== "failed" && check !== "stale" && check !== "unreadable" && check !== "not-run")
|
|
134
142
|
return null;
|
|
@@ -138,6 +146,17 @@ function runChecksOfferOf(store, assignment, check) {
|
|
|
138
146
|
const level = store.liveVerifyCommand(assignment.repo) !== null ? "full" : liveQuickCommand(store, assignment.repo) !== null ? "quick" : null;
|
|
139
147
|
return level === null ? null : { run: receipt.runId, level };
|
|
140
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
|
+
}
|
|
141
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.";
|
|
142
161
|
export const SHELL_NO_COMMIT = "This build has no saved commit to open a terminal on.";
|
|
143
162
|
function shellOf(store, family, runId) {
|
|
@@ -624,7 +643,7 @@ export function threadDiffOf(thread, turn, changes, seen = {}) {
|
|
|
624
643
|
if (!changes.ok)
|
|
625
644
|
return empty(`This thread's changes can't be read: ${cleanLiveText(changes.message)}`);
|
|
626
645
|
if ("none" in changes && seen.edited === true)
|
|
627
|
-
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.");
|
|
628
647
|
if ("none" in changes)
|
|
629
648
|
return empty("No committed changes yet. Ask the agent to commit its work: Ship sends committed work only.");
|
|
630
649
|
const files = patchFiles(changes.patch).map((text, index) => {
|
|
@@ -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 [];
|
package/dist/flexible-import.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { closeSync, constants as fsConstants, existsSync, fstatSync, lstatSync, mkdirSync, mkdtempSync, opendirSync, openSync, readFileSync, readSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { closeSync, constants as fsConstants, existsSync, fstatSync, lstatSync, mkdirSync, mkdtempSync, opendirSync, openSync, readFileSync, readSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { basename, dirname, isAbsolute, join } from "node:path";
|
|
4
4
|
import { FLEXIBLE_UNAVAILABLE } from "./flexible.js";
|
|
5
5
|
import { flexibleProjectKnown, flexibleThread, flexibleThreadBranch, flexibleThreadPaths, withFlexibleThreadLock } from "./flexible-thread.js";
|
|
@@ -8,7 +8,8 @@ import { PROTECTED_FILES, protectedChanges, protectedLinks } from "./agent-fence
|
|
|
8
8
|
import { scanPatchForSecrets } from "./evidence.js";
|
|
9
9
|
import { PROOF_LIMITS } from "./proof.js";
|
|
10
10
|
import { run } from "./exec.js";
|
|
11
|
-
import { hardenedGit, recordedCommonDir } from "./teardown-git.js";
|
|
11
|
+
import { hardenedGit, recordedCommonDir, viewedGitSync } from "./teardown-git.js";
|
|
12
|
+
import { identityEnv, projectGitIdentity, THREAD_IDENTITY } from "./git-identity.js";
|
|
12
13
|
const NOTHING = "Nothing was imported.";
|
|
13
14
|
const PRE_WORDS = {
|
|
14
15
|
"not-available": FLEXIBLE_UNAVAILABLE,
|
|
@@ -858,3 +859,159 @@ export async function settleInterruptedImport(store, input) {
|
|
|
858
859
|
}
|
|
859
860
|
return { ok: true, importRef: importState, branch: branchState };
|
|
860
861
|
}
|
|
862
|
+
export const LEFTOVER_COMMIT_MESSAGE = "Edits the thread's agent left uncommitted\n\nCommitted by Toolroll when the thread's work was saved.\n";
|
|
863
|
+
function onThreadBranch(paths, id) {
|
|
864
|
+
const file = join(paths.repo, ".git", "HEAD");
|
|
865
|
+
try {
|
|
866
|
+
const held = lstatSync(file);
|
|
867
|
+
if (!held.isFile() || held.isSymbolicLink() || held.size > 512)
|
|
868
|
+
return false;
|
|
869
|
+
return readFileSync(file, "utf8") === `ref: refs/heads/${flexibleThreadBranch(id)}\n`;
|
|
870
|
+
}
|
|
871
|
+
catch {
|
|
872
|
+
return false;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
function nulNames(stdout) {
|
|
876
|
+
const fields = stdout.split("\0");
|
|
877
|
+
if (fields.at(-1) === "")
|
|
878
|
+
fields.pop();
|
|
879
|
+
if (fields.some(one => one === "" || /[\n\r]/.test(one)))
|
|
880
|
+
return null;
|
|
881
|
+
return [...new Set(fields)].sort();
|
|
882
|
+
}
|
|
883
|
+
export async function flexibleLeftover(store, input) {
|
|
884
|
+
const limits = limitsOf(undefined);
|
|
885
|
+
const deadline = Date.now() + limits.importMs;
|
|
886
|
+
const source = sourceOf(store, input.thread, limits, deadline);
|
|
887
|
+
if ("ok" in source)
|
|
888
|
+
return { state: "unknown", why: source.message };
|
|
889
|
+
const tip = threadBranchTip(source.paths, source.thread.id);
|
|
890
|
+
if (tip === null || tip.length !== source.thread.baseSha.length)
|
|
891
|
+
return { state: "unknown", why: "its branch couldn't be read" };
|
|
892
|
+
if (!onThreadBranch(source.paths, source.thread.id))
|
|
893
|
+
return { state: "unknown", why: "its copy isn't on the thread's branch" };
|
|
894
|
+
const inner = input.runner ?? run;
|
|
895
|
+
const repo = source.paths.repo;
|
|
896
|
+
let scratch;
|
|
897
|
+
try {
|
|
898
|
+
const imports = join(source.paths.root, FLEXIBLE_IMPORTS_DIR);
|
|
899
|
+
try {
|
|
900
|
+
mkdirSync(imports, { mode: 0o700 });
|
|
901
|
+
}
|
|
902
|
+
catch (error) {
|
|
903
|
+
if (error.code !== "EEXIST")
|
|
904
|
+
throw error;
|
|
905
|
+
}
|
|
906
|
+
if (!ownFolder(imports))
|
|
907
|
+
return { state: "unknown", why: "Toolroll's own folder for it isn't private" };
|
|
908
|
+
scratch = mkdtempSync(join(imports, `${source.thread.id}-index-`));
|
|
909
|
+
}
|
|
910
|
+
catch {
|
|
911
|
+
return { state: "unknown", why: "Toolroll couldn't make a folder of its own to read it in" };
|
|
912
|
+
}
|
|
913
|
+
const index = join(scratch, "index");
|
|
914
|
+
const git = (mode, args, env = {}, maxBuffer) => {
|
|
915
|
+
const left = deadline - Date.now();
|
|
916
|
+
if (left <= 0)
|
|
917
|
+
throw new DeadlinePassed("the time ran out");
|
|
918
|
+
return hardenedGit(inner, mode, { repo })("git", [...IMPORT_FLAGS, ...args], { cwd: repo, timeoutMs: Math.max(1, Math.min(60_000, left)), env: { ...env, GIT_INDEX_FILE: index }, ...(maxBuffer === undefined ? {} : { maxBuffer }) });
|
|
919
|
+
};
|
|
920
|
+
const big = 32 * 1024 * 1024;
|
|
921
|
+
try {
|
|
922
|
+
if (!input.commit) {
|
|
923
|
+
if ((await git("read", ["read-tree", tip])).code !== 0)
|
|
924
|
+
return { state: "unknown", why: "its branch couldn't be read" };
|
|
925
|
+
const refreshed = await git("read", ["update-index", "-q", "--refresh"]);
|
|
926
|
+
if (refreshed.code !== 0 && refreshed.code !== 1)
|
|
927
|
+
return { state: "unknown", why: "its files couldn't be read" };
|
|
928
|
+
const changed = await git("read", ["diff-files", "--name-only", "-z", "--no-renames"], {}, big);
|
|
929
|
+
const untracked = await git("read", ["ls-files", "-z", "--others", "--exclude-standard"], {}, big);
|
|
930
|
+
const found = changed.code === 0 && untracked.code === 0 ? nulNames(`${changed.stdout}${untracked.stdout}`) : null;
|
|
931
|
+
if (found === null)
|
|
932
|
+
return { state: "unknown", why: "its files couldn't be read" };
|
|
933
|
+
return found.length === 0 ? { state: "none" } : { state: "found", paths: found };
|
|
934
|
+
}
|
|
935
|
+
if ((await git("build", ["read-tree", tip])).code !== 0)
|
|
936
|
+
return { state: "unknown", why: "its branch couldn't be read" };
|
|
937
|
+
if ((await git("build", ["add", "-A"])).code !== 0)
|
|
938
|
+
return { state: "unknown", why: "its files couldn't be read" };
|
|
939
|
+
const raw = await git("build", ["diff", "--cached", "--raw", "--no-renames", "--no-abbrev", "-z", tip], {}, big);
|
|
940
|
+
const staged = raw.code === 0 ? parseRawDiff(raw.stdout) : null;
|
|
941
|
+
if (staged === null)
|
|
942
|
+
return { state: "unknown", why: "its files couldn't be read" };
|
|
943
|
+
if (staged.length === 0)
|
|
944
|
+
return { state: "none" };
|
|
945
|
+
const found = staged.map(one => one.path).sort();
|
|
946
|
+
const keep = (why) => ({ state: "kept", paths: found, why });
|
|
947
|
+
if (staged.length > PROOF_LIMITS.changed)
|
|
948
|
+
return keep(`they change ${staged.length} files, more than Toolroll saves at once`);
|
|
949
|
+
const added = staged.filter(one => one.status !== "D");
|
|
950
|
+
if (added.some(one => one.newMode === "160000"))
|
|
951
|
+
return keep("they hold another repository");
|
|
952
|
+
const placeholders = placeholderBlobs(source.format);
|
|
953
|
+
if (added.some(one => PLACEHOLDER_NAMES.has(one.path) && placeholders.has(one.newSha)))
|
|
954
|
+
return keep("they include one of Toolroll's placeholder files");
|
|
955
|
+
const names = staged.map(one => foldPath(one.path));
|
|
956
|
+
if (names.some(one => one.split("/").includes(".git")) || protectedChanges(names).length > 0
|
|
957
|
+
|| protectedLinks(added.filter(one => one.newMode === "120000").map(one => foldPath(one.path))).length > 0)
|
|
958
|
+
return keep("they touch a file Toolroll protects");
|
|
959
|
+
for (const one of added) {
|
|
960
|
+
let held;
|
|
961
|
+
try {
|
|
962
|
+
held = lstatSync(join(repo, one.path));
|
|
963
|
+
}
|
|
964
|
+
catch {
|
|
965
|
+
return keep("a file changed while it was read");
|
|
966
|
+
}
|
|
967
|
+
if (one.newMode === "120000") {
|
|
968
|
+
if (!held.isSymbolicLink())
|
|
969
|
+
return keep("a file changed while it was read");
|
|
970
|
+
const target = await git("build", ["cat-file", "blob", one.newSha]);
|
|
971
|
+
if (target.code !== 0 || linkLeadsOut(one.path, target.stdout))
|
|
972
|
+
return keep("they add a link that leads outside the project");
|
|
973
|
+
}
|
|
974
|
+
else if (!held.isFile() || held.nlink > 1)
|
|
975
|
+
return keep("they include a file Toolroll can't save safely");
|
|
976
|
+
else if (held.size > limits.blobBytes)
|
|
977
|
+
return keep(`a file is over ${Math.round(limits.blobBytes / 1024 / 1024)} MB`);
|
|
978
|
+
}
|
|
979
|
+
const patch = await git("build", ["diff", "--cached", "-p", "--no-ext-diff", "--no-textconv", "--no-color", "--no-renames", tip], {}, limits.patchBytes);
|
|
980
|
+
if (patch.code !== 0)
|
|
981
|
+
return keep("they couldn't be read whole");
|
|
982
|
+
if (scanPatchForSecrets(patch.stdout).length > 0)
|
|
983
|
+
return keep("an added line looks like a real key");
|
|
984
|
+
const identity = await projectGitIdentity(source.project, THREAD_IDENTITY, inner);
|
|
985
|
+
if (!identity.ok)
|
|
986
|
+
return keep(`the project's git identity couldn't be read (${identity.why})`);
|
|
987
|
+
const tree = (await git("build", ["write-tree"])).stdout.trim();
|
|
988
|
+
if (!SHA.test(tree))
|
|
989
|
+
return keep("git couldn't write them");
|
|
990
|
+
const made = await git("build", ["commit-tree", "--no-gpg-sign", "-p", tip, "-m", LEFTOVER_COMMIT_MESSAGE, tree], identityEnv(identity.identity));
|
|
991
|
+
const commit = made.stdout.trim();
|
|
992
|
+
if (made.code !== 0 || !SHA.test(commit) || commit.length !== tip.length)
|
|
993
|
+
return keep("git refused the commit");
|
|
994
|
+
if (input.allowed !== undefined && !input.allowed())
|
|
995
|
+
return { state: "refused" };
|
|
996
|
+
let moved;
|
|
997
|
+
try {
|
|
998
|
+
moved = viewedGitSync(repo, ["update-ref", "--no-deref", `refs/heads/${flexibleThreadBranch(source.thread.id)}`, commit, tip], { write: true, binding: { repo }, timeoutMs: Math.max(1, Math.min(60_000, deadline - Date.now())) }).status === 0;
|
|
999
|
+
}
|
|
1000
|
+
catch {
|
|
1001
|
+
moved = false;
|
|
1002
|
+
}
|
|
1003
|
+
if (!moved || threadBranchTip(source.paths, source.thread.id) !== commit)
|
|
1004
|
+
return { state: "unknown", why: "the thread's branch moved while it was saved" };
|
|
1005
|
+
try {
|
|
1006
|
+
renameSync(index, join(repo, ".git", "index"));
|
|
1007
|
+
}
|
|
1008
|
+
catch { }
|
|
1009
|
+
return { state: "committed", commit, paths: found };
|
|
1010
|
+
}
|
|
1011
|
+
catch (error) {
|
|
1012
|
+
return { state: "unknown", why: error instanceof DeadlinePassed ? "the time ran out" : "its files couldn't be read" };
|
|
1013
|
+
}
|
|
1014
|
+
finally {
|
|
1015
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
1016
|
+
}
|
|
1017
|
+
}
|
package/dist/flexible-save.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { canonicalJson } from "./canonical-json.js";
|
|
3
3
|
import { flexibleStanding } from "./flexible.js";
|
|
4
|
-
import { flexibleImportRef, importFlexibleCandidate, projectMergeHint, projectThreadBranch, readFlexibleCandidate } from "./flexible-import.js";
|
|
4
|
+
import { flexibleImportRef, flexibleLeftover, importFlexibleCandidate, projectMergeHint, projectThreadBranch, readFlexibleCandidate } from "./flexible-import.js";
|
|
5
|
+
import { unsettledLaunch } from "./flexible-launch.js";
|
|
5
6
|
import { branchHeld, nextSeq, turnRunning } from "./flexible-ship.js";
|
|
6
7
|
import { flexibleThread, flexibleThreadBranch, withFlexibleThreadLock } from "./flexible-thread.js";
|
|
7
8
|
import { machineActing } from "./scope.js";
|
|
@@ -58,9 +59,30 @@ export async function saveFlexibleBranch(store, input) {
|
|
|
58
59
|
const locked = await withFlexibleThreadLock(input.thread, async () => {
|
|
59
60
|
if (turnRunning(store, input.thread))
|
|
60
61
|
return refuse("thread-running");
|
|
62
|
+
const standingNow = () => store.transact(() => {
|
|
63
|
+
const thread = flexibleThread(store, input.thread);
|
|
64
|
+
if (thread === null)
|
|
65
|
+
return refuse("thread-unknown");
|
|
66
|
+
if (thread.state !== "ready")
|
|
67
|
+
return refuse("thread-removed");
|
|
68
|
+
return saverStanding(store, thread, input.by) ?? (input.prove() ? null : refuse("stale-generation"));
|
|
69
|
+
});
|
|
70
|
+
const standing = standingNow();
|
|
71
|
+
if (standing !== null)
|
|
72
|
+
return standing;
|
|
73
|
+
let late = null;
|
|
74
|
+
const allowed = () => {
|
|
75
|
+
late = turnRunning(store, input.thread) || unsettledLaunch(store, input.thread) !== null ? refuse("changed") : standingNow();
|
|
76
|
+
return late === null;
|
|
77
|
+
};
|
|
78
|
+
const leftover = await flexibleLeftover(store, { thread: input.thread, commit: unsettledLaunch(store, input.thread) === null, allowed, ...runner });
|
|
79
|
+
if (leftover.state === "refused")
|
|
80
|
+
return late ?? refuse("changed");
|
|
81
|
+
const uncommitted = leftoverNote(leftover);
|
|
82
|
+
const withNote = (next) => ({ ...next, leftover: leftover.state, uncommitted });
|
|
61
83
|
const read = await readFlexibleCandidate(store, { thread: input.thread, ...runner });
|
|
62
84
|
if (!read.ok)
|
|
63
|
-
return read;
|
|
85
|
+
return uncommitted !== null && "check" in read && read.check === "nothing-to-send" ? { ...read, message: `${read.message} ${uncommitted}` } : read;
|
|
64
86
|
const branch = flexibleThreadBranch(input.thread);
|
|
65
87
|
const held = branchHeld(store, input.thread);
|
|
66
88
|
if (held === read.candidate) {
|
|
@@ -69,7 +91,7 @@ export async function saveFlexibleBranch(store, input) {
|
|
|
69
91
|
return refuse("branch-gone");
|
|
70
92
|
if (actual !== read.candidate)
|
|
71
93
|
return refuse("branch-moved");
|
|
72
|
-
return { ok: true, already: true, branch, candidate: read.candidate, seq: null, changedPaths: read.changedPaths, ...(await nextWords(store, input.thread, read.candidate, branch, input.runner)) };
|
|
94
|
+
return { ok: true, already: true, branch, candidate: read.candidate, seq: null, changedPaths: read.changedPaths, ...withNote(await nextWords(store, input.thread, read.candidate, branch, input.runner)) };
|
|
73
95
|
}
|
|
74
96
|
const at = input.now.toISOString();
|
|
75
97
|
const recorded = store.transact(() => {
|
|
@@ -107,7 +129,7 @@ export async function saveFlexibleBranch(store, input) {
|
|
|
107
129
|
return imported;
|
|
108
130
|
}
|
|
109
131
|
store.transact(() => { store.handle.prepare("UPDATE flexible_ship SET state = 'imported', state_at = ? WHERE id = ? AND state = 'approved'").run(at, recorded.digest); });
|
|
110
|
-
return { ok: true, already: false, branch, candidate: read.candidate, seq: recorded.seq, changedPaths: read.changedPaths, ...(await nextWords(store, input.thread, read.candidate, branch, input.runner)) };
|
|
132
|
+
return { ok: true, already: false, branch, candidate: read.candidate, seq: recorded.seq, changedPaths: read.changedPaths, ...withNote(await nextWords(store, input.thread, read.candidate, branch, input.runner)) };
|
|
111
133
|
});
|
|
112
134
|
if (locked.ok === false && (locked.reason === "not-available" || locked.reason === "thread-unknown"))
|
|
113
135
|
return refuse("thread-unknown");
|
|
@@ -128,3 +150,26 @@ export function latestFlexibleSave(store, thread) {
|
|
|
128
150
|
return null;
|
|
129
151
|
return { seq: Number(newest["seq"]), candidate: String(newest["candidate"]), at: String(newest["state_at"]) };
|
|
130
152
|
}
|
|
153
|
+
function leftoverNote(leftover) {
|
|
154
|
+
switch (leftover.state) {
|
|
155
|
+
case "none": return null;
|
|
156
|
+
case "committed": return `It includes the edits the agent hadn't committed (${filesWord(leftover.paths.length)}).`;
|
|
157
|
+
case "found": return `The agent's uncommitted edits (${filesWord(leftover.paths.length)}) aren't in it while its agent is running: end the thread, then save again.`;
|
|
158
|
+
case "kept": return `The agent's uncommitted edits (${filesWord(leftover.paths.length)}) weren't saved: ${leftover.why}. They stay in the thread's copy.`;
|
|
159
|
+
case "unknown": return `Toolroll couldn't check the thread's copy for uncommitted edits: ${leftover.why}.`;
|
|
160
|
+
case "refused": return null;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const filesWord = (n) => `${n} file${n === 1 ? "" : "s"}`;
|
|
164
|
+
export async function flexibleUncommittedFiles(store, input) {
|
|
165
|
+
if (unsettledLaunch(store, input.thread) !== null)
|
|
166
|
+
return [];
|
|
167
|
+
const found = await flexibleLeftover(store, { thread: input.thread, commit: false, ...(input.runner === undefined ? {} : { runner: input.runner }) });
|
|
168
|
+
return found.state === "found" ? found.paths : [];
|
|
169
|
+
}
|
|
170
|
+
export function flexibleSavedWords(saved) {
|
|
171
|
+
const commit = saved.candidate.slice(0, 12);
|
|
172
|
+
if (!saved.already)
|
|
173
|
+
return `Saved as ${saved.branch} (commit ${commit}, ${filesWord(saved.changedPaths.length)}).${saved.uncommitted === null ? "" : ` ${saved.uncommitted}`}`;
|
|
174
|
+
return saved.uncommitted === null ? `Already saved as ${saved.branch} (commit ${commit}).` : `Its committed work is already saved as ${saved.branch} (commit ${commit}). ${saved.uncommitted}`;
|
|
175
|
+
}
|
package/dist/flexible-session.js
CHANGED
|
@@ -14,7 +14,7 @@ import { flexibleThread, prepareFlexibleThread, removeFlexibleThread, stopFlexib
|
|
|
14
14
|
import { admitFlexibleTurn, finishFlexibleTurn, flexibleTurn, interruptFlexibleThreadTurns, interruptFlexibleTurnsOf, withdrawFlexibleTurn } from "./flexible-turns.js";
|
|
15
15
|
import { userFrame } from "./live-input.js";
|
|
16
16
|
import { cleanLiveText, createLiveRecorder, HIDDEN_LINE, liveSecretHit } from "./live-records.js";
|
|
17
|
-
import { flexibleConversationOf, flexibleTurnMessage, recordFlexibleFiles, recordFlexibleReply, recordFlexibleSaid, recordFlexibleStartTip, saidLines } from "./flexible-conversation.js";
|
|
17
|
+
import { flexibleConversationOf, flexibleTurnMessage, flexibleTurnRecordsOf, keepFlexibleTurnRecords, recordFlexibleFiles, recordFlexibleReply, recordFlexibleSaid, recordFlexibleStartTip, saidLines, sayTextOf } from "./flexible-conversation.js";
|
|
18
18
|
import { flexibleThreadTip, readFlexibleChanges } from "./flexible-import.js";
|
|
19
19
|
import { primaryResultEvent } from "./stream-scope.js";
|
|
20
20
|
const WORDS = Object.freeze({
|
|
@@ -481,12 +481,30 @@ export function attachFlexibleAgent(store, sessions, input) {
|
|
|
481
481
|
recorder: createLiveRecorder({ base: thread.folder === "" ? null : `${thread.folder}/repo`, commands: false, clock }) };
|
|
482
482
|
session.agent = link;
|
|
483
483
|
let outputTurn = input.turn;
|
|
484
|
+
const shown = new Map();
|
|
485
|
+
const kept = new Set();
|
|
486
|
+
const keepShown = (turn) => {
|
|
487
|
+
if (turn === null || kept.has(turn))
|
|
488
|
+
return;
|
|
489
|
+
kept.add(turn);
|
|
490
|
+
try {
|
|
491
|
+
keepFlexibleTurnRecords(thread.folder, turn, shown.get(turn) ?? []);
|
|
492
|
+
}
|
|
493
|
+
catch { }
|
|
494
|
+
shown.delete(turn);
|
|
495
|
+
};
|
|
484
496
|
const keep = (given) => {
|
|
485
497
|
if (link.turn !== null)
|
|
486
498
|
outputTurn = link.turn;
|
|
487
499
|
const records = withoutRefusedLines(store, outputTurn, given);
|
|
488
500
|
if (records.length === 0)
|
|
489
501
|
return;
|
|
502
|
+
if (outputTurn !== null && !kept.has(outputTurn)) {
|
|
503
|
+
const mine = shown.get(outputTurn) ?? [];
|
|
504
|
+
if (mine.length < FLEXIBLE_RECORDS_KEPT)
|
|
505
|
+
mine.push(...records);
|
|
506
|
+
shown.set(outputTurn, mine);
|
|
507
|
+
}
|
|
490
508
|
session.records.push(...records);
|
|
491
509
|
if (session.records.length > FLEXIBLE_RECORDS_KEPT) {
|
|
492
510
|
const drop = session.records.length - FLEXIBLE_RECORDS_KEPT;
|
|
@@ -531,12 +549,15 @@ export function attachFlexibleAgent(store, sessions, input) {
|
|
|
531
549
|
keep(link.recorder.observe(raw));
|
|
532
550
|
if (primaryResultEvent(raw) && link.turn !== null) {
|
|
533
551
|
const failed = raw["is_error"] === true;
|
|
534
|
-
|
|
552
|
+
const said = sayTextOf(shown.get(link.turn) ?? []);
|
|
553
|
+
const reply = said.trim() !== "" ? said : typeof raw["result"] === "string" ? raw["result"] : null;
|
|
554
|
+
if (!failed && reply !== null) {
|
|
535
555
|
try {
|
|
536
|
-
recordFlexibleReply(store, { turn: link.turn, reply
|
|
556
|
+
recordFlexibleReply(store, { turn: link.turn, reply });
|
|
537
557
|
}
|
|
538
558
|
catch { }
|
|
539
559
|
}
|
|
560
|
+
keepShown(link.turn);
|
|
540
561
|
void endFlexibleThreadTurn(store, sessions, { thread: input.thread, turn: link.turn, outcome: failed ? "unknown" : "finished", ...(failed ? { detail: "The agent stopped with an error." } : {}), ...clocked });
|
|
541
562
|
}
|
|
542
563
|
};
|
|
@@ -569,6 +590,7 @@ export function attachFlexibleAgent(store, sessions, input) {
|
|
|
569
590
|
keep(link.recorder.end());
|
|
570
591
|
session.agent = null;
|
|
571
592
|
}
|
|
593
|
+
keepShown(outputTurn);
|
|
572
594
|
revokeFlexibleAnswers(store, sessions.catalog, { thread: input.thread, connection: link.launch, reason: "the agent stopped", ...clocked });
|
|
573
595
|
bump(sessions, input.thread);
|
|
574
596
|
});
|
|
@@ -1315,10 +1337,14 @@ function conversationRecords(store, thread) {
|
|
|
1315
1337
|
catch {
|
|
1316
1338
|
return [];
|
|
1317
1339
|
}
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1340
|
+
const folder = flexibleThread(store, thread)?.folder ?? "";
|
|
1341
|
+
return turns.filter(one => one.status !== "admitted" && one.status !== "running").flatMap((one) => {
|
|
1342
|
+
const shown = folder === "" ? [] : flexibleTurnRecordsOf(folder, one.turn);
|
|
1343
|
+
return [
|
|
1344
|
+
{ k: "you", at: one.saidAt, t: saidLines(one.said) },
|
|
1345
|
+
...(shown.length > 0 ? shown : one.reply === null ? [] : [{ k: "say", at: one.saidAt, t: saidLines(one.reply, 400) }]),
|
|
1346
|
+
];
|
|
1347
|
+
});
|
|
1322
1348
|
}
|
|
1323
1349
|
const FILES_READ_PER_TURN = 1;
|
|
1324
1350
|
const FILES_READ_MS = 10_000;
|
package/dist/flexible-start.js
CHANGED
|
@@ -78,7 +78,8 @@ export function flexibleStartCard(store, input) {
|
|
|
78
78
|
FLEXIBLE_UNKNOWN_COST_WORDS,
|
|
79
79
|
], fields: ["flexible.caps"], ...(caps.measuredMicrousdPerDay === null ? { risky: true } : {}) },
|
|
80
80
|
shipNeeds === null ? { label: "Ship", words: FLEXIBLE_SHIP_WORDS, fields: ["flexible.ship"] }
|
|
81
|
-
: { label: "Ship", words: shipNeeds.short, lines: [
|
|
81
|
+
: { label: "Ship", words: shipNeeds.short, lines: ["Until then, you can save its work as a branch in your repository instead (S on the thread, or `toolroll thread save <id>`).",
|
|
82
|
+
`After that: ${lowerFirst(FLEXIBLE_SHIP_WORDS)}`], fields: ["flexible.ship"] },
|
|
82
83
|
{ label: "Terms", words: `this project's Flexible terms, turned on by ${terms.signer}`, lines: [`They last until someone turns them off or lowers them, or ${terms.signer}'s account or access changes.`], fields: ["flexible.terms"] },
|
|
83
84
|
];
|
|
84
85
|
if (runtime === "interactive") {
|