toolroll 0.9.112 → 0.9.114

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 (52) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/README.md +28 -29
  3. package/dist/backup.js +29 -0
  4. package/dist/contracts/console-api.js +5 -1
  5. package/dist/contracts/engine-api.js +12 -0
  6. package/dist/easy-start.js +12 -7
  7. package/dist/engine-reads.js +20 -2
  8. package/dist/fast-terms.js +8 -4
  9. package/dist/flexible-agents.js +2 -8
  10. package/dist/flexible-answers.js +4 -26
  11. package/dist/flexible-available.js +31 -1
  12. package/dist/flexible-import.js +2 -14
  13. package/dist/flexible-launch.js +15 -3
  14. package/dist/flexible-launcher.js +0 -5
  15. package/dist/flexible-relay.js +66 -75
  16. package/dist/flexible-session.js +130 -36
  17. package/dist/flexible-setting-schema.js +10 -0
  18. package/dist/flexible-ship.js +8 -18
  19. package/dist/flexible-sign-in-schema.js +47 -0
  20. package/dist/flexible-sign-in-slot.js +4 -0
  21. package/dist/flexible-sign-in.js +470 -0
  22. package/dist/flexible-start.js +27 -8
  23. package/dist/flexible-thread.js +21 -27
  24. package/dist/flexible-turns.js +22 -17
  25. package/dist/flexible.js +9 -11
  26. package/dist/flow-triggers.js +4 -1
  27. package/dist/live-terminal.js +28 -0
  28. package/dist/local-owner.js +1 -0
  29. package/dist/operate.js +170 -4
  30. package/dist/release.js +1 -0
  31. package/dist/serve.js +9 -0
  32. package/dist/server/engine-api.js +112 -32
  33. package/dist/server/mutation-key.js +6 -0
  34. package/dist/server/people-tokens.js +10 -1
  35. package/dist/server/route-table.js +6 -0
  36. package/dist/server/settings-section-table.js +7 -0
  37. package/dist/server/settings-sections.js +87 -1
  38. package/dist/server/settings.js +123 -3
  39. package/dist/server/terminals.js +3 -3
  40. package/dist/settings-groups-ui.js +3 -0
  41. package/dist/settings-proofs.js +5 -0
  42. package/dist/store.js +71 -5
  43. package/dist/tool-secret-store.js +105 -0
  44. package/dist/toolroll-update.js +2 -1
  45. package/dist/tui/darwin-arm64/toolroll-tui +0 -0
  46. package/dist/tui/darwin-x64/toolroll-tui +0 -0
  47. package/dist/tui/linux-arm64/toolroll-tui +0 -0
  48. package/dist/tui/linux-x64/toolroll-tui +0 -0
  49. package/dist/tui-contract.js +2 -1
  50. package/dist/tui-launch.js +3 -1
  51. package/dist/work-index.js +4 -0
  52. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -4,6 +4,64 @@ Each release opens with one line on its theme, then **New**, **Changed**, **Fixe
4
4
  the ones it has). Each item is at most two lines and says where to find it. Notes for maintainers (CI, the release
5
5
  tooling) go on the GitHub release, not here. Entries before 0.9.104 use the older format.
6
6
 
7
+ ## 0.9.114 — 2026-11-17
8
+
9
+ Interactive agent threads (beta) now run on each person's own Claude sign-in.
10
+
11
+ ### New
12
+
13
+ - **Your Claude sign-in for threads.** Settings → General, or `toolroll config set flexible-sign-in`: paste a Claude
14
+ setup-token and confirm with your password. Toolroll checks it with a free token count and says what it found.
15
+ - **Each person uses their own.** A thread always runs on the sign-in of the person who started it, never someone
16
+ else's. Operators can remove a person's sign-in on People but never see or set it.
17
+
18
+ ### Changed
19
+
20
+ - **Turning on threads walks you through it in order:** threads on, then your sign-in, then the project's terms. The
21
+ workbench and the Agents page point to the next step.
22
+ - **When Claude can't be used, the thread says why and stops** (no sign-in, a refused sign-in, threads turned off)
23
+ instead of retrying silently or suggesting `/login`.
24
+
25
+ ### Fixed
26
+
27
+ - **Removing a sign-in, a password reset or a removed account** stops that person's running threads
28
+ at once, mid-answer too.
29
+ - **Saving a sign-in in the terminal always asks for your password,** even when a login is remembered on the computer.
30
+
31
+ ## 0.9.113 — 2026-11-17
32
+
33
+ The terminal workbench for people coming from herdr: a clear first screen, a build shell that can't take your keys by
34
+ mistake, approving a sent-back plan without leaving the terminal, and interactive agent threads as a beta switch.
35
+
36
+ ### New
37
+
38
+ - **Interactive agent threads (beta).** Settings → General, or `toolroll config set flexible on` (your password).
39
+ Off by default; Claude Code only for now; `T` starts a thread. Turning it off stops running threads.
40
+ - **Approve a sent-back plan in the workbench.** After you send a result back, press `a` on the revision to read its
41
+ terms and approve them; `w` still opens it in your browser.
42
+ - **Watch running tasks** from the command palette (`:`): every running task in its own panel.
43
+ - **Coming from herdr?** `docs/guide/from-herdr.md` maps the keys and says what differs.
44
+
45
+ ### Changed
46
+
47
+ - **"Take over" is now "Open build shell"** and asks first: it opens a shell in a separate copy of the build and
48
+ never controls the running agent.
49
+ - **Quitting asks** whether to stop the agents or keep them running, and prints how to reopen.
50
+ - **Panel headers lead with the task,** its state and cost; long titles wrap instead of being cut.
51
+ - **`toolroll view reset` keeps your keys** and names its backup by date; nothing is backed up when already default.
52
+ - **The README opens with the terminal loop** and a real screenshot of the workbench.
53
+
54
+ ### Fixed
55
+
56
+ - **Open build shell on a task with no saved build** refuses at once; your typing can no longer reach workbench keys.
57
+ - **A sent-back task no longer closes the workbench** with "isn't what this version expects"; one task's
58
+ unreadable steps only affect that task.
59
+ - **"Building it." clears** when a task moves on to waiting, retrying, Ready or failed.
60
+ - **The mail inbox never skips an email** when two checks overlap.
61
+ - **Threads start in a project `toolroll` added itself,** and the new-task box shows while a thread is open.
62
+ - **`tui.toml` with both `list-side` and `list_side`** reads back the same after a change (the dashed spelling wins).
63
+ - **Turning on threads without a password** tells you to set one first (`toolroll password set`), in plain words.
64
+
7
65
  ## 0.9.112 — 2026-11-16
