usebeeline 0.1.185 → 0.1.186-rc.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.
Files changed (2) hide show
  1. package/dist/usebeeline.mjs +203 -31
  2. package/package.json +1 -1
@@ -915,7 +915,7 @@ async function resolveBundleEntrypoint(bundleDir) {
915
915
  return void 0;
916
916
  }
917
917
  function requiredBundlePaths() {
918
- return [BUNDLE_ENTRYPOINT, PI_MCP_ADAPTER_ENTRYPOINT, CODEGRAPH_ENTRYPOINT];
918
+ return [BUNDLE_ENTRYPOINT, PI_MCP_ADAPTER_ENTRYPOINT, "lib/beeline/owned-model-provider.mjs", CODEGRAPH_ENTRYPOINT];
919
919
  }
920
920
  async function stageRelease(layout, manifestUrl, published, opts = {}) {
921
921
  assertInstallTestIsolation(layout);
@@ -1380,6 +1380,7 @@ var init_agent_command = __esm({
1380
1380
  quotaCredential: { homeEnv: "CODEX_HOME", directory: ".codex", file: "auth.json" },
1381
1381
  importedMcp: { format: "toml", source: ".codex/config.toml", homeEnv: "CODEX_HOME", file: "config.toml" },
1382
1382
  session: {
1383
+ joinDelivery: "local",
1383
1384
  delivery: "queue",
1384
1385
  processNames: ["codex", "codex-tui"],
1385
1386
  clientNames: ["codex"],
@@ -1392,6 +1393,7 @@ var init_agent_command = __esm({
1392
1393
  quotaCredential: { homeEnv: "CLAUDE_CONFIG_DIR", directory: ".claude", file: ".credentials.json" },
1393
1394
  importedMcp: { format: "json", source: ".claude.json", homeEnv: "CLAUDE_CONFIG_DIR", file: ".claude.json" },
1394
1395
  session: {
1396
+ joinDelivery: "local",
1395
1397
  delivery: "socket",
1396
1398
  processNames: ["claude"],
1397
1399
  clientNames: ["claude-code", "claude code"],
@@ -1416,6 +1418,7 @@ var init_agent_command = __esm({
1416
1418
  session: { processNames: ["pi"], clientPrefix: "pi", mailEvents: ["poll", "post-tool-use"], pollText: true }
1417
1419
  },
1418
1420
  grok: {
1421
+ session: { joinDelivery: "on_demand", processNames: ["grok"], clientExactNames: ["grok", "grok cli", "grok build"] },
1419
1422
  label: "Grok",
1420
1423
  cliSignIn: "grok",
1421
1424
  modelLaunch: "native-args",
@@ -1435,9 +1438,11 @@ var init_agent_command = __esm({
1435
1438
  SESSION_AGENT_BEHAVIORS = {
1436
1439
  "claude-code": AGENT_BEHAVIORS.claude.session,
1437
1440
  codex: AGENT_BEHAVIORS.codex.session,
1441
+ grok: AGENT_BEHAVIORS.grok.session,
1438
1442
  opencode: AGENT_BEHAVIORS.opencode.session,
1439
1443
  pi: AGENT_BEHAVIORS.pi.session,
1440
1444
  antigravity: {
1445
+ joinDelivery: "local",
1441
1446
  processNames: ["antigravity", "agy"],
1442
1447
  clientNames: ["antigravity"],
1443
1448
  mailEvents: ["session-start", "user-prompt-submit", "stop"],
@@ -1451,7 +1456,7 @@ var init_agent_command = __esm({
1451
1456
  hermes: { processNames: ["hermes"], clientNames: ["hermes"], mailEvents: ["poll"], pollText: true },
1452
1457
  zcode: { processNames: ["zcode"], clientPrefix: "zcode", mailEvents: ["poll"], pollText: true }
1453
1458
  };
1454
- SESSION_CLIENT_ORDER = ["claude-code", "codex", "antigravity", "gemini", "opencode", "pi", "hermes", "zcode"];
1459
+ SESSION_CLIENT_ORDER = ["claude-code", "codex", "antigravity", "gemini", "opencode", "pi", "hermes", "zcode", "grok"];
1455
1460
  SHARED_CREDENTIALS = [
1456
1461
  // Claude Code relocates ~/.claude wholesale via CLAUDE_CONFIG_DIR; the OAuth
1457
1462
  // credentials live inside it, so an isolated dir needs them linked back.
@@ -1499,6 +1504,8 @@ function detectEnv(env = process.env) {
1499
1504
  return "claude-code";
1500
1505
  if (has("CODEX_THREAD_ID") || has("CODEX_SESSION_ID"))
1501
1506
  return "codex";
1507
+ if (has("GROK_SESSION_ID") || has("GROK_CLI"))
1508
+ return "grok";
1502
1509
  if (has("ANTIGRAVITY_SESSION_ID") || has("ANTIGRAVITY_AGENT"))
1503
1510
  return "antigravity";
1504
1511
  if (has("GEMINI_CLI"))
@@ -1608,8 +1615,9 @@ var init_agents = __esm({
1608
1615
  "apps/body/dist/session-join/agents.js"() {
1609
1616
  "use strict";
1610
1617
  init_agent_command();
1611
- AGENTS = ["claude-code", "codex", "opencode", "pi", "antigravity", "gemini", "hermes", "zcode"];
1618
+ AGENTS = ["claude-code", "codex", "opencode", "pi", "antigravity", "gemini", "hermes", "zcode", "grok"];
1612
1619
  LABELS = {
1620
+ grok: "Grok",
1613
1621
  "claude-code": "Claude Code",
1614
1622
  codex: "Codex",
1615
1623
  opencode: "OpenCode",
@@ -20242,6 +20250,7 @@ var store_exports = {};
20242
20250
  __export(store_exports, {
20243
20251
  HOOK_TTL_MS: () => HOOK_TTL_MS,
20244
20252
  forgetHookSession: () => forgetHookSession,
20253
+ hasLocalDelivery: () => hasLocalDelivery,
20245
20254
  hookSessions: () => hookSessions,
20246
20255
  pidAlive: () => pidAlive,
20247
20256
  queueInbox: () => queueInbox,
@@ -20426,11 +20435,12 @@ function hookSessions(dir, now = Date.now(), alive = pidAlive) {
20426
20435
  }
20427
20436
  return found;
20428
20437
  }
20429
- var HOOK_TTL_MS, lastInboxOrder;
20438
+ var hasLocalDelivery, HOOK_TTL_MS, lastInboxOrder;
20430
20439
  var init_store = __esm({
20431
20440
  "apps/body/dist/session-join/store.js"() {
20432
20441
  "use strict";
20433
20442
  init_filesystem_change();
20443
+ hasLocalDelivery = (session2) => session2.deliveryMechanism === void 0 || session2.deliveryMechanism === "local";
20434
20444
  HOOK_TTL_MS = 6 * 36e5;
20435
20445
  lastInboxOrder = 0;
20436
20446
  }
@@ -20472,6 +20482,12 @@ async function postJson(url, body, headers = {}, signal, _timeoutMs = 6e4, held
20472
20482
  }
20473
20483
  return { status: response.status, value };
20474
20484
  }
20485
+ async function attachLocalDelivery(server, secret) {
20486
+ const { status, value } = await postJson(`${server}/mcp/oauth/delivery-attach`, { secret });
20487
+ if (status !== 200 || typeof value.clientId !== "string" || typeof value.access_token !== "string" || typeof value.refresh_token !== "string" || typeof value.expires_in !== "number")
20488
+ throw new Error("The local delivery handoff ended or was already used. Ask this same connected member for setup_delivery again.");
20489
+ return value;
20490
+ }
20475
20491
  function handoffUri(server) {
20476
20492
  return `${server}/mcp/oauth/handoff`;
20477
20493
  }
@@ -22931,6 +22947,13 @@ var init_artifacts = __esm({
22931
22947
  }
22932
22948
  });
22933
22949
 
22950
+ // packages/api-contract/dist/mcp-delivery.js
22951
+ var init_mcp_delivery = __esm({
22952
+ "packages/api-contract/dist/mcp-delivery.js"() {
22953
+ "use strict";
22954
+ }
22955
+ });
22956
+
22934
22957
  // packages/api-contract/dist/agent-usage.js
22935
22958
  var USAGE_OLD_SECONDS, USAGE_WINDOW_LABELS;
22936
22959
  var init_agent_usage = __esm({
@@ -23168,6 +23191,7 @@ var CLOSED_VIEWER;
23168
23191
  var init_phone_guards = __esm({
23169
23192
  "packages/api-contract/dist/phone-guards.js"() {
23170
23193
  "use strict";
23194
+ init_mcp_delivery();
23171
23195
  init_agent_usage();
23172
23196
  init_agent_sign_in();
23173
23197
  init_agent_grants();
@@ -23728,6 +23752,13 @@ var init_external_agent_rules = __esm({
23728
23752
  }
23729
23753
  });
23730
23754
 
23755
+ // packages/api-contract/dist/mcp-muse-recipe.js
23756
+ var init_mcp_muse_recipe = __esm({
23757
+ "packages/api-contract/dist/mcp-muse-recipe.js"() {
23758
+ "use strict";
23759
+ }
23760
+ });
23761
+
23731
23762
  // packages/api-contract/dist/phone.js
23732
23763
  var init_phone = __esm({
23733
23764
  "packages/api-contract/dist/phone.js"() {
@@ -23773,6 +23804,8 @@ var init_phone = __esm({
23773
23804
  init_media_metadata();
23774
23805
  init_external_agent_rules();
23775
23806
  init_phone_guards();
23807
+ init_mcp_delivery();
23808
+ init_mcp_muse_recipe();
23776
23809
  }
23777
23810
  });
23778
23811
 
@@ -24389,6 +24422,12 @@ function renderRules(joined2, runner2) {
24389
24422
  ].join("\n");
24390
24423
  }
24391
24424
  function renderWake(w, joined2, runner2) {
24425
+ if (w.kind === "join_probe" && w.receipt)
24426
+ return [
24427
+ "Beeline join delivery check: this probe arrived through your selected receiver. It grants no work authority.",
24428
+ "In this exact host conversation, run the receipt command once. Do not post a Room message:",
24429
+ ` ${command(runner2, joined2, `tool confirm_delivery '${JSON.stringify(w.receipt).replace(/'/g, "'\\''")}'`)}`
24430
+ ].join("\n");
24392
24431
  const header = [
24393
24432
  `Beeline: private ${w.kind ?? w.reason} for you (@${joined2.handle ?? joined2.name}) at ${w.address}. It is not a tag; do not reply with --reply-to.`,
24394
24433
  ...w.text ? [w.text.split("\n").map((l) => `> ${l}`).join("\n")] : [],
@@ -24409,6 +24448,13 @@ function renderWake(w, joined2, runner2) {
24409
24448
  `Other Beeline tools: ${command(runner2, joined2, `tool <name> '<json arguments>'`)}`
24410
24449
  ].join("\n");
24411
24450
  }
24451
+ async function recordDeliveryFailure(dir, joined2, reason) {
24452
+ try {
24453
+ if (joined2.deliveryGeneration)
24454
+ await callTool(joined2, await accessToken(dir, joined2.key), "delivery_failed", { generation: joined2.deliveryGeneration, reason });
24455
+ } catch {
24456
+ }
24457
+ }
24412
24458
  async function deliver(dir, joined2, session2, deps = realDeps) {
24413
24459
  if (!sessionAgentBehavior(joined2.agent).delivery)
24414
24460
  return "waiting for the app to collect it";
@@ -24416,6 +24462,9 @@ async function deliver(dir, joined2, session2, deps = realDeps) {
24416
24462
  return "waiting for the session to open";
24417
24463
  if (joined2.agent === "claude-code" && hasClaudeMcp(dir, session2.pid))
24418
24464
  return "waiting for the in-session MCP server";
24465
+ const binding = `${session2.sessionId}:${session2.pid ?? ""}:${joined2.deliveryGeneration ?? ""}`;
24466
+ if (failedLocalHandoffs.get(joined2.key) === binding)
24467
+ return "waiting for host recovery after failed handoff";
24419
24468
  const text = takeInbox(dir, joined2.key);
24420
24469
  if (!text)
24421
24470
  return "nothing waiting";
@@ -24430,7 +24479,9 @@ async function deliver(dir, joined2, session2, deps = realDeps) {
24430
24479
  await deps.queueCodex(joined2.agentBin ?? "codex", session2.sessionId, text);
24431
24480
  return busy ? "queued for after the current Codex turn" : "queued into the idle Codex thread";
24432
24481
  } catch (error) {
24482
+ failedLocalHandoffs.set(joined2.key, binding);
24433
24483
  queueInbox(dir, joined2.key, text);
24484
+ await recordDeliveryFailure(dir, joined2, "local_handoff_failed");
24434
24485
  return `left waiting: ${error instanceof Error ? error.message : String(error)}`;
24435
24486
  }
24436
24487
  }
@@ -24444,6 +24495,11 @@ async function acceptMemberDelivery(dir, key, runner2, raw) {
24444
24495
  return 0;
24445
24496
  let queued = 0;
24446
24497
  if (frame.type === "delivery") {
24498
+ const proof = frame.wakes.find((wake) => wake.kind === "join_probe" && wake.receipt)?.receipt;
24499
+ if (proof) {
24500
+ joined2.deliveryGeneration = proof.generation;
24501
+ joined2.deliveryMechanism = "local";
24502
+ }
24447
24503
  const parts = [
24448
24504
  ...frame.mentions.map((mention) => renderMention(mention, joined2, runner2)),
24449
24505
  ...frame.wakes.filter((wake) => !joined2.deliveredWakes.includes(wake.id)).map((wake) => renderWake(wake, joined2, runner2))
@@ -24475,11 +24531,22 @@ async function flush(dir, sources, deps = realDeps) {
24475
24531
  for (const joined2 of state.sessions) {
24476
24532
  const session2 = findSession(joined2, live, state.sessions);
24477
24533
  if (session2 && (session2.sessionId !== joined2.sessionId || session2.pid !== joined2.pid)) {
24534
+ if (joined2.deliveryGeneration && session2.sessionId !== joined2.sessionId) {
24535
+ const binding = await callTool(joined2, await accessToken(dir, joined2.key), "setup_delivery", {
24536
+ mechanism: "local",
24537
+ host: joined2.agent,
24538
+ surface: joined2.agent === "antigravity" ? "app" : "local_session",
24539
+ conversation: session2.sessionId,
24540
+ installed: true
24541
+ });
24542
+ joined2.deliveryGeneration = binding.delivery.generation;
24543
+ }
24478
24544
  await updateState(dir, (s) => {
24479
24545
  const current = s.sessions.find((x) => x.key === joined2.key);
24480
24546
  if (current) {
24481
24547
  current.sessionId = session2.sessionId;
24482
24548
  current.pid = session2.pid;
24549
+ current.deliveryGeneration = joined2.deliveryGeneration;
24483
24550
  }
24484
24551
  });
24485
24552
  log(dir, `${joined2.key}: in session ${session2.sessionId}`);
@@ -24684,7 +24751,7 @@ async function runBridge(dir, runner2) {
24684
24751
  process.once("SIGTERM", stop);
24685
24752
  process.once("SIGINT", stop);
24686
24753
  const jobs = /* @__PURE__ */ new Set();
24687
- const expected = new Set(readState(dir).sessions.map((session2) => session2.key));
24754
+ const expected = new Set(readState(dir).sessions.filter(hasLocalDelivery).map((session2) => session2.key));
24688
24755
  const openedKeys = /* @__PURE__ */ new Set();
24689
24756
  const failedStartup = (error) => {
24690
24757
  if (staged && !activated) {
@@ -24770,7 +24837,7 @@ async function runBridge(dir, runner2) {
24770
24837
  if (staged) {
24771
24838
  if (!expected.size)
24772
24839
  throw new Error("No joined sessions to activate");
24773
- for (const joined2 of readState(dir).sessions)
24840
+ for (const joined2 of readState(dir).sessions.filter(hasLocalDelivery))
24774
24841
  start(joined2);
24775
24842
  await handoff;
24776
24843
  runner2 = { ...runner2, bundle: join8(dir, "usebeeline.mjs") };
@@ -24787,7 +24854,7 @@ async function runBridge(dir, runner2) {
24787
24854
  log(dir, `bridge ${process.pid} started`);
24788
24855
  for (; !stopping; ) {
24789
24856
  localDirty = false;
24790
- const sessions = readState(dir).sessions;
24857
+ const sessions = readState(dir).sessions.filter(hasLocalDelivery);
24791
24858
  if (!sessions.length)
24792
24859
  break;
24793
24860
  for (const [key, stream] of streams)
@@ -24841,7 +24908,7 @@ async function runBridge(dir, runner2) {
24841
24908
  rmSync4(join8(dir, "bridge.sock"), { force: true });
24842
24909
  process.exit(0);
24843
24910
  }
24844
- var realDeps;
24911
+ var realDeps, failedLocalHandoffs;
24845
24912
  var init_bridge = __esm({
24846
24913
  "apps/body/dist/session-join/bridge.js"() {
24847
24914
  "use strict";
@@ -24861,6 +24928,7 @@ var init_bridge = __esm({
24861
24928
  queueCodex: (bin, thread, text) => codexQueue(thread, text, bin),
24862
24929
  codexBusy: (rollout) => turnRunning(rollout)
24863
24930
  };
24931
+ failedLocalHandoffs = /* @__PURE__ */ new Map();
24864
24932
  }
24865
24933
  });
24866
24934
 
@@ -25271,6 +25339,10 @@ function gemini(context) {
25271
25339
  ["SessionEnd", group("session-end", 5e3)]
25272
25340
  ], Boolean(context.remove));
25273
25341
  }
25342
+ function antigravitySidecarEnabled(env) {
25343
+ const config = readJson(join9(home(env), ".gemini/config/config.json"));
25344
+ return config.sidecars?.[NAME] === void 0 || config.sidecars[NAME]?.enabled !== false;
25345
+ }
25274
25346
  function antigravity(context) {
25275
25347
  const dir = join9(home(context.env), ".gemini/config");
25276
25348
  const lines = [];
@@ -25400,6 +25472,8 @@ var init_setup = __esm({
25400
25472
  opencode,
25401
25473
  pi,
25402
25474
  hermes,
25475
+ // Headless Grok joins on demand until its actual host supplies a proved inbound trigger.
25476
+ grok: () => [],
25403
25477
  zcode: (context) => zcodeIn(home(context.env), context)
25404
25478
  };
25405
25479
  }
@@ -25672,9 +25746,12 @@ async function runZcodeMcp(dir, cwd = process.cwd()) {
25672
25746
  async function antigravityOnce(dir, live, send = agentapi) {
25673
25747
  let handed = 0;
25674
25748
  for (const joined2 of readState(dir).sessions.filter((s) => s.agent === "antigravity")) {
25675
- const session2 = live.find((h) => h.agent === "antigravity" && (h.sessionId === joined2.sessionId || h.cwd === joined2.cwd));
25749
+ const session2 = live.find((h) => h.agent === "antigravity" && h.sessionId === joined2.sessionId);
25676
25750
  if (!session2)
25677
25751
  continue;
25752
+ const generation = joined2.deliveryGeneration ?? session2.sessionId;
25753
+ if (failedHandoffs.get(joined2.key) === generation)
25754
+ continue;
25678
25755
  const text = takeInbox(dir, joined2.key);
25679
25756
  if (!text)
25680
25757
  continue;
@@ -25682,26 +25759,34 @@ async function antigravityOnce(dir, live, send = agentapi) {
25682
25759
  await send(session2.sessionId, text);
25683
25760
  handed++;
25684
25761
  } catch {
25762
+ failedHandoffs.set(joined2.key, generation);
25685
25763
  queueInbox(dir, joined2.key, text);
25764
+ await recordDeliveryFailure(dir, joined2, "antigravity_agentapi_failed");
25686
25765
  }
25687
25766
  }
25688
25767
  return handed;
25689
25768
  }
25690
25769
  async function runAntigravitySidecar(dir) {
25770
+ await tryWithKernelLock("beeline-antigravity-sidecar:" + dir, () => watchAntigravity(dir));
25771
+ }
25772
+ async function watchAntigravity(dir) {
25691
25773
  await antigravityOnce(dir, hookSessions(dir)).catch(() => 0);
25692
25774
  for await (const event of watch6(dir, { recursive: true })) {
25693
- if (event.filename?.startsWith("inbox/"))
25775
+ if (event.filename?.startsWith("inbox/") || event.filename?.startsWith("deliveries/"))
25694
25776
  await antigravityOnce(dir, hookSessions(dir)).catch(() => 0);
25695
25777
  }
25696
25778
  throw new Error("session inbox watcher closed");
25697
25779
  }
25698
- var agentapi;
25780
+ var agentapi, failedHandoffs;
25699
25781
  var init_pull_apps = __esm({
25700
25782
  "apps/body/dist/session-join/pull-apps.js"() {
25701
25783
  "use strict";
25784
+ init_kernel_lock();
25785
+ init_bridge();
25702
25786
  init_store();
25703
25787
  init_beeline_api();
25704
25788
  agentapi = (sessionId, text) => new Promise((resolve13, reject) => execFile4("agentapi", ["send-message", sessionId, text], { timeout: 3e4 }, (error) => error ? reject(error) : resolve13()));
25789
+ failedHandoffs = /* @__PURE__ */ new Map();
25705
25790
  }
25706
25791
  });
25707
25792
 
@@ -25821,25 +25906,55 @@ function findOwnSession(env, dir) {
25821
25906
  };
25822
25907
  }
25823
25908
  if (sessionAgentBehavior(detected.agent).delivery === "queue") {
25824
- const thread = env.CODEX_THREAD_ID ?? env.CODEX_SESSION_ID;
25909
+ const reported2 = hookSessions(dir).filter((h) => h.agent === detected.agent && h.cwd === cwd).sort((a, b) => b.seenAt - a.seenAt)[0];
25910
+ const thread = env.CODEX_THREAD_ID ?? env.CODEX_SESSION_ID ?? reported2?.sessionId;
25825
25911
  const live = scanCodex();
25826
25912
  const own2 = thread ? live.find((s) => s.threadId === thread) : live.find((s) => detected.pid !== void 0 && s.pid === detected.pid);
25827
25913
  return { agent: "codex", cwd: own2?.cwd ?? cwd, sessionId: thread ?? own2?.threadId, pid: own2?.pid ?? detected.pid };
25828
25914
  }
25829
25915
  const reported = hookSessions(dir).filter((h) => h.agent === detected.agent && h.cwd === cwd).sort((a, b) => b.seenAt - a.seenAt)[0];
25830
- return { agent: detected.agent, cwd, sessionId: reported?.sessionId, pid: reported?.pid ?? detected.pid };
25916
+ return { agent: detected.agent, cwd, sessionId: env.ANTIGRAVITY_CONVERSATION_ID ?? env.ANTIGRAVITY_SESSION_ID ?? env.GROK_SESSION_ID ?? env.CONVERSATION_ID ?? reported?.sessionId, pid: reported?.pid ?? detected.pid };
25831
25917
  }
25832
25918
  function serverUrl(args, env) {
25833
25919
  return (flag(args, "--server") ?? env.BEELINE_SERVER_URL ?? DEFAULT_SERVER).replace(/\/+$/, "");
25834
25920
  }
25835
25921
  async function joinCommand(args, env) {
25922
+ const host = flag(args, "--host");
25923
+ if (host) {
25924
+ if (!isAgentId(host))
25925
+ throw new Error("Unknown join host");
25926
+ env = { ...env, BEELINE_SESSION_AGENT: host };
25927
+ }
25836
25928
  const dir = stateDir(env);
25837
25929
  const own2 = findOwnSession(env, dir);
25930
+ own2.sessionId = flag(args, "--conversation") ?? own2.sessionId;
25838
25931
  if (own2.agent === "claude-code")
25839
25932
  assertClaudePolicy(env);
25840
25933
  const run2 = runner(dir, env);
25841
25934
  const key = sessionKey(own2.agent, own2.cwd);
25842
25935
  const server = serverUrl(args, env);
25936
+ const attachment = flag(args, "--attach");
25937
+ if (attachment) {
25938
+ const tokens = await attachLocalDelivery(server, attachment);
25939
+ const pending2 = {
25940
+ server,
25941
+ clientId: tokens.clientId,
25942
+ signIn: { url: "", verifier: "", state: randomUUID2(), tokens, tokensAt: Date.now() },
25943
+ agent: own2.agent,
25944
+ cwd: own2.cwd,
25945
+ name: own2.chosen ?? agentLabel(own2.agent),
25946
+ sessionId: flag(args, "--conversation") ?? own2.sessionId,
25947
+ pid: own2.pid,
25948
+ agentBin: sessionAgentBehavior(own2.agent).delivery === "queue" ? which("codex", env) : void 0,
25949
+ startedAt: Date.now()
25950
+ };
25951
+ mkdirSync6(join12(dir, "pending"), { recursive: true, mode: 448 });
25952
+ const file2 = join12(dir, "pending", `${createHash8("sha256").update(pending2.signIn.state).digest("hex").slice(0, 24)}.json`);
25953
+ writePending(file2, pending2);
25954
+ await finishJoin(file2, env);
25955
+ console.log("Joined as the existing consented member. Live replies stay connecting until this host returns the delivery receipt.");
25956
+ return;
25957
+ }
25843
25958
  const existing = readState(dir).sessions.find((s) => s.key === key && s.server === server);
25844
25959
  if (existing) {
25845
25960
  let connected = false;
@@ -25856,8 +25971,13 @@ async function joinCommand(args, env) {
25856
25971
  } catch {
25857
25972
  }
25858
25973
  if (connected) {
25859
- await ensureBridge(dir, run2, env);
25860
- console.log(`This ${agentLabel(own2.agent)} session is on Beeline as @${existing.handle ?? existing.name}. Tags in its Rooms arrive here.`);
25974
+ const current = readState(dir).sessions.find((s) => s.key === key);
25975
+ await bindLocalDelivery(dir, current, await accessToken(dir, key), env);
25976
+ if (current.deliveryMechanism === "local") {
25977
+ setupAgent(current.agent, { env, node: run2.node, bundle: run2.bundle });
25978
+ await ensureBridge(dir, run2, env);
25979
+ }
25980
+ console.log(`This ${agentLabel(own2.agent)} session is on Beeline as @${existing.handle ?? existing.name}. Live replies are connecting until this host returns the delivery receipt. Run session status to read the current server proof.`);
25861
25981
  return;
25862
25982
  }
25863
25983
  }
@@ -25898,10 +26018,32 @@ async function joinCommand(args, env) {
25898
26018
  ` ${signIn.url}`,
25899
26019
  "",
25900
26020
  `This ${agentLabel(own2.agent)} session joins their Beeline Rooms as "${name}" (they can rename it on the Allow page).`,
25901
- `Nothing else to run: once they tap Allow, a confirmation arrives in this conversation. The link expires in 10 minutes.`,
26021
+ ...sessionAgentBehavior(own2.agent).joinDelivery === "on_demand" ? ["After Allow, run usebeeline session status to confirm your member identity. This CLI uses on-demand Room tools until its host provides a proved inbound trigger."] : [`After Allow, Beeline sets up this session\u2019s receiver and sends one delivery check here. Return its receipt from this conversation. Until then, membership is joined and live replies are connecting. The sign-in link expires in 10 minutes.`],
25902
26022
  ...env.BEELINE_SESSION_DEBUG ? [`(log: ${out})`] : []
25903
26023
  ].join("\n"));
25904
26024
  }
26025
+ async function bindLocalDelivery(dir, joined2, token, env) {
26026
+ const local = sessionAgentBehavior(joined2.agent).joinDelivery === "local";
26027
+ if (local && (!joined2.sessionId || joined2.agent === "antigravity" && !which("agentapi", env)))
26028
+ return;
26029
+ const result = await callTool(joined2, token, "setup_delivery", {
26030
+ mechanism: local ? "local" : "on_demand",
26031
+ host: joined2.agent,
26032
+ surface: joined2.agent === "antigravity" ? "app" : "local_session",
26033
+ conversation: joined2.sessionId ?? joined2.key,
26034
+ installed: true
26035
+ });
26036
+ joined2.deliveryGeneration = result.delivery.generation;
26037
+ joined2.deliveryMechanism = result.delivery.mechanism;
26038
+ await updateState(dir, (state) => {
26039
+ const current = state.sessions.find((s) => s.key === joined2.key);
26040
+ if (current) {
26041
+ current.deliveryGeneration = joined2.deliveryGeneration;
26042
+ current.deliveryMechanism = joined2.deliveryMechanism;
26043
+ }
26044
+ });
26045
+ return joined2.deliveryGeneration;
26046
+ }
25905
26047
  async function finishJoin(file, env) {
25906
26048
  await tryWithKernelLock(finisherKey(file), () => finishJoinOwned(file, env));
25907
26049
  }
@@ -25929,6 +26071,7 @@ async function finishJoinOwned(file, env) {
25929
26071
  name: pending.name,
25930
26072
  server: pending.server,
25931
26073
  clientId: pending.clientId,
26074
+ deliveryMechanism: "unfinished",
25932
26075
  refreshToken: tokens.refresh_token,
25933
26076
  accessToken: tokens.access_token,
25934
26077
  accessExpiresAt: Date.now() + tokens.expires_in * 1e3,
@@ -25946,7 +26089,6 @@ async function finishJoinOwned(file, env) {
25946
26089
  const me = await callTool(joined2, tokens.access_token, "list_rooms", {});
25947
26090
  joined2.name = me.you?.name ?? joined2.name;
25948
26091
  joined2.handle = me.you?.handle ?? void 0;
25949
- await callTool(joined2, tokens.access_token, "set_profile", { name: joined2.name }).catch(() => void 0);
25950
26092
  if (pending.agent === "claude-code" && pending.claudeInboundFallback && !hasClaudeMcp(dir, pending.pid)) {
25951
26093
  const transcript = pending.sessionId ? claudeTranscript(pending.sessionId, env) : void 0;
25952
26094
  if (transcript && permissionMode(transcript) === "bypassPermissions") {
@@ -25960,19 +26102,39 @@ async function finishJoinOwned(file, env) {
25960
26102
  if (waiting.length)
25961
26103
  queueInbox(dir, key, waiting.join("\n\n"));
25962
26104
  });
25963
- const changes = setupAgent(pending.agent, { env, node: run2.node, bundle: run2.bundle });
25964
- if (sessionAgentBehavior(pending.agent).delivery === "queue" && await trustCodexHook({ env, node: run2.node, bundle: run2.bundle }, pending.agentBin ?? "codex", pending.cwd)) {
25965
- const prompt = changes.findIndex((line) => line.startsWith("Codex asks once"));
25966
- if (prompt >= 0)
25967
- changes.splice(prompt, 1);
25968
- changes.push("Trusted only Beeline\u2019s SessionStart hook, pinned to its current Codex hash.");
25969
- }
25970
- await ensureBridge(dir, run2, env);
25971
- const rooms = me.rooms.map((r) => r.name).slice(0, 5).join(", ");
25972
- await announce(joined2, `Beeline: you joined as @${joined2.handle ?? joined2.name}${rooms ? ` in ${rooms}` : ""}. When someone tags you there, the message arrives here with the command that answers it.${changes.length ? `
26105
+ if (joined2.sessionId)
26106
+ recordHookSession(dir, { agent: joined2.agent, sessionId: joined2.sessionId, cwd: joined2.cwd, pid: joined2.pid, seenAt: Date.now() });
26107
+ const generation = await bindLocalDelivery(dir, joined2, tokens.access_token, env);
26108
+ try {
26109
+ const changes = joined2.deliveryMechanism === "local" ? setupAgent(pending.agent, { env, node: run2.node, bundle: run2.bundle }) : [];
26110
+ if (sessionAgentBehavior(pending.agent).delivery === "queue" && await trustCodexHook({ env, node: run2.node, bundle: run2.bundle }, pending.agentBin ?? "codex", pending.cwd)) {
26111
+ const prompt = changes.findIndex((line) => line.startsWith("Codex asks once"));
26112
+ if (prompt >= 0)
26113
+ changes.splice(prompt, 1);
26114
+ changes.push("Trusted only Beeline\u2019s SessionStart hook, pinned to its current Codex hash.");
26115
+ }
26116
+ if (joined2.deliveryMechanism === "local")
26117
+ await ensureBridge(dir, run2, env);
26118
+ if (joined2.agent === "antigravity" && which("agentapi", env) && joined2.sessionId) {
26119
+ if (!antigravitySidecarEnabled(env))
26120
+ throw new Error("Beeline\u2019s Antigravity sidecar is disabled in the host configuration.");
26121
+ const child = spawn8(run2.node, [run2.bundle, "session", "antigravity-sidecar"], { detached: true, stdio: "ignore", env });
26122
+ child.unref();
26123
+ }
26124
+ const rooms = me.rooms.map((r) => r.name).slice(0, 5).join(", ");
26125
+ if (joined2.deliveryMechanism === "on_demand") {
26126
+ console.log(`Joined on demand as @${joined2.handle ?? joined2.name}. Run session status to read the approved member and owner.`);
26127
+ return;
26128
+ }
26129
+ await announce(joined2, `Beeline: joined \xB7 connecting live replies as @${joined2.handle ?? joined2.name}${rooms ? ` in ${rooms}` : ""}. A separate delivery check must reach this conversation and return its receipt before live replies are proved ready. Incoming Room messages include the command that answers them.${changes.length ? `
25973
26130
  (${changes.join("; ")})` : ""}
25974
26131
 
25975
26132
  ${renderRules(joined2, run2)}`, dir);
26133
+ } catch (error) {
26134
+ if (generation)
26135
+ await callTool(joined2, tokens.access_token, "delivery_failed", { generation, reason: "local_receiver_setup_failed" }).catch(() => void 0);
26136
+ throw error;
26137
+ }
25976
26138
  } catch (error) {
25977
26139
  retain = !(error instanceof SignInEndedError);
25978
26140
  throw error;
@@ -25990,12 +26152,12 @@ async function announce(joined2, text, dir) {
25990
26152
  }
25991
26153
  const session2 = scanClaude().find((s) => s.sessionId === joined2.sessionId || s.pid === joined2.pid);
25992
26154
  if (session2?.messagingSocketPath) {
25993
- await postToClaude({ path: session2.messagingSocketPath }, text).catch(() => void 0);
26155
+ await postToClaude({ path: session2.messagingSocketPath }, text);
25994
26156
  return;
25995
26157
  }
25996
26158
  }
25997
26159
  if (sessionAgentBehavior(joined2.agent).delivery === "queue" && joined2.sessionId) {
25998
- await codexQueue(joined2.sessionId, text, joined2.agentBin ?? "codex").catch(() => void 0);
26160
+ await codexQueue(joined2.sessionId, text, joined2.agentBin ?? "codex");
25999
26161
  return;
26000
26162
  }
26001
26163
  const { queueInbox: queueInbox2 } = await Promise.resolve().then(() => (init_store(), store_exports));
@@ -26094,13 +26256,23 @@ async function session(args, env) {
26094
26256
  const [name, json] = words(rest, VALUED);
26095
26257
  if (!name)
26096
26258
  throw new Error("Usage: usebeeline session tool <name> '<json arguments>'");
26097
- const result = await ownTool(dir, joined2, name, json ? JSON.parse(json) : {});
26259
+ const input = json ? JSON.parse(json) : {};
26260
+ if (name === "confirm_delivery" && findOwnSession(env, dir).sessionId !== input.conversation)
26261
+ throw new Error("The receipt must run in its bound host conversation");
26262
+ const result = await ownTool(dir, joined2, name, input);
26098
26263
  console.log(JSON.stringify(result, null, 2));
26099
26264
  return;
26100
26265
  }
26101
26266
  if (sub === "status") {
26102
- for (const s of readState(dir).sessions)
26267
+ for (const s of readState(dir).sessions) {
26103
26268
  console.log(`${s.key} @${s.handle ?? s.name} ${s.server} session ${s.sessionId ?? "unknown"}`);
26269
+ try {
26270
+ const result = await ownTool(dir, s, "list_rooms", {});
26271
+ console.log(JSON.stringify({ you: result.you, owner: result.owner, delivery: result.delivery ?? { state: "setup_unfinished" } }, null, 2));
26272
+ } catch {
26273
+ console.log("Delivery state unavailable; no host receipt verified by this read.");
26274
+ }
26275
+ }
26104
26276
  return;
26105
26277
  }
26106
26278
  if (sub === "leave") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "usebeeline",
3
- "version": "0.1.185",
3
+ "version": "0.1.186-rc.3",
4
4
  "description": "Connect an AI coding agent to Beeline with one command.",
5
5
  "homepage": "https://usebeeline.app",
6
6
  "bugs": {