@factiii/runner 0.23.1 → 0.24.0

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 (3) hide show
  1. package/README.md +3 -3
  2. package/dist/cli.js +273 -63
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -5,7 +5,7 @@ A headless daemon that runs Factiii's Board AI agents (Claude-driven coding sess
5
5
  ## Requirements
6
6
 
7
7
  - Node 20+
8
- - git, tmux, and redis-server on PATH (`setup` checks for them)
8
+ - git, tmux, and redis-server on PATH (installed for you when a space first opens)
9
9
  - The agent CLIs you plan to use: `claude` and/or `codex`
10
10
  - A Factiii account
11
11
  - Outbound network access to the Factiii API server
@@ -25,7 +25,7 @@ npx @factiii/runner setup
25
25
  ## Usage
26
26
 
27
27
  ```bash
28
- factiii-runner setup # verify the host toolchain, pair this runner
28
+ factiii-runner setup # pair this runner
29
29
  factiii-runner connect # re-pair with a different account
30
30
  factiii-runner start # run the daemon (keep this process alive)
31
31
  factiii-runner status # show current config + credential storage state
@@ -33,7 +33,7 @@ factiii-runner doctor # show where each host tool resolves, and the PATH
33
33
  factiii-runner password # enter an old connection password once, to remove it (see Security notes)
34
34
  ```
35
35
 
36
- `setup` is the one-shot command that gets you from zero to running. It checks the host toolchain and walks you through the browser pairing flow. After it finishes, `factiii-runner start` runs the daemon.
36
+ `setup` walks you through the browser pairing flow. After it finishes, `factiii-runner start` runs the daemon. The host toolchain (git, tmux, redis, the agent CLIs) installs when you first open a space on the board, with progress shown there; `factiii-runner setup --tools` runs the same install from the terminal.
37
37
 
38
38
  `doctor` is the first thing to run when a board reports "Couldn't initialize the environment". It prints the resolved location of every tool the runner needs and the PATH it searched, which separates a tool that is genuinely absent from one that is installed somewhere the runner cannot see.
39
39
 