8
66
 
9
67
  A security release: keys and folder paths in an agent's output never leave Toolroll. Plus asking your agent to restyle
package/README.md CHANGED
@@ -7,8 +7,15 @@
7
7
 
8
8
  ### Your agents build. You decide.
9
9
 
10
- For Claude Code, Codex and Gemini, on your own machine.<br>
11
- Approve each plan once. Get results back Ready with the diff, the check status and screenshots.
10
+ **Delegate a change. Review the diff here.**
11
+
12
+ <picture>
13
+ <source media="(prefers-color-scheme: light)" srcset="docs/media/terminal-workbench-light.png">
14
+ <img src="docs/media/terminal-workbench.png" alt="The Toolroll terminal workbench: the work list with two tasks that need you, and the Live tab following a running build" width="900">
15
+ </picture>
16
+ <sub>The terminal workbench, shown with sample tasks and output.</sub>
17
+
18
+ For Claude Code, Codex and Gemini, on your own machine.
12
19
 
13
20
  [![npm](https://img.shields.io/npm/v/toolroll?color=171717)](https://www.npmjs.com/package/toolroll)
14
21
  [![CI](https://github.com/ap9000/toolroll/actions/workflows/ci.yml/badge.svg)](https://github.com/ap9000/toolroll/actions/workflows/ci.yml)
@@ -18,13 +25,6 @@ Approve each plan once. Get results back Ready with the diff, the check status a
18
25
 
19
26
  **[Website](https://toolroll.dev)** · [Docs](docs/guide/README.md) · [For agents](docs/agents.md) · [Use cases](https://toolroll.dev/use-cases) · [Changelog](CHANGELOG.md)
20
27
 
21
- <picture>
22
- <source media="(prefers-color-scheme: dark)" srcset="docs/media/ui/tasks-dark.png">
23
- <img src="docs/media/ui/tasks-light.png" alt="The Tasks page in Toolroll: tasks grouped by what they need from you (approve a plan, open a result, unblock), each with one button." width="920">
24
- </picture>
25
-
26
- <sub>Every task across every project, and the one thing each needs from you. (Demo workspace.)</sub>
27
-
28
28
  </div>
29
29
 
30
30
  ## Quick start
@@ -48,36 +48,35 @@ The first command removes Toolroll's older package, `standing-orders`, if you
48
48
  have it: npm can't install over it (it stops with `EEXIST: file already
49
49
  exists … bin/standing-orders`). Without it, the command does nothing.
50
50
 
51
- Toolroll opens in your terminal and runs while that window is open. No
51
+ Toolroll opens in your terminal. On quit, choose whether agents keep running. No
52
52
  password and no login file: on your own computer you're already in. Started
53
53
  in a git repository, that repository is your project; press `n` for a first
54
- task, approve the plan, and the result comes back **Ready**. Elsewhere, press
54
+ task and describe the change. Enter chooses **Just code**; Tab switches to
55
+ **Plan first**, then Enter submits. Review any proposed build terms before
56
+ starting. The result comes back **Ready**: review the diff with Enter, then
57
+ press `a` to accept (confirm after reading), or `r` to request a revision. Elsewhere, press
55
58
  `s` to try a small sample project, add your own with
56
59
  `toolroll repos add <folder>`, or open the browser (press `w`, or run
57
60
  `toolroll --web`). To look around
58
61
  first, `toolroll demo` opens a seeded sandbox with no model calls and no spend.
59
62
  More: [Getting started](docs/guide/getting-started.md).
60
63
 
61
- ## How it works
64
+ ## The terminal loop
62
65
 
63
- ```
64
- describe ─▶ plan ─▶ approve ─▶ build ─▶ check ─▶ Ready ─▶ you decide
65
- you agent exact diff Complete,
66
- commit + checks send back or merge
67
- ```
66
+ **Install → `toolroll` → `n` → describe → Enter → build → review diff → accept.**
67
+
68
+ Enter in the new-task composer chooses **Just code** by default. Tab toggles
69
+ **Plan first**; Enter then submits that choice. Just code skips planning, not
70
+ the build terms or safety checks. Plan first drafts a scope for you to review
71
+ and approve before building.
72
+
73
+ Agents work on their own branches. A judgement call becomes a question for
74
+ you. A result becomes **Ready**, awaiting your review, with its diff and actual
75
+ check status. Accept marks it Complete; publishing and merging need their own
76
+ approvals. Set your project's check to verify the exact result.
68
77
 
69
- 1. **Describe** the outcome in Chat, the terminal or your phone.
70
- 2. **Plan.** Toolroll reads the repository and drafts the goal, what's out of
71
- bounds, the requirements, and the exact agent and model.
72
- 3. **Approve** once. Nothing spends until you do; changing the terms asks again.
73
- 4. **Build.** An agent works on its own branch. A judgement call
74
- becomes a question for you, not a guess.
75
- 5. **Check.** Once you set your project's check, it runs on the exact commit.
76
- 6. **Ready.** The diff, the check log and screenshots. Mark it Complete, send
77
- it back with what to change, or merge through the pull request.
78
-
79
- Approving work you start on this computer needs no password. Hands-off modes,
80
- merging, releasing and most settings ask you to set one first: `toolroll password set`.
78
+ [Coming from herdr](docs/guide/from-herdr.md) ·
79
+ [Terminal keys and layouts](docs/guide/getting-started.md#the-terminal-workbench)
81
80
 
82
81
  ## Use cases
83
82
 
package/dist/backup.js CHANGED
@@ -7,6 +7,7 @@ import { BACKUP_EVERY_HOURS, MAX_KEEP } from "./backup-ui.js";
7
7
  import { verifyLedgerChain } from "./ledger-chain.js";
8
8
  import { DEFAULT_LIVENESS_MS } from "./runner.js";
9
9
  import { openStore, readSchemaVersion, SCHEMA_VERSION } from "./store.js";
10
+ import { resetFlexibleSignInsForRestore } from "./flexible-sign-in.js";
10
11
  const BACKUP_NAME = /^(?:toolroll|standing-orders)-(?:([0-9a-f]{8})-)?(\d{4}-\d{2}-\d{2}-\d{6})(?:-(\d+))?\.db$/;
11
12
  export const OLDEST_RESTORABLE = 103;
12
13
  export { BACKUP_EVERY_HOURS, MAX_KEEP };
@@ -326,14 +327,41 @@ export async function restoreDatabase(options) {
326
327
  }
327
328
  report.savedAs = saved;
328
329
  const store = openStore(databaseFile);
330
+ let carried;
329
331
  try {
330
332
  const running = runningNow(store, new Date());
331
333
  if (running.length > 0)
332
334
  return refuse("running", `Toolroll started (${running.join(" and ")}). Stop it first, then restore. The database is unchanged.`);
335
+ carried = store.handle.prepare("SELECT person, generation, account_generation FROM flexible_sign_in").all()
336
+ .map(row => ({ person: String(row["person"]), generation: String(row["generation"]), accountGeneration: Number(row["account_generation"]) }));
333
337
  }
334
338
  finally {
335
339
  store.close();
336
340
  }
341
+ try {
342
+ const prepared = openStore(staged);
343
+ try {
344
+ prepared.transact(() => { resetFlexibleSignInsForRestore(prepared, { now, carried }); });
345
+ }
346
+ finally {
347
+ prepared.close();
348
+ }
349
+ const folded = connect(staged);
350
+ try {
351
+ folded.exec("PRAGMA wal_checkpoint(TRUNCATE)");
352
+ folded.exec("PRAGMA journal_mode = DELETE");
353
+ }
354
+ finally {
355
+ folded.close();
356
+ }
357
+ for (const suffix of ["-wal", "-shm", "-journal"])
358
+ rmSync(`${staged}${suffix}`, { force: true });
359
+ }
360
+ catch (error) {
361
+ for (const suffix of ["-wal", "-shm", "-journal"])
362
+ rmSync(`${staged}${suffix}`, { force: true });
363
+ return refuse("schema", `That backup doesn't open as a Toolroll database (${firstLine(error)}). The database is unchanged.`);
364
+ }
337
365
  const live = connect(databaseFile);
338
366
  try {
339
367
  live.exec("PRAGMA wal_checkpoint(TRUNCATE)");
@@ -346,6 +374,7 @@ export async function restoreDatabase(options) {
346
374
  rmSync(`${databaseFile}${suffix}`, { force: true });
347
375
  renameSync(staged, databaseFile);
348
376
  keepStaged = true;
377
+ options.afterPublish?.();
349
378
  let restored;
350
379
  try {
351
380
  restored = openStore(databaseFile);
@@ -51,10 +51,14 @@ export const CONSOLE_FORMS = {
51
51
  localModeOff: formContract("POST /settings/local-mode/off", ["password"]),
52
52
  justMe: formContract("POST /settings/install-mode/solo", ["password"]),
53
53
  taskSizing: formContract("POST /settings/task-sizing", ["password", "enabled", "sizer"]),
54
+ flexibleSwitch: formContract("POST /settings/flexible", ["password", "enabled"]),
55
+ flexibleSignIn: formContract("POST /settings/flexible-sign-in", ["token", "password"]),
56
+ flexibleSignInCheck: formContract("POST /settings/flexible-sign-in-check", ["password"]),
57
+ flexibleSignInClear: formContract("POST /settings/flexible-sign-in-clear", ["person", "password"]),
54
58
  releaseApproval: formContract("POST /settings/release-approval", ["repo", "action", "password"]),
55
59
  projectFlexible: formContract("POST /settings/project/flexible", ["repo", "action", "max", "digest", "password"]),
56
60
  threadAnswer: formContract("POST /agents/live/thread/<id>/answer", ["request", "card", "decision", "question", "answer"]),
57
- threadStart: formContract("POST /agents/live/thread", ["repo", "message", "model", "terms", "password"]),
61
+ threadStart: formContract("POST /agents/live/thread", ["repo", "message", "model", "terms", "password", "agent"]),
58
62
  term: formContract("POST /term/start, /term/<terminal>/close, /term/<terminal>/remove", ["repo", "program", "password", "task", "run"]),
59
63
  termAgent: formContract("POST /term/agent/sign-in, /term/agent/install", ["agent", "password", "confirm"]),
60
64
  agentsCheck: formContract("POST /engine/agents/check", []),
@@ -59,6 +59,7 @@ export const liveSessionWindowSchema = z.object({
59
59
  });
60
60
  export const liveThreadsSchema = z.object({
61
61
  version,
62
+ on: z.boolean().optional(),
62
63
  threads: z.array(z.object({ id: hex32, title: z.string(), project: z.string().nullable(), level: flexibleLevelSchema.nullable(), live: z.boolean(), waiting: z.number().int(),
63
64
  costUsd: z.number().nullable() })),
64
65
  });
@@ -136,6 +137,7 @@ export const stepCardsSchema = z.object({
136
137
  review: z.object({ run: z.number().int(), receipt: z.string().regex(/^[0-9a-f]{64}$/), source: z.string(),
137
138
  accept: z.object({ owed: z.enum(["person-check", "exception"]).nullable(), blockers: z.array(z.string()), needs: z.string().nullable() }),
138
139
  }).nullable(),
140
+ shell: z.object({ run: z.number().int(), why: z.string().nullable() }).nullable(),
139
141
  failure: z.object({ line: z.string(), failedInARow: z.number().int(), suggestion: z.string().nullable(),
140
142
  agentSaid: z.array(z.string()).max(8).nullable() }).nullable(),
141
143
  waiting: waitingSchema.extend({ agentSaid: z.array(z.string()).max(8).nullable() }).nullable(),
@@ -144,6 +146,15 @@ export const stepCardsSchema = z.object({
144
146
  approval: z.object({ by: z.string(), you: z.boolean(), automatic: z.boolean() }).nullable(),
145
147
  room: z.string(),
146
148
  });
149
+ export const approvalCardSchema = z.object({
150
+ version,
151
+ task: z.string(),
152
+ key: z.string().nullable(),
153
+ digest: z.string().regex(/^[0-9a-f]{64}$/).nullable(),
154
+ nonce: z.string().regex(/^[0-9a-f]{32}$/).nullable(),
155
+ terms: z.array(z.object({ label: z.string(), words: z.string() })),
156
+ problem: z.string().nullable(),
157
+ });
147
158
  const diffProblemSchema = z.string().nullable();
148
159
  export const resultDiffSchema = z.object({
149
160
  version,
@@ -252,6 +263,7 @@ export const ENGINE_RESPONSES = {
252
263
  liveThreads: { route: "GET /agents/live/threads", schema: liveThreadsSchema },
253
264
  workRows: { route: "GET /work/rows", schema: workRowsSchema },
254
265
  stepCards: { route: "GET /t/<task>/steps", schema: stepCardsSchema },
266
+ approvalCard: { route: "GET /t/<task>/approval", schema: approvalCardSchema },
255
267
  resultDiff: { route: "GET /t/<task>/diff", schema: resultDiffSchema },
256
268
  resultDiffFile: { route: "GET /t/<task>/diff?run=&file=", schema: resultDiffFileSchema },
257
269
  resultDiffContext: { route: "GET /t/<task>/diff?run=&file=&from=&count=", schema: resultDiffContextSchema },
@@ -188,8 +188,8 @@ export async function runEasyStart(mode, args, seams) {
188
188
  const session = {
189
189
  owned: () => ownedNow() !== null,
190
190
  stopped: stoppedOnItsOwn,
191
- openBrowser: async () => {
192
- const opened = await seams.openSignedIn();
191
+ openBrowser: async (page) => {
192
+ const opened = await seams.openSignedIn(page);
193
193
  return opened.ok ? "Opened in your browser." : `The browser couldn't be opened: ${opened.message}.`;
194
194
  },
195
195
  shouldAskBackground: () => ownedNow() !== null && !seams.serviceInstalled() && !seams.backgroundAsked(),
@@ -215,14 +215,17 @@ export async function runEasyStart(mode, args, seams) {
215
215
  if (exit === "keep") {
216
216
  const said = await handoff();
217
217
  write(said);
218
- if (ownedNow() === null)
218
+ if (ownedNow() === null) {
219
+ write("Reopen with: toolroll");
219
220
  return EXIT.ok;
221
+ }
220
222
  }
221
223
  write("Stopping Toolroll… (running work is saved)");
222
224
  stopOwned(child);
223
225
  await child.exited;
224
226
  write("Toolroll stopped.");
225
227
  }
228
+ write("Reopen with: toolroll");
226
229
  return EXIT.ok;
227
230
  }
228
231
  export function spawnOwnedUp(args, options) {
@@ -303,7 +306,7 @@ export function defaultEasyStartSeams(options) {
303
306
  spawnUp: args => spawnOwnedUp(args, { cwd, databaseFile: file }),
304
307
  runUpForeground: async (args) => (await import("./operate.js")).runOperate("up", [...args, "--db", file], options.write, options.operate ?? {}),
305
308
  openBrowser: async (url) => { (await import("./operate.js")).openBrowser(url); },
306
- openSignedIn: () => openLocalSignIn(file, options.build),
309
+ openSignedIn: page => openLocalSignIn(file, options.build, page === undefined ? {} : { then: page }),
307
310
  openTui: async (session) => {
308
311
  const { chooseTuiBinary, runTuiBinary } = await import("./tui-launch.js");
309
312
  const { engineContractDigest } = await import("./contracts/engine-api.js");
@@ -426,9 +429,11 @@ export async function openLocalSignIn(databaseFile, build, seams = {}) {
426
429
  try {
427
430
  const spent = ledgerSpent(store, "local link", null);
428
431
  const expiresAt = Date.now() + (seams.expiresMs ?? (await import("./server/session.js")).SIGN_IN_LINK_MS);
429
- const link = await (seams.request ?? (one => requestLocalLink(databaseFile, one, build)))(store);
430
- if (!link.ok)
431
- return link;
432
+ const asked = await (seams.request ?? (one => requestLocalLink(databaseFile, one, build)))(store);
433
+ if (!asked.ok)
434
+ return asked;
435
+ const { isTuiPage } = await import("./tui-contract.js");
436
+ const link = seams.then !== undefined && isTuiPage(seams.then) ? { ...asked, url: `${asked.url}?then=${seams.then}` } : asked;
432
437
  handed = true;
433
438
  const opened = await openSignInLink(link.url, {
434
439
  parent, spent, expiresAt, onEnd: () => store.close(),
@@ -88,6 +88,8 @@ export function stepCardsOf({ store, family, now, access, evidenceRoot, viewer =
88
88
  review: assignment !== null && assignment.state === "ready-to-check" && assignment.receipt !== null && assignment.receipt.taskId === current.id
89
89
  ? { run: assignment.receipt.runId, receipt: assignment.receipt.digest, source: revisionSourceOf(scope?.digest ?? null),
90
90
  accept: acceptFactsOf(store, assignment, viewer, evidenceRoot) } : null,
91
+ shell: shellOf(store, family, assignment !== null && assignment.state === "ready-to-check" && assignment.receipt !== null && assignment.receipt.taskId === current.id
92
+ ? assignment.receipt.runId : builds[0]?.id ?? null),
91
93
  failure: current.state === "failed" ? failureOf(store, ref?.id ?? null, builds) : null,
92
94
  waiting: (() => {
93
95
  const waiting = waitingOf(store, current.id, now);
@@ -103,6 +105,19 @@ export function stepCardsOf({ store, family, now, access, evidenceRoot, viewer =
103
105
  room: `task:${encodeURIComponent(root.id)}`,
104
106
  };
105
107
  }
108
+ 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.";
109
+ export const SHELL_NO_COMMIT = "This build has no saved commit to open a terminal on.";
110
+ function shellOf(store, family, runId) {
111
+ if (runId === null)
112
+ return null;
113
+ const run = resultRunsOf(store, family).find(one => one.id === runId) ?? null;
114
+ if (run === null)
115
+ return { run: runId, why: SHELL_NO_RESULT };
116
+ const revision = run.headRevision;
117
+ if (revision === null || !/^[0-9a-f]{40}(?:[0-9a-f]{24})?$/.test(revision))
118
+ return { run: runId, why: SHELL_NO_COMMIT };
119
+ return { run: runId, why: null };
120
+ }
106
121
  function failureOf(store, taskRef, builds) {
107
122
  const last = latestFinishedAttempt(builds);
108
123
  const failedInARow = taskRef === null ? 0
@@ -326,8 +341,11 @@ export function setupOf(id, home = null) {
326
341
  return { install: setup.install, canInstall: setup.installRun !== null, signIn: setup.signIn, canSignIn: setup.signInRun !== null, key: setup.key, check: setup.check, note: setup.note,
327
342
  registry: registry.url, registryUnsure: registry.unsure };
328
343
  }
329
- export function agentsReadOf(detection, view = "full", home = null) {
330
- const agents = (detection?.agents ?? []).map(one => ({ id: one.id, name: one.name, state: one.state, how: one.how, signIn: one.signIn, ready: one.ready, next: one.next, setup: setupOf(one.id, home) }));
344
+ export function agentsReadOf(detection, view = "full", home = null, claudeNote = null) {
345
+ const agents = (detection?.agents ?? []).map(one => {
346
+ const setup = setupOf(one.id, home);
347
+ return { id: one.id, name: one.name, state: one.state, how: one.how, signIn: one.signIn, ready: one.ready, next: one.next, setup: one.id === "claude" && claudeNote !== null ? { ...setup, note: claudeNote } : setup };
348
+ });
331
349
  const first = detection?.firstTask ?? null;
332
350
  const firstTask = first === null ? null : { id: first, name: agents.find(one => one.id === first)?.name ?? first };
333
351
  if (view === "summary") {
@@ -1,9 +1,15 @@
1
1
  import { describeScope, summaryContextOf } from "./approval-summary.js";
2
2
  const LABELS = { goal: "Goal", "not this": "Not this", files: "Files", budget: "Budget", network: "Network", writes: "Writes", reads: "Reads", checks: "Checks", services: "Services" };
3
3
  export function fastTermsLines(store, scope, repo) {
4
+ const lines = termsOfLines(describeScope(scope, undefined, null, summaryContextOf(store, scope.taskId, scope, new Date(), null, repo)));
5
+ const tools = store.projectTools(repo).map(one => one.name);
6
+ lines.push({ label: "Project tools", words: tools.length === 0 ? "None" : tools.join(", ") });
7
+ return lines;
8
+ }
9
+ export function termsOfLines(raw) {
4
10
  const lines = [];
5
- for (const raw of describeScope(scope, undefined, null, summaryContextOf(store, scope.taskId, scope, new Date(), null, repo))) {
6
- const line = raw.trimEnd();
11
+ for (const one of raw) {
12
+ const line = one.trimEnd();
7
13
  const named = /^ {2}(\S+(?: \S+)?) {2,}(.*)$/.exec(line);
8
14
  if (named !== null && (named[1] === "version" || named[1] === "approved"))
9
15
  continue;
@@ -14,7 +20,5 @@ export function fastTermsLines(store, scope, repo) {
14
20
  else
15
21
  lines.push({ label: "Plan", words: line.trim() });
16
22
  }
17
- const tools = store.projectTools(repo).map(one => one.name);
18
- lines.push({ label: "Project tools", words: tools.length === 0 ? "None" : tools.join(", ") });
19
23
  return lines;
20
24
  }
@@ -1,5 +1,5 @@
1
1
  import { join } from "node:path";
2
- import { FLEXIBLE_AVAILABLE } from "./flexible-available.js";
2
+ import { flexibleAvailable } from "./flexible-available.js";
3
3
  import { flexibleDelegationAtUse, FLEXIBLE_LEVEL_WORDS, FLEXIBLE_LEVELS, FLEXIBLE_UNAVAILABLE, isFlexibleLevel } from "./flexible.js";
4
4
  import { threadLevelAllowed, FLEXIBLE_PROVEN } from "./flexible-levels.js";
5
5
  import { defaultCustodyIO, flexibleLaunch, freshProviderFolder, onLaunchStopped, unsettledLaunch, watchLaunch } from "./flexible-launch.js";
@@ -22,8 +22,6 @@ const refuse = (reason, message = WORDS[reason]) => ({ ok: false, reason, messag
22
22
  const MODEL = /^[A-Za-z0-9._:/@+-]{1,200}$/;
23
23
  const EMPTY_MCP = '{"mcpServers":{}}';
24
24
  export function flexibleAgentLaunch(provider, level, input) {
25
- if (!FLEXIBLE_AVAILABLE)
26
- return refuse("not-available");
27
25
  if (typeof input.model !== "string" || !MODEL.test(input.model) || !isFlexibleLevel(level))
28
26
  return refuse("invalid-request");
29
27
  if (provider === "codex" || provider === "openrouter")
@@ -63,7 +61,7 @@ function stillMayStart(store, turnId, holder) {
63
61
  return allowed.ok ? null : allowed.message;
64
62
  }
65
63
  export async function startFlexibleTurn(store, input) {
66
- if (!FLEXIBLE_AVAILABLE)
64
+ if (!flexibleAvailable(store))
67
65
  return refuse("not-available");
68
66
  const first = flexibleTurn(store, input.turn);
69
67
  if (first === null)
@@ -163,8 +161,6 @@ async function startLocked(store, input) {
163
161
  return { ok: true, launched: "started", launchId: spawned.launchId, pid: spawned.pid, child: spawned.child, stopWatching };
164
162
  }
165
163
  export async function lowerFlexibleThreadLevel(store, input) {
166
- if (!FLEXIBLE_AVAILABLE)
167
- return refuse("not-available");
168
164
  if (!isFlexibleLevel(input.level) || typeof input.by?.name !== "string" || !Number.isSafeInteger(input.by.generation))
169
165
  return refuse("invalid-request");
170
166
  return withFlexibleThreadLock(input.thread, () => lowerLocked(store, input)).then(result => result);
@@ -210,8 +206,6 @@ async function lowerLocked(store, input) {
210
206
  : { ok: true, level: input.level, stopped: "pending", message: `Lowered to ${words}. Some of the agent's processes are still running, so no new turn starts until they stop (${stopped.why}).` };
211
207
  }
212
208
  export async function recoverFlexibleLaunchesOf(store, input) {
213
- if (!FLEXIBLE_AVAILABLE)
214
- return refuse("not-available");
215
209
  if (typeof input.holder !== "string" || !/^[A-Za-z0-9._:-]{1,128}$/.test(input.holder))
216
210
  return refuse("invalid-request");
217
211
  const launches = store.handle.prepare("SELECT thread, id FROM flexible_thread_launch WHERE holder = ? AND state <> 'exited' ORDER BY started_at, id").all(input.holder)
@@ -1,7 +1,7 @@
1
1
  import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
2
2
  import { closeSync, constants as fsConstants, lstatSync, openSync, realpathSync } from "node:fs";
3
3
  import { basename, dirname, join, relative, isAbsolute } from "node:path";
4
- import { FLEXIBLE_AVAILABLE } from "./flexible-available.js";
4
+ import { flexibleAvailable } from "./flexible-available.js";
5
5
  import { flexibleDelegationAtUse, FLEXIBLE_LEVELS, FLEXIBLE_UNAVAILABLE, isFlexibleLevel } from "./flexible.js";
6
6
  import { flexibleLaunch } from "./flexible-launch.js";
7
7
  import { flexibleTurn } from "./flexible-turns.js";
@@ -38,8 +38,6 @@ const WORDS = Object.freeze({
38
38
  const refuse = (reason, state, message = WORDS[reason]) => state === undefined ? { ok: false, reason, message } : { ok: false, reason, message, state };
39
39
  export const FLEXIBLE_ANSWER_UNCERTAIN = WORDS["uncertain"];
40
40
  export function streamAnswerSender(stream) {
41
- if (!FLEXIBLE_AVAILABLE)
42
- return refuse("not-available");
43
41
  return (bytes, { deadlineMs, signal }) => new Promise(resolve => {
44
42
  if (stream.destroyed || !stream.writable || signal.aborted) {
45
43
  resolve({ written: 0, complete: false });
@@ -187,8 +185,6 @@ function fileProblem(path) {
187
185
  return null;
188
186
  }
189
187
  export function openFlexibleAnswerCatalog(store) {
190
- if (!FLEXIBLE_AVAILABLE)
191
- return refuse("not-available");
192
188
  const database = store.databaseFile();
193
189
  if (database === null || !isAbsolute(database))
194
190
  return refuse("catalog-unsafe");
@@ -401,7 +397,7 @@ function answerFor(kind, card, decision, answers) {
401
397
  return { answers: Object.fromEntries(entries) };
402
398
  }
403
399
  export function recordFlexibleRequest(store, catalog, input) {
404
- if (!FLEXIBLE_AVAILABLE)
400
+ if (!flexibleAvailable(store))
405
401
  return refuse("not-available");
406
402
  if (![input.thread, input.turn, input.connection].every(id => typeof id === "string" && ID.test(id)) || typeof input.holder !== "string" || !HOLDER.test(input.holder)
407
403
  || typeof input.requestRef !== "string" || !REF.test(input.requestRef) || cardProblem(input.kind, input.card) !== null
@@ -474,7 +470,7 @@ function decide(store, catalog, input, who, decision, answers) {
474
470
  return { ok: true, decisionId: made.decisionId, state: "decided" };
475
471
  }
476
472
  export function decideFlexibleAnswer(store, catalog, input) {
477
- if (!FLEXIBLE_AVAILABLE)
473
+ if (!flexibleAvailable(store))
478
474
  return refuse("not-available");
479
475
  if (input.by?.kind !== "person")
480
476
  return refuse("not-a-person");
@@ -486,8 +482,6 @@ export function decideFlexibleAnswer(store, catalog, input) {
486
482
  ...(input.held === undefined ? {} : { held: input.held }) }, input.decision, input.answers);
487
483
  }
488
484
  export function decideFlexibleAnswerByPolicy(store, catalog, input) {
489
- if (!FLEXIBLE_AVAILABLE)
490
- return refuse("not-available");
491
485
  if (typeof input.request !== "string" || !ID.test(input.request) || !Object.hasOwn(FLEXIBLE_ANSWER_RULES, input.rule))
492
486
  return refuse("invalid-request");
493
487
  return decide(store, catalog, input, { source: "policy", rule: input.rule }, FLEXIBLE_ANSWER_RULES[input.rule], undefined);
@@ -501,7 +495,7 @@ function agreeing(store, catalog, request) {
501
495
  return agree ? { row, decision } : { row, decision, problem: true };
502
496
  }
503
497
  export async function sendFlexibleAnswer(store, catalog, input) {
504
- if (!FLEXIBLE_AVAILABLE)
498
+ if (!flexibleAvailable(store))
505
499
  return refuse("not-available");
506
500
  if (typeof input.request !== "string" || !ID.test(input.request) || typeof input.holder !== "string" || !HOLDER.test(input.holder)
507
501
  || typeof input.connection?.id !== "string" || typeof input.connection.frame !== "function" || typeof input.connection.send !== "function"
@@ -672,8 +666,6 @@ function markUncertain(store, catalog, request, clock, detail) {
672
666
  const stoppable = (decision, row) => decision !== null && row !== null && (decision.state === "decided" || decision.state === "sending") && (row.state === "decided" || row.state === "sending")
673
667
  && decision.attemptId === null && row.attemptId === null && !attempted.has(decision.decisionId);
674
668
  export function cancelFlexibleAnswer(store, catalog, input) {
675
- if (!FLEXIBLE_AVAILABLE)
676
- return refuse("not-available");
677
669
  if (input.by?.kind !== "person")
678
670
  return refuse("not-a-person");
679
671
  if (typeof input.request !== "string" || !ID.test(input.request) || typeof input.by.name !== "string" || !Number.isSafeInteger(input.by.generation))
@@ -696,8 +688,6 @@ export function cancelFlexibleAnswer(store, catalog, input) {
696
688
  });
697
689
  }
698
690
  export function revokeFlexibleAnswers(store, catalog, input) {
699
- if (!FLEXIBLE_AVAILABLE)
700
- return refuse("not-available");
701
691
  if (![input.thread, ...(input.turn === undefined ? [] : [input.turn]), ...(input.connection === undefined ? [] : [input.connection])].every(id => typeof id === "string" && ID.test(id))
702
692
  || typeof input.reason !== "string" || input.reason.length < 1 || input.reason.length > 200)
703
693
  return refuse("invalid-request");
@@ -723,8 +713,6 @@ export function revokeFlexibleAnswers(store, catalog, input) {
723
713
  });
724
714
  }
725
715
  export function ackFlexibleAnswer(store, catalog, input) {
726
- if (!FLEXIBLE_AVAILABLE)
727
- return refuse("not-available");
728
716
  if (typeof input.connection !== "string" || !ID.test(input.connection) || typeof input.requestRef !== "string" || !REF.test(input.requestRef))
729
717
  return refuse("invalid-request");
730
718
  return store.transact(() => {
@@ -740,8 +728,6 @@ export function ackFlexibleAnswer(store, catalog, input) {
740
728
  });
741
729
  }
742
730
  export function noteFlexibleToolActivity(store, catalog, input) {
743
- if (!FLEXIBLE_AVAILABLE)
744
- return refuse("not-available");
745
731
  if (![input.connection, input.turn].every(id => typeof id === "string" && ID.test(id)) || typeof input.correlation !== "string" || !REF.test(input.correlation))
746
732
  return refuse("invalid-request");
747
733
  return store.transact(() => {
@@ -758,8 +744,6 @@ export function noteFlexibleToolActivity(store, catalog, input) {
758
744
  });
759
745
  }
760
746
  export function expireFlexibleAnswers(store, catalog, input = {}) {
761
- if (!FLEXIBLE_AVAILABLE)
762
- return refuse("not-available");
763
747
  const ackMs = input.ackMs ?? FLEXIBLE_ANSWER_ACK_MS, writeMs = input.writeMs ?? FLEXIBLE_ANSWER_WRITE_MS;
764
748
  if (!Number.isSafeInteger(ackMs) || ackMs < 0 || !Number.isSafeInteger(writeMs) || writeMs < 0)
765
749
  return refuse("invalid-request");
@@ -809,8 +793,6 @@ export function expireFlexibleAnswers(store, catalog, input = {}) {
809
793
  });
810
794
  }
811
795
  export function recoverFlexibleAnswersOf(store, catalog, input) {
812
- if (!FLEXIBLE_AVAILABLE)
813
- return refuse("not-available");
814
796
  if (typeof input.holder !== "string" || !HOLDER.test(input.holder))
815
797
  return refuse("invalid-request");
816
798
  return store.transact(() => {
@@ -851,8 +833,6 @@ export function recoverFlexibleAnswersOf(store, catalog, input) {
851
833
  });
852
834
  }
853
835
  export function recordFlexibleProviderDecision(store, input) {
854
- if (!FLEXIBLE_AVAILABLE)
855
- return refuse("not-available");
856
836
  if (![input.thread, input.turn, input.connection].every(id => typeof id === "string" && ID.test(id)) || typeof input.holder !== "string" || !HOLDER.test(input.holder)
857
837
  || typeof input.requestRef !== "string" || !REF.test(input.requestRef) || (input.decision !== "accept" && input.decision !== "decline")
858
838
  || typeof input.provider !== "string" || !/^[a-z][a-z0-9-]{0,39}$/.test(input.provider))
@@ -872,8 +852,6 @@ export function recordFlexibleProviderDecision(store, input) {
872
852
  });
873
853
  }
874
854
  export function flexibleRequestsOf(catalog, input) {
875
- if (!FLEXIBLE_AVAILABLE)
876
- return refuse("not-available");
877
855
  const limit = input.limit ?? 20;
878
856
  if (typeof input.thread !== "string" || !ID.test(input.thread) || (input.turn !== undefined && (typeof input.turn !== "string" || !ID.test(input.turn)))
879
857
  || !Number.isSafeInteger(limit) || limit < 1 || limit > 100)
@@ -1 +1,31 @@
1
- export const FLEXIBLE_AVAILABLE = false;
1
+ export const FLEXIBLE_SETTING_ACTION = "interactive agent threads";
2
+ export function flexibleAvailable(store) {
3
+ let row;
4
+ try {
5
+ row = store.handle.prepare("SELECT enabled FROM flexible_setting WHERE id = 1").get();
6
+ }
7
+ catch {
8
+ return false;
9
+ }
10
+ return row !== undefined && row["enabled"] === 1;
11
+ }
12
+ export function flexibleSetting(store) {
13
+ let row;
14
+ try {
15
+ row = store.handle.prepare("SELECT enabled, updated_by, updated_at FROM flexible_setting WHERE id = 1").get();
16
+ }
17
+ catch {
18
+ row = undefined;
19
+ }
20
+ if (row === undefined)
21
+ return { on: false, by: null, at: null };
22
+ return { on: row["enabled"] === 1, by: String(row["updated_by"]), at: String(row["updated_at"]) };
23
+ }
24
+ export function setFlexibleSetting(store, on, by, now) {
25
+ const was = flexibleAvailable(store);
26
+ store.handle.prepare(`INSERT INTO flexible_setting (id, enabled, updated_by, updated_at) VALUES (1, ?, ?, ?)
27
+ ON CONFLICT(id) DO UPDATE SET enabled = excluded.enabled, updated_by = excluded.updated_by, updated_at = excluded.updated_at`).run(on ? 1 : 0, by, now.toISOString());
28
+ store.recordAction({ at: now.toISOString(), actor: by, repo: null, taskId: null, runId: null, action: FLEXIBLE_SETTING_ACTION, outcome: on ? "on" : "off", source: "policy",
29
+ detail: was === on ? "unchanged" : null });
30
+ return { changed: was !== on };
31
+ }