@open-artifacts/bus 0.127.0 → 0.129.0

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.
package/dist/index.js CHANGED
@@ -4586,7 +4586,7 @@ function isRef(value) {
4586
4586
  function cloneIssues(issues) {
4587
4587
  return issues.map((iss) => iss.path ? { ...iss, path: iss.path.slice() } : { ...iss });
4588
4588
  }
4589
- function isRecursive(inst, stack, resolve8) {
4589
+ function isRecursive(inst, stack, resolve9) {
4590
4590
  const cached2 = recursive.get(inst);
4591
4591
  if (cached2 !== void 0)
4592
4592
  return cached2 ? PROVEN : NONE;
@@ -4596,7 +4596,7 @@ function isRecursive(inst, stack, resolve8) {
4596
4596
  let result = NONE;
4597
4597
  const check2 = (child) => {
4598
4598
  if (result !== PROVEN && child?._zod) {
4599
- const answer = isRecursive(child, stack, resolve8);
4599
+ const answer = isRecursive(child, stack, resolve9);
4600
4600
  if (answer > result)
4601
4601
  result = answer;
4602
4602
  }
@@ -4607,7 +4607,7 @@ function isRecursive(inst, stack, resolve8) {
4607
4607
  const desc = Object.getOwnPropertyDescriptor(sh, key2);
4608
4608
  if (spread && !desc.enumerable)
4609
4609
  continue;
4610
- const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve8) : NONE;
4610
+ const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve9) : NONE;
4611
4611
  if (child > answer)
4612
4612
  answer = child;
4613
4613
  }
@@ -4671,7 +4671,7 @@ function isRecursive(inst, stack, resolve8) {
4671
4671
  break;
4672
4672
  // `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
4673
4673
  case "lazy": {
4674
- const inner = def._cachedInner ?? (resolve8 ? inst._zod.innerType : void 0);
4674
+ const inner = def._cachedInner ?? (resolve9 ? inst._zod.innerType : void 0);
4675
4675
  merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
4676
4676
  break;
4677
4677
  }
@@ -23038,7 +23038,7 @@ var init_protocol = __esm({
23038
23038
  return;
23039
23039
  }
23040
23040
  const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
23041
- await new Promise((resolve8) => setTimeout(resolve8, pollInterval));
23041
+ await new Promise((resolve9) => setTimeout(resolve9, pollInterval));
23042
23042
  options?.signal?.throwIfAborted();
23043
23043
  }
23044
23044
  } catch (error62) {
@@ -23055,7 +23055,7 @@ var init_protocol = __esm({
23055
23055
  */
23056
23056
  request(request, resultSchema, options) {
23057
23057
  const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
23058
- return new Promise((resolve8, reject) => {
23058
+ return new Promise((resolve9, reject) => {
23059
23059
  const earlyReject = (error62) => {
23060
23060
  reject(error62);
23061
23061
  };
@@ -23133,7 +23133,7 @@ var init_protocol = __esm({
23133
23133
  if (!parseResult.success) {
23134
23134
  reject(parseResult.error);
23135
23135
  } else {
23136
- resolve8(parseResult.data);
23136
+ resolve9(parseResult.data);
23137
23137
  }
23138
23138
  } catch (error62) {
23139
23139
  reject(error62);
@@ -23395,12 +23395,12 @@ var init_protocol = __esm({
23395
23395
  }
23396
23396
  } catch {
23397
23397
  }
23398
- return new Promise((resolve8, reject) => {
23398
+ return new Promise((resolve9, reject) => {
23399
23399
  if (signal.aborted) {
23400
23400
  reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
23401
23401
  return;
23402
23402
  }
23403
- const timeoutId = setTimeout(resolve8, interval);
23403
+ const timeoutId = setTimeout(resolve9, interval);
23404
23404
  signal.addEventListener("abort", () => {
23405
23405
  clearTimeout(timeoutId);
23406
23406
  reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
@@ -26427,7 +26427,7 @@ var require_compile = __commonJS({
26427
26427
  const schOrFunc = root.refs[ref];
26428
26428
  if (schOrFunc)
26429
26429
  return schOrFunc;
26430
- let _sch = resolve8.call(this, root, ref);
26430
+ let _sch = resolve9.call(this, root, ref);
26431
26431
  if (_sch === void 0) {
26432
26432
  const schema = (_a3 = root.localRefs) === null || _a3 === void 0 ? void 0 : _a3[ref];
26433
26433
  const { schemaId } = this.opts;
@@ -26454,7 +26454,7 @@ var require_compile = __commonJS({
26454
26454
  function sameSchemaEnv(s1, s2) {
26455
26455
  return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
26456
26456
  }
26457
- function resolve8(root, ref) {
26457
+ function resolve9(root, ref) {
26458
26458
  let sch;
26459
26459
  while (typeof (sch = this.refs[ref]) == "string")
26460
26460
  ref = sch;
@@ -27284,7 +27284,7 @@ var require_fast_uri = __commonJS({
27284
27284
  }
27285
27285
  return uri;
27286
27286
  }
27287
- function resolve8(baseURI, relativeURI, options) {
27287
+ function resolve9(baseURI, relativeURI, options) {
27288
27288
  const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
27289
27289
  const {
27290
27290
  parsed: baseParsed,
@@ -27653,7 +27653,7 @@ var require_fast_uri = __commonJS({
27653
27653
  var fastUri = {
27654
27654
  SCHEMES,
27655
27655
  normalize,
27656
- resolve: resolve8,
27656
+ resolve: resolve9,
27657
27657
  resolveComponent,
27658
27658
  equal,
27659
27659
  serialize,
@@ -31399,7 +31399,16 @@ var init_caps = __esm({
31399
31399
  * A client also lists it to have the hub hand an address over on `agent_up`
31400
31400
  * `replaces` (a /clear).
31401
31401
  */
31402
- mailbox: "mailbox"
31402
+ mailbox: "mailbox",
31403
+ /**
31404
+ * Project links (#1567): the client understands roster rows and routing
31405
+ * across the namespaces its member linked (each row carries its own
31406
+ * `namespace`; a name in two linked namespaces is `ambiguous` until the
31407
+ * send names `to_namespace`). The hub widens a socket's roster and routing
31408
+ * only when its hello listed it, and lists it in `hello_ok.caps`; any other
31409
+ * socket sees today's isolation.
31410
+ */
31411
+ links: "links"
31403
31412
  };
31404
31413
  MAX_CAPS = 16;
31405
31414
  CapTokenSchema = external_exports.string().regex(/^[a-z][a-z0-9_-]{0,31}$/);
@@ -32409,11 +32418,20 @@ var init_frames = __esm({
32409
32418
  late = { late: external_exports.array(external_exports.string().min(1)).optional() };
32410
32419
  isWellFormed2 = (s) => s.isWellFormed();
32411
32420
  WELL_FORMED = { message: "text is not well-formed unicode" };
32412
- CLIENT_VERSION = true ? "0.127.0" : "0.0.0";
32421
+ CLIENT_VERSION = true ? "0.129.0" : "0.0.0";
32413
32422
  clientVersion = {
32414
32423
  client_version: external_exports.string().min(1).max(64).optional()
32415
32424
  };
32416
- ADAPTER_CAPS = { mailbox: "mailbox" };
32425
+ ADAPTER_CAPS = {
32426
+ mailbox: "mailbox",
32427
+ /**
32428
+ * `pending` (#1525): a `config_files` entry with `state: "pending"`, a
32429
+ * namespace waiting for the user's approval. An older strict decoder would
32430
+ * reject the whole frame on it, so the daemon sends it only to a client that
32431
+ * listed this.
32432
+ */
32433
+ pending: "pending"
32434
+ };
32417
32435
  Hello2 = external_exports.object({
32418
32436
  ...base2,
32419
32437
  ...clientVersion,
@@ -32514,7 +32532,9 @@ var init_frames = __esm({
32514
32532
  ...base2,
32515
32533
  ...clientVersion,
32516
32534
  type: external_exports.literal("status"),
32517
- cwd: external_exports.string().min(1).max(4096).optional()
32535
+ cwd: external_exports.string().min(1).max(4096).optional(),
32536
+ /** What this client can decode (ADAPTER_CAPS); absent means none. */
32537
+ caps: external_exports.array(external_exports.string().max(32)).max(16).optional()
32518
32538
  });
32519
32539
  AdapterFrame = external_exports.discriminatedUnion("type", [
32520
32540
  Hello2,
@@ -32527,7 +32547,8 @@ var init_frames = __esm({
32527
32547
  ]);
32528
32548
  ConfigFile = external_exports.object({
32529
32549
  file: external_exports.string(),
32530
- state: external_exports.enum(["refused", "noted"]),
32550
+ /** `pending` (#1525) goes only to clients that listed ADAPTER_CAPS.pending. */
32551
+ state: external_exports.enum(["refused", "noted", "pending"]),
32531
32552
  reason: external_exports.string(),
32532
32553
  fix: external_exports.string()
32533
32554
  });
@@ -32731,8 +32752,8 @@ var init_lines = __esm({
32731
32752
  import { connect } from "node:net";
32732
32753
  async function connectDaemon(opts) {
32733
32754
  const sock = connect(opts.path);
32734
- await new Promise((resolve8, reject) => {
32735
- sock.once("connect", resolve8);
32755
+ await new Promise((resolve9, reject) => {
32756
+ sock.once("connect", resolve9);
32736
32757
  sock.once("error", reject);
32737
32758
  });
32738
32759
  const decoder = new LineDecoder();
@@ -32792,8 +32813,8 @@ async function connectDaemon(opts) {
32792
32813
  sock.on("error", (e) => failAll(e));
32793
32814
  sock.on("close", () => failAll(new Error("daemon connection closed")));
32794
32815
  let timer;
32795
- const welcomeRaw = await new Promise((resolve8, reject) => {
32796
- waiters.push({ resolve: resolve8, reject });
32816
+ const welcomeRaw = await new Promise((resolve9, reject) => {
32817
+ waiters.push({ resolve: resolve9, reject });
32797
32818
  timer = setTimeout(() => {
32798
32819
  reject(new Error("daemon did not answer hello"));
32799
32820
  sock.destroy();
@@ -32815,7 +32836,7 @@ async function connectDaemon(opts) {
32815
32836
  if (state === "closed")
32816
32837
  return Promise.reject(new Error("daemon connection closed"));
32817
32838
  const id = partial2.id ?? String(++seq2);
32818
- return new Promise((resolve8, reject) => {
32839
+ return new Promise((resolve9, reject) => {
32819
32840
  const ms = opts.requestTimeoutMs ?? 2e4;
32820
32841
  const timer2 = setTimeout(() => {
32821
32842
  if (pending.delete(id))
@@ -32830,7 +32851,7 @@ async function connectDaemon(opts) {
32830
32851
  clearTimeout(timer2);
32831
32852
  f(...a);
32832
32853
  };
32833
- pending.set(id, { resolve: done(resolve8), reject: done(reject) });
32854
+ pending.set(id, { resolve: done(resolve9), reject: done(reject) });
32834
32855
  sock.write(`${JSON.stringify({ v: 1, ...partial2, id })}
32835
32856
  `);
32836
32857
  });
@@ -32854,7 +32875,7 @@ async function connectDaemon(opts) {
32854
32875
  };
32855
32876
  }
32856
32877
  function daemonStatus(opts) {
32857
- return new Promise((resolve8, reject) => {
32878
+ return new Promise((resolve9, reject) => {
32858
32879
  const sock = connect(opts.path);
32859
32880
  const decoder = new LineDecoder();
32860
32881
  const done = (f) => {
@@ -32883,7 +32904,7 @@ function daemonStatus(opts) {
32883
32904
  sock.once(
32884
32905
  "connect",
32885
32906
  () => sock.write(
32886
- `${JSON.stringify({ v: 1, id: "status", type: "status", client_version: CLIENT_VERSION, ...opts.cwd ? { cwd: opts.cwd } : {} })}
32907
+ `${JSON.stringify({ v: 1, id: "status", type: "status", client_version: CLIENT_VERSION, caps: [ADAPTER_CAPS.pending], ...opts.cwd ? { cwd: opts.cwd } : {} })}
32887
32908
  `
32888
32909
  )
32889
32910
  );
@@ -32891,7 +32912,7 @@ function daemonStatus(opts) {
32891
32912
  try {
32892
32913
  for (const raw of decoder.push(chunk)) {
32893
32914
  const f = DaemonFrame.parse(raw);
32894
- if (f.type === "status") return done(() => resolve8(f));
32915
+ if (f.type === "status") return done(() => resolve9(f));
32895
32916
  if (f.type === "error")
32896
32917
  return done(
32897
32918
  () => reject(
@@ -33056,13 +33077,13 @@ function selfText(agent) {
33056
33077
  if (!agent) return JSON.stringify(agent, null, 2);
33057
33078
  const { status: _s, status_label: _l, status_at: _a3, ...rest } = agent;
33058
33079
  const label = typeof agent.status_label === "string" ? displayLabel(agent.status_label) : "";
33059
- const shown2 = {
33080
+ const shown3 = {
33060
33081
  ...rest,
33061
33082
  ...typeof agent.status === "string" ? { status: displayKind(agent.status) } : {},
33062
33083
  ...label ? { status_label: label } : {},
33063
33084
  ...typeof agent.status_at === "string" && !Number.isNaN(Date.parse(agent.status_at)) ? { status_at: agent.status_at } : {}
33064
33085
  };
33065
- return JSON.stringify(shown2, null, 2);
33086
+ return JSON.stringify(shown3, null, 2);
33066
33087
  }
33067
33088
  var MAX_COLS, RETAIN, MB, refusals, quoted, TERMINAL_CONTROLS, CUT_OFF, stripTerminalControls, KIND_CHARS, displayKind, neutralizeBody, deliveredText, oversizedText, INVISIBLES, EXCERPT_CHARS, STATUS_COPY, BAD_LABEL_CHARS2, cleanStatusLabel, statusLabelTooLong, statusSetText, earlierStatusText, STATUS_STALE_MS, agoText, displayLabel, awayTime, replyGoneText;
33068
33089
  var init_copy = __esm({
@@ -33207,13 +33228,13 @@ async function clearStale(path) {
33207
33228
  code: "ENOTSOCK"
33208
33229
  });
33209
33230
  }
33210
- const live = await new Promise((resolve8) => {
33231
+ const live = await new Promise((resolve9) => {
33211
33232
  const probe = connect2(path);
33212
33233
  probe.once("connect", () => {
33213
33234
  probe.destroy();
33214
- resolve8(true);
33235
+ resolve9(true);
33215
33236
  });
33216
- probe.once("error", () => resolve8(false));
33237
+ probe.once("error", () => resolve9(false));
33217
33238
  });
33218
33239
  if (live) {
33219
33240
  throw Object.assign(new Error(`daemon already listening on ${path}`), {
@@ -33233,16 +33254,16 @@ async function serveDaemon(opts) {
33233
33254
  sock.once("close", () => sockets.delete(sock));
33234
33255
  handle(sock, opts);
33235
33256
  });
33236
- await new Promise((resolve8, reject) => {
33257
+ await new Promise((resolve9, reject) => {
33237
33258
  server4.once("error", reject);
33238
- server4.listen(opts.path, () => resolve8());
33259
+ server4.listen(opts.path, () => resolve9());
33239
33260
  });
33240
33261
  chmodSync(opts.path, 384);
33241
33262
  const st = statSync(opts.path);
33242
33263
  const mode = st.mode & 511;
33243
33264
  return {
33244
33265
  mode,
33245
- close: () => new Promise((resolve8) => {
33266
+ close: () => new Promise((resolve9) => {
33246
33267
  for (const s of sockets) s.destroy();
33247
33268
  let parked;
33248
33269
  try {
@@ -33260,7 +33281,7 @@ async function serveDaemon(opts) {
33260
33281
  } catch {
33261
33282
  }
33262
33283
  }
33263
- resolve8();
33284
+ resolve9();
33264
33285
  });
33265
33286
  })
33266
33287
  };
@@ -33537,17 +33558,17 @@ async function run(name, args, request) {
33537
33558
  const to = String(args.to ?? "");
33538
33559
  const body = String(args.text ?? "");
33539
33560
  if (!to || !body) return text("oa-bus: to and text are required", true);
33540
- const namespace = typeof args.to_namespace === "string" && args.to_namespace ? args.to_namespace : void 0;
33561
+ const namespace2 = typeof args.to_namespace === "string" && args.to_namespace ? args.to_namespace : void 0;
33541
33562
  const r = await request({
33542
33563
  type: "send",
33543
33564
  to,
33544
33565
  body,
33545
- ...namespace ? { namespace } : {}
33566
+ ...namespace2 ? { namespace: namespace2 } : {}
33546
33567
  });
33547
33568
  if (r.type !== "receipt") return failed(r);
33548
33569
  if (r.text) return text(r.text, false);
33549
33570
  const n = r.reason === "ambiguous" ? await namespacesOf(to, request) : void 0;
33550
- const moved = r.reason === "revoked" ? await movedTo(to, namespace, request) : void 0;
33571
+ const moved = r.reason === "revoked" ? await movedTo(to, namespace2, request) : void 0;
33551
33572
  return text(
33552
33573
  receiptText(r, to, n, excerptOf(body), moved),
33553
33574
  r.state === "refused" || r.state === "expired"
@@ -33617,13 +33638,13 @@ async function namespacesOf(name, request) {
33617
33638
  return void 0;
33618
33639
  }
33619
33640
  }
33620
- async function movedTo(name, namespace, request) {
33641
+ async function movedTo(name, namespace2, request) {
33621
33642
  try {
33622
33643
  const r = await request({ type: "list" });
33623
33644
  if (r.type !== "roster") return void 0;
33624
33645
  return movedName(
33625
33646
  name,
33626
- r.agents.filter((a) => namespace === void 0 || a.namespace === namespace).map((a) => a.name)
33647
+ r.agents.filter((a) => namespace2 === void 0 || a.namespace === namespace2).map((a) => a.name)
33627
33648
  );
33628
33649
  } catch {
33629
33650
  return void 0;
@@ -33758,7 +33779,7 @@ function codexHello(call, pid, ppid) {
33758
33779
  pid,
33759
33780
  ...call.cwd ? { cwd: call.cwd } : {},
33760
33781
  proposed_name: "codex",
33761
- caps: [ADAPTER_CAPS.mailbox],
33782
+ caps: [ADAPTER_CAPS.mailbox, ADAPTER_CAPS.pending],
33762
33783
  codex: {
33763
33784
  thread_id: call.threadId,
33764
33785
  call_id: call.callId,
@@ -33857,7 +33878,7 @@ ${neutralize(a.text)}
33857
33878
  };
33858
33879
  }
33859
33880
  function inject(a) {
33860
- return new Promise((resolve8, reject) => {
33881
+ return new Promise((resolve9, reject) => {
33861
33882
  const sock = connect3(a.socketPath);
33862
33883
  let connected = false;
33863
33884
  const fail = (e) => {
@@ -33881,7 +33902,7 @@ function inject(a) {
33881
33902
  sock.once("finish", () => {
33882
33903
  clearTimeout(timer);
33883
33904
  sock.destroy();
33884
- resolve8();
33905
+ resolve9();
33885
33906
  });
33886
33907
  sock.end(`${JSON.stringify(frameOf(a))}
33887
33908
  `);
@@ -34001,7 +34022,7 @@ function sessionHello(session, pid, cwd) {
34001
34022
  pid,
34002
34023
  cwd,
34003
34024
  proposed_name: fitName(session.name, 64) || void 0,
34004
- caps: [ADAPTER_CAPS.mailbox],
34025
+ caps: [ADAPTER_CAPS.mailbox, ADAPTER_CAPS.pending],
34005
34026
  attest: {
34006
34027
  session_id: session.sessionId,
34007
34028
  socket_path: session.socketPath ?? void 0
@@ -36378,7 +36399,7 @@ var require_websocket = __commonJS({
36378
36399
  var http = __require("http");
36379
36400
  var net = __require("net");
36380
36401
  var tls = __require("tls");
36381
- var { randomBytes: randomBytes4, createHash: createHash6 } = __require("crypto");
36402
+ var { randomBytes: randomBytes5, createHash: createHash6 } = __require("crypto");
36382
36403
  var { Duplex, Readable } = __require("stream");
36383
36404
  var { URL: URL2 } = __require("url");
36384
36405
  var PerMessageDeflate2 = require_permessage_deflate();
@@ -36916,7 +36937,7 @@ var require_websocket = __commonJS({
36916
36937
  }
36917
36938
  }
36918
36939
  const defaultPort = isSecure ? 443 : 80;
36919
- const key2 = randomBytes4(16).toString("base64");
36940
+ const key2 = randomBytes5(16).toString("base64");
36920
36941
  const request = isSecure ? https.request : http.request;
36921
36942
  const protocolSet = /* @__PURE__ */ new Set();
36922
36943
  let perMessageDeflate;
@@ -37811,12 +37832,12 @@ var require_websocket_server = __commonJS({
37811
37832
 
37812
37833
  // ../bus-adapter-opencode/src/session.ts
37813
37834
  import { execFile as execFile4 } from "node:child_process";
37814
- import { isAbsolute as isAbsolute7 } from "node:path";
37835
+ import { isAbsolute as isAbsolute8 } from "node:path";
37815
37836
  import { promisify as promisify2 } from "node:util";
37816
37837
  function directoryOf(s) {
37817
37838
  const loc = s.location;
37818
37839
  const dir = s.directory ?? loc?.directory;
37819
- return typeof dir === "string" && isAbsolute7(dir) ? dir : null;
37840
+ return typeof dir === "string" && isAbsolute8(dir) ? dir : null;
37820
37841
  }
37821
37842
  async function rootSession(sessionId, deps) {
37822
37843
  const cache = deps.cache ?? ROOTS;
@@ -37894,7 +37915,7 @@ async function handleToolCall(input2) {
37894
37915
  pid: process.pid,
37895
37916
  cwd: session.directory,
37896
37917
  proposed_name: nameOf(session.title),
37897
- caps: [ADAPTER_CAPS.mailbox],
37918
+ caps: [ADAPTER_CAPS.mailbox, ADAPTER_CAPS.pending],
37898
37919
  attest: { session_id: sessionId }
37899
37920
  });
37900
37921
  let client;
@@ -38034,12 +38055,12 @@ var init_stdio2 = __esm({
38034
38055
  this.onclose?.();
38035
38056
  }
38036
38057
  send(message) {
38037
- return new Promise((resolve8) => {
38058
+ return new Promise((resolve9) => {
38038
38059
  const json3 = serializeMessage(message);
38039
38060
  if (this._stdout.write(json3)) {
38040
- resolve8();
38061
+ resolve9();
38041
38062
  } else {
38042
- this._stdout.once("drain", resolve8);
38063
+ this._stdout.once("drain", resolve9);
38043
38064
  }
38044
38065
  });
38045
38066
  }
@@ -38208,16 +38229,16 @@ var harnessSkills = {
38208
38229
  var harnessNames = Object.keys(harnessSkills);
38209
38230
 
38210
38231
  // src/main.ts
38211
- import { resolve as resolve7 } from "node:path";
38232
+ import { resolve as resolve8 } from "node:path";
38212
38233
 
38213
38234
  // src/commands/daemon.ts
38214
38235
  import { existsSync as existsSync4 } from "node:fs";
38215
- import { join as join15 } from "node:path";
38236
+ import { join as join16 } from "node:path";
38216
38237
 
38217
38238
  // ../bus-daemon/src/index.ts
38218
38239
  init_src3();
38219
38240
  import { lstatSync as lstatSync6, realpathSync as realpathSync6, writeFileSync as writeFileSync4 } from "node:fs";
38220
- import { basename as basename5, isAbsolute as isAbsolute5, join as join11 } from "node:path";
38241
+ import { basename as basename5, isAbsolute as isAbsolute6, join as join12 } from "node:path";
38221
38242
 
38222
38243
  // ../bus-adapter-opencode/src/version.ts
38223
38244
  var MIN_PROMPT_ID_VERSION = "2.0.0";
@@ -39202,8 +39223,8 @@ function defaultOpenSessions() {
39202
39223
 
39203
39224
  // ../bus-daemon/src/config-issues.ts
39204
39225
  init_src();
39205
- import { realpathSync as realpathSync4 } from "node:fs";
39206
- import { dirname as dirname4, join as join8 } from "node:path";
39226
+ import { realpathSync as realpathSync5 } from "node:fs";
39227
+ import { dirname as dirname5, join as join9 } from "node:path";
39207
39228
 
39208
39229
  // ../bus-daemon/src/global.ts
39209
39230
  import { randomBytes } from "node:crypto";
@@ -39402,6 +39423,227 @@ function writeGlobalDirs(dirs, h = home()) {
39402
39423
  }
39403
39424
  }
39404
39425
 
39426
+ // ../bus-daemon/src/namespace.ts
39427
+ init_src();
39428
+ import { execFileSync as execFileSync4 } from "node:child_process";
39429
+ import { realpathSync as realpathSync4 } from "node:fs";
39430
+ import { basename as basename4, dirname as dirname4, resolve as resolve2 } from "node:path";
39431
+
39432
+ // ../bus-daemon/src/namespaces.ts
39433
+ import { randomBytes as randomBytes2 } from "node:crypto";
39434
+ import {
39435
+ appendFileSync,
39436
+ chmodSync as chmodSync4,
39437
+ closeSync as closeSync4,
39438
+ mkdirSync as mkdirSync5,
39439
+ openSync as openSync4,
39440
+ renameSync as renameSync3,
39441
+ unlinkSync as unlinkSync2,
39442
+ writeSync as writeSync2
39443
+ } from "node:fs";
39444
+ import { isAbsolute as isAbsolute4, join as join8 } from "node:path";
39445
+ var namespacesFile = (h = home()) => join8(h, "namespaces.json");
39446
+ function readApprovals(file2 = namespacesFile()) {
39447
+ const own2 = readOwnFile(file2);
39448
+ if (own2.state === "none") return { entries: [] };
39449
+ if (own2.state === "unsafe") return { entries: [], error: own2.why };
39450
+ try {
39451
+ const raw = JSON.parse(own2.text);
39452
+ const list = raw?.approved;
39453
+ if (raw && !Array.isArray(raw) && Array.isArray(list) && list.every(
39454
+ (e) => e && typeof e === "object" && typeof e.dir === "string" && isAbsolute4(e.dir) && typeof e.namespace === "string" && e.namespace !== ""
39455
+ ))
39456
+ return {
39457
+ entries: list.map((e) => ({ dir: e.dir, namespace: e.namespace }))
39458
+ };
39459
+ } catch {
39460
+ }
39461
+ return { entries: [], error: "is not valid JSON" };
39462
+ }
39463
+ function isApproved(dir, namespace2, entries) {
39464
+ return entries.some((e) => e.namespace === namespace2 && sameDir(e.dir, dir));
39465
+ }
39466
+ function writeApprovals(entries, h = home()) {
39467
+ mkdirSync5(h, { recursive: true, mode: 448 });
39468
+ chmodSync4(h, 448);
39469
+ const tmp = join8(h, `.namespaces.json.${randomBytes2(8).toString("hex")}.tmp`);
39470
+ const fd = openSync4(tmp, "wx", 384);
39471
+ try {
39472
+ writeSync2(fd, `${JSON.stringify({ approved: entries }, null, 2)}
39473
+ `);
39474
+ } catch (e) {
39475
+ closeSync4(fd);
39476
+ unlinkSync2(tmp);
39477
+ throw e;
39478
+ }
39479
+ closeSync4(fd);
39480
+ try {
39481
+ chmodSync4(tmp, 384);
39482
+ renameSync3(tmp, namespacesFile(h));
39483
+ } catch (e) {
39484
+ unlinkSync2(tmp);
39485
+ throw e;
39486
+ }
39487
+ }
39488
+ function logApproval(entry, h = home(), now = /* @__PURE__ */ new Date()) {
39489
+ const dir = join8(h, "logs");
39490
+ mkdirSync5(dir, { recursive: true, mode: 448 });
39491
+ const file2 = join8(dir, "approvals.log");
39492
+ const line = `${now.toISOString()} ${entry.action} dir=${JSON.stringify(entry.dir)} namespace=${JSON.stringify(entry.namespace)} tty=${entry.tty ? "yes" : "no"}
39493
+ `;
39494
+ appendFileSync(file2, line, { mode: 384 });
39495
+ chmodSync4(file2, 384);
39496
+ }
39497
+
39498
+ // ../bus-daemon/src/namespace.ts
39499
+ var warned = /* @__PURE__ */ new Set();
39500
+ var once = (deps, key2, msg) => {
39501
+ if (warned.has(key2)) return;
39502
+ warned.add(key2);
39503
+ deps.log?.(msg);
39504
+ };
39505
+ function resolveNamespace(start, deps = {}) {
39506
+ let cwd;
39507
+ let missing2 = false;
39508
+ try {
39509
+ cwd = realpathSync4(start);
39510
+ } catch (e) {
39511
+ if (!deps.allowMissing) throw e;
39512
+ cwd = resolve2(start);
39513
+ missing2 = true;
39514
+ if (!warned.has(cwd)) {
39515
+ warned.add(cwd);
39516
+ deps.log?.(`${cwd} does not resolve; using it as given`);
39517
+ }
39518
+ }
39519
+ const { cfg, asked, nsFile } = readConfigs(cwd, deps);
39520
+ const global2 = !missing2 && allowlisted(cwd, deps);
39521
+ if (!global2)
39522
+ for (const file2 of asked)
39523
+ once(
39524
+ deps,
39525
+ `global:${file2}`,
39526
+ `ignoring global in ${file2}: only \`${BUS_CMD} global add\` makes a directory global`
39527
+ );
39528
+ const remoteUrl = (deps.gitRemote ?? gitRemote)(cwd);
39529
+ const root = (deps.gitRoot ?? gitRoot)(cwd);
39530
+ const derived2 = namespaceFrom({
39531
+ remoteUrl,
39532
+ gitRootName: root ? basename4(root) : null,
39533
+ cwd
39534
+ });
39535
+ const source = remoteUrl && normalizeRemote(remoteUrl) ? "git" : root ? "dir" : "cwd";
39536
+ const fallback = { namespace: derived2, global: global2, source };
39537
+ if (!cfg.namespace || !nsFile) return fallback;
39538
+ if (cfg.namespace === derived2) {
39539
+ deps.issues?.setPending(nsFile, deps.uid ?? process.getuid?.(), void 0);
39540
+ return fallback;
39541
+ }
39542
+ if (approved(nsFile, cfg.namespace, deps))
39543
+ return { namespace: cfg.namespace, global: global2, source: "config" };
39544
+ const dir = dirname4(nsFile);
39545
+ deps.issues?.setPending(nsFile, deps.uid ?? process.getuid?.(), {
39546
+ file: nsFile,
39547
+ dir,
39548
+ namespace: cfg.namespace,
39549
+ approvals: deps.namespacesFile
39550
+ });
39551
+ once(
39552
+ deps,
39553
+ `ns:${nsFile}:${cfg.namespace}`,
39554
+ `ignoring namespace "${cfg.namespace}" in ${nsFile}: not approved; run: ${approveCommand(dir)}`
39555
+ );
39556
+ return fallback;
39557
+ }
39558
+ function approved(file2, namespace2, deps) {
39559
+ const path = deps.namespacesFile ?? namespacesFile();
39560
+ const list = readApprovals(path);
39561
+ if (list.error)
39562
+ once(
39563
+ deps,
39564
+ `approvals:${path}:${list.error}`,
39565
+ `${path} ${list.error}: no namespace is approved`
39566
+ );
39567
+ return isApproved(dirname4(file2), namespace2, list.entries);
39568
+ }
39569
+ function allowlisted(cwd, deps) {
39570
+ const file2 = deps.globalFile ?? globalFile();
39571
+ const list = readGlobalDirs(file2);
39572
+ if (list.error)
39573
+ once(
39574
+ deps,
39575
+ `allowlist:${file2}:${list.error}`,
39576
+ `${file2} ${list.error}: no directory is global`
39577
+ );
39578
+ if (list.dirs.length === 0) return false;
39579
+ try {
39580
+ return isGlobalDir(
39581
+ cwd,
39582
+ list.dirs,
39583
+ (entry) => once(
39584
+ deps,
39585
+ `stale:${file2}:${entry}`,
39586
+ `ignoring ${entry} in ${file2}: its path is no longer real (a symlink now stands in it)`
39587
+ )
39588
+ );
39589
+ } catch {
39590
+ return false;
39591
+ }
39592
+ }
39593
+ function readConfigs(cwd, deps) {
39594
+ const uid = deps.uid ?? process.getuid?.();
39595
+ const configs = [];
39596
+ const asked = [];
39597
+ let nsFile;
39598
+ for (const file2 of configPaths(cwd)) {
39599
+ const own2 = readOwnFile(file2, uid, {
39600
+ allowGroupWrite: true,
39601
+ ...deps.group ? { group: deps.group } : {}
39602
+ });
39603
+ if (own2.state === "unsafe")
39604
+ once(deps, file2, `ignoring ${file2}: it ${own2.why}`);
39605
+ let valid2 = true;
39606
+ if (own2.state === "ok") {
39607
+ if (own2.note) once(deps, `note:${file2}`, `using ${file2}: it ${own2.note}`);
39608
+ let parsed;
39609
+ try {
39610
+ parsed = BusConfigSchema.safeParse(JSON.parse(own2.text));
39611
+ } catch {
39612
+ }
39613
+ if (parsed?.success) {
39614
+ configs.push(parsed.data);
39615
+ if (parsed.data.global === true) asked.push(file2);
39616
+ if (parsed.data.namespace !== void 0 && nsFile === void 0)
39617
+ nsFile = file2;
39618
+ } else {
39619
+ valid2 = false;
39620
+ deps.log?.(`ignoring invalid ${file2}`);
39621
+ }
39622
+ }
39623
+ deps.issues?.set(file2, uid, configIssue(file2, own2, valid2), deps.group);
39624
+ }
39625
+ return { cfg: mergeConfigs(configs), asked, nsFile };
39626
+ }
39627
+ function nearestConfig(dir, deps = {}) {
39628
+ try {
39629
+ return readConfigs(realpathSync4(dir), deps).cfg;
39630
+ } catch {
39631
+ return {};
39632
+ }
39633
+ }
39634
+ var git = (cwd, args) => {
39635
+ try {
39636
+ return execFileSync4("git", ["-C", cwd, ...args], {
39637
+ encoding: "utf8",
39638
+ stdio: ["ignore", "pipe", "ignore"]
39639
+ }).trim() || null;
39640
+ } catch {
39641
+ return null;
39642
+ }
39643
+ };
39644
+ var gitRemote = (cwd) => git(cwd, ["remote", "get-url", "origin"]);
39645
+ var gitRoot = (cwd) => git(cwd, ["rev-parse", "--show-toplevel"]);
39646
+
39405
39647
  // ../bus-daemon/src/config-issues.ts
39406
39648
  var shq = (s) => `'${s.replace(/'/g, "'\\''")}'`;
39407
39649
  function fixFor(file2, why) {
@@ -39441,6 +39683,24 @@ function configIssue(file2, own2, valid2 = true) {
39441
39683
  };
39442
39684
  return void 0;
39443
39685
  }
39686
+ var approveCommand = (dir) => `oa-bus namespace approve ${shq(dir)}`;
39687
+ var pendingIssue = (p) => ({
39688
+ file: p.file,
39689
+ state: "pending",
39690
+ reason: `sets namespace "${p.namespace}", which you have not approved`,
39691
+ fix: approveCommand(p.dir)
39692
+ });
39693
+ function stillPending(p, uid) {
39694
+ const own2 = readOwnFile(p.file, uid, { allowGroupWrite: true });
39695
+ if (own2.state !== "ok") return false;
39696
+ try {
39697
+ const parsed = BusConfigSchema.safeParse(JSON.parse(own2.text));
39698
+ if (!parsed.success || parsed.data.namespace !== p.namespace) return false;
39699
+ } catch {
39700
+ return false;
39701
+ }
39702
+ return !isApproved(p.dir, p.namespace, readApprovals(p.approvals).entries);
39703
+ }
39444
39704
  function isValidConfig(text3) {
39445
39705
  try {
39446
39706
  return BusConfigSchema.safeParse(JSON.parse(text3)).success;
@@ -39465,6 +39725,16 @@ function inspectGlobal(file2 = globalFile()) {
39465
39725
  fix: error62 === "is not valid JSON" ? `remove it (rm ${shq(file2)}), then run oa-bus global add <dir> again` : fixFor(file2, error62)
39466
39726
  };
39467
39727
  }
39728
+ function inspectApprovals(file2 = namespacesFile()) {
39729
+ const { error: error62 } = readApprovals(file2);
39730
+ if (error62 === void 0) return void 0;
39731
+ return {
39732
+ file: file2,
39733
+ state: "refused",
39734
+ reason: error62,
39735
+ fix: error62 === "is not valid JSON" ? `remove it (rm ${shq(file2)}), then run oa-bus namespace approve <dir> again` : fixFor(file2, error62)
39736
+ };
39737
+ }
39468
39738
  var ConfigIssues = class {
39469
39739
  #files = /* @__PURE__ */ new Map();
39470
39740
  /** Records the result of reading `file` (undefined: it is fine now). */
@@ -39472,9 +39742,21 @@ var ConfigIssues = class {
39472
39742
  if (issue2) this.#files.set(file2, { uid, group });
39473
39743
  else this.#files.delete(file2);
39474
39744
  }
39745
+ #pending = /* @__PURE__ */ new Map();
39746
+ /** Records a namespace waiting for approval, or clears it (undefined). */
39747
+ setPending(file2, uid, pending) {
39748
+ if (pending) this.#pending.set(file2, { p: pending, uid });
39749
+ else this.#pending.delete(file2);
39750
+ }
39475
39751
  /** Every tracked file, re-read now; `within` keeps only those at these paths. */
39476
- list(within) {
39752
+ list(within, opts = {}) {
39477
39753
  const out = [];
39754
+ for (const [file2, { p, uid }] of [...this.#pending]) {
39755
+ if (within && !within.has(file2)) continue;
39756
+ if (stillPending(p, uid)) {
39757
+ if (opts.pending) out.push(pendingIssue(p));
39758
+ } else this.#pending.delete(file2);
39759
+ }
39478
39760
  for (const [file2, { uid, group }] of [...this.#files]) {
39479
39761
  if (within && !within.has(file2)) continue;
39480
39762
  const issue2 = inspectConfig(file2, uid, group);
@@ -39489,22 +39771,40 @@ function scanConfigFiles(cwd, opts = {}) {
39489
39771
  const out = [];
39490
39772
  let real2 = cwd;
39491
39773
  try {
39492
- real2 = realpathSync4(cwd);
39774
+ real2 = realpathSync5(cwd);
39493
39775
  } catch {
39494
39776
  }
39495
39777
  for (const file2 of configPaths(real2)) {
39496
39778
  const issue2 = inspectConfig(file2, uid, opts.group);
39497
39779
  if (issue2) out.push(issue2);
39498
39780
  }
39781
+ const seen2 = new ConfigIssues();
39782
+ try {
39783
+ resolveNamespace(real2, {
39784
+ issues: seen2,
39785
+ allowMissing: true,
39786
+ ...opts.uid === void 0 ? {} : { uid: opts.uid },
39787
+ ...opts.group ? { group: opts.group } : {},
39788
+ ...opts.namespacesFile ? { namespacesFile: opts.namespacesFile } : {},
39789
+ ...opts.gitRemote ? { gitRemote: opts.gitRemote } : {},
39790
+ ...opts.gitRoot ? { gitRoot: opts.gitRoot } : {}
39791
+ });
39792
+ } catch {
39793
+ }
39794
+ out.push(
39795
+ ...seen2.list(void 0, { pending: true }).filter((f) => f.state === "pending")
39796
+ );
39797
+ const a = inspectApprovals(opts.namespacesFile);
39798
+ if (a) out.push(a);
39499
39799
  const g = inspectGlobal(opts.globalFile);
39500
39800
  if (g) out.push(g);
39501
39801
  return out;
39502
39802
  }
39503
39803
  function configPaths(cwd) {
39504
39804
  const out = [];
39505
- for (let dir = cwd; ; dir = dirname4(dir)) {
39506
- out.push(join8(dir, CONFIG_FILE));
39507
- if (dirname4(dir) === dir) return out;
39805
+ for (let dir = cwd; ; dir = dirname5(dir)) {
39806
+ out.push(join9(dir, CONFIG_FILE));
39807
+ if (dirname5(dir) === dir) return out;
39508
39808
  }
39509
39809
  }
39510
39810
 
@@ -40018,127 +40318,6 @@ function defaultBackoff(attempt) {
40018
40318
  return Math.round(base3 * (0.5 + Math.random() / 2));
40019
40319
  }
40020
40320
 
40021
- // ../bus-daemon/src/namespace.ts
40022
- init_src();
40023
- import { execFileSync as execFileSync4 } from "node:child_process";
40024
- import { realpathSync as realpathSync5 } from "node:fs";
40025
- import { basename as basename4, resolve as resolve2 } from "node:path";
40026
- var warned = /* @__PURE__ */ new Set();
40027
- var once = (deps, key2, msg) => {
40028
- if (warned.has(key2)) return;
40029
- warned.add(key2);
40030
- deps.log?.(msg);
40031
- };
40032
- function resolveNamespace(start, deps = {}) {
40033
- let cwd;
40034
- let missing2 = false;
40035
- try {
40036
- cwd = realpathSync5(start);
40037
- } catch (e) {
40038
- if (!deps.allowMissing) throw e;
40039
- cwd = resolve2(start);
40040
- missing2 = true;
40041
- if (!warned.has(cwd)) {
40042
- warned.add(cwd);
40043
- deps.log?.(`${cwd} does not resolve; using it as given`);
40044
- }
40045
- }
40046
- const { cfg, asked } = readConfigs(cwd, deps);
40047
- const global2 = !missing2 && allowlisted(cwd, deps);
40048
- if (!global2)
40049
- for (const file2 of asked)
40050
- once(
40051
- deps,
40052
- `global:${file2}`,
40053
- `ignoring global in ${file2}: only \`${BUS_CMD} global add\` makes a directory global`
40054
- );
40055
- if (cfg.namespace)
40056
- return { namespace: cfg.namespace, global: global2, source: "config" };
40057
- const remoteUrl = (deps.gitRemote ?? gitRemote)(cwd);
40058
- const root = (deps.gitRoot ?? gitRoot)(cwd);
40059
- const namespace = namespaceFrom({
40060
- remoteUrl,
40061
- gitRootName: root ? basename4(root) : null,
40062
- cwd
40063
- });
40064
- const source = remoteUrl && normalizeRemote(remoteUrl) ? "git" : root ? "dir" : "cwd";
40065
- return { namespace, global: global2, source };
40066
- }
40067
- function allowlisted(cwd, deps) {
40068
- const file2 = deps.globalFile ?? globalFile();
40069
- const list = readGlobalDirs(file2);
40070
- if (list.error)
40071
- once(
40072
- deps,
40073
- `allowlist:${file2}:${list.error}`,
40074
- `${file2} ${list.error}: no directory is global`
40075
- );
40076
- if (list.dirs.length === 0) return false;
40077
- try {
40078
- return isGlobalDir(
40079
- cwd,
40080
- list.dirs,
40081
- (entry) => once(
40082
- deps,
40083
- `stale:${file2}:${entry}`,
40084
- `ignoring ${entry} in ${file2}: its path is no longer real (a symlink now stands in it)`
40085
- )
40086
- );
40087
- } catch {
40088
- return false;
40089
- }
40090
- }
40091
- function readConfigs(cwd, deps) {
40092
- const uid = deps.uid ?? process.getuid?.();
40093
- const configs = [];
40094
- const asked = [];
40095
- for (const file2 of configPaths(cwd)) {
40096
- const own2 = readOwnFile(file2, uid, {
40097
- allowGroupWrite: true,
40098
- ...deps.group ? { group: deps.group } : {}
40099
- });
40100
- if (own2.state === "unsafe")
40101
- once(deps, file2, `ignoring ${file2}: it ${own2.why}`);
40102
- let valid2 = true;
40103
- if (own2.state === "ok") {
40104
- if (own2.note) once(deps, `note:${file2}`, `using ${file2}: it ${own2.note}`);
40105
- let parsed;
40106
- try {
40107
- parsed = BusConfigSchema.safeParse(JSON.parse(own2.text));
40108
- } catch {
40109
- }
40110
- if (parsed?.success) {
40111
- configs.push(parsed.data);
40112
- if (parsed.data.global === true) asked.push(file2);
40113
- } else {
40114
- valid2 = false;
40115
- deps.log?.(`ignoring invalid ${file2}`);
40116
- }
40117
- }
40118
- deps.issues?.set(file2, uid, configIssue(file2, own2, valid2), deps.group);
40119
- }
40120
- return { cfg: mergeConfigs(configs), asked };
40121
- }
40122
- function nearestConfig(dir, deps = {}) {
40123
- try {
40124
- return readConfigs(realpathSync5(dir), deps).cfg;
40125
- } catch {
40126
- return {};
40127
- }
40128
- }
40129
- var git = (cwd, args) => {
40130
- try {
40131
- return execFileSync4("git", ["-C", cwd, ...args], {
40132
- encoding: "utf8",
40133
- stdio: ["ignore", "pipe", "ignore"]
40134
- }).trim() || null;
40135
- } catch {
40136
- return null;
40137
- }
40138
- };
40139
- var gitRemote = (cwd) => git(cwd, ["remote", "get-url", "origin"]);
40140
- var gitRoot = (cwd) => git(cwd, ["rev-parse", "--show-toplevel"]);
40141
-
40142
40321
  // ../bus-daemon/src/outbox.ts
40143
40322
  var Outbox = class {
40144
40323
  constructor(opts) {
@@ -40595,7 +40774,10 @@ function routeLocal(frame, hello, reply, ctx) {
40595
40774
  const ref = agent.ref;
40596
40775
  switch (frame.type) {
40597
40776
  case "self": {
40598
- const files = frame.row ? ctx.configFiles?.(agent.cwd) ?? [] : [];
40777
+ const files = frame.row ? ctx.configFiles?.(
40778
+ agent.cwd,
40779
+ hello.caps?.includes(ADAPTER_CAPS.pending)
40780
+ ) ?? [] : [];
40599
40781
  const self = {
40600
40782
  type: "agent",
40601
40783
  agent: {
@@ -40683,9 +40865,9 @@ function routeLocal(frame, hello, reply, ctx) {
40683
40865
  init_src2();
40684
40866
  init_src();
40685
40867
  import {
40686
- chmodSync as chmodSync4,
40868
+ chmodSync as chmodSync5,
40687
40869
  readFileSync as readFileSync7,
40688
- renameSync as renameSync3,
40870
+ renameSync as renameSync4,
40689
40871
  rmSync as rmSync2,
40690
40872
  writeFileSync
40691
40873
  } from "node:fs";
@@ -40863,20 +41045,20 @@ var SentStore = class {
40863
41045
  from_ref,
40864
41046
  from_name,
40865
41047
  to_name,
40866
- namespace,
41048
+ namespace: namespace2,
40867
41049
  excerpt,
40868
41050
  at,
40869
41051
  outcome,
40870
41052
  delivered,
40871
41053
  late: late2,
40872
- shown: shown2,
41054
+ shown: shown3,
40873
41055
  native
40874
41056
  } = e;
40875
41057
  this.#all.set(id, {
40876
41058
  from_ref,
40877
41059
  ...BusNameSchema.safeParse(from_name).success ? { from_name } : {},
40878
41060
  to_name,
40879
- ...namespace === void 0 ? {} : { namespace },
41061
+ ...namespace2 === void 0 ? {} : { namespace: namespace2 },
40880
41062
  ...validExcerpt(excerpt) ? { excerpt } : {},
40881
41063
  at,
40882
41064
  ...outcome ? {
@@ -40887,7 +41069,7 @@ var SentStore = class {
40887
41069
  } : {},
40888
41070
  ...delivered ? { delivered } : {},
40889
41071
  ...delivered && late2 ? { late: late2 } : {},
40890
- ...delivered && late2 && shown2 ? { shown: shown2 } : {},
41072
+ ...delivered && late2 && shown3 ? { shown: shown3 } : {},
40891
41073
  ...native ? { native } : {}
40892
41074
  });
40893
41075
  }
@@ -40913,8 +41095,8 @@ var SentStore = class {
40913
41095
  mode: 384,
40914
41096
  flag: "wx"
40915
41097
  });
40916
- chmodSync4(tmp, 384);
40917
- renameSync3(tmp, this.file);
41098
+ chmodSync5(tmp, 384);
41099
+ renameSync4(tmp, this.file);
40918
41100
  } catch (e) {
40919
41101
  this.#log?.(
40920
41102
  `sent file write failed: ${e instanceof Error ? e.message : String(e)}`
@@ -40949,7 +41131,7 @@ var Receipts = class {
40949
41131
  #now;
40950
41132
  #after;
40951
41133
  /** `native`: no tool call waits for this receipt, so a refusal is a notice too. */
40952
- sending(f, namespace, native, fromName) {
41134
+ sending(f, namespace2, native, fromName) {
40953
41135
  const excerpt = typeof f.body === "string" ? excerptOf(f.body) : void 0;
40954
41136
  const cutoff = this.#now() - 15 * 6e4;
40955
41137
  for (const [id, s] of this.#sending)
@@ -40959,7 +41141,7 @@ var Receipts = class {
40959
41141
  from_ref: f.from_ref,
40960
41142
  ...fromName ? { from_name: fromName } : {},
40961
41143
  to_name: f.to_name,
40962
- ...namespace ? { namespace } : {},
41144
+ ...namespace2 ? { namespace: namespace2 } : {},
40963
41145
  ...excerpt ? { excerpt } : {}
40964
41146
  },
40965
41147
  native,
@@ -41029,12 +41211,12 @@ var Receipts = class {
41029
41211
  this.#waiting.delete(msgId);
41030
41212
  return Promise.resolve(w.final);
41031
41213
  }
41032
- return new Promise((resolve8) => {
41214
+ return new Promise((resolve9) => {
41033
41215
  const cancel = this.#after(ms, () => w.done?.(void 0));
41034
41216
  w.done = (f) => {
41035
41217
  cancel();
41036
41218
  this.#waiting.delete(msgId);
41037
- resolve8(f);
41219
+ resolve9(f);
41038
41220
  };
41039
41221
  });
41040
41222
  }
@@ -41090,20 +41272,20 @@ init_src3();
41090
41272
  init_src();
41091
41273
  import { createHash as createHash4, randomUUID } from "node:crypto";
41092
41274
  import {
41093
- chmodSync as chmodSync6,
41275
+ chmodSync as chmodSync7,
41094
41276
  lstatSync as lstatSync5,
41095
- mkdirSync as mkdirSync5,
41277
+ mkdirSync as mkdirSync6,
41096
41278
  readFileSync as readFileSync9,
41097
- renameSync as renameSync5,
41279
+ renameSync as renameSync6,
41098
41280
  rmSync as rmSync3,
41099
41281
  writeFileSync as writeFileSync3
41100
41282
  } from "node:fs";
41101
41283
  import { createServer as createServer2 } from "node:net";
41102
- import { dirname as dirname5, join as join9 } from "node:path";
41284
+ import { dirname as dirname6, join as join10 } from "node:path";
41103
41285
  import { createInterface } from "node:readline";
41104
41286
 
41105
41287
  // ../bus-daemon/src/transports/held.ts
41106
- import { chmodSync as chmodSync5, readFileSync as readFileSync8, renameSync as renameSync4, writeFileSync as writeFileSync2 } from "node:fs";
41288
+ import { chmodSync as chmodSync6, readFileSync as readFileSync8, renameSync as renameSync5, writeFileSync as writeFileSync2 } from "node:fs";
41107
41289
  var HeldStore = class {
41108
41290
  constructor(file2, opts = {}) {
41109
41291
  this.file = file2;
@@ -41142,8 +41324,8 @@ var HeldStore = class {
41142
41324
  #write(all) {
41143
41325
  const tmp = `${this.file}.${process.pid}.tmp`;
41144
41326
  writeFileSync2(tmp, JSON.stringify(all), { mode: 384 });
41145
- chmodSync5(tmp, 384);
41146
- renameSync4(tmp, this.file);
41327
+ chmodSync6(tmp, 384);
41328
+ renameSync5(tmp, this.file);
41147
41329
  }
41148
41330
  };
41149
41331
 
@@ -41169,7 +41351,7 @@ function unsafeClaudeSocket(path) {
41169
41351
  try {
41170
41352
  if (!sock.isSocket()) return `${path} is not a socket`;
41171
41353
  if (sock.uid !== uid) return `${path} belongs to another user`;
41172
- const dir = dirname5(path);
41354
+ const dir = dirname6(path);
41173
41355
  const st = lstatSync5(dir);
41174
41356
  if (!st.isDirectory()) return `${dir} is not a folder`;
41175
41357
  if (st.uid !== uid) return `${dir} belongs to another user`;
@@ -41183,8 +41365,8 @@ function unsafeClaudeSocket(path) {
41183
41365
  var RETURN_INDEX_MAX = 500;
41184
41366
  var RETURN_TTL_MS = LIMITS.mailTtlSec * 1e3;
41185
41367
  var INDEX_REFRESH_MS = 6e4;
41186
- function returnKey(agentRef, namespace, peerName, fromId) {
41187
- return `${agentRef}\0${namespace}\0${peerName}\0${fromId ?? ""}`;
41368
+ function returnKey(agentRef, namespace2, peerName, fromId) {
41369
+ return `${agentRef}\0${namespace2}\0${peerName}\0${fromId ?? ""}`;
41188
41370
  }
41189
41371
  function readReturnIndex(file2) {
41190
41372
  let raw;
@@ -41226,7 +41408,7 @@ var ClaudeTransport = class {
41226
41408
  this.opts = opts;
41227
41409
  this.#held = opts.heldFile ? new HeldStore(opts.heldFile) : void 0;
41228
41410
  this.#injected = opts.heldFile ? new HeldStore(opts.heldFile.replace(/(\.json)?$/, ".injected.json")) : void 0;
41229
- const sample = join9(opts.socketsDir, "00000000.sock");
41411
+ const sample = join10(opts.socketsDir, "00000000.sock");
41230
41412
  if (Buffer.byteLength(sample) > MAX_SOCKET_PATH) {
41231
41413
  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 OA_BUS_HOME`;
41232
41414
  opts.log?.(this.#disabled);
@@ -41343,22 +41525,22 @@ var ClaudeTransport = class {
41343
41525
  return { ok: false, reason: "closed", cause: st };
41344
41526
  }
41345
41527
  #waitFor(msgId, ms) {
41346
- return new Promise((resolve8) => {
41528
+ return new Promise((resolve9) => {
41347
41529
  const buffered = this.#buffered.get(msgId);
41348
41530
  if (buffered !== void 0) {
41349
41531
  this.#buffered.delete(msgId);
41350
- resolve8(buffered);
41532
+ resolve9(buffered);
41351
41533
  return;
41352
41534
  }
41353
41535
  const timer = setTimeout(() => {
41354
41536
  this.#waiting.delete(msgId);
41355
- resolve8(void 0);
41537
+ resolve9(void 0);
41356
41538
  }, ms);
41357
41539
  timer.unref();
41358
41540
  this.#waiting.set(msgId, (s) => {
41359
41541
  clearTimeout(timer);
41360
41542
  this.#waiting.delete(msgId);
41361
- resolve8(s);
41543
+ resolve9(s);
41362
41544
  });
41363
41545
  });
41364
41546
  }
@@ -41439,14 +41621,14 @@ var ClaudeTransport = class {
41439
41621
  return t ? `uds:${t.socketPath}` : "";
41440
41622
  }
41441
41623
  /** A global session hears from alice@ns1 and alice@ns2 on different sockets. */
41442
- #sink(agentRef, namespace, peerName, fromId, revived) {
41443
- const key2 = returnKey(agentRef, namespace, peerName, fromId);
41624
+ #sink(agentRef, namespace2, peerName, fromId, revived) {
41625
+ const key2 = returnKey(agentRef, namespace2, peerName, fromId);
41444
41626
  let sink = this.#sinks.get(key2);
41445
41627
  if (!sink) {
41446
41628
  sink = this.#listen(
41447
41629
  key2,
41448
41630
  agentRef,
41449
- namespace,
41631
+ namespace2,
41450
41632
  peerName,
41451
41633
  false,
41452
41634
  revived,
@@ -41460,8 +41642,8 @@ var ClaudeTransport = class {
41460
41642
  }
41461
41643
  return sink;
41462
41644
  }
41463
- async #listen(key2, agentRef, namespace, peerName, notice = false, revived, fromId) {
41464
- const path = join9(
41645
+ async #listen(key2, agentRef, namespace2, peerName, notice = false, revived, fromId) {
41646
+ const path = join10(
41465
41647
  this.opts.socketsDir,
41466
41648
  `${notice ? randomUUID().slice(0, 8) : returnName(key2, this.#pathsInUse())}.sock`
41467
41649
  );
@@ -41469,8 +41651,8 @@ var ClaudeTransport = class {
41469
41651
  const unsafe = this.opts.prepareDir(this.opts.socketsDir);
41470
41652
  if (unsafe) throw new UnsafeDir(unsafe);
41471
41653
  } else {
41472
- mkdirSync5(this.opts.socketsDir, { recursive: true, mode: 448 });
41473
- chmodSync6(this.opts.socketsDir, 448);
41654
+ mkdirSync6(this.opts.socketsDir, { recursive: true, mode: 448 });
41655
+ chmodSync7(this.opts.socketsDir, 448);
41474
41656
  }
41475
41657
  rmSync3(path, { force: true });
41476
41658
  this.#paths.set(key2, path);
@@ -41480,7 +41662,7 @@ var ClaudeTransport = class {
41480
41662
  path,
41481
41663
  conns,
41482
41664
  agentRef,
41483
- namespace,
41665
+ namespace: namespace2,
41484
41666
  peerName,
41485
41667
  claudeFrom: "",
41486
41668
  notice,
@@ -41498,11 +41680,11 @@ var ClaudeTransport = class {
41498
41680
  );
41499
41681
  })
41500
41682
  };
41501
- await new Promise((resolve8, reject) => {
41683
+ await new Promise((resolve9, reject) => {
41502
41684
  sink.server.once("error", reject);
41503
- sink.server.listen(path, () => resolve8());
41685
+ sink.server.listen(path, () => resolve9());
41504
41686
  });
41505
- chmodSync6(path, 384);
41687
+ chmodSync7(path, 384);
41506
41688
  return sink;
41507
41689
  }
41508
41690
  /** Paths of the sinks bound or binding now, by key. */
@@ -41543,8 +41725,8 @@ var ClaudeTransport = class {
41543
41725
  for (const [k, v] of keep) out[k] = v;
41544
41726
  const tmp = `${file2}.${process.pid}.tmp`;
41545
41727
  writeFileSync3(tmp, JSON.stringify(out), { mode: 384 });
41546
- chmodSync6(tmp, 384);
41547
- renameSync5(tmp, file2);
41728
+ chmodSync7(tmp, 384);
41729
+ renameSync6(tmp, file2);
41548
41730
  return out;
41549
41731
  } catch (e) {
41550
41732
  this.opts.log?.(
@@ -41624,10 +41806,10 @@ init_src2();
41624
41806
  import { execFile } from "node:child_process";
41625
41807
  import { accessSync, constants as constants2, readFileSync as readFileSync10, statSync as statSync7 } from "node:fs";
41626
41808
  import { readFile } from "node:fs/promises";
41627
- import { delimiter, isAbsolute as isAbsolute4, join as join10 } from "node:path";
41809
+ import { delimiter, isAbsolute as isAbsolute5, join as join11 } from "node:path";
41628
41810
  var CODEX_QUEUE_TIMEOUT_MS = 1e4;
41629
41811
  var CODEX_TEXT_CAP = 64 * 1024;
41630
- var codexBinFile = (busHome2) => join10(busHome2, "codex.json");
41812
+ var codexBinFile = (busHome2) => join11(busHome2, "codex.json");
41631
41813
  var codexBinPin = (bin) => `${JSON.stringify({ bin }, null, 2)}
41632
41814
  `;
41633
41815
  var CODEX_APP = "/Applications/ChatGPT.app";
@@ -41643,11 +41825,11 @@ var executable = (p) => {
41643
41825
  };
41644
41826
  function codexAppBin(app) {
41645
41827
  try {
41646
- const plist = readFileSync10(join10(app, "Contents", "Info.plist"), "utf8");
41828
+ const plist = readFileSync10(join11(app, "Contents", "Info.plist"), "utf8");
41647
41829
  const id = /<key>CFBundleIdentifier<\/key>\s*<string>([^<]*)<\/string>/.exec(
41648
41830
  plist
41649
41831
  )?.[1];
41650
- return id === CODEX_APP_ID ? join10(app, "Contents", "Resources", "codex") : void 0;
41832
+ return id === CODEX_APP_ID ? join11(app, "Contents", "Resources", "codex") : void 0;
41651
41833
  } catch {
41652
41834
  return void 0;
41653
41835
  }
@@ -41656,13 +41838,13 @@ function resolveCodexBin(o) {
41656
41838
  if (o.configFile)
41657
41839
  try {
41658
41840
  const raw = JSON.parse(readFileSync10(o.configFile, "utf8"));
41659
- if (typeof raw.bin === "string" && isAbsolute4(raw.bin) && executable(raw.bin))
41841
+ if (typeof raw.bin === "string" && isAbsolute5(raw.bin) && executable(raw.bin))
41660
41842
  return { path: raw.bin, from: "config" };
41661
41843
  } catch {
41662
41844
  }
41663
41845
  for (const dir of (o.path ?? "").split(delimiter)) {
41664
- if (!isAbsolute4(dir)) continue;
41665
- const p = join10(dir, "codex");
41846
+ if (!isAbsolute5(dir)) continue;
41847
+ const p = join11(dir, "codex");
41666
41848
  if (executable(p)) return { path: p, from: "path" };
41667
41849
  }
41668
41850
  const app = o.app === null ? void 0 : codexAppBin(o.app ?? CODEX_APP);
@@ -41712,14 +41894,14 @@ function splitArgv0(args) {
41712
41894
  const real2 = ends.find((e) => {
41713
41895
  const p = args.slice(0, e);
41714
41896
  try {
41715
- return isAbsolute4(p) && statSync7(p).isFile();
41897
+ return isAbsolute5(p) && statSync7(p).isFile();
41716
41898
  } catch {
41717
41899
  return false;
41718
41900
  }
41719
41901
  });
41720
41902
  return words(args.slice(real2 ?? ends[0]));
41721
41903
  }
41722
- var execText = (cmd, args) => new Promise((resolve8) => {
41904
+ var execText = (cmd, args) => new Promise((resolve9) => {
41723
41905
  execFile(
41724
41906
  cmd,
41725
41907
  args,
@@ -41728,7 +41910,7 @@ var execText = (cmd, args) => new Promise((resolve8) => {
41728
41910
  timeout: 2e3,
41729
41911
  env: { ...process.env, LC_ALL: "C" }
41730
41912
  },
41731
- (err, stdout) => resolve8(err ? void 0 : stdout)
41913
+ (err, stdout) => resolve9(err ? void 0 : stdout)
41732
41914
  );
41733
41915
  });
41734
41916
  async function processArgs(pid) {
@@ -41751,17 +41933,17 @@ async function processArgs(pid) {
41751
41933
  return args ? splitArgv0(args) : void 0;
41752
41934
  }
41753
41935
  var START_ERRORS = /* @__PURE__ */ new Set(["ENOENT", "EACCES", "ENOEXEC"]);
41754
- var execCodex = (timeoutMs = CODEX_QUEUE_TIMEOUT_MS) => (bin, args, env2) => new Promise((resolve8, reject) => {
41936
+ var execCodex = (timeoutMs = CODEX_QUEUE_TIMEOUT_MS) => (bin, args, env2) => new Promise((resolve9, reject) => {
41755
41937
  execFile(
41756
41938
  bin,
41757
41939
  args,
41758
41940
  { timeout: timeoutMs, maxBuffer: 64 * 1024, env: env2 },
41759
41941
  (err, _stdout, stderr) => {
41760
- if (!err) return resolve8({ code: 0, stderr });
41942
+ if (!err) return resolve9({ code: 0, stderr });
41761
41943
  const e = err;
41762
41944
  if (typeof e.code === "string" && START_ERRORS.has(e.code))
41763
41945
  return reject(err);
41764
- resolve8({
41946
+ resolve9({
41765
41947
  // A maxBuffer kill is SIGTERM too, but carries its own string code.
41766
41948
  code: e.killed && e.signal === "SIGTERM" && typeof e.code !== "string" ? null : typeof e.code === "number" ? e.code : -1,
41767
41949
  stderr: String(stderr ?? "")
@@ -41886,17 +42068,17 @@ var codexHostWakes = async (pid) => {
41886
42068
  init_src2();
41887
42069
  import { execFile as execFile2 } from "node:child_process";
41888
42070
  var START_ERRORS2 = /* @__PURE__ */ new Set(["ENOENT", "EACCES"]);
41889
- var execSpawn = (timeoutMs, maxBuffer = 1024 * 1024) => (cmd, args) => new Promise((resolve8, reject) => {
42071
+ var execSpawn = (timeoutMs, maxBuffer = 1024 * 1024) => (cmd, args) => new Promise((resolve9, reject) => {
41890
42072
  execFile2(
41891
42073
  cmd,
41892
42074
  args,
41893
42075
  { timeout: timeoutMs, maxBuffer },
41894
42076
  (err, stdout, stderr) => {
41895
- if (!err) return resolve8({ code: 0, stdout, stderr });
42077
+ if (!err) return resolve9({ code: 0, stdout, stderr });
41896
42078
  const e = err;
41897
42079
  if (typeof e.code === "string" && START_ERRORS2.has(e.code))
41898
42080
  return reject(err);
41899
- resolve8({
42081
+ resolve9({
41900
42082
  code: e.killed || typeof e.code !== "number" ? null : e.code,
41901
42083
  stdout,
41902
42084
  stderr
@@ -42011,18 +42193,18 @@ var PiTransport = class {
42011
42193
  });
42012
42194
  if (!pushed) return { ok: false, reason: "closed" };
42013
42195
  this.#forget(mail.msg_id);
42014
- return new Promise((resolve8) => {
42196
+ return new Promise((resolve9) => {
42015
42197
  const timer = setTimeout(() => {
42016
42198
  this.#waiting.delete(mail.msg_id);
42017
42199
  this.#remember(mail.msg_id, agent.ref);
42018
- resolve8({ ok: false, reason: "timeout" });
42200
+ resolve9({ ok: false, reason: "timeout" });
42019
42201
  }, this.opts.ackTimeoutMs ?? 1e4);
42020
42202
  timer.unref();
42021
42203
  this.#waiting.set(mail.msg_id, {
42022
42204
  ref: agent.ref,
42023
42205
  done: (o) => {
42024
42206
  clearTimeout(timer);
42025
- resolve8(o);
42207
+ resolve9(o);
42026
42208
  }
42027
42209
  });
42028
42210
  });
@@ -42145,8 +42327,9 @@ async function runDaemon(deps = {}) {
42145
42327
  caps.delete(ref);
42146
42328
  };
42147
42329
  const configIssues = new ConfigIssues();
42148
- const configFiles = (cwd) => {
42330
+ const configFiles = (cwd, pending2 = false) => {
42149
42331
  const g = inspectGlobal();
42332
+ const a = inspectApprovals();
42150
42333
  let within;
42151
42334
  if (cwd !== void 0) {
42152
42335
  try {
@@ -42155,7 +42338,11 @@ async function runDaemon(deps = {}) {
42155
42338
  within = new Set(configPaths(cwd));
42156
42339
  }
42157
42340
  }
42158
- return [...configIssues.list(within), ...g ? [g] : []];
42341
+ return [
42342
+ ...configIssues.list(within, { pending: pending2 }),
42343
+ ...a ? [a] : [],
42344
+ ...g ? [g] : []
42345
+ ];
42159
42346
  };
42160
42347
  const resolveNs = (cwd, allowMissing) => (deps.resolveNamespace ?? ((dir) => resolveNamespace(dir, { log, allowMissing, issues: configIssues })))(cwd);
42161
42348
  const cl = deps.claude ?? {};
@@ -42201,7 +42388,7 @@ async function runDaemon(deps = {}) {
42201
42388
  log,
42202
42389
  promptIdSupported: () => promptIdSupported,
42203
42390
  uncertain: new HeldStore(
42204
- oc.uncertainFile ?? join11(home(), "opencode-uncertain.json")
42391
+ oc.uncertainFile ?? join12(home(), "opencode-uncertain.json")
42205
42392
  )
42206
42393
  });
42207
42394
  const codex = new CodexTransport({
@@ -42212,7 +42399,7 @@ async function runDaemon(deps = {}) {
42212
42399
  run: cx.run ?? execCodex(),
42213
42400
  home: cx.home ?? codexHome(),
42214
42401
  wakes: cx.wakes ?? codexHostWakes,
42215
- queued: new HeldStore(cx.queuedFile ?? join11(home(), "codex-queued.json")),
42402
+ queued: new HeldStore(cx.queuedFile ?? join12(home(), "codex-queued.json")),
42216
42403
  log
42217
42404
  });
42218
42405
  const pi = new PiTransport({
@@ -42224,7 +42411,7 @@ async function runDaemon(deps = {}) {
42224
42411
  },
42225
42412
  ackTimeoutMs: deps.pi?.ackTimeoutMs
42226
42413
  });
42227
- const sent = new SentStore(deps.sentFile ?? join11(home(), "sent.json"), {
42414
+ const sent = new SentStore(deps.sentFile ?? join12(home(), "sent.json"), {
42228
42415
  log
42229
42416
  });
42230
42417
  const receipts = new Receipts(sent, { after: deps.deliveredTimer });
@@ -42317,15 +42504,15 @@ async function runDaemon(deps = {}) {
42317
42504
  socketsDir: returnDir,
42318
42505
  // A deps.socketsDir is the caller's (tests); ours is re-checked before each bind.
42319
42506
  prepareDir: cl.socketsDir ? void 0 : (d) => prepareReturnDir(d),
42320
- heldFile: cl.heldFile ?? join11(home(), "claude-held.json"),
42321
- returnIndexFile: cl.returnIndexFile ?? (cl.heldFile ? cl.heldFile.replace(/(\.json)?$/, ".return.json") : join11(home(), "claude-return.json")),
42507
+ heldFile: cl.heldFile ?? join12(home(), "claude-held.json"),
42508
+ returnIndexFile: cl.returnIndexFile ?? (cl.heldFile ? cl.heldFile.replace(/(\.json)?$/, ".return.json") : join12(home(), "claude-return.json")),
42322
42509
  statusWindowMs: cl.statusWindowMs,
42323
42510
  injectTimeoutMs: cl.injectTimeoutMs,
42324
42511
  log,
42325
42512
  target: (ref) => claudeTarget(ref, claudeSessions),
42326
42513
  // A native reply is a message from the session: the sink names the sender, never the frame.
42327
42514
  // Every reply names the peer's namespace (the deliver's), so a same-named local peer cannot get it.
42328
- onReply: (agentRef, peerName, text3, namespace, peerId) => {
42515
+ onReply: (agentRef, peerName, text3, namespace2, peerId) => {
42329
42516
  if (!isWellFormed2(text3))
42330
42517
  log(
42331
42518
  `a Claude reply to ${peerName} was not well-formed unicode; sent with U+FFFD`
@@ -42337,7 +42524,7 @@ async function runDaemon(deps = {}) {
42337
42524
  type: "send",
42338
42525
  from_ref: agentRef,
42339
42526
  to_name: peerName,
42340
- to_namespace: namespace,
42527
+ to_namespace: namespace2,
42341
42528
  body
42342
42529
  };
42343
42530
  if (!ClientFrameSchema.safeParse(f).success) {
@@ -42378,7 +42565,7 @@ async function runDaemon(deps = {}) {
42378
42565
  continue;
42379
42566
  }
42380
42567
  if (prev && prev.pid === s.pid) continue;
42381
- if (!isAbsolute5(s.cwd)) continue;
42568
+ if (!isAbsolute6(s.cwd)) continue;
42382
42569
  let ns;
42383
42570
  try {
42384
42571
  ns = resolveNs(s.cwd, true);
@@ -42564,7 +42751,7 @@ async function runDaemon(deps = {}) {
42564
42751
  process.exitCode = 1;
42565
42752
  try {
42566
42753
  writeFileSync4(
42567
- deps.revokedFile ?? join11(home(), "revoked"),
42754
+ deps.revokedFile ?? join12(home(), "revoked"),
42568
42755
  revokedMarker(cfg.machine_token),
42569
42756
  { mode: 384 }
42570
42757
  );
@@ -42612,21 +42799,21 @@ async function runDaemon(deps = {}) {
42612
42799
  statusEveryMs: deps.status?.statusEveryMs
42613
42800
  });
42614
42801
  const hubRoster = (ref) => new Promise(
42615
- (resolve8) => {
42802
+ (resolve9) => {
42616
42803
  const id = pending.open(
42617
42804
  "status",
42618
- (f) => resolve8(f.type === "roster" ? f.agents : void 0)
42805
+ (f) => resolve9(f.type === "roster" ? f.agents : void 0)
42619
42806
  );
42620
42807
  const timer = setTimeout(() => {
42621
42808
  pending.cancel(id);
42622
42809
  hub.cancel(id);
42623
- resolve8(void 0);
42810
+ resolve9(void 0);
42624
42811
  }, deps.statusRosterMs ?? 1500);
42625
42812
  timer.unref();
42626
42813
  if (!hub.send({ v: 1, id, type: "list", from_ref: ref })) {
42627
42814
  clearTimeout(timer);
42628
42815
  pending.cancel(id);
42629
- resolve8(void 0);
42816
+ resolve9(void 0);
42630
42817
  }
42631
42818
  }
42632
42819
  );
@@ -42650,7 +42837,7 @@ async function runDaemon(deps = {}) {
42650
42837
  // this machine's open sessions are in (or only the cwd's).
42651
42838
  onStatus: async (req) => {
42652
42839
  let only;
42653
- if (req.cwd && isAbsolute5(req.cwd)) {
42840
+ if (req.cwd && isAbsolute6(req.cwd)) {
42654
42841
  try {
42655
42842
  only = resolveNs(req.cwd, true).namespace;
42656
42843
  } catch {
@@ -42663,8 +42850,8 @@ async function runDaemon(deps = {}) {
42663
42850
  )
42664
42851
  ];
42665
42852
  const namespaces = await Promise.all(
42666
- names2.map(async (namespace) => {
42667
- const local = live.filter((a) => a.namespace === namespace);
42853
+ names2.map(async (namespace2) => {
42854
+ const local = live.filter((a) => a.namespace === namespace2);
42668
42855
  const mine = new Map(local.map((a) => [a.busName, a.kind]));
42669
42856
  const roster2 = local[0] && hub.open ? await hubRoster(local[0].ref) : void 0;
42670
42857
  const rows = roster2 ? roster2.filter((a) => a.state !== "away").map((a) => ({
@@ -42681,10 +42868,13 @@ async function runDaemon(deps = {}) {
42681
42868
  machine: cfg.label,
42682
42869
  state: "live"
42683
42870
  }));
42684
- return { namespace, agents: rows };
42871
+ return { namespace: namespace2, agents: rows };
42685
42872
  })
42686
42873
  );
42687
- const config_files = configFiles();
42874
+ const config_files = configFiles(
42875
+ void 0,
42876
+ req.caps?.includes(ADAPTER_CAPS.pending)
42877
+ );
42688
42878
  return {
42689
42879
  pid: process.pid,
42690
42880
  version: version2,
@@ -42759,7 +42949,7 @@ async function runDaemon(deps = {}) {
42759
42949
  };
42760
42950
  }
42761
42951
  const cwd = check2.cwd ?? hello.cwd;
42762
- if (!cwd || !isAbsolute5(cwd)) return { error: "cwd must be absolute" };
42952
+ if (!cwd || !isAbsolute6(cwd)) return { error: "cwd must be absolute" };
42763
42953
  let ns;
42764
42954
  try {
42765
42955
  ns = resolveNs(cwd, check2.cwd !== void 0);
@@ -42973,8 +43163,9 @@ async function runDaemon(deps = {}) {
42973
43163
  // src/context.ts
42974
43164
  init_src3();
42975
43165
  import { execFileSync as execFileSync5, spawn as spawn2 } from "node:child_process";
42976
- import { closeSync as closeSync4, openSync as openSync4, readFileSync as readFileSync13 } from "node:fs";
43166
+ import { closeSync as closeSync5, openSync as openSync5, readFileSync as readFileSync13 } from "node:fs";
42977
43167
  import { homedir as homedir3, userInfo as userInfo2 } from "node:os";
43168
+ import { createInterface as createInterface2 } from "node:readline";
42978
43169
  init_src2();
42979
43170
 
42980
43171
  // src/copy.ts
@@ -43279,11 +43470,11 @@ function copy(style) {
43279
43470
  fail("The daemon did not start within 10 seconds."),
43280
43471
  next(`Run ${BUS_CMD} doctor to see why.`)
43281
43472
  ],
43282
- rosterHeader: (namespace, live, queued2) => {
43473
+ rosterHeader: (namespace2, live, queued2) => {
43283
43474
  const n = live + queued2;
43284
43475
  const meta3 = queued2 ? `${live} live ${g("sep")} ${queued2} queued` : `${live} live`;
43285
43476
  const lead = `${n} agent${n === 1 ? "" : "s"} in namespace `;
43286
- return `${lead}${p("accent", clip(namespace, len(lead) + 2 + len(meta3)))} ${p("muted", meta3)}`;
43477
+ return `${lead}${p("accent", clip(namespace2, len(lead) + 2 + len(meta3)))} ${p("muted", meta3)}`;
43287
43478
  },
43288
43479
  rosterRow: (a) => ` ${cell(a.name, 20, more)}${cell(kindLabel(a.kind), 13, more)}${cell(a.machine, 22, more)}${a.state === "live" ? p("success", `${g("live")} live`) : p("warning", `${g("queued")} queued`)}`,
43289
43480
  /** The row's status, under it (AC5c): the agent's own report, cut to 80 columns. */
@@ -43300,10 +43491,10 @@ function copy(style) {
43300
43491
  ),
43301
43492
  p("muted", "then the sender is told.")
43302
43493
  ],
43303
- noAgents: (namespace) => {
43494
+ noAgents: (namespace2) => {
43304
43495
  const lead = "No agents in namespace ";
43305
43496
  return [
43306
- `${lead}${p("accent", clip(namespace, len(lead) + 5))} yet.`,
43497
+ `${lead}${p("accent", clip(namespace2, len(lead) + 5))} yet.`,
43307
43498
  "Start Claude Code, OpenCode, Pi, oh-my-pi or Codex in this folder and it joins."
43308
43499
  ];
43309
43500
  },
@@ -43382,8 +43573,8 @@ function copy(style) {
43382
43573
  next(`Run ${BUS_CMD} --instance <your instance URL>,`),
43383
43574
  next("or set OA_BUS_INSTANCE.")
43384
43575
  ],
43385
- hubMismatch: (approved, asked, askedUrl) => {
43386
- const a = clip(approved, 39 + Math.min(len(asked), 20));
43576
+ hubMismatch: (approved2, asked, askedUrl) => {
43577
+ const a = clip(approved2, 39 + Math.min(len(asked), 20));
43387
43578
  const b2 = clip(asked, 39 + len(a));
43388
43579
  return [
43389
43580
  fail(`This machine is approved for ${a}, not ${b2}.`),
@@ -43488,7 +43679,7 @@ function copy(style) {
43488
43679
  /** A refused or noted config file (#1527): the reason, then the exact fix. Paths arrive already shortened. */
43489
43680
  configFile: (f) => [
43490
43681
  warn(
43491
- f.state === "refused" ? `${f.file} ${f.reason}, so it is ignored.` : `${f.file} ${f.reason}; it is still used.`
43682
+ f.state === "refused" ? `${f.file} ${f.reason}, so it is ignored.` : f.state === "pending" ? `${f.file} ${f.reason}, so its namespace is ignored.` : `${f.file} ${f.reason}; it is still used.`
43492
43683
  ),
43493
43684
  next(`Fix: ${f.fix}`),
43494
43685
  ...f.restart ? [next("Restart the session to pick up a fix.")] : []
@@ -43622,6 +43813,60 @@ function copy(style) {
43622
43813
  `${dirs.length} global ${dirs.length === 1 ? "directory" : "directories"}`,
43623
43814
  ...dirs.map((d) => ` ${clip(d, 2)}`)
43624
43815
  ],
43816
+ // 12. namespace approvals (#1525)
43817
+ nsUnusable: (path, why) => [
43818
+ warn(`${clip(path, 45)} can't be used, so no namespace is approved.`),
43819
+ next(p("muted", clip(`It ${why}.`, 3))),
43820
+ next(`Remove it, then run ${BUS_CMD} namespace approve <dir> again.`)
43821
+ ],
43822
+ nsNoFile: (dir) => [
43823
+ fail(`${clip(dir, 40)} has no .oa-bus.json.`),
43824
+ next("Check the path: approval is for the namespace that file sets.")
43825
+ ],
43826
+ nsFileUnusable: (file2, why) => [
43827
+ fail(`${clip(file2, 40)} can't be read: it ${why}.`)
43828
+ ],
43829
+ nsNoNamespace: (file2) => warn(`${clip(file2, 40)} sets no namespace. Nothing to approve.`),
43830
+ nsNotDir: (dir) => [
43831
+ fail(`${clip(dir, 23)} is not a directory.`),
43832
+ next(`Check the path, then run ${BUS_CMD} namespace approve again.`)
43833
+ ],
43834
+ nsAsk: (dir, namespace2) => [
43835
+ `${dir} sets its namespace to ${namespace2}.`,
43836
+ "Agents started there join it and can message everyone in it."
43837
+ ],
43838
+ nsPrompt: () => "Approve it? [y/N] ",
43839
+ nsNeedTty: (command) => [
43840
+ fail("Approving a namespace needs your user."),
43841
+ next(`Ask them to run this in a terminal: ${command}`)
43842
+ ],
43843
+ nsDeclined: () => warn("Not approved. Nothing changed."),
43844
+ nsAlready: (dir, namespace2) => done(`${clip(dir, 20)} is already approved for ${clip(namespace2, 40)}.`),
43845
+ nsApproved: (dir, namespace2) => [
43846
+ done(
43847
+ `${clip(dir, 20)} may now use the namespace ${clip(namespace2, 40)}.`
43848
+ ),
43849
+ p(
43850
+ "muted",
43851
+ " Agents already running there keep their namespace until they restart."
43852
+ )
43853
+ ],
43854
+ nsRevoked: (dir) => [
43855
+ done(`${clip(dir, 24)} is no longer approved.`),
43856
+ p(
43857
+ "muted",
43858
+ " Agents already running there keep their namespace until they restart."
43859
+ )
43860
+ ],
43861
+ nsNotListed: (dir) => warn(`${clip(dir, 36)} was not approved. Nothing changed.`),
43862
+ nsNone: () => [
43863
+ "No approved namespaces.",
43864
+ p("muted", `Approve one with ${BUS_CMD} namespace approve <dir>.`)
43865
+ ],
43866
+ nsList: (rows) => [
43867
+ `${rows.length} approved ${rows.length === 1 ? "namespace" : "namespaces"}`,
43868
+ ...rows.map((r) => ` ${clip(r.dir, 2)} ${p("muted", r.namespace)}`)
43869
+ ],
43625
43870
  // logs, mcp (DRAFT)
43626
43871
  noLog: (path) => [
43627
43872
  warn(`No daemon log yet at ${clip(path, 24)}`),
@@ -43640,19 +43885,19 @@ init_src2();
43640
43885
  import { execFile as execFile3, spawn } from "node:child_process";
43641
43886
  import { promisify } from "node:util";
43642
43887
  var browserCommand = (platform, url2) => platform === "darwin" ? { cmd: "open", args: [url2] } : platform === "win32" ? { cmd: "rundll32", args: ["url.dll,FileProtocolHandler", url2] } : { cmd: "xdg-open", args: [url2] };
43643
- var openBrowser = (url2, launcher = browserCommand(process.platform, url2)) => new Promise((resolve8) => {
43888
+ var openBrowser = (url2, launcher = browserCommand(process.platform, url2)) => new Promise((resolve9) => {
43644
43889
  try {
43645
43890
  const child = spawn(launcher.cmd, launcher.args, {
43646
43891
  stdio: "ignore",
43647
43892
  detached: true
43648
43893
  });
43649
- child.once("error", () => resolve8(false));
43894
+ child.once("error", () => resolve9(false));
43650
43895
  child.once("spawn", () => {
43651
43896
  child.unref();
43652
- resolve8(true);
43897
+ resolve9(true);
43653
43898
  });
43654
43899
  } catch {
43655
- resolve8(false);
43900
+ resolve9(false);
43656
43901
  }
43657
43902
  });
43658
43903
  var EXEC_TIMEOUT_MS = 1e4;
@@ -43693,22 +43938,22 @@ var realDeps = {
43693
43938
  // src/steps/service.ts
43694
43939
  import { createHash as createHash5 } from "node:crypto";
43695
43940
  import {
43696
- chmodSync as chmodSync8,
43941
+ chmodSync as chmodSync9,
43697
43942
  cpSync,
43698
43943
  existsSync as existsSync3,
43699
43944
  lstatSync as lstatSync8,
43700
- mkdirSync as mkdirSync7,
43945
+ mkdirSync as mkdirSync8,
43701
43946
  realpathSync as realpathSync7,
43702
- renameSync as renameSync7,
43947
+ renameSync as renameSync8,
43703
43948
  rmSync as rmSync4,
43704
43949
  writeFileSync as writeFileSync6
43705
43950
  } from "node:fs";
43706
- import { basename as basename6, dirname as dirname7, isAbsolute as isAbsolute6, join as join13, resolve as resolve4 } from "node:path";
43951
+ import { basename as basename6, dirname as dirname8, isAbsolute as isAbsolute7, join as join14, resolve as resolve4 } from "node:path";
43707
43952
  import { fileURLToPath } from "node:url";
43708
43953
 
43709
43954
  // src/steps/codex.ts
43710
43955
  import { lstatSync as lstatSync7, readFileSync as readFileSync11 } from "node:fs";
43711
- import { join as join12, resolve as resolve3 } from "node:path";
43956
+ import { join as join13, resolve as resolve3 } from "node:path";
43712
43957
 
43713
43958
  // ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/error.js
43714
43959
  function getLineColFromPtr(string4, ptr) {
@@ -44470,12 +44715,12 @@ var HAS_WELLFORMED = !!"".isWellFormed;
44470
44715
 
44471
44716
  // src/steps/codex.ts
44472
44717
  var CODEX_ENTRY = "oa_bus";
44473
- var codexHome2 = (home2, env2) => env2.CODEX_HOME ? resolve3(env2.CODEX_HOME) : join12(home2, ".codex");
44718
+ var codexHome2 = (home2, env2) => env2.CODEX_HOME ? resolve3(env2.CODEX_HOME) : join13(home2, ".codex");
44474
44719
  function codexHomeEnv(home2, env2) {
44475
44720
  const dir = codexHome2(home2, env2);
44476
- return dir === join12(home2, ".codex") ? {} : { CODEX_HOME: dir };
44721
+ return dir === join13(home2, ".codex") ? {} : { CODEX_HOME: dir };
44477
44722
  }
44478
- var codexConfig = (home2, env2) => join12(codexHome2(home2, env2), "config.toml");
44723
+ var codexConfig = (home2, env2) => join13(codexHome2(home2, env2), "config.toml");
44479
44724
  function hasCodex(o) {
44480
44725
  if (o.which("codex")) return true;
44481
44726
  try {
@@ -44509,7 +44754,7 @@ function codexEntry(busBin, home2, busHome2) {
44509
44754
  return {
44510
44755
  command: busBin[0],
44511
44756
  args: [...busBin.slice(1), "mcp", "codex"],
44512
- ...ob === join12(home2, ".oa-bus") ? {} : { env: { OA_BUS_HOME: ob } },
44757
+ ...ob === join13(home2, ".oa-bus") ? {} : { env: { OA_BUS_HOME: ob } },
44513
44758
  default_tools_approval_mode: "approve"
44514
44759
  };
44515
44760
  }
@@ -44535,7 +44780,7 @@ function sandboxRisk(doc, home2, codexDir) {
44535
44780
  });
44536
44781
  const covers = (root) => {
44537
44782
  const r = resolve3(
44538
- root === "~" ? home2 : root.startsWith("~/") ? join12(home2, root.slice(2)) : root
44783
+ root === "~" ? home2 : root.startsWith("~/") ? join13(home2, root.slice(2)) : root
44539
44784
  );
44540
44785
  return r === "/" || codexDir === r || codexDir.startsWith(`${r}/`) || r.startsWith(`${codexDir}/`);
44541
44786
  };
@@ -44742,13 +44987,13 @@ function remove(path, text3, doc) {
44742
44987
 
44743
44988
  // src/steps/step.ts
44744
44989
  import {
44745
- chmodSync as chmodSync7,
44746
- mkdirSync as mkdirSync6,
44990
+ chmodSync as chmodSync8,
44991
+ mkdirSync as mkdirSync7,
44747
44992
  readFileSync as readFileSync12,
44748
- renameSync as renameSync6,
44993
+ renameSync as renameSync7,
44749
44994
  writeFileSync as writeFileSync5
44750
44995
  } from "node:fs";
44751
- import { dirname as dirname6 } from "node:path";
44996
+ import { dirname as dirname7 } from "node:path";
44752
44997
  function readInstallFile(path) {
44753
44998
  try {
44754
44999
  const v = JSON.parse(readFileSync12(path, "utf8"));
@@ -44760,12 +45005,12 @@ function readInstallFile(path) {
44760
45005
  }
44761
45006
  function updateInstallFile(path, patch) {
44762
45007
  const next = { ...readInstallFile(path), ...patch };
44763
- mkdirSync6(dirname6(path), { recursive: true, mode: 448 });
45008
+ mkdirSync7(dirname7(path), { recursive: true, mode: 448 });
44764
45009
  const tmp = `${path}.${process.pid}.tmp`;
44765
45010
  writeFileSync5(tmp, `${JSON.stringify(next, null, 2)}
44766
45011
  `, { mode: 384 });
44767
- chmodSync7(tmp, 384);
44768
- renameSync6(tmp, path);
45012
+ chmodSync8(tmp, 384);
45013
+ renameSync7(tmp, path);
44769
45014
  }
44770
45015
  async function runSteps(steps, ctx, record6) {
44771
45016
  for (const step2 of steps) {
@@ -44861,7 +45106,7 @@ function cliSource() {
44861
45106
  jiti: import.meta.resolve("jiti")
44862
45107
  } : { kind: "bundle", file: here };
44863
45108
  }
44864
- var entryName = (src) => src.kind === "bundle" ? join13(basename6(dirname7(src.file)), basename6(src.file)) : "oa-bus.js";
45109
+ var entryName = (src) => src.kind === "bundle" ? join14(basename6(dirname8(src.file)), basename6(src.file)) : "oa-bus.js";
44865
45110
  var shim = (src) => `// Written by oa-bus install: runs the sources it was installed from.
44866
45111
  import { createJiti } from ${JSON.stringify(src.jiti)};
44867
45112
 
@@ -44871,24 +45116,24 @@ const code = await main(process.argv.slice(2));
44871
45116
  if (code !== undefined) process.exit(code);
44872
45117
  `;
44873
45118
  function installCli(home2, src) {
44874
- const bin = join13(home2, "bin");
45119
+ const bin = join14(home2, "bin");
44875
45120
  const tmp = `${bin}.${process.pid}.tmp`;
44876
- mkdirSync7(home2, { recursive: true, mode: 448 });
44877
- chmodSync8(home2, 448);
45121
+ mkdirSync8(home2, { recursive: true, mode: 448 });
45122
+ chmodSync9(home2, 448);
44878
45123
  rmSync4(tmp, { recursive: true, force: true });
44879
- mkdirSync7(tmp);
45124
+ mkdirSync8(tmp);
44880
45125
  if (src.kind === "bundle") {
44881
- const pkg = dirname7(dirname7(src.file));
45126
+ const pkg = dirname8(dirname8(src.file));
44882
45127
  for (const name of ["dist", "assets", "package.json"])
44883
- if (existsSync3(join13(pkg, name)))
44884
- cpSync(join13(pkg, name), join13(tmp, name), { recursive: true });
44885
- } else writeFileSync6(join13(tmp, entryName(src)), shim(src));
44886
- chmodSync8(tmp, 448);
44887
- if (!existsSync3(join13(tmp, "package.json")))
44888
- writeFileSync6(join13(tmp, "package.json"), '{ "type": "module" }\n');
45128
+ if (existsSync3(join14(pkg, name)))
45129
+ cpSync(join14(pkg, name), join14(tmp, name), { recursive: true });
45130
+ } else writeFileSync6(join14(tmp, entryName(src)), shim(src));
45131
+ chmodSync9(tmp, 448);
45132
+ if (!existsSync3(join14(tmp, "package.json")))
45133
+ writeFileSync6(join14(tmp, "package.json"), '{ "type": "module" }\n');
44889
45134
  rmSync4(bin, { recursive: true, force: true });
44890
- renameSync7(tmp, bin);
44891
- return join13(bin, entryName(src));
45135
+ renameSync8(tmp, bin);
45136
+ return join14(bin, entryName(src));
44892
45137
  }
44893
45138
  var present = (path) => {
44894
45139
  try {
@@ -44899,11 +45144,11 @@ var present = (path) => {
44899
45144
  }
44900
45145
  };
44901
45146
  function writeReplacing(path, text3) {
44902
- mkdirSync7(dirname7(path), { recursive: true });
45147
+ mkdirSync8(dirname8(path), { recursive: true });
44903
45148
  const tmp = `${path}.${process.pid}.tmp`;
44904
45149
  try {
44905
45150
  writeFileSync6(tmp, text3, { mode: 420 });
44906
- renameSync7(tmp, path);
45151
+ renameSync8(tmp, path);
44907
45152
  } catch (e) {
44908
45153
  rmSync4(tmp, { force: true });
44909
45154
  throw e;
@@ -44914,11 +45159,11 @@ var real = (path) => {
44914
45159
  try {
44915
45160
  return realpathSync7(abs);
44916
45161
  } catch {
44917
- const parent = dirname7(abs);
44918
- return parent === abs ? abs : join13(real(parent), basename6(abs));
45162
+ const parent = dirname8(abs);
45163
+ return parent === abs ? abs : join14(real(parent), basename6(abs));
44919
45164
  }
44920
45165
  };
44921
- var isDefaultHome = (home2, userHome) => real(home2) === real(join13(userHome, ".oa-bus"));
45166
+ var isDefaultHome = (home2, userHome) => real(home2) === real(join14(userHome, ".oa-bus"));
44922
45167
  function serviceNames(home2, userHome) {
44923
45168
  const suffix = isDefaultHome(home2, userHome) ? "" : createHash5("sha256").update(real(home2)).digest("hex").slice(0, 8);
44924
45169
  return {
@@ -44945,19 +45190,19 @@ function systemService(d) {
44945
45190
  const manager = d.platform === "darwin" ? "launchd" : d.platform === "linux" ? "systemd" : void 0;
44946
45191
  const home2 = () => resolve4(d.home());
44947
45192
  const names2 = () => serviceNames(home2(), d.userHome);
44948
- const entryOf = () => join13(home2(), "bin", entryName(d.source()));
44949
- const installFile = () => join13(home2(), "install.json");
45193
+ const entryOf = () => join14(home2(), "bin", entryName(d.source()));
45194
+ const installFile = () => join14(home2(), "install.json");
44950
45195
  const record6 = () => {
44951
45196
  const r = readInstallFile(installFile()).service;
44952
45197
  return typeof r === "object" && r !== null ? r : {};
44953
45198
  };
44954
45199
  const xdg = d.env.XDG_CONFIG_HOME;
44955
- const configHome = xdg && isAbsolute6(xdg) ? xdg : join13(d.userHome, ".config");
45200
+ const configHome = xdg && isAbsolute7(xdg) ? xdg : join14(d.userHome, ".config");
44956
45201
  const fileName = () => manager === "launchd" ? `${names2().label}.plist` : names2().unit;
44957
- const fresh = () => manager === "launchd" ? join13(d.userHome, "Library/LaunchAgents", fileName()) : join13(configHome, "systemd/user", fileName());
45202
+ const fresh = () => manager === "launchd" ? join14(d.userHome, "Library/LaunchAgents", fileName()) : join14(configHome, "systemd/user", fileName());
44958
45203
  const recorded = () => {
44959
45204
  const r = record6().unit;
44960
- return typeof r === "string" && isAbsolute6(r) && basename6(r) === fileName() ? r : void 0;
45205
+ return typeof r === "string" && isAbsolute7(r) && basename6(r) === fileName() ? r : void 0;
44961
45206
  };
44962
45207
  const file2 = () => {
44963
45208
  const r = recorded();
@@ -45019,10 +45264,10 @@ function systemService(d) {
45019
45264
  async ensure() {
45020
45265
  const h = home2();
45021
45266
  const src = d.source();
45022
- const logs2 = join13(h, "logs");
45267
+ const logs2 = join14(h, "logs");
45023
45268
  const u = {
45024
45269
  node: d.execPath,
45025
- entry: join13(h, "bin", entryName(src)),
45270
+ entry: join14(h, "bin", entryName(src)),
45026
45271
  env: {
45027
45272
  PATH: d.env.PATH ?? DEFAULT_PATH,
45028
45273
  ...isDefaultHome(h, d.userHome) ? {} : { OA_BUS_HOME: h },
@@ -45030,8 +45275,8 @@ function systemService(d) {
45030
45275
  ...codexHomeEnv(d.userHome, d.env)
45031
45276
  },
45032
45277
  // One file: the daemon logs to stderr, and `oa-bus logs` tails it.
45033
- out: join13(logs2, "daemon.log"),
45034
- err: join13(logs2, "daemon.log")
45278
+ out: join14(logs2, "daemon.log"),
45279
+ err: join14(logs2, "daemon.log")
45035
45280
  };
45036
45281
  const unit = { ...u, env: { ...u.env, OA_BUS_SERVICE: "1" } };
45037
45282
  renderPlist(unit);
@@ -45042,7 +45287,7 @@ function systemService(d) {
45042
45287
  const left = await stopDaemon();
45043
45288
  if (left !== void 0) return { running: left };
45044
45289
  installCli(h, src);
45045
- mkdirSync7(logs2, { recursive: true, mode: 448 });
45290
+ mkdirSync8(logs2, { recursive: true, mode: 448 });
45046
45291
  const f = fresh();
45047
45292
  const old = recorded();
45048
45293
  if (old && old !== f) {
@@ -45132,7 +45377,7 @@ function systemService(d) {
45132
45377
  const node2 = record6().node;
45133
45378
  if (typeof node2 === "string" && !existsSync3(node2))
45134
45379
  out.push({ kind: "node-missing", node: node2 });
45135
- if (manager === "systemd" && !existsSync3(join13(d.lingerDir ?? "/var/lib/systemd/linger", d.user)))
45380
+ if (manager === "systemd" && !existsSync3(join14(d.lingerDir ?? "/var/lib/systemd/linger", d.user)))
45136
45381
  out.push({ kind: "linger-off" });
45137
45382
  return out;
45138
45383
  }
@@ -45145,7 +45390,7 @@ var noService = {
45145
45390
  remove: async () => ({}),
45146
45391
  cli: () => ["oa-bus"]
45147
45392
  };
45148
- var VERSION = true ? "0.127.0" : JSON.parse(
45393
+ var VERSION = true ? "0.129.0" : JSON.parse(
45149
45394
  readFileSync13(new URL("../package.json", import.meta.url), "utf8")
45150
45395
  ).version;
45151
45396
  var which = (cmd) => {
@@ -45174,8 +45419,8 @@ function processArgs2(pid, io = {
45174
45419
  }
45175
45420
  }
45176
45421
  var spawnDaemon = (cmd, args, opts) => {
45177
- const out = openSync4(opts.out, "a", 384);
45178
- const err = openSync4(opts.err, "a", 384);
45422
+ const out = openSync5(opts.out, "a", 384);
45423
+ const err = openSync5(opts.err, "a", 384);
45179
45424
  try {
45180
45425
  const child = spawn2(cmd, args, {
45181
45426
  detached: true,
@@ -45185,8 +45430,8 @@ var spawnDaemon = (cmd, args, opts) => {
45185
45430
  child.unref();
45186
45431
  return child.pid;
45187
45432
  } finally {
45188
- closeSync4(out);
45189
- closeSync4(err);
45433
+ closeSync5(out);
45434
+ closeSync5(err);
45190
45435
  }
45191
45436
  };
45192
45437
  var userName = () => {
@@ -45218,7 +45463,21 @@ function realCtx(noColor) {
45218
45463
  copy: copy(style),
45219
45464
  platform: `${process.platform} ${process.arch}`,
45220
45465
  nodeVersion: process.version,
45221
- ...process.platform === "darwin" ? { codexApp: CODEX_APP } : {}
45466
+ ...process.platform === "darwin" ? { codexApp: CODEX_APP } : {},
45467
+ stdinIsTTY: Boolean(process.stdin.isTTY),
45468
+ readLine: async (question) => {
45469
+ const rl = createInterface2({
45470
+ input: process.stdin,
45471
+ output: process.stdout
45472
+ });
45473
+ try {
45474
+ return await new Promise(
45475
+ (resolve9) => rl.question(question, resolve9)
45476
+ );
45477
+ } finally {
45478
+ rl.close();
45479
+ }
45480
+ }
45222
45481
  };
45223
45482
  ctx.service = systemService({
45224
45483
  platform: process.platform,
@@ -45300,10 +45559,10 @@ var configFileLines = (ctx, files) => files.flatMap(
45300
45559
 
45301
45560
  // src/machine.ts
45302
45561
  import { readFileSync as readFileSync14, statSync as statSync8 } from "node:fs";
45303
- import { join as join14 } from "node:path";
45562
+ import { join as join15 } from "node:path";
45304
45563
  init_src();
45305
45564
  function readMachine(home2) {
45306
- const file2 = join14(home2, "machine.json");
45565
+ const file2 = join15(home2, "machine.json");
45307
45566
  let text3;
45308
45567
  let mode;
45309
45568
  try {
@@ -45334,11 +45593,11 @@ var lasting = (e) => [...START_ERROR_CODES, "EACCES", "EPERM"].includes(
45334
45593
  );
45335
45594
  async function daemon(ctx, run4 = runDaemon, signals = process) {
45336
45595
  const m = readMachine(ctx.home);
45337
- if (existsSync4(join15(ctx.home, "revoked")) && (m.state !== "ok" || m.revoked)) {
45596
+ if (existsSync4(join16(ctx.home, "revoked")) && (m.state !== "ok" || m.revoked)) {
45338
45597
  sayErr(ctx, ctx.copy.revoked());
45339
45598
  return 0;
45340
45599
  }
45341
- return new Promise((resolve8) => {
45600
+ return new Promise((resolve9) => {
45342
45601
  let running;
45343
45602
  let ended = false;
45344
45603
  const end = (code2) => {
@@ -45346,7 +45605,7 @@ async function daemon(ctx, run4 = runDaemon, signals = process) {
45346
45605
  ended = true;
45347
45606
  signals.off("SIGINT", onSignal);
45348
45607
  signals.off("SIGTERM", onSignal);
45349
- void (running?.stop() ?? Promise.resolve()).finally(() => resolve8(code2));
45608
+ void (running?.stop() ?? Promise.resolve()).finally(() => resolve9(code2));
45350
45609
  };
45351
45610
  const onSignal = () => end(0);
45352
45611
  signals.once("SIGINT", onSignal);
@@ -45376,7 +45635,7 @@ async function daemon(ctx, run4 = runDaemon, signals = process) {
45376
45635
 
45377
45636
  // src/commands/doctor.ts
45378
45637
  import { readFileSync as readFileSync17 } from "node:fs";
45379
- import { join as join20 } from "node:path";
45638
+ import { join as join21 } from "node:path";
45380
45639
 
45381
45640
  // ../bus-adapter-opencode/src/index.ts
45382
45641
  init_session2();
@@ -45387,20 +45646,20 @@ var OPENCODE_TUI_PLUGIN = fileURLToPath2(
45387
45646
  );
45388
45647
 
45389
45648
  // src/steps/adapters.ts
45390
- import { randomBytes as randomBytes2 } from "node:crypto";
45649
+ import { randomBytes as randomBytes3 } from "node:crypto";
45391
45650
  import {
45392
- chmodSync as chmodSync9,
45651
+ chmodSync as chmodSync10,
45393
45652
  existsSync as existsSync5,
45394
45653
  lstatSync as lstatSync9,
45395
- mkdirSync as mkdirSync8,
45654
+ mkdirSync as mkdirSync9,
45396
45655
  readFileSync as readFileSync15,
45397
45656
  readlinkSync,
45398
- renameSync as renameSync8,
45657
+ renameSync as renameSync9,
45399
45658
  rmSync as rmSync5,
45400
45659
  statSync as statSync9,
45401
45660
  writeFileSync as writeFileSync7
45402
45661
  } from "node:fs";
45403
- import { dirname as dirname8, join as join16, resolve as resolve5 } from "node:path";
45662
+ import { dirname as dirname9, join as join17, resolve as resolve5 } from "node:path";
45404
45663
  import { isDeepStrictEqual } from "node:util";
45405
45664
 
45406
45665
  // ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/scanner.js
@@ -46632,31 +46891,31 @@ var readAssets = () => ({
46632
46891
  var movedHome = (deps) => {
46633
46892
  if (deps.busHome === void 0) return void 0;
46634
46893
  const ob = resolve5(deps.busHome);
46635
- return ob === join16(deps.home, ".oa-bus") ? void 0 : ob;
46894
+ return ob === join17(deps.home, ".oa-bus") ? void 0 : ob;
46636
46895
  };
46637
46896
  var homeLine = (ob) => `process.env.OA_BUS_HOME ||= ${JSON.stringify(ob)};`;
46638
46897
  var withHome = (text3, ob) => ob === void 0 ? text3 : `${homeLine(ob)}
46639
46898
  ${text3}`;
46640
46899
  var paths = (deps) => {
46641
46900
  const env2 = deps.env ?? {};
46642
- const opencode = env2.OPENCODE_CONFIG_DIR ?? join16(env2.XDG_CONFIG_HOME ?? join16(deps.home, ".config"), "opencode");
46643
- const busDir = deps.busHome ?? join16(deps.home, ".oa-bus");
46901
+ const opencode = env2.OPENCODE_CONFIG_DIR ?? join17(env2.XDG_CONFIG_HOME ?? join17(deps.home, ".config"), "opencode");
46902
+ const busDir = deps.busHome ?? join17(deps.home, ".oa-bus");
46644
46903
  return {
46645
- claude: join16(env2.CLAUDE_CONFIG_DIR ?? deps.home, ".claude.json"),
46904
+ claude: join17(env2.CLAUDE_CONFIG_DIR ?? deps.home, ".claude.json"),
46646
46905
  // OpenCode reads both; edit the one the user has, else create .json.
46647
46906
  opencodeConfigs: [
46648
- join16(opencode, "opencode.json"),
46649
- join16(opencode, "opencode.jsonc")
46907
+ join17(opencode, "opencode.json"),
46908
+ join17(opencode, "opencode.jsonc")
46650
46909
  ],
46651
- opencodeCli: join16(opencode, "cli.json"),
46652
- record: join16(busDir, "install.json"),
46910
+ opencodeCli: join17(opencode, "cli.json"),
46911
+ record: join17(busDir, "install.json"),
46653
46912
  // OpenCode registers the folder that holds tui.js.
46654
- opencodePlugin: join16(busDir, "integrations/opencode", NAME),
46655
- pi: join16(
46656
- agentDirEnv(deps.home, env2) ?? join16(deps.home, ".pi/agent"),
46913
+ opencodePlugin: join17(busDir, "integrations/opencode", NAME),
46914
+ pi: join17(
46915
+ agentDirEnv(deps.home, env2) ?? join17(deps.home, ".pi/agent"),
46657
46916
  "extensions/oa-bus.ts"
46658
46917
  ),
46659
- omp: join16(ompAgentDir(deps.home, env2), "extensions/oa-bus.ts"),
46918
+ omp: join17(ompAgentDir(deps.home, env2), "extensions/oa-bus.ts"),
46660
46919
  codex: codexConfig(deps.home, env2),
46661
46920
  codexBin: codexBinFile(busDir),
46662
46921
  busDir
@@ -46666,9 +46925,9 @@ function agentDirEnv(home2, env2) {
46666
46925
  const dir = env2.PI_CODING_AGENT_DIR;
46667
46926
  if (!dir) return void 0;
46668
46927
  if (dir === "~") return home2;
46669
- return resolve5(dir.startsWith("~/") ? join16(home2, dir.slice(2)) : dir);
46928
+ return resolve5(dir.startsWith("~/") ? join17(home2, dir.slice(2)) : dir);
46670
46929
  }
46671
- var ompRoot = (home2, env2) => join16(home2, env2.PI_CONFIG_DIR || ".omp");
46930
+ var ompRoot = (home2, env2) => join17(home2, env2.PI_CONFIG_DIR || ".omp");
46672
46931
  function ompProfile(env2) {
46673
46932
  const name = (env2.OMP_PROFILE !== void 0 ? env2.OMP_PROFILE : env2.PI_PROFILE)?.trim();
46674
46933
  if (!name || name === "default" || name.endsWith(".")) return void 0;
@@ -46677,14 +46936,14 @@ function ompProfile(env2) {
46677
46936
  function ompAgentDir(home2, env2) {
46678
46937
  const root = ompRoot(home2, env2);
46679
46938
  const profile = ompProfile(env2);
46680
- if (profile) return join16(root, "profiles", profile, "agent");
46939
+ if (profile) return join17(root, "profiles", profile, "agent");
46681
46940
  const piProfile = ompProfile({ PI_PROFILE: env2.PI_PROFILE });
46682
46941
  const dir = agentDirEnv(home2, env2);
46683
- if (dir && !(piProfile && dir === join16(root, "profiles", piProfile, "agent")))
46942
+ if (dir && !(piProfile && dir === join17(root, "profiles", piProfile, "agent")))
46684
46943
  return dir;
46685
- return join16(root, "agent");
46944
+ return join17(root, "agent");
46686
46945
  }
46687
- var hasOmp = (deps) => deps.which("omp") || present2(ompRoot(deps.home, deps.env ?? {})) || present2(join16(deps.home, ".bun/bin/omp"));
46946
+ var hasOmp = (deps) => deps.which("omp") || present2(ompRoot(deps.home, deps.env ?? {})) || present2(join17(deps.home, ".bun/bin/omp"));
46688
46947
  var sharedFile = (deps) => paths(deps).omp === paths(deps).pi;
46689
46948
  function readDoc(path) {
46690
46949
  let text3;
@@ -46714,30 +46973,30 @@ function target(path) {
46714
46973
  let p = path;
46715
46974
  for (let hops = 0; hops < 40; hops++) {
46716
46975
  if (!present2(p) || !lstatSync9(p).isSymbolicLink()) {
46717
- if (p !== path && !existsSync5(dirname8(p)))
46976
+ if (p !== path && !existsSync5(dirname9(p)))
46718
46977
  throw new Error(
46719
46978
  `${path} is a dangling symlink to ${p}; left it untouched`
46720
46979
  );
46721
46980
  return p;
46722
46981
  }
46723
- p = resolve5(dirname8(p), readlinkSync(p));
46982
+ p = resolve5(dirname9(p), readlinkSync(p));
46724
46983
  }
46725
46984
  throw new Error(`${path}: too many symlinks; left it untouched`);
46726
46985
  }
46727
46986
  function writeAtomic(path, data, mode) {
46728
46987
  const dest = target(path);
46729
- mkdirSync8(dirname8(dest), { recursive: true });
46988
+ mkdirSync9(dirname9(dest), { recursive: true });
46730
46989
  let m = mode ?? 420;
46731
46990
  if (mode === void 0)
46732
46991
  try {
46733
46992
  m = statSync9(dest).mode & 511;
46734
46993
  } catch {
46735
46994
  }
46736
- const tmp = `${dest}.${process.pid}.${randomBytes2(4).toString("hex")}.tmp`;
46995
+ const tmp = `${dest}.${process.pid}.${randomBytes3(4).toString("hex")}.tmp`;
46737
46996
  try {
46738
46997
  writeFileSync7(tmp, data, { mode: m, flag: "wx" });
46739
- chmodSync9(tmp, m);
46740
- renameSync8(tmp, dest);
46998
+ chmodSync10(tmp, m);
46999
+ renameSync9(tmp, dest);
46741
47000
  } catch (e) {
46742
47001
  rmSync5(tmp, { force: true });
46743
47002
  throw e;
@@ -46892,7 +47151,7 @@ var install = {
46892
47151
  created[p.opencodeCli] = add(p.opencodeCli, madeCli);
46893
47152
  writeRecord(p.record, record6, created);
46894
47153
  writeAtomic(
46895
- join16(p.opencodePlugin, "tui.js"),
47154
+ join17(p.opencodePlugin, "tui.js"),
46896
47155
  withHome(deps.assets.opencodePlugin, movedHome(deps)),
46897
47156
  420
46898
47157
  );
@@ -47108,7 +47367,7 @@ function checkAdapters(deps) {
47108
47367
  }) && listed(
47109
47368
  parseJsonc(readFileSync15(p.opencodeCli, "utf8"), p.opencodeCli),
47110
47369
  p.opencodePlugin
47111
- ) && homed(join16(p.opencodePlugin, "tui.js"))
47370
+ ) && homed(join17(p.opencodePlugin, "tui.js"))
47112
47371
  ),
47113
47372
  pi: state("pi", () => homed(p.pi)),
47114
47373
  omp: state("omp", () => homed(p.omp)),
@@ -47130,18 +47389,18 @@ function checkAdapters(deps) {
47130
47389
 
47131
47390
  // src/commands/login.ts
47132
47391
  init_src();
47133
- import { randomBytes as randomBytes3 } from "node:crypto";
47392
+ import { randomBytes as randomBytes4 } from "node:crypto";
47134
47393
  import {
47135
- chmodSync as chmodSync10,
47136
- closeSync as closeSync5,
47137
- mkdirSync as mkdirSync9,
47138
- openSync as openSync5,
47139
- renameSync as renameSync9,
47394
+ chmodSync as chmodSync11,
47395
+ closeSync as closeSync6,
47396
+ mkdirSync as mkdirSync10,
47397
+ openSync as openSync6,
47398
+ renameSync as renameSync10,
47140
47399
  rmSync as rmSync6,
47141
- unlinkSync as unlinkSync2,
47142
- writeSync as writeSync2
47400
+ unlinkSync as unlinkSync3,
47401
+ writeSync as writeSync3
47143
47402
  } from "node:fs";
47144
- import { join as join17 } from "node:path";
47403
+ import { join as join18 } from "node:path";
47145
47404
 
47146
47405
  // src/machine-label.ts
47147
47406
  import { hostname as osHostname } from "node:os";
@@ -47187,23 +47446,23 @@ function checkVerificationUri(uri, hub) {
47187
47446
  return uri;
47188
47447
  }
47189
47448
  function writeMachineFile(home2, body) {
47190
- mkdirSync9(home2, { recursive: true, mode: 448 });
47191
- chmodSync10(home2, 448);
47192
- const tmp = join17(home2, `.machine.json.${randomBytes3(8).toString("hex")}.tmp`);
47193
- const fd = openSync5(tmp, "wx", 384);
47449
+ mkdirSync10(home2, { recursive: true, mode: 448 });
47450
+ chmodSync11(home2, 448);
47451
+ const tmp = join18(home2, `.machine.json.${randomBytes4(8).toString("hex")}.tmp`);
47452
+ const fd = openSync6(tmp, "wx", 384);
47194
47453
  try {
47195
- writeSync2(fd, body);
47454
+ writeSync3(fd, body);
47196
47455
  } catch (e) {
47197
- closeSync5(fd);
47198
- unlinkSync2(tmp);
47456
+ closeSync6(fd);
47457
+ unlinkSync3(tmp);
47199
47458
  throw e;
47200
47459
  }
47201
- closeSync5(fd);
47460
+ closeSync6(fd);
47202
47461
  try {
47203
- chmodSync10(tmp, 384);
47204
- renameSync9(tmp, join17(home2, "machine.json"));
47462
+ chmodSync11(tmp, 384);
47463
+ renameSync10(tmp, join18(home2, "machine.json"));
47205
47464
  } catch (e) {
47206
- unlinkSync2(tmp);
47465
+ unlinkSync3(tmp);
47207
47466
  throw e;
47208
47467
  }
47209
47468
  }
@@ -47328,7 +47587,7 @@ async function login(args) {
47328
47587
  `${JSON.stringify({ hub, label, machine_token: poll.machine_token }, null, 2)}
47329
47588
  `
47330
47589
  );
47331
- rmSync6(join17(args.home, "revoked"), { force: true });
47590
+ rmSync6(join18(args.home, "revoked"), { force: true });
47332
47591
  if (!events?.code) print(`Approved this machine as ${label}.`);
47333
47592
  return {
47334
47593
  machineToken: poll.machine_token,
@@ -47352,7 +47611,7 @@ init_src();
47352
47611
 
47353
47612
  // src/commands/install.ts
47354
47613
  init_src3();
47355
- import { join as join19 } from "node:path";
47614
+ import { join as join20 } from "node:path";
47356
47615
  init_src2();
47357
47616
 
47358
47617
  // src/live.ts
@@ -47405,16 +47664,16 @@ function spinner(ctx) {
47405
47664
  import {
47406
47665
  existsSync as existsSync6,
47407
47666
  lstatSync as lstatSync10,
47408
- mkdirSync as mkdirSync10,
47667
+ mkdirSync as mkdirSync11,
47409
47668
  readdirSync as readdirSync4,
47410
47669
  readFileSync as readFileSync16,
47411
47670
  realpathSync as realpathSync8,
47412
- renameSync as renameSync10,
47671
+ renameSync as renameSync11,
47413
47672
  rmdirSync,
47414
47673
  rmSync as rmSync7,
47415
47674
  writeFileSync as writeFileSync8
47416
47675
  } from "node:fs";
47417
- import { dirname as dirname9, join as join18 } from "node:path";
47676
+ import { dirname as dirname10, join as join19 } from "node:path";
47418
47677
  var SKILL_MARKER = "<!-- managed by the Open Artifacts bus installer: edits are replaced on reinstall. -->";
47419
47678
  var CODEX_BEGIN = "<!-- BEGIN Open Artifacts skill (managed): edits inside are replaced on reinstall. -->";
47420
47679
  var CODEX_END = "<!-- END Open Artifacts skill -->";
@@ -47422,14 +47681,14 @@ var MAX_SKILL_BYTES = 256 * 1024;
47422
47681
  var env = (deps) => deps.env ?? {};
47423
47682
  var skillDir = (deps, h) => {
47424
47683
  const e = env(deps);
47425
- const opencode = e.OPENCODE_CONFIG_DIR ?? join18(e.XDG_CONFIG_HOME ?? join18(deps.home, ".config"), "opencode");
47426
- const agents = join18(deps.home, ".agents", "skills");
47684
+ const opencode = e.OPENCODE_CONFIG_DIR ?? join19(e.XDG_CONFIG_HOME ?? join19(deps.home, ".config"), "opencode");
47685
+ const agents = join19(deps.home, ".agents", "skills");
47427
47686
  return {
47428
- claude: join18(e.CLAUDE_CONFIG_DIR ?? join18(deps.home, ".claude"), "skills"),
47429
- opencode: join18(opencode, "skills"),
47687
+ claude: join19(e.CLAUDE_CONFIG_DIR ?? join19(deps.home, ".claude"), "skills"),
47688
+ opencode: join19(opencode, "skills"),
47430
47689
  pi: agents,
47431
47690
  omp: agents,
47432
- codex: join18(codexHome2(deps.home, e), "AGENTS.md")
47691
+ codex: join19(codexHome2(deps.home, e), "AGENTS.md")
47433
47692
  }[h];
47434
47693
  };
47435
47694
  var skillFolder = (text3) => {
@@ -47525,11 +47784,11 @@ var targetOf = (path) => {
47525
47784
  };
47526
47785
  var seq = 0;
47527
47786
  var writeAtomic2 = (path, text3) => {
47528
- mkdirSync10(dirname9(path), { recursive: true });
47787
+ mkdirSync11(dirname10(path), { recursive: true });
47529
47788
  const tmp = `${path}.oa-${process.pid}-${seq++}.tmp`;
47530
47789
  try {
47531
47790
  writeFileSync8(tmp, text3);
47532
- renameSync10(tmp, path);
47791
+ renameSync11(tmp, path);
47533
47792
  } catch (e) {
47534
47793
  try {
47535
47794
  rmSync7(tmp, { force: true });
@@ -47584,7 +47843,7 @@ async function installSkill(deps, origin, harnesses) {
47584
47843
  failedUrl: url2
47585
47844
  };
47586
47845
  const base3 = skillDir(deps, h);
47587
- const path = harnessSkills[h].agentsMd ? base3 : join18(base3, folder, "SKILL.md");
47846
+ const path = harnessSkills[h].agentsMd ? base3 : join19(base3, folder, "SKILL.md");
47588
47847
  if (brokenLink(path)) {
47589
47848
  notes.push(`Left ${path} alone: it is a broken symlink.`);
47590
47849
  continue;
@@ -47662,8 +47921,8 @@ var uninstallSkill = (deps, harnesses = ["claude", "opencode", "pi", "omp", "cod
47662
47921
  continue;
47663
47922
  }
47664
47923
  for (const entry of entries) {
47665
- const dir = join18(base3, entry);
47666
- const file2 = join18(dir, "SKILL.md");
47924
+ const dir = join19(base3, entry);
47925
+ const file2 = join19(dir, "SKILL.md");
47667
47926
  try {
47668
47927
  const st = lstatSync10(dir);
47669
47928
  if (st.isSymbolicLink()) {
@@ -47772,7 +48031,7 @@ async function loginStep(ctx, opts) {
47772
48031
  ctx,
47773
48032
  c.approved(result.label),
47774
48033
  c.tokenSaved(
47775
- tilde(ctx, join19(ctx.home, "machine.json")),
48034
+ tilde(ctx, join20(ctx.home, "machine.json")),
47776
48035
  result.machineToken
47777
48036
  ),
47778
48037
  c.connected(originOf2(result.hub)),
@@ -47861,7 +48120,7 @@ function shownSocket(ctx) {
47861
48120
  const real2 = `${canonicalHome(ctx.home)}/`;
47862
48121
  return tilde(
47863
48122
  ctx,
47864
- path.startsWith(real2) ? join19(ctx.home, path.slice(real2.length)) : path
48123
+ path.startsWith(real2) ? join20(ctx.home, path.slice(real2.length)) : path
47865
48124
  );
47866
48125
  }
47867
48126
  async function waitForDaemon(ctx) {
@@ -47912,12 +48171,12 @@ function rosterBlock(ctx, ns) {
47912
48171
  (a, b) => Number(a.state === "queued") - Number(b.state === "queued") || a.name.localeCompare(b.name)
47913
48172
  );
47914
48173
  const queued2 = rows.filter((r) => r.state === "queued").length;
47915
- const shown2 = rows.slice(0, ROSTER_ROWS);
48174
+ const shown3 = rows.slice(0, ROSTER_ROWS);
47916
48175
  const now = ctx.now();
47917
48176
  return {
47918
48177
  lines: [
47919
48178
  c.rosterHeader(ns.namespace, rows.length - queued2, queued2),
47920
- ...shown2.flatMap((r) => {
48179
+ ...shown3.flatMap((r) => {
47921
48180
  const says = c.rosterSays(r, now);
47922
48181
  return [c.rosterRow(r), ...says ? [says] : []];
47923
48182
  }),
@@ -47997,7 +48256,7 @@ async function install2(opts, ctx) {
47997
48256
  return results.every((r) => r.state === "done") ? 0 : 1;
47998
48257
  }
47999
48258
  const ok = await runSteps(steps, ctx, {
48000
- path: join19(ctx.home, "install.json"),
48259
+ path: join20(ctx.home, "install.json"),
48001
48260
  now: ctx.now
48002
48261
  });
48003
48262
  const skillFailed = reportSkillFailure(ctx);
@@ -48213,7 +48472,7 @@ async function doctor(ctx) {
48213
48472
  const node2 = ctx.nodeVersion.replace(/^v/, "");
48214
48473
  if (Number(node2.split(".")[0]) >= MIN_NODE) pass(c.nodeOk(node2));
48215
48474
  else fail(c.nodeOld(node2));
48216
- const machineFile = tilde(ctx, join20(ctx.home, "machine.json"));
48475
+ const machineFile = tilde(ctx, join21(ctx.home, "machine.json"));
48217
48476
  const m = readMachine(ctx.home);
48218
48477
  if (m.state !== "ok") fail(c.noCredentials(machineFile));
48219
48478
  else if (m.revoked) fail(c.revokedCheck());
@@ -48283,8 +48542,8 @@ async function doctor(ctx) {
48283
48542
  if (wiring[h] === "configured") pass(c.wired(h, version2));
48284
48543
  else fail(c.notWired(h));
48285
48544
  if (h === "claude") {
48286
- const settings = join20(
48287
- ctx.env.CLAUDE_CONFIG_DIR ?? join20(ctx.userHome, ".claude"),
48545
+ const settings = join21(
48546
+ ctx.env.CLAUDE_CONFIG_DIR ?? join21(ctx.userHome, ".claude"),
48288
48547
  "settings.json"
48289
48548
  );
48290
48549
  const isolates = claudeIsolates(settings);
@@ -48296,9 +48555,10 @@ async function doctor(ctx) {
48296
48555
  const allow = globalFile(ctx.home);
48297
48556
  const list = readGlobalDirs(allow);
48298
48557
  if (list.error) warn(c.globalUnusable(tilde(ctx, allow), list.error));
48299
- const files = scanConfigFiles(ctx.cwd, { globalFile: allow }).filter(
48300
- (f) => f.file !== allow
48301
- );
48558
+ const files = scanConfigFiles(ctx.cwd, {
48559
+ globalFile: allow,
48560
+ namespacesFile: namespacesFile(ctx.home)
48561
+ }).filter((f) => f.file !== allow);
48302
48562
  if (files.length > 0) {
48303
48563
  n.warnings += files.length;
48304
48564
  say(ctx, configFileLines(ctx, files));
@@ -48369,10 +48629,10 @@ async function global(opts, ctx) {
48369
48629
 
48370
48630
  // src/commands/logs.ts
48371
48631
  import { readFileSync as readFileSync18 } from "node:fs";
48372
- import { join as join21 } from "node:path";
48632
+ import { join as join22 } from "node:path";
48373
48633
  var TAIL = 50;
48374
48634
  async function logs(ctx) {
48375
- const path = join21(ctx.home, "logs", "daemon.log");
48635
+ const path = join22(ctx.home, "logs", "daemon.log");
48376
48636
  let text3;
48377
48637
  try {
48378
48638
  text3 = readFileSync18(path, "utf8");
@@ -48400,13 +48660,125 @@ async function mcp(harness, ctx, load = (h) => MCP_SERVER[h]()) {
48400
48660
  return void 0;
48401
48661
  }
48402
48662
 
48663
+ // src/commands/namespace.ts
48664
+ import { realpathSync as realpathSync10, statSync as statSync11 } from "node:fs";
48665
+ import { join as join23, resolve as resolve7 } from "node:path";
48666
+ init_src();
48667
+ function shown2(ctx, path) {
48668
+ const t = tilde(ctx, path);
48669
+ if (t !== path) return t;
48670
+ try {
48671
+ return tilde({ userHome: realpathSync10(ctx.userHome) }, path);
48672
+ } catch {
48673
+ return path;
48674
+ }
48675
+ }
48676
+ async function namespace(opts, ctx) {
48677
+ const c = ctx.copy;
48678
+ say(ctx, c.header(ctx.version), "");
48679
+ const file2 = namespacesFile(ctx.home);
48680
+ const { entries, error: error62 } = readApprovals(file2);
48681
+ if (error62) {
48682
+ sayErr(ctx, c.nsUnusable(tilde(ctx, file2), error62));
48683
+ return 1;
48684
+ }
48685
+ if (opts.sub === "list") {
48686
+ say(
48687
+ ctx,
48688
+ entries.length ? c.nsList(entries.map((e) => ({ ...e, dir: shown2(ctx, e.dir) }))) : c.nsNone()
48689
+ );
48690
+ return 0;
48691
+ }
48692
+ const given = resolve7(ctx.cwd, opts.dir);
48693
+ let real2;
48694
+ try {
48695
+ real2 = canonicalPath(given);
48696
+ } catch {
48697
+ }
48698
+ if (opts.sub === "revoke") {
48699
+ const keep = entries.filter(
48700
+ (e) => e.dir !== given && e.dir !== real2 && !(real2 && sameDir(e.dir, real2))
48701
+ );
48702
+ if (keep.length === entries.length) {
48703
+ say(ctx, c.nsNotListed(shown2(ctx, real2 ?? given)));
48704
+ return 0;
48705
+ }
48706
+ writeApprovals(keep, ctx.home);
48707
+ for (const e of entries.filter((x) => !keep.includes(x)))
48708
+ logApproval(
48709
+ { action: "revoke", ...e, tty: Boolean(ctx.stdinIsTTY) },
48710
+ ctx.home
48711
+ );
48712
+ say(ctx, c.nsRevoked(shown2(ctx, real2 ?? given)));
48713
+ return 0;
48714
+ }
48715
+ if (!real2 || !statSync11(real2).isDirectory()) {
48716
+ sayErr(ctx, c.nsNotDir(shown2(ctx, real2 ?? given)));
48717
+ return 1;
48718
+ }
48719
+ const cfgFile = join23(real2, CONFIG_FILE);
48720
+ const own2 = readOwnFile(cfgFile, process.getuid?.(), {
48721
+ allowGroupWrite: true
48722
+ });
48723
+ if (own2.state === "none") {
48724
+ sayErr(ctx, c.nsNoFile(shown2(ctx, real2)));
48725
+ return 1;
48726
+ }
48727
+ if (own2.state === "unsafe") {
48728
+ sayErr(ctx, c.nsFileUnusable(shown2(ctx, cfgFile), own2.why));
48729
+ return 1;
48730
+ }
48731
+ let ns;
48732
+ try {
48733
+ const parsed = BusConfigSchema.safeParse(JSON.parse(own2.text));
48734
+ if (parsed.success) ns = parsed.data.namespace;
48735
+ } catch {
48736
+ }
48737
+ if (!ns) {
48738
+ say(ctx, c.nsNoNamespace(shown2(ctx, cfgFile)));
48739
+ return 1;
48740
+ }
48741
+ if (isApproved(real2, ns, entries)) {
48742
+ say(ctx, c.nsAlready(shown2(ctx, real2), plain2(ns)));
48743
+ return 0;
48744
+ }
48745
+ if (!opts.yes) {
48746
+ if (!ctx.stdinIsTTY || !ctx.readLine) {
48747
+ sayErr(ctx, c.nsNeedTty(approveCommand(real2)));
48748
+ return 1;
48749
+ }
48750
+ say(ctx, c.nsAsk(shown2(ctx, real2), plain2(ns)));
48751
+ const answer = (await ctx.readLine(c.nsPrompt())).trim().toLowerCase();
48752
+ if (answer !== "y" && answer !== "yes") {
48753
+ say(ctx, c.nsDeclined());
48754
+ return 1;
48755
+ }
48756
+ }
48757
+ const next = [
48758
+ ...entries.filter((e) => !sameDir(e.dir, real2)),
48759
+ { dir: real2, namespace: ns }
48760
+ ];
48761
+ writeApprovals(next, ctx.home);
48762
+ logApproval(
48763
+ {
48764
+ action: "approve",
48765
+ dir: real2,
48766
+ namespace: ns,
48767
+ tty: Boolean(ctx.stdinIsTTY)
48768
+ },
48769
+ ctx.home
48770
+ );
48771
+ say(ctx, c.nsApproved(shown2(ctx, real2), plain2(ns)));
48772
+ return 0;
48773
+ }
48774
+
48403
48775
  // src/commands/uninstall.ts
48404
- import { join as join23 } from "node:path";
48776
+ import { join as join25 } from "node:path";
48405
48777
 
48406
48778
  // src/steps/purge.ts
48407
48779
  init_src3();
48408
48780
  import { lstatSync as lstatSync11, readdirSync as readdirSync5, rmdirSync as rmdirSync2, rmSync as rmSync8 } from "node:fs";
48409
- import { join as join22 } from "node:path";
48781
+ import { join as join24 } from "node:path";
48410
48782
  var FILES = [
48411
48783
  "machine.json",
48412
48784
  "install.json",
@@ -48455,14 +48827,14 @@ var rmdirIfEmpty = (path) => {
48455
48827
  };
48456
48828
  function purgeShort(dir, removed) {
48457
48829
  if (kind(dir) !== "dir" || unsafeSocketDir(dir)) return;
48458
- const ret = join22(dir, "claude-return");
48830
+ const ret = join24(dir, "claude-return");
48459
48831
  for (const [d, ours2] of [
48460
48832
  [ret, (_n, p) => kind(p) === "socket"],
48461
48833
  [dir, (n) => /^daemon\.sock(\.keep-\d+)?$/.test(n)]
48462
48834
  ]) {
48463
48835
  if (kind(d) !== "dir") continue;
48464
48836
  for (const name of readdirSync5(d)) {
48465
- const path = join22(d, name);
48837
+ const path = join24(d, name);
48466
48838
  const k = kind(path);
48467
48839
  if (k === void 0 || k === "dir" || !ours2(name, path)) continue;
48468
48840
  remove2(path, k);
@@ -48487,21 +48859,21 @@ function purge(home2, opts) {
48487
48859
  ...FILES,
48488
48860
  ...entries.filter((n) => TEMP.some((re) => re.test(n)))
48489
48861
  ]) {
48490
- const path = join22(home2, name);
48862
+ const path = join24(home2, name);
48491
48863
  const k = kind(path);
48492
48864
  if (k === void 0 || k === "dir") continue;
48493
48865
  remove2(path, k);
48494
48866
  removed.push(name);
48495
48867
  }
48496
48868
  for (const folder of FOLDERS) {
48497
- const dir = join22(home2, folder.path);
48869
+ const dir = join24(home2, folder.path);
48498
48870
  if (kind(dir) !== "dir") continue;
48499
48871
  for (const name of readdirSync5(dir)) {
48500
- const path = join22(dir, name);
48872
+ const path = join24(dir, name);
48501
48873
  const k = kind(path);
48502
48874
  if (k === void 0 || !folder.ours(name, path)) continue;
48503
48875
  remove2(path, k);
48504
- removed.push(join22(folder.path, name));
48876
+ removed.push(join24(folder.path, name));
48505
48877
  }
48506
48878
  if (rmdirIfEmpty(dir)) removed.push(folder.path);
48507
48879
  }
@@ -48553,7 +48925,7 @@ async function uninstall2(opts, ctx) {
48553
48925
  r.opencodeRestarted ? c.restartedUnload() : c.opencodeNotRunningUnload()
48554
48926
  );
48555
48927
  if (!opts.purge) {
48556
- say(ctx, "", c.kept(tilde(ctx, join23(ctx.home, "machine.json"))));
48928
+ say(ctx, "", c.kept(tilde(ctx, join25(ctx.home, "machine.json"))));
48557
48929
  return 0;
48558
48930
  }
48559
48931
  const home2 = tilde(ctx, ctx.home);
@@ -48564,7 +48936,7 @@ async function uninstall2(opts, ctx) {
48564
48936
  } catch {
48565
48937
  }
48566
48938
  const out = purge(ctx.home, {
48567
- isDefault: ctx.home === join23(ctx.userHome, ".oa-bus")
48939
+ isDefault: ctx.home === join25(ctx.userHome, ".oa-bus")
48568
48940
  });
48569
48941
  if ("refused" in out) {
48570
48942
  sayErr(ctx, c.purgeRefused(home2));
@@ -48589,16 +48961,19 @@ var COMMANDS = /* @__PURE__ */ new Set([
48589
48961
  "doctor",
48590
48962
  "uninstall",
48591
48963
  "global",
48964
+ "namespace",
48592
48965
  "version"
48593
48966
  ]);
48594
48967
  var HARNESSES2 = ["claude", "opencode", "codex", "pi"];
48595
48968
  var GLOBAL_USAGE = `usage: ${BUS_CMD} global <add|rm> <dir>, or global list`;
48969
+ var NAMESPACE_USAGE = `usage: ${BUS_CMD} namespace approve [dir], namespace revoke <dir>, or namespace list`;
48596
48970
  var COMMON = /* @__PURE__ */ new Set(["no-color", "version", "home"]);
48597
48971
  var FLAGS = {
48598
48972
  install: ["instance", "no-open", "yes", "check", "no-service"],
48599
48973
  login: ["instance", "no-open"],
48600
48974
  daemon: ["instance"],
48601
- uninstall: ["purge"]
48975
+ uninstall: ["purge"],
48976
+ namespace: ["yes"]
48602
48977
  };
48603
48978
  function parse7(argv) {
48604
48979
  const { values, positionals, tokens: tokens2 } = parseArgs({
@@ -48624,7 +48999,16 @@ function parse7(argv) {
48624
48999
  if (cmd === "mcp" && rest.length === 0)
48625
49000
  throw new Error(`usage: ${BUS_CMD} mcp <claude|opencode|codex|pi>`);
48626
49001
  if (cmd === "global" && rest.length < takes) throw new Error(GLOBAL_USAGE);
48627
- const extra = rest[takes];
49002
+ if (cmd === "namespace") {
49003
+ const sub = rest[0];
49004
+ const max = sub === "list" ? 1 : sub === "approve" ? 2 : 2;
49005
+ const min = sub === "revoke" ? 2 : 1;
49006
+ if (!["approve", "revoke", "list"].includes(sub ?? "") || rest.length < min)
49007
+ throw new Error(NAMESPACE_USAGE);
49008
+ if (rest[max] !== void 0)
49009
+ throw new Error(`unexpected argument: ${rest[max]}`);
49010
+ }
49011
+ const extra = cmd === "namespace" ? void 0 : rest[takes];
48628
49012
  if (extra !== void 0) throw new Error(`unexpected argument: ${extra}`);
48629
49013
  for (const name of ["home", "instance"])
48630
49014
  if (values[name] === "") throw new Error(`--${name} needs a value`);
@@ -48660,6 +49044,14 @@ function route(cmd, values, positionals) {
48660
49044
  if ((sub === "add" || sub === "rm") && dir) return { cmd, sub, dir };
48661
49045
  throw new Error(GLOBAL_USAGE);
48662
49046
  }
49047
+ case "namespace": {
49048
+ const [sub, dir] = positionals;
49049
+ if (sub === "list") return { cmd, sub };
49050
+ if (sub === "revoke" && dir) return { cmd, sub, dir };
49051
+ if (sub === "approve")
49052
+ return { cmd, sub, dir: dir ?? ".", yes: values.yes };
49053
+ throw new Error(NAMESPACE_USAGE);
49054
+ }
48663
49055
  case "install":
48664
49056
  return {
48665
49057
  cmd,
@@ -48690,7 +49082,7 @@ async function main(argv, makeCtx = realCtx) {
48690
49082
  return 2;
48691
49083
  }
48692
49084
  const ctx = makeCtx(cmd.noColor);
48693
- if (cmd.home) ctx.home = resolve7(cmd.home);
49085
+ if (cmd.home) ctx.home = resolve8(cmd.home);
48694
49086
  try {
48695
49087
  return await dispatch(cmd, ctx);
48696
49088
  } catch (e) {
@@ -48742,6 +49134,8 @@ async function dispatch(cmd, ctx) {
48742
49134
  return uninstall2({ purge: cmd.purge }, ctx);
48743
49135
  case "global":
48744
49136
  return global(cmd, ctx);
49137
+ case "namespace":
49138
+ return namespace(cmd, ctx);
48745
49139
  case "version":
48746
49140
  say(ctx, ctx.copy.header(ctx.version));
48747
49141
  return 0;