toolroll 0.9.112 → 0.9.113

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 (42) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +28 -29
  3. package/dist/contracts/console-api.js +2 -1
  4. package/dist/contracts/engine-api.js +12 -0
  5. package/dist/easy-start.js +4 -1
  6. package/dist/engine-reads.js +15 -0
  7. package/dist/fast-terms.js +8 -4
  8. package/dist/flexible-agents.js +2 -8
  9. package/dist/flexible-answers.js +4 -26
  10. package/dist/flexible-available.js +31 -1
  11. package/dist/flexible-import.js +2 -14
  12. package/dist/flexible-launch.js +15 -3
  13. package/dist/flexible-launcher.js +0 -5
  14. package/dist/flexible-relay.js +7 -4
  15. package/dist/flexible-session.js +123 -32
  16. package/dist/flexible-setting-schema.js +10 -0
  17. package/dist/flexible-ship.js +8 -18
  18. package/dist/flexible-start.js +2 -2
  19. package/dist/flexible-thread.js +21 -27
  20. package/dist/flexible-turns.js +7 -17
  21. package/dist/flexible.js +9 -11
  22. package/dist/flow-triggers.js +4 -1
  23. package/dist/live-terminal.js +28 -0
  24. package/dist/local-owner.js +1 -0
  25. package/dist/operate.js +60 -4
  26. package/dist/release.js +1 -0
  27. package/dist/serve.js +9 -0
  28. package/dist/server/engine-api.js +91 -27
  29. package/dist/server/mutation-key.js +6 -0
  30. package/dist/server/route-table.js +3 -0
  31. package/dist/server/settings-section-table.js +3 -0
  32. package/dist/server/settings-sections.js +23 -0
  33. package/dist/server/settings.js +36 -3
  34. package/dist/server/terminals.js +3 -3
  35. package/dist/settings-proofs.js +2 -0
  36. package/dist/store.js +18 -4
  37. package/dist/tui/darwin-arm64/toolroll-tui +0 -0
  38. package/dist/tui/darwin-x64/toolroll-tui +0 -0
  39. package/dist/tui/linux-arm64/toolroll-tui +0 -0
  40. package/dist/tui/linux-x64/toolroll-tui +0 -0
  41. package/dist/work-index.js +4 -0
  42. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -4,6 +4,40 @@ 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.113 — 2026-11-17
8
+
9
+ The terminal workbench for people coming from herdr: a clear first screen, a build shell that can't take your keys by
10
+ mistake, approving a sent-back plan without leaving the terminal, and interactive agent threads as a beta switch.
11
+
12
+ ### New
13
+
14
+ - **Interactive agent threads (beta).** Settings → General, or `toolroll config set flexible on` (your password).
15
+ Off by default; Claude Code only for now; `T` starts a thread. Turning it off stops running threads.
16
+ - **Approve a sent-back plan in the workbench.** After you send a result back, press `a` on the revision to read its
17
+ terms and approve them; `w` still opens it in your browser.
18
+ - **Watch running tasks** from the command palette (`:`): every running task in its own panel.
19
+ - **Coming from herdr?** `docs/guide/from-herdr.md` maps the keys and says what differs.
20
+
21
+ ### Changed
22
+
23
+ - **"Take over" is now "Open build shell"** and asks first: it opens a shell in a separate copy of the build and
24
+ never controls the running agent.
25
+ - **Quitting asks** whether to stop the agents or keep them running, and prints how to reopen.
26
+ - **Panel headers lead with the task,** its state and cost; long titles wrap instead of being cut.
27
+ - **`toolroll view reset` keeps your keys** and names its backup by date; nothing is backed up when already default.
28
+ - **The README opens with the terminal loop** and a real screenshot of the workbench.
29
+
30
+ ### Fixed
31
+
32
+ - **Open build shell on a task with no saved build** refuses at once; your typing can no longer reach workbench keys.
33
+ - **A sent-back task no longer closes the workbench** with "isn't what this version expects"; one task's
34
+ unreadable steps only affect that task.
35
+ - **"Building it." clears** when a task moves on to waiting, retrying, Ready or failed.
36
+ - **The mail inbox never skips an email** when two checks overlap.
37
+ - **Threads start in a project `toolroll` added itself,** and the new-task box shows while a thread is open.
38
+ - **`tui.toml` with both `list-side` and `list_side`** reads back the same after a change (the dashed spelling wins).
39
+ - **Turning on threads without a password** tells you to set one first (`toolroll password set`), in plain words.
40
+
7
41
  ## 0.9.112 — 2026-11-16
