byollm 0.1.1 → 0.1.3

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.
@@ -194,6 +194,10 @@ function asHttpOrigin(candidate) {
194
194
 
195
195
  // src/local-server.ts
196
196
  import { spawn } from "child_process";
197
+ import {
198
+ BACKEND_IDS,
199
+ backendDescriptor
200
+ } from "@byollm/protocol";
197
201
  function startCommandFor(id) {
198
202
  switch (id) {
199
203
  case "ollama":
@@ -202,6 +206,18 @@ function startCommandFor(id) {
202
206
  return void 0;
203
207
  }
204
208
  }
209
+ function startableAt(origin) {
210
+ for (const id of BACKEND_IDS) {
211
+ if (startCommandFor(id) === void 0) continue;
212
+ const address = backendDescriptor(id).defaultBaseUrl;
213
+ if (address === void 0) continue;
214
+ try {
215
+ if (new URL(address).origin === origin) return id;
216
+ } catch {
217
+ }
218
+ }
219
+ return void 0;
220
+ }
205
221
  function isLoopback(baseUrl) {
206
222
  let host;
207
223
  try {
@@ -360,7 +376,7 @@ import {
360
376
  BackendIdSchema,
361
377
  JobKind,
362
378
  OfferScope,
363
- backendDescriptor,
379
+ backendDescriptor as backendDescriptor2,
364
380
  effectiveOfferScope,
365
381
  classifyCost
366
382
  } from "@byollm/protocol";
@@ -613,11 +629,41 @@ var DaemonConfig = z.object({
613
629
  * The trade this switch represents is written down rather than
614
630
  * discovered: an auto-updating daemon means whoever controls the npm
615
631
  * publish controls the fleet. The controls on that are 2FA at publish,
616
- * exact-version installs (never a tag), the canary and rollback in
617
- * `update.ts`, and staged cohorts. It is the Chrome trade, taken
618
- * deliberately.
632
+ * exact-version installs (never a tag), forward-only versions, offers
633
+ * from {@link updateAuthority} alone, SLSA provenance checked before the
634
+ * new binary runs, and the canary and rollback in `update.ts`. Staged
635
+ * cohorts are NOT among them yet: nothing in this file or on the wire
636
+ * spreads an offer over time, so every machine the authority offers a
637
+ * version to takes it on its next heartbeat. It is the Chrome trade,
638
+ * taken deliberately.
619
639
  */
620
640
  autoUpdate: z.boolean().default(false),
641
+ /**
642
+ * The one origin whose update offers this daemon takes — B360.
643
+ *
644
+ * Unset means the reference hub (`DEFAULT_ORIGIN` in `cli.ts`), and it is
645
+ * resolved there rather than defaulted here on purpose: `byollm offer`
646
+ * writes the PARSED config back, so a schema default would be baked into
647
+ * every owner's file — and an older daemon, which is exactly what a
648
+ * rollback installs, refuses a key its strict schema has never seen.
649
+ *
650
+ * Every other paired origin's offer is ignored and said once. The
651
+ * authority's own offers count only over a pairing that pinned a control
652
+ * plane; a direct-mode pairing never updates the daemon.
653
+ */
654
+ updateAuthority: z.string().refine(
655
+ (value) => {
656
+ try {
657
+ normalizeOrigin(value);
658
+ return true;
659
+ } catch {
660
+ return false;
661
+ }
662
+ },
663
+ {
664
+ message: "an origin byollm can reach, the way `byollm connect` takes one (https://hub.byollm.cloud)"
665
+ }
666
+ ).optional(),
621
667
  /**
622
668
  * The memory floor this device refuses model work below — B090.
623
669
  *
@@ -746,7 +792,7 @@ function resolveConfig(config) {
746
792
  }
747
793
  for (const [name, service] of Object.entries(config.services)) {
748
794
  const where = `services.${name}`;
749
- const descriptor = backendDescriptor(service.type);
795
+ const descriptor = backendDescriptor2(service.type);
750
796
  const baseUrl = service.baseUrl ?? descriptor.defaultBaseUrl;
751
797
  if (descriptor.class === "http") {
752
798
  if (baseUrl === void 0) {
@@ -1058,7 +1104,7 @@ function serviceLine(input) {
1058
1104
  }
1059
1105
  case "unstartable":
1060
1106
  return {
1061
- line: `${service} \u2014 ${state.model}, not running, and ${device} cannot start it for you: start it yourself, then it will be offered`
1107
+ line: `${service} \u2014 ${state.model}, not running, and ${device} cannot start it for you: start it yourself, then it will be offered` + (state.startableAs === void 0 ? "" : ` \u2014 or set "type": "${state.startableAs}" on it in ~/.byollm/config.json and byollm will start it for you`)
1062
1108
  };
1063
1109
  case "blocked": {
1064
1110
  const when = state.until === void 0 ? "it needs time, not a fix" : `back around ${clockTime(state.until)}`;
@@ -1152,37 +1198,58 @@ ${plan.say}
1152
1198
  }
1153
1199
 
1154
1200
  // src/update.ts
1201
+ import { compareVersions } from "@byollm/protocol";
1155
1202
  function exactVersion(value) {
1156
1203
  return /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(value) ? value : void 0;
1157
1204
  }
1158
1205
  async function update(from, to, deps) {
1159
1206
  const target = exactVersion(to);
1160
1207
  if (target === void 0) {
1161
- const why2 = `refusing to install "${to}" \u2014 the updater installs exact versions only`;
1162
- deps.report(why2);
1163
- return { kind: "refused", why: why2 };
1208
+ const why = `refusing to install "${to}" \u2014 the updater installs exact versions only`;
1209
+ deps.report(why);
1210
+ return { kind: "refused", why };
1164
1211
  }
1165
- if (target === from) {
1212
+ if (exactVersion(from) === void 0) {
1213
+ const why = `refusing to update from "${from}" \u2014 no version to roll back to`;
1214
+ deps.report(why);
1215
+ return { kind: "refused", why };
1216
+ }
1217
+ const order = compareVersions(target, from);
1218
+ if (order === 0) {
1166
1219
  return { kind: "refused", why: `already on ${from}` };
1167
1220
  }
1168
- if (exactVersion(from) === void 0) {
1169
- const why2 = `refusing to update from "${from}" \u2014 no version to roll back to`;
1170
- deps.report(why2);
1171
- return { kind: "refused", why: why2 };
1221
+ if (order === void 0 || order < 0) {
1222
+ const why = order === void 0 ? `refusing to install ${target} \u2014 cannot tell whether it is newer than ${from}` : `refusing to install ${target} \u2014 it is older than ${from}, and the updater never downgrades`;
1223
+ deps.report(why);
1224
+ return { kind: "refused", why };
1172
1225
  }
1173
1226
  await deps.drain();
1174
1227
  if (!await deps.install(target)) {
1175
1228
  await deps.reregister();
1176
- const why2 = `could not install ${target} \u2014 staying on ${from}`;
1177
- deps.report(why2);
1178
- return { kind: "refused", why: why2 };
1229
+ const why = `could not install ${target} \u2014 staying on ${from}`;
1230
+ deps.report(why);
1231
+ return { kind: "refused", why };
1232
+ }
1233
+ const proof = await deps.verify(target);
1234
+ if (!proof.verified) {
1235
+ return rollBack(
1236
+ from,
1237
+ `${target} failed its provenance check: ${proof.why}`,
1238
+ deps
1239
+ );
1179
1240
  }
1180
1241
  await deps.reregister();
1181
1242
  const reported = await deps.installedVersion();
1182
1243
  if (reported === target) {
1183
1244
  return { kind: "updated", to: target };
1184
1245
  }
1185
- const why = reported === void 0 ? `${target} did not answer after installing` : `installed ${target} but the binary reports ${reported}`;
1246
+ return rollBack(
1247
+ from,
1248
+ reported === void 0 ? `${target} did not answer after installing` : `installed ${target} but the binary reports ${reported}`,
1249
+ deps
1250
+ );
1251
+ }
1252
+ async function rollBack(from, why, deps) {
1186
1253
  if (!await deps.install(from)) {
1187
1254
  const stranded = `${why}; rolling back to ${from} also failed`;
1188
1255
  deps.report(stranded);
@@ -1198,6 +1265,115 @@ async function update(from, to, deps) {
1198
1265
  deps.report(`${why}; rolled back to ${from}`);
1199
1266
  return { kind: "rolled-back", to: from, why };
1200
1267
  }
1268
+ function offerInbox(input) {
1269
+ let offered;
1270
+ const refused = /* @__PURE__ */ new Set();
1271
+ return {
1272
+ receive: (origin, version) => {
1273
+ const why = origin !== input.authority ? `updates are taken only from ${input.authority}` : input.hasControlPlane(origin) ? void 0 : "it is a direct-mode pairing, and those never update this daemon";
1274
+ if (why === void 0) {
1275
+ offered = version;
1276
+ return;
1277
+ }
1278
+ if (refused.has(origin)) return;
1279
+ refused.add(origin);
1280
+ input.report(`ignoring an offer of ${version} from ${origin} \u2014 ${why}`);
1281
+ },
1282
+ current: () => offered
1283
+ };
1284
+ }
1285
+
1286
+ // src/provenance.ts
1287
+ var NPM_REGISTRY = "https://registry.npmjs.org";
1288
+ var RELEASE_REPOSITORY = "https://github.com/oftomorrowinc/byollm";
1289
+ var SLSA_V1 = "https://slsa.dev/provenance/v1";
1290
+ async function verifyProvenance(version, options = {}) {
1291
+ const get = options.fetch ?? ((url) => fetch(url));
1292
+ const registry = options.registry ?? NPM_REGISTRY;
1293
+ const no = (why) => ({ verified: false, why });
1294
+ const integrity = await readJson(get, `${registry}/byollm/${version}`);
1295
+ if (!integrity.ok)
1296
+ return no(`could not read the registry entry: ${integrity.why}`);
1297
+ const expected = sha512Hex(
1298
+ integrity.body?.dist?.integrity
1299
+ );
1300
+ if (expected === void 0) {
1301
+ return no("the registry entry has no sha512 integrity to check against");
1302
+ }
1303
+ const listed = await readJson(
1304
+ get,
1305
+ `${registry}/-/npm/v1/attestations/byollm@${version}`
1306
+ );
1307
+ if (!listed.ok) return no(`could not read the attestations: ${listed.why}`);
1308
+ const attestations = listed.body?.attestations;
1309
+ if (!Array.isArray(attestations))
1310
+ return no("the registry lists no attestations");
1311
+ const slsa = attestations.filter(
1312
+ (entry) => entry?.predicateType === SLSA_V1
1313
+ );
1314
+ if (slsa.length === 0) return no("there is no SLSA provenance for it");
1315
+ for (const entry of slsa) {
1316
+ const statement = decodeStatement(entry);
1317
+ if (statement === void 0) return no("its provenance could not be read");
1318
+ const why = checkStatement(statement, version, expected);
1319
+ if (why !== void 0) return no(why);
1320
+ }
1321
+ return { verified: true };
1322
+ }
1323
+ function checkStatement(statement, version, expected) {
1324
+ const workflow = statement.predicate?.buildDefinition?.externalParameters?.workflow;
1325
+ if (workflow?.repository !== RELEASE_REPOSITORY) {
1326
+ return `it was built by ${named(workflow?.repository)}, not ${RELEASE_REPOSITORY}`;
1327
+ }
1328
+ if (workflow.ref !== `refs/tags/v${version}`) {
1329
+ return `it was built from ${named(workflow.ref)}, not refs/tags/v${version}`;
1330
+ }
1331
+ const subjects = Array.isArray(
1332
+ statement.subject
1333
+ ) ? statement.subject : [];
1334
+ const ours = subjects.find((s) => s.name === `pkg:npm/byollm@${version}`);
1335
+ if (ours === void 0)
1336
+ return `its provenance does not name byollm@${version}`;
1337
+ if (ours.digest?.sha512 !== expected) {
1338
+ return "its provenance names a different tarball than the one npm installed";
1339
+ }
1340
+ return void 0;
1341
+ }
1342
+ async function readJson(get, url) {
1343
+ try {
1344
+ const response = await get(url);
1345
+ if (!response.ok)
1346
+ return { ok: false, why: `HTTP ${String(response.status)}` };
1347
+ return { ok: true, body: await response.json() };
1348
+ } catch (error) {
1349
+ return {
1350
+ ok: false,
1351
+ why: error instanceof Error ? error.message : "unknown error"
1352
+ };
1353
+ }
1354
+ }
1355
+ function decodeStatement(entry) {
1356
+ const payload = entry?.bundle?.dsseEnvelope?.payload;
1357
+ if (typeof payload !== "string") return void 0;
1358
+ try {
1359
+ const parsed = JSON.parse(
1360
+ Buffer.from(payload, "base64").toString("utf8")
1361
+ );
1362
+ return typeof parsed === "object" && parsed !== null ? parsed : void 0;
1363
+ } catch {
1364
+ return void 0;
1365
+ }
1366
+ }
1367
+ function sha512Hex(integrity) {
1368
+ if (typeof integrity !== "string") return void 0;
1369
+ const match = /^sha512-([A-Za-z0-9+/]+={0,2})$/.exec(integrity.trim());
1370
+ if (match?.[1] === void 0) return void 0;
1371
+ const bytes2 = Buffer.from(match[1], "base64");
1372
+ return bytes2.length === 64 ? bytes2.toString("hex") : void 0;
1373
+ }
1374
+ function named(value) {
1375
+ return typeof value === "string" ? value : "an unnamed workflow";
1376
+ }
1201
1377
 
1202
1378
  // src/update-deps.ts
1203
1379
  function realUpdateDeps(input) {
@@ -1209,6 +1385,8 @@ function realUpdateDeps(input) {
1209
1385
  "npm",
1210
1386
  "install",
1211
1387
  "--global",
1388
+ "--ignore-scripts",
1389
+ `--registry=${NPM_REGISTRY}`,
1212
1390
  `byollm@${version}`
1213
1391
  ]);
1214
1392
  if (result.code !== 0) {
@@ -1218,6 +1396,7 @@ function realUpdateDeps(input) {
1218
1396
  }
1219
1397
  return result.code === 0;
1220
1398
  },
1399
+ verify: input.verify ?? ((version) => verifyProvenance(version)),
1221
1400
  reregister: async () => (await input.run([binary, "start"])).code === 0,
1222
1401
  installedVersion: async () => {
1223
1402
  const result = await input.run([binary, "--version"]);
@@ -1232,7 +1411,7 @@ function realUpdateDeps(input) {
1232
1411
  }
1233
1412
 
1234
1413
  // src/backends/index.ts
1235
- import { backendDescriptor as backendDescriptor2 } from "@byollm/protocol";
1414
+ import { backendDescriptor as backendDescriptor3 } from "@byollm/protocol";
1236
1415
 
1237
1416
  // src/backends/claude-cli.ts
1238
1417
  import { execFile as execFile2 } from "child_process";
@@ -1548,6 +1727,7 @@ var FIXED_ARGV = Object.freeze([
1548
1727
  "--strict-mcp-config",
1549
1728
  "--mcp-config",
1550
1729
  '{"mcpServers":{}}',
1730
+ "--restricted",
1551
1731
  "--no-session-persistence"
1552
1732
  ]);
1553
1733
  var ENV_ALLOWLIST = Object.freeze([
@@ -2228,7 +2408,7 @@ function stopReasonOf(result) {
2228
2408
 
2229
2409
  // src/backends/index.ts
2230
2410
  function createBackend(id, init) {
2231
- const kind = backendDescriptor2(id).class;
2411
+ const kind = backendDescriptor3(id).class;
2232
2412
  switch (kind) {
2233
2413
  // Process class dispatches by **id**, not by class, and the difference is
2234
2414
  // not stylistic. `case "process": return new ClaudeCliBackend()` was
@@ -2346,7 +2526,7 @@ var CLAUDE_ALIASES = [
2346
2526
  { id: "sonnet", note: "balanced" },
2347
2527
  { id: "fable", note: "fastest" }
2348
2528
  ];
2349
- async function readJson(path) {
2529
+ async function readJson2(path) {
2350
2530
  try {
2351
2531
  return JSON.parse(await readFile6(path, "utf8"));
2352
2532
  } catch {
@@ -2371,7 +2551,7 @@ function codexSuggestions(cache) {
2371
2551
  }));
2372
2552
  }
2373
2553
  async function claudeSuggestions(home) {
2374
- const settings = await readJson(join3(home, ".claude", "settings.json"));
2554
+ const settings = await readJson2(join3(home, ".claude", "settings.json"));
2375
2555
  const configured = typeof settings === "object" && settings !== null ? settings.model : void 0;
2376
2556
  const out = [];
2377
2557
  if (typeof configured === "string" && configured !== "") {
@@ -2388,7 +2568,7 @@ async function claudeSuggestions(home) {
2388
2568
  async function modelSuggestions(cli, home = homedir()) {
2389
2569
  if (cli === "codex-cli") {
2390
2570
  return codexSuggestions(
2391
- await readJson(join3(home, ".codex", "models_cache.json"))
2571
+ await readJson2(join3(home, ".codex", "models_cache.json"))
2392
2572
  );
2393
2573
  }
2394
2574
  if (cli === "claude-cli") return claudeSuggestions(home);
@@ -3076,14 +3256,14 @@ async function candidates(input) {
3076
3256
  let model = cli.model;
3077
3257
  let namedByOwner = false;
3078
3258
  if (model === void 0) {
3079
- const named = await modelByHand({
3259
+ const named2 = await modelByHand({
3080
3260
  cli,
3081
3261
  io: input.io,
3082
3262
  verifier: input.verifier,
3083
3263
  ...input.suggest === void 0 ? {} : { suggest: input.suggest }
3084
3264
  });
3085
- if (named === void 0) continue;
3086
- model = named;
3265
+ if (named2 === void 0) continue;
3266
+ model = named2;
3087
3267
  namedByOwner = true;
3088
3268
  }
3089
3269
  const proof = await input.verifier(cli.id, model);
@@ -4059,11 +4239,7 @@ var TEST_YOUR_DEVICE = "TEST YOUR DEVICE: Visit https://test.byollm.cloud and pr
4059
4239
  // src/diagnose.ts
4060
4240
  import { execFile as execFile4 } from "child_process";
4061
4241
  import { promisify as promisify2 } from "util";
4062
- import {
4063
- BACKEND_IDS,
4064
- backendDescriptor as backendDescriptor3,
4065
- backendName as backendName2
4066
- } from "@byollm/protocol";
4242
+ import { backendName as backendName2 } from "@byollm/protocol";
4067
4243
  var run = promisify2(execFile4);
4068
4244
  var BY_PORT = {
4069
4245
  "11434": {
@@ -4118,18 +4294,6 @@ var whichProbe = async (binary) => {
4118
4294
  return code === 1 || code === "ENOENT" ? false : void 0;
4119
4295
  }
4120
4296
  };
4121
- function startableAt(origin) {
4122
- for (const id of BACKEND_IDS) {
4123
- if (startCommandFor(id) === void 0) continue;
4124
- const address = backendDescriptor3(id).defaultBaseUrl;
4125
- if (address === void 0) continue;
4126
- try {
4127
- if (new URL(address).origin === origin) return id;
4128
- } catch {
4129
- }
4130
- }
4131
- return void 0;
4132
- }
4133
4297
  async function diagnoseRoute(input) {
4134
4298
  const onPath = input.onPath ?? whichProbe;
4135
4299
  const reach = input.reach ?? fetchProbe;
@@ -4813,7 +4977,7 @@ function isNotFound2(error) {
4813
4977
  }
4814
4978
 
4815
4979
  // src/console-agent.ts
4816
- import { Buffer } from "buffer";
4980
+ import { Buffer as Buffer2 } from "buffer";
4817
4981
  import {
4818
4982
  ConsoleFrame,
4819
4983
  CONSOLE_FRAME_VERSION,
@@ -4973,7 +5137,7 @@ function consoleSession(deps) {
4973
5137
  case "stdin":
4974
5138
  if (!started) return;
4975
5139
  fromBrowser += 1;
4976
- deps.shell.write(Buffer.from(consoleDataBytes(frame.data)));
5140
+ deps.shell.write(Buffer2.from(consoleDataBytes(frame.data)));
4977
5141
  return;
4978
5142
  case "resize":
4979
5143
  if (!started) return;
@@ -4992,7 +5156,7 @@ function consoleSession(deps) {
4992
5156
  }
4993
5157
 
4994
5158
  // src/pty-shell.ts
4995
- import { Buffer as Buffer2 } from "buffer";
5159
+ import { Buffer as Buffer3 } from "buffer";
4996
5160
  var NO_PTY_MESSAGE = "byollm console-agent needs node-pty, which is a hosted-box feature and is not installed here.\nIf you are self-hosting a box, install it beside byollm: npm i -g node-pty";
4997
5161
  var NoPtyError = class extends Error {
4998
5162
  constructor() {
@@ -5032,7 +5196,7 @@ async function openPtyShell(options) {
5032
5196
  let exited;
5033
5197
  let announce;
5034
5198
  child.onData((data) => {
5035
- const chunk = Buffer2.from(data, "utf8");
5199
+ const chunk = Buffer3.from(data, "utf8");
5036
5200
  if (deliver !== void 0) {
5037
5201
  deliver(chunk);
5038
5202
  return;
@@ -6282,10 +6446,12 @@ var Runner = class {
6282
6446
  usable = health.healthy && (health.models.length === 0 || modelPresent(health.models, route.model));
6283
6447
  const remedy = backend.signIn === void 0 ? {} : { signIn: backend.signIn };
6284
6448
  if (!health.healthy) {
6449
+ const baseUrl = this.#options.loaded.config.services[route.service]?.baseUrl;
6450
+ const onPath = this.#options.onPath === void 0 ? {} : { onPath: this.#options.onPath };
6285
6451
  const startable = await startability({
6286
6452
  id: route.backendId,
6287
- baseUrl: this.#options.loaded.config.services[route.service]?.baseUrl,
6288
- ...this.#options.onPath === void 0 ? {} : { onPath: this.#options.onPath }
6453
+ baseUrl,
6454
+ ...onPath
6289
6455
  });
6290
6456
  const starts = this.#options.spawnServer !== void 0;
6291
6457
  usable = startable.startable && starts;
@@ -6302,7 +6468,11 @@ var Runner = class {
6302
6468
  * Only `not-installed` is `missing`. The advertising decision is
6303
6469
  * unchanged: nothing here is offered either way.
6304
6470
  */
6305
- state: startable.startable ? { kind: "stopped", model: route.model, starts } : startable.why === "not-installed" ? { kind: "missing" } : { kind: "unstartable", model: route.model },
6471
+ state: startable.startable ? { kind: "stopped", model: route.model, starts } : startable.why === "not-installed" ? { kind: "missing" } : {
6472
+ kind: "unstartable",
6473
+ model: route.model,
6474
+ ...await this.#startableAs(route.backendId, baseUrl)
6475
+ },
6306
6476
  ...remedy
6307
6477
  });
6308
6478
  } else if (options.canary !== true || backend.canary === void 0) {
@@ -6697,6 +6867,33 @@ var Runner = class {
6697
6867
  * too, and none of them should be able to start a model server as a side
6698
6868
  * effect of asking a question.
6699
6869
  */
6870
+ /**
6871
+ * The type that WOULD be started at this address, for the owner's line —
6872
+ * B098's offer, reaching `byollm status`.
6873
+ *
6874
+ * Asks `startableAt`, the one function `byollm diagnose` asks, and then
6875
+ * asks `startability` of THAT type at this address — so the offer is made
6876
+ * only where taking it would actually work: loopback, a start command, and
6877
+ * the binary on PATH. Retyping a service into one that then reads "not
6878
+ * found" is a remedy that moves the problem rather than fixing it.
6879
+ */
6880
+ async #startableAs(configured, baseUrl) {
6881
+ if (baseUrl === void 0 || !isLoopback(baseUrl)) return {};
6882
+ let origin;
6883
+ try {
6884
+ origin = new URL(baseUrl).origin;
6885
+ } catch {
6886
+ return {};
6887
+ }
6888
+ const id = startableAt(origin);
6889
+ if (id === void 0 || id === configured) return {};
6890
+ const would = await startability({
6891
+ id,
6892
+ baseUrl,
6893
+ ...this.#options.onPath === void 0 ? {} : { onPath: this.#options.onPath }
6894
+ });
6895
+ return would.startable ? { startableAs: id } : {};
6896
+ }
6700
6897
  /**
6701
6898
  * Should this machine take a job that loads a model right now — B080.
6702
6899
  *
@@ -7550,11 +7747,14 @@ var Runner = class {
7550
7747
  jobId: job.id,
7551
7748
  senderKeyId: keyId2(publicIdentityOf2(keys).identity),
7552
7749
  recipientKeyId: keyId2(this.#pinFor(job).identity),
7553
- // This runner's clock, not the process's — cloud_008 §31. The only
7554
- // `Date.now()` left in this class, in the one place that stamps a
7555
- // deadline somebody else enforces: a test that moves time moved every
7556
- // other clock here and not this one, so a sealed result carried an
7557
- // expiry from a different timeline than the lease it answered.
7750
+ // This runner's clock, not the process's — cloud_008 §31. This was a
7751
+ // `Date.now()`, in the one place that stamps a deadline somebody else
7752
+ // enforces: a test that moves time moved every other clock here and
7753
+ // not this one, so a sealed result carried an expiry from a different
7754
+ // timeline than the lease it answered. The retirement window had the
7755
+ // same two clocks until it was found the same way; `drain` is the one
7756
+ // read left on the process clock, because it waits out real time
7757
+ // beside a real sleep.
7558
7758
  deadlineAt: this.#now() + ENVELOPE_MAX_AGE_MS,
7559
7759
  direction: "result"
7560
7760
  }
@@ -7861,7 +8061,7 @@ var Runner = class {
7861
8061
  for (const id of [...this.#sites.keys()]) {
7862
8062
  if (id in sites) continue;
7863
8063
  const until2 = this.#retiring.get(id);
7864
- if (until2 !== void 0 && Date.now() < until2) continue;
8064
+ if (until2 !== void 0 && this.#now() < until2) continue;
7865
8065
  this.#retiring.delete(id);
7866
8066
  this.#sites.delete(id);
7867
8067
  for (const [leaseId, held] of this.#active) {
@@ -7943,7 +8143,7 @@ var Runner = class {
7943
8143
  if (!previous) return false;
7944
8144
  this.#known.set(id, site);
7945
8145
  this.#sites.set(id, site);
7946
- const ceiling = Date.now() + RETIREMENT_WINDOW_MS;
8146
+ const ceiling = this.#now() + RETIREMENT_WINDOW_MS;
7947
8147
  const proposed = offered.retiringUntil ?? ceiling;
7948
8148
  this.#retiring.set(walk.from, Math.min(proposed, ceiling));
7949
8149
  this.#options.onEvent?.({
@@ -8615,6 +8815,7 @@ async function writeUnit(path, contents, encoding) {
8615
8815
 
8616
8816
  // src/service-states.ts
8617
8817
  import { readFile as readFile13, writeFile as writeFile8 } from "fs/promises";
8818
+ import { BackendIdSchema as BackendIdSchema2 } from "@byollm/protocol";
8618
8819
  import { z as z8 } from "zod";
8619
8820
  var Stored = z8.record(
8620
8821
  z8.string(),
@@ -8628,7 +8829,13 @@ var Stored = z8.record(
8628
8829
  z8.object({ kind: z8.literal("missing") }),
8629
8830
  /* B098. Stopped and unstartable is not the same as absent, and the
8630
8831
  file `byollm status` reads has to be able to tell them apart. */
8631
- z8.object({ kind: z8.literal("unstartable"), model: z8.string() }),
8832
+ z8.object({
8833
+ kind: z8.literal("unstartable"),
8834
+ model: z8.string(),
8835
+ /* An id this build does not know degrades to no offer, rather than
8836
+ failing the whole file and blanking every service's line. */
8837
+ startableAs: BackendIdSchema2.optional().catch(void 0)
8838
+ }),
8632
8839
  /**
8633
8840
  * Installed here, not running, and startable — B056.
8634
8841
  *
@@ -8975,18 +9182,18 @@ function consoleSpecArg(args) {
8975
9182
  var UNRESTRICTED = "--unrestricted-shell";
8976
9183
  function consoleShellChoice(args) {
8977
9184
  const at = args.indexOf("--shell");
8978
- const named = at === -1 ? void 0 : args[at + 1];
9185
+ const named2 = at === -1 ? void 0 : args[at + 1];
8979
9186
  const escaped = args.includes(UNRESTRICTED);
8980
- if (at !== -1 && (named === void 0 || named.startsWith("--"))) {
9187
+ if (at !== -1 && (named2 === void 0 || named2.startsWith("--"))) {
8981
9188
  return { ok: false, why: "`--shell` needs a path to the shell to run." };
8982
9189
  }
8983
- if (named !== void 0 && escaped) {
9190
+ if (named2 !== void 0 && escaped) {
8984
9191
  return {
8985
9192
  ok: false,
8986
9193
  why: `\`--shell\` and \`${UNRESTRICTED}\` disagree about what to run.`
8987
9194
  };
8988
9195
  }
8989
- if (named !== void 0) return { ok: true, command: named, fenced: true };
9196
+ if (named2 !== void 0) return { ok: true, command: named2, fenced: true };
8990
9197
  if (escaped) return { ok: true, command: "/bin/sh", fenced: false };
8991
9198
  return {
8992
9199
  ok: false,
@@ -9120,9 +9327,9 @@ async function commandConsoleAgent(paths, args, io) {
9120
9327
  }
9121
9328
  var DEFAULT_ORIGIN = "https://hub.byollm.cloud";
9122
9329
  function connectTarget(args) {
9123
- const named = args.indexOf("--name");
9330
+ const named2 = args.indexOf("--name");
9124
9331
  const positional = args.filter(
9125
- (arg, at) => !arg.startsWith("-") && (named === -1 || at !== named && at !== named + 1)
9332
+ (arg, at) => !arg.startsWith("-") && (named2 === -1 || at !== named2 && at !== named2 + 1)
9126
9333
  );
9127
9334
  return positional[0] ?? DEFAULT_ORIGIN;
9128
9335
  }
@@ -9191,10 +9398,14 @@ async function commandModel(paths, args, io) {
9191
9398
  const shown = await showModel(paths.config, service, io);
9192
9399
  return shown.code;
9193
9400
  }
9401
+ const loaded = await loadConfig(paths.config).catch(() => void 0);
9402
+ const configured = loaded?.config.services[service];
9194
9403
  const set = await setModel(
9195
9404
  { configPath: paths.config, service, model },
9196
9405
  io,
9197
- backendVerifier((id) => createBackend(id, {})),
9406
+ backendVerifier(
9407
+ (id) => backendFor({ type: id, baseUrl: configured?.baseUrl })
9408
+ ),
9198
9409
  /**
9199
9410
  * The memory guard on the owner's own command — B106.
9200
9411
  *
@@ -9206,12 +9417,11 @@ async function commandModel(paths, args, io) {
9206
9417
  * job — `minAvailableMemoryBytes`, one value, one meaning, whoever asked.
9207
9418
  */
9208
9419
  async (backendId) => {
9209
- const loaded = await loadConfig(paths.config).catch(() => void 0);
9210
9420
  if (loaded === void 0) return { ask: false };
9211
9421
  const { memory, pressure } = await readHostMemory();
9212
9422
  return modelLoadQuestion({
9213
9423
  backendId,
9214
- baseUrl: loaded.config.services[service]?.baseUrl,
9424
+ baseUrl: configured?.baseUrl,
9215
9425
  model,
9216
9426
  memory,
9217
9427
  pressure,
@@ -9223,9 +9433,9 @@ async function commandModel(paths, args, io) {
9223
9433
  return set.code;
9224
9434
  }
9225
9435
  async function commandConnect(paths, args, io, signal) {
9226
- const named = args.indexOf("--name");
9227
- const name = named === -1 ? void 0 : args[named + 1];
9228
- if (named !== -1 && (name === void 0 || name.startsWith("-"))) {
9436
+ const named2 = args.indexOf("--name");
9437
+ const name = named2 === -1 ? void 0 : args[named2 + 1];
9438
+ if (named2 !== -1 && (name === void 0 || name.startsWith("-"))) {
9229
9439
  io.err("usage: byollm connect [<url>] [--name <name>]\n");
9230
9440
  return 2;
9231
9441
  }
@@ -9563,7 +9773,16 @@ async function runLoop(paths, origins, io, signal, supervised = !process.stdout.
9563
9773
  );
9564
9774
  if (signal?.aborted === true) controller.abort();
9565
9775
  const runners = [];
9566
- let offered;
9776
+ const inbox = loaded.config.autoUpdate ? offerInbox({
9777
+ authority: normalizeOrigin(
9778
+ loaded.config.updateAuthority ?? DEFAULT_ORIGIN
9779
+ ),
9780
+ hasControlPlane: (origin) => pairings.get(origin)?.controlPlanePublic !== void 0,
9781
+ report: (line) => {
9782
+ io.err(`update: ${line}
9783
+ `);
9784
+ }
9785
+ }) : void 0;
9567
9786
  for (const origin of origins) {
9568
9787
  const pairing = pairings.get(origin);
9569
9788
  if (!pairing) {
@@ -9662,7 +9881,8 @@ async function runLoop(paths, origins, io, signal, supervised = !process.stdout.
9662
9881
  },
9663
9882
  onEvent: (event) => {
9664
9883
  report(origin, event, io);
9665
- if (event.type === "update-offered") offered = event.version;
9884
+ if (event.type === "update-offered")
9885
+ inbox?.receive(origin, event.version);
9666
9886
  if (event.type === "heartbeat") {
9667
9887
  void recordSites(pairings, origin, runner.sites, {
9668
9888
  known: runner.known
@@ -9717,11 +9937,11 @@ Which sites may send work is enabled from your dashboard. Ctrl-C to stop.
9717
9937
  `
9718
9938
  );
9719
9939
  await ingress.applyRetention(Date.now());
9720
- const updated = loaded.config.autoUpdate ? watchForUpdate({
9940
+ const updated = inbox ? watchForUpdate({
9721
9941
  runners,
9722
9942
  io,
9723
9943
  signal: controller.signal,
9724
- offered: () => offered
9944
+ offered: inbox.current
9725
9945
  }) : new Promise(() => void 0);
9726
9946
  const tookUpdate = await Promise.race([
9727
9947
  Promise.all(runners.map((runner) => runner.run(controller.signal))).then(
@@ -9747,6 +9967,7 @@ async function watchForUpdate(input) {
9747
9967
  const outcome = await update(DAEMON_VERSION, version, {
9748
9968
  ...realUpdateDeps({
9749
9969
  run: input.run ?? spawnCommand,
9970
+ ...input.verify === void 0 ? {} : { verify: input.verify },
9750
9971
  drain: async () => {
9751
9972
  await Promise.all(
9752
9973
  input.runners.map(
@@ -9910,7 +10131,7 @@ function describeAge(ms) {
9910
10131
  return seconds < 120 ? `${String(seconds)} seconds` : `${String(Math.round(seconds / 60))} minutes`;
9911
10132
  }
9912
10133
  async function commandStatus(paths, io, service) {
9913
- const { loaded, ingress, budgets, spend, spentGrants } = await context(paths);
10134
+ const { loaded, configured, ingress, budgets, spend, spentGrants } = await context(paths);
9914
10135
  const pairings = new Pairings(paths.pairings);
9915
10136
  await pairings.load();
9916
10137
  reportSkipped(pairings, io);
@@ -9931,10 +10152,17 @@ async function commandStatus(paths, io, service) {
9931
10152
  const plan = servicePlan(serviceTarget(paths, service));
9932
10153
  const supervision = await serviceState(plan, service.run);
9933
10154
  const revoked = await revokedMark(paths.health);
10155
+ const notSetUp = !configured && beat === void 0;
9934
10156
  io.out(
9935
- `state: ${revoked !== void 0 ? "REVOKED" : supervision.state === "installed" || stale ? "NOT RUNNING" : failing ? "NOT REPORTING" : "running"}
10157
+ `state: ${revoked !== void 0 ? "REVOKED" : supervision.state === "installed" || stale ? "NOT RUNNING" : failing ? "NOT REPORTING" : notSetUp ? "NOT SET UP" : "running"}
9936
10158
  `
9937
10159
  );
10160
+ if (revoked === void 0 && !stale && !failing && notSetUp) {
10161
+ io.out(
10162
+ ` no config at ${paths.config}, and nothing has run here yet.
10163
+ ${NOT_SET_UP_HINT}`
10164
+ );
10165
+ }
9938
10166
  if (revoked !== void 0) {
9939
10167
  io.out(
9940
10168
  ` ${REVOKED_SENTENCE}.
@@ -10000,8 +10228,10 @@ async function commandStatus(paths, io, service) {
10000
10228
  io.out("\nservices\n");
10001
10229
  const recorded = await readServiceStates(paths.serviceStates);
10002
10230
  const deviceName = await labelFor(paths, void 0);
10003
- const declared = Object.entries(loaded.config.services);
10004
- if (declared.length === 0) {
10231
+ const declared = configured ? Object.entries(loaded.config.services) : [];
10232
+ if (!configured) {
10233
+ io.out(" (none \u2014 run `byollm setup`)\n");
10234
+ } else if (declared.length === 0) {
10005
10235
  io.out(" (none configured)\n");
10006
10236
  }
10007
10237
  for (const [name, service2] of declared) {
@@ -10506,7 +10736,16 @@ ${summarise(outcome).join("\n")}
10506
10736
  return signal?.aborted === true ? 1 : 0;
10507
10737
  }
10508
10738
  async function commandServices(paths, io, service) {
10509
- const { loaded, ingress, budgets, spend, spentGrants } = await context(paths);
10739
+ const { loaded, configured, ingress, budgets, spend, spentGrants } = await context(paths);
10740
+ if (!configured) {
10741
+ io.out(
10742
+ `services
10743
+ (none \u2014 no config at ${paths.config})
10744
+
10745
+ ` + NOT_SET_UP_HINT
10746
+ );
10747
+ return 1;
10748
+ }
10510
10749
  const pairings = new Pairings(paths.pairings);
10511
10750
  await pairings.load();
10512
10751
  const hasRelay = pairings.list().some((pairing) => pairing.controlPlanePublic !== void 0);
@@ -10602,6 +10841,10 @@ with the device's page, and after installing a new CLI run
10602
10841
  }
10603
10842
  async function context(paths) {
10604
10843
  const loaded = await loadConfig(paths.config);
10844
+ const configured = await access(paths.config).then(
10845
+ () => true,
10846
+ () => false
10847
+ );
10605
10848
  const ingress = new IngressLog({
10606
10849
  path: paths.ingressLog,
10607
10850
  communityPromptDays: loaded.config.ingress.communityPromptDays,
@@ -10613,8 +10856,9 @@ async function context(paths) {
10613
10856
  const spentGrants = new SpentGrants(paths.spentGrants);
10614
10857
  spentGrants.load(Date.now());
10615
10858
  await spend.load(Date.now());
10616
- return { loaded, ingress, budgets, spend, spentGrants };
10859
+ return { loaded, configured, ingress, budgets, spend, spentGrants };
10617
10860
  }
10861
+ var NOT_SET_UP_HINT = "Run `byollm setup` to find what this computer already has.\n";
10618
10862
  async function confirmInteractively(question) {
10619
10863
  if (!process.stdin.isTTY) {
10620
10864
  process.stderr.write(
@@ -10680,7 +10924,7 @@ async function exists(path) {
10680
10924
  }
10681
10925
 
10682
10926
  // src/index.ts
10683
- var DAEMON_VERSION = "0.1.1";
10927
+ var DAEMON_VERSION = "0.1.3";
10684
10928
  function daemonVersion() {
10685
10929
  return {
10686
10930
  daemon: DAEMON_VERSION,
@@ -10697,6 +10941,8 @@ ${v.platform}-${v.arch}, node ${v.node}
10697
10941
  }
10698
10942
 
10699
10943
  export {
10944
+ UnusableOrigin,
10945
+ normalizeOrigin,
10700
10946
  checkBaseUrl,
10701
10947
  BASE_URL_REFUSAL_MESSAGES,
10702
10948
  DaemonConfig,
@@ -10710,8 +10956,6 @@ export {
10710
10956
  createBackend,
10711
10957
  SpendLedger,
10712
10958
  estimateCents,
10713
- UnusableOrigin,
10714
- normalizeOrigin,
10715
10959
  Budgets,
10716
10960
  ClientError,
10717
10961
  ProtocolClient,
@@ -10739,4 +10983,4 @@ export {
10739
10983
  runCli,
10740
10984
  main
10741
10985
  };
10742
- //# sourceMappingURL=chunk-OOC3ASS6.js.map
10986
+ //# sourceMappingURL=chunk-PXL5HY2O.js.map