toolroll 0.9.106 → 0.9.107

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,24 @@ 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.107 — 2026-11-13
8
+
9
+ A smoother install, an honest terminal when something stops, and sign-in links that stay private.
10
+
11
+ ### Changed
12
+
13
+ - **The installer checks everything first.** On a fresh machine it lists every missing piece (Node, git, the Linux
14
+ sandbox tools) with one block of install commands, so you fix it once. Install lines start with `apt update`.
15
+ - **Codex reads "(optional)" in setup** once Claude Code is installed: you need one coding agent, not both.
16
+ - **Sign-in links stay private.** `w`, `toolroll open --web`, `up` and the demo open the browser through a private page,
17
+ so other users on the computer can't see the one-time link. `toolroll open --web` now waits until you're signed in.
18
+
19
+ ### Fixed
20
+
21
+ - **The terminal says when Toolroll's background worker stops** on its own, instead of "Filed. Planning…".
22
+ `toolroll --verbose` shows why.
23
+ - **A browser that can't be opened is said, not claimed.** On Windows, Toolroll tells you to set a password and sign in.
24
+
7
25
  ## 0.9.106 — 2026-11-13
8
26
 
9
27
  Toolroll runs on the Node you just installed, and Linux says exactly what it needs.
package/README.md CHANGED
@@ -31,7 +31,7 @@ Approve each plan once. Get results back Ready with the diff, the check status a
31
31
 
32
32
  macOS or Linux, Node.js 22.20+, git 2.41+, and Claude Code (`claude`) or
33
33
  Codex (`codex`) signed in on this computer. On Linux, also the sandbox tools:
34
- `sudo apt install bubblewrap socat ripgrep`.
34
+ `sudo apt update && sudo apt install bubblewrap socat ripgrep`.
35
35
 
36
36
  ```sh
37
37
  curl -fsSL https://raw.githubusercontent.com/ap9000/toolroll/main/install.sh | sh
package/dist/cli.js CHANGED
@@ -1172,7 +1172,19 @@ async function runDemoCommand(argv, write, seams = {}) {
1172
1172
  const url = allowedHosts.length > 0 ? `http://${allowedHosts[0]}` : `http://127.0.0.1:${boundPort}`;
1173
1173
  const terminal = seams.terminal ?? (process.stdin.isTTY === true && process.stdout.isTTY === true);
1174
1174
  const demoSignIn = await import("./demo-sign-in.js");
1175
- const signIn = demoSignIn.demoSignInLink(server, seed.login.name, { stdin: terminal, stdout: terminal, agent: seams.underAgent ?? underAgent(process.env), json });
1175
+ const signInPage = await import("./sign-in-page.js");
1176
+ const canOpen = signInPage.platformOpener() !== null;
1177
+ const { SIGN_IN_LINK_MS } = await import("./server/session.js");
1178
+ const linkExpiresAt = Date.now() + SIGN_IN_LINK_MS;
1179
+ const signIn = canOpen ? demoSignIn.demoSignInLink(server, seed.login.name, { stdin: terminal, stdout: terminal, agent: seams.underAgent ?? underAgent(process.env), json }) : null;
1180
+ let removePage = () => { };
1181
+ let opened = false;
1182
+ if (signIn !== null) {
1183
+ const page = await signInPage.openSignInLink(signIn, { parent: sandbox, spent: signInPage.ledgerSpent(store, "one-time link", seed.login.name), expiresAt: linkExpiresAt,
1184
+ ...(seams.opener === undefined ? {} : { opener: seams.opener }) });
1185
+ removePage = page.stop;
1186
+ opened = page.opened;
1187
+ }
1176
1188
  if (json) {
1177
1189
  write(envelopeJson({ ok: true, command: "demo", url, sandbox, login: { name: seed.login.name, passwordFile }, keep }));
1178
1190
  }
