usebeeline 0.1.201 → 0.1.202-rc.2

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 (2) hide show
  1. package/dist/usebeeline.mjs +118 -98
  2. package/package.json +1 -1
@@ -1164,8 +1164,6 @@ var init_self_update = __esm({
1164
1164
  var managed_update_exports = {};
1165
1165
  __export(managed_update_exports, {
1166
1166
  ReleaseTransaction: () => ReleaseTransaction,
1167
- UPDATE_CONVERGENCE_SLO_MS: () => UPDATE_CONVERGENCE_SLO_MS,
1168
- UPDATE_DRAIN_DEADLINE_MS: () => UPDATE_DRAIN_DEADLINE_MS,
1169
1167
  prepareReleaseInWorker: () => prepareReleaseInWorker,
1170
1168
  runManagedUpdateWorker: () => runManagedUpdateWorker,
1171
1169
  versionAtLeast: () => versionAtLeast,
@@ -1197,7 +1195,7 @@ async function runManagedUpdateWorker() {
1197
1195
  logger: (line) => console.error(line)
1198
1196
  }));
1199
1197
  }
1200
- async function prepareReleaseInWorker(env, deadlineAt, entrypoint) {
1198
+ async function prepareReleaseInWorker(env, deadlineAt, entrypoint, signal) {
1201
1199
  const layout = beelineInstallLayout(env);
1202
1200
  const bootstrap = entrypoint ?? resolve8(layout.libDir, "../beeline-bootstrap.mjs");
1203
1201
  return new Promise((done, reject) => {
@@ -1211,6 +1209,20 @@ async function prepareReleaseInWorker(env, deadlineAt, entrypoint) {
1211
1209
  },
1212
1210
  stdio: ["ignore", "pipe", "pipe", "ipc"]
1213
1211
  });
1212
+ const abort = () => {
1213
+ try {
1214
+ if (child.pid && child.exitCode === null && child.signalCode === null)
1215
+ process.kill(-child.pid, "SIGKILL");
1216
+ } catch (error) {
1217
+ if (error.code !== "ESRCH")
1218
+ reject(error);
1219
+ }
1220
+ reject(signal?.reason ?? new Error("update handoff abandoned"));
1221
+ };
1222
+ signal?.addEventListener("abort", abort, { once: true });
1223
+ if (signal?.aborted)
1224
+ abort();
1225
+ child.once("close", () => signal?.removeEventListener("abort", abort));
1214
1226
  let stdout = "", stderr = "";
1215
1227
  child.stdout.setEncoding("utf8");
1216
1228
  child.stderr.setEncoding("utf8");
@@ -1237,28 +1249,22 @@ async function prepareReleaseInWorker(env, deadlineAt, entrypoint) {
1237
1249
  });
1238
1250
  });
1239
1251
  }
