toolroll 0.9.119 → 0.9.120

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +8 -8
  3. package/dist/assignment.js +9 -7
  4. package/dist/browser/workspace.js +23 -23
  5. package/dist/builder.js +2 -1
  6. package/dist/cli-help.js +1 -0
  7. package/dist/codex-limits.js +40 -22
  8. package/dist/contracts/console-api.js +2 -0
  9. package/dist/engine-reads.js +3 -1
  10. package/dist/flexible-import.js +38 -0
  11. package/dist/flexible-save.js +128 -0
  12. package/dist/flexible-session.js +9 -2
  13. package/dist/flexible-ship.js +3 -3
  14. package/dist/flexible-thread.js +2 -2
  15. package/dist/local-checks.js +32 -0
  16. package/dist/local-landing.js +321 -63
  17. package/dist/local-owner.js +2 -0
  18. package/dist/operate.js +25 -7
  19. package/dist/plan-limits-demand.js +48 -0
  20. package/dist/result-follow-ups.js +22 -8
  21. package/dist/review-context.js +2 -1
  22. package/dist/server/direct-chat.js +24 -3
  23. package/dist/server/engine-api.js +24 -3
  24. package/dist/server/render-results.js +6 -4
  25. package/dist/server/route-table.js +6 -1
  26. package/dist/server/send-back-build.js +4 -0
  27. package/dist/server/settings.js +2 -0
  28. package/dist/server/task-views.js +8 -3
  29. package/dist/server/tasks.js +51 -9
  30. package/dist/settings-groups-ui.js +1 -1
  31. package/dist/subscription-usage.js +11 -5
  32. package/dist/surface.js +3 -2
  33. package/dist/task-base.js +23 -4
  34. package/dist/task-outcome-cli.js +10 -1
  35. package/dist/tui/darwin-arm64/toolroll-tui +0 -0
  36. package/dist/tui/darwin-x64/toolroll-tui +0 -0
  37. package/dist/tui/linux-arm64/toolroll-tui +0 -0
  38. package/dist/tui/linux-x64/toolroll-tui +0 -0
  39. package/dist/verification-evidence.js +3 -1
  40. package/package.json +1 -1
package/dist/builder.js CHANGED
@@ -4,6 +4,7 @@ import { agentSaidTail } from "./agent-said.js";
4
4
  import { CHECK_ACCESS_DEFAULT, checkAccessHere, checkNetworkOf, localModeCap } from "./check-access.js";
5
5
  import { localModeOn } from "./local-owner.js";
6
6
  import { checkoutGit, refusal as gitRefusal } from "./teardown-git.js";
7
+ import { wholeChangeBaseOf } from "./task-base.js";
7
8
  import { isAcpProvider } from "./acp-agents.js";
8
9
  import { OBSERVATION_MAILBOX, observationBrief, parseObservationCases, collectObservations } from "./observations.js";
9
10
  import { checkCommandFor, effectiveCheckLevel, recordRunCheckLevel } from "./check-levels.js";