8
42
 
9
43
  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
 
@@ -51,10 +51,11 @@ 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"]),
54
55
  releaseApproval: formContract("POST /settings/release-approval", ["repo", "action", "password"]),
55
56
  projectFlexible: formContract("POST /settings/project/flexible", ["repo", "action", "max", "digest", "password"]),
56
57
  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"]),
58
+ threadStart: formContract("POST /agents/live/thread", ["repo", "message", "model", "terms", "password", "agent"]),
58
59
  term: formContract("POST /term/start, /term/<terminal>/close, /term/<terminal>/remove", ["repo", "program", "password", "task", "run"]),
59
60
  termAgent: formContract("POST /term/agent/sign-in, /term/agent/install", ["agent", "password", "confirm"]),
60
61
  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 },
@@ -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) {
@@ -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
@@ -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
+ }
@@ -1,16 +1,14 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { closeSync, constants as fsConstants, existsSync, fstatSync, lstatSync, mkdirSync, mkdtempSync, opendirSync, openSync, readFileSync, readSync, realpathSync, rmSync, writeFileSync } from "node:fs";
3
3
  import { basename, dirname, isAbsolute, join } from "node:path";
4
- import { FLEXIBLE_AVAILABLE } from "./flexible-available.js";
5
4
  import { FLEXIBLE_UNAVAILABLE } from "./flexible.js";
6
- import { flexibleThread, flexibleThreadBranch, flexibleThreadPaths, withFlexibleThreadLock } from "./flexible-thread.js";
5
+ import { flexibleProjectKnown, flexibleThread, flexibleThreadBranch, flexibleThreadPaths, withFlexibleThreadLock } from "./flexible-thread.js";
7
6
  import { readProjectRefs, refsChangedOutside, refSnapshotOf, saveRefSnapshot } from "./flexible-refs.js";
8
7
  import { PROTECTED_FILES, protectedChanges, protectedLinks } from "./agent-fence.js";
9
8
  import { scanPatchForSecrets } from "./evidence.js";
10
9
  import { PROOF_LIMITS } from "./proof.js";
11
10
  import { run } from "./exec.js";
12
11
  import { hardenedGit, recordedCommonDir } from "./teardown-git.js";
13
- import { projectRowKnown } from "./store.js";
14
12
  const NOTHING = "Nothing was imported.";