1240
- var UPDATE_CONVERGENCE_SLO_MS, UPDATE_DRAIN_DEADLINE_MS, UPDATE_INTERRUPT_DEADLINE_MS, UPDATE_PREPARE_DEADLINE_MS, ReleaseTransaction;
1252
+ var UPDATE_HANDOFF_TIMEOUT_MS, ReleaseTransaction;
1241
1253
  var init_managed_update = __esm({
1242
1254
  "apps/body/dist/managed-update.js"() {
1243
1255
  "use strict";
1244
1256
  init_kernel_lock();
1245
1257
  init_self_update();
1246
- UPDATE_CONVERGENCE_SLO_MS = 20 * 6e4;
1247
- UPDATE_DRAIN_DEADLINE_MS = 5 * 6e4;
1248
- UPDATE_INTERRUPT_DEADLINE_MS = 15 * 6e4;
1249
- UPDATE_PREPARE_DEADLINE_MS = 3 * 6e4;
1258
+ UPDATE_HANDOFF_TIMEOUT_MS = 3 * 6e4;
1250
1259
  ReleaseTransaction = class {
1251
1260
  options;
1252
- #pendingCheck = false;
1261
+ #attempt;
1253
1262
  #preparing;
1263
+ #handingOff;
1254
1264
  #prepared;
1255
1265
  #minimum;
1256
- #handoffAt;
1257
- #interruptAt;
1258
- #deadlineAt;
1259
- #handingOff;
1260
1266
  #completed = false;
1261
- #draining = false;
1267
+ #pendingCheck = false;
1262
1268
  constructor(options) {
1263
1269
  this.options = options;
1264
1270
  }
@@ -1268,105 +1274,120 @@ var init_managed_update = __esm({
1268
1274
  get pending() {
1269
1275
  return this.#preparing ?? this.#handingOff;
1270
1276
  }
1277
+ begin() {
1278
+ if (this.#attempt)
1279
+ return this.#attempt;
1280
+ const controller = new AbortController();
1281
+ const timer = setTimeout(() => this.fail(controller.signal, new Error("update handoff timed out; keeping current release")), UPDATE_HANDOFF_TIMEOUT_MS);
1282
+ timer.unref();
1283
+ return this.#attempt = { controller, timer };
1284
+ }
1285
+ fail(signal, error) {
1286
+ if (this.#attempt?.controller.signal !== signal)
1287
+ return;
1288
+ this.dispose();
1289
+ this.#prepared = void 0;
1290
+ this.#preparing = this.#handingOff = void 0;
1291
+ this.options.changed(void 0);
1292
+ this.options.failed(error, this.#minimum);
1293
+ }
1271
1294
  notify(_releaseKey, minimum) {
1272
- if (minimum && (!this.#minimum || !versionAtLeast(this.#minimum, minimum))) {
1295
+ if (minimum && (!this.#minimum || !versionAtLeast(this.#minimum, minimum)))
1273
1296
  this.#minimum = minimum;
1274
- this.#handoffAt = this.now();
1275
- try {
1276
- this.options.interrupt();
1277
- } catch (error) {
1278
- this.options.failed(error, minimum);
1279
- return;
1280
- }
1297
+ if (this.#completed)
1298
+ return;
1299
+ if (this.#preparing || this.#handingOff) {
1300
+ this.#pendingCheck = true;
1301
+ return;
1281
1302
  }
1282
- this.#deadlineAt ??= this.now() + UPDATE_CONVERGENCE_SLO_MS;
1283
- this.#pendingCheck = true;
1284
- this.prepare();
1303
+ this.#pendingCheck = false;
1304
+ const { controller } = this.begin();
1305
+ const { signal } = controller;
1306
+ const operation = Promise.resolve().then(async () => {
1307
+ if (this.options.prepare)
1308
+ await this.options.prepare(signal);
1309
+ else
1310
+ await prepareReleaseInWorker(this.options.env, Date.now() + UPDATE_HANDOFF_TIMEOUT_MS, void 0, signal);
1311
+ if (signal.aborted)
1312
+ return;
1313
+ const target = (await readUpdateState(this.options.layout)).stagedReleaseId;
1314
+ if (!signal.aborted && target)
1315
+ await this.prepared(target);
1316
+ else if (!signal.aborted && !this.#pendingCheck)
1317
+ this.dispose();
1318
+ }).catch((error) => this.fail(signal, error)).finally(() => {
1319
+ if (this.#preparing !== operation)
1320
+ return;
1321
+ this.#preparing = void 0;
1322
+ if (signal.aborted)
1323
+ return;
1324
+ if (this.#pendingCheck)
1325
+ this.notify();
1326
+ else
1327
+ this.idleChanged();
1328
+ });
1329
+ this.#preparing = operation;
1285
1330
  }
1286
1331
  async prepared(releaseId) {
1287
- if (this.#minimum) {
1288
- const identity = await readInstalledBundleIdentity({
1289
- ...this.options.layout,
1290
- libDir: resolve8(this.options.layout.releasesRoot, releaseId)
1291
- });
1292
- if (!identity?.version || !versionAtLeast(identity.version, this.#minimum)) {
1332
+ if (this.#completed)
1333
+ return;
1334
+ const { signal } = this.begin().controller;
1335
+ try {
1336
+ if (this.#minimum) {
1337
+ const identity = await readInstalledBundleIdentity({
1338
+ ...this.options.layout,
1339
+ libDir: resolve8(this.options.layout.releasesRoot, releaseId)
1340
+ });
1341
+ if (!identity?.version || !versionAtLeast(identity.version, this.#minimum))
1342
+ throw new Error(`published helper ${identity?.version ?? "unknown"} is below required ${this.#minimum}`);
1343
+ }
1344
+ if (signal.aborted)
1345
+ return;
1346
+ if (releaseId === this.options.loadedRelease) {
1293
1347
  this.#prepared = void 0;
1294
- throw new Error(`published helper ${identity?.version ?? "unknown"} is below required ${this.#minimum}`);
1348
+ if (!this.#pendingCheck)
1349
+ this.dispose();
1350
+ this.options.changed(void 0);
1351
+ return;
1295
1352
  }
1353
+ this.#prepared = releaseId;
1354
+ this.options.changed(releaseId);
1355
+ this.idleChanged();
1356
+ } catch (error) {
1357
+ this.fail(signal, error);
1296
1358
  }
1297
- if (releaseId === this.options.loadedRelease && !this.#draining) {
1298
- this.#prepared = void 0;
1299
- this.#deadlineAt = void 0;
1300
- this.#handoffAt = void 0;
1301
- this.#interruptAt = void 0;
1302
- this.#draining = false;
1303
- this.options.changed(void 0);
1304
- return;
1305
- }
1306
- this.#prepared = releaseId;
1307
- this.#deadlineAt ??= this.now() + UPDATE_CONVERGENCE_SLO_MS;
1308
- this.#handoffAt ??= Math.min(this.now() + (this.options.drainMs ?? UPDATE_DRAIN_DEADLINE_MS), this.#deadlineAt - 12e4);
1309
- this.#interruptAt ??= this.now() + UPDATE_INTERRUPT_DEADLINE_MS;
1310
- this.options.changed(releaseId);
1311
- await this.idleChanged();
1312
1359
  }
1313
- async idleChanged() {
1314
- if (this.#completed || !this.#prepared || this.#preparing || this.#pendingCheck || this.#handingOff)
1360
+ idleChanged() {
1361
+ if (this.#completed || !this.#prepared || this.#preparing || this.#handingOff)
1315
1362
  return;
1316
- const idle = this.options.idle();
1317
- const interrupted = Boolean(this.#minimum) || !idle && this.now() >= this.#interruptAt;
1318
- if (!interrupted && !idle) {
1319
- if (!this.#draining && this.now() >= this.#handoffAt) {
1320
- try {
1321
- this.options.drain();
1322
- this.#draining = true;
1323
- } catch (error) {
1324
- this.options.failed(error, this.#minimum);
1325
- }
1363
+ const { signal } = this.begin().controller;
1364
+ const operation = Promise.resolve().then(async () => {
1365
+ if (signal.aborted)
1366
+ return;
1367
+ const interrupted = Boolean(this.#minimum);
1368
+ if (!interrupted && !this.options.idle())
1369
+ return;
1370
+ await this.options.handoff(this.#prepared, interrupted, signal);
1371
+ if (!signal.aborted) {
1372
+ this.#completed = true;
1373
+ this.dispose();
1326
1374
  }
1327
- return;
1328
- }
1329
- const target = this.#prepared;
1330
- this.#handingOff = this.options.handoff(target, interrupted).then(() => {
1331
- this.#completed = true;
1332
- }).catch((error) => {
1333
- this.options.failed(error, this.#minimum);
1334
- this.#draining = false;
1335
- }).finally(() => {
1375
+ }).catch((error) => this.fail(signal, error)).finally(() => {
1376
+ if (this.#handingOff !== operation)
1377
+ return;
1336
1378
  this.#handingOff = void 0;
1379
+ if (!signal.aborted && this.#pendingCheck)
1380
+ this.notify();
1337
1381
  });
1338
- await this.#handingOff;
1382
+ this.#handingOff = operation;
1339
1383
  }
1340
1384
  dispose() {
1341
- }
1342
- now() {
1343
- return (this.options.now ?? Date.now)();
1344
- }
1345
- prepare() {
1346
- if (this.#preparing)
1385
+ this.#pendingCheck = false;
1386
+ if (!this.#attempt)
1347
1387
  return;
1348
- this.#preparing = Promise.resolve().then(async () => {
1349
- while (this.#pendingCheck) {
1350
- this.#pendingCheck = false;
1351
- if (this.options.prepare)
1352
- await this.options.prepare();
1353
- else
1354
- await prepareReleaseInWorker(this.options.env, Math.min(this.#deadlineAt, this.now() + UPDATE_PREPARE_DEADLINE_MS));
1355
- const target = (await readUpdateState(this.options.layout)).stagedReleaseId;
1356
- if (!this.#pendingCheck && target)
1357
- await this.prepared(target);
1358
- }
1359
- }).catch((error) => {
1360
- this.options.failed(error, this.#minimum);
1361
- if (!this.#prepared)
1362
- this.#deadlineAt = void 0;
1363
- }).finally(() => {
1364
- this.#preparing = void 0;
1365
- if (this.#pendingCheck)
1366
- this.prepare();
1367
- else
1368
- void this.idleChanged();
1369
- });
1388
+ clearTimeout(this.#attempt.timer);
1389
+ this.#attempt.controller.abort();
1390
+ this.#attempt = void 0;
1370
1391
  }
1371
1392
  };
1372
1393
  }
@@ -1434,7 +1455,6 @@ var init_agent_command = __esm({
1434
1455
  label: "Pi",
1435
1456
  providerKeyStore: "env",
1436
1457
  hostedModelConfig: "model-file",
1437
- validateHostedModelInSession: true,
1438
1458
  importedMcp: { format: "json", source: ".pi/agent/mcp.json", homeEnv: "PI_CODING_AGENT_DIR", file: "mcp.json" },
1439
1459
  session: { processNames: ["pi"], clientPrefix: "pi", mailEvents: ["poll", "post-tool-use"], pollText: true }
1440
1460
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "usebeeline",
3
- "version": "0.1.201",
3
+ "version": "0.1.202-rc.2",
4
4
  "description": "Connect an AI coding agent to Beeline with one command.",
5
5
  "homepage": "https://usebeeline.app",
6
6
  "bugs": {