@@ -1292,7 +1293,7 @@ export async function settleProviderOutcome(captured, result) {
1292
1293
  .filter(line => line.trim() !== "" &&
1293
1294
  !line.trimEnd().endsWith(LEASE_MARKER) &&
1294
1295
  !(line.startsWith("?? ") && looksLikeProtocolFile(line.slice(3))));
1295
- const pinnedBase = store.firstBuilderBase(taskRef, branch) ?? baseRevision;
1296
+ const pinnedBase = wholeChangeBaseOf(store, taskRef, branch) ?? baseRevision;
1296
1297
  if (handoff.status === "no-change") {
1297
1298
  if (dirty.length > 0) {
1298
1299
  return {
package/dist/cli-help.js CHANGED
@@ -98,6 +98,7 @@ Tasks (\`toolroll task --help\` lists every task command)
98
98
  the yes — nothing builds without one
99
99
  toolroll task accept <id> --finish
100
100
  accept the result you read (--despite "<why>": accept it with a reason, without finishing)
101
+ toolroll task land <id> put accepted work on your branch as one commit (no pull requests)
101
102
  toolroll task send-back <id> --feedback "<what to change>"
102
103
  send the result back for changes
103
104
  toolroll task retry <id> build it again
@@ -3,6 +3,7 @@ import { tmpdir } from "node:os";
3
3
  import { codingEnvironment } from "./coding-provider.js";
4
4
  import { codexLimitsOf, record } from "./provider-limits.js";
5
5
  import { refreshSubscriptions } from "./subscription-usage.js";
6
+ import { directChatRunning, onPlanLimitsViewed, planLimitsWanted } from "./plan-limits-demand.js";
6
7
  import { billingOf } from "./spend.js";
7
8
  import { envValue } from "./names.js";
8
9
  function accountBilling(account) {
@@ -103,28 +104,7 @@ export function readCodexLimits(options = {}) {
103
104
  export function startCodexLimits(store, signedIn, everyMs = 5 * 60_000) {
104
105
  if (process.env["VITEST"] !== undefined || envValue(process.env, "NO_PLAN_PROBE") !== undefined || store.isDemo())
105
106
  return () => { };
106
- let stopped = false, busy = false;
107
- const pass = async () => {
108
- if (stopped || busy)
109
- return;
110
- busy = true;
111
- try {
112
- await codexLimitsPass(store, { signedIn, stopped: () => stopped });
113
- if (!stopped) {
114
- await refreshSubscriptions(store, store.databaseFile(), { skipCodex: true });
115
- }
116
- }
117
- catch {
118
- }
119
- finally {
120
- busy = false;
121
- }
122
- };
123
- const timer = setInterval(() => void pass(), everyMs);
124
- timer.unref?.();
125
- const first = setTimeout(() => void pass(), 10_000);
126
- first.unref?.();
127
- return () => { stopped = true; clearInterval(timer); clearTimeout(first); };
107
+ return scheduleLimitsLoop(store, { signedIn }, everyMs);
128
108
  }
129
109
  export async function codexLimitsPass(store, seams) {
130
110
  if (billingOf("codex") !== "subscription")
@@ -132,8 +112,12 @@ export async function codexLimitsPass(store, seams) {
132
112
  const recent = new Date(Date.now() - 6 * 3_600_000).toISOString();
133
113
  if (store.handle.prepare("SELECT 1 AS live FROM run WHERE provider = 'codex' AND outcome IS NULL AND started_at > ? LIMIT 1").get(recent) !== undefined)
134
114
  return "skipped";
115
+ if (directChatRunning(store, "codex", new Date()))
116
+ return "skipped";
135
117
  if (!(await seams.signedIn()))
136
118
  return "skipped";
119
+ if (seams.stillWanted?.() === false)
120
+ return "skipped";
137
121
  const reading = await (seams.read ?? (() => readCodexLimits()))();
138
122
  if (reading !== null && seams.stopped?.() !== true)
139
123
  store.recordProviderLimits(reading, new Date());
@@ -144,3 +128,37 @@ export async function codexSignedInNow(check) {
144
128
  return false;
145
129
  return (await check("codex", true)).state === "connected";
146
130
  }
131
+ const VIEWED_PASS_GAP_MS = 60_000;
132
+ export function scheduleLimitsLoop(store, seams, everyMs = 5 * 60_000) {
133
+ const clock = seams.clock ?? (() => new Date());
134
+ let stopped = false, busy = false, lastPass = -Infinity;
135
+ const pass = async (viewed) => {
136
+ if (stopped || busy)
137
+ return;
138
+ const now = clock();
139
+ if (!planLimitsWanted(store, now))
140
+ return;
141
+ if (viewed && now.getTime() - lastPass < VIEWED_PASS_GAP_MS)
142
+ return;
143
+ busy = true;
144
+ lastPass = now.getTime();
145
+ try {
146
+ const stillWanted = () => !stopped && planLimitsWanted(store, clock());
147
+ await codexLimitsPass(store, { signedIn: seams.signedIn, stopped: () => stopped, stillWanted, ...(seams.readCodex === undefined ? {} : { read: seams.readCodex }) });
148
+ if (stillWanted()) {
149
+ await refreshSubscriptions(store, store.databaseFile(), { skipCodex: true, now: clock(), stillWanted, ...(seams.readers === undefined ? {} : { readers: seams.readers }) });
150
+ }
151
+ }
152
+ catch {
153
+ }
154
+ finally {
155
+ busy = false;
156
+ }
157
+ };
158
+ const timer = setInterval(() => void pass(false), everyMs);
159
+ timer.unref?.();
160
+ const first = setTimeout(() => void pass(false), 10_000);
161
+ first.unref?.();
162
+ const stopListening = onPlanLimitsViewed(store, () => void pass(true));
163
+ return () => { stopped = true; clearInterval(timer); clearTimeout(first); stopListening(); };
164
+ }
@@ -62,6 +62,7 @@ export const CONSOLE_FORMS = {
62
62
  threadTurn: formContract("POST /agents/live/thread/<id>/turn", ["message", "key", "password"]),
63
63
  threadShip: formContract("POST /agents/live/thread/<id>/ship", ["terms", "digest"]),
64
64
  threadSendBack: formContract("POST /agents/live/thread/<id>/ship/send-back", ["feedback", "key", "password"]),
65
+ threadSave: formContract("POST /agents/live/thread/<id>/save", []),
65
66
  threadClose: formContract("POST /agents/live/thread/<id>/stop, /agents/live/thread/<id>/end, /agents/live/thread/<id>/ship/cancel", []),
66
67
  term: formContract("POST /term/start, /term/<terminal>/close, /term/<terminal>/remove", ["repo", "program", "password", "task", "run"]),
67
68
  termAgent: formContract("POST /term/agent/sign-in, /term/agent/install", ["agent", "password", "confirm"]),
@@ -219,6 +220,7 @@ export const CONSOLE_FORMS = {
219
220
  directChatShipCancel: formContract("POST /engine/direct-chats/<id>/ship-cancel", ["shipId"]),
220
221
  directChatPageShipReview: formContract("POST /direct-chats/<id>/ship-review", []),
221
222
  directChatPageShip: formContract("POST /direct-chats/<id>/ship", ["mode", "termsDigest", "title", "goal", "password"]),
223
+ directChatPageReply: formContract("POST /direct-chats/<id>/reply", ["prompt", "request"]),
222
224
  };
223
225
  export const BODILESS_POSTS = [
224
226
  "POST /settings/models/<unknown action>",
@@ -605,10 +605,12 @@ function shownPatch(text) {
605
605
  }
606
606
  const PRIVATE_KEY_MARK = /-----(?:BEGIN|END) [A-Z ]*PRIVATE KEY-----/;
607
607
  const HIDDEN_NAME = "[a name was hidden]";
608
- export function threadDiffOf(thread, turn, changes) {
608
+ export function threadDiffOf(thread, turn, changes, seen = {}) {
609
609
  const empty = (problem) => ({ version: ENGINE_API_VERSION, task: thread, run: turn, totals: null, files: [], patchTruncated: false, problem });
610
610
  if (!changes.ok)
611
611
  return empty(`This thread's changes can't be read: ${cleanLiveText(changes.message)}`);
612
+ if ("none" in changes && seen.edited === true)
613
+ return empty("The agent has uncommitted edits. Ask it to commit them: Ship and Save as branch take committed work only.");
612
614
  if ("none" in changes)
613
615
  return empty("No committed changes yet. Ask the agent to commit its work: Ship sends committed work only.");
614
616
  const files = patchFiles(changes.patch).map((text, index) => {
@@ -786,6 +786,44 @@ export async function flexibleTaskBranch(store, input) {
786
786
  : await build(project, ["update-ref", "--no-deref", "-d", ref, input.at]);
787
787
  return done.code === 0;
788
788
  }
789
+ export async function projectThreadBranch(store, input) {
790
+ const thread = flexibleThread(store, input.thread);
791
+ if (thread === null)
792
+ return "unreadable";
793
+ let project;
794
+ try {
795
+ project = realpathSync(thread.repo);
796
+ recordedCommonDir(project);
797
+ }
798
+ catch {
799
+ return "unreadable";
800
+ }
801
+ const read = gitIn(input.runner ?? run, "read");
802
+ const held = await read(project, ["rev-parse", "--verify", "--quiet", "--end-of-options", `refs/heads/${flexibleThreadBranch(thread.id)}`]);
803
+ if (held.code === 0 && SHA.test(held.stdout.trim()))
804
+ return held.stdout.trim();
805
+ return held.code === 1 ? null : "unreadable";
806
+ }
807
+ export async function projectMergeHint(store, input) {
808
+ const thread = flexibleThread(store, input.thread);
809
+ if (thread === null || !SHA.test(input.candidate))
810
+ return null;
811
+ let project;
812
+ try {
813
+ project = realpathSync(thread.repo);
814
+ recordedCommonDir(project);
815
+ }
816
+ catch {
817
+ return null;
818
+ }
819
+ const read = gitIn(input.runner ?? run, "read");
820
+ const head = await read(project, ["symbolic-ref", "-q", "HEAD"]);
821
+ const ref = head.code === 0 ? head.stdout.trim() : "";
822
+ if (!ref.startsWith("refs/heads/"))
823
+ return { repo: project, branch: null, fastForward: false };
824
+ const ancestor = await read(project, ["merge-base", "--is-ancestor", "--end-of-options", ref, input.candidate]);
825
+ return { repo: project, branch: ref.slice("refs/heads/".length), fastForward: ancestor.code === 0 };
826
+ }
789
827
  export async function settleInterruptedImport(store, input) {
790
828
  const thread = flexibleThread(store, input.thread);
791
829
  if (thread === null)
@@ -0,0 +1,128 @@
1
+ import { createHash } from "node:crypto";
2
+ import { canonicalJson } from "./canonical-json.js";
3
+ import { flexibleStanding } from "./flexible.js";
4
+ import { flexibleImportRef, importFlexibleCandidate, projectMergeHint, projectThreadBranch, readFlexibleCandidate } from "./flexible-import.js";
5
+ import { branchHeld, nextSeq, turnRunning } from "./flexible-ship.js";
6
+ import { flexibleThread, flexibleThreadBranch, withFlexibleThreadLock } from "./flexible-thread.js";
7
+ import { machineActing } from "./scope.js";
8
+ const WORDS = Object.freeze({
9
+ "machine-proof": "Only a person can save a thread's work. Nothing was saved.",
10
+ "thread-unknown": "There's no such thread.",
11
+ "not-owner": "Only the person who started this thread can save its work. Nothing was saved.",
12
+ "not-an-approver": "Only an approver for this project can save a thread's work. Nothing was saved.",
13
+ "stale-generation": "Your account changed since you signed in. Sign in again and retry. Nothing was saved.",
14
+ "thread-running": "The agent is still working on your last message. Wait for it, or stop its turn, then save. Nothing was saved.",
15
+ "thread-removed": "This thread's working copy was removed, so there's nothing left to save.",
16
+ "changed": "The thread changed while it was being saved. Try again. Nothing was saved.",
17
+ "branch-gone": "Toolroll saved this work before, but its branch was deleted from your repository since. Toolroll doesn't make it again by itself. Nothing was changed.",
18
+ "branch-moved": "This thread's branch in your repository was changed by someone else since Toolroll saved it. Toolroll won't overwrite it. Nothing was changed.",
19
+ });
20
+ const refuse = (reason) => ({ ok: false, reason, message: WORDS[reason] });
21
+ export const flexibleSaveDigestOf = (terms) => createHash("sha256").update(`standing-orders:flexible-save:${canonicalJson(terms)}`, "utf8").digest("hex").slice(0, 32);
22
+ const shellWord = (text) => /^[A-Za-z0-9_./~+@%=:,-]+$/.test(text) ? text : `'${text.replace(/'/g, "'\\''")}'`;
23
+ function saverStanding(store, thread, by) {
24
+ if (thread.createdBy !== by.name)
25
+ return refuse("not-owner");
26
+ const account = store.accountOf(by.name);
27
+ if (account === null || account.revokedAt !== null || account.role !== "approver" || !store.accountCanAccess(by.name, thread.repo))
28
+ return refuse("not-an-approver");
29
+ if (account.generation !== by.generation)
30
+ return refuse("stale-generation");
31
+ return null;
32
+ }
33
+ async function nextWords(store, thread, candidate, branch, runner) {
34
+ const hint = await projectMergeHint(store, { thread, candidate, ...(runner === undefined ? {} : { runner }) });
35
+ if (hint === null)
36
+ return `To use it: merge ${branch} in your repository.`;
37
+ const repo = shellWord(hint.repo);
38
+ if (hint.branch === null)
39
+ return `To use it: check out the branch you want it on, then run \`git -C ${repo} merge --ff-only ${branch}\`.`;
40
+ if (hint.fastForward)
41
+ return `To put it on ${hint.branch}: \`git -C ${repo} merge --ff-only ${branch}\`.`;
42
+ return `${hint.branch} moved since the thread started, so it won't fast-forward. To merge it: \`git -C ${repo} merge ${branch}\`.`;
43
+ }
44
+ export async function saveFlexibleBranch(store, input) {
45
+ if (machineActing())
46
+ return refuse("machine-proof");
47
+ const first = flexibleThread(store, input.thread);
48
+ if (first === null)
49
+ return refuse("thread-unknown");
50
+ const early = saverStanding(store, first, input.by);
51
+ if (early !== null)
52
+ return early;
53
+ if (first.state !== "ready")
54
+ return refuse("thread-removed");
55
+ const runner = input.runner === undefined ? {} : { runner: input.runner };
56
+ const locked = await withFlexibleThreadLock(input.thread, async () => {
57
+ if (turnRunning(store, input.thread))
58
+ return refuse("thread-running");
59
+ const read = await readFlexibleCandidate(store, { thread: input.thread, ...runner });
60
+ if (!read.ok)
61
+ return read;
62
+ const branch = flexibleThreadBranch(input.thread);
63
+ const held = branchHeld(store, input.thread);
64
+ if (held === read.candidate) {
65
+ const actual = await projectThreadBranch(store, { thread: input.thread, ...runner });
66
+ if (actual === null)
67
+ return refuse("branch-gone");
68
+ if (actual !== read.candidate)
69
+ return refuse("branch-moved");
70
+ return { ok: true, already: true, branch, candidate: read.candidate, seq: null, changedPaths: read.changedPaths, next: await nextWords(store, input.thread, read.candidate, branch, input.runner) };
71
+ }
72
+ const at = input.now.toISOString();
73
+ const recorded = store.transact(() => {
74
+ const thread = flexibleThread(store, input.thread);
75
+ if (thread === null)
76
+ return refuse("thread-unknown");
77
+ if (thread.state !== "ready")
78
+ return refuse("thread-removed");
79
+ const standing = saverStanding(store, thread, input.by);
80
+ if (standing !== null)
81
+ return standing;
82
+ if (!input.prove())
83
+ return refuse("stale-generation");
84
+ if (branchHeld(store, thread.id) !== held)
85
+ return refuse("changed");
86
+ const seq = nextSeq(store, thread.id);
87
+ const terms = { kind: "flexible-save", version: 1, thread: thread.id, repo: thread.repo, owner: input.by.name, ownerGeneration: input.by.generation, seq,
88
+ base: read.base, candidate: read.candidate, branch, importRef: flexibleImportRef(thread.id, seq), changedPaths: read.changedPaths };
89
+ const digest = flexibleSaveDigestOf(terms);
90
+ const live = flexibleStanding(store, thread.repo);
91
+ store.handle.prepare(`INSERT INTO flexible_ship (id, thread, seq, repo, base_sha, candidate, import_ref, branch, branch_before, terms_json, digest, summary_key, approved_by, approved_generation, proof, approved_at, delegation_id, state, state_at)
92
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'session', ?, ?, 'approved', ?)`).run(digest, thread.id, seq, thread.repo, terms.base, terms.candidate, terms.importRef, branch, held, canonicalJson(terms), digest, digest, input.by.name, input.by.generation, at, live.state === "on" ? live.id : 0, at);
93
+ store.recordAction({ at, actor: input.by.name, repo: thread.repo, taskId: null, runId: null, source: "work", action: "flexible branch saved", outcome: "flexible-save",
94
+ detail: `thread ${thread.id} · save ${seq} · candidate ${read.candidate} · ${branch}` });
95
+ return { seq, digest };
96
+ });
97
+ if ("ok" in recorded)
98
+ return recorded;
99
+ const imported = await importFlexibleCandidate(store, { thread: input.thread, seq: recorded.seq, expected: read.candidate, branchBefore: held, by: input.by.name, now: input.now, ...runner });
100
+ if (!imported.ok) {
101
+ store.transact(() => {
102
+ store.handle.prepare("UPDATE flexible_ship SET state = 'refused', reason = ?, detail = ?, state_at = ? WHERE id = ? AND state = 'approved'")
103
+ .run("check" in imported ? imported.check : imported.reason, imported.message.slice(0, 2000), at, recorded.digest);
104
+ });
105
+ return imported;
106
+ }
107
+ store.transact(() => { store.handle.prepare("UPDATE flexible_ship SET state = 'imported', state_at = ? WHERE id = ? AND state = 'approved'").run(at, recorded.digest); });
108
+ return { ok: true, already: false, branch, candidate: read.candidate, seq: recorded.seq, changedPaths: read.changedPaths, next: await nextWords(store, input.thread, read.candidate, branch, input.runner) };
109
+ });
110
+ if (locked.ok === false && (locked.reason === "not-available" || locked.reason === "thread-unknown"))
111
+ return refuse("thread-unknown");
112
+ return locked;
113
+ }
114
+ export function isFlexibleSave(termsJson) {
115
+ try {
116
+ return JSON.parse(String(termsJson)).kind === "flexible-save";
117
+ }
118
+ catch {
119
+ return false;
120
+ }
121
+ }
122
+ export function latestFlexibleSave(store, thread) {
123
+ const rows = store.handle.prepare("SELECT seq, candidate, terms_json, state_at FROM flexible_ship WHERE thread = ? AND state = 'imported' AND task_id IS NULL ORDER BY seq DESC").all(thread);
124
+ const newest = rows[0];
125
+ if (newest === undefined || !isFlexibleSave(newest["terms_json"]))
126
+ return null;
127
+ return { seq: Number(newest["seq"]), candidate: String(newest["candidate"]), at: String(newest["state_at"]) };
128
+ }
@@ -905,7 +905,7 @@ export async function flexibleThreadShipTerms(store, input) {
905
905
  return refuse("thread-unknown");
906
906
  const needs = flexibleShipNeeds(store, owned.repo);
907
907
  if (needs !== null)
908
- return { ok: false, reason: needs.reason, message: needs.message };
908
+ return { ok: false, reason: needs.reason, message: `${needs.message} ${saveInsteadWords(input.thread)}` };
909
909
  const shown = await flexibleShipTerms(store, { thread: input.thread, by: input.by.name });
910
910
  if (!shown.ok)
911
911
  return shown;
@@ -1263,7 +1263,7 @@ export function flexibleShipNeedsFor(store, asked) {
1263
1263
  if (found.length !== 1)
1264
1264
  return null;
1265
1265
  const needs = flexibleShipNeeds(store, String(found[0]["repo"]));
1266
- return needs === null ? null : { reason: needs.reason, message: needs.message };
1266
+ return needs === null ? null : { reason: needs.reason, message: `${needs.message} ${saveInsteadWords(asked)}` };
1267
1267
  }
1268
1268
  async function stopSessionLocked(store, sessions, input) {
1269
1269
  const clocked = input.clock === undefined ? {} : { clock: input.clock };
@@ -1361,3 +1361,10 @@ export async function flexibleThreadChanges(store, input) {
1361
1361
  return { tip: read.base, changes: { ok: true, none: true } };
1362
1362
  return { tip: read.tip, changes: { ok: true, patch: read.patch, truncated: read.truncated } };
1363
1363
  }
1364
+ function saveInsteadWords(thread) {
1365
+ return `To use its work now, save it as a branch in your repository instead (S on the thread in \`toolroll\`, or \`toolroll thread save ${thread.slice(0, 8)}\`).`;
1366
+ }
1367
+ export function flexibleThreadEdited(sessions, input) {
1368
+ const session = sessions.threads.get(input.thread);
1369
+ return session !== undefined && session.records.some(one => one.k === "step" && one.kind === "edit");
1370
+ }
@@ -118,12 +118,12 @@ function shipProofNow(store, by, proof, repo) {
118
118
  return refuse("laptop", problem);
119
119
  return { method: "local-owner", localGeneration: local.localGeneration, accountGeneration: local.accountGeneration };
120
120
  }
121
- const turnRunning = (store, thread) => store.handle.prepare("SELECT 1 FROM thread_turn WHERE thread = ? AND status IN ('admitted', 'running')").get(thread) !== undefined;
122
- function branchHeld(store, thread) {
121
+ export const turnRunning = (store, thread) => store.handle.prepare("SELECT 1 FROM thread_turn WHERE thread = ? AND status IN ('admitted', 'running')").get(thread) !== undefined;
122
+ export function branchHeld(store, thread) {
123
123
  const row = store.handle.prepare("SELECT candidate FROM flexible_ship WHERE thread = ? AND state IN ('imported', 'armed', 'completed', 'merged', 'cancelled', 'sent-back') ORDER BY seq DESC LIMIT 1").get(thread);
124
124
  return row === undefined ? null : String(row["candidate"]);
125
125
  }
126
- const nextSeq = (store, thread) => Number(store.handle.prepare("SELECT COALESCE(MAX(seq), 0) + 1 AS n FROM flexible_ship WHERE thread = ?").get(thread)["n"]);
126
+ export const nextSeq = (store, thread) => Number(store.handle.prepare("SELECT COALESCE(MAX(seq), 0) + 1 AS n FROM flexible_ship WHERE thread = ?").get(thread)["n"]);
127
127
  function destinationOf(store, repo) {
128
128
  const grant = store.publicationGrantFor(repo);
129
129
  if (grant === null || !grant.capabilities.includes("push-branch") || !grant.capabilities.includes("open-pr"))
@@ -309,7 +309,7 @@ async function removeLocked(store, input) {
309
309
  keepRef = "removed";
310
310
  else
311
311
  keepRef = (await read(project, ["rev-parse", "--verify", "--quiet", "--end-of-options", thread.keepRef])).code === 0 ? "moved" : "already-gone";
312
- const ships = store.handle.prepare("SELECT import_ref, candidate, state FROM flexible_ship WHERE thread = ? ORDER BY seq").all(thread.id);
312
+ const ships = store.handle.prepare("SELECT import_ref, candidate, state, json_extract(terms_json, '$.kind') AS kind FROM flexible_ship WHERE thread = ? ORDER BY seq").all(thread.id);
313
313
  for (const ship of ships.filter(one => ["imported", "merged", "cancelled", "sent-back"].includes(String(one["state"])))) {
314
314
  const gone = await build(project, ["update-ref", "--no-deref", "-d", String(ship["import_ref"]), String(ship["candidate"])]);
315
315
  if (gone.code === 0)
@@ -318,7 +318,7 @@ async function removeLocked(store, input) {
318
318
  shipRefsLeft++;
319
319
  }
320
320
  const standing = [...ships].reverse().find(one => ["imported", "merged", "cancelled", "sent-back"].includes(String(one["state"])));
321
- if (standing !== undefined) {
321
+ if (standing !== undefined && standing["kind"] !== "flexible-save") {
322
322
  const branch = `refs/heads/${flexibleThreadBranch(thread.id)}`;
323
323
  const gone = await build(project, ["update-ref", "--no-deref", "-d", branch, String(standing["candidate"])]);
324
324
  if (gone.code === 0)
@@ -0,0 +1,32 @@
1
+ import { soloNow } from "./install-mode.js";
2
+ import { localModeOn } from "./local-owner.js";
3
+ import { localWorkEligible } from "./scope.js";
4
+ export const LOCAL_CHECKS_CEILING = "sign-ins";
5
+ const WORDS = {
6
+ team: "Running checks without a password works only on a solo install. Sign in with your password to run them.",
7
+ "local-mode-off": "Local mode is off, so running checks needs your password.",
8
+ "not-owner": "Only this computer's owner runs checks here without a password.",
9
+ "no-scope": "This task has no approved plan, so running its checks needs your password.",
10
+ release: "Running a release's checks needs your password.",
11
+ protected: "This is protected work, so running its checks needs your password.",
12
+ escalated: "Work with wider permissions needs your password to run its checks.",
13
+ coordinator: "Work a coordinator filed needs your password to run its checks.",
14
+ unsandboxed: "This project's checks run without a sandbox, so running them needs your password.",
15
+ imported: "A task from outside needs your password to run its checks.",
16
+ };
17
+ export function localChecksRefusal(store, by, taskId) {
18
+ if (!soloNow(store))
19
+ return WORDS.team;
20
+ const eligible = localWorkEligible(store, by, taskId, { act: "retry" });
21
+ return eligible.ok ? null : WORDS[eligible.reason];
22
+ }
23
+ export function localChecksStanding(store, input) {
24
+ if (!soloNow(store) || !localModeOn(store))
25
+ return { ok: false, problem: "Asked for without a password, and the install is no longer solo with local mode on, so they didn't run." };
26
+ const refused = localChecksRefusal(store, input.by, input.taskId);
27
+ if (refused !== null)
28
+ return { ok: false, problem: `Asked for without a password, and now: ${refused}` };
29
+ return { ok: true, access: LOCAL_CHECKS_CEILING };
30
+ }
31
+ export class LocalChecksLapsed extends Error {
32
+ }