@open-bus/cli 0.43.0 → 0.43.1

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/index.js +345 -249
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -22214,6 +22214,21 @@ import { createHash } from "node:crypto";
22214
22214
  import { readFileSync } from "node:fs";
22215
22215
  import { homedir } from "node:os";
22216
22216
  import { join, resolve } from "node:path";
22217
+ function readSessionFile(dir, pid) {
22218
+ let text3;
22219
+ try {
22220
+ text3 = readFileSync(join(dir, `${pid}.json`), "utf8");
22221
+ } catch (e) {
22222
+ return e.code === "ENOENT" ? { state: "none" } : { state: "unreadable" };
22223
+ }
22224
+ try {
22225
+ const rec = JSON.parse(text3);
22226
+ if (typeof rec?.sessionId === "string")
22227
+ return { state: "ok", rec };
22228
+ } catch {
22229
+ }
22230
+ return { state: "unreadable" };
22231
+ }
22217
22232
  function peerTokenFor(pid, socketPath2, dir, procStart, hash2 = sha256) {
22218
22233
  try {
22219
22234
  const key = JSON.parse(
@@ -22226,15 +22241,10 @@ function peerTokenFor(pid, socketPath2, dir, procStart, hash2 = sha256) {
22226
22241
  }
22227
22242
  function findSession(pid, deps) {
22228
22243
  for (const anc of deps.ancestors(pid)) {
22229
- let rec;
22230
- try {
22231
- rec = JSON.parse(
22232
- readFileSync(join(deps.sessionsDir, `${anc}.json`), "utf8")
22233
- );
22234
- } catch {
22235
- continue;
22236
- }
22237
- if (typeof rec?.sessionId !== "string") continue;
22244
+ const file2 = readSessionFile(deps.sessionsDir, anc);
22245
+ if (file2.state === "none") continue;
22246
+ if (file2.state === "unreadable") return null;
22247
+ const { rec } = file2;
22238
22248
  if (notASession(rec)) return null;
22239
22249
  if (typeof rec.procStart !== "string") return null;
22240
22250
  const start = deps.procStart(anc);
@@ -24779,7 +24789,7 @@ var require_websocket = __commonJS({
24779
24789
  var http = __require("http");
24780
24790
  var net = __require("net");
24781
24791
  var tls = __require("tls");
24782
- var { randomBytes: randomBytes3, createHash: createHash4 } = __require("crypto");
24792
+ var { randomBytes: randomBytes3, createHash: createHash5 } = __require("crypto");
24783
24793
  var { Duplex, Readable } = __require("stream");
24784
24794
  var { URL: URL2 } = __require("url");
24785
24795
  var PerMessageDeflate2 = require_permessage_deflate();
@@ -25460,7 +25470,7 @@ var require_websocket = __commonJS({
25460
25470
  abortHandshake(websocket, socket, "Invalid Upgrade header");
25461
25471
  return;
25462
25472
  }
25463
- const digest = createHash4("sha1").update(key + GUID).digest("base64");
25473
+ const digest = createHash5("sha1").update(key + GUID).digest("base64");
25464
25474
  if (res.headers["sec-websocket-accept"] !== digest) {
25465
25475
  abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
25466
25476
  return;
@@ -25829,7 +25839,7 @@ var require_websocket_server = __commonJS({
25829
25839
  var EventEmitter = __require("events");
25830
25840
  var http = __require("http");
25831
25841
  var { Duplex } = __require("stream");
25832
- var { createHash: createHash4 } = __require("crypto");
25842
+ var { createHash: createHash5 } = __require("crypto");
25833
25843
  var extension2 = require_extension();
25834
25844
  var PerMessageDeflate2 = require_permessage_deflate();
25835
25845
  var subprotocol2 = require_subprotocol();
@@ -26136,7 +26146,7 @@ var require_websocket_server = __commonJS({
26136
26146
  );
26137
26147
  }
26138
26148
  if (this._state > RUNNING) return abortHandshake(socket, 503);
26139
- const digest = createHash4("sha1").update(key + GUID).digest("base64");
26149
+ const digest = createHash5("sha1").update(key + GUID).digest("base64");
26140
26150
  const headers = [
26141
26151
  "HTTP/1.1 101 Switching Protocols",
26142
26152
  "Upgrade: websocket",
@@ -29746,11 +29756,11 @@ var require_codegen = __commonJS({
29746
29756
  const rhs = this.rhs === void 0 ? "" : ` = ${this.rhs}`;
29747
29757
  return `${varKind} ${this.name}${rhs};` + _n;
29748
29758
  }
29749
- optimizeNames(names2, constants) {
29759
+ optimizeNames(names2, constants2) {
29750
29760
  if (!names2[this.name.str])
29751
29761
  return;
29752
29762
  if (this.rhs)
29753
- this.rhs = optimizeExpr(this.rhs, names2, constants);
29763
+ this.rhs = optimizeExpr(this.rhs, names2, constants2);
29754
29764
  return this;
29755
29765
  }
29756
29766
  get names() {
@@ -29767,10 +29777,10 @@ var require_codegen = __commonJS({
29767
29777
  render({ _n }) {
29768
29778
  return `${this.lhs} = ${this.rhs};` + _n;
29769
29779
  }
29770
- optimizeNames(names2, constants) {
29780
+ optimizeNames(names2, constants2) {
29771
29781
  if (this.lhs instanceof code_1.Name && !names2[this.lhs.str] && !this.sideEffects)
29772
29782
  return;
29773
- this.rhs = optimizeExpr(this.rhs, names2, constants);
29783
+ this.rhs = optimizeExpr(this.rhs, names2, constants2);
29774
29784
  return this;
29775
29785
  }
29776
29786
  get names() {
@@ -29831,8 +29841,8 @@ var require_codegen = __commonJS({
29831
29841
  optimizeNodes() {
29832
29842
  return `${this.code}` ? this : void 0;
29833
29843
  }
29834
- optimizeNames(names2, constants) {
29835
- this.code = optimizeExpr(this.code, names2, constants);
29844
+ optimizeNames(names2, constants2) {
29845
+ this.code = optimizeExpr(this.code, names2, constants2);
29836
29846
  return this;
29837
29847
  }
29838
29848
  get names() {
@@ -29861,12 +29871,12 @@ var require_codegen = __commonJS({
29861
29871
  }
29862
29872
  return nodes.length > 0 ? this : void 0;
29863
29873
  }
29864
- optimizeNames(names2, constants) {
29874
+ optimizeNames(names2, constants2) {
29865
29875
  const { nodes } = this;
29866
29876
  let i = nodes.length;
29867
29877
  while (i--) {
29868
29878
  const n = nodes[i];
29869
- if (n.optimizeNames(names2, constants))
29879
+ if (n.optimizeNames(names2, constants2))
29870
29880
  continue;
29871
29881
  subtractNames(names2, n.names);
29872
29882
  nodes.splice(i, 1);
@@ -29919,12 +29929,12 @@ var require_codegen = __commonJS({
29919
29929
  return void 0;
29920
29930
  return this;
29921
29931
  }
29922
- optimizeNames(names2, constants) {
29932
+ optimizeNames(names2, constants2) {
29923
29933
  var _a3;
29924
- this.else = (_a3 = this.else) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names2, constants);
29925
- if (!(super.optimizeNames(names2, constants) || this.else))
29934
+ this.else = (_a3 = this.else) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names2, constants2);
29935
+ if (!(super.optimizeNames(names2, constants2) || this.else))
29926
29936
  return;
29927
- this.condition = optimizeExpr(this.condition, names2, constants);
29937
+ this.condition = optimizeExpr(this.condition, names2, constants2);
29928
29938
  return this;
29929
29939
  }
29930
29940
  get names() {
@@ -29947,10 +29957,10 @@ var require_codegen = __commonJS({
29947
29957
  render(opts) {
29948
29958
  return `for(${this.iteration})` + super.render(opts);
29949
29959
  }
29950
- optimizeNames(names2, constants) {
29951
- if (!super.optimizeNames(names2, constants))
29960
+ optimizeNames(names2, constants2) {
29961
+ if (!super.optimizeNames(names2, constants2))
29952
29962
  return;
29953
- this.iteration = optimizeExpr(this.iteration, names2, constants);
29963
+ this.iteration = optimizeExpr(this.iteration, names2, constants2);
29954
29964
  return this;
29955
29965
  }
29956
29966
  get names() {
@@ -29986,10 +29996,10 @@ var require_codegen = __commonJS({
29986
29996
  render(opts) {
29987
29997
  return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts);
29988
29998
  }
29989
- optimizeNames(names2, constants) {
29990
- if (!super.optimizeNames(names2, constants))
29999
+ optimizeNames(names2, constants2) {
30000
+ if (!super.optimizeNames(names2, constants2))
29991
30001
  return;
29992
- this.iterable = optimizeExpr(this.iterable, names2, constants);
30002
+ this.iterable = optimizeExpr(this.iterable, names2, constants2);
29993
30003
  return this;
29994
30004
  }
29995
30005
  get names() {
@@ -30031,11 +30041,11 @@ var require_codegen = __commonJS({
30031
30041
  (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNodes();
30032
30042
  return this;
30033
30043
  }
30034
- optimizeNames(names2, constants) {
30044
+ optimizeNames(names2, constants2) {
30035
30045
  var _a3, _b;
30036
- super.optimizeNames(names2, constants);
30037
- (_a3 = this.catch) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names2, constants);
30038
- (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names2, constants);
30046
+ super.optimizeNames(names2, constants2);
30047
+ (_a3 = this.catch) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names2, constants2);
30048
+ (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names2, constants2);
30039
30049
  return this;
30040
30050
  }
30041
30051
  get names() {
@@ -30336,7 +30346,7 @@ var require_codegen = __commonJS({
30336
30346
  function addExprNames(names2, from) {
30337
30347
  return from instanceof code_1._CodeOrName ? addNames(names2, from.names) : names2;
30338
30348
  }
30339
- function optimizeExpr(expr, names2, constants) {
30349
+ function optimizeExpr(expr, names2, constants2) {
30340
30350
  if (expr instanceof code_1.Name)
30341
30351
  return replaceName(expr);
30342
30352
  if (!canOptimize(expr))
@@ -30351,14 +30361,14 @@ var require_codegen = __commonJS({
30351
30361
  return items;
30352
30362
  }, []));
30353
30363
  function replaceName(n) {
30354
- const c = constants[n.str];
30364
+ const c = constants2[n.str];
30355
30365
  if (c === void 0 || names2[n.str] !== 1)
30356
30366
  return n;
30357
30367
  delete names2[n.str];
30358
30368
  return c;
30359
30369
  }
30360
30370
  function canOptimize(e) {
30361
- return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names2[c.str] === 1 && constants[c.str] !== void 0);
30371
+ return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names2[c.str] === 1 && constants2[c.str] !== void 0);
30362
30372
  }
30363
30373
  }
30364
30374
  function subtractNames(names2, from) {
@@ -37537,8 +37547,8 @@ import { join as join11 } from "node:path";
37537
37547
 
37538
37548
  // ../daemon/src/index.ts
37539
37549
  init_src2();
37540
- import { lstatSync as lstatSync3, writeFileSync as writeFileSync3 } from "node:fs";
37541
- import { basename as basename4, isAbsolute as isAbsolute2, join as join9 } from "node:path";
37550
+ import { lstatSync as lstatSync4, writeFileSync as writeFileSync3 } from "node:fs";
37551
+ import { basename as basename4, isAbsolute as isAbsolute2, join as join8 } from "node:path";
37542
37552
 
37543
37553
  // ../adapters/opencode/src/version.ts
37544
37554
  var MIN_PROMPT_ID_VERSION = "2.0.0";
@@ -37609,8 +37619,7 @@ var AgentTable = class {
37609
37619
  // ../daemon/src/attest.ts
37610
37620
  init_src2();
37611
37621
  import { execFileSync as execFileSync2 } from "node:child_process";
37612
- import { readFileSync as readFileSync5 } from "node:fs";
37613
- import { basename as basename2, isAbsolute, join as join6 } from "node:path";
37622
+ import { basename as basename2, isAbsolute } from "node:path";
37614
37623
 
37615
37624
  // ../daemon/src/liveness/claude.ts
37616
37625
  init_src2();
@@ -37704,6 +37713,7 @@ import { join as join5 } from "node:path";
37704
37713
  // ../daemon/src/config.ts
37705
37714
  init_src2();
37706
37715
  init_dist();
37716
+ import { createHash as createHash3 } from "node:crypto";
37707
37717
  import {
37708
37718
  chmodSync as chmodSync2,
37709
37719
  existsSync,
@@ -37787,12 +37797,29 @@ function originOf(url2) {
37787
37797
  }
37788
37798
  }
37789
37799
  var cleanLabel = (raw) => typeof raw === "string" ? newMachineLabel(raw) : "machine";
37800
+ var tokenHash = (token) => createHash3("sha256").update(token).digest("hex");
37801
+ var revokedMarker = (token, at = /* @__PURE__ */ new Date()) => `${JSON.stringify({ at: at.toISOString(), token_sha256: tokenHash(token) })}
37802
+ `;
37803
+ function revokedFor(token, h = home()) {
37804
+ const file2 = join4(h, "revoked");
37805
+ if (!existsSync(file2)) return false;
37806
+ try {
37807
+ const m = JSON.parse(readFileSync3(file2, "utf8"));
37808
+ if (typeof m.token_sha256 === "string")
37809
+ return m.token_sha256 === tokenHash(token);
37810
+ } catch {
37811
+ }
37812
+ return true;
37813
+ }
37814
+ function savedToken(h = home()) {
37815
+ try {
37816
+ const r = JSON.parse(readFileSync3(join4(h, "machine.json"), "utf8"));
37817
+ return typeof r.machine_token === "string" ? r.machine_token : void 0;
37818
+ } catch {
37819
+ return void 0;
37820
+ }
37821
+ }
37790
37822
  function readConfig() {
37791
- if (existsSync(join4(home(), "revoked")))
37792
- throw new StartError(
37793
- "REVOKED",
37794
- "this machine was revoked; run `npx @open-bus/cli install`"
37795
- );
37796
37823
  const file2 = join4(home(), "machine.json");
37797
37824
  let text3;
37798
37825
  try {
@@ -37823,9 +37850,15 @@ function readConfig() {
37823
37850
  throw notLoggedIn();
37824
37851
  }
37825
37852
  const r = raw;
37826
- const hub = process.env.OPENBUS_HUB ?? r.hub;
37827
- if (!hub || r.machine_token === void 0) throw notLoggedIn();
37828
- if (r.hub && hub !== r.hub && originOf(hub) !== originOf(r.hub))
37853
+ if (typeof r.hub !== "string" || !r.hub || r.machine_token === void 0)
37854
+ throw notLoggedIn();
37855
+ if (revokedFor(String(r.machine_token)))
37856
+ throw new StartError(
37857
+ "REVOKED",
37858
+ "this machine was revoked; run `npx @open-bus/cli install`"
37859
+ );
37860
+ const hub = process.env.OPENBUS_HUB || r.hub;
37861
+ if (hub !== r.hub && originOf(hub) !== originOf(r.hub))
37829
37862
  throw new StartError(
37830
37863
  "HUB_MISMATCH",
37831
37864
  `the hub ${hub} is not the one this machine was approved for (${r.hub}); run \`npx @open-bus/cli login --hub ${hub}\` to approve it there`
@@ -37905,13 +37938,11 @@ function attest(hello, deps = {}) {
37905
37938
  function attestClaude(hello, deps) {
37906
37939
  const dir = deps.sessionsDir ?? claudeSessionsDir();
37907
37940
  for (const pid of (deps.ancestors ?? ancestorChain)(hello.pid)) {
37908
- let raw;
37909
- try {
37910
- raw = JSON.parse(readFileSync5(join6(dir, `${pid}.json`), "utf8"));
37911
- } catch {
37912
- continue;
37913
- }
37914
- if (typeof raw?.sessionId !== "string") continue;
37941
+ const file2 = readSessionFile(dir, pid);
37942
+ if (file2.state === "none") continue;
37943
+ if (file2.state === "unreadable")
37944
+ return { ok: false, reason: "session file unreadable; retry" };
37945
+ const raw = file2.rec;
37915
37946
  if (raw.sessionId !== hello.agent_ref || notASession(raw)) {
37916
37947
  return {
37917
37948
  ok: false,
@@ -38374,7 +38405,7 @@ var HubConnection = class {
38374
38405
  res.resume();
38375
38406
  limitedUpgrade = res.statusCode === 429;
38376
38407
  this.lastError = limitedUpgrade ? "rate limited" : `HTTP ${res.statusCode}`;
38377
- if (res.statusCode === 401 || res.statusCode === 403) {
38408
+ if (res.statusCode === 401) {
38378
38409
  this.#ws = void 0;
38379
38410
  this.#revoke();
38380
38411
  }
@@ -38471,8 +38502,15 @@ function defaultBackoff(attempt) {
38471
38502
  // ../daemon/src/namespace.ts
38472
38503
  init_dist();
38473
38504
  import { execFileSync as execFileSync3 } from "node:child_process";
38474
- import { readFileSync as readFileSync6, realpathSync as realpathSync2, statSync as statSync5 } from "node:fs";
38475
- import { basename as basename3, dirname as dirname3, join as join7, resolve as resolve2 } from "node:path";
38505
+ import {
38506
+ closeSync,
38507
+ constants,
38508
+ fstatSync,
38509
+ openSync,
38510
+ readFileSync as readFileSync5,
38511
+ realpathSync as realpathSync2
38512
+ } from "node:fs";
38513
+ import { basename as basename3, dirname as dirname3, join as join6, resolve as resolve2 } from "node:path";
38476
38514
  var warned = /* @__PURE__ */ new Set();
38477
38515
  function resolveNamespace(start, deps = {}) {
38478
38516
  let cwd;
@@ -38489,10 +38527,15 @@ function resolveNamespace(start, deps = {}) {
38489
38527
  const uid = deps.uid ?? process.getuid?.();
38490
38528
  const configs = [];
38491
38529
  for (let dir = cwd; ; dir = dirname3(dir)) {
38492
- const file2 = join7(dir, CONFIG_FILE);
38530
+ const file2 = join6(dir, CONFIG_FILE);
38493
38531
  let text3;
38532
+ let fd;
38494
38533
  try {
38495
- const st = statSync5(file2);
38534
+ fd = openSync(
38535
+ file2,
38536
+ constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0)
38537
+ );
38538
+ const st = fstatSync(fd);
38496
38539
  if (uid !== void 0 && st.uid !== uid || st.mode & 18) {
38497
38540
  if (!warned.has(file2)) {
38498
38541
  warned.add(file2);
@@ -38500,8 +38543,10 @@ function resolveNamespace(start, deps = {}) {
38500
38543
  `ignoring ${file2}: not owned by you or writable by others`
38501
38544
  );
38502
38545
  }
38503
- } else text3 = readFileSync6(file2, "utf8");
38546
+ } else if (st.isFile()) text3 = readFileSync5(fd, "utf8");
38504
38547
  } catch {
38548
+ } finally {
38549
+ if (fd !== void 0) closeSync(fd);
38505
38550
  }
38506
38551
  if (text3 !== void 0) {
38507
38552
  let parsed;
@@ -38917,7 +38962,7 @@ init_src();
38917
38962
  init_dist();
38918
38963
  import {
38919
38964
  chmodSync as chmodSync3,
38920
- readFileSync as readFileSync7,
38965
+ readFileSync as readFileSync6,
38921
38966
  renameSync as renameSync2,
38922
38967
  rmSync as rmSync2,
38923
38968
  writeFileSync
@@ -39080,7 +39125,7 @@ var SentStore = class {
39080
39125
  if (!this.file) return;
39081
39126
  let raw;
39082
39127
  try {
39083
- raw = JSON.parse(readFileSync7(this.file, "utf8"));
39128
+ raw = JSON.parse(readFileSync6(this.file, "utf8"));
39084
39129
  } catch {
39085
39130
  return;
39086
39131
  }
@@ -39318,13 +39363,13 @@ var Receipts = class {
39318
39363
  init_src2();
39319
39364
  init_dist();
39320
39365
  import { randomUUID } from "node:crypto";
39321
- import { chmodSync as chmodSync5, mkdirSync as mkdirSync4, rmSync as rmSync3 } from "node:fs";
39366
+ import { chmodSync as chmodSync5, lstatSync as lstatSync3, mkdirSync as mkdirSync4, rmSync as rmSync3 } from "node:fs";
39322
39367
  import { createServer as createServer2 } from "node:net";
39323
- import { join as join8 } from "node:path";
39368
+ import { dirname as dirname4, join as join7 } from "node:path";
39324
39369
  import { createInterface } from "node:readline";
39325
39370
 
39326
39371
  // ../daemon/src/transports/held.ts
39327
- import { chmodSync as chmodSync4, readFileSync as readFileSync8, renameSync as renameSync3, writeFileSync as writeFileSync2 } from "node:fs";
39372
+ import { chmodSync as chmodSync4, readFileSync as readFileSync7, renameSync as renameSync3, writeFileSync as writeFileSync2 } from "node:fs";
39328
39373
  var HeldStore = class {
39329
39374
  constructor(file2, opts = {}) {
39330
39375
  this.file = file2;
@@ -39349,7 +39394,7 @@ var HeldStore = class {
39349
39394
  #read() {
39350
39395
  let raw;
39351
39396
  try {
39352
- raw = JSON.parse(readFileSync8(this.file, "utf8"));
39397
+ raw = JSON.parse(readFileSync7(this.file, "utf8"));
39353
39398
  } catch {
39354
39399
  return {};
39355
39400
  }
@@ -39378,6 +39423,29 @@ var STATUSES = /* @__PURE__ */ new Set([
39378
39423
  "dropped"
39379
39424
  ]);
39380
39425
  var STOPPED = /* @__PURE__ */ Symbol("stopped");
39426
+ function unsafeClaudeSocket(path) {
39427
+ const uid = process.getuid?.();
39428
+ let sock;
39429
+ try {
39430
+ sock = lstatSync3(path);
39431
+ } catch (e) {
39432
+ if (e.code === "ENOENT") return null;
39433
+ return `${path} cannot be checked (${e.code ?? String(e)})`;
39434
+ }
39435
+ try {
39436
+ if (!sock.isSocket()) return `${path} is not a socket`;
39437
+ if (sock.uid !== uid) return `${path} belongs to another user`;
39438
+ const dir = dirname4(path);
39439
+ const st = lstatSync3(dir);
39440
+ if (!st.isDirectory()) return `${dir} is not a folder`;
39441
+ if (st.uid !== uid) return `${dir} belongs to another user`;
39442
+ if (st.mode & 18)
39443
+ return `${dir} is open to other users (mode ${(st.mode & 511).toString(8)})`;
39444
+ } catch (e) {
39445
+ return `${path} cannot be checked (${e.code ?? String(e)})`;
39446
+ }
39447
+ return null;
39448
+ }
39381
39449
  var UnsafeDir = class extends Error {
39382
39450
  };
39383
39451
  var NOTICE_FROM = "[openbus]";
@@ -39387,7 +39455,7 @@ var ClaudeTransport = class {
39387
39455
  this.opts = opts;
39388
39456
  this.#held = opts.heldFile ? new HeldStore(opts.heldFile) : void 0;
39389
39457
  this.#injected = opts.heldFile ? new HeldStore(opts.heldFile.replace(/(\.json)?$/, ".injected.json")) : void 0;
39390
- const sample = join8(opts.socketsDir, "00000000.sock");
39458
+ const sample = join7(opts.socketsDir, "00000000.sock");
39391
39459
  if (Buffer.byteLength(sample) > MAX_SOCKET_PATH) {
39392
39460
  this.#disabled = `claude delivery disabled: return socket paths are too long for a unix socket (${Buffer.byteLength(sample)} > ${MAX_SOCKET_PATH} bytes under ${opts.socketsDir}); use a shorter OPENBUS_HOME`;
39393
39461
  opts.log?.(this.#disabled);
@@ -39402,6 +39470,8 @@ var ClaudeTransport = class {
39402
39470
  /** A status can arrive before the caller starts waiting; keep the latest. */
39403
39471
  #buffered = /* @__PURE__ */ new Map();
39404
39472
  #closed = false;
39473
+ /** Claude sockets already logged as unsafe: each is logged once. */
39474
+ #unsafeLogged = /* @__PURE__ */ new Set();
39405
39475
  #held;
39406
39476
  /** Injected, outcome not yet heard: a restart inside the status window must not inject again. */
39407
39477
  #injected;
@@ -39442,6 +39512,14 @@ var ClaudeTransport = class {
39442
39512
  }
39443
39513
  const target2 = this.opts.target(agent.ref);
39444
39514
  if (!target2) return { ok: false, reason: "closed" };
39515
+ const unsafe = unsafeClaudeSocket(target2.socketPath);
39516
+ if (unsafe) {
39517
+ if (!this.#unsafeLogged.has(target2.socketPath)) {
39518
+ this.#unsafeLogged.add(target2.socketPath);
39519
+ this.opts.log?.(`claude delivery refused: ${unsafe}`);
39520
+ }
39521
+ return { ok: false, reason: "closed", cause: "dropped" };
39522
+ }
39445
39523
  let sink;
39446
39524
  try {
39447
39525
  sink = await this.#sink(agent.ref, mail.namespace, mail.from_name);
@@ -39550,7 +39628,7 @@ var ClaudeTransport = class {
39550
39628
  return sink;
39551
39629
  }
39552
39630
  async #listen(key, agentRef, namespace, peerName, notice = false) {
39553
- const path = join8(this.opts.socketsDir, `${randomUUID().slice(0, 8)}.sock`);
39631
+ const path = join7(this.opts.socketsDir, `${randomUUID().slice(0, 8)}.sock`);
39554
39632
  if (this.opts.prepareDir) {
39555
39633
  const unsafe = this.opts.prepareDir(this.opts.socketsDir);
39556
39634
  if (unsafe) throw new UnsafeDir(unsafe);
@@ -39946,7 +40024,7 @@ async function runDaemon(deps = {}) {
39946
40024
  log,
39947
40025
  promptIdSupported: () => promptIdSupported,
39948
40026
  uncertain: new HeldStore(
39949
- oc.uncertainFile ?? join9(home(), "opencode-uncertain.json")
40027
+ oc.uncertainFile ?? join8(home(), "opencode-uncertain.json")
39950
40028
  )
39951
40029
  });
39952
40030
  const pi = new PiTransport({
@@ -39958,7 +40036,7 @@ async function runDaemon(deps = {}) {
39958
40036
  },
39959
40037
  ackTimeoutMs: deps.pi?.ackTimeoutMs
39960
40038
  });
39961
- const sent = new SentStore(deps.sentFile ?? join9(home(), "sent.json"), {
40039
+ const sent = new SentStore(deps.sentFile ?? join8(home(), "sent.json"), {
39962
40040
  log
39963
40041
  });
39964
40042
  const receipts = new Receipts(sent, { after: deps.deliveredTimer });
@@ -40048,7 +40126,7 @@ async function runDaemon(deps = {}) {
40048
40126
  socketsDir: returnDir,
40049
40127
  // A deps.socketsDir is the caller's (tests); ours is re-checked before each bind.
40050
40128
  prepareDir: cl.socketsDir ? void 0 : (d) => prepareReturnDir(d),
40051
- heldFile: cl.heldFile ?? join9(home(), "claude-held.json"),
40129
+ heldFile: cl.heldFile ?? join8(home(), "claude-held.json"),
40052
40130
  statusWindowMs: cl.statusWindowMs,
40053
40131
  injectTimeoutMs: cl.injectTimeoutMs,
40054
40132
  log,
@@ -40240,13 +40318,21 @@ async function runDaemon(deps = {}) {
40240
40318
  pending.fail(id, error62, "the hub sent a frame this daemon cannot read");
40241
40319
  },
40242
40320
  onRevoked: () => {
40321
+ const saved = savedToken();
40322
+ if (saved !== void 0 && saved !== cfg.machine_token) {
40323
+ log(
40324
+ "the hub refused the token this daemon started with; machine.json holds a newer one: restarting"
40325
+ );
40326
+ process.exitCode = 1;
40327
+ deps.onRevoked?.(true);
40328
+ return;
40329
+ }
40243
40330
  log("this machine was revoked; run `npx @open-bus/cli install`");
40244
40331
  process.exitCode = 1;
40245
40332
  try {
40246
40333
  writeFileSync3(
40247
- deps.revokedFile ?? join9(home(), "revoked"),
40248
- `${JSON.stringify({ at: (/* @__PURE__ */ new Date()).toISOString() })}
40249
- `,
40334
+ deps.revokedFile ?? join8(home(), "revoked"),
40335
+ revokedMarker(cfg.machine_token),
40250
40336
  { mode: 384 }
40251
40337
  );
40252
40338
  } catch (e) {
@@ -40494,11 +40580,11 @@ async function runDaemon(deps = {}) {
40494
40580
  announceSessions();
40495
40581
  }
40496
40582
  }).catch(socketInUse);
40497
- const bound = lstatSync3(listenPath);
40583
+ const bound = lstatSync4(listenPath);
40498
40584
  const socketWatch = setInterval(() => {
40499
40585
  let now;
40500
40586
  try {
40501
- now = lstatSync3(listenPath);
40587
+ now = lstatSync4(listenPath);
40502
40588
  } catch {
40503
40589
  }
40504
40590
  if (now?.ino === bound.ino && now.dev === bound.dev) return;
@@ -40559,7 +40645,7 @@ async function runDaemon(deps = {}) {
40559
40645
  init_src2();
40560
40646
  init_src();
40561
40647
  import { execFileSync as execFileSync4, spawn as spawn2 } from "node:child_process";
40562
- import { closeSync, openSync, readFileSync as readFileSync10 } from "node:fs";
40648
+ import { closeSync as closeSync2, openSync as openSync2, readFileSync as readFileSync9 } from "node:fs";
40563
40649
  import { homedir as homedir2, userInfo } from "node:os";
40564
40650
 
40565
40651
  // ../ui/src/tokens/terminal.ts
@@ -40711,6 +40797,11 @@ function copy(style) {
40711
40797
  waitingPlain: () => `Waiting for approval (up to 10 minutes)${more}`,
40712
40798
  approved: (label) => done(`Approved as ${clip(label, 15)}`),
40713
40799
  tokenSaved: (path, token) => done(`Token saved to ${path}`, tokenTail(token, more)),
40800
+ // `login` saved a new token; the running daemon keeps the old one.
40801
+ daemonOldToken: (pid) => [
40802
+ warn(`The daemon (pid ${pid}) still uses the old token.`),
40803
+ next("Run npx @open-bus/cli install to restart it with the new one.")
40804
+ ],
40714
40805
  alreadyConnected: (label) => done(`Already connected as ${clip(label, 24)}`),
40715
40806
  configured: (names2) => done(
40716
40807
  `Configured ${listing(
@@ -41099,33 +41190,33 @@ var realDeps = {
41099
41190
  };
41100
41191
 
41101
41192
  // src/steps/service.ts
41102
- import { createHash as createHash3 } from "node:crypto";
41193
+ import { createHash as createHash4 } from "node:crypto";
41103
41194
  import {
41104
41195
  chmodSync as chmodSync7,
41105
41196
  cpSync,
41106
41197
  existsSync as existsSync2,
41107
- lstatSync as lstatSync4,
41198
+ lstatSync as lstatSync5,
41108
41199
  mkdirSync as mkdirSync6,
41109
41200
  realpathSync as realpathSync3,
41110
41201
  renameSync as renameSync5,
41111
41202
  rmSync as rmSync4,
41112
41203
  writeFileSync as writeFileSync5
41113
41204
  } from "node:fs";
41114
- import { basename as basename5, dirname as dirname5, isAbsolute as isAbsolute3, join as join10, resolve as resolve3 } from "node:path";
41205
+ import { basename as basename5, dirname as dirname6, isAbsolute as isAbsolute3, join as join9, resolve as resolve3 } from "node:path";
41115
41206
  import { fileURLToPath } from "node:url";
41116
41207
 
41117
41208
  // src/steps/step.ts
41118
41209
  import {
41119
41210
  chmodSync as chmodSync6,
41120
41211
  mkdirSync as mkdirSync5,
41121
- readFileSync as readFileSync9,
41212
+ readFileSync as readFileSync8,
41122
41213
  renameSync as renameSync4,
41123
41214
  writeFileSync as writeFileSync4
41124
41215
  } from "node:fs";
41125
- import { dirname as dirname4 } from "node:path";
41216
+ import { dirname as dirname5 } from "node:path";
41126
41217
  function readInstallFile(path) {
41127
41218
  try {
41128
- const v = JSON.parse(readFileSync9(path, "utf8"));
41219
+ const v = JSON.parse(readFileSync8(path, "utf8"));
41129
41220
  if (typeof v === "object" && v !== null && !Array.isArray(v))
41130
41221
  return v;
41131
41222
  } catch {
@@ -41134,7 +41225,7 @@ function readInstallFile(path) {
41134
41225
  }
41135
41226
  function updateInstallFile(path, patch) {
41136
41227
  const next = { ...readInstallFile(path), ...patch };
41137
- mkdirSync5(dirname4(path), { recursive: true, mode: 448 });
41228
+ mkdirSync5(dirname5(path), { recursive: true, mode: 448 });
41138
41229
  const tmp = `${path}.${process.pid}.tmp`;
41139
41230
  writeFileSync4(tmp, `${JSON.stringify(next, null, 2)}
41140
41231
  `, { mode: 384 });
@@ -41235,7 +41326,7 @@ function cliSource() {
41235
41326
  jiti: import.meta.resolve("jiti")
41236
41327
  } : { kind: "bundle", file: here };
41237
41328
  }
41238
- var entryName = (src) => src.kind === "bundle" ? join10(basename5(dirname5(src.file)), basename5(src.file)) : "open-bus.js";
41329
+ var entryName = (src) => src.kind === "bundle" ? join9(basename5(dirname6(src.file)), basename5(src.file)) : "open-bus.js";
41239
41330
  var shim = (src) => `// Written by open-bus install: runs the sources it was installed from.
41240
41331
  import { createJiti } from ${JSON.stringify(src.jiti)};
41241
41332
 
@@ -41245,35 +41336,35 @@ const code = await main(process.argv.slice(2));
41245
41336
  if (code !== undefined) process.exit(code);
41246
41337
  `;
41247
41338
  function installCli(home2, src) {
41248
- const bin = join10(home2, "bin");
41339
+ const bin = join9(home2, "bin");
41249
41340
  const tmp = `${bin}.${process.pid}.tmp`;
41250
41341
  mkdirSync6(home2, { recursive: true, mode: 448 });
41251
41342
  chmodSync7(home2, 448);
41252
41343
  rmSync4(tmp, { recursive: true, force: true });
41253
41344
  mkdirSync6(tmp);
41254
41345
  if (src.kind === "bundle") {
41255
- const pkg = dirname5(dirname5(src.file));
41346
+ const pkg = dirname6(dirname6(src.file));
41256
41347
  for (const name of ["dist", "assets", "package.json"])
41257
- if (existsSync2(join10(pkg, name)))
41258
- cpSync(join10(pkg, name), join10(tmp, name), { recursive: true });
41259
- } else writeFileSync5(join10(tmp, entryName(src)), shim(src));
41348
+ if (existsSync2(join9(pkg, name)))
41349
+ cpSync(join9(pkg, name), join9(tmp, name), { recursive: true });
41350
+ } else writeFileSync5(join9(tmp, entryName(src)), shim(src));
41260
41351
  chmodSync7(tmp, 448);
41261
- if (!existsSync2(join10(tmp, "package.json")))
41262
- writeFileSync5(join10(tmp, "package.json"), '{ "type": "module" }\n');
41352
+ if (!existsSync2(join9(tmp, "package.json")))
41353
+ writeFileSync5(join9(tmp, "package.json"), '{ "type": "module" }\n');
41263
41354
  rmSync4(bin, { recursive: true, force: true });
41264
41355
  renameSync5(tmp, bin);
41265
- return join10(bin, entryName(src));
41356
+ return join9(bin, entryName(src));
41266
41357
  }
41267
41358
  var present = (path) => {
41268
41359
  try {
41269
- lstatSync4(path);
41360
+ lstatSync5(path);
41270
41361
  return true;
41271
41362
  } catch {
41272
41363
  return false;
41273
41364
  }
41274
41365
  };
41275
41366
  function writeReplacing(path, text3) {
41276
- mkdirSync6(dirname5(path), { recursive: true });
41367
+ mkdirSync6(dirname6(path), { recursive: true });
41277
41368
  const tmp = `${path}.${process.pid}.tmp`;
41278
41369
  try {
41279
41370
  writeFileSync5(tmp, text3, { mode: 420 });
@@ -41288,13 +41379,13 @@ var real = (path) => {
41288
41379
  try {
41289
41380
  return realpathSync3(abs);
41290
41381
  } catch {
41291
- const parent = dirname5(abs);
41292
- return parent === abs ? abs : join10(real(parent), basename5(abs));
41382
+ const parent = dirname6(abs);
41383
+ return parent === abs ? abs : join9(real(parent), basename5(abs));
41293
41384
  }
41294
41385
  };
41295
- var isDefaultHome = (home2, userHome) => real(home2) === real(join10(userHome, ".openbus"));
41386
+ var isDefaultHome = (home2, userHome) => real(home2) === real(join9(userHome, ".openbus"));
41296
41387
  function serviceNames(home2, userHome) {
41297
- const suffix = isDefaultHome(home2, userHome) ? "" : createHash3("sha256").update(real(home2)).digest("hex").slice(0, 8);
41388
+ const suffix = isDefaultHome(home2, userHome) ? "" : createHash4("sha256").update(real(home2)).digest("hex").slice(0, 8);
41298
41389
  return {
41299
41390
  label: suffix ? `${LAUNCHD_LABEL}.${suffix}` : LAUNCHD_LABEL,
41300
41391
  unit: suffix ? `open-bus-${suffix}.service` : SYSTEMD_UNIT
@@ -41319,16 +41410,16 @@ function systemService(d) {
41319
41410
  const manager = d.platform === "darwin" ? "launchd" : d.platform === "linux" ? "systemd" : void 0;
41320
41411
  const home2 = () => resolve3(d.home());
41321
41412
  const names2 = () => serviceNames(home2(), d.userHome);
41322
- const entryOf = () => join10(home2(), "bin", entryName(d.source()));
41323
- const installFile = () => join10(home2(), "install.json");
41413
+ const entryOf = () => join9(home2(), "bin", entryName(d.source()));
41414
+ const installFile = () => join9(home2(), "install.json");
41324
41415
  const record4 = () => {
41325
41416
  const r = readInstallFile(installFile()).service;
41326
41417
  return typeof r === "object" && r !== null ? r : {};
41327
41418
  };
41328
41419
  const xdg = d.env.XDG_CONFIG_HOME;
41329
- const configHome = xdg && isAbsolute3(xdg) ? xdg : join10(d.userHome, ".config");
41420
+ const configHome = xdg && isAbsolute3(xdg) ? xdg : join9(d.userHome, ".config");
41330
41421
  const fileName = () => manager === "launchd" ? `${names2().label}.plist` : names2().unit;
41331
- const fresh = () => manager === "launchd" ? join10(d.userHome, "Library/LaunchAgents", fileName()) : join10(configHome, "systemd/user", fileName());
41422
+ const fresh = () => manager === "launchd" ? join9(d.userHome, "Library/LaunchAgents", fileName()) : join9(configHome, "systemd/user", fileName());
41332
41423
  const recorded = () => {
41333
41424
  const r = record4().unit;
41334
41425
  return typeof r === "string" && isAbsolute3(r) && basename5(r) === fileName() ? r : void 0;
@@ -41393,17 +41484,17 @@ function systemService(d) {
41393
41484
  async ensure() {
41394
41485
  const h = home2();
41395
41486
  const src = d.source();
41396
- const logs2 = join10(h, "logs");
41487
+ const logs2 = join9(h, "logs");
41397
41488
  const u = {
41398
41489
  node: d.execPath,
41399
- entry: join10(h, "bin", entryName(src)),
41490
+ entry: join9(h, "bin", entryName(src)),
41400
41491
  env: {
41401
41492
  PATH: d.env.PATH ?? DEFAULT_PATH,
41402
41493
  ...isDefaultHome(h, d.userHome) ? {} : { OPENBUS_HOME: h }
41403
41494
  },
41404
41495
  // One file: the daemon logs to stderr, and `open-bus logs` tails it.
41405
- out: join10(logs2, "daemon.log"),
41406
- err: join10(logs2, "daemon.log")
41496
+ out: join9(logs2, "daemon.log"),
41497
+ err: join9(logs2, "daemon.log")
41407
41498
  };
41408
41499
  const unit = { ...u, env: { ...u.env, OPENBUS_SERVICE: "1" } };
41409
41500
  renderPlist(unit);
@@ -41474,7 +41565,7 @@ function systemService(d) {
41474
41565
  const node2 = record4().node;
41475
41566
  if (typeof node2 === "string" && !existsSync2(node2))
41476
41567
  out.push({ kind: "node-missing", node: node2 });
41477
- if (manager === "systemd" && !existsSync2(join10(d.lingerDir ?? "/var/lib/systemd/linger", d.user)))
41568
+ if (manager === "systemd" && !existsSync2(join9(d.lingerDir ?? "/var/lib/systemd/linger", d.user)))
41478
41569
  out.push({ kind: "linger-off" });
41479
41570
  return out;
41480
41571
  }
@@ -41487,8 +41578,8 @@ var noService = {
41487
41578
  remove: async () => ({}),
41488
41579
  cli: () => ["open-bus"]
41489
41580
  };
41490
- var VERSION = true ? "0.43.0" : JSON.parse(
41491
- readFileSync10(new URL("../package.json", import.meta.url), "utf8")
41581
+ var VERSION = true ? "0.43.1" : JSON.parse(
41582
+ readFileSync9(new URL("../package.json", import.meta.url), "utf8")
41492
41583
  ).version;
41493
41584
  var which = (cmd) => {
41494
41585
  try {
@@ -41503,7 +41594,7 @@ function processArgs(pid, io = {
41503
41594
  encoding: "utf8",
41504
41595
  stdio: ["ignore", "pipe", "ignore"]
41505
41596
  }),
41506
- proc: (path) => readFileSync10(path, "utf8")
41597
+ proc: (path) => readFileSync9(path, "utf8")
41507
41598
  }) {
41508
41599
  try {
41509
41600
  return io.ps(pid).trim() || void 0;
@@ -41516,8 +41607,8 @@ function processArgs(pid, io = {
41516
41607
  }
41517
41608
  }
41518
41609
  var spawnDaemon = (cmd, args, opts) => {
41519
- const out = openSync(opts.out, "a", 384);
41520
- const err = openSync(opts.err, "a", 384);
41610
+ const out = openSync2(opts.out, "a", 384);
41611
+ const err = openSync2(opts.err, "a", 384);
41521
41612
  try {
41522
41613
  const child = spawn2(cmd, args, {
41523
41614
  detached: true,
@@ -41527,8 +41618,8 @@ var spawnDaemon = (cmd, args, opts) => {
41527
41618
  child.unref();
41528
41619
  return child.pid;
41529
41620
  } finally {
41530
- closeSync(out);
41531
- closeSync(err);
41621
+ closeSync2(out);
41622
+ closeSync2(err);
41532
41623
  }
41533
41624
  };
41534
41625
  var userName = () => {
@@ -41572,7 +41663,7 @@ function realCtx(noColor) {
41572
41663
  uid: process.getuid?.() ?? 0,
41573
41664
  user: userName(),
41574
41665
  source: cliSource,
41575
- daemonPid: () => ctx.status({ path: daemonSocketPath(ctx.home), timeoutMs: 1e3 }).then(
41666
+ daemonPid: () => askDaemon(ctx, { timeoutMs: 1e3 }).then(
41576
41667
  (st) => st.pid,
41577
41668
  () => void 0
41578
41669
  ),
@@ -41587,6 +41678,17 @@ function realCtx(noColor) {
41587
41678
  });
41588
41679
  return ctx;
41589
41680
  }
41681
+ function askDaemon(ctx, opts = {}) {
41682
+ const problem = socketDirProblem(ctx.home);
41683
+ if (problem) return Promise.reject(new Error(problem));
41684
+ return ctx.status({ ...opts, path: daemonSocketPath(ctx.home) });
41685
+ }
41686
+ function socketFolderLines(ctx) {
41687
+ const dirs = shortDirInUse(ctx.home) ? [shortSocketDir(ctx.home), claudeReturnDir(ctx.home)] : [];
41688
+ const bad = dirs.map((d) => ({ d, why: unsafeSocketDir(d) })).find((x) => x.why);
41689
+ if (!bad) return void 0;
41690
+ return bad.why === NOT_OURS ? ctx.copy.socketFolderNotYours(bad.d) : ctx.copy.socketFolderUnsafe(tilde(ctx, bad.d), bad.why);
41691
+ }
41590
41692
  var say = (ctx, ...lines) => {
41591
41693
  for (const l of lines.flat()) ctx.stdout.write(`${l}
41592
41694
  `);
@@ -41597,12 +41699,43 @@ var sayErr = (ctx, ...lines) => {
41597
41699
  };
41598
41700
  var tilde = (ctx, path) => path === ctx.userHome ? "~" : path.startsWith(`${ctx.userHome}/`) ? `~${path.slice(ctx.userHome.length)}` : path;
41599
41701
 
41702
+ // src/machine.ts
41703
+ import { readFileSync as readFileSync10, statSync as statSync5 } from "node:fs";
41704
+ import { join as join10 } from "node:path";
41705
+ init_dist();
41706
+ function readMachine(home2) {
41707
+ const file2 = join10(home2, "machine.json");
41708
+ let text3;
41709
+ let mode;
41710
+ try {
41711
+ mode = statSync5(file2).mode;
41712
+ text3 = readFileSync10(file2, "utf8");
41713
+ } catch (e) {
41714
+ return e.code === "ENOENT" ? { state: "missing" } : { state: "bad" };
41715
+ }
41716
+ try {
41717
+ const m = JSON.parse(text3);
41718
+ if (typeof m.hub === "string" && typeof m.label === "string" && isMachineToken(m.machine_token))
41719
+ return {
41720
+ state: "ok",
41721
+ hub: m.hub,
41722
+ label: m.label,
41723
+ token: m.machine_token,
41724
+ open: process.platform !== "win32" && (mode & 63) !== 0,
41725
+ revoked: revokedFor(m.machine_token, home2)
41726
+ };
41727
+ } catch {
41728
+ }
41729
+ return { state: "bad" };
41730
+ }
41731
+
41600
41732
  // src/commands/daemon.ts
41601
41733
  var lasting = (e) => [...START_ERROR_CODES, "EACCES", "EPERM"].includes(
41602
41734
  e?.code
41603
41735
  );
41604
41736
  async function daemon(ctx, run4 = runDaemon, signals = process) {
41605
- if (existsSync3(join11(ctx.home, "revoked"))) {
41737
+ const m = readMachine(ctx.home);
41738
+ if (existsSync3(join11(ctx.home, "revoked")) && (m.state !== "ok" || m.revoked)) {
41606
41739
  sayErr(ctx, ctx.copy.revoked());
41607
41740
  return 0;
41608
41741
  }
@@ -41621,7 +41754,8 @@ async function daemon(ctx, run4 = runDaemon, signals = process) {
41621
41754
  signals.once("SIGTERM", onSignal);
41622
41755
  run4({
41623
41756
  version: ctx.version,
41624
- onRevoked: () => end(REVOKED_EXIT),
41757
+ // Only an older token was revoked: a restart picks up the new one.
41758
+ onRevoked: (replaced) => end(replaced ? 1 : REVOKED_EXIT),
41625
41759
  // Exit non-zero: the service restarts the daemon, which binds again.
41626
41760
  onSocketLost: () => end(1)
41627
41761
  }).then(
@@ -41642,9 +41776,8 @@ async function daemon(ctx, run4 = runDaemon, signals = process) {
41642
41776
  }
41643
41777
 
41644
41778
  // src/commands/doctor.ts
41645
- init_src2();
41646
- import { readFileSync as readFileSync13 } from "node:fs";
41647
- import { join as join16 } from "node:path";
41779
+ import { readFileSync as readFileSync12 } from "node:fs";
41780
+ import { join as join15 } from "node:path";
41648
41781
 
41649
41782
  // ../adapters/opencode/src/index.ts
41650
41783
  init_session2();
@@ -41654,51 +41787,21 @@ var OPENCODE_TUI_PLUGIN = fileURLToPath2(
41654
41787
  new URL("../assets/opencode-tui/tui.js", import.meta.url)
41655
41788
  );
41656
41789
 
41657
- // src/machine.ts
41658
- init_dist();
41659
- import { existsSync as existsSync4, readFileSync as readFileSync11, statSync as statSync6 } from "node:fs";
41660
- import { join as join12 } from "node:path";
41661
- function readMachine(home2) {
41662
- const file2 = join12(home2, "machine.json");
41663
- let text3;
41664
- let mode;
41665
- try {
41666
- mode = statSync6(file2).mode;
41667
- text3 = readFileSync11(file2, "utf8");
41668
- } catch (e) {
41669
- return e.code === "ENOENT" ? { state: "missing" } : { state: "bad" };
41670
- }
41671
- try {
41672
- const m = JSON.parse(text3);
41673
- if (typeof m.hub === "string" && typeof m.label === "string" && isMachineToken(m.machine_token))
41674
- return {
41675
- state: "ok",
41676
- hub: m.hub,
41677
- label: m.label,
41678
- token: m.machine_token,
41679
- open: process.platform !== "win32" && (mode & 63) !== 0,
41680
- revoked: existsSync4(join12(home2, "revoked"))
41681
- };
41682
- } catch {
41683
- }
41684
- return { state: "bad" };
41685
- }
41686
-
41687
41790
  // src/steps/adapters.ts
41688
41791
  import { randomBytes } from "node:crypto";
41689
41792
  import {
41690
41793
  chmodSync as chmodSync8,
41691
- existsSync as existsSync5,
41692
- lstatSync as lstatSync5,
41794
+ existsSync as existsSync4,
41795
+ lstatSync as lstatSync6,
41693
41796
  mkdirSync as mkdirSync7,
41694
- readFileSync as readFileSync12,
41797
+ readFileSync as readFileSync11,
41695
41798
  readlinkSync,
41696
41799
  renameSync as renameSync6,
41697
41800
  rmSync as rmSync5,
41698
- statSync as statSync7,
41801
+ statSync as statSync6,
41699
41802
  writeFileSync as writeFileSync6
41700
41803
  } from "node:fs";
41701
- import { dirname as dirname6, join as join13, resolve as resolve4 } from "node:path";
41804
+ import { dirname as dirname7, join as join12, resolve as resolve4 } from "node:path";
41702
41805
  import { isDeepStrictEqual } from "node:util";
41703
41806
 
41704
41807
  // ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/scanner.js
@@ -42923,26 +43026,26 @@ var PI_EXTENSION = fileURLToPath3(
42923
43026
  var NAME = "openbus";
42924
43027
  var HARNESSES = ["claude", "opencode", "pi"];
42925
43028
  var readAssets = () => ({
42926
- pi: readFileSync12(PI_EXTENSION, "utf8"),
42927
- opencodePlugin: readFileSync12(OPENCODE_TUI_PLUGIN, "utf8")
43029
+ pi: readFileSync11(PI_EXTENSION, "utf8"),
43030
+ opencodePlugin: readFileSync11(OPENCODE_TUI_PLUGIN, "utf8")
42928
43031
  });
42929
43032
  var paths = (deps) => {
42930
43033
  const env = deps.env ?? {};
42931
- const opencode = env.OPENCODE_CONFIG_DIR ?? join13(env.XDG_CONFIG_HOME ?? join13(deps.home, ".config"), "opencode");
42932
- const openbus = deps.openbusHome ?? join13(deps.home, ".openbus");
43034
+ const opencode = env.OPENCODE_CONFIG_DIR ?? join12(env.XDG_CONFIG_HOME ?? join12(deps.home, ".config"), "opencode");
43035
+ const openbus = deps.openbusHome ?? join12(deps.home, ".openbus");
42933
43036
  return {
42934
- claude: join13(env.CLAUDE_CONFIG_DIR ?? deps.home, ".claude.json"),
43037
+ claude: join12(env.CLAUDE_CONFIG_DIR ?? deps.home, ".claude.json"),
42935
43038
  // OpenCode reads both; edit the one the user has, else create .json.
42936
43039
  opencodeConfigs: [
42937
- join13(opencode, "opencode.json"),
42938
- join13(opencode, "opencode.jsonc")
43040
+ join12(opencode, "opencode.json"),
43041
+ join12(opencode, "opencode.jsonc")
42939
43042
  ],
42940
- opencodeCli: join13(opencode, "cli.json"),
42941
- record: join13(openbus, "install.json"),
43043
+ opencodeCli: join12(opencode, "cli.json"),
43044
+ record: join12(openbus, "install.json"),
42942
43045
  // OpenCode registers the folder that holds tui.js.
42943
- opencodePlugin: join13(openbus, "integrations/opencode", NAME),
42944
- pi: join13(
42945
- env.PI_CODING_AGENT_DIR ?? join13(deps.home, ".pi/agent"),
43046
+ opencodePlugin: join12(openbus, "integrations/opencode", NAME),
43047
+ pi: join12(
43048
+ env.PI_CODING_AGENT_DIR ?? join12(deps.home, ".pi/agent"),
42946
43049
  "extensions/openbus.ts"
42947
43050
  )
42948
43051
  };
@@ -42950,7 +43053,7 @@ var paths = (deps) => {
42950
43053
  function readDoc(path) {
42951
43054
  let text3;
42952
43055
  try {
42953
- text3 = readFileSync12(path, "utf8");
43056
+ text3 = readFileSync11(path, "utf8");
42954
43057
  } catch (e) {
42955
43058
  if (e.code === "ENOENT") return {};
42956
43059
  throw e;
@@ -42965,7 +43068,7 @@ function readDoc(path) {
42965
43068
  }
42966
43069
  function present2(path) {
42967
43070
  try {
42968
- lstatSync5(path);
43071
+ lstatSync6(path);
42969
43072
  return true;
42970
43073
  } catch {
42971
43074
  return false;
@@ -42974,24 +43077,24 @@ function present2(path) {
42974
43077
  function target(path) {
42975
43078
  let p = path;
42976
43079
  for (let hops = 0; hops < 40; hops++) {
42977
- if (!present2(p) || !lstatSync5(p).isSymbolicLink()) {
42978
- if (p !== path && !existsSync5(dirname6(p)))
43080
+ if (!present2(p) || !lstatSync6(p).isSymbolicLink()) {
43081
+ if (p !== path && !existsSync4(dirname7(p)))
42979
43082
  throw new Error(
42980
43083
  `${path} is a dangling symlink to ${p}; left it untouched`
42981
43084
  );
42982
43085
  return p;
42983
43086
  }
42984
- p = resolve4(dirname6(p), readlinkSync(p));
43087
+ p = resolve4(dirname7(p), readlinkSync(p));
42985
43088
  }
42986
43089
  throw new Error(`${path}: too many symlinks; left it untouched`);
42987
43090
  }
42988
43091
  function writeAtomic(path, data, mode) {
42989
43092
  const dest = target(path);
42990
- mkdirSync7(dirname6(dest), { recursive: true });
43093
+ mkdirSync7(dirname7(dest), { recursive: true });
42991
43094
  let m = mode ?? 420;
42992
43095
  if (mode === void 0)
42993
43096
  try {
42994
- m = statSync7(dest).mode & 511;
43097
+ m = statSync6(dest).mode & 511;
42995
43098
  } catch {
42996
43099
  }
42997
43100
  const tmp = `${dest}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
@@ -43007,7 +43110,7 @@ function writeAtomic(path, data, mode) {
43007
43110
  function readJsonc(path) {
43008
43111
  let text3;
43009
43112
  try {
43010
- text3 = readFileSync12(path, "utf8");
43113
+ text3 = readFileSync11(path, "utf8");
43011
43114
  } catch (e) {
43012
43115
  if (e.code === "ENOENT") return "";
43013
43116
  throw e;
@@ -43024,7 +43127,7 @@ function saveText(path, before, next, ok) {
43024
43127
  }
43025
43128
  function readRecord(path) {
43026
43129
  try {
43027
- const v = JSON.parse(readFileSync12(path, "utf8"));
43130
+ const v = JSON.parse(readFileSync11(path, "utf8"));
43028
43131
  const c = v?.created;
43029
43132
  if (typeof c === "object" && c !== null) return c;
43030
43133
  } catch {
@@ -43035,7 +43138,7 @@ function writeRecord(path, before, created) {
43035
43138
  if (isDeepStrictEqual(before, created)) return;
43036
43139
  let rest = {};
43037
43140
  try {
43038
- const v = JSON.parse(readFileSync12(path, "utf8"));
43141
+ const v = JSON.parse(readFileSync11(path, "utf8"));
43039
43142
  if (typeof v === "object" && v !== null && !Array.isArray(v))
43040
43143
  rest = v;
43041
43144
  } catch {
@@ -43142,7 +43245,7 @@ var install = {
43142
43245
  created[p.opencodeCli] = add(p.opencodeCli, madeCli);
43143
43246
  writeRecord(p.record, record4, created);
43144
43247
  writeAtomic(
43145
- join13(p.opencodePlugin, "tui.js"),
43248
+ join12(p.opencodePlugin, "tui.js"),
43146
43249
  deps.assets.opencodePlugin,
43147
43250
  420
43148
43251
  );
@@ -43205,7 +43308,7 @@ var uninstall = {
43205
43308
  const left = { ...record4 };
43206
43309
  for (const { file: file2 } of edits) delete left[file2];
43207
43310
  writeRecord(p.record, record4, left);
43208
- const hadPlugin = existsSync5(p.opencodePlugin);
43311
+ const hadPlugin = existsSync4(p.opencodePlugin);
43209
43312
  rmSync5(p.opencodePlugin, { recursive: true, force: true });
43210
43313
  if (!saved.some(Boolean) && !hadPlugin) return "none";
43211
43314
  if (deps.which("opencode")) await restartOpencode(deps, notes);
@@ -43213,7 +43316,7 @@ var uninstall = {
43213
43316
  },
43214
43317
  async pi(deps) {
43215
43318
  const path = paths(deps).pi;
43216
- if (!existsSync5(path)) return "none";
43319
+ if (!existsSync4(path)) return "none";
43217
43320
  rmSync5(path, { force: true });
43218
43321
  return "done";
43219
43322
  }
@@ -43278,14 +43381,14 @@ function checkAdapters(deps) {
43278
43381
  opencode: state(
43279
43382
  "opencode",
43280
43383
  () => p.opencodeConfigs.filter(present2).some((f) => {
43281
- const d = parseJsonc(readFileSync12(f, "utf8"), f);
43384
+ const d = parseJsonc(readFileSync11(f, "utf8"), f);
43282
43385
  return servers(d)?.[NAME] !== void 0 || d.mcp?.[NAME] !== void 0;
43283
43386
  }) && listed(
43284
- parseJsonc(readFileSync12(p.opencodeCli, "utf8"), p.opencodeCli),
43387
+ parseJsonc(readFileSync11(p.opencodeCli, "utf8"), p.opencodeCli),
43285
43388
  p.opencodePlugin
43286
- ) && existsSync5(join13(p.opencodePlugin, "tui.js"))
43389
+ ) && existsSync4(join12(p.opencodePlugin, "tui.js"))
43287
43390
  ),
43288
- pi: state("pi", () => existsSync5(p.pi))
43391
+ pi: state("pi", () => existsSync4(p.pi))
43289
43392
  };
43290
43393
  }
43291
43394
 
@@ -43294,16 +43397,16 @@ init_dist();
43294
43397
  import { randomBytes as randomBytes2 } from "node:crypto";
43295
43398
  import {
43296
43399
  chmodSync as chmodSync9,
43297
- closeSync as closeSync2,
43400
+ closeSync as closeSync3,
43298
43401
  mkdirSync as mkdirSync8,
43299
- openSync as openSync2,
43402
+ openSync as openSync3,
43300
43403
  renameSync as renameSync7,
43301
43404
  rmSync as rmSync6,
43302
43405
  unlinkSync,
43303
43406
  writeSync
43304
43407
  } from "node:fs";
43305
43408
  import { hostname as hostname3 } from "node:os";
43306
- import { join as join14 } from "node:path";
43409
+ import { join as join13 } from "node:path";
43307
43410
  var LoginFailed = class extends Error {
43308
43411
  constructor(kind2, message, detail = {}) {
43309
43412
  super(message);
@@ -43336,19 +43439,19 @@ function checkVerificationUri(uri, hub, userCode) {
43336
43439
  function writeMachineFile(home2, body) {
43337
43440
  mkdirSync8(home2, { recursive: true, mode: 448 });
43338
43441
  chmodSync9(home2, 448);
43339
- const tmp = join14(home2, `.machine.json.${randomBytes2(8).toString("hex")}.tmp`);
43340
- const fd = openSync2(tmp, "wx", 384);
43442
+ const tmp = join13(home2, `.machine.json.${randomBytes2(8).toString("hex")}.tmp`);
43443
+ const fd = openSync3(tmp, "wx", 384);
43341
43444
  try {
43342
43445
  writeSync(fd, body);
43343
43446
  } catch (e) {
43344
- closeSync2(fd);
43447
+ closeSync3(fd);
43345
43448
  unlinkSync(tmp);
43346
43449
  throw e;
43347
43450
  }
43348
- closeSync2(fd);
43451
+ closeSync3(fd);
43349
43452
  try {
43350
43453
  chmodSync9(tmp, 384);
43351
- renameSync7(tmp, join14(home2, "machine.json"));
43454
+ renameSync7(tmp, join13(home2, "machine.json"));
43352
43455
  } catch (e) {
43353
43456
  unlinkSync(tmp);
43354
43457
  throw e;
@@ -43472,7 +43575,7 @@ async function login(args) {
43472
43575
  `${JSON.stringify({ hub, machine_id: poll.machine_id, label, machine_token: poll.token }, null, 2)}
43473
43576
  `
43474
43577
  );
43475
- rmSync6(join14(args.home, "revoked"), { force: true });
43578
+ rmSync6(join13(args.home, "revoked"), { force: true });
43476
43579
  if (!events?.code) print(`Approved this machine as ${label}.`);
43477
43580
  return {
43478
43581
  machineToken: poll.token,
@@ -43492,12 +43595,11 @@ async function login(args) {
43492
43595
  }
43493
43596
 
43494
43597
  // src/commands/status.ts
43495
- init_src2();
43496
43598
  init_src();
43497
43599
 
43498
43600
  // src/commands/install.ts
43499
43601
  init_src2();
43500
- import { join as join15 } from "node:path";
43602
+ import { join as join14 } from "node:path";
43501
43603
 
43502
43604
  // src/live.ts
43503
43605
  var FRAME_MS = 80;
@@ -43624,7 +43726,7 @@ async function loginStep(ctx, opts) {
43624
43726
  ctx,
43625
43727
  c.approved(result.label),
43626
43728
  c.tokenSaved(
43627
- tilde(ctx, join15(ctx.home, "machine.json")),
43729
+ tilde(ctx, join14(ctx.home, "machine.json")),
43628
43730
  result.machineToken
43629
43731
  ),
43630
43732
  ""
@@ -43684,15 +43786,14 @@ function shownSocket(ctx) {
43684
43786
  const real2 = `${canonicalHome(ctx.home)}/`;
43685
43787
  return tilde(
43686
43788
  ctx,
43687
- path.startsWith(real2) ? join15(ctx.home, path.slice(real2.length)) : path
43789
+ path.startsWith(real2) ? join14(ctx.home, path.slice(real2.length)) : path
43688
43790
  );
43689
43791
  }
43690
43792
  async function waitForDaemon(ctx) {
43691
43793
  const start = ctx.now();
43692
- const path = daemonSocketPath(ctx.home);
43693
43794
  for (; ; ) {
43694
43795
  try {
43695
- return await ctx.status({ path, cwd: ctx.cwd, timeoutMs: 1e3 });
43796
+ return await askDaemon(ctx, { cwd: ctx.cwd, timeoutMs: 1e3 });
43696
43797
  } catch {
43697
43798
  }
43698
43799
  if (ctx.now() - start >= DAEMON_WAIT_MS) return void 0;
@@ -43706,9 +43807,10 @@ async function daemonStep(ctx) {
43706
43807
  sayErr(ctx, c.daemonInTheWay(shownSocket(ctx), running));
43707
43808
  return false;
43708
43809
  }
43709
- const st = await waitForDaemon(ctx);
43810
+ const unsafe = socketFolderLines(ctx);
43811
+ const st = unsafe ? void 0 : await waitForDaemon(ctx);
43710
43812
  if (!st) {
43711
- sayErr(ctx, c.daemonTimeout());
43813
+ sayErr(ctx, unsafe ?? c.daemonTimeout());
43712
43814
  return false;
43713
43815
  }
43714
43816
  say(ctx, c.daemonRunning(st.pid, ctx.service.kind, ctx.service.fallback), "");
@@ -43779,10 +43881,7 @@ var installSteps = (opts) => [
43779
43881
  action: "Run npx @open-bus/cli to start it.",
43780
43882
  check: async (ctx) => {
43781
43883
  try {
43782
- await ctx.status({
43783
- path: daemonSocketPath(ctx.home),
43784
- timeoutMs: 1e3
43785
- });
43884
+ await askDaemon(ctx, { timeoutMs: 1e3 });
43786
43885
  return "done";
43787
43886
  } catch {
43788
43887
  return "todo";
@@ -43804,7 +43903,7 @@ async function install2(opts, ctx) {
43804
43903
  return results.every((r) => r.state === "done") ? 0 : 1;
43805
43904
  }
43806
43905
  const ok = await runSteps(steps, ctx, {
43807
- path: join15(ctx.home, "install.json"),
43906
+ path: join14(ctx.home, "install.json"),
43808
43907
  now: ctx.now
43809
43908
  });
43810
43909
  return ok ? 0 : 1;
@@ -43834,12 +43933,9 @@ async function status(ctx) {
43834
43933
  }
43835
43934
  let st;
43836
43935
  try {
43837
- st = await ctx.status({
43838
- path: daemonSocketPath(ctx.home),
43839
- timeoutMs: 3e3
43840
- });
43936
+ st = await askDaemon(ctx, { timeoutMs: 3e3 });
43841
43937
  } catch {
43842
- sayErr(ctx, c.statusDaemonDown());
43938
+ sayErr(ctx, socketFolderLines(ctx) ?? c.statusDaemonDown());
43843
43939
  return 1;
43844
43940
  }
43845
43941
  say(ctx, c.daemonRunning(st.pid, ctx.service.kind, ctx.service.fallback));
@@ -43876,7 +43972,7 @@ async function healthz(ctx, hub) {
43876
43972
  function claudeIsolates(path) {
43877
43973
  let text3;
43878
43974
  try {
43879
- text3 = readFileSync13(path, "utf8");
43975
+ text3 = readFileSync12(path, "utf8");
43880
43976
  } catch {
43881
43977
  return void 0;
43882
43978
  }
@@ -43905,16 +44001,13 @@ async function doctor(ctx) {
43905
44001
  const node2 = ctx.nodeVersion.replace(/^v/, "");
43906
44002
  if (Number(node2.split(".")[0]) >= MIN_NODE) pass(c.nodeOk(node2));
43907
44003
  else fail(c.nodeOld(node2));
43908
- const machineFile = tilde(ctx, join16(ctx.home, "machine.json"));
44004
+ const machineFile = tilde(ctx, join15(ctx.home, "machine.json"));
43909
44005
  const m = readMachine(ctx.home);
43910
44006
  if (m.state !== "ok") fail(c.noCredentials(machineFile));
43911
44007
  else if (m.revoked) fail(c.revokedCheck());
43912
44008
  else pass(c.credentials(machineFile, m.token));
43913
44009
  try {
43914
- const st = await ctx.status({
43915
- path: daemonSocketPath(ctx.home),
43916
- timeoutMs: 3e3
43917
- });
44010
+ const st = await askDaemon(ctx, { timeoutMs: 3e3 });
43918
44011
  const lines = c.daemonRunning(
43919
44012
  st.pid,
43920
44013
  ctx.service.kind,
@@ -43923,11 +44016,7 @@ async function doctor(ctx) {
43923
44016
  if (ctx.service.kind) pass(lines[0]);
43924
44017
  else warn(lines);
43925
44018
  } catch {
43926
- const dirs = shortDirInUse(ctx.home) ? [shortSocketDir(ctx.home), claudeReturnDir(ctx.home)] : [];
43927
- const bad = dirs.map((d) => ({ d, why: unsafeSocketDir(d) })).find((x) => x.why);
43928
- fail(
43929
- !bad ? c.daemonNotRunning() : bad.why === NOT_OURS ? c.socketFolderNotYours(bad.d) : c.socketFolderUnsafe(tilde(ctx, bad.d), bad.why)
43930
- );
44019
+ fail(socketFolderLines(ctx) ?? c.daemonNotRunning());
43931
44020
  }
43932
44021
  for (const p of ctx.service.problems?.() ?? [])
43933
44022
  if (p.kind === "node-missing") fail(c.serviceNodeMissing(p.node));
@@ -43961,8 +44050,8 @@ async function doctor(ctx) {
43961
44050
  if (wiring[h] === "configured") pass(c.wired(h, version2));
43962
44051
  else fail(c.notWired(h));
43963
44052
  if (h === "claude") {
43964
- const settings = join16(
43965
- ctx.env.CLAUDE_CONFIG_DIR ?? join16(ctx.userHome, ".claude"),
44053
+ const settings = join15(
44054
+ ctx.env.CLAUDE_CONFIG_DIR ?? join15(ctx.userHome, ".claude"),
43966
44055
  "settings.json"
43967
44056
  );
43968
44057
  const isolates = claudeIsolates(settings);
@@ -43975,14 +44064,14 @@ async function doctor(ctx) {
43975
44064
  }
43976
44065
 
43977
44066
  // src/commands/logs.ts
43978
- import { readFileSync as readFileSync14 } from "node:fs";
43979
- import { join as join17 } from "node:path";
44067
+ import { readFileSync as readFileSync13 } from "node:fs";
44068
+ import { join as join16 } from "node:path";
43980
44069
  var TAIL = 50;
43981
44070
  async function logs(ctx) {
43982
- const path = join17(ctx.home, "logs", "daemon.log");
44071
+ const path = join16(ctx.home, "logs", "daemon.log");
43983
44072
  let text3;
43984
44073
  try {
43985
- text3 = readFileSync14(path, "utf8");
44074
+ text3 = readFileSync13(path, "utf8");
43986
44075
  } catch {
43987
44076
  say(ctx, ctx.copy.noLog(tilde(ctx, path)));
43988
44077
  return 1;
@@ -44007,13 +44096,12 @@ async function mcp(harness, ctx, load = (h) => MCP_SERVER[h]()) {
44007
44096
  }
44008
44097
 
44009
44098
  // src/commands/uninstall.ts
44010
- init_src2();
44011
- import { join as join19 } from "node:path";
44099
+ import { join as join18 } from "node:path";
44012
44100
 
44013
44101
  // src/steps/purge.ts
44014
44102
  init_src2();
44015
- import { lstatSync as lstatSync6, readdirSync as readdirSync3, rmdirSync, rmSync as rmSync7 } from "node:fs";
44016
- import { join as join18 } from "node:path";
44103
+ import { lstatSync as lstatSync7, readdirSync as readdirSync3, rmdirSync, rmSync as rmSync7 } from "node:fs";
44104
+ import { join as join17 } from "node:path";
44017
44105
  var FILES = [
44018
44106
  "machine.json",
44019
44107
  "install.json",
@@ -44045,7 +44133,7 @@ var FOLDERS = [
44045
44133
  ];
44046
44134
  function kind(path) {
44047
44135
  try {
44048
- const st = lstatSync6(path);
44136
+ const st = lstatSync7(path);
44049
44137
  return st.isDirectory() ? "dir" : st.isSocket() ? "socket" : "other";
44050
44138
  } catch {
44051
44139
  return void 0;
@@ -44062,14 +44150,14 @@ var rmdirIfEmpty = (path) => {
44062
44150
  };
44063
44151
  function purgeShort(dir, removed) {
44064
44152
  if (kind(dir) !== "dir" || unsafeSocketDir(dir)) return;
44065
- const ret = join18(dir, "claude-return");
44153
+ const ret = join17(dir, "claude-return");
44066
44154
  for (const [d, ours] of [
44067
44155
  [ret, (_n, p) => kind(p) === "socket"],
44068
44156
  [dir, (n) => /^daemon\.sock(\.keep-\d+)?$/.test(n)]
44069
44157
  ]) {
44070
44158
  if (kind(d) !== "dir") continue;
44071
44159
  for (const name of readdirSync3(d)) {
44072
- const path = join18(d, name);
44160
+ const path = join17(d, name);
44073
44161
  const k = kind(path);
44074
44162
  if (k === void 0 || k === "dir" || !ours(name, path)) continue;
44075
44163
  remove(path, k);
@@ -44094,21 +44182,21 @@ function purge(home2, opts) {
44094
44182
  ...FILES,
44095
44183
  ...entries.filter((n) => TEMP.some((re) => re.test(n)))
44096
44184
  ]) {
44097
- const path = join18(home2, name);
44185
+ const path = join17(home2, name);
44098
44186
  const k = kind(path);
44099
44187
  if (k === void 0 || k === "dir") continue;
44100
44188
  remove(path, k);
44101
44189
  removed.push(name);
44102
44190
  }
44103
44191
  for (const folder of FOLDERS) {
44104
- const dir = join18(home2, folder.path);
44192
+ const dir = join17(home2, folder.path);
44105
44193
  if (kind(dir) !== "dir") continue;
44106
44194
  for (const name of readdirSync3(dir)) {
44107
- const path = join18(dir, name);
44195
+ const path = join17(dir, name);
44108
44196
  const k = kind(path);
44109
44197
  if (k === void 0 || !folder.ours(name, path)) continue;
44110
44198
  remove(path, k);
44111
- removed.push(join18(folder.path, name));
44199
+ removed.push(join17(folder.path, name));
44112
44200
  }
44113
44201
  if (rmdirIfEmpty(dir)) removed.push(folder.path);
44114
44202
  }
@@ -44147,18 +44235,18 @@ async function uninstall2(opts, ctx) {
44147
44235
  r.opencodeRestarted ? c.restartedUnload() : c.opencodeNotRunningUnload()
44148
44236
  );
44149
44237
  if (!opts.purge) {
44150
- say(ctx, "", c.kept(tilde(ctx, join19(ctx.home, "machine.json"))));
44238
+ say(ctx, "", c.kept(tilde(ctx, join18(ctx.home, "machine.json"))));
44151
44239
  return 0;
44152
44240
  }
44153
44241
  const home2 = tilde(ctx, ctx.home);
44154
44242
  try {
44155
- await ctx.status({ path: daemonSocketPath(ctx.home), timeoutMs: 1e3 });
44243
+ await askDaemon(ctx, { timeoutMs: 1e3 });
44156
44244
  sayErr(ctx, c.purgeDaemonRunning(home2));
44157
44245
  return 1;
44158
44246
  } catch {
44159
44247
  }
44160
44248
  const out = purge(ctx.home, {
44161
- isDefault: ctx.home === join19(ctx.userHome, ".openbus")
44249
+ isDefault: ctx.home === join18(ctx.userHome, ".openbus")
44162
44250
  });
44163
44251
  if ("refused" in out) {
44164
44252
  sayErr(ctx, c.purgeRefused(home2));
@@ -44287,13 +44375,21 @@ async function dispatch(cmd, ctx) {
44287
44375
  { hub: cmd.hub, noOpen: cmd.noOpen, check: cmd.check },
44288
44376
  ctx
44289
44377
  );
44290
- case "login":
44378
+ case "login": {
44291
44379
  say(ctx, ctx.copy.header(ctx.version), "");
44292
- return await loginStep(ctx, {
44380
+ const ok = await loginStep(ctx, {
44293
44381
  hub: cmd.hub,
44294
44382
  noOpen: cmd.noOpen,
44295
44383
  force: true
44296
- }) ? 0 : 1;
44384
+ });
44385
+ if (!ok) return 1;
44386
+ const pid = await askDaemon(ctx, { timeoutMs: 1e3 }).then(
44387
+ (st) => st.pid,
44388
+ () => void 0
44389
+ );
44390
+ if (pid !== void 0) say(ctx, ctx.copy.daemonOldToken(pid));
44391
+ return 0;
44392
+ }
44297
44393
  case "daemon":
44298
44394
  if (cmd.home) process.env.OPENBUS_HOME = ctx.home;
44299
44395
  if (cmd.hub) process.env.OPENBUS_HUB = cmd.hub;