usebeeline 0.1.193 → 0.1.194

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 +33 -12
  2. package/package.json +1 -1
@@ -24275,8 +24275,10 @@ async function ensureBridge(dir, runner2, env = process.env) {
24275
24275
  if (!isBridgeProcess(old))
24276
24276
  throw new Error("Beeline bridge PID belongs to an unrecognized process; refusing takeover");
24277
24277
  const owner = bridgeOwner(dir);
24278
- if (owner?.pid === old && owner.digest === digest)
24278
+ if (owner?.pid === old && owner.digest === digest) {
24279
+ await notifyBridgeSessions(dir);
24279
24280
  return;
24281
+ }
24280
24282
  }
24281
24283
  mkdirSync3(dir, { recursive: true, mode: 448 });
24282
24284
  const stable = join7(dir, "usebeeline.mjs");
@@ -24340,6 +24342,7 @@ var init_bridge_launch = __esm({
24340
24342
  init_kernel_lock();
24341
24343
  init_process_exit();
24342
24344
  init_store();
24345
+ init_bridge();
24343
24346
  }
24344
24347
  });
24345
24348
 
@@ -24507,7 +24510,7 @@ async function flush(dir, sources, deps = realDeps) {
24507
24510
  log(dir, `${joined2.key}: ${outcome}`);
24508
24511
  }
24509
24512
  }
24510
- async function serveTools(dir, path = join8(dir, "bridge.sock")) {
24513
+ async function serveTools(dir, path, sessionsChanged) {
24511
24514
  rmSync4(path, { force: true });
24512
24515
  const server = createServer3((connection) => {
24513
24516
  let buffer = "", taken = false;
@@ -24521,10 +24524,18 @@ async function serveTools(dir, path = join8(dir, "bridge.sock")) {
24521
24524
  let answer;
24522
24525
  try {
24523
24526
  const request2 = JSON.parse(buffer.slice(0, end));
24524
- const joined2 = readState(dir).sessions.find((s) => s.key === request2.key);
24525
- if (!joined2)
24526
- throw new Error("This session has not joined Beeline");
24527
- answer = { ok: true, data: await callTool(joined2, await accessToken(dir, joined2.key), request2.name, request2.args ?? {}) };
24527
+ if (request2.type === "sessions-changed") {
24528
+ sessionsChanged();
24529
+ answer = { ok: true };
24530
+ } else {
24531
+ const joined2 = readState(dir).sessions.find((s) => s.key === request2.key);
24532
+ if (!joined2)
24533
+ throw new Error("This session has not joined Beeline");
24534
+ const token = await accessToken(dir, joined2.key);
24535
+ if (token !== joined2.accessToken)
24536
+ sessionsChanged();
24537
+ answer = { ok: true, data: await callTool(joined2, token, request2.name, request2.args ?? {}) };
24538
+ }
24528
24539
  } catch (error) {
24529
24540
  answer = { ok: false, error: error instanceof Error ? error.message : String(error) };
24530
24541
  }
@@ -24610,6 +24621,14 @@ async function toolViaOutbox(cwd, name, args) {
24610
24621
  });
24611
24622
  }
24612
24623
  function toolViaBridge(dir, key, name, args) {
24624
+ return bridgeRequest(dir, { key, name, args });
24625
+ }
24626
+ async function notifyBridgeSessions(dir) {
24627
+ const answer = await bridgeRequest(dir, { type: "sessions-changed" });
24628
+ if (!answer?.ok)
24629
+ throw new Error(answer?.error ?? "Beeline tool result is awaiting confirmation");
24630
+ }
24631
+ function bridgeRequest(dir, request2) {
24613
24632
  return new Promise((resolve13) => {
24614
24633
  const connection = createConnection4(join8(dir, "bridge.sock"));
24615
24634
  let text = "", sent = false, settled = false;
@@ -24624,7 +24643,7 @@ function toolViaBridge(dir, key, name, args) {
24624
24643
  connection.setEncoding("utf8");
24625
24644
  connection.once("connect", () => {
24626
24645
  sent = true;
24627
- connection.write(JSON.stringify({ key, name, args }) + "\n");
24646
+ connection.write(JSON.stringify(request2) + "\n");
24628
24647
  });
24629
24648
  connection.once("error", () => finish(sent ? unknown : void 0));
24630
24649
  connection.on("data", (chunk) => {
@@ -24677,18 +24696,18 @@ async function runBridge(dir, runner2) {
24677
24696
  if (!staged && !claim())
24678
24697
  return;
24679
24698
  const socket = join8(dir, staged ? `bridge-${process.pid}.sock` : "bridge.sock");
24680
- const tools = await serveTools(dir, socket);
24681
- const sources = machineSources(dir);
24682
- const streams = /* @__PURE__ */ new Map();
24683
- const outboxWatches = /* @__PURE__ */ new Map();
24684
24699
  let localDirty = true, wake;
24685
24700
  const changed = () => {
24686
24701
  localDirty = true;
24687
24702
  wake?.();
24688
24703
  };
24704
+ const tools = await serveTools(dir, socket, changed);
24705
+ const sources = machineSources(dir);
24706
+ const streams = /* @__PURE__ */ new Map();
24707
+ const outboxWatches = /* @__PURE__ */ new Map();
24689
24708
  const localWatch = watch5(dir, { recursive: true }, (_event, name) => {
24690
24709
  const path = String(name ?? "");
24691
- if (path === "state.json" || path.startsWith("hooks/") || path.startsWith("inbox/") || path.startsWith("deliveries/"))
24710
+ if (path.startsWith("hooks/") || path.startsWith("inbox/") || path.startsWith("deliveries/"))
24692
24711
  changed();
24693
24712
  });
24694
24713
  const stop = () => {
@@ -26238,6 +26257,8 @@ async function session(args, env) {
26238
26257
  state.sessions = state.sessions.filter((s) => s.key !== joined2.key);
26239
26258
  return state.sessions;
26240
26259
  });
26260
+ if (bridgeRunning(dir))
26261
+ await notifyBridgeSessions(dir);
26241
26262
  const r = runner(dir, env);
26242
26263
  await restoreClaudeInbound(env);
26243
26264
  const changes = left.some((s) => s.agent === joined2.agent) ? [] : setupAgent(joined2.agent, { env, node: r.node, bundle: r.bundle, remove: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "usebeeline",
3
- "version": "0.1.193",
3
+ "version": "0.1.194",
4
4
  "description": "Connect an AI coding agent to Beeline with one command.",
5
5
  "homepage": "https://usebeeline.app",
6
6
  "bugs": {