@@ -1183,10 +1195,14 @@ async function runDemoCommand(argv, write, seams = {}) {
1183
1195
  write(` login ${seed.login.name} / ${seed.login.password}`);
1184
1196
  write(` sandbox ${sandbox}`);
1185
1197
  write("");
1186
- if (signIn !== null) {
1198
+ if (opened) {
1187
1199
  write("Opened in your browser, signed in.");
1188
1200
  write("");
1189
1201
  }
1202
+ else if (signIn !== null) {
1203
+ write("Your browser didn't open: go to the address above and sign in with the login above.");
1204
+ write("");
1205
+ }
1190
1206
  write("Open Chat and ask for a change, like \"fix the flaky refund test\".");
1191
1207
  write("For your own project, run `toolroll` in its folder.");
1192
1208
  write("");
@@ -1194,15 +1210,6 @@ async function runDemoCommand(argv, write, seams = {}) {
1194
1210
  ? "Ctrl-C stops the server; the sandbox is KEPT. It stays a demo forever — every spending command refuses it."
1195
1211
  : "Ctrl-C stops the server and deletes the sandbox. --keep preserves it (still fenced from spending).");
1196
1212
  }
1197
- let removePage = () => { };
1198
- if (signIn !== null) {
1199
- const page = demoSignIn.writeSignInPage(sandbox, signIn);
1200
- removePage = demoSignIn.removeSignInPageWhenSpent(store, page, seed.login.name);
1201
- if (seams.openPage !== undefined)
1202
- seams.openPage(page);
1203
- else
1204
- demoSignIn.openSignInPage(page);
1205
- }
1206
1213
  await new Promise(done => {
1207
1214
  const stop = () => {
1208
1215
  process.off("SIGINT", stop);
@@ -165,7 +165,7 @@ export const COMMAND_OUTPUTS = {
165
165
  audit: auditOutput,
166
166
  "skills list": answers("skills list", { guides: rows({ name: str, title: str, oneLiner: str }) }),
167
167
  welcome: answers("welcome", {
168
- agent: z.looseObject({ done: z.boolean(), checking: z.boolean(), agents: rows({ id: str, name: str, state: str, command: nullable(str), inUse: z.boolean(), canUse: z.boolean() }), inUse: nullable(str), buildsWith: nullable(str) }),
168
+ agent: z.looseObject({ done: z.boolean(), checking: z.boolean(), agents: rows({ id: str, name: str, state: str, command: nullable(str), inUse: z.boolean(), canUse: z.boolean(), optional: z.boolean() }), inUse: nullable(str), buildsWith: nullable(str) }),
169
169
  project: z.looseObject({ done: z.boolean(), projects: rows({ name: str, path: str }), sample: nullable(str), notTakingWork: z.boolean() }),
170
170
  task: z.looseObject({ done: z.boolean(), open: z.boolean(), starters: rows({ label: str, draft: str, href: str }) }),
171
171
  next: nullable(z.enum(["agent", "project", "task"])),
@@ -1,7 +1,4 @@
1
- import { spawn as spawnChild } from "node:child_process";
2
- import { chmodSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
3
- import { join } from "node:path";
4
- import { SIGN_IN_LINK_MS, SIGN_IN_LINK_PATH } from "./server/session.js";
1
+ import { SIGN_IN_LINK_PATH } from "./server/session.js";
5
2
  export function demoLoopbackOrigin(address) {
6
3
  if (address === null || typeof address === "string")
7
4
  return null;
@@ -24,54 +21,3 @@ export function demoSignInLink(server, account, caller) {
24
21
  return null;
25
22
  return `${origin}${path}`;
26
23
  }
27
- export function writeSignInPage(parent, link) {
28
- const dir = mkdtempSync(join(parent, "sign-in-"));
29
- chmodSync(dir, 0o700);
30
- const file = join(dir, "open.html");
31
- const attribute = link.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
32
- writeFileSync(file, `<!doctype html><meta charset="utf-8"><meta name="referrer" content="no-referrer">`
33
- + `<meta http-equiv="refresh" content="0;url=${attribute}"><title>Toolroll</title>`
34
- + `<script>location.replace(${JSON.stringify(link).replace(/</g, "\\u003c")})</script><p>Opening Toolroll…</p>\n`, { mode: 0o600 });
35
- chmodSync(file, 0o600);
36
- return file;
37
- }
38
- export function removeSignInPage(file) {
39
- rmSync(join(file, ".."), { recursive: true, force: true });
40
- }
41
- export function openSignInPage(file, spawn = spawnChild, platform = process.platform) {
42
- const command = platform === "darwin" ? "open" : platform === "linux" ? "xdg-open" : null;
43
- if (command === null)
44
- return false;
45
- try {
46
- spawn(command, [file], { detached: true, stdio: "ignore" }).unref();
47
- return true;
48
- }
49
- catch {
50
- return false;
51
- }
52
- }
53
- export function removeSignInPageWhenSpent(store, file, account, options = {}) {
54
- const sinceRow = store.handle.prepare("SELECT coalesce(max(id), 0) AS id FROM action_ledger").get();
55
- const since = Number(sinceRow?.["id"] ?? 0);
56
- const spent = store.handle.prepare("SELECT 1 FROM action_ledger WHERE id > ? AND source = 'sign-in' AND actor = ? AND action = 'signed in' AND outcome = 'one-time link' LIMIT 1");
57
- let done = false;
58
- const finish = () => {
59
- if (done)
60
- return;
61
- done = true;
62
- clearInterval(timer);
63
- clearTimeout(expiry);
64
- removeSignInPage(file);
65
- };
66
- const timer = setInterval(() => { try {
67
- if (spent.get(since, account) !== undefined)
68
- finish();
69
- }
70
- catch {
71
- finish();
72
- } }, options.everyMs ?? 500);
73
- const expiry = setTimeout(finish, options.expiresMs ?? SIGN_IN_LINK_MS);
74
- timer.unref?.();
75
- expiry.unref?.();
76
- return finish;
77
- }
@@ -1,9 +1,11 @@
1
1
  export function easyStartArgs(argv) {
2
- let web = false, projectRoot = null, port = null;
2
+ let web = false, verbose = false, projectRoot = null, port = null;
3
3
  for (let index = 0; index < argv.length; index += 1) {
4
4
  const one = argv[index];
5
5
  if (one === "--web" && !web)
6
6
  web = true;
7
+ else if (one === "--verbose" && !verbose)
8
+ verbose = true;
7
9
  else if ((one === "--project-root" && projectRoot === null) || (one === "--port" && port === null)) {
8
10
  const value = argv[index + 1];
9
11
  if (value === undefined || value === "" || value.startsWith("-"))
@@ -17,7 +19,7 @@ export function easyStartArgs(argv) {
17
19
  else
18
20
  return null;
19
21
  }
20
- return { web, projectRoot, port };
22
+ return { web, projectRoot, port, ...(verbose ? { verbose } : {}) };
21
23
  }
22
24
  export function easyStartApplies(argv, facts) {
23
25
  return facts.stdin && facts.stdout && !facts.agent && easyStartArgs(argv) !== null;
@@ -9,7 +9,9 @@ import { backgroundAsked, installationCreatedBy, localModeCandidate, localModeOf
9
9
  import { underAgent } from "./prompt.js";
10
10
  import { savedLoginFile } from "./login-secrets.js";
11
11
  export { easyStartApplies, easyStartArgs } from "./easy-start-args.js";
12
+ export const SIGN_IN_HANDOFF_MS = 60_000;
12
13
  const EXIT = { ok: 0, failed: 1, usage: 2, refused: 3 };
14
+ export const UP_STOPPED_LINE = "Toolroll's background worker stopped. Run `toolroll --verbose` to see why.";
13
15
  export const START_OVER_POINTER = "This Toolroll was set up with a password. To start over without one: https://github.com/ap9000/toolroll/blob/main/docs/guide/linux.md#start-over-without-a-password";
14
16
  export async function runEasyStart(mode, args, seams) {
15
17
  const { write } = seams;
@@ -18,7 +20,8 @@ export async function runEasyStart(mode, args, seams) {
18
20
  write("--port is a whole number from 1 to 65535.");
19
21
  return EXIT.usage;
20
22
  }
21
- const rootArgs = [...(args.projectRoot === null ? [] : ["--project-root", args.projectRoot]), ...(port === null ? [] : ["--port", String(port)])];
23
+ const rootArgs = [...(args.projectRoot === null ? [] : ["--project-root", args.projectRoot]), ...(port === null ? [] : ["--port", String(port)]),
24
+ ...(args.verbose === true ? ["--verbose"] : [])];
22
25
  const elsewhere = (proof) => {
23
26
  if (port !== null && proof.ok && proof.port !== port)
24
27
  write(`Toolroll is already set up on port ${proof.port}, so it opens there.`);
@@ -72,10 +75,21 @@ export async function runEasyStart(mode, args, seams) {
72
75
  if (args.web && !first.ok && !seams.serviceInstalled())
73
76
  return seams.runUpForeground(["--laptop", ...rootArgs]);
74
77
  let owned = null;
78
+ const stoppedHere = new Set();
79
+ const exitCodes = new Map();
80
+ const stopOwned = (child) => { stoppedHere.add(child); child.stop(); };
81
+ const stoppedOnItsOwn = () => {
82
+ const child = owned;
83
+ if (child === null || child.running() || stoppedHere.has(child))
84
+ return null;
85
+ const code = exitCodes.get(child);
86
+ return typeof code === "number" && code !== 0 ? UP_STOPPED_LINE : null;
87
+ };
75
88
  const upArgs = ["--laptop", "--no-open", ...rootArgs];
76
89
  const startOwned = async () => {
77
90
  const child = seams.spawnUp(upArgs);
78
91
  owned = child;
92
+ void child.exited.then(code => { exitCodes.set(child, code); });
79
93
  const deadline = Date.now() + (seams.startTimeoutMs ?? 90_000);
80
94
  for (;;) {
81
95
  const proof = await seams.prove();
@@ -86,7 +100,7 @@ export async function runEasyStart(mode, args, seams) {
86
100
  return { ok: false, state: "refused", message: last === "" ? "it stopped while starting" : last };
87
101
  }
88
102
  if (Date.now() >= deadline) {
89
- child.stop();
103
+ stopOwned(child);
90
104
  return { ok: false, state: "refused", message: "it didn't answer in time" };
91
105
  }
92
106
  await sleep(250);
@@ -127,18 +141,26 @@ export async function runEasyStart(mode, args, seams) {
127
141
  return waitOwned();
128
142
  }
129
143
  if (args.web) {
130
- const link = await seams.requestLink();
131
- if (!link.ok) {
132
- write(`Toolroll is on ${url}, but it couldn't sign you in: ${link.message}.`);
133
- ownedNow()?.stop();
144
+ const opened = await seams.openSignedIn();
145
+ if (!opened.ok) {
146
+ write(`Toolroll is on ${url}, but it couldn't sign you in: ${opened.message}.`);
147
+ const child = ownedNow();
148
+ if (child !== null)
149
+ stopOwned(child);
134
150
  return EXIT.refused;
135
151
  }
136
152
  write(`Toolroll is on ${url}`);
137
- await seams.openBrowser(link.url);
153
+ if (ownedNow() === null) {
154
+ write("Opening Toolroll in your browser…");
155
+ await opened.wait(SIGN_IN_HANDOFF_MS);
156
+ return EXIT.ok;
157
+ }
138
158
  return waitOwned();
139
159
  }
140
160
  const handoff = async () => {
141
161
  const child = ownedNow();
162
+ if (child !== null)
163
+ stoppedHere.add(child);
142
164
  const result = await seams.backgroundOn(child === null ? null : {
143
165
  controllerPid: child.pid,
144
166
  restart: async () => { const again = await startOwned(); if (!again.ok)
@@ -150,12 +172,10 @@ export async function runEasyStart(mode, args, seams) {
150
172
  };
151
173
  const session = {
152
174
  owned: () => ownedNow() !== null,
175
+ stopped: stoppedOnItsOwn,
153
176
  openBrowser: async () => {
154
- const link = await seams.requestLink();
155
- if (!link.ok)
156
- return `The browser couldn't be opened: ${link.message}.`;
157
- await seams.openBrowser(link.url);
158
- return "Opened in your browser.";
177
+ const opened = await seams.openSignedIn();
178
+ return opened.ok ? "Opened in your browser." : `The browser couldn't be opened: ${opened.message}.`;
159
179
  },
160
180
  shouldAskBackground: () => ownedNow() !== null && !seams.serviceInstalled() && !seams.backgroundAsked(),
161
181
  answerBackground: async (yes) => {
@@ -164,6 +184,17 @@ export async function runEasyStart(mode, args, seams) {
164
184
  },
165
185
  };
166
186
  const exit = await seams.openTui(session);
187
+ const ended = owned;
188
+ if (ended !== null && !ended.running())
189
+ await ended.exited;
190
+ const died = stoppedOnItsOwn();
191
+ if (died !== null) {
192
+ if (args.verbose === true)
193
+ for (const line of ended?.tail() ?? [])
194
+ write(line);
195
+ write(died);
196
+ return EXIT.failed;
197
+ }
167
198
  const child = ownedNow();
168
199
  if (child !== null) {
169
200
  if (exit === "keep") {
@@ -173,7 +204,7 @@ export async function runEasyStart(mode, args, seams) {
173
204
  return EXIT.ok;
174
205
  }
175
206
  write("Stopping Toolroll… (running work is saved)");
176
- child.stop();
207
+ stopOwned(child);
177
208
  await child.exited;
178
209
  write("Toolroll stopped.");
179
210
  }
@@ -256,17 +287,7 @@ export function defaultEasyStartSeams(options) {
256
287
  spawnUp: args => spawnOwnedUp(args, { cwd, databaseFile: file }),
257
288
  runUpForeground: async (args) => (await import("./operate.js")).runOperate("up", [...args, "--db", file], options.write, options.operate ?? {}),
258
289
  openBrowser: async (url) => { (await import("./operate.js")).openBrowser(url); },
259
- requestLink: async () => {
260
- const store = openStoreReadOnly(file);
261
- if (store === null)
262
- return { ok: false, message: "Toolroll's database can't be read" };
263
- try {
264
- return await requestLocalLink(file, store, options.build);
265
- }
266
- finally {
267
- store.close();
268
- }
269
- },
290
+ openSignedIn: () => openLocalSignIn(file, options.build),
270
291
  openTui: async (session) => {
271
292
  const { createTuiSource } = await import("./tui-source.js");
272
293
  const { runAsLocalOwner } = await import("./local-owner.js");
@@ -348,3 +369,36 @@ export function localModeRead(file) {
348
369
  store.close();
349
370
  }
350
371
  }
372
+ export async function openLocalSignIn(databaseFile, build, seams = {}) {
373
+ const { ledgerSpent, NO_SAFE_OPENER, openSignInLink, platformOpener } = await import("./sign-in-page.js");
374
+ if (platformOpener(seams.platform) === null)
375
+ return { ok: false, message: NO_SAFE_OPENER };
376
+ const { instanceRunDir, prepareRunDir } = await import("./console-instance.js");
377
+ const parent = instanceRunDir(databaseFile);
378
+ const problem = prepareRunDir(parent);
379
+ if (problem !== null)
380
+ return { ok: false, message: problem };
381
+ const store = openStoreReadOnly(databaseFile);
382
+ if (store === null)
383
+ return { ok: false, message: "Toolroll's database can't be read" };
384
+ let handed = false;
385
+ try {
386
+ const spent = ledgerSpent(store, "local link", null);
387
+ const expiresAt = Date.now() + (seams.expiresMs ?? (await import("./server/session.js")).SIGN_IN_LINK_MS);
388
+ const link = await (seams.request ?? (one => requestLocalLink(databaseFile, one, build)))(store);
389
+ if (!link.ok)
390
+ return link;
391
+ handed = true;
392
+ const opened = await openSignInLink(link.url, {
393
+ parent, spent, expiresAt, onEnd: () => store.close(),
394
+ ...(seams.opener === undefined ? {} : { opener: seams.opener }),
395
+ ...(seams.platform === undefined ? {} : { platform: seams.platform }),
396
+ ...(seams.everyMs === undefined ? {} : { everyMs: seams.everyMs }),
397
+ });
398
+ return opened.opened ? { ok: true, wait: opened.wait } : { ok: false, message: "the browser opener didn't start or failed" };
399
+ }
400
+ finally {
401
+ if (!handed)
402
+ store.close();
403
+ }
404
+ }
package/dist/first-run.js CHANGED
@@ -191,9 +191,12 @@ export function welcomeModel(facts) {
191
191
  const state = seen === null ? "checking" : SIGNED_IN.has(seen) ? "signed-in" : seen === "not-installed" ? "not-installed" : "signed-out";
192
192
  const command = state === "signed-in" || state === "checking" ? null : state === "not-installed" ? `${one.install}${join} ${one.signIn}` : one.signIn;
193
193
  const inUse = facts.inUse === one.id;
194
- return { id: one.id, name: one.name, state, command, inUse, canUse: facts.canChoose && !inUse && seen === "connected" };
194
+ return { id: one.id, name: one.name, state, command, inUse, canUse: facts.canChoose && !inUse && seen === "connected", optional: false };
195
195
  });
196
196
  const signedIn = agents.some(one => one.state === "signed-in");
197
+ const installed = agents.some(one => one.state === "signed-in" || one.state === "signed-out");
198
+ for (const one of agents)
199
+ one.optional = signedIn ? one.state !== "signed-in" : installed && one.state === "not-installed";
197
200
  const checking = !signedIn && agents.some(one => one.state === "checking");
198
201
  const builds = facts.buildsOn === null ? null : WELCOME_AGENTS.find(one => one.id === facts.buildsOn)?.name ?? facts.buildsOn;
199
202
  const buildsWith = facts.inUse !== null && facts.buildsOn !== null && facts.buildsOn !== facts.inUse ? builds : null;
package/dist/git-floor.js CHANGED
@@ -5,13 +5,20 @@ export function parseGitVersion(text) {
5
5
  const found = /^git version (\d+)\.(\d+)(?:\.(\d+))?/.exec(text.trim());
6
6
  return found === null ? null : { major: Number(found[1]), minor: Number(found[2]), words: `${found[1]}.${found[2]}${found[3] === undefined ? "" : `.${found[3]}`}` };
7
7
  }
8
- export function gitFloorWords(versionText) {
8
+ export function newerGitHow(platform = process.platform) {
9
+ if (platform === "linux")
10
+ return "get one from https://git-scm.com/downloads/linux (Ubuntu: `sudo add-apt-repository ppa:git-core/ppa && sudo apt update && sudo apt install git`)";
11
+ if (platform === "darwin")
12
+ return "`brew install git`, or update Xcode's Command Line Tools in Software Update";
13
+ return "get one from https://git-scm.com/downloads";
14
+ }
15
+ export function gitFloorWords(versionText, platform = process.platform) {
9
16
  const version = parseGitVersion(versionText);
10
17
  if (version === null)
11
18
  return null;
12
19
  if (version.major > GIT_FLOOR.major || (version.major === GIT_FLOOR.major && version.minor >= GIT_FLOOR.minor))
13
20
  return null;
14
- return `Toolroll needs git ${GIT_FLOOR_WORDS} or newer, and this machine's git is ${version.words}. Install a newer git (and put it first on PATH), then start Toolroll again.`;
21
+ return `Toolroll needs git ${GIT_FLOOR_WORDS} or newer, and this machine's git is ${version.words}. Install a newer git (and put it first on PATH): ${newerGitHow(platform)}. Then start Toolroll again.`;
15
22
  }
16
23
  let probed;
17
24
  export function installedGitFloorProblem() {
package/dist/operate.js CHANGED
@@ -100,7 +100,7 @@ import { releaseStalledUpdate, waitingUpdate } from "./toolroll-update.js";
100
100
  import { dur } from "./design/kit.js";
101
101
  import { requeueEligibility, checkoutIdle, setCheckoutIdle, leadQuickAnswersOn, setLeadQuickAnswers, openStore, openStoreNoMigrate, initLocalMode, localModeCandidate, consoleServingNow, consoleComponent, consoleRowForPort, openConsoleRows, enrollOwnerPassword, installationCreatedBy, laptopPortOf, recordLaptopPort, localModeOf, localOwnerBinding, archiveTaskFamily, restoreTaskFamily, shipChecksForTask, elapsedSeconds, CONCURRENT_WRITER_WAIT_MS, isDatabaseBusy, databasePath, BUILT_IN, parseCapabilityKey, verifiedAuthor, isDigestTime, predecessorWatches, RESULT_SCREENSHOTS, lifecycleOf, reportLifecycle, beatLifecycle, } from "./store.js";
102
102
  import { createHash, randomBytes, randomInt, randomUUID } from "node:crypto";
103
- import { claimInstance, clearInstance, openInstanceSocket, proveLiveConsole } from "./console-instance.js";
103
+ import { claimInstance, clearInstance, instanceRunDir, openInstanceSocket, prepareRunDir, proveLiveConsole } from "./console-instance.js";
104
104
  import { backgroundOff, backgroundOn, backgroundShow, laptopStatus, laptopStop, restartOwnBuilder } from "./laptop-background.js";
105
105
  import { authorizePlanUnderMode } from "./plan-auto.js";
106
106
  import { ghDispatchAdapter, mirrorTaskId, syncPass } from "./sync.js";
@@ -120,6 +120,7 @@ import { LOCAL_POLICY } from "./surface.js";
120
120
  import { asLocalOwner, currentLocalOwner, LOCAL_MODE_CONFINES, localModeOn, localOwnerRefusal, localOwnerRequested } from "./local-owner.js";
121
121
  import { CHECK_ACCESS_WARNINGS, checkAccessRunsAs, checkAccessWords, isCheckAccess, signInHostsMissing, signInsUnavailableWords, widerThan } from "./check-access.js";
122
122
  import { CLI_PASSWORD_SOURCE, withPasswordSource } from "./sign-in-guard.js";
123
+ import { ledgerSpent, NO_SAFE_OPENER, openSignInLink, platformOpener } from "./sign-in-page.js";
123
124
  import { admissionRecorded, admitProject, commandLineActor } from "./project-admission.js";
124
125
  import { leadClaim, leadSay, noteLeadWork } from "./lead-voice.js";
125
126
  import { createConnection as createNetConnection, createServer as createNetServer } from "node:net";
@@ -166,7 +167,7 @@ function planContractLines(store, evidenceRoot, taskId) {
166
167
  import { verdictWords as proofVerdictWords, matrixWords, plainReasonWords, semanticCoverage, coverageWords } from "./proof.js";
167
168
  import { probeRepo } from "./probe.js";
168
169
  import { agentlessFirstRun, diagnoseTaskDispatch, diagnosisIsDispatchable, NO_AGENT_TITLE, scopeApprovedForDispatch, } from "./dispatch.js";
169
- import { createDecisionServer } from "./serve.js";
170
+ import { createDecisionServer, SIGN_IN_LINK_MS } from "./serve.js";
170
171
  import { readTailnetNames } from "./tailnet.js";
171
172
  import { daemonLaunchCommand, daemonStatus, installReplacingLegacy, installedLegacyDaemon, planDaemon, uninstallDaemon, awaitFreshHeartbeat, } from "./daemon.js";
172
173
  import { bridgePass, clearBotToken, createTransport, followBridge, hashPairingCode, loadBotToken, mintPairingCode, networkFence, networkFenceLine, redactToken, saveBotToken, PAIRING_TTL_MS, TOKEN_ENV, telegramHookSecret, telegramPushUrl, } from "./telegram.js";
@@ -6515,6 +6516,7 @@ async function upCommand(flags, context) {
6515
6516
  }
6516
6517
  }, RUNNER_HEARTBEAT_MS);
6517
6518
  runnerHeartbeat.unref?.();
6519
+ let removeSignInPageNow = () => { };
6518
6520
  const approverPlan2 = approver;
6519
6521
  const terminal = !agentRunning && (context.upSeams?.terminal ?? process.stdout.isTTY === true);
6520
6522
  const upHandoff = buildHandoff({
@@ -6547,7 +6549,11 @@ async function upCommand(flags, context) {
6547
6549
  const account = approverPlan2.approver;
6548
6550
  const localStart = approverPlan2.startAuthority === "local";
6549
6551
  const request = upLinkRequest(approverPlan2.startAuthority, account);
6550
- const link = request === null || flags.has("no-open") ? null : await new Promise(resolveLink => {
6552
+ const pageParent = instanceRunDir(context.databaseFile);
6553
+ const hasOpener = platformOpener(context.upSeams?.signInPlatform) !== null;
6554
+ const canOpen = hasOpener && prepareRunDir(pageParent) === null;
6555
+ const linkExpiresAt = Date.now() + SIGN_IN_LINK_MS;
6556
+ const link = request === null || flags.has("no-open") || !canOpen ? null : await new Promise(resolveLink => {
6551
6557
  const id = ++linkRequests;
6552
6558
  const timer = setTimeout(() => { pendingLinks.delete(id); resolveLink(null); }, 10_000);
6553
6559
  pendingLinks.set(id, value => { clearTimeout(timer); resolveLink(value); });
@@ -6558,28 +6564,40 @@ async function upCommand(flags, context) {
6558
6564
  const signInWords = account === null
6559
6565
  ? `sign in as one of ${approverPlan2.approvers.join(", ")}`
6560
6566
  : showCommand === null ? `sign in as ${account} with your password` : `sign in as ${account}`;
6567
+ const opened = link === null ? false : await (async () => {
6568
+ const outcome = localStart ? "local link" : "one-time link";
6569
+ const page = await openSignInLink(new URL(link, url).toString(), {
6570
+ parent: pageParent, spent: ledgerSpent(store, outcome, localStart ? null : account), expiresAt: linkExpiresAt,
6571
+ ...(context.upSeams?.signInOpener === undefined ? {} : { opener: context.upSeams.signInOpener }),
6572
+ ...(context.upSeams?.signInPlatform === undefined ? {} : { platform: context.upSeams.signInPlatform }),
6573
+ });
6574
+ removeSignInPageNow = page.stop;
6575
+ return page.opened;
6576
+ })();
6561
6577
  write("");
6562
6578
  write(`Toolroll is on ${url}`);
6563
6579
  if (localStart) {
6564
- if (link !== null) {
6580
+ if (opened) {
6565
6581
  write("Opening it in your browser now, already signed in.");
6566
6582
  write("If it doesn't open, stop it with Ctrl-C and run the same command again.");
6567
- (context.upSeams?.openBrowser ?? openBrowser)(new URL(link, url).toString());
6568
6583
  }
6569
- else
6584
+ else if (flags.has("no-open"))
6570
6585
  write("To sign in from this computer's browser, run the same command again without --no-open.");
6586
+ else if (!hasOpener)
6587
+ write(`${NO_SAFE_OPENER.charAt(0).toUpperCase()}${NO_SAFE_OPENER.slice(1)}.`);
6588
+ else
6589
+ write("Your browser didn't open. Stop it with Ctrl-C and run the same command again.");
6571
6590
  }
6572
- else if (link !== null) {
6591
+ else if (opened) {
6573
6592
  write("Opening it in your browser now, already signed in.");
6574
6593
  write(`If it doesn't open, go to that address and ${signInWords}.`);
6575
- (context.upSeams?.openBrowser ?? openBrowser)(new URL(link, url).toString());
6576
6594
  }
6577
6595
  else {
6578
6596
  write(`${signInWords.charAt(0).toUpperCase()}${signInWords.slice(1)}.`);
6579
6597
  }
6580
6598
  if (showCommand !== null)
6581
6599
  write(`Your password: run \`${showCommand}\``);
6582
- if (link === null)
6600
+ if (!opened)
6583
6601
  write("Ctrl-C stops it.");
6584
6602
  }
6585
6603
  }
@@ -6588,6 +6606,7 @@ async function upCommand(flags, context) {
6588
6606
  runTimer.unref?.();
6589
6607
  }
6590
6608
  await stopped;
6609
+ removeSignInPageNow();
6591
6610
  if (workerRole !== null)
6592
6611
  await Promise.race([workerRole.done, forced]);
6593
6612
  clearInterval(runnerHeartbeat);
@@ -64,7 +64,7 @@ export function missingLinuxSandboxTools(path = process.env["PATH"] ?? "") {
64
64
  return LINUX_SANDBOX_TOOLS.filter(tool => !found(tool.command)).map(tool => tool.package);
65
65
  }
66
66
  export function linuxSandboxInstallLine(packages = LINUX_SANDBOX_TOOLS.map(tool => tool.package)) {
67
- return `sudo apt install ${packages.join(" ")} (Fedora: sudo dnf install ${packages.join(" ")})`;
67
+ return `sudo apt update && sudo apt install ${packages.join(" ")} (Fedora: sudo dnf install ${packages.join(" ")})`;
68
68
  }
69
69
  export const linuxSandboxToolsWords = () => toolWords(LINUX_SANDBOX_TOOLS.map(tool => tool.package));
70
70
  export function missingSandboxToolsWords(missing) {