15
13
  const PRE_WORDS = {
16
14
  "not-available": FLEXIBLE_UNAVAILABLE,
@@ -246,7 +244,7 @@ function sourceOf(store, id, limits, deadline) {
246
244
  return pre("thread-unknown");
247
245
  if (thread.state !== "ready")
248
246
  return pre("thread-not-ready");
249
- if (!projectRowKnown(store, thread.repo))
247
+ if (!flexibleProjectKnown(store, thread.repo))
250
248
  return pre("not-a-project");
251
249
  const state = stateFolderOf(store);
252
250
  if (state === null)
@@ -333,8 +331,6 @@ async function changedEntries(read, repo, base, candidate) {
333
331
  return entries;
334
332
  }
335
333
  export async function readFlexibleCandidate(store, input) {
336
- if (!FLEXIBLE_AVAILABLE)
337
- return pre("not-available");
338
334
  const limits = limitsOf(input.limits);
339
335
  const deadline = Date.now() + limits.importMs;
340
336
  const source = sourceOf(store, input.thread, limits, deadline);
@@ -612,8 +608,6 @@ async function quarantineChecks(read, repo, source, candidate, limits) {
612
608
  return null;
613
609
  }
614
610
  export async function importFlexibleCandidate(store, input) {
615
- if (!FLEXIBLE_AVAILABLE)
616
- return pre("not-available");
617
611
  const locked = await withFlexibleThreadLock(input.thread, () => guarded(() => importLocked(store, input)));
618
612
  if (locked.ok === false && (locked.reason === "not-available" || locked.reason === "thread-unknown"))
619
613
  return pre(locked.reason);
@@ -692,8 +686,6 @@ async function importLocked(store, input) {
692
686
  });
693
687
  }
694
688
  export async function removeFlexibleImportRefs(store, input) {
695
- if (!FLEXIBLE_AVAILABLE)
696
- return pre("not-available");
697
689
  const locked = await withFlexibleThreadLock(input.thread, async () => {
698
690
  const thread = flexibleThread(store, input.thread);
699
691
  if (thread === null)
@@ -726,8 +718,6 @@ export async function removeFlexibleImportRefs(store, input) {
726
718
  return locked;
727
719
  }
728
720
  export async function flexibleTaskBranch(store, input) {
729
- if (!FLEXIBLE_AVAILABLE)
730
- return false;
731
721
  const thread = flexibleThread(store, input.thread);
732
722
  if (thread === null || !SHA.test(input.at) || !/^toolroll\/flexible-[0-9a-f]{32}$/.test(input.branch))
733
723
  return false;
@@ -746,8 +736,6 @@ export async function flexibleTaskBranch(store, input) {
746
736
  return done.code === 0;
747
737
  }
748
738
  export async function settleInterruptedImport(store, input) {
749
- if (!FLEXIBLE_AVAILABLE)
750
- return pre("not-available");
751
739
  const thread = flexibleThread(store, input.thread);
752
740
  if (thread === null)
753
741
  return pre("thread-unknown");
@@ -7,6 +7,7 @@ import { observeCustody, realCustodyIO, stopCustody, custodySettled } from "./fl
7
7
  import { interruptFlexibleThreadTurns } from "./flexible-turns.js";
8
8
  import { currentMachineId } from "./machine-identity.js";
9
9
  import { relayCancel } from "./flexible-relay-cancel.js";
10
+ import { flexibleAvailable } from "./flexible-available.js";
10
11
  export const FLEXIBLE_AGENT_PROVIDERS = ["claude", "codex", "gemini", "openrouter"];
11
12
  const LAUNCH_ID = /^[0-9a-f]{32}$/;
12
13
  const text = (value) => value === null || value === undefined ? null : String(value);
@@ -73,9 +74,20 @@ export function recordGateShut(store, input) {
73
74
  });
74
75
  }
75
76
  const LAUNCHED = "flexible agent launched";
76
- export function recordLaunchOpened(store, input) {
77
- store.recordAction({ at: (input.clock ?? (() => new Date()))().toISOString(), actor: "toolroll", repo: null, taskId: null, runId: null, source: "policy", action: LAUNCHED, outcome: "launched",
78
- detail: `turn ${input.turn ?? "none"} · thread ${input.thread} · launch ${input.launch}` });
77
+ export function reserveLaunchOpen(store, input) {
78
+ return store.transact(() => {
79
+ if (!flexibleAvailable(store))
80
+ return "interactive agent threads were turned off";
81
+ const why = input.check();
82
+ if (why !== null)
83
+ return why;
84
+ const live = store.handle.prepare("SELECT 1 AS live FROM flexible_thread_launch WHERE id = ? AND thread = ? AND state = 'live'").get(input.launch, input.thread);
85
+ if (live === undefined)
86
+ return "its launch is no longer live";
87
+ store.recordAction({ at: (input.clock ?? (() => new Date()))().toISOString(), actor: "toolroll", repo: null, taskId: null, runId: null, source: "policy", action: LAUNCHED, outcome: "launched",
88
+ detail: `turn ${input.turn ?? "none"} · thread ${input.thread} · launch ${input.launch}` });
89
+ return null;
90
+ });
79
91
  }
80
92
  export function flexibleTurnLaunched(store, turn) {
81
93
  if (!/^[0-9a-f]{32}$/.test(turn))
@@ -1,6 +1,5 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { homedir } from "node:os";
3
- import { FLEXIBLE_AVAILABLE } from "./flexible-available.js";
4
3
  import { FLEXIBLE_UNAVAILABLE } from "./flexible.js";
5
4
  import { NETWORK_POLICY_VERSION, proxyEnv, REGISTRY_HOSTS, repositoryEcosystems, startEgressProxy } from "./egress.js";
6
5
  import { prepareProtectedStorage, storageRefusalOf } from "./protected-storage.js";
@@ -12,8 +11,6 @@ const WORDS = Object.freeze({
12
11
  });
13
12
  const refuse = (reason, message = WORDS[reason]) => ({ ok: false, reason, message });
14
13
  export function flexibleThreadNetwork(store, repo) {
15
- if (!FLEXIBLE_AVAILABLE)
16
- return refuse("not-available");
17
14
  const project = store.projectNetwork(repo);
18
15
  if (project.mode === "open")
19
16
  return { version: NETWORK_POLICY_VERSION, mode: "open", hosts: [], loopback: "proxy-only" };
@@ -24,8 +21,6 @@ export function flexibleNetworkDigest(network) {
24
21
  return createHash("sha256").update(`standing-orders:flexible-network:${JSON.stringify({ mode: network.mode, hosts: network.hosts, loopback: network.loopback })}`, "utf8").digest("hex").slice(0, 32);
25
22
  }
26
23
  export function createFlexibleLauncher(store, seams = {}) {
27
- if (!FLEXIBLE_AVAILABLE)
28
- return refuse("not-available");
29
24
  const startProxy = seams.startProxy ?? ((options) => startEgressProxy(options));
30
25
  const storageNow = seams.storage ?? (() => prepareProtectedStorage(homedir()));
31
26
  const live = new Map();
@@ -4,7 +4,7 @@ import { createServer, request as httpRequest } from "node:http";
4
4
  import { request as httpsRequest } from "node:https";
5
5
  import { dirname } from "node:path";
6
6
  import { StringDecoder } from "node:string_decoder";
7
- import { FLEXIBLE_AVAILABLE } from "./flexible-available.js";
7
+ import { flexibleAvailable } from "./flexible-available.js";
8
8
  import { FLEXIBLE_UNAVAILABLE } from "./flexible.js";
9
9
  import { issueRelayGrant, revokeRelayGrant } from "./flexible-launch.js";
10
10
  import { onRelayCancel } from "./flexible-relay-cancel.js";
@@ -25,6 +25,7 @@ export function relayUrlInside(port, platform = process.platform) {
25
25
  }
26
26
  export const FLEXIBLE_RELAY_CREDENTIAL = Object.freeze({ name: "flexible-claude-relay", file: Object.freeze(["flexible", "claude-relay.json"]) });
27
27
  const CALL_WORDS = Object.freeze({
28
+ "threads-off": { status: 403, type: "permission_error", message: "Interactive agent threads were turned off in Toolroll, so nothing was sent to the model." },
28
29
  unsettled: { status: 503, type: "api_error", message: "An earlier model call in this turn couldn't be charged yet, so nothing more is sent until it is." },
29
30
  "check-failed": { status: 503, type: "api_error", message: "Toolroll couldn't check this call's authority, so nothing was sent." },
30
31
  "credential-header": { status: 400, type: "invalid_request_error", message: "Toolroll's sign-in relay chooses the credential itself: a call can't carry its own key, sign-in or service override." },
@@ -66,8 +67,6 @@ function credentialOf(state, upstream) {
66
67
  }
67
68
  }
68
69
  export function flexibleRelayBilling(store) {
69
- if (!FLEXIBLE_AVAILABLE)
70
- return refuse("not-available");
71
70
  const file = store.databaseFile();
72
71
  let state;
73
72
  try {
@@ -401,7 +400,7 @@ const UPSTREAM_IDLE_MS = 10 * 60_000;
401
400
  const WATCH_MS = 250;
402
401
  const THREAD_ID = /^[0-9a-f]{32}$/;
403
402
  export async function startFlexibleRelay(store, input) {
404
- if (!FLEXIBLE_AVAILABLE)
403
+ if (!flexibleAvailable(store))
405
404
  return refuse("not-available");
406
405
  if (typeof input?.thread !== "string" || !THREAD_ID.test(input.thread) || (input.log !== undefined && typeof input.log !== "function"))
407
406
  return refuse("invalid-request");
@@ -698,6 +697,10 @@ export async function startFlexibleRelay(store, input) {
698
697
  let blocked = null;
699
698
  try {
700
699
  store.transact(() => {
700
+ if (!flexibleAvailable(store)) {
701
+ blocked = "threads-off";
702
+ return;
703
+ }
701
704
  if (!grantStillLive(store, authed.digest)) {
702
705
  blocked = "unauthorized";
703
706
  return;