package/dist/cli.js CHANGED
@@ -3984,7 +3984,7 @@ var require_has_flag = __commonJS({
3984
3984
  var require_supports_color = __commonJS({
3985
3985
  "../../node_modules/debug/node_modules/supports-color/index.js"(exports2, module2) {
3986
3986
  "use strict";
3987
- var os7 = require("os");
3987
+ var os8 = require("os");
3988
3988
  var hasFlag = require_has_flag();
3989
3989
  var env = process.env;
3990
3990
  var forceColor;
@@ -4022,7 +4022,7 @@ var require_supports_color = __commonJS({
4022
4022
  }
4023
4023
  const min = forceColor ? 1 : 0;
4024
4024
  if (process.platform === "win32") {
4025
- const osRelease = os7.release().split(".");
4025
+ const osRelease = os8.release().split(".");
4026
4026
  if (Number(process.versions.node.split(".")[0]) >= 8 && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
4027
4027
  return Number(osRelease[2]) >= 14931 ? 3 : 2;
4028
4028
  }
@@ -34755,7 +34755,7 @@ var CodexLoginFlow = class {
34755
34755
  var DEVICE_CODE_URL = "https://github.com/login/device/code";
34756
34756
  var TOKEN_URL = "https://github.com/login/oauth/access_token";
34757
34757
  var API_BASE = "https://api.github.com";
34758
- var GITHUB_SCOPES = "repo read:user user:email";
34758
+ var GITHUB_SCOPES = "repo workflow read:user user:email";
34759
34759
  var DEVICE_CODE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
34760
34760
  async function startGithubDeviceCode(clientId) {
34761
34761
  const res = await fetch(DEVICE_CODE_URL, {
@@ -34877,6 +34877,7 @@ var import_path14 = __toESM(require("path"));
34877
34877
  var import_child_process4 = require("child_process");
34878
34878
  var import_crypto6 = __toESM(require("crypto"));
34879
34879
  var import_promises9 = __toESM(require("fs/promises"));
34880
+ var import_os4 = __toESM(require("os"));
34880
34881
  var import_path12 = __toESM(require("path"));
34881
34882
  var import_util11 = require("util");
34882
34883
 
@@ -35625,6 +35626,57 @@ async function writeBackupFiles(spaceDir, files) {
35625
35626
  }
35626
35627
  });
35627
35628
  }
35629
+ var BACKUP_FILE_VIEW_MAX = 1024 * 1024;
35630
+ async function openBackupFiles(files, password, throttleDir) {
35631
+ const paths = Object.keys(files);
35632
+ const bad = paths.find((rel) => !isBackupPath(rel));
35633
+ if (bad !== void 0) {
35634
+ throw new Error(`This backup holds a file it should not: ${bad}`);
35635
+ }
35636
+ const boxRaw = files[IDENTITY_FILE];
35637
+ if (!boxRaw) throw new Error("This backup has no key in it.");
35638
+ let box;
35639
+ try {
35640
+ box = JSON.parse(
35641
+ Buffer.from(boxRaw, "base64").toString("utf-8")
35642
+ );
35643
+ } catch {
35644
+ throw new Error("This backup has no key in it.");
35645
+ }
35646
+ const identity = await throttledPasswordCheck(
35647
+ throttleDir,
35648
+ () => decryptIdentity(box, password)
35649
+ );
35650
+ await assertBinaries();
35651
+ const scratch = await import_promises9.default.mkdtemp(import_path12.default.join(import_os4.default.tmpdir(), "factiii-backup-"));
35652
+ try {
35653
+ const root = import_path12.default.join(scratch, "secrets");
35654
+ await import_promises9.default.mkdir(import_path12.default.join(root, FILES_DIR), { recursive: true, mode: 448 });
35655
+ for (const rel of paths) {
35656
+ await import_promises9.default.writeFile(
35657
+ import_path12.default.join(root, rel),
35658
+ Buffer.from(files[rel], "base64"),
35659
+ { mode: 384 }
35660
+ );
35661
+ }
35662
+ const opened = {
35663
+ values: await readEnv(scratch, identity),
35664
+ meta: await readSecretMeta(scratch),
35665
+ files: []
35666
+ };
35667
+ for (const name of await storedSecretFiles(scratch)) {
35668
+ const data = await readSecretFileWithIdentity(scratch, identity, name);
35669
+ opened.files.push({
35670
+ name,
35671
+ size: data.length,
35672
+ data: data.length > BACKUP_FILE_VIEW_MAX ? null : data.toString("base64")
35673
+ });
35674
+ }
35675
+ return opened;
35676
+ } finally {
35677
+ await import_promises9.default.rm(scratch, { recursive: true, force: true });
35678
+ }
35679
+ }
35628
35680
 
35629
35681
  // ../../shared/all/helpers/board-agent-core/secrets-gate.ts
35630
35682
  var import_crypto7 = __toESM(require("crypto"));
@@ -35813,7 +35865,7 @@ var SecretsGate = class {
35813
35865
 
35814
35866
  // ../../shared/all/helpers/board-agent-core/secrets-run.ts
35815
35867
  var import_promises10 = __toESM(require("fs/promises"));
35816
- var import_os4 = __toESM(require("os"));
35868
+ var import_os5 = __toESM(require("os"));
35817
35869
  var import_path13 = __toESM(require("path"));
35818
35870
 
35819
35871
  // ../../shared/all/helpers/board-agent-core/secrets-window.ts
@@ -35954,6 +36006,10 @@ function lineStreamer(redact, emit) {
35954
36006
  var DOTENV_LINE = /^\s*(?:export\s+)?[A-Za-z_][A-Za-z0-9_]*\s*=\s*(.*?)\s*$/;
35955
36007
  var PLAIN_ENV_VALUE = /^(?:true|false|yes|no|on|off|production|development|staging|test|localhost|[0-9.:]+)$/i;
35956
36008
  var MIN_ENV_VALUE = 6;
36009
+ var GITHUB_TOKEN_KEYS = /* @__PURE__ */ new Set([
36010
+ "GH_TOKEN",
36011
+ "GITHUB_TOKEN"
36012
+ ]);
35957
36013
  function redactionValues(value2) {
35958
36014
  const out2 = [value2];
35959
36015
  if (value2.includes("\n")) {
@@ -36113,7 +36169,9 @@ async function authorizeAndRun(opts) {
36113
36169
  const missing = [];
36114
36170
  for (const key of scope) {
36115
36171
  if (key in store) injected[key] = store[key];
36116
- else missing.push(key);
36172
+ else if (GITHUB_TOKEN_KEYS.has(key) && opts.githubToken) {
36173
+ injected[key] = opts.githubToken;
36174
+ } else missing.push(key);
36117
36175
  }
36118
36176
  if (missing.length && opts.keys) {
36119
36177
  const note = `${missing.join(", ")} ${missing.length === 1 ? "is" : "are"} not in the store, so the command sees ${missing.length === 1 ? "it" : "them"} empty.`;
@@ -36121,11 +36179,12 @@ async function authorizeAndRun(opts) {
36121
36179
  opts.sendLog?.({ type: "system", content: note });
36122
36180
  }
36123
36181
  const secrets = Object.values(store).flatMap(redactionValues);
36182
+ if (opts.githubToken) secrets.push(...redactionValues(opts.githubToken));
36124
36183
  let tempDir = null;
36125
36184
  const fileEnv = {};
36126
36185
  try {
36127
36186
  if (files.length) {
36128
- tempDir = await import_promises10.default.mkdtemp(import_path13.default.join(import_os4.default.tmpdir(), "factiii-secrets-"));
36187
+ tempDir = await import_promises10.default.mkdtemp(import_path13.default.join(import_os5.default.tmpdir(), "factiii-secrets-"));
36129
36188
  await import_promises10.default.chmod(tempDir, 448);
36130
36189
  for (const name of files) {
36131
36190
  const data = await readSecretFileWithIdentity(
@@ -36304,6 +36363,7 @@ async function startDeployRun(opts) {
36304
36363
  spaceDir: opts.spaceDir,
36305
36364
  cwd: workspace,
36306
36365
  command,
36366
+ githubToken: opts.githubToken || void 0,
36307
36367
  // The marker carries a command and nothing else, so a skill speaking
36308
36368
  // it cannot name its keys. null takes the declared contract - still
36309
36369
  // a narrowing from the whole store, and the most this protocol can
@@ -36434,11 +36494,11 @@ function parseBundle(raw) {
36434
36494
  }
36435
36495
  return b;
36436
36496
  }
36437
- async function restoreSecretsBackup(opts) {
36438
- const bundle = parseBundle(opts.bundle);
36497
+ function unseal(raw, passphrase) {
36498
+ const bundle = parseBundle(raw);
36439
36499
  const decipher = import_crypto8.default.createDecipheriv(
36440
36500
  "aes-256-gcm",
36441
- deriveKey2(opts.passphrase, Buffer.from(bundle.salt, "base64")),
36501
+ deriveKey2(passphrase, Buffer.from(bundle.salt, "base64")),
36442
36502
  Buffer.from(bundle.iv, "base64")
36443
36503
  );
36444
36504
  decipher.setAAD(header(bundle));
@@ -36453,6 +36513,10 @@ async function restoreSecretsBackup(opts) {
36453
36513
  throw new Error("Wrong backup passphrase, or the file was changed.");
36454
36514
  }
36455
36515
  const { files } = JSON.parse(plain);
36516
+ return { bundle, files };
36517
+ }
36518
+ async function restoreSecretsBackup(opts) {
36519
+ const { bundle, files } = unseal(opts.bundle, opts.passphrase);
36456
36520
  await writeBackupFiles(opts.spaceDir, files);
36457
36521
  return {
36458
36522
  board: bundle.board,
@@ -36460,6 +36524,20 @@ async function restoreSecretsBackup(opts) {
36460
36524
  files: Object.keys(files).length
36461
36525
  };
36462
36526
  }
36527
+ async function openSecretsBackup(opts) {
36528
+ const { bundle, files } = unseal(opts.bundle, opts.passphrase);
36529
+ const opened = await openBackupFiles(files, opts.password, opts.throttleDir);
36530
+ return {
36531
+ board: bundle.board,
36532
+ createdAt: bundle.createdAt,
36533
+ secrets: Object.keys(opened.values).sort().map((name) => ({
36534
+ name,
36535
+ value: opened.values[name],
36536
+ description: opened.meta[name]?.description || opened.meta[name]?.title || ""
36537
+ })),
36538
+ files: opened.files
36539
+ };
36540
+ }
36463
36541
 
36464
36542
  // ../../shared/all/helpers/graphFetch.ts
36465
36543
  var GRAPH_MAX_RETRIES = 3;
@@ -38017,6 +38095,15 @@ async function detectPackageManager(target) {
38017
38095
  }
38018
38096
  return null;
38019
38097
  }
38098
+ var MINUTE = 6e4;
38099
+ var NPM_TIMEOUT_MS = 15 * MINUTE;
38100
+ var PACKAGE_TIMEOUT_MS = 30 * MINUTE;
38101
+ var BREW_TIMEOUT_MS = 3 * 60 * MINUTE;
38102
+ var BREW_BOOTSTRAP_TIMEOUT_MS = 60 * MINUTE;
38103
+ function installTimeout(tool, mgr) {
38104
+ if (tool.npm) return NPM_TIMEOUT_MS;
38105
+ return mgr === "brew" ? BREW_TIMEOUT_MS : PACKAGE_TIMEOUT_MS;
38106
+ }
38020
38107
  function installCommand(tool, mgr) {
38021
38108
  if (tool.npm) return `npm install -g --prefix "${NPM_PREFIX}" ${tool.npm}`;
38022
38109
  const pkg = tool.pkg?.[mgr] ?? tool.bin;
@@ -38133,7 +38220,12 @@ async function provision(target, onStatus, requestSudo) {
38133
38220
  if (!mgr && needsManager && process.platform === "darwin") {
38134
38221
  onStatus("Homebrew not found");
38135
38222
  onStatus("Installing Homebrew\u2026");
38136
- await runStreaming(target, BREW_INSTALL, onStatus);
38223
+ await runStreaming(
38224
+ target,
38225
+ BREW_INSTALL,
38226
+ onStatus,
38227
+ BREW_BOOTSTRAP_TIMEOUT_MS
38228
+ );
38137
38229
  invalidatePathCache();
38138
38230
  mgr = await detectPackageManager(target);
38139
38231
  if (mgr) onStatus("Installed Homebrew.");
@@ -38143,39 +38235,74 @@ async function provision(target, onStatus, requestSudo) {
38143
38235
  `Missing required tools (${missing.map((t) => t.bin).join(", ")}) and no package manager was found on this runner. Install your distro's package manager, then try again.`
38144
38236
  );
38145
38237
  }
38146
- for (const tool of missing) {
38147
- onStatus(`${tool.bin} not found`);
38148
- const cmd = installCommand(tool, mgr ?? "brew");
38149
- onStatus(`Installing ${tool.bin}\u2026`);
38150
- const output2 = await runStreaming(target, cmd, onStatus);
38151
- invalidatePathCache();
38152
- if (!await isInstalled(target, tool.bin)) {
38153
- const searched = await target.sh('printf %s "$PATH"').catch(() => "<unavailable>");
38154
- throw new Error(
38155
- `Failed to install ${tool.bin} with \`${cmd}\`.
38156
-
38157
- Searched PATH: ${searched.trim()}
38158
-
38159
- ${output2.slice(-2e3)}`
38160
- );
38238
+ const manager = mgr ?? "brew";
38239
+ const installAll = async (tools) => {
38240
+ const failures = [];
38241
+ for (const tool of tools) {
38242
+ const message = await installOne(target, tool, manager, onStatus);
38243
+ if (message) failures.push({ tool, message });
38161
38244
  }
38245
+ return failures;
38246
+ };
38247
+ let failed = await installAll(missing);
38248
+ if (failed.length) {
38249
+ onStatus(`Retrying ${failed.map((f) => f.tool.bin).join(", ")}\u2026`);
38250
+ failed = await installAll(failed.map((f) => f.tool));
38251
+ }
38252
+ if (failed.length) {
38253
+ throw new Error(failed.map((f) => f.message).join("\n\n"));
38254
+ }
38255
+ }
38256
+ async function installOne(target, tool, mgr, onStatus) {
38257
+ onStatus(`${tool.bin} not found`);
38258
+ const cmd = installCommand(tool, mgr);
38259
+ onStatus(`Installing ${tool.bin}\u2026`);
38260
+ const output2 = await runStreaming(
38261
+ target,
38262
+ cmd,
38263
+ onStatus,
38264
+ installTimeout(tool, mgr)
38265
+ );
38266
+ invalidatePathCache();
38267
+ if (await isInstalled(target, tool.bin)) {
38162
38268
  onStatus(`Installed ${tool.bin}.`);
38269
+ return null;
38163
38270
  }
38271
+ onStatus(`Could not install ${tool.bin}.`);
38272
+ const searched = await target.sh('printf %s "$PATH"').catch(() => "<unavailable>");
38273
+ return `Failed to install ${tool.bin} with \`${cmd}\`.
38274
+
38275
+ Searched PATH: ${searched.trim()}
38276
+
38277
+ ${output2.slice(-2e3)}`;
38164
38278
  }
38165
- async function runStreaming(target, cmd, onStatus) {
38279
+ async function runStreaming(target, cmd, onStatus, timeoutMs) {
38166
38280
  let seen = 0;
38167
- const result = await target.step(cmd, {
38168
- timeoutMs: 15 * 6e4,
38169
- onOutput: (combined) => {
38170
- const fresh = combined.slice(seen);
38171
- seen = combined.length;
38172
- for (const line of fresh.split("\n")) {
38173
- const trimmed = line.trim();
38174
- if (trimmed) onStatus(trimmed);
38281
+ const started = Date.now();
38282
+ let lastLine = started;
38283
+ const beat = setInterval(() => {
38284
+ if (Date.now() - lastLine < MINUTE) return;
38285
+ const minutes = Math.round((Date.now() - started) / MINUTE);
38286
+ onStatus(`Still working\u2026 (${minutes} min)`);
38287
+ }, MINUTE);
38288
+ try {
38289
+ const result = await target.step(cmd, {
38290
+ timeoutMs,
38291
+ onOutput: (combined) => {
38292
+ const fresh = combined.slice(seen);
38293
+ seen = combined.length;
38294
+ for (const line of fresh.split("\n")) {
38295
+ const trimmed = line.trim();
38296
+ if (!trimmed) continue;
38297
+ lastLine = Date.now();
38298
+ onStatus(trimmed);
38299
+ }
38175
38300
  }
38176
- }
38177
- });
38178
- return result.stdout;
38301
+ });
38302
+ return result.stdout;
38303
+ } finally {
38304
+ clearInterval(beat);
38305
+ }
38179
38306
  }
38180
38307
 
38181
38308
  // ../../shared/all/helpers/board-agent-core/space-core.ts
@@ -38327,6 +38454,7 @@ var SpaceCore = class {
38327
38454
  // confused caller, and the workspace is the safe reading.
38328
38455
  cwd: containedCwd(cwd, spaceDir) ?? this.target().paths.workspace,
38329
38456
  command,
38457
+ githubToken: this.readConfig().githubToken || void 0,
38330
38458
  keys,
38331
38459
  files,
38332
38460
  // Only the legacy marker needs a declared fallback, and that never
@@ -39218,6 +39346,39 @@ var BoardAgentEngine = class _BoardAgentEngine {
39218
39346
  bundle
39219
39347
  };
39220
39348
  }
39349
+ /** The owner reading a backup file's secrets (secrets-backup.ts). The file
39350
+ * may be of any board, so its board password is checked under THIS board's
39351
+ * guess limit and a wrong one is logged here. An open is logged with the
39352
+ * names it showed: it is the one time values leave the runner. */
39353
+ async secretsOpenBackup(payload, ctx = OWNER_CONTEXT) {
39354
+ const { spaceDir } = this.secretsDirs();
39355
+ const opened = await this.auditPasswordFailure(
39356
+ ctx,
39357
+ "open backup",
39358
+ [],
39359
+ () => openSecretsBackup({
39360
+ bundle: payload.bundle,
39361
+ passphrase: payload.passphrase,
39362
+ password: payload.password,
39363
+ throttleDir: spaceKeyDir(spaceDir)
39364
+ })
39365
+ );
39366
+ await this.core.audit.append({
39367
+ actor: ctx.actor,
39368
+ via: ctx.via,
39369
+ action: "backup-open",
39370
+ job: null,
39371
+ keys: [
39372
+ ...opened.secrets.map((s) => s.name),
39373
+ ...opened.files.map((f) => f.name)
39374
+ ],
39375
+ exitCode: null,
39376
+ durationMs: null,
39377
+ unlockedBy: null,
39378
+ detail: `${opened.board} backup of ${opened.createdAt.slice(0, 10)}`
39379
+ });
39380
+ return opened;
39381
+ }
39221
39382
  // ── Jobs (jobs.ts), the inbox (secrets-inbox.ts), the audit log ──
39222
39383
  /** The jobs.json on the default branch. A repo with none has no jobs. */
39223
39384
  async loadJobs() {
@@ -39311,6 +39472,7 @@ var BoardAgentEngine = class _BoardAgentEngine {
39311
39472
  keys: def.keys,
39312
39473
  declared: [],
39313
39474
  files: def.files,
39475
+ githubToken: this.core.readConfig().githubToken || void 0,
39314
39476
  origin: `Job ${def.name} \xB7 ${caller.name}`,
39315
39477
  gate: this.gate,
39316
39478
  window: this.core.window,
@@ -40000,7 +40162,10 @@ var BoardAgentEngine = class _BoardAgentEngine {
40000
40162
  () => listSecretKeys(configDir, spaceDir, payload.password)
40001
40163
  ),
40002
40164
  meta: await readSecretMeta(spaceDir),
40003
- files: await storedSecretFiles(spaceDir)
40165
+ files: await storedSecretFiles(spaceDir),
40166
+ // With GitHub connected, the connection answers for these when the
40167
+ // store has no value, so they are not "missing".
40168
+ provided: this.core.readConfig().githubToken ? [...GITHUB_TOKEN_KEYS] : []
40004
40169
  };
40005
40170
  }
40006
40171
  async deploySecretsSet(payload, ctx = OWNER_CONTEXT) {
@@ -41058,6 +41223,11 @@ ${c.content.trim() || "(no description)"}`
41058
41223
  payload,
41059
41224
  ctx
41060
41225
  );
41226
+ case "secretsOpenBackup":
41227
+ return await this.secretsOpenBackup(
41228
+ payload,
41229
+ ctx
41230
+ );
41061
41231
  case "secretsChangePassword":
41062
41232
  return await this.secretsChangePassword(
41063
41233
  payload,
@@ -41367,7 +41537,7 @@ var import_util12 = require("util");
41367
41537
 
41368
41538
  // ../../shared/all/helpers/board-agent-core/node-version.ts
41369
41539
  var import_fs5 = require("fs");
41370
- var import_os5 = __toESM(require("os"));
41540
+ var import_os6 = __toESM(require("os"));
41371
41541
  var import_path19 = require("path");
41372
41542
  var MIN_INDEX_NODE_MAJOR = 20;
41373
41543
  var MAX_INDEX_NODE_MAJOR = 24;
@@ -41381,7 +41551,7 @@ function indexNodeSupported(version2 = process.versions.node) {
41381
41551
  }
41382
41552
  function candidateNodes() {
41383
41553
  const paths = [];
41384
- const home = import_os5.default.homedir();
41554
+ const home = import_os6.default.homedir();
41385
41555
  const nvmRoot = (0, import_path19.join)(home, ".nvm", "versions", "node");
41386
41556
  try {
41387
41557
  const versions = (0, import_fs5.readdirSync)(nvmRoot).filter((v) => indexNodeSupported(v)).sort((a, b) => nodeMajor(b) - nodeMajor(a));
@@ -41720,6 +41890,7 @@ var OWNER_ONLY_ACTIONS = /* @__PURE__ */ new Set([
41720
41890
  "runnerAccessSet",
41721
41891
  "secretsChangePassword",
41722
41892
  "secretsExportBackup",
41893
+ "secretsOpenBackup",
41723
41894
  "deploySecretsSetFile",
41724
41895
  "deploySecretsUnsetFile",
41725
41896
  // The desktop view is the whole machine, on screen and under the pointer.
@@ -41739,6 +41910,18 @@ function actionAllowed(role, access, action) {
41739
41910
  if (MEMBER_API_ACTIONS.has(action)) return access.apiAccess;
41740
41911
  return access.shareTerminals;
41741
41912
  }
41913
+ function parseVouchedScope(raw) {
41914
+ if (!raw || typeof raw !== "object") return null;
41915
+ const scope = raw;
41916
+ const userId = typeof scope.userId === "string" ? scope.userId : "";
41917
+ const name = typeof scope.name === "string" ? scope.name : "";
41918
+ if (scope.role === "owner") return { role: "owner", userId, name };
41919
+ if (scope.role !== "member" || !Array.isArray(scope.spaceSlugs)) return null;
41920
+ const spaceSlugs = scope.spaceSlugs.filter(
41921
+ (slug) => typeof slug === "string"
41922
+ );
41923
+ return { role: "member", spaceSlugs, userId, name };
41924
+ }
41742
41925
  function rawUseAllowed(role, access, use) {
41743
41926
  if (role === "owner") return true;
41744
41927
  if (use === "runner-control") return false;
@@ -41760,6 +41943,7 @@ var RELAY_REFUSED_ACTIONS = /* @__PURE__ */ new Set([
41760
41943
  "deployRunAuthorize",
41761
41944
  "secretsChangePassword",
41762
41945
  "secretsExportBackup",
41946
+ "secretsOpenBackup",
41763
41947
  "secureUnlock",
41764
41948
  "secureSetPassword",
41765
41949
  "secureClearPassword"
@@ -42184,7 +42368,7 @@ function wrapKey(machineKey, pwKey) {
42184
42368
  )
42185
42369
  );
42186
42370
  }
42187
- function unseal(box, key) {
42371
+ function unseal2(box, key) {
42188
42372
  try {
42189
42373
  const decipher = import_crypto13.default.createDecipheriv(
42190
42374
  "aes-256-gcm",
@@ -42223,7 +42407,7 @@ function vaultKey() {
42223
42407
  'Open Runner Settings \u2192 Secrets on any device and enter the password, restart the runner in a terminal and type it there, or run "factiii-runner password".'
42224
42408
  );
42225
42409
  }
42226
- const dek = unseal(file2, wrapKey(machineKey, null));
42410
+ const dek = unseal2(file2, wrapKey(machineKey, null));
42227
42411
  if (!dek) {
42228
42412
  throw new SecureStoreError(
42229
42413
  "no-keychain",
@@ -42246,7 +42430,7 @@ function unlock(password) {
42246
42430
  "This runner has no connection password, so there is nothing to unlock."
42247
42431
  );
42248
42432
  }
42249
- const dek = unseal(
42433
+ const dek = unseal2(
42250
42434
  file2,
42251
42435
  wrapKey(machineKey, passwordKey(password, Buffer.from(file2.salt, "base64")))
42252
42436
  );
@@ -43402,7 +43586,7 @@ ${callId ? `${args.job} (call ${callId})` : `Could not start ${args.job}`}: ${er
43402
43586
  }
43403
43587
 
43404
43588
  // src/remote/login.ts
43405
- var import_os6 = __toESM(require("os"));
43589
+ var import_os7 = __toESM(require("os"));
43406
43590
 
43407
43591
  // src/remote/tokenStore.ts
43408
43592
  var import_child_process8 = require("child_process");
@@ -43488,7 +43672,7 @@ var DEFAULT_LOGIN_WINDOW_MS = 10 * 60 * 1e3;
43488
43672
  async function login(api, serverUrl, io) {
43489
43673
  const start = await api.mutation(PROCEDURES.startLogin, {
43490
43674
  // Shown on the approve page and in the token list; the server caps it at 64.
43491
- label: (import_os6.default.hostname() || "factiii-runner CLI").slice(0, 64)
43675
+ label: (import_os7.default.hostname() || "factiii-runner CLI").slice(0, 64)
43492
43676
  });
43493
43677
  const now = io.now ?? Date.now;
43494
43678
  const deadline = now() + (start.expiresIn ? start.expiresIn * 1e3 : DEFAULT_LOGIN_WINDOW_MS);
@@ -43908,7 +44092,20 @@ async function setup(serverUrl) {
43908
44092
  );
43909
44093
  process.exit(1);
43910
44094
  }
43911
- console.log("[1/2] Preparing the host toolchain...");
44095
+ console.log("Pairing this runner with a Factiii account...");
44096
+ const wasPaired = configExists();
44097
+ const { token, runnerName } = await pairWithBrowser(serverUrl);
44098
+ writeRunnerConfig({ serverUrl, authToken: token, runnerName });
44099
+ markNewRunner(CONFIG_DIR, wasPaired);
44100
+ console.log(" Paired and config saved.");
44101
+ console.log("\n=== Setup complete ===\n");
44102
+ console.log("Start the runner with: factiii-runner start");
44103
+ console.log(
44104
+ "Anything the host is missing (git, tmux, redis, the agent CLIs) installs when you open a space on the board.\n"
44105
+ );
44106
+ }
44107
+ async function setupTools() {
44108
+ console.log("\n=== Factiii Runner \u2014 Host toolchain ===\n");
43912
44109
  try {
43913
44110
  await ensureToolchain(
43914
44111
  hostTarget(CONFIG_DIR),
@@ -43918,15 +44115,7 @@ async function setup(serverUrl) {
43918
44115
  console.error(` ${err2 instanceof Error ? err2.message : String(err2)}`);
43919
44116
  process.exit(1);
43920
44117
  }
43921
- console.log(" Toolchain is ready.");
43922
- console.log("\n[2/2] Pairing this runner with a Factiii account...");
43923
- const wasPaired = configExists();
43924
- const { token, runnerName } = await pairWithBrowser(serverUrl);
43925
- writeRunnerConfig({ serverUrl, authToken: token, runnerName });
43926
- markNewRunner(CONFIG_DIR, wasPaired);
43927
- console.log(" Paired and config saved.");
43928
- console.log("\n=== Setup complete ===\n");
43929
- console.log("Start the runner with: factiii-runner start\n");
44118
+ console.log(" Toolchain is ready.\n");
43930
44119
  }
43931
44120
 
43932
44121
  // src/selfUpdate.ts
@@ -47749,13 +47938,19 @@ var ownerActor = {
47749
47938
  name: "Owner"
47750
47939
  };
47751
47940
  function toChannelScope(raw) {
47752
- const userId = raw?.userId ?? "";
47753
- const name = raw?.name ?? "";
47754
- if (!raw || raw.role === "owner") {
47941
+ const scope = parseVouchedScope(raw);
47942
+ if (!scope) return null;
47943
+ const { userId, name } = scope;
47944
+ if (scope.role === "owner") {
47755
47945
  if (name) ownerActor = { userId: ownerActor.userId || userId, name };
47756
47946
  return { role: "owner", userId: userId || ownerActor.userId, name };
47757
47947
  }
47758
- return { role: "member", spaceSlugs: new Set(raw.spaceSlugs), userId, name };
47948
+ return {
47949
+ role: "member",
47950
+ spaceSlugs: new Set(scope.spaceSlugs),
47951
+ userId,
47952
+ name
47953
+ };
47759
47954
  }
47760
47955
  var SIMULATOR_PAYLOAD_TYPE = 96;
47761
47956
  var SIMULATOR_PROFILE = "f4001f";
@@ -48476,6 +48671,14 @@ async function startDaemon(config2) {
48476
48671
  socket.on("runnerSocketOpen", ({ fromSocketId, linkId, scope }) => {
48477
48672
  const key = `${fromSocketId}:${linkId}`;
48478
48673
  socketLinks.get(key)?.close();
48674
+ const channelScope = toChannelScope(scope);
48675
+ if (!channelScope) {
48676
+ console.error(
48677
+ `Refused socket link from ${fromSocketId}: the server sent no scope`
48678
+ );
48679
+ socket.emit("runnerSocketClose", { targetSocketId: fromSocketId, linkId });
48680
+ return;
48681
+ }
48479
48682
  console.log(`Socket link opened with ${fromSocketId}`);
48480
48683
  let open2 = true;
48481
48684
  let handleOpen = () => {
@@ -48511,7 +48714,7 @@ async function startDaemon(config2) {
48511
48714
  handleClosed();
48512
48715
  };
48513
48716
  socketLinks.set(key, { feed: (frame) => handleMessage(frame), close });
48514
- attachChannel(wire, toChannelScope(scope), fromSocketId, "socket");
48717
+ attachChannel(wire, channelScope, fromSocketId, "socket");
48515
48718
  socket.emit("runnerSocketOpened", { targetSocketId: fromSocketId, linkId });
48516
48719
  handleOpen();
48517
48720
  });
@@ -48524,6 +48727,12 @@ async function startDaemon(config2) {
48524
48727
  socket.on("runnerOffer", (data) => {
48525
48728
  console.log(`Received WebRTC offer from ${data.fromSocketId}`);
48526
48729
  const scope = toChannelScope(data.scope);
48730
+ if (!scope) {
48731
+ console.error(
48732
+ `Refused WebRTC offer from ${data.fromSocketId}: the server sent no scope`
48733
+ );
48734
+ return;
48735
+ }
48527
48736
  try {
48528
48737
  let iceServers;
48529
48738
  try {
@@ -48951,10 +49160,11 @@ OneDrive search will be unavailable until a supported Node is installed (nvm ins
48951
49160
  import_node_dns.default.setDefaultResultOrder("ipv4first");
48952
49161
  var program2 = new Command();
48953
49162
  program2.name("factiii-runner").description("Factiii Runner - run Board AI agents on remote servers").version(currentVersion());
48954
- program2.command("setup").description("Verify the host toolchain and pair this runner").option("-s, --server <url>", "API server URL", "https://api.factiii.com").action(async (opts) => {
49163
+ program2.command("setup").description("Pair this runner; --tools installs the host toolchain instead").option("-s, --server <url>", "API server URL", "https://api.factiii.com").option("--tools", "Install the host toolchain from this terminal").action(async (opts) => {
48955
49164
  try {
48956
49165
  warnUnsupportedNode();
48957
- await setup(opts.server);
49166
+ if (opts.tools) await setupTools();
49167
+ else await setup(opts.server);
48958
49168
  } catch (err2) {
48959
49169
  console.error(
48960
49170
  "Setup failed:",
@@ -49047,7 +49257,7 @@ Login PATH
49047
49257
  const missing = report.tools.filter((t) => !t.location);
49048
49258
  console.log(
49049
49259
  missing.length ? `
49050
- Missing: ${missing.map((t) => t.bin).join(", ")}. Run "factiii-runner setup" to install them.
49260
+ Missing: ${missing.map((t) => t.bin).join(", ")}. Open a space on the board, or run "factiii-runner setup --tools", to install them.
49051
49261
  ` : "\nAll host tools resolved.\n"
49052
49262
  );
49053
49263
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@factiii/runner",
3
- "version": "0.23.1",
3
+ "version": "0.24.0",
4
4
  "description": "Factiii Runner, run Board AI agents on a machine you control. Pairs with the Factiii web/mobile clients over WebRTC.",
5
5
  "license": "ISC",
6
6
  "homepage": "https://factiii.com",