@open-artifacts/bus 0.126.0 → 0.128.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"));
@@ -26316,20 +26316,20 @@ var require_compile = __commonJS({
26316
26316
  var util_1 = require_util();
26317
26317
  var validate_1 = require_validate();
26318
26318
  var SchemaEnv = class {
26319
- constructor(env) {
26319
+ constructor(env2) {
26320
26320
  var _a3;
26321
26321
  this.refs = {};
26322
26322
  this.dynamicAnchors = {};
26323
26323
  let schema;
26324
- if (typeof env.schema == "object")
26325
- schema = env.schema;
26326
- this.schema = env.schema;
26327
- this.schemaId = env.schemaId;
26328
- this.root = env.root || this;
26329
- this.baseId = (_a3 = env.baseId) !== null && _a3 !== void 0 ? _a3 : (0, resolve_1.normalizeId)(schema === null || schema === void 0 ? void 0 : schema[env.schemaId || "$id"]);
26330
- this.schemaPath = env.schemaPath;
26331
- this.localRefs = env.localRefs;
26332
- this.meta = env.meta;
26324
+ if (typeof env2.schema == "object")
26325
+ schema = env2.schema;
26326
+ this.schema = env2.schema;
26327
+ this.schemaId = env2.schemaId;
26328
+ this.root = env2.root || this;
26329
+ this.baseId = (_a3 = env2.baseId) !== null && _a3 !== void 0 ? _a3 : (0, resolve_1.normalizeId)(schema === null || schema === void 0 ? void 0 : schema[env2.schemaId || "$id"]);
26330
+ this.schemaPath = env2.schemaPath;
26331
+ this.localRefs = env2.localRefs;
26332
+ this.meta = env2.meta;
26333
26333
  this.$async = schema === null || schema === void 0 ? void 0 : schema.$async;
26334
26334
  this.refs = {};
26335
26335
  }
@@ -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;
@@ -26513,15 +26513,15 @@ var require_compile = __commonJS({
26513
26513
  baseId = (0, resolve_1.resolveUrl)(this.opts.uriResolver, baseId, schId);
26514
26514
  }
26515
26515
  }
26516
- let env;
26516
+ let env2;
26517
26517
  if (typeof schema != "boolean" && schema.$ref && !(0, util_1.schemaHasRulesButRef)(schema, this.RULES)) {
26518
26518
  const $ref = (0, resolve_1.resolveUrl)(this.opts.uriResolver, baseId, schema.$ref);
26519
- env = resolveSchema.call(this, root, $ref);
26519
+ env2 = resolveSchema.call(this, root, $ref);
26520
26520
  }
26521
26521
  const { schemaId } = this.opts;
26522
- env = env || new SchemaEnv({ schema, schemaId, root, baseId });
26523
- if (env.schema !== env.root.schema)
26524
- return env;
26522
+ env2 = env2 || new SchemaEnv({ schema, schemaId, root, baseId });
26523
+ if (env2.schema !== env2.root.schema)
26524
+ return env2;
26525
26525
  return void 0;
26526
26526
  }
26527
26527
  }
@@ -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,
@@ -28319,8 +28319,8 @@ var require_ref = __commonJS({
28319
28319
  schemaType: "string",
28320
28320
  code(cxt) {
28321
28321
  const { gen, schema: $ref, it } = cxt;
28322
- const { baseId, schemaEnv: env, validateName, opts, self } = it;
28323
- const { root } = env;
28322
+ const { baseId, schemaEnv: env2, validateName, opts, self } = it;
28323
+ const { root } = env2;
28324
28324
  if (($ref === "#" || $ref === "#/") && baseId === root.baseId)
28325
28325
  return callRootRef();
28326
28326
  const schOrEnv = compile_1.resolveRef.call(self, root, baseId, $ref);
@@ -28330,8 +28330,8 @@ var require_ref = __commonJS({
28330
28330
  return callValidate(schOrEnv);
28331
28331
  return inlineRefSchema(schOrEnv);
28332
28332
  function callRootRef() {
28333
- if (env === root)
28334
- return callRef(cxt, validateName, env, env.$async);
28333
+ if (env2 === root)
28334
+ return callRef(cxt, validateName, env2, env2.$async);
28335
28335
  const rootName = gen.scopeValue("root", { ref: root });
28336
28336
  return callRef(cxt, (0, codegen_1._)`${rootName}.validate`, root, root.$async);
28337
28337
  }
@@ -28361,14 +28361,14 @@ var require_ref = __commonJS({
28361
28361
  exports.getValidate = getValidate;
28362
28362
  function callRef(cxt, v, sch, $async) {
28363
28363
  const { gen, it } = cxt;
28364
- const { allErrors, schemaEnv: env, opts } = it;
28364
+ const { allErrors, schemaEnv: env2, opts } = it;
28365
28365
  const passCxt = opts.passContext ? names_1.default.this : codegen_1.nil;
28366
28366
  if ($async)
28367
28367
  callAsyncRef();
28368
28368
  else
28369
28369
  callSyncRef();
28370
28370
  function callAsyncRef() {
28371
- if (!env.$async)
28371
+ if (!env2.$async)
28372
28372
  throw new Error("async schema referenced by sync schema");
28373
28373
  const valid2 = gen.let("valid");
28374
28374
  gen.try(() => {
@@ -32409,11 +32409,20 @@ var init_frames = __esm({
32409
32409
  late = { late: external_exports.array(external_exports.string().min(1)).optional() };
32410
32410
  isWellFormed2 = (s) => s.isWellFormed();
32411
32411
  WELL_FORMED = { message: "text is not well-formed unicode" };
32412
- CLIENT_VERSION = true ? "0.126.0" : "0.0.0";
32412
+ CLIENT_VERSION = true ? "0.128.0" : "0.0.0";
32413
32413
  clientVersion = {
32414
32414
  client_version: external_exports.string().min(1).max(64).optional()
32415
32415
  };
32416
- ADAPTER_CAPS = { mailbox: "mailbox" };
32416
+ ADAPTER_CAPS = {
32417
+ mailbox: "mailbox",
32418
+ /**
32419
+ * `pending` (#1525): a `config_files` entry with `state: "pending"`, a
32420
+ * namespace waiting for the user's approval. An older strict decoder would
32421
+ * reject the whole frame on it, so the daemon sends it only to a client that
32422
+ * listed this.
32423
+ */
32424
+ pending: "pending"
32425
+ };
32417
32426
  Hello2 = external_exports.object({
32418
32427
  ...base2,
32419
32428
  ...clientVersion,
@@ -32514,7 +32523,9 @@ var init_frames = __esm({
32514
32523
  ...base2,
32515
32524
  ...clientVersion,
32516
32525
  type: external_exports.literal("status"),
32517
- cwd: external_exports.string().min(1).max(4096).optional()
32526
+ cwd: external_exports.string().min(1).max(4096).optional(),
32527
+ /** What this client can decode (ADAPTER_CAPS); absent means none. */
32528
+ caps: external_exports.array(external_exports.string().max(32)).max(16).optional()
32518
32529
  });
32519
32530
  AdapterFrame = external_exports.discriminatedUnion("type", [
32520
32531
  Hello2,
@@ -32527,7 +32538,8 @@ var init_frames = __esm({
32527
32538
  ]);
32528
32539
  ConfigFile = external_exports.object({
32529
32540
  file: external_exports.string(),
32530
- state: external_exports.enum(["refused", "noted"]),
32541
+ /** `pending` (#1525) goes only to clients that listed ADAPTER_CAPS.pending. */
32542
+ state: external_exports.enum(["refused", "noted", "pending"]),
32531
32543
  reason: external_exports.string(),
32532
32544
  fix: external_exports.string()
32533
32545
  });
@@ -32731,13 +32743,13 @@ var init_lines = __esm({
32731
32743
  import { connect } from "node:net";
32732
32744
  async function connectDaemon(opts) {
32733
32745
  const sock = connect(opts.path);
32734
- await new Promise((resolve8, reject) => {
32735
- sock.once("connect", resolve8);
32746
+ await new Promise((resolve9, reject) => {
32747
+ sock.once("connect", resolve9);
32736
32748
  sock.once("error", reject);
32737
32749
  });
32738
32750
  const decoder = new LineDecoder();
32739
32751
  let state = "open";
32740
- let seq = 0;
32752
+ let seq2 = 0;
32741
32753
  const pending = /* @__PURE__ */ new Map();
32742
32754
  const waiters = [];
32743
32755
  let deliver;
@@ -32792,8 +32804,8 @@ async function connectDaemon(opts) {
32792
32804
  sock.on("error", (e) => failAll(e));
32793
32805
  sock.on("close", () => failAll(new Error("daemon connection closed")));
32794
32806
  let timer;
32795
- const welcomeRaw = await new Promise((resolve8, reject) => {
32796
- waiters.push({ resolve: resolve8, reject });
32807
+ const welcomeRaw = await new Promise((resolve9, reject) => {
32808
+ waiters.push({ resolve: resolve9, reject });
32797
32809
  timer = setTimeout(() => {
32798
32810
  reject(new Error("daemon did not answer hello"));
32799
32811
  sock.destroy();
@@ -32814,8 +32826,8 @@ async function connectDaemon(opts) {
32814
32826
  request: (partial2) => {
32815
32827
  if (state === "closed")
32816
32828
  return Promise.reject(new Error("daemon connection closed"));
32817
- const id = partial2.id ?? String(++seq);
32818
- return new Promise((resolve8, reject) => {
32829
+ const id = partial2.id ?? String(++seq2);
32830
+ return new Promise((resolve9, reject) => {
32819
32831
  const ms = opts.requestTimeoutMs ?? 2e4;
32820
32832
  const timer2 = setTimeout(() => {
32821
32833
  if (pending.delete(id))
@@ -32830,7 +32842,7 @@ async function connectDaemon(opts) {
32830
32842
  clearTimeout(timer2);
32831
32843
  f(...a);
32832
32844
  };
32833
- pending.set(id, { resolve: done(resolve8), reject: done(reject) });
32845
+ pending.set(id, { resolve: done(resolve9), reject: done(reject) });
32834
32846
  sock.write(`${JSON.stringify({ v: 1, ...partial2, id })}
32835
32847
  `);
32836
32848
  });
@@ -32838,7 +32850,7 @@ async function connectDaemon(opts) {
32838
32850
  ack: (msg_id) => {
32839
32851
  if (state === "closed") return;
32840
32852
  sock.write(
32841
- `${JSON.stringify({ v: 1, type: "ack", id: `ack-${++seq}`, msg_id })}
32853
+ `${JSON.stringify({ v: 1, type: "ack", id: `ack-${++seq2}`, msg_id })}
32842
32854
  `
32843
32855
  );
32844
32856
  },
@@ -32854,7 +32866,7 @@ async function connectDaemon(opts) {
32854
32866
  };
32855
32867
  }
32856
32868
  function daemonStatus(opts) {
32857
- return new Promise((resolve8, reject) => {
32869
+ return new Promise((resolve9, reject) => {
32858
32870
  const sock = connect(opts.path);
32859
32871
  const decoder = new LineDecoder();
32860
32872
  const done = (f) => {
@@ -32883,7 +32895,7 @@ function daemonStatus(opts) {
32883
32895
  sock.once(
32884
32896
  "connect",
32885
32897
  () => sock.write(
32886
- `${JSON.stringify({ v: 1, id: "status", type: "status", client_version: CLIENT_VERSION, ...opts.cwd ? { cwd: opts.cwd } : {} })}
32898
+ `${JSON.stringify({ v: 1, id: "status", type: "status", client_version: CLIENT_VERSION, caps: [ADAPTER_CAPS.pending], ...opts.cwd ? { cwd: opts.cwd } : {} })}
32887
32899
  `
32888
32900
  )
32889
32901
  );
@@ -32891,7 +32903,7 @@ function daemonStatus(opts) {
32891
32903
  try {
32892
32904
  for (const raw of decoder.push(chunk)) {
32893
32905
  const f = DaemonFrame.parse(raw);
32894
- if (f.type === "status") return done(() => resolve8(f));
32906
+ if (f.type === "status") return done(() => resolve9(f));
32895
32907
  if (f.type === "error")
32896
32908
  return done(
32897
32909
  () => reject(
@@ -33014,11 +33026,11 @@ function lateDeliveredText(to, excerpt) {
33014
33026
  if (!excerpt) return fitLine((v) => `${head(v)} ${tail}`, to);
33015
33027
  return fitLine((v) => quoted(head(v), `"${excerpt}"`, tail), to);
33016
33028
  }
33017
- function cutOff(seq) {
33018
- const bel = seq.endsWith("\x07");
33019
- if (seq[0] === "\x1B" && seq.length > 1 && "P]X^_".includes(seq[1]))
33020
- return !bel && !seq.endsWith("\x1B\\");
33021
- return seq[0] === "\x9D" && !bel && !seq.endsWith("\x9C");
33029
+ function cutOff(seq2) {
33030
+ const bel = seq2.endsWith("\x07");
33031
+ if (seq2[0] === "\x1B" && seq2.length > 1 && "P]X^_".includes(seq2[1]))
33032
+ return !bel && !seq2.endsWith("\x1B\\");
33033
+ return seq2[0] === "\x9D" && !bel && !seq2.endsWith("\x9C");
33022
33034
  }
33023
33035
  function messageHeader(m) {
33024
33036
  const reply = m.global ? `Reply with the oa_bus send_message tool (to_namespace ${m.namespace}) if needed.` : "Reply with the oa_bus send_message tool if needed.";
@@ -33056,13 +33068,13 @@ function selfText(agent) {
33056
33068
  if (!agent) return JSON.stringify(agent, null, 2);
33057
33069
  const { status: _s, status_label: _l, status_at: _a3, ...rest } = agent;
33058
33070
  const label = typeof agent.status_label === "string" ? displayLabel(agent.status_label) : "";
33059
- const shown2 = {
33071
+ const shown3 = {
33060
33072
  ...rest,
33061
33073
  ...typeof agent.status === "string" ? { status: displayKind(agent.status) } : {},
33062
33074
  ...label ? { status_label: label } : {},
33063
33075
  ...typeof agent.status_at === "string" && !Number.isNaN(Date.parse(agent.status_at)) ? { status_at: agent.status_at } : {}
33064
33076
  };
33065
- return JSON.stringify(shown2, null, 2);
33077
+ return JSON.stringify(shown3, null, 2);
33066
33078
  }
33067
33079
  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
33080
  var init_copy = __esm({
@@ -33140,7 +33152,7 @@ ${own2}` : `${head},
33140
33152
  "g"
33141
33153
  );
33142
33154
  CUT_OFF = " [control sequence removed]";
33143
- stripTerminalControls = (text3) => text3.replace(TERMINAL_CONTROLS, (seq) => cutOff(seq) ? CUT_OFF : "");
33155
+ stripTerminalControls = (text3) => text3.replace(TERMINAL_CONTROLS, (seq2) => cutOff(seq2) ? CUT_OFF : "");
33144
33156
  KIND_CHARS = 32;
33145
33157
  displayKind = (kind2) => [
33146
33158
  ...stripTerminalControls(kind2).replace(INVISIBLES, "").replace(/\s+/g, " ").trim()
@@ -33207,13 +33219,13 @@ async function clearStale(path) {
33207
33219
  code: "ENOTSOCK"
33208
33220
  });
33209
33221
  }
33210
- const live = await new Promise((resolve8) => {
33222
+ const live = await new Promise((resolve9) => {
33211
33223
  const probe = connect2(path);
33212
33224
  probe.once("connect", () => {
33213
33225
  probe.destroy();
33214
- resolve8(true);
33226
+ resolve9(true);
33215
33227
  });
33216
- probe.once("error", () => resolve8(false));
33228
+ probe.once("error", () => resolve9(false));
33217
33229
  });
33218
33230
  if (live) {
33219
33231
  throw Object.assign(new Error(`daemon already listening on ${path}`), {
@@ -33233,16 +33245,16 @@ async function serveDaemon(opts) {
33233
33245
  sock.once("close", () => sockets.delete(sock));
33234
33246
  handle(sock, opts);
33235
33247
  });
33236
- await new Promise((resolve8, reject) => {
33248
+ await new Promise((resolve9, reject) => {
33237
33249
  server4.once("error", reject);
33238
- server4.listen(opts.path, () => resolve8());
33250
+ server4.listen(opts.path, () => resolve9());
33239
33251
  });
33240
33252
  chmodSync(opts.path, 384);
33241
33253
  const st = statSync(opts.path);
33242
33254
  const mode = st.mode & 511;
33243
33255
  return {
33244
33256
  mode,
33245
- close: () => new Promise((resolve8) => {
33257
+ close: () => new Promise((resolve9) => {
33246
33258
  for (const s of sockets) s.destroy();
33247
33259
  let parked;
33248
33260
  try {
@@ -33260,7 +33272,7 @@ async function serveDaemon(opts) {
33260
33272
  } catch {
33261
33273
  }
33262
33274
  }
33263
- resolve8();
33275
+ resolve9();
33264
33276
  });
33265
33277
  })
33266
33278
  };
@@ -33537,17 +33549,17 @@ async function run(name, args, request) {
33537
33549
  const to = String(args.to ?? "");
33538
33550
  const body = String(args.text ?? "");
33539
33551
  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;
33552
+ const namespace2 = typeof args.to_namespace === "string" && args.to_namespace ? args.to_namespace : void 0;
33541
33553
  const r = await request({
33542
33554
  type: "send",
33543
33555
  to,
33544
33556
  body,
33545
- ...namespace ? { namespace } : {}
33557
+ ...namespace2 ? { namespace: namespace2 } : {}
33546
33558
  });
33547
33559
  if (r.type !== "receipt") return failed(r);
33548
33560
  if (r.text) return text(r.text, false);
33549
33561
  const n = r.reason === "ambiguous" ? await namespacesOf(to, request) : void 0;
33550
- const moved = r.reason === "revoked" ? await movedTo(to, namespace, request) : void 0;
33562
+ const moved = r.reason === "revoked" ? await movedTo(to, namespace2, request) : void 0;
33551
33563
  return text(
33552
33564
  receiptText(r, to, n, excerptOf(body), moved),
33553
33565
  r.state === "refused" || r.state === "expired"
@@ -33617,13 +33629,13 @@ async function namespacesOf(name, request) {
33617
33629
  return void 0;
33618
33630
  }
33619
33631
  }
33620
- async function movedTo(name, namespace, request) {
33632
+ async function movedTo(name, namespace2, request) {
33621
33633
  try {
33622
33634
  const r = await request({ type: "list" });
33623
33635
  if (r.type !== "roster") return void 0;
33624
33636
  return movedName(
33625
33637
  name,
33626
- r.agents.filter((a) => namespace === void 0 || a.namespace === namespace).map((a) => a.name)
33638
+ r.agents.filter((a) => namespace2 === void 0 || a.namespace === namespace2).map((a) => a.name)
33627
33639
  );
33628
33640
  } catch {
33629
33641
  return void 0;
@@ -33758,7 +33770,7 @@ function codexHello(call, pid, ppid) {
33758
33770
  pid,
33759
33771
  ...call.cwd ? { cwd: call.cwd } : {},
33760
33772
  proposed_name: "codex",
33761
- caps: [ADAPTER_CAPS.mailbox],
33773
+ caps: [ADAPTER_CAPS.mailbox, ADAPTER_CAPS.pending],
33762
33774
  codex: {
33763
33775
  thread_id: call.threadId,
33764
33776
  call_id: call.callId,
@@ -33857,7 +33869,7 @@ ${neutralize(a.text)}
33857
33869
  };
33858
33870
  }
33859
33871
  function inject(a) {
33860
- return new Promise((resolve8, reject) => {
33872
+ return new Promise((resolve9, reject) => {
33861
33873
  const sock = connect3(a.socketPath);
33862
33874
  let connected = false;
33863
33875
  const fail = (e) => {
@@ -33881,7 +33893,7 @@ function inject(a) {
33881
33893
  sock.once("finish", () => {
33882
33894
  clearTimeout(timer);
33883
33895
  sock.destroy();
33884
- resolve8();
33896
+ resolve9();
33885
33897
  });
33886
33898
  sock.end(`${JSON.stringify(frameOf(a))}
33887
33899
  `);
@@ -34001,7 +34013,7 @@ function sessionHello(session, pid, cwd) {
34001
34013
  pid,
34002
34014
  cwd,
34003
34015
  proposed_name: fitName(session.name, 64) || void 0,
34004
- caps: [ADAPTER_CAPS.mailbox],
34016
+ caps: [ADAPTER_CAPS.mailbox, ADAPTER_CAPS.pending],
34005
34017
  attest: {
34006
34018
  session_id: session.sessionId,
34007
34019
  socket_path: session.socketPath ?? void 0
@@ -34013,8 +34025,8 @@ var init_session = __esm({
34013
34025
  "../bus-adapter-claude-code/src/session.ts"() {
34014
34026
  "use strict";
34015
34027
  init_src2();
34016
- claudeSessionsDir = (env = process.env) => env.OA_BUS_CLAUDE_SESSIONS_DIR || join(env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "sessions");
34017
- busHome = (env = process.env) => resolve(env.OA_BUS_HOME || join(homedir(), ".oa-bus"));
34028
+ claudeSessionsDir = (env2 = process.env) => env2.OA_BUS_CLAUDE_SESSIONS_DIR || join(env2.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "sessions");
34029
+ busHome = (env2 = process.env) => resolve(env2.OA_BUS_HOME || join(homedir(), ".oa-bus"));
34018
34030
  notASession = (rec) => rec.parkedJobId !== void 0 || Boolean(rec.agentBus);
34019
34031
  sha256 = (s) => createHash("sha256").update(s).digest("hex");
34020
34032
  NOT_UNDER_CLAUDE = "This MCP server is for Claude Code; use this harness's own bus tools.";
@@ -36378,7 +36390,7 @@ var require_websocket = __commonJS({
36378
36390
  var http = __require("http");
36379
36391
  var net = __require("net");
36380
36392
  var tls = __require("tls");
36381
- var { randomBytes: randomBytes4, createHash: createHash6 } = __require("crypto");
36393
+ var { randomBytes: randomBytes5, createHash: createHash6 } = __require("crypto");
36382
36394
  var { Duplex, Readable } = __require("stream");
36383
36395
  var { URL: URL2 } = __require("url");
36384
36396
  var PerMessageDeflate2 = require_permessage_deflate();
@@ -36916,7 +36928,7 @@ var require_websocket = __commonJS({
36916
36928
  }
36917
36929
  }
36918
36930
  const defaultPort = isSecure ? 443 : 80;
36919
- const key2 = randomBytes4(16).toString("base64");
36931
+ const key2 = randomBytes5(16).toString("base64");
36920
36932
  const request = isSecure ? https.request : http.request;
36921
36933
  const protocolSet = /* @__PURE__ */ new Set();
36922
36934
  let perMessageDeflate;
@@ -37811,12 +37823,12 @@ var require_websocket_server = __commonJS({
37811
37823
 
37812
37824
  // ../bus-adapter-opencode/src/session.ts
37813
37825
  import { execFile as execFile4 } from "node:child_process";
37814
- import { isAbsolute as isAbsolute7 } from "node:path";
37826
+ import { isAbsolute as isAbsolute8 } from "node:path";
37815
37827
  import { promisify as promisify2 } from "node:util";
37816
37828
  function directoryOf(s) {
37817
37829
  const loc = s.location;
37818
37830
  const dir = s.directory ?? loc?.directory;
37819
- return typeof dir === "string" && isAbsolute7(dir) ? dir : null;
37831
+ return typeof dir === "string" && isAbsolute8(dir) ? dir : null;
37820
37832
  }
37821
37833
  async function rootSession(sessionId, deps) {
37822
37834
  const cache = deps.cache ?? ROOTS;
@@ -37894,7 +37906,7 @@ async function handleToolCall(input2) {
37894
37906
  pid: process.pid,
37895
37907
  cwd: session.directory,
37896
37908
  proposed_name: nameOf(session.title),
37897
- caps: [ADAPTER_CAPS.mailbox],
37909
+ caps: [ADAPTER_CAPS.mailbox, ADAPTER_CAPS.pending],
37898
37910
  attest: { session_id: sessionId }
37899
37911
  });
37900
37912
  let client;
@@ -38034,12 +38046,12 @@ var init_stdio2 = __esm({
38034
38046
  this.onclose?.();
38035
38047
  }
38036
38048
  send(message) {
38037
- return new Promise((resolve8) => {
38049
+ return new Promise((resolve9) => {
38038
38050
  const json3 = serializeMessage(message);
38039
38051
  if (this._stdout.write(json3)) {
38040
- resolve8();
38052
+ resolve9();
38041
38053
  } else {
38042
- this._stdout.once("drain", resolve8);
38054
+ this._stdout.once("drain", resolve9);
38043
38055
  }
38044
38056
  });
38045
38057
  }
@@ -38208,16 +38220,16 @@ var harnessSkills = {
38208
38220
  var harnessNames = Object.keys(harnessSkills);
38209
38221
 
38210
38222
  // src/main.ts
38211
- import { resolve as resolve7 } from "node:path";
38223
+ import { resolve as resolve8 } from "node:path";
38212
38224
 
38213
38225
  // src/commands/daemon.ts
38214
38226
  import { existsSync as existsSync4 } from "node:fs";
38215
- import { join as join15 } from "node:path";
38227
+ import { join as join16 } from "node:path";
38216
38228
 
38217
38229
  // ../bus-daemon/src/index.ts
38218
38230
  init_src3();
38219
38231
  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";
38232
+ import { basename as basename5, isAbsolute as isAbsolute6, join as join12 } from "node:path";
38221
38233
 
38222
38234
  // ../bus-adapter-opencode/src/version.ts
38223
38235
  var MIN_PROMPT_ID_VERSION = "2.0.0";
@@ -39202,8 +39214,8 @@ function defaultOpenSessions() {
39202
39214
 
39203
39215
  // ../bus-daemon/src/config-issues.ts
39204
39216
  init_src();
39205
- import { realpathSync as realpathSync4 } from "node:fs";
39206
- import { dirname as dirname4, join as join8 } from "node:path";
39217
+ import { realpathSync as realpathSync5 } from "node:fs";
39218
+ import { dirname as dirname5, join as join9 } from "node:path";
39207
39219
 
39208
39220
  // ../bus-daemon/src/global.ts
39209
39221
  import { randomBytes } from "node:crypto";
@@ -39402,6 +39414,227 @@ function writeGlobalDirs(dirs, h = home()) {
39402
39414
  }
39403
39415
  }
39404
39416
 
39417
+ // ../bus-daemon/src/namespace.ts
39418
+ init_src();
39419
+ import { execFileSync as execFileSync4 } from "node:child_process";
39420
+ import { realpathSync as realpathSync4 } from "node:fs";
39421
+ import { basename as basename4, dirname as dirname4, resolve as resolve2 } from "node:path";
39422
+
39423
+ // ../bus-daemon/src/namespaces.ts
39424
+ import { randomBytes as randomBytes2 } from "node:crypto";
39425
+ import {
39426
+ appendFileSync,
39427
+ chmodSync as chmodSync4,
39428
+ closeSync as closeSync4,
39429
+ mkdirSync as mkdirSync5,
39430
+ openSync as openSync4,
39431
+ renameSync as renameSync3,
39432
+ unlinkSync as unlinkSync2,
39433
+ writeSync as writeSync2
39434
+ } from "node:fs";
39435
+ import { isAbsolute as isAbsolute4, join as join8 } from "node:path";
39436
+ var namespacesFile = (h = home()) => join8(h, "namespaces.json");
39437
+ function readApprovals(file2 = namespacesFile()) {
39438
+ const own2 = readOwnFile(file2);
39439
+ if (own2.state === "none") return { entries: [] };
39440
+ if (own2.state === "unsafe") return { entries: [], error: own2.why };
39441
+ try {
39442
+ const raw = JSON.parse(own2.text);
39443
+ const list = raw?.approved;
39444
+ if (raw && !Array.isArray(raw) && Array.isArray(list) && list.every(
39445
+ (e) => e && typeof e === "object" && typeof e.dir === "string" && isAbsolute4(e.dir) && typeof e.namespace === "string" && e.namespace !== ""
39446
+ ))
39447
+ return {
39448
+ entries: list.map((e) => ({ dir: e.dir, namespace: e.namespace }))
39449
+ };
39450
+ } catch {
39451
+ }
39452
+ return { entries: [], error: "is not valid JSON" };
39453
+ }
39454
+ function isApproved(dir, namespace2, entries) {
39455
+ return entries.some((e) => e.namespace === namespace2 && sameDir(e.dir, dir));
39456
+ }
39457
+ function writeApprovals(entries, h = home()) {
39458
+ mkdirSync5(h, { recursive: true, mode: 448 });
39459
+ chmodSync4(h, 448);
39460
+ const tmp = join8(h, `.namespaces.json.${randomBytes2(8).toString("hex")}.tmp`);
39461
+ const fd = openSync4(tmp, "wx", 384);
39462
+ try {
39463
+ writeSync2(fd, `${JSON.stringify({ approved: entries }, null, 2)}
39464
+ `);
39465
+ } catch (e) {
39466
+ closeSync4(fd);
39467
+ unlinkSync2(tmp);
39468
+ throw e;
39469
+ }
39470
+ closeSync4(fd);
39471
+ try {
39472
+ chmodSync4(tmp, 384);
39473
+ renameSync3(tmp, namespacesFile(h));
39474
+ } catch (e) {
39475
+ unlinkSync2(tmp);
39476
+ throw e;
39477
+ }
39478
+ }
39479
+ function logApproval(entry, h = home(), now = /* @__PURE__ */ new Date()) {
39480
+ const dir = join8(h, "logs");
39481
+ mkdirSync5(dir, { recursive: true, mode: 448 });
39482
+ const file2 = join8(dir, "approvals.log");
39483
+ const line = `${now.toISOString()} ${entry.action} dir=${JSON.stringify(entry.dir)} namespace=${JSON.stringify(entry.namespace)} tty=${entry.tty ? "yes" : "no"}
39484
+ `;
39485
+ appendFileSync(file2, line, { mode: 384 });
39486
+ chmodSync4(file2, 384);
39487
+ }
39488
+
39489
+ // ../bus-daemon/src/namespace.ts
39490
+ var warned = /* @__PURE__ */ new Set();
39491
+ var once = (deps, key2, msg) => {
39492
+ if (warned.has(key2)) return;
39493
+ warned.add(key2);
39494
+ deps.log?.(msg);
39495
+ };
39496
+ function resolveNamespace(start, deps = {}) {
39497
+ let cwd;
39498
+ let missing2 = false;
39499
+ try {
39500
+ cwd = realpathSync4(start);
39501
+ } catch (e) {
39502
+ if (!deps.allowMissing) throw e;
39503
+ cwd = resolve2(start);
39504
+ missing2 = true;
39505
+ if (!warned.has(cwd)) {
39506
+ warned.add(cwd);
39507
+ deps.log?.(`${cwd} does not resolve; using it as given`);
39508
+ }
39509
+ }
39510
+ const { cfg, asked, nsFile } = readConfigs(cwd, deps);
39511
+ const global2 = !missing2 && allowlisted(cwd, deps);
39512
+ if (!global2)
39513
+ for (const file2 of asked)
39514
+ once(
39515
+ deps,
39516
+ `global:${file2}`,
39517
+ `ignoring global in ${file2}: only \`${BUS_CMD} global add\` makes a directory global`
39518
+ );
39519
+ const remoteUrl = (deps.gitRemote ?? gitRemote)(cwd);
39520
+ const root = (deps.gitRoot ?? gitRoot)(cwd);
39521
+ const derived2 = namespaceFrom({
39522
+ remoteUrl,
39523
+ gitRootName: root ? basename4(root) : null,
39524
+ cwd
39525
+ });
39526
+ const source = remoteUrl && normalizeRemote(remoteUrl) ? "git" : root ? "dir" : "cwd";
39527
+ const fallback = { namespace: derived2, global: global2, source };
39528
+ if (!cfg.namespace || !nsFile) return fallback;
39529
+ if (cfg.namespace === derived2) {
39530
+ deps.issues?.setPending(nsFile, deps.uid ?? process.getuid?.(), void 0);
39531
+ return fallback;
39532
+ }
39533
+ if (approved(nsFile, cfg.namespace, deps))
39534
+ return { namespace: cfg.namespace, global: global2, source: "config" };
39535
+ const dir = dirname4(nsFile);
39536
+ deps.issues?.setPending(nsFile, deps.uid ?? process.getuid?.(), {
39537
+ file: nsFile,
39538
+ dir,
39539
+ namespace: cfg.namespace,
39540
+ approvals: deps.namespacesFile
39541
+ });
39542
+ once(
39543
+ deps,
39544
+ `ns:${nsFile}:${cfg.namespace}`,
39545
+ `ignoring namespace "${cfg.namespace}" in ${nsFile}: not approved; run: ${approveCommand(dir)}`
39546
+ );
39547
+ return fallback;
39548
+ }
39549
+ function approved(file2, namespace2, deps) {
39550
+ const path = deps.namespacesFile ?? namespacesFile();
39551
+ const list = readApprovals(path);
39552
+ if (list.error)
39553
+ once(
39554
+ deps,
39555
+ `approvals:${path}:${list.error}`,
39556
+ `${path} ${list.error}: no namespace is approved`
39557
+ );
39558
+ return isApproved(dirname4(file2), namespace2, list.entries);
39559
+ }
39560
+ function allowlisted(cwd, deps) {
39561
+ const file2 = deps.globalFile ?? globalFile();
39562
+ const list = readGlobalDirs(file2);
39563
+ if (list.error)
39564
+ once(
39565
+ deps,
39566
+ `allowlist:${file2}:${list.error}`,
39567
+ `${file2} ${list.error}: no directory is global`
39568
+ );
39569
+ if (list.dirs.length === 0) return false;
39570
+ try {
39571
+ return isGlobalDir(
39572
+ cwd,
39573
+ list.dirs,
39574
+ (entry) => once(
39575
+ deps,
39576
+ `stale:${file2}:${entry}`,
39577
+ `ignoring ${entry} in ${file2}: its path is no longer real (a symlink now stands in it)`
39578
+ )
39579
+ );
39580
+ } catch {
39581
+ return false;
39582
+ }
39583
+ }
39584
+ function readConfigs(cwd, deps) {
39585
+ const uid = deps.uid ?? process.getuid?.();
39586
+ const configs = [];
39587
+ const asked = [];
39588
+ let nsFile;
39589
+ for (const file2 of configPaths(cwd)) {
39590
+ const own2 = readOwnFile(file2, uid, {
39591
+ allowGroupWrite: true,
39592
+ ...deps.group ? { group: deps.group } : {}
39593
+ });
39594
+ if (own2.state === "unsafe")
39595
+ once(deps, file2, `ignoring ${file2}: it ${own2.why}`);
39596
+ let valid2 = true;
39597
+ if (own2.state === "ok") {
39598
+ if (own2.note) once(deps, `note:${file2}`, `using ${file2}: it ${own2.note}`);
39599
+ let parsed;
39600
+ try {
39601
+ parsed = BusConfigSchema.safeParse(JSON.parse(own2.text));
39602
+ } catch {
39603
+ }
39604
+ if (parsed?.success) {
39605
+ configs.push(parsed.data);
39606
+ if (parsed.data.global === true) asked.push(file2);
39607
+ if (parsed.data.namespace !== void 0 && nsFile === void 0)
39608
+ nsFile = file2;
39609
+ } else {
39610
+ valid2 = false;
39611
+ deps.log?.(`ignoring invalid ${file2}`);
39612
+ }
39613
+ }
39614
+ deps.issues?.set(file2, uid, configIssue(file2, own2, valid2), deps.group);
39615
+ }
39616
+ return { cfg: mergeConfigs(configs), asked, nsFile };
39617
+ }
39618
+ function nearestConfig(dir, deps = {}) {
39619
+ try {
39620
+ return readConfigs(realpathSync4(dir), deps).cfg;
39621
+ } catch {
39622
+ return {};
39623
+ }
39624
+ }
39625
+ var git = (cwd, args) => {
39626
+ try {
39627
+ return execFileSync4("git", ["-C", cwd, ...args], {
39628
+ encoding: "utf8",
39629
+ stdio: ["ignore", "pipe", "ignore"]
39630
+ }).trim() || null;
39631
+ } catch {
39632
+ return null;
39633
+ }
39634
+ };
39635
+ var gitRemote = (cwd) => git(cwd, ["remote", "get-url", "origin"]);
39636
+ var gitRoot = (cwd) => git(cwd, ["rev-parse", "--show-toplevel"]);
39637
+
39405
39638
  // ../bus-daemon/src/config-issues.ts
39406
39639
  var shq = (s) => `'${s.replace(/'/g, "'\\''")}'`;
39407
39640
  function fixFor(file2, why) {
@@ -39441,6 +39674,24 @@ function configIssue(file2, own2, valid2 = true) {
39441
39674
  };
39442
39675
  return void 0;
39443
39676
  }
39677
+ var approveCommand = (dir) => `oa-bus namespace approve ${shq(dir)}`;
39678
+ var pendingIssue = (p) => ({
39679
+ file: p.file,
39680
+ state: "pending",
39681
+ reason: `sets namespace "${p.namespace}", which you have not approved`,
39682
+ fix: approveCommand(p.dir)
39683
+ });
39684
+ function stillPending(p, uid) {
39685
+ const own2 = readOwnFile(p.file, uid, { allowGroupWrite: true });
39686
+ if (own2.state !== "ok") return false;
39687
+ try {
39688
+ const parsed = BusConfigSchema.safeParse(JSON.parse(own2.text));
39689
+ if (!parsed.success || parsed.data.namespace !== p.namespace) return false;
39690
+ } catch {
39691
+ return false;
39692
+ }
39693
+ return !isApproved(p.dir, p.namespace, readApprovals(p.approvals).entries);
39694
+ }
39444
39695
  function isValidConfig(text3) {
39445
39696
  try {
39446
39697
  return BusConfigSchema.safeParse(JSON.parse(text3)).success;
@@ -39465,6 +39716,16 @@ function inspectGlobal(file2 = globalFile()) {
39465
39716
  fix: error62 === "is not valid JSON" ? `remove it (rm ${shq(file2)}), then run oa-bus global add <dir> again` : fixFor(file2, error62)
39466
39717
  };
39467
39718
  }
39719
+ function inspectApprovals(file2 = namespacesFile()) {
39720
+ const { error: error62 } = readApprovals(file2);
39721
+ if (error62 === void 0) return void 0;
39722
+ return {
39723
+ file: file2,
39724
+ state: "refused",
39725
+ reason: error62,
39726
+ fix: error62 === "is not valid JSON" ? `remove it (rm ${shq(file2)}), then run oa-bus namespace approve <dir> again` : fixFor(file2, error62)
39727
+ };
39728
+ }
39468
39729
  var ConfigIssues = class {
39469
39730
  #files = /* @__PURE__ */ new Map();
39470
39731
  /** Records the result of reading `file` (undefined: it is fine now). */
@@ -39472,9 +39733,21 @@ var ConfigIssues = class {
39472
39733
  if (issue2) this.#files.set(file2, { uid, group });
39473
39734
  else this.#files.delete(file2);
39474
39735
  }
39736
+ #pending = /* @__PURE__ */ new Map();
39737
+ /** Records a namespace waiting for approval, or clears it (undefined). */
39738
+ setPending(file2, uid, pending) {
39739
+ if (pending) this.#pending.set(file2, { p: pending, uid });
39740
+ else this.#pending.delete(file2);
39741
+ }
39475
39742
  /** Every tracked file, re-read now; `within` keeps only those at these paths. */
39476
- list(within) {
39743
+ list(within, opts = {}) {
39477
39744
  const out = [];
39745
+ for (const [file2, { p, uid }] of [...this.#pending]) {
39746
+ if (within && !within.has(file2)) continue;
39747
+ if (stillPending(p, uid)) {
39748
+ if (opts.pending) out.push(pendingIssue(p));
39749
+ } else this.#pending.delete(file2);
39750
+ }
39478
39751
  for (const [file2, { uid, group }] of [...this.#files]) {
39479
39752
  if (within && !within.has(file2)) continue;
39480
39753
  const issue2 = inspectConfig(file2, uid, group);
@@ -39489,22 +39762,40 @@ function scanConfigFiles(cwd, opts = {}) {
39489
39762
  const out = [];
39490
39763
  let real2 = cwd;
39491
39764
  try {
39492
- real2 = realpathSync4(cwd);
39765
+ real2 = realpathSync5(cwd);
39493
39766
  } catch {
39494
39767
  }
39495
39768
  for (const file2 of configPaths(real2)) {
39496
39769
  const issue2 = inspectConfig(file2, uid, opts.group);
39497
39770
  if (issue2) out.push(issue2);
39498
39771
  }
39772
+ const seen2 = new ConfigIssues();
39773
+ try {
39774
+ resolveNamespace(real2, {
39775
+ issues: seen2,
39776
+ allowMissing: true,
39777
+ ...opts.uid === void 0 ? {} : { uid: opts.uid },
39778
+ ...opts.group ? { group: opts.group } : {},
39779
+ ...opts.namespacesFile ? { namespacesFile: opts.namespacesFile } : {},
39780
+ ...opts.gitRemote ? { gitRemote: opts.gitRemote } : {},
39781
+ ...opts.gitRoot ? { gitRoot: opts.gitRoot } : {}
39782
+ });
39783
+ } catch {
39784
+ }
39785
+ out.push(
39786
+ ...seen2.list(void 0, { pending: true }).filter((f) => f.state === "pending")
39787
+ );
39788
+ const a = inspectApprovals(opts.namespacesFile);
39789
+ if (a) out.push(a);
39499
39790
  const g = inspectGlobal(opts.globalFile);
39500
39791
  if (g) out.push(g);
39501
39792
  return out;
39502
39793
  }
39503
39794
  function configPaths(cwd) {
39504
39795
  const out = [];
39505
- for (let dir = cwd; ; dir = dirname4(dir)) {
39506
- out.push(join8(dir, CONFIG_FILE));
39507
- if (dirname4(dir) === dir) return out;
39796
+ for (let dir = cwd; ; dir = dirname5(dir)) {
39797
+ out.push(join9(dir, CONFIG_FILE));
39798
+ if (dirname5(dir) === dir) return out;
39508
39799
  }
39509
39800
  }
39510
39801
 
@@ -40018,127 +40309,6 @@ function defaultBackoff(attempt) {
40018
40309
  return Math.round(base3 * (0.5 + Math.random() / 2));
40019
40310
  }
40020
40311
 
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
40312
  // ../bus-daemon/src/outbox.ts
40143
40313
  var Outbox = class {
40144
40314
  constructor(opts) {
@@ -40595,7 +40765,10 @@ function routeLocal(frame, hello, reply, ctx) {
40595
40765
  const ref = agent.ref;
40596
40766
  switch (frame.type) {
40597
40767
  case "self": {
40598
- const files = frame.row ? ctx.configFiles?.(agent.cwd) ?? [] : [];
40768
+ const files = frame.row ? ctx.configFiles?.(
40769
+ agent.cwd,
40770
+ hello.caps?.includes(ADAPTER_CAPS.pending)
40771
+ ) ?? [] : [];
40599
40772
  const self = {
40600
40773
  type: "agent",
40601
40774
  agent: {
@@ -40683,9 +40856,9 @@ function routeLocal(frame, hello, reply, ctx) {
40683
40856
  init_src2();
40684
40857
  init_src();
40685
40858
  import {
40686
- chmodSync as chmodSync4,
40859
+ chmodSync as chmodSync5,
40687
40860
  readFileSync as readFileSync7,
40688
- renameSync as renameSync3,
40861
+ renameSync as renameSync4,
40689
40862
  rmSync as rmSync2,
40690
40863
  writeFileSync
40691
40864
  } from "node:fs";
@@ -40863,20 +41036,20 @@ var SentStore = class {
40863
41036
  from_ref,
40864
41037
  from_name,
40865
41038
  to_name,
40866
- namespace,
41039
+ namespace: namespace2,
40867
41040
  excerpt,
40868
41041
  at,
40869
41042
  outcome,
40870
41043
  delivered,
40871
41044
  late: late2,
40872
- shown: shown2,
41045
+ shown: shown3,
40873
41046
  native
40874
41047
  } = e;
40875
41048
  this.#all.set(id, {
40876
41049
  from_ref,
40877
41050
  ...BusNameSchema.safeParse(from_name).success ? { from_name } : {},
40878
41051
  to_name,
40879
- ...namespace === void 0 ? {} : { namespace },
41052
+ ...namespace2 === void 0 ? {} : { namespace: namespace2 },
40880
41053
  ...validExcerpt(excerpt) ? { excerpt } : {},
40881
41054
  at,
40882
41055
  ...outcome ? {
@@ -40887,7 +41060,7 @@ var SentStore = class {
40887
41060
  } : {},
40888
41061
  ...delivered ? { delivered } : {},
40889
41062
  ...delivered && late2 ? { late: late2 } : {},
40890
- ...delivered && late2 && shown2 ? { shown: shown2 } : {},
41063
+ ...delivered && late2 && shown3 ? { shown: shown3 } : {},
40891
41064
  ...native ? { native } : {}
40892
41065
  });
40893
41066
  }
@@ -40913,8 +41086,8 @@ var SentStore = class {
40913
41086
  mode: 384,
40914
41087
  flag: "wx"
40915
41088
  });
40916
- chmodSync4(tmp, 384);
40917
- renameSync3(tmp, this.file);
41089
+ chmodSync5(tmp, 384);
41090
+ renameSync4(tmp, this.file);
40918
41091
  } catch (e) {
40919
41092
  this.#log?.(
40920
41093
  `sent file write failed: ${e instanceof Error ? e.message : String(e)}`
@@ -40949,7 +41122,7 @@ var Receipts = class {
40949
41122
  #now;
40950
41123
  #after;
40951
41124
  /** `native`: no tool call waits for this receipt, so a refusal is a notice too. */
40952
- sending(f, namespace, native, fromName) {
41125
+ sending(f, namespace2, native, fromName) {
40953
41126
  const excerpt = typeof f.body === "string" ? excerptOf(f.body) : void 0;
40954
41127
  const cutoff = this.#now() - 15 * 6e4;
40955
41128
  for (const [id, s] of this.#sending)
@@ -40959,7 +41132,7 @@ var Receipts = class {
40959
41132
  from_ref: f.from_ref,
40960
41133
  ...fromName ? { from_name: fromName } : {},
40961
41134
  to_name: f.to_name,
40962
- ...namespace ? { namespace } : {},
41135
+ ...namespace2 ? { namespace: namespace2 } : {},
40963
41136
  ...excerpt ? { excerpt } : {}
40964
41137
  },
40965
41138
  native,
@@ -41029,12 +41202,12 @@ var Receipts = class {
41029
41202
  this.#waiting.delete(msgId);
41030
41203
  return Promise.resolve(w.final);
41031
41204
  }
41032
- return new Promise((resolve8) => {
41205
+ return new Promise((resolve9) => {
41033
41206
  const cancel = this.#after(ms, () => w.done?.(void 0));
41034
41207
  w.done = (f) => {
41035
41208
  cancel();
41036
41209
  this.#waiting.delete(msgId);
41037
- resolve8(f);
41210
+ resolve9(f);
41038
41211
  };
41039
41212
  });
41040
41213
  }
@@ -41090,20 +41263,20 @@ init_src3();
41090
41263
  init_src();
41091
41264
  import { createHash as createHash4, randomUUID } from "node:crypto";
41092
41265
  import {
41093
- chmodSync as chmodSync6,
41266
+ chmodSync as chmodSync7,
41094
41267
  lstatSync as lstatSync5,
41095
- mkdirSync as mkdirSync5,
41268
+ mkdirSync as mkdirSync6,
41096
41269
  readFileSync as readFileSync9,
41097
- renameSync as renameSync5,
41270
+ renameSync as renameSync6,
41098
41271
  rmSync as rmSync3,
41099
41272
  writeFileSync as writeFileSync3
41100
41273
  } from "node:fs";
41101
41274
  import { createServer as createServer2 } from "node:net";
41102
- import { dirname as dirname5, join as join9 } from "node:path";
41275
+ import { dirname as dirname6, join as join10 } from "node:path";
41103
41276
  import { createInterface } from "node:readline";
41104
41277
 
41105
41278
  // ../bus-daemon/src/transports/held.ts
41106
- import { chmodSync as chmodSync5, readFileSync as readFileSync8, renameSync as renameSync4, writeFileSync as writeFileSync2 } from "node:fs";
41279
+ import { chmodSync as chmodSync6, readFileSync as readFileSync8, renameSync as renameSync5, writeFileSync as writeFileSync2 } from "node:fs";
41107
41280
  var HeldStore = class {
41108
41281
  constructor(file2, opts = {}) {
41109
41282
  this.file = file2;
@@ -41142,8 +41315,8 @@ var HeldStore = class {
41142
41315
  #write(all) {
41143
41316
  const tmp = `${this.file}.${process.pid}.tmp`;
41144
41317
  writeFileSync2(tmp, JSON.stringify(all), { mode: 384 });
41145
- chmodSync5(tmp, 384);
41146
- renameSync4(tmp, this.file);
41318
+ chmodSync6(tmp, 384);
41319
+ renameSync5(tmp, this.file);
41147
41320
  }
41148
41321
  };
41149
41322
 
@@ -41169,7 +41342,7 @@ function unsafeClaudeSocket(path) {
41169
41342
  try {
41170
41343
  if (!sock.isSocket()) return `${path} is not a socket`;
41171
41344
  if (sock.uid !== uid) return `${path} belongs to another user`;
41172
- const dir = dirname5(path);
41345
+ const dir = dirname6(path);
41173
41346
  const st = lstatSync5(dir);
41174
41347
  if (!st.isDirectory()) return `${dir} is not a folder`;
41175
41348
  if (st.uid !== uid) return `${dir} belongs to another user`;
@@ -41183,8 +41356,8 @@ function unsafeClaudeSocket(path) {
41183
41356
  var RETURN_INDEX_MAX = 500;
41184
41357
  var RETURN_TTL_MS = LIMITS.mailTtlSec * 1e3;
41185
41358
  var INDEX_REFRESH_MS = 6e4;
41186
- function returnKey(agentRef, namespace, peerName, fromId) {
41187
- return `${agentRef}\0${namespace}\0${peerName}\0${fromId ?? ""}`;
41359
+ function returnKey(agentRef, namespace2, peerName, fromId) {
41360
+ return `${agentRef}\0${namespace2}\0${peerName}\0${fromId ?? ""}`;
41188
41361
  }
41189
41362
  function readReturnIndex(file2) {
41190
41363
  let raw;
@@ -41226,7 +41399,7 @@ var ClaudeTransport = class {
41226
41399
  this.opts = opts;
41227
41400
  this.#held = opts.heldFile ? new HeldStore(opts.heldFile) : void 0;
41228
41401
  this.#injected = opts.heldFile ? new HeldStore(opts.heldFile.replace(/(\.json)?$/, ".injected.json")) : void 0;
41229
- const sample = join9(opts.socketsDir, "00000000.sock");
41402
+ const sample = join10(opts.socketsDir, "00000000.sock");
41230
41403
  if (Buffer.byteLength(sample) > MAX_SOCKET_PATH) {
41231
41404
  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
41405
  opts.log?.(this.#disabled);
@@ -41343,22 +41516,22 @@ var ClaudeTransport = class {
41343
41516
  return { ok: false, reason: "closed", cause: st };
41344
41517
  }
41345
41518
  #waitFor(msgId, ms) {
41346
- return new Promise((resolve8) => {
41519
+ return new Promise((resolve9) => {
41347
41520
  const buffered = this.#buffered.get(msgId);
41348
41521
  if (buffered !== void 0) {
41349
41522
  this.#buffered.delete(msgId);
41350
- resolve8(buffered);
41523
+ resolve9(buffered);
41351
41524
  return;
41352
41525
  }
41353
41526
  const timer = setTimeout(() => {
41354
41527
  this.#waiting.delete(msgId);
41355
- resolve8(void 0);
41528
+ resolve9(void 0);
41356
41529
  }, ms);
41357
41530
  timer.unref();
41358
41531
  this.#waiting.set(msgId, (s) => {
41359
41532
  clearTimeout(timer);
41360
41533
  this.#waiting.delete(msgId);
41361
- resolve8(s);
41534
+ resolve9(s);
41362
41535
  });
41363
41536
  });
41364
41537
  }
@@ -41439,14 +41612,14 @@ var ClaudeTransport = class {
41439
41612
  return t ? `uds:${t.socketPath}` : "";
41440
41613
  }
41441
41614
  /** 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);
41615
+ #sink(agentRef, namespace2, peerName, fromId, revived) {
41616
+ const key2 = returnKey(agentRef, namespace2, peerName, fromId);
41444
41617
  let sink = this.#sinks.get(key2);
41445
41618
  if (!sink) {
41446
41619
  sink = this.#listen(
41447
41620
  key2,
41448
41621
  agentRef,
41449
- namespace,
41622
+ namespace2,
41450
41623
  peerName,
41451
41624
  false,
41452
41625
  revived,
@@ -41460,8 +41633,8 @@ var ClaudeTransport = class {
41460
41633
  }
41461
41634
  return sink;
41462
41635
  }
41463
- async #listen(key2, agentRef, namespace, peerName, notice = false, revived, fromId) {
41464
- const path = join9(
41636
+ async #listen(key2, agentRef, namespace2, peerName, notice = false, revived, fromId) {
41637
+ const path = join10(
41465
41638
  this.opts.socketsDir,
41466
41639
  `${notice ? randomUUID().slice(0, 8) : returnName(key2, this.#pathsInUse())}.sock`
41467
41640
  );
@@ -41469,8 +41642,8 @@ var ClaudeTransport = class {
41469
41642
  const unsafe = this.opts.prepareDir(this.opts.socketsDir);
41470
41643
  if (unsafe) throw new UnsafeDir(unsafe);
41471
41644
  } else {
41472
- mkdirSync5(this.opts.socketsDir, { recursive: true, mode: 448 });
41473
- chmodSync6(this.opts.socketsDir, 448);
41645
+ mkdirSync6(this.opts.socketsDir, { recursive: true, mode: 448 });
41646
+ chmodSync7(this.opts.socketsDir, 448);
41474
41647
  }
41475
41648
  rmSync3(path, { force: true });
41476
41649
  this.#paths.set(key2, path);
@@ -41480,7 +41653,7 @@ var ClaudeTransport = class {
41480
41653
  path,
41481
41654
  conns,
41482
41655
  agentRef,
41483
- namespace,
41656
+ namespace: namespace2,
41484
41657
  peerName,
41485
41658
  claudeFrom: "",
41486
41659
  notice,
@@ -41498,11 +41671,11 @@ var ClaudeTransport = class {
41498
41671
  );
41499
41672
  })
41500
41673
  };
41501
- await new Promise((resolve8, reject) => {
41674
+ await new Promise((resolve9, reject) => {
41502
41675
  sink.server.once("error", reject);
41503
- sink.server.listen(path, () => resolve8());
41676
+ sink.server.listen(path, () => resolve9());
41504
41677
  });
41505
- chmodSync6(path, 384);
41678
+ chmodSync7(path, 384);
41506
41679
  return sink;
41507
41680
  }
41508
41681
  /** Paths of the sinks bound or binding now, by key. */
@@ -41543,8 +41716,8 @@ var ClaudeTransport = class {
41543
41716
  for (const [k, v] of keep) out[k] = v;
41544
41717
  const tmp = `${file2}.${process.pid}.tmp`;
41545
41718
  writeFileSync3(tmp, JSON.stringify(out), { mode: 384 });
41546
- chmodSync6(tmp, 384);
41547
- renameSync5(tmp, file2);
41719
+ chmodSync7(tmp, 384);
41720
+ renameSync6(tmp, file2);
41548
41721
  return out;
41549
41722
  } catch (e) {
41550
41723
  this.opts.log?.(
@@ -41624,10 +41797,10 @@ init_src2();
41624
41797
  import { execFile } from "node:child_process";
41625
41798
  import { accessSync, constants as constants2, readFileSync as readFileSync10, statSync as statSync7 } from "node:fs";
41626
41799
  import { readFile } from "node:fs/promises";
41627
- import { delimiter, isAbsolute as isAbsolute4, join as join10 } from "node:path";
41800
+ import { delimiter, isAbsolute as isAbsolute5, join as join11 } from "node:path";
41628
41801
  var CODEX_QUEUE_TIMEOUT_MS = 1e4;
41629
41802
  var CODEX_TEXT_CAP = 64 * 1024;
41630
- var codexBinFile = (busHome2) => join10(busHome2, "codex.json");
41803
+ var codexBinFile = (busHome2) => join11(busHome2, "codex.json");
41631
41804
  var codexBinPin = (bin) => `${JSON.stringify({ bin }, null, 2)}
41632
41805
  `;
41633
41806
  var CODEX_APP = "/Applications/ChatGPT.app";
@@ -41643,11 +41816,11 @@ var executable = (p) => {
41643
41816
  };
41644
41817
  function codexAppBin(app) {
41645
41818
  try {
41646
- const plist = readFileSync10(join10(app, "Contents", "Info.plist"), "utf8");
41819
+ const plist = readFileSync10(join11(app, "Contents", "Info.plist"), "utf8");
41647
41820
  const id = /<key>CFBundleIdentifier<\/key>\s*<string>([^<]*)<\/string>/.exec(
41648
41821
  plist
41649
41822
  )?.[1];
41650
- return id === CODEX_APP_ID ? join10(app, "Contents", "Resources", "codex") : void 0;
41823
+ return id === CODEX_APP_ID ? join11(app, "Contents", "Resources", "codex") : void 0;
41651
41824
  } catch {
41652
41825
  return void 0;
41653
41826
  }
@@ -41656,13 +41829,13 @@ function resolveCodexBin(o) {
41656
41829
  if (o.configFile)
41657
41830
  try {
41658
41831
  const raw = JSON.parse(readFileSync10(o.configFile, "utf8"));
41659
- if (typeof raw.bin === "string" && isAbsolute4(raw.bin) && executable(raw.bin))
41832
+ if (typeof raw.bin === "string" && isAbsolute5(raw.bin) && executable(raw.bin))
41660
41833
  return { path: raw.bin, from: "config" };
41661
41834
  } catch {
41662
41835
  }
41663
41836
  for (const dir of (o.path ?? "").split(delimiter)) {
41664
- if (!isAbsolute4(dir)) continue;
41665
- const p = join10(dir, "codex");
41837
+ if (!isAbsolute5(dir)) continue;
41838
+ const p = join11(dir, "codex");
41666
41839
  if (executable(p)) return { path: p, from: "path" };
41667
41840
  }
41668
41841
  const app = o.app === null ? void 0 : codexAppBin(o.app ?? CODEX_APP);
@@ -41712,14 +41885,14 @@ function splitArgv0(args) {
41712
41885
  const real2 = ends.find((e) => {
41713
41886
  const p = args.slice(0, e);
41714
41887
  try {
41715
- return isAbsolute4(p) && statSync7(p).isFile();
41888
+ return isAbsolute5(p) && statSync7(p).isFile();
41716
41889
  } catch {
41717
41890
  return false;
41718
41891
  }
41719
41892
  });
41720
41893
  return words(args.slice(real2 ?? ends[0]));
41721
41894
  }
41722
- var execText = (cmd, args) => new Promise((resolve8) => {
41895
+ var execText = (cmd, args) => new Promise((resolve9) => {
41723
41896
  execFile(
41724
41897
  cmd,
41725
41898
  args,
@@ -41728,7 +41901,7 @@ var execText = (cmd, args) => new Promise((resolve8) => {
41728
41901
  timeout: 2e3,
41729
41902
  env: { ...process.env, LC_ALL: "C" }
41730
41903
  },
41731
- (err, stdout) => resolve8(err ? void 0 : stdout)
41904
+ (err, stdout) => resolve9(err ? void 0 : stdout)
41732
41905
  );
41733
41906
  });
41734
41907
  async function processArgs(pid) {
@@ -41751,17 +41924,17 @@ async function processArgs(pid) {
41751
41924
  return args ? splitArgv0(args) : void 0;
41752
41925
  }
41753
41926
  var START_ERRORS = /* @__PURE__ */ new Set(["ENOENT", "EACCES", "ENOEXEC"]);
41754
- var execCodex = (timeoutMs = CODEX_QUEUE_TIMEOUT_MS) => (bin, args, env) => new Promise((resolve8, reject) => {
41927
+ var execCodex = (timeoutMs = CODEX_QUEUE_TIMEOUT_MS) => (bin, args, env2) => new Promise((resolve9, reject) => {
41755
41928
  execFile(
41756
41929
  bin,
41757
41930
  args,
41758
- { timeout: timeoutMs, maxBuffer: 64 * 1024, env },
41931
+ { timeout: timeoutMs, maxBuffer: 64 * 1024, env: env2 },
41759
41932
  (err, _stdout, stderr) => {
41760
- if (!err) return resolve8({ code: 0, stderr });
41933
+ if (!err) return resolve9({ code: 0, stderr });
41761
41934
  const e = err;
41762
41935
  if (typeof e.code === "string" && START_ERRORS.has(e.code))
41763
41936
  return reject(err);
41764
- resolve8({
41937
+ resolve9({
41765
41938
  // A maxBuffer kill is SIGTERM too, but carries its own string code.
41766
41939
  code: e.killed && e.signal === "SIGTERM" && typeof e.code !== "string" ? null : typeof e.code === "number" ? e.code : -1,
41767
41940
  stderr: String(stderr ?? "")
@@ -41886,17 +42059,17 @@ var codexHostWakes = async (pid) => {
41886
42059
  init_src2();
41887
42060
  import { execFile as execFile2 } from "node:child_process";
41888
42061
  var START_ERRORS2 = /* @__PURE__ */ new Set(["ENOENT", "EACCES"]);
41889
- var execSpawn = (timeoutMs, maxBuffer = 1024 * 1024) => (cmd, args) => new Promise((resolve8, reject) => {
42062
+ var execSpawn = (timeoutMs, maxBuffer = 1024 * 1024) => (cmd, args) => new Promise((resolve9, reject) => {
41890
42063
  execFile2(
41891
42064
  cmd,
41892
42065
  args,
41893
42066
  { timeout: timeoutMs, maxBuffer },
41894
42067
  (err, stdout, stderr) => {
41895
- if (!err) return resolve8({ code: 0, stdout, stderr });
42068
+ if (!err) return resolve9({ code: 0, stdout, stderr });
41896
42069
  const e = err;
41897
42070
  if (typeof e.code === "string" && START_ERRORS2.has(e.code))
41898
42071
  return reject(err);
41899
- resolve8({
42072
+ resolve9({
41900
42073
  code: e.killed || typeof e.code !== "number" ? null : e.code,
41901
42074
  stdout,
41902
42075
  stderr
@@ -42011,18 +42184,18 @@ var PiTransport = class {
42011
42184
  });
42012
42185
  if (!pushed) return { ok: false, reason: "closed" };
42013
42186
  this.#forget(mail.msg_id);
42014
- return new Promise((resolve8) => {
42187
+ return new Promise((resolve9) => {
42015
42188
  const timer = setTimeout(() => {
42016
42189
  this.#waiting.delete(mail.msg_id);
42017
42190
  this.#remember(mail.msg_id, agent.ref);
42018
- resolve8({ ok: false, reason: "timeout" });
42191
+ resolve9({ ok: false, reason: "timeout" });
42019
42192
  }, this.opts.ackTimeoutMs ?? 1e4);
42020
42193
  timer.unref();
42021
42194
  this.#waiting.set(mail.msg_id, {
42022
42195
  ref: agent.ref,
42023
42196
  done: (o) => {
42024
42197
  clearTimeout(timer);
42025
- resolve8(o);
42198
+ resolve9(o);
42026
42199
  }
42027
42200
  });
42028
42201
  });
@@ -42145,8 +42318,9 @@ async function runDaemon(deps = {}) {
42145
42318
  caps.delete(ref);
42146
42319
  };
42147
42320
  const configIssues = new ConfigIssues();
42148
- const configFiles = (cwd) => {
42321
+ const configFiles = (cwd, pending2 = false) => {
42149
42322
  const g = inspectGlobal();
42323
+ const a = inspectApprovals();
42150
42324
  let within;
42151
42325
  if (cwd !== void 0) {
42152
42326
  try {
@@ -42155,7 +42329,11 @@ async function runDaemon(deps = {}) {
42155
42329
  within = new Set(configPaths(cwd));
42156
42330
  }
42157
42331
  }
42158
- return [...configIssues.list(within), ...g ? [g] : []];
42332
+ return [
42333
+ ...configIssues.list(within, { pending: pending2 }),
42334
+ ...a ? [a] : [],
42335
+ ...g ? [g] : []
42336
+ ];
42159
42337
  };
42160
42338
  const resolveNs = (cwd, allowMissing) => (deps.resolveNamespace ?? ((dir) => resolveNamespace(dir, { log, allowMissing, issues: configIssues })))(cwd);
42161
42339
  const cl = deps.claude ?? {};
@@ -42201,7 +42379,7 @@ async function runDaemon(deps = {}) {
42201
42379
  log,
42202
42380
  promptIdSupported: () => promptIdSupported,
42203
42381
  uncertain: new HeldStore(
42204
- oc.uncertainFile ?? join11(home(), "opencode-uncertain.json")
42382
+ oc.uncertainFile ?? join12(home(), "opencode-uncertain.json")
42205
42383
  )
42206
42384
  });
42207
42385
  const codex = new CodexTransport({
@@ -42212,7 +42390,7 @@ async function runDaemon(deps = {}) {
42212
42390
  run: cx.run ?? execCodex(),
42213
42391
  home: cx.home ?? codexHome(),
42214
42392
  wakes: cx.wakes ?? codexHostWakes,
42215
- queued: new HeldStore(cx.queuedFile ?? join11(home(), "codex-queued.json")),
42393
+ queued: new HeldStore(cx.queuedFile ?? join12(home(), "codex-queued.json")),
42216
42394
  log
42217
42395
  });
42218
42396
  const pi = new PiTransport({
@@ -42224,7 +42402,7 @@ async function runDaemon(deps = {}) {
42224
42402
  },
42225
42403
  ackTimeoutMs: deps.pi?.ackTimeoutMs
42226
42404
  });
42227
- const sent = new SentStore(deps.sentFile ?? join11(home(), "sent.json"), {
42405
+ const sent = new SentStore(deps.sentFile ?? join12(home(), "sent.json"), {
42228
42406
  log
42229
42407
  });
42230
42408
  const receipts = new Receipts(sent, { after: deps.deliveredTimer });
@@ -42317,15 +42495,15 @@ async function runDaemon(deps = {}) {
42317
42495
  socketsDir: returnDir,
42318
42496
  // A deps.socketsDir is the caller's (tests); ours is re-checked before each bind.
42319
42497
  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")),
42498
+ heldFile: cl.heldFile ?? join12(home(), "claude-held.json"),
42499
+ returnIndexFile: cl.returnIndexFile ?? (cl.heldFile ? cl.heldFile.replace(/(\.json)?$/, ".return.json") : join12(home(), "claude-return.json")),
42322
42500
  statusWindowMs: cl.statusWindowMs,
42323
42501
  injectTimeoutMs: cl.injectTimeoutMs,
42324
42502
  log,
42325
42503
  target: (ref) => claudeTarget(ref, claudeSessions),
42326
42504
  // A native reply is a message from the session: the sink names the sender, never the frame.
42327
42505
  // 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) => {
42506
+ onReply: (agentRef, peerName, text3, namespace2, peerId) => {
42329
42507
  if (!isWellFormed2(text3))
42330
42508
  log(
42331
42509
  `a Claude reply to ${peerName} was not well-formed unicode; sent with U+FFFD`
@@ -42337,7 +42515,7 @@ async function runDaemon(deps = {}) {
42337
42515
  type: "send",
42338
42516
  from_ref: agentRef,
42339
42517
  to_name: peerName,
42340
- to_namespace: namespace,
42518
+ to_namespace: namespace2,
42341
42519
  body
42342
42520
  };
42343
42521
  if (!ClientFrameSchema.safeParse(f).success) {
@@ -42378,7 +42556,7 @@ async function runDaemon(deps = {}) {
42378
42556
  continue;
42379
42557
  }
42380
42558
  if (prev && prev.pid === s.pid) continue;
42381
- if (!isAbsolute5(s.cwd)) continue;
42559
+ if (!isAbsolute6(s.cwd)) continue;
42382
42560
  let ns;
42383
42561
  try {
42384
42562
  ns = resolveNs(s.cwd, true);
@@ -42564,7 +42742,7 @@ async function runDaemon(deps = {}) {
42564
42742
  process.exitCode = 1;
42565
42743
  try {
42566
42744
  writeFileSync4(
42567
- deps.revokedFile ?? join11(home(), "revoked"),
42745
+ deps.revokedFile ?? join12(home(), "revoked"),
42568
42746
  revokedMarker(cfg.machine_token),
42569
42747
  { mode: 384 }
42570
42748
  );
@@ -42612,21 +42790,21 @@ async function runDaemon(deps = {}) {
42612
42790
  statusEveryMs: deps.status?.statusEveryMs
42613
42791
  });
42614
42792
  const hubRoster = (ref) => new Promise(
42615
- (resolve8) => {
42793
+ (resolve9) => {
42616
42794
  const id = pending.open(
42617
42795
  "status",
42618
- (f) => resolve8(f.type === "roster" ? f.agents : void 0)
42796
+ (f) => resolve9(f.type === "roster" ? f.agents : void 0)
42619
42797
  );
42620
42798
  const timer = setTimeout(() => {
42621
42799
  pending.cancel(id);
42622
42800
  hub.cancel(id);
42623
- resolve8(void 0);
42801
+ resolve9(void 0);
42624
42802
  }, deps.statusRosterMs ?? 1500);
42625
42803
  timer.unref();
42626
42804
  if (!hub.send({ v: 1, id, type: "list", from_ref: ref })) {
42627
42805
  clearTimeout(timer);
42628
42806
  pending.cancel(id);
42629
- resolve8(void 0);
42807
+ resolve9(void 0);
42630
42808
  }
42631
42809
  }
42632
42810
  );
@@ -42650,7 +42828,7 @@ async function runDaemon(deps = {}) {
42650
42828
  // this machine's open sessions are in (or only the cwd's).
42651
42829
  onStatus: async (req) => {
42652
42830
  let only;
42653
- if (req.cwd && isAbsolute5(req.cwd)) {
42831
+ if (req.cwd && isAbsolute6(req.cwd)) {
42654
42832
  try {
42655
42833
  only = resolveNs(req.cwd, true).namespace;
42656
42834
  } catch {
@@ -42663,8 +42841,8 @@ async function runDaemon(deps = {}) {
42663
42841
  )
42664
42842
  ];
42665
42843
  const namespaces = await Promise.all(
42666
- names2.map(async (namespace) => {
42667
- const local = live.filter((a) => a.namespace === namespace);
42844
+ names2.map(async (namespace2) => {
42845
+ const local = live.filter((a) => a.namespace === namespace2);
42668
42846
  const mine = new Map(local.map((a) => [a.busName, a.kind]));
42669
42847
  const roster2 = local[0] && hub.open ? await hubRoster(local[0].ref) : void 0;
42670
42848
  const rows = roster2 ? roster2.filter((a) => a.state !== "away").map((a) => ({
@@ -42681,10 +42859,13 @@ async function runDaemon(deps = {}) {
42681
42859
  machine: cfg.label,
42682
42860
  state: "live"
42683
42861
  }));
42684
- return { namespace, agents: rows };
42862
+ return { namespace: namespace2, agents: rows };
42685
42863
  })
42686
42864
  );
42687
- const config_files = configFiles();
42865
+ const config_files = configFiles(
42866
+ void 0,
42867
+ req.caps?.includes(ADAPTER_CAPS.pending)
42868
+ );
42688
42869
  return {
42689
42870
  pid: process.pid,
42690
42871
  version: version2,
@@ -42759,7 +42940,7 @@ async function runDaemon(deps = {}) {
42759
42940
  };
42760
42941
  }
42761
42942
  const cwd = check2.cwd ?? hello.cwd;
42762
- if (!cwd || !isAbsolute5(cwd)) return { error: "cwd must be absolute" };
42943
+ if (!cwd || !isAbsolute6(cwd)) return { error: "cwd must be absolute" };
42763
42944
  let ns;
42764
42945
  try {
42765
42946
  ns = resolveNs(cwd, check2.cwd !== void 0);
@@ -42973,8 +43154,9 @@ async function runDaemon(deps = {}) {
42973
43154
  // src/context.ts
42974
43155
  init_src3();
42975
43156
  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";
43157
+ import { closeSync as closeSync5, openSync as openSync5, readFileSync as readFileSync13 } from "node:fs";
42977
43158
  import { homedir as homedir3, userInfo as userInfo2 } from "node:os";
43159
+ import { createInterface as createInterface2 } from "node:readline";
42978
43160
  init_src2();
42979
43161
 
42980
43162
  // src/copy.ts
@@ -43001,19 +43183,19 @@ var terminalAnsi = {
43001
43183
  };
43002
43184
 
43003
43185
  // src/term.ts
43004
- function detectStyle(env, stream, noColor = false) {
43005
- const fgbg = env.COLORFGBG?.split(";").at(-1);
43186
+ function detectStyle(env2, stream, noColor = false) {
43187
+ const fgbg = env2.COLORFGBG?.split(";").at(-1);
43006
43188
  const dark = !(fgbg === "7" || fgbg === "15");
43007
- const locale = `${env.LC_ALL ?? ""} ${env.LC_CTYPE ?? ""} ${env.LANG ?? ""}`;
43008
- const utf8 = /utf-?8/i.test(locale) || Boolean(env.WT_SESSION);
43189
+ const locale = `${env2.LC_ALL ?? ""} ${env2.LC_CTYPE ?? ""} ${env2.LANG ?? ""}`;
43190
+ const utf8 = /utf-?8/i.test(locale) || Boolean(env2.WT_SESSION);
43009
43191
  const style = (color) => ({ color, dark, utf8 });
43010
- if (noColor || env.NO_COLOR) return style("none");
43011
- const force = env.FORCE_COLOR;
43192
+ if (noColor || env2.NO_COLOR) return style("none");
43193
+ const force = env2.FORCE_COLOR;
43012
43194
  if (force !== void 0)
43013
43195
  return style(force === "0" ? "none" : force === "3" ? "truecolor" : "ansi");
43014
- if (env.TERM === "dumb" || !stream.isTTY || !stream.hasColors?.())
43196
+ if (env2.TERM === "dumb" || !stream.isTTY || !stream.hasColors?.())
43015
43197
  return style("none");
43016
- const deep = stream.hasColors(2 ** 24) || /^(truecolor|24bit)$/i.test(env.COLORTERM ?? "");
43198
+ const deep = stream.hasColors(2 ** 24) || /^(truecolor|24bit)$/i.test(env2.COLORTERM ?? "");
43017
43199
  return style(deep ? "truecolor" : "ansi");
43018
43200
  }
43019
43201
  var rgb = (hex3) => [1, 3, 5].map((i) => Number.parseInt(hex3.slice(i, i + 2), 16)).join(";");
@@ -43279,11 +43461,11 @@ function copy(style) {
43279
43461
  fail("The daemon did not start within 10 seconds."),
43280
43462
  next(`Run ${BUS_CMD} doctor to see why.`)
43281
43463
  ],
43282
- rosterHeader: (namespace, live, queued2) => {
43464
+ rosterHeader: (namespace2, live, queued2) => {
43283
43465
  const n = live + queued2;
43284
43466
  const meta3 = queued2 ? `${live} live ${g("sep")} ${queued2} queued` : `${live} live`;
43285
43467
  const lead = `${n} agent${n === 1 ? "" : "s"} in namespace `;
43286
- return `${lead}${p("accent", clip(namespace, len(lead) + 2 + len(meta3)))} ${p("muted", meta3)}`;
43468
+ return `${lead}${p("accent", clip(namespace2, len(lead) + 2 + len(meta3)))} ${p("muted", meta3)}`;
43287
43469
  },
43288
43470
  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
43471
  /** The row's status, under it (AC5c): the agent's own report, cut to 80 columns. */
@@ -43300,10 +43482,10 @@ function copy(style) {
43300
43482
  ),
43301
43483
  p("muted", "then the sender is told.")
43302
43484
  ],
43303
- noAgents: (namespace) => {
43485
+ noAgents: (namespace2) => {
43304
43486
  const lead = "No agents in namespace ";
43305
43487
  return [
43306
- `${lead}${p("accent", clip(namespace, len(lead) + 5))} yet.`,
43488
+ `${lead}${p("accent", clip(namespace2, len(lead) + 5))} yet.`,
43307
43489
  "Start Claude Code, OpenCode, Pi, oh-my-pi or Codex in this folder and it joins."
43308
43490
  ];
43309
43491
  },
@@ -43382,8 +43564,8 @@ function copy(style) {
43382
43564
  next(`Run ${BUS_CMD} --instance <your instance URL>,`),
43383
43565
  next("or set OA_BUS_INSTANCE.")
43384
43566
  ],
43385
- hubMismatch: (approved, asked, askedUrl) => {
43386
- const a = clip(approved, 39 + Math.min(len(asked), 20));
43567
+ hubMismatch: (approved2, asked, askedUrl) => {
43568
+ const a = clip(approved2, 39 + Math.min(len(asked), 20));
43387
43569
  const b2 = clip(asked, 39 + len(a));
43388
43570
  return [
43389
43571
  fail(`This machine is approved for ${a}, not ${b2}.`),
@@ -43488,7 +43670,7 @@ function copy(style) {
43488
43670
  /** A refused or noted config file (#1527): the reason, then the exact fix. Paths arrive already shortened. */
43489
43671
  configFile: (f) => [
43490
43672
  warn(
43491
- f.state === "refused" ? `${f.file} ${f.reason}, so it is ignored.` : `${f.file} ${f.reason}; it is still used.`
43673
+ 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
43674
  ),
43493
43675
  next(`Fix: ${f.fix}`),
43494
43676
  ...f.restart ? [next("Restart the session to pick up a fix.")] : []
@@ -43622,6 +43804,60 @@ function copy(style) {
43622
43804
  `${dirs.length} global ${dirs.length === 1 ? "directory" : "directories"}`,
43623
43805
  ...dirs.map((d) => ` ${clip(d, 2)}`)
43624
43806
  ],
43807
+ // 12. namespace approvals (#1525)
43808
+ nsUnusable: (path, why) => [
43809
+ warn(`${clip(path, 45)} can't be used, so no namespace is approved.`),
43810
+ next(p("muted", clip(`It ${why}.`, 3))),
43811
+ next(`Remove it, then run ${BUS_CMD} namespace approve <dir> again.`)
43812
+ ],
43813
+ nsNoFile: (dir) => [
43814
+ fail(`${clip(dir, 40)} has no .oa-bus.json.`),
43815
+ next("Check the path: approval is for the namespace that file sets.")
43816
+ ],
43817
+ nsFileUnusable: (file2, why) => [
43818
+ fail(`${clip(file2, 40)} can't be read: it ${why}.`)
43819
+ ],
43820
+ nsNoNamespace: (file2) => warn(`${clip(file2, 40)} sets no namespace. Nothing to approve.`),
43821
+ nsNotDir: (dir) => [
43822
+ fail(`${clip(dir, 23)} is not a directory.`),
43823
+ next(`Check the path, then run ${BUS_CMD} namespace approve again.`)
43824
+ ],
43825
+ nsAsk: (dir, namespace2) => [
43826
+ `${dir} sets its namespace to ${namespace2}.`,
43827
+ "Agents started there join it and can message everyone in it."
43828
+ ],
43829
+ nsPrompt: () => "Approve it? [y/N] ",
43830
+ nsNeedTty: (command) => [
43831
+ fail("Approving a namespace needs your user."),
43832
+ next(`Ask them to run this in a terminal: ${command}`)
43833
+ ],
43834
+ nsDeclined: () => warn("Not approved. Nothing changed."),
43835
+ nsAlready: (dir, namespace2) => done(`${clip(dir, 20)} is already approved for ${clip(namespace2, 40)}.`),
43836
+ nsApproved: (dir, namespace2) => [
43837
+ done(
43838
+ `${clip(dir, 20)} may now use the namespace ${clip(namespace2, 40)}.`
43839
+ ),
43840
+ p(
43841
+ "muted",
43842
+ " Agents already running there keep their namespace until they restart."
43843
+ )
43844
+ ],
43845
+ nsRevoked: (dir) => [
43846
+ done(`${clip(dir, 24)} is no longer approved.`),
43847
+ p(
43848
+ "muted",
43849
+ " Agents already running there keep their namespace until they restart."
43850
+ )
43851
+ ],
43852
+ nsNotListed: (dir) => warn(`${clip(dir, 36)} was not approved. Nothing changed.`),
43853
+ nsNone: () => [
43854
+ "No approved namespaces.",
43855
+ p("muted", `Approve one with ${BUS_CMD} namespace approve <dir>.`)
43856
+ ],
43857
+ nsList: (rows) => [
43858
+ `${rows.length} approved ${rows.length === 1 ? "namespace" : "namespaces"}`,
43859
+ ...rows.map((r) => ` ${clip(r.dir, 2)} ${p("muted", r.namespace)}`)
43860
+ ],
43625
43861
  // logs, mcp (DRAFT)
43626
43862
  noLog: (path) => [
43627
43863
  warn(`No daemon log yet at ${clip(path, 24)}`),
@@ -43640,24 +43876,24 @@ init_src2();
43640
43876
  import { execFile as execFile3, spawn } from "node:child_process";
43641
43877
  import { promisify } from "node:util";
43642
43878
  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) => {
43879
+ var openBrowser = (url2, launcher = browserCommand(process.platform, url2)) => new Promise((resolve9) => {
43644
43880
  try {
43645
43881
  const child = spawn(launcher.cmd, launcher.args, {
43646
43882
  stdio: "ignore",
43647
43883
  detached: true
43648
43884
  });
43649
- child.once("error", () => resolve8(false));
43885
+ child.once("error", () => resolve9(false));
43650
43886
  child.once("spawn", () => {
43651
43887
  child.unref();
43652
- resolve8(true);
43888
+ resolve9(true);
43653
43889
  });
43654
43890
  } catch {
43655
- resolve8(false);
43891
+ resolve9(false);
43656
43892
  }
43657
43893
  });
43658
43894
  var EXEC_TIMEOUT_MS = 1e4;
43659
- function guardServiceManager(cmd, args = [], env = process.env) {
43660
- if (!env.VITEST) return;
43895
+ function guardServiceManager(cmd, args = [], env2 = process.env) {
43896
+ if (!env2.VITEST) return;
43661
43897
  if ([cmd, ...args].some((a) => /\b(launchctl|systemctl)\b/.test(a)))
43662
43898
  throw new Error(`refusing to run ${cmd} under vitest: inject exec`);
43663
43899
  }
@@ -43693,22 +43929,22 @@ var realDeps = {
43693
43929
  // src/steps/service.ts
43694
43930
  import { createHash as createHash5 } from "node:crypto";
43695
43931
  import {
43696
- chmodSync as chmodSync8,
43932
+ chmodSync as chmodSync9,
43697
43933
  cpSync,
43698
43934
  existsSync as existsSync3,
43699
43935
  lstatSync as lstatSync8,
43700
- mkdirSync as mkdirSync7,
43936
+ mkdirSync as mkdirSync8,
43701
43937
  realpathSync as realpathSync7,
43702
- renameSync as renameSync7,
43938
+ renameSync as renameSync8,
43703
43939
  rmSync as rmSync4,
43704
43940
  writeFileSync as writeFileSync6
43705
43941
  } from "node:fs";
43706
- import { basename as basename6, dirname as dirname7, isAbsolute as isAbsolute6, join as join13, resolve as resolve4 } from "node:path";
43942
+ import { basename as basename6, dirname as dirname8, isAbsolute as isAbsolute7, join as join14, resolve as resolve4 } from "node:path";
43707
43943
  import { fileURLToPath } from "node:url";
43708
43944
 
43709
43945
  // src/steps/codex.ts
43710
43946
  import { lstatSync as lstatSync7, readFileSync as readFileSync11 } from "node:fs";
43711
- import { join as join12, resolve as resolve3 } from "node:path";
43947
+ import { join as join13, resolve as resolve3 } from "node:path";
43712
43948
 
43713
43949
  // ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/error.js
43714
43950
  function getLineColFromPtr(string4, ptr) {
@@ -44470,12 +44706,12 @@ var HAS_WELLFORMED = !!"".isWellFormed;
44470
44706
 
44471
44707
  // src/steps/codex.ts
44472
44708
  var CODEX_ENTRY = "oa_bus";
44473
- var codexHome2 = (home2, env) => env.CODEX_HOME ? resolve3(env.CODEX_HOME) : join12(home2, ".codex");
44474
- function codexHomeEnv(home2, env) {
44475
- const dir = codexHome2(home2, env);
44476
- return dir === join12(home2, ".codex") ? {} : { CODEX_HOME: dir };
44709
+ var codexHome2 = (home2, env2) => env2.CODEX_HOME ? resolve3(env2.CODEX_HOME) : join13(home2, ".codex");
44710
+ function codexHomeEnv(home2, env2) {
44711
+ const dir = codexHome2(home2, env2);
44712
+ return dir === join13(home2, ".codex") ? {} : { CODEX_HOME: dir };
44477
44713
  }
44478
- var codexConfig = (home2, env) => join12(codexHome2(home2, env), "config.toml");
44714
+ var codexConfig = (home2, env2) => join13(codexHome2(home2, env2), "config.toml");
44479
44715
  function hasCodex(o) {
44480
44716
  if (o.which("codex")) return true;
44481
44717
  try {
@@ -44509,7 +44745,7 @@ function codexEntry(busBin, home2, busHome2) {
44509
44745
  return {
44510
44746
  command: busBin[0],
44511
44747
  args: [...busBin.slice(1), "mcp", "codex"],
44512
- ...ob === join12(home2, ".oa-bus") ? {} : { env: { OA_BUS_HOME: ob } },
44748
+ ...ob === join13(home2, ".oa-bus") ? {} : { env: { OA_BUS_HOME: ob } },
44513
44749
  default_tools_approval_mode: "approve"
44514
44750
  };
44515
44751
  }
@@ -44535,7 +44771,7 @@ function sandboxRisk(doc, home2, codexDir) {
44535
44771
  });
44536
44772
  const covers = (root) => {
44537
44773
  const r = resolve3(
44538
- root === "~" ? home2 : root.startsWith("~/") ? join12(home2, root.slice(2)) : root
44774
+ root === "~" ? home2 : root.startsWith("~/") ? join13(home2, root.slice(2)) : root
44539
44775
  );
44540
44776
  return r === "/" || codexDir === r || codexDir.startsWith(`${r}/`) || r.startsWith(`${codexDir}/`);
44541
44777
  };
@@ -44544,12 +44780,12 @@ function sandboxRisk(doc, home2, codexDir) {
44544
44780
  var str2 = (s) => JSON.stringify(s);
44545
44781
  var key = (k) => /^[A-Za-z0-9_-]+$/.test(k) ? k : str2(k);
44546
44782
  function renderEntry(e) {
44547
- const env = Object.entries(e.env ?? {});
44783
+ const env2 = Object.entries(e.env ?? {});
44548
44784
  return [
44549
44785
  `[mcp_servers.${CODEX_ENTRY}]`,
44550
44786
  `command = ${str2(e.command)}`,
44551
44787
  `args = [${e.args.map(str2).join(", ")}]`,
44552
- ...env.length ? [`env = { ${env.map(([k, v]) => `${key(k)} = ${str2(v)}`).join(", ")} }`] : [],
44788
+ ...env2.length ? [`env = { ${env2.map(([k, v]) => `${key(k)} = ${str2(v)}`).join(", ")} }`] : [],
44553
44789
  `default_tools_approval_mode = ${str2(e.default_tools_approval_mode)}`
44554
44790
  ];
44555
44791
  }
@@ -44742,13 +44978,13 @@ function remove(path, text3, doc) {
44742
44978
 
44743
44979
  // src/steps/step.ts
44744
44980
  import {
44745
- chmodSync as chmodSync7,
44746
- mkdirSync as mkdirSync6,
44981
+ chmodSync as chmodSync8,
44982
+ mkdirSync as mkdirSync7,
44747
44983
  readFileSync as readFileSync12,
44748
- renameSync as renameSync6,
44984
+ renameSync as renameSync7,
44749
44985
  writeFileSync as writeFileSync5
44750
44986
  } from "node:fs";
44751
- import { dirname as dirname6 } from "node:path";
44987
+ import { dirname as dirname7 } from "node:path";
44752
44988
  function readInstallFile(path) {
44753
44989
  try {
44754
44990
  const v = JSON.parse(readFileSync12(path, "utf8"));
@@ -44760,12 +44996,12 @@ function readInstallFile(path) {
44760
44996
  }
44761
44997
  function updateInstallFile(path, patch) {
44762
44998
  const next = { ...readInstallFile(path), ...patch };
44763
- mkdirSync6(dirname6(path), { recursive: true, mode: 448 });
44999
+ mkdirSync7(dirname7(path), { recursive: true, mode: 448 });
44764
45000
  const tmp = `${path}.${process.pid}.tmp`;
44765
45001
  writeFileSync5(tmp, `${JSON.stringify(next, null, 2)}
44766
45002
  `, { mode: 384 });
44767
- chmodSync7(tmp, 384);
44768
- renameSync6(tmp, path);
45003
+ chmodSync8(tmp, 384);
45004
+ renameSync7(tmp, path);
44769
45005
  }
44770
45006
  async function runSteps(steps, ctx, record6) {
44771
45007
  for (const step2 of steps) {
@@ -44811,7 +45047,7 @@ var oneLine = (v) => {
44811
45047
  var xml = (v) => oneLine(v).replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&apos;");
44812
45048
  function renderPlist(u, label = LAUNCHD_LABEL) {
44813
45049
  const str3 = (v) => `<string>${xml(v)}</string>`;
44814
- const env = Object.entries(u.env).map(([k, v]) => `<key>${xml(k)}</key>${str3(v)}`).join("");
45050
+ const env2 = Object.entries(u.env).map(([k, v]) => `<key>${xml(k)}</key>${str3(v)}`).join("");
44815
45051
  return `<?xml version="1.0" encoding="UTF-8"?>
44816
45052
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
44817
45053
  <plist version="1.0">
@@ -44825,7 +45061,7 @@ function renderPlist(u, label = LAUNCHD_LABEL) {
44825
45061
  <key>StandardOutPath</key>${str3(u.out)}
44826
45062
  <key>StandardErrorPath</key>${str3(u.err)}
44827
45063
  <key>EnvironmentVariables</key>
44828
- <dict>${env}</dict>
45064
+ <dict>${env2}</dict>
44829
45065
  </dict>
44830
45066
  </plist>
44831
45067
  `;
@@ -44834,7 +45070,7 @@ var specifiers = (v) => oneLine(v).replaceAll("%", "%%");
44834
45070
  var quoted2 = (v) => `"${specifiers(v).replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`;
44835
45071
  var execWord = (v) => quoted2(v.replaceAll("$", "$$$$"));
44836
45072
  function renderSystemd(u) {
44837
- const env = Object.entries(u.env).map(([k, v]) => `Environment=${quoted2(`${k}=${v}`)}
45073
+ const env2 = Object.entries(u.env).map(([k, v]) => `Environment=${quoted2(`${k}=${v}`)}
44838
45074
  `).join("");
44839
45075
  return `[Unit]
44840
45076
  Description=Open Artifacts bus daemon
@@ -44846,7 +45082,7 @@ ExecStart=${execWord(u.node)} ${execWord(u.entry)} daemon
44846
45082
  Restart=on-failure
44847
45083
  RestartSec=10
44848
45084
  RestartPreventExitStatus=${REVOKED_EXIT}
44849
- ${env}StandardOutput=append:${specifiers(u.out)}
45085
+ ${env2}StandardOutput=append:${specifiers(u.out)}
44850
45086
  StandardError=append:${specifiers(u.err)}
44851
45087
 
44852
45088
  [Install]
@@ -44861,7 +45097,7 @@ function cliSource() {
44861
45097
  jiti: import.meta.resolve("jiti")
44862
45098
  } : { kind: "bundle", file: here };
44863
45099
  }
44864
- var entryName = (src) => src.kind === "bundle" ? join13(basename6(dirname7(src.file)), basename6(src.file)) : "oa-bus.js";
45100
+ var entryName = (src) => src.kind === "bundle" ? join14(basename6(dirname8(src.file)), basename6(src.file)) : "oa-bus.js";
44865
45101
  var shim = (src) => `// Written by oa-bus install: runs the sources it was installed from.
44866
45102
  import { createJiti } from ${JSON.stringify(src.jiti)};
44867
45103
 
@@ -44871,24 +45107,24 @@ const code = await main(process.argv.slice(2));
44871
45107
  if (code !== undefined) process.exit(code);
44872
45108
  `;
44873
45109
  function installCli(home2, src) {
44874
- const bin = join13(home2, "bin");
45110
+ const bin = join14(home2, "bin");
44875
45111
  const tmp = `${bin}.${process.pid}.tmp`;
44876
- mkdirSync7(home2, { recursive: true, mode: 448 });
44877
- chmodSync8(home2, 448);
45112
+ mkdirSync8(home2, { recursive: true, mode: 448 });
45113
+ chmodSync9(home2, 448);
44878
45114
  rmSync4(tmp, { recursive: true, force: true });
44879
- mkdirSync7(tmp);
45115
+ mkdirSync8(tmp);
44880
45116
  if (src.kind === "bundle") {
44881
- const pkg = dirname7(dirname7(src.file));
45117
+ const pkg = dirname8(dirname8(src.file));
44882
45118
  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');
45119
+ if (existsSync3(join14(pkg, name)))
45120
+ cpSync(join14(pkg, name), join14(tmp, name), { recursive: true });
45121
+ } else writeFileSync6(join14(tmp, entryName(src)), shim(src));
45122
+ chmodSync9(tmp, 448);
45123
+ if (!existsSync3(join14(tmp, "package.json")))
45124
+ writeFileSync6(join14(tmp, "package.json"), '{ "type": "module" }\n');
44889
45125
  rmSync4(bin, { recursive: true, force: true });
44890
- renameSync7(tmp, bin);
44891
- return join13(bin, entryName(src));
45126
+ renameSync8(tmp, bin);
45127
+ return join14(bin, entryName(src));
44892
45128
  }
44893
45129
  var present = (path) => {
44894
45130
  try {
@@ -44899,11 +45135,11 @@ var present = (path) => {
44899
45135
  }
44900
45136
  };
44901
45137
  function writeReplacing(path, text3) {
44902
- mkdirSync7(dirname7(path), { recursive: true });
45138
+ mkdirSync8(dirname8(path), { recursive: true });
44903
45139
  const tmp = `${path}.${process.pid}.tmp`;
44904
45140
  try {
44905
45141
  writeFileSync6(tmp, text3, { mode: 420 });
44906
- renameSync7(tmp, path);
45142
+ renameSync8(tmp, path);
44907
45143
  } catch (e) {
44908
45144
  rmSync4(tmp, { force: true });
44909
45145
  throw e;
@@ -44914,11 +45150,11 @@ var real = (path) => {
44914
45150
  try {
44915
45151
  return realpathSync7(abs);
44916
45152
  } catch {
44917
- const parent = dirname7(abs);
44918
- return parent === abs ? abs : join13(real(parent), basename6(abs));
45153
+ const parent = dirname8(abs);
45154
+ return parent === abs ? abs : join14(real(parent), basename6(abs));
44919
45155
  }
44920
45156
  };
44921
- var isDefaultHome = (home2, userHome) => real(home2) === real(join13(userHome, ".oa-bus"));
45157
+ var isDefaultHome = (home2, userHome) => real(home2) === real(join14(userHome, ".oa-bus"));
44922
45158
  function serviceNames(home2, userHome) {
44923
45159
  const suffix = isDefaultHome(home2, userHome) ? "" : createHash5("sha256").update(real(home2)).digest("hex").slice(0, 8);
44924
45160
  return {
@@ -44945,19 +45181,19 @@ function systemService(d) {
44945
45181
  const manager = d.platform === "darwin" ? "launchd" : d.platform === "linux" ? "systemd" : void 0;
44946
45182
  const home2 = () => resolve4(d.home());
44947
45183
  const names2 = () => serviceNames(home2(), d.userHome);
44948
- const entryOf = () => join13(home2(), "bin", entryName(d.source()));
44949
- const installFile = () => join13(home2(), "install.json");
45184
+ const entryOf = () => join14(home2(), "bin", entryName(d.source()));
45185
+ const installFile = () => join14(home2(), "install.json");
44950
45186
  const record6 = () => {
44951
45187
  const r = readInstallFile(installFile()).service;
44952
45188
  return typeof r === "object" && r !== null ? r : {};
44953
45189
  };
44954
45190
  const xdg = d.env.XDG_CONFIG_HOME;
44955
- const configHome = xdg && isAbsolute6(xdg) ? xdg : join13(d.userHome, ".config");
45191
+ const configHome = xdg && isAbsolute7(xdg) ? xdg : join14(d.userHome, ".config");
44956
45192
  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());
45193
+ const fresh = () => manager === "launchd" ? join14(d.userHome, "Library/LaunchAgents", fileName()) : join14(configHome, "systemd/user", fileName());
44958
45194
  const recorded = () => {
44959
45195
  const r = record6().unit;
44960
- return typeof r === "string" && isAbsolute6(r) && basename6(r) === fileName() ? r : void 0;
45196
+ return typeof r === "string" && isAbsolute7(r) && basename6(r) === fileName() ? r : void 0;
44961
45197
  };
44962
45198
  const file2 = () => {
44963
45199
  const r = recorded();
@@ -45019,10 +45255,10 @@ function systemService(d) {
45019
45255
  async ensure() {
45020
45256
  const h = home2();
45021
45257
  const src = d.source();
45022
- const logs2 = join13(h, "logs");
45258
+ const logs2 = join14(h, "logs");
45023
45259
  const u = {
45024
45260
  node: d.execPath,
45025
- entry: join13(h, "bin", entryName(src)),
45261
+ entry: join14(h, "bin", entryName(src)),
45026
45262
  env: {
45027
45263
  PATH: d.env.PATH ?? DEFAULT_PATH,
45028
45264
  ...isDefaultHome(h, d.userHome) ? {} : { OA_BUS_HOME: h },
@@ -45030,8 +45266,8 @@ function systemService(d) {
45030
45266
  ...codexHomeEnv(d.userHome, d.env)
45031
45267
  },
45032
45268
  // 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")
45269
+ out: join14(logs2, "daemon.log"),
45270
+ err: join14(logs2, "daemon.log")
45035
45271
  };
45036
45272
  const unit = { ...u, env: { ...u.env, OA_BUS_SERVICE: "1" } };
45037
45273
  renderPlist(unit);
@@ -45042,7 +45278,7 @@ function systemService(d) {
45042
45278
  const left = await stopDaemon();
45043
45279
  if (left !== void 0) return { running: left };
45044
45280
  installCli(h, src);
45045
- mkdirSync7(logs2, { recursive: true, mode: 448 });
45281
+ mkdirSync8(logs2, { recursive: true, mode: 448 });
45046
45282
  const f = fresh();
45047
45283
  const old = recorded();
45048
45284
  if (old && old !== f) {
@@ -45132,7 +45368,7 @@ function systemService(d) {
45132
45368
  const node2 = record6().node;
45133
45369
  if (typeof node2 === "string" && !existsSync3(node2))
45134
45370
  out.push({ kind: "node-missing", node: node2 });
45135
- if (manager === "systemd" && !existsSync3(join13(d.lingerDir ?? "/var/lib/systemd/linger", d.user)))
45371
+ if (manager === "systemd" && !existsSync3(join14(d.lingerDir ?? "/var/lib/systemd/linger", d.user)))
45136
45372
  out.push({ kind: "linger-off" });
45137
45373
  return out;
45138
45374
  }
@@ -45145,7 +45381,7 @@ var noService = {
45145
45381
  remove: async () => ({}),
45146
45382
  cli: () => ["oa-bus"]
45147
45383
  };
45148
- var VERSION = true ? "0.126.0" : JSON.parse(
45384
+ var VERSION = true ? "0.128.0" : JSON.parse(
45149
45385
  readFileSync13(new URL("../package.json", import.meta.url), "utf8")
45150
45386
  ).version;
45151
45387
  var which = (cmd) => {
@@ -45174,8 +45410,8 @@ function processArgs2(pid, io = {
45174
45410
  }
45175
45411
  }
45176
45412
  var spawnDaemon = (cmd, args, opts) => {
45177
- const out = openSync4(opts.out, "a", 384);
45178
- const err = openSync4(opts.err, "a", 384);
45413
+ const out = openSync5(opts.out, "a", 384);
45414
+ const err = openSync5(opts.err, "a", 384);
45179
45415
  try {
45180
45416
  const child = spawn2(cmd, args, {
45181
45417
  detached: true,
@@ -45185,8 +45421,8 @@ var spawnDaemon = (cmd, args, opts) => {
45185
45421
  child.unref();
45186
45422
  return child.pid;
45187
45423
  } finally {
45188
- closeSync4(out);
45189
- closeSync4(err);
45424
+ closeSync5(out);
45425
+ closeSync5(err);
45190
45426
  }
45191
45427
  };
45192
45428
  var userName = () => {
@@ -45197,19 +45433,19 @@ var userName = () => {
45197
45433
  }
45198
45434
  };
45199
45435
  function realCtx(noColor) {
45200
- const env = process.env;
45201
- const style = detectStyle(env, process.stdout, noColor);
45436
+ const env2 = process.env;
45437
+ const style = detectStyle(env2, process.stdout, noColor);
45202
45438
  const ctx = {
45203
45439
  ...realDeps,
45204
45440
  print: (line) => process.stdout.write(`${line}
45205
45441
  `),
45206
45442
  stdout: process.stdout,
45207
45443
  stderr: process.stderr,
45208
- env,
45444
+ env: env2,
45209
45445
  cwd: process.cwd(),
45210
45446
  userHome: homedir3(),
45211
45447
  // Absolute: the plist and unit must never carry a relative path.
45212
- home: busHome(env),
45448
+ home: busHome(env2),
45213
45449
  which,
45214
45450
  service: noService,
45215
45451
  status: daemonStatus,
@@ -45218,13 +45454,27 @@ function realCtx(noColor) {
45218
45454
  copy: copy(style),
45219
45455
  platform: `${process.platform} ${process.arch}`,
45220
45456
  nodeVersion: process.version,
45221
- ...process.platform === "darwin" ? { codexApp: CODEX_APP } : {}
45457
+ ...process.platform === "darwin" ? { codexApp: CODEX_APP } : {},
45458
+ stdinIsTTY: Boolean(process.stdin.isTTY),
45459
+ readLine: async (question) => {
45460
+ const rl = createInterface2({
45461
+ input: process.stdin,
45462
+ output: process.stdout
45463
+ });
45464
+ try {
45465
+ return await new Promise(
45466
+ (resolve9) => rl.question(question, resolve9)
45467
+ );
45468
+ } finally {
45469
+ rl.close();
45470
+ }
45471
+ }
45222
45472
  };
45223
45473
  ctx.service = systemService({
45224
45474
  platform: process.platform,
45225
45475
  userHome: ctx.userHome,
45226
45476
  home: () => ctx.home,
45227
- env,
45477
+ env: env2,
45228
45478
  exec: ctx.exec,
45229
45479
  sleep: ctx.sleep,
45230
45480
  execPath: process.execPath,
@@ -45300,10 +45550,10 @@ var configFileLines = (ctx, files) => files.flatMap(
45300
45550
 
45301
45551
  // src/machine.ts
45302
45552
  import { readFileSync as readFileSync14, statSync as statSync8 } from "node:fs";
45303
- import { join as join14 } from "node:path";
45553
+ import { join as join15 } from "node:path";
45304
45554
  init_src();
45305
45555
  function readMachine(home2) {
45306
- const file2 = join14(home2, "machine.json");
45556
+ const file2 = join15(home2, "machine.json");
45307
45557
  let text3;
45308
45558
  let mode;
45309
45559
  try {
@@ -45334,11 +45584,11 @@ var lasting = (e) => [...START_ERROR_CODES, "EACCES", "EPERM"].includes(
45334
45584
  );
45335
45585
  async function daemon(ctx, run4 = runDaemon, signals = process) {
45336
45586
  const m = readMachine(ctx.home);
45337
- if (existsSync4(join15(ctx.home, "revoked")) && (m.state !== "ok" || m.revoked)) {
45587
+ if (existsSync4(join16(ctx.home, "revoked")) && (m.state !== "ok" || m.revoked)) {
45338
45588
  sayErr(ctx, ctx.copy.revoked());
45339
45589
  return 0;
45340
45590
  }
45341
- return new Promise((resolve8) => {
45591
+ return new Promise((resolve9) => {
45342
45592
  let running;
45343
45593
  let ended = false;
45344
45594
  const end = (code2) => {
@@ -45346,7 +45596,7 @@ async function daemon(ctx, run4 = runDaemon, signals = process) {
45346
45596
  ended = true;
45347
45597
  signals.off("SIGINT", onSignal);
45348
45598
  signals.off("SIGTERM", onSignal);
45349
- void (running?.stop() ?? Promise.resolve()).finally(() => resolve8(code2));
45599
+ void (running?.stop() ?? Promise.resolve()).finally(() => resolve9(code2));
45350
45600
  };
45351
45601
  const onSignal = () => end(0);
45352
45602
  signals.once("SIGINT", onSignal);
@@ -45375,8 +45625,8 @@ async function daemon(ctx, run4 = runDaemon, signals = process) {
45375
45625
  }
45376
45626
 
45377
45627
  // src/commands/doctor.ts
45378
- import { readFileSync as readFileSync16 } from "node:fs";
45379
- import { join as join19 } from "node:path";
45628
+ import { readFileSync as readFileSync17 } from "node:fs";
45629
+ import { join as join21 } from "node:path";
45380
45630
 
45381
45631
  // ../bus-adapter-opencode/src/index.ts
45382
45632
  init_session2();
@@ -45387,20 +45637,20 @@ var OPENCODE_TUI_PLUGIN = fileURLToPath2(
45387
45637
  );
45388
45638
 
45389
45639
  // src/steps/adapters.ts
45390
- import { randomBytes as randomBytes2 } from "node:crypto";
45640
+ import { randomBytes as randomBytes3 } from "node:crypto";
45391
45641
  import {
45392
- chmodSync as chmodSync9,
45642
+ chmodSync as chmodSync10,
45393
45643
  existsSync as existsSync5,
45394
45644
  lstatSync as lstatSync9,
45395
- mkdirSync as mkdirSync8,
45645
+ mkdirSync as mkdirSync9,
45396
45646
  readFileSync as readFileSync15,
45397
45647
  readlinkSync,
45398
- renameSync as renameSync8,
45648
+ renameSync as renameSync9,
45399
45649
  rmSync as rmSync5,
45400
45650
  statSync as statSync9,
45401
45651
  writeFileSync as writeFileSync7
45402
45652
  } from "node:fs";
45403
- import { dirname as dirname8, join as join16, resolve as resolve5 } from "node:path";
45653
+ import { dirname as dirname9, join as join17, resolve as resolve5 } from "node:path";
45404
45654
  import { isDeepStrictEqual } from "node:util";
45405
45655
 
45406
45656
  // ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/scanner.js
@@ -46632,59 +46882,59 @@ var readAssets = () => ({
46632
46882
  var movedHome = (deps) => {
46633
46883
  if (deps.busHome === void 0) return void 0;
46634
46884
  const ob = resolve5(deps.busHome);
46635
- return ob === join16(deps.home, ".oa-bus") ? void 0 : ob;
46885
+ return ob === join17(deps.home, ".oa-bus") ? void 0 : ob;
46636
46886
  };
46637
46887
  var homeLine = (ob) => `process.env.OA_BUS_HOME ||= ${JSON.stringify(ob)};`;
46638
46888
  var withHome = (text3, ob) => ob === void 0 ? text3 : `${homeLine(ob)}
46639
46889
  ${text3}`;
46640
46890
  var paths = (deps) => {
46641
- const env = deps.env ?? {};
46642
- const opencode = env.OPENCODE_CONFIG_DIR ?? join16(env.XDG_CONFIG_HOME ?? join16(deps.home, ".config"), "opencode");
46643
- const busDir = deps.busHome ?? join16(deps.home, ".oa-bus");
46891
+ const env2 = deps.env ?? {};
46892
+ const opencode = env2.OPENCODE_CONFIG_DIR ?? join17(env2.XDG_CONFIG_HOME ?? join17(deps.home, ".config"), "opencode");
46893
+ const busDir = deps.busHome ?? join17(deps.home, ".oa-bus");
46644
46894
  return {
46645
- claude: join16(env.CLAUDE_CONFIG_DIR ?? deps.home, ".claude.json"),
46895
+ claude: join17(env2.CLAUDE_CONFIG_DIR ?? deps.home, ".claude.json"),
46646
46896
  // OpenCode reads both; edit the one the user has, else create .json.
46647
46897
  opencodeConfigs: [
46648
- join16(opencode, "opencode.json"),
46649
- join16(opencode, "opencode.jsonc")
46898
+ join17(opencode, "opencode.json"),
46899
+ join17(opencode, "opencode.jsonc")
46650
46900
  ],
46651
- opencodeCli: join16(opencode, "cli.json"),
46652
- record: join16(busDir, "install.json"),
46901
+ opencodeCli: join17(opencode, "cli.json"),
46902
+ record: join17(busDir, "install.json"),
46653
46903
  // OpenCode registers the folder that holds tui.js.
46654
- opencodePlugin: join16(busDir, "integrations/opencode", NAME),
46655
- pi: join16(
46656
- agentDirEnv(deps.home, env) ?? join16(deps.home, ".pi/agent"),
46904
+ opencodePlugin: join17(busDir, "integrations/opencode", NAME),
46905
+ pi: join17(
46906
+ agentDirEnv(deps.home, env2) ?? join17(deps.home, ".pi/agent"),
46657
46907
  "extensions/oa-bus.ts"
46658
46908
  ),
46659
- omp: join16(ompAgentDir(deps.home, env), "extensions/oa-bus.ts"),
46660
- codex: codexConfig(deps.home, env),
46909
+ omp: join17(ompAgentDir(deps.home, env2), "extensions/oa-bus.ts"),
46910
+ codex: codexConfig(deps.home, env2),
46661
46911
  codexBin: codexBinFile(busDir),
46662
46912
  busDir
46663
46913
  };
46664
46914
  };
46665
- function agentDirEnv(home2, env) {
46666
- const dir = env.PI_CODING_AGENT_DIR;
46915
+ function agentDirEnv(home2, env2) {
46916
+ const dir = env2.PI_CODING_AGENT_DIR;
46667
46917
  if (!dir) return void 0;
46668
46918
  if (dir === "~") return home2;
46669
- return resolve5(dir.startsWith("~/") ? join16(home2, dir.slice(2)) : dir);
46919
+ return resolve5(dir.startsWith("~/") ? join17(home2, dir.slice(2)) : dir);
46670
46920
  }
46671
- var ompRoot = (home2, env) => join16(home2, env.PI_CONFIG_DIR || ".omp");
46672
- function ompProfile(env) {
46673
- const name = (env.OMP_PROFILE !== void 0 ? env.OMP_PROFILE : env.PI_PROFILE)?.trim();
46921
+ var ompRoot = (home2, env2) => join17(home2, env2.PI_CONFIG_DIR || ".omp");
46922
+ function ompProfile(env2) {
46923
+ const name = (env2.OMP_PROFILE !== void 0 ? env2.OMP_PROFILE : env2.PI_PROFILE)?.trim();
46674
46924
  if (!name || name === "default" || name.endsWith(".")) return void 0;
46675
46925
  return /^[a-z0-9][a-z0-9._-]{0,63}$/.test(name) ? name : void 0;
46676
46926
  }
46677
- function ompAgentDir(home2, env) {
46678
- const root = ompRoot(home2, env);
46679
- const profile = ompProfile(env);
46680
- if (profile) return join16(root, "profiles", profile, "agent");
46681
- const piProfile = ompProfile({ PI_PROFILE: env.PI_PROFILE });
46682
- const dir = agentDirEnv(home2, env);
46683
- if (dir && !(piProfile && dir === join16(root, "profiles", piProfile, "agent")))
46927
+ function ompAgentDir(home2, env2) {
46928
+ const root = ompRoot(home2, env2);
46929
+ const profile = ompProfile(env2);
46930
+ if (profile) return join17(root, "profiles", profile, "agent");
46931
+ const piProfile = ompProfile({ PI_PROFILE: env2.PI_PROFILE });
46932
+ const dir = agentDirEnv(home2, env2);
46933
+ if (dir && !(piProfile && dir === join17(root, "profiles", piProfile, "agent")))
46684
46934
  return dir;
46685
- return join16(root, "agent");
46935
+ return join17(root, "agent");
46686
46936
  }
46687
- var hasOmp = (deps) => deps.which("omp") || present2(ompRoot(deps.home, deps.env ?? {})) || present2(join16(deps.home, ".bun/bin/omp"));
46937
+ var hasOmp = (deps) => deps.which("omp") || present2(ompRoot(deps.home, deps.env ?? {})) || present2(join17(deps.home, ".bun/bin/omp"));
46688
46938
  var sharedFile = (deps) => paths(deps).omp === paths(deps).pi;
46689
46939
  function readDoc(path) {
46690
46940
  let text3;
@@ -46714,30 +46964,30 @@ function target(path) {
46714
46964
  let p = path;
46715
46965
  for (let hops = 0; hops < 40; hops++) {
46716
46966
  if (!present2(p) || !lstatSync9(p).isSymbolicLink()) {
46717
- if (p !== path && !existsSync5(dirname8(p)))
46967
+ if (p !== path && !existsSync5(dirname9(p)))
46718
46968
  throw new Error(
46719
46969
  `${path} is a dangling symlink to ${p}; left it untouched`
46720
46970
  );
46721
46971
  return p;
46722
46972
  }
46723
- p = resolve5(dirname8(p), readlinkSync(p));
46973
+ p = resolve5(dirname9(p), readlinkSync(p));
46724
46974
  }
46725
46975
  throw new Error(`${path}: too many symlinks; left it untouched`);
46726
46976
  }
46727
46977
  function writeAtomic(path, data, mode) {
46728
46978
  const dest = target(path);
46729
- mkdirSync8(dirname8(dest), { recursive: true });
46979
+ mkdirSync9(dirname9(dest), { recursive: true });
46730
46980
  let m = mode ?? 420;
46731
46981
  if (mode === void 0)
46732
46982
  try {
46733
46983
  m = statSync9(dest).mode & 511;
46734
46984
  } catch {
46735
46985
  }
46736
- const tmp = `${dest}.${process.pid}.${randomBytes2(4).toString("hex")}.tmp`;
46986
+ const tmp = `${dest}.${process.pid}.${randomBytes3(4).toString("hex")}.tmp`;
46737
46987
  try {
46738
46988
  writeFileSync7(tmp, data, { mode: m, flag: "wx" });
46739
- chmodSync9(tmp, m);
46740
- renameSync8(tmp, dest);
46989
+ chmodSync10(tmp, m);
46990
+ renameSync9(tmp, dest);
46741
46991
  } catch (e) {
46742
46992
  rmSync5(tmp, { force: true });
46743
46993
  throw e;
@@ -46892,7 +47142,7 @@ var install = {
46892
47142
  created[p.opencodeCli] = add(p.opencodeCli, madeCli);
46893
47143
  writeRecord(p.record, record6, created);
46894
47144
  writeAtomic(
46895
- join16(p.opencodePlugin, "tui.js"),
47145
+ join17(p.opencodePlugin, "tui.js"),
46896
47146
  withHome(deps.assets.opencodePlugin, movedHome(deps)),
46897
47147
  420
46898
47148
  );
@@ -47086,7 +47336,7 @@ function checkAdapters(deps) {
47086
47336
  return false;
47087
47337
  }
47088
47338
  };
47089
- const homeOf = (env) => typeof env === "object" && env !== null ? env.OA_BUS_HOME : void 0;
47339
+ const homeOf = (env2) => typeof env2 === "object" && env2 !== null ? env2.OA_BUS_HOME : void 0;
47090
47340
  const homed = (file2) => {
47091
47341
  if (!existsSync5(file2)) return false;
47092
47342
  const first = readFileSync15(file2, "utf8").split("\n", 1)[0] ?? "";
@@ -47108,7 +47358,7 @@ function checkAdapters(deps) {
47108
47358
  }) && listed(
47109
47359
  parseJsonc(readFileSync15(p.opencodeCli, "utf8"), p.opencodeCli),
47110
47360
  p.opencodePlugin
47111
- ) && homed(join16(p.opencodePlugin, "tui.js"))
47361
+ ) && homed(join17(p.opencodePlugin, "tui.js"))
47112
47362
  ),
47113
47363
  pi: state("pi", () => homed(p.pi)),
47114
47364
  omp: state("omp", () => homed(p.omp)),
@@ -47130,18 +47380,18 @@ function checkAdapters(deps) {
47130
47380
 
47131
47381
  // src/commands/login.ts
47132
47382
  init_src();
47133
- import { randomBytes as randomBytes3 } from "node:crypto";
47383
+ import { randomBytes as randomBytes4 } from "node:crypto";
47134
47384
  import {
47135
- chmodSync as chmodSync10,
47136
- closeSync as closeSync5,
47137
- mkdirSync as mkdirSync9,
47138
- openSync as openSync5,
47139
- renameSync as renameSync9,
47385
+ chmodSync as chmodSync11,
47386
+ closeSync as closeSync6,
47387
+ mkdirSync as mkdirSync10,
47388
+ openSync as openSync6,
47389
+ renameSync as renameSync10,
47140
47390
  rmSync as rmSync6,
47141
- unlinkSync as unlinkSync2,
47142
- writeSync as writeSync2
47391
+ unlinkSync as unlinkSync3,
47392
+ writeSync as writeSync3
47143
47393
  } from "node:fs";
47144
- import { join as join17 } from "node:path";
47394
+ import { join as join18 } from "node:path";
47145
47395
 
47146
47396
  // src/machine-label.ts
47147
47397
  import { hostname as osHostname } from "node:os";
@@ -47187,23 +47437,23 @@ function checkVerificationUri(uri, hub) {
47187
47437
  return uri;
47188
47438
  }
47189
47439
  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);
47440
+ mkdirSync10(home2, { recursive: true, mode: 448 });
47441
+ chmodSync11(home2, 448);
47442
+ const tmp = join18(home2, `.machine.json.${randomBytes4(8).toString("hex")}.tmp`);
47443
+ const fd = openSync6(tmp, "wx", 384);
47194
47444
  try {
47195
- writeSync2(fd, body);
47445
+ writeSync3(fd, body);
47196
47446
  } catch (e) {
47197
- closeSync5(fd);
47198
- unlinkSync2(tmp);
47447
+ closeSync6(fd);
47448
+ unlinkSync3(tmp);
47199
47449
  throw e;
47200
47450
  }
47201
- closeSync5(fd);
47451
+ closeSync6(fd);
47202
47452
  try {
47203
- chmodSync10(tmp, 384);
47204
- renameSync9(tmp, join17(home2, "machine.json"));
47453
+ chmodSync11(tmp, 384);
47454
+ renameSync10(tmp, join18(home2, "machine.json"));
47205
47455
  } catch (e) {
47206
- unlinkSync2(tmp);
47456
+ unlinkSync3(tmp);
47207
47457
  throw e;
47208
47458
  }
47209
47459
  }
@@ -47328,7 +47578,7 @@ async function login(args) {
47328
47578
  `${JSON.stringify({ hub, label, machine_token: poll.machine_token }, null, 2)}
47329
47579
  `
47330
47580
  );
47331
- rmSync6(join17(args.home, "revoked"), { force: true });
47581
+ rmSync6(join18(args.home, "revoked"), { force: true });
47332
47582
  if (!events?.code) print(`Approved this machine as ${label}.`);
47333
47583
  return {
47334
47584
  machineToken: poll.machine_token,
@@ -47352,7 +47602,7 @@ init_src();
47352
47602
 
47353
47603
  // src/commands/install.ts
47354
47604
  init_src3();
47355
- import { join as join18 } from "node:path";
47605
+ import { join as join20 } from "node:path";
47356
47606
  init_src2();
47357
47607
 
47358
47608
  // src/live.ts
@@ -47401,6 +47651,297 @@ function spinner(ctx) {
47401
47651
  };
47402
47652
  }
47403
47653
 
47654
+ // src/steps/skill.ts
47655
+ import {
47656
+ existsSync as existsSync6,
47657
+ lstatSync as lstatSync10,
47658
+ mkdirSync as mkdirSync11,
47659
+ readdirSync as readdirSync4,
47660
+ readFileSync as readFileSync16,
47661
+ realpathSync as realpathSync8,
47662
+ renameSync as renameSync11,
47663
+ rmdirSync,
47664
+ rmSync as rmSync7,
47665
+ writeFileSync as writeFileSync8
47666
+ } from "node:fs";
47667
+ import { dirname as dirname10, join as join19 } from "node:path";
47668
+ var SKILL_MARKER = "<!-- managed by the Open Artifacts bus installer: edits are replaced on reinstall. -->";
47669
+ var CODEX_BEGIN = "<!-- BEGIN Open Artifacts skill (managed): edits inside are replaced on reinstall. -->";
47670
+ var CODEX_END = "<!-- END Open Artifacts skill -->";
47671
+ var MAX_SKILL_BYTES = 256 * 1024;
47672
+ var env = (deps) => deps.env ?? {};
47673
+ var skillDir = (deps, h) => {
47674
+ const e = env(deps);
47675
+ const opencode = e.OPENCODE_CONFIG_DIR ?? join19(e.XDG_CONFIG_HOME ?? join19(deps.home, ".config"), "opencode");
47676
+ const agents = join19(deps.home, ".agents", "skills");
47677
+ return {
47678
+ claude: join19(e.CLAUDE_CONFIG_DIR ?? join19(deps.home, ".claude"), "skills"),
47679
+ opencode: join19(opencode, "skills"),
47680
+ pi: agents,
47681
+ omp: agents,
47682
+ codex: join19(codexHome2(deps.home, e), "AGENTS.md")
47683
+ }[h];
47684
+ };
47685
+ var skillFolder = (text3) => {
47686
+ const m = /^---\n([\s\S]*?)\n---\n/.exec(text3);
47687
+ const name = m?.[1] ? /^name:\s*"?([^"\n]+)"?\s*$/m.exec(m[1])?.[1] : void 0;
47688
+ return name && /^[a-z0-9][a-z0-9-]{0,62}$/.test(name) ? name : void 0;
47689
+ };
47690
+ var withMarker = (text3) => {
47691
+ const end = text3.startsWith("---\n") ? text3.indexOf("\n---\n", 3) : -1;
47692
+ if (end === -1) return `${text3.trimEnd()}
47693
+
47694
+ ${SKILL_MARKER}
47695
+ `;
47696
+ const at = end + "\n---\n".length;
47697
+ return `${text3.slice(0, at)}${SKILL_MARKER}
47698
+ ${text3.slice(at)}`;
47699
+ };
47700
+ var isOurs = (text3, folder) => {
47701
+ const t = text3.replace(/\r\n/g, "\n");
47702
+ const m = /^---\n[\s\S]*?\n---\n/.exec(t);
47703
+ if (!m) return false;
47704
+ const name = skillFolder(t);
47705
+ return name === folder && name.startsWith("open-artifacts") && t.slice(m[0].length).split("\n", 1)[0] === SKILL_MARKER;
47706
+ };
47707
+ var lineIndex = (lines, marker, from = 0) => {
47708
+ for (let i = from; i < lines.length; i++)
47709
+ if (lines[i]?.replace(/\r$/, "") === marker) return i;
47710
+ return -1;
47711
+ };
47712
+ var quotesMarker = (text3) => {
47713
+ const lines = text3.split("\n");
47714
+ return [SKILL_MARKER, CODEX_BEGIN, CODEX_END].some(
47715
+ (m) => lineIndex(lines, m) !== -1
47716
+ );
47717
+ };
47718
+ var lstatOk = (path) => {
47719
+ try {
47720
+ lstatSync10(path);
47721
+ return true;
47722
+ } catch {
47723
+ return false;
47724
+ }
47725
+ };
47726
+ var brokenLink = (path) => {
47727
+ try {
47728
+ return lstatSync10(path).isSymbolicLink() && !existsSync6(path);
47729
+ } catch {
47730
+ return false;
47731
+ }
47732
+ };
47733
+ async function fetchSkillText(doFetch, url2) {
47734
+ const r = await doFetch(url2, {
47735
+ headers: { accept: "text/markdown" },
47736
+ redirect: "error"
47737
+ });
47738
+ if (!r.ok) throw new Error(`${r.status} ${r.statusText}`);
47739
+ const type = r.headers.get("content-type") ?? "";
47740
+ if (!type.toLowerCase().startsWith("text/markdown"))
47741
+ throw new Error(`unexpected content-type: ${type || "none"}`);
47742
+ const declared = Number(r.headers.get("content-length"));
47743
+ if (Number.isFinite(declared) && declared > MAX_SKILL_BYTES) {
47744
+ await r.body?.cancel().catch(() => {
47745
+ });
47746
+ throw new Error("skill too large");
47747
+ }
47748
+ const chunks = [];
47749
+ let total = 0;
47750
+ const reader = r.body?.getReader();
47751
+ if (reader) {
47752
+ for (; ; ) {
47753
+ const { done, value } = await reader.read();
47754
+ if (done) break;
47755
+ total += value.byteLength;
47756
+ if (total > MAX_SKILL_BYTES) {
47757
+ await reader.cancel().catch(() => {
47758
+ });
47759
+ throw new Error("skill too large");
47760
+ }
47761
+ chunks.push(value);
47762
+ }
47763
+ }
47764
+ const text3 = new TextDecoder().decode(Buffer.concat(chunks));
47765
+ if (!text3.startsWith("---\nname: "))
47766
+ throw new Error("not a skill: no frontmatter");
47767
+ return text3;
47768
+ }
47769
+ var targetOf = (path) => {
47770
+ try {
47771
+ return lstatSync10(path).isSymbolicLink() ? realpathSync8(path) : path;
47772
+ } catch {
47773
+ return path;
47774
+ }
47775
+ };
47776
+ var seq = 0;
47777
+ var writeAtomic2 = (path, text3) => {
47778
+ mkdirSync11(dirname10(path), { recursive: true });
47779
+ const tmp = `${path}.oa-${process.pid}-${seq++}.tmp`;
47780
+ try {
47781
+ writeFileSync8(tmp, text3);
47782
+ renameSync11(tmp, path);
47783
+ } catch (e) {
47784
+ try {
47785
+ rmSync7(tmp, { force: true });
47786
+ } catch {
47787
+ }
47788
+ throw e;
47789
+ }
47790
+ };
47791
+ var withCodexBlock = (existing, text3) => {
47792
+ const lines = existing.split("\n");
47793
+ const start = lineIndex(lines, CODEX_BEGIN);
47794
+ const end = lineIndex(lines, CODEX_END, start + 1);
47795
+ const block = [CODEX_BEGIN, ...text3.trimEnd().split("\n"), CODEX_END];
47796
+ if (start === -1) {
47797
+ const head = existing.trimEnd();
47798
+ return `${head}${head ? "\n\n" : ""}${block.join("\n")}
47799
+ `;
47800
+ }
47801
+ if (end === -1) throw new Error("unterminated");
47802
+ return [...lines.slice(0, start), ...block, ...lines.slice(end + 1)].join(
47803
+ "\n"
47804
+ );
47805
+ };
47806
+ var codexBroken = (text3) => {
47807
+ const lines = text3.split("\n");
47808
+ const start = lineIndex(lines, CODEX_BEGIN);
47809
+ return start !== -1 && lineIndex(lines, CODEX_END, start + 1) === -1;
47810
+ };
47811
+ async function installSkill(deps, origin, harnesses) {
47812
+ const written = [];
47813
+ const notes = [];
47814
+ if (harnesses.length === 0) return { written, notes };
47815
+ if (!origin) {
47816
+ notes.push(
47817
+ "Skipped the skill file: this machine isn't approved on an instance yet. Rerun the install once it is."
47818
+ );
47819
+ return { written, notes };
47820
+ }
47821
+ for (const h of harnesses) {
47822
+ const url2 = `${origin}/skill.md?harness=${h}`;
47823
+ let text3;
47824
+ try {
47825
+ text3 = await deps.fetchSkill(url2);
47826
+ } catch {
47827
+ return { written, notes, failedUrl: url2 };
47828
+ }
47829
+ const folder = skillFolder(text3);
47830
+ if (!folder?.startsWith("open-artifacts") || quotesMarker(text3))
47831
+ return {
47832
+ written,
47833
+ notes,
47834
+ failedUrl: url2
47835
+ };
47836
+ const base3 = skillDir(deps, h);
47837
+ const path = harnessSkills[h].agentsMd ? base3 : join19(base3, folder, "SKILL.md");
47838
+ if (brokenLink(path)) {
47839
+ notes.push(`Left ${path} alone: it is a broken symlink.`);
47840
+ continue;
47841
+ }
47842
+ const writing = targetOf(path);
47843
+ try {
47844
+ if (harnessSkills[h].agentsMd) {
47845
+ const before = existsSync6(writing) ? readFileSync16(writing, "utf8") : "";
47846
+ if (codexBroken(before)) {
47847
+ notes.push(
47848
+ `Left ${writing} alone: its Open Artifacts block has no END marker. Fix or remove the block, then rerun the install.`
47849
+ );
47850
+ continue;
47851
+ }
47852
+ writeAtomic2(writing, withCodexBlock(before, text3));
47853
+ } else {
47854
+ if (existsSync6(writing) && !isOurs(readFileSync16(writing, "utf8"), folder)) {
47855
+ notes.push(
47856
+ `Left ${writing} alone: it has no Open Artifacts marker, so it is not ours to replace.`
47857
+ );
47858
+ continue;
47859
+ }
47860
+ writeAtomic2(writing, withMarker(text3));
47861
+ }
47862
+ written.push(path);
47863
+ } catch (e) {
47864
+ notes.push(
47865
+ `Could not write ${writing}: ${e instanceof Error ? e.message : String(e)}`
47866
+ );
47867
+ }
47868
+ }
47869
+ return { written, notes };
47870
+ }
47871
+ var uninstallSkill = (deps, harnesses = ["claude", "opencode", "pi", "omp", "codex"]) => {
47872
+ const written = [];
47873
+ const notes = [];
47874
+ const seen2 = /* @__PURE__ */ new Set();
47875
+ const fail = (path, e) => notes.push(
47876
+ `Left ${path} alone: ${e instanceof Error ? e.message : String(e)}`
47877
+ );
47878
+ for (const h of harnesses) {
47879
+ const base3 = skillDir(deps, h);
47880
+ if (seen2.has(base3)) continue;
47881
+ seen2.add(base3);
47882
+ if (harnessSkills[h].agentsMd) {
47883
+ try {
47884
+ if (brokenLink(base3) || !existsSync6(base3)) continue;
47885
+ const text3 = readFileSync16(base3, "utf8");
47886
+ if (codexBroken(text3)) {
47887
+ notes.push(
47888
+ `Left ${base3} alone: its Open Artifacts block has no END marker. Fix or remove the block, then rerun the install.`
47889
+ );
47890
+ continue;
47891
+ }
47892
+ const next = withCodexBlock(text3, "");
47893
+ const clean = next.split("\n").filter((l) => {
47894
+ const t = l.replace(/\r$/, "");
47895
+ return t !== CODEX_BEGIN && t !== CODEX_END;
47896
+ }).join("\n").trimEnd();
47897
+ if (clean) writeAtomic2(targetOf(base3), `${clean}
47898
+ `);
47899
+ else rmSync7(targetOf(base3), { force: true });
47900
+ written.push(base3);
47901
+ } catch (e) {
47902
+ fail(base3, e);
47903
+ }
47904
+ continue;
47905
+ }
47906
+ let entries;
47907
+ try {
47908
+ if (!existsSync6(base3)) continue;
47909
+ entries = readdirSync4(base3);
47910
+ } catch (e) {
47911
+ fail(base3, e);
47912
+ continue;
47913
+ }
47914
+ for (const entry of entries) {
47915
+ const dir = join19(base3, entry);
47916
+ const file2 = join19(dir, "SKILL.md");
47917
+ try {
47918
+ const st = lstatSync10(dir);
47919
+ if (st.isSymbolicLink()) {
47920
+ if (existsSync6(file2))
47921
+ notes.push(`Left ${dir} alone: it is a symlinked folder.`);
47922
+ continue;
47923
+ }
47924
+ if (!st.isDirectory() || !lstatOk(file2)) continue;
47925
+ if (!isOurs(readFileSync16(targetOf(file2), "utf8"), entry)) {
47926
+ notes.push(
47927
+ `Left ${file2} alone: it is not an Open Artifacts skill file.`
47928
+ );
47929
+ continue;
47930
+ }
47931
+ rmSync7(targetOf(file2), { force: true });
47932
+ try {
47933
+ rmdirSync(dir);
47934
+ } catch {
47935
+ }
47936
+ written.push(file2);
47937
+ } catch (e) {
47938
+ fail(file2, e);
47939
+ }
47940
+ }
47941
+ }
47942
+ return { written, notes };
47943
+ };
47944
+
47404
47945
  // src/commands/install.ts
47405
47946
  var CODE_RETRY_MS = [2e3, 4e3, 8e3];
47406
47947
  var DAEMON_WAIT_MS = 1e4;
@@ -47481,7 +48022,7 @@ async function loginStep(ctx, opts) {
47481
48022
  ctx,
47482
48023
  c.approved(result.label),
47483
48024
  c.tokenSaved(
47484
- tilde(ctx, join18(ctx.home, "machine.json")),
48025
+ tilde(ctx, join20(ctx.home, "machine.json")),
47485
48026
  result.machineToken
47486
48027
  ),
47487
48028
  c.connected(originOf2(result.hub)),
@@ -47509,7 +48050,7 @@ async function loginStep(ctx, opts) {
47509
48050
  live.clear();
47510
48051
  }
47511
48052
  }
47512
- async function harnessesStep(ctx) {
48053
+ async function harnessesStep(ctx, hub) {
47513
48054
  const c = ctx.copy;
47514
48055
  const out = await installAdapters({
47515
48056
  home: ctx.userHome,
@@ -47530,8 +48071,33 @@ async function harnessesStep(ctx) {
47530
48071
  say(ctx, await skippedLines(ctx, s.harness, s.reason));
47531
48072
  if (out.installed.includes("opencode"))
47532
48073
  say(ctx, out.opencodeRestarted ? c.restarted() : c.opencodeNotRunning());
48074
+ const skill = await installSkill(
48075
+ {
48076
+ home: ctx.userHome,
48077
+ env: ctx.env,
48078
+ fetchSkill: (url2) => fetchSkillText(ctx.fetch, url2)
48079
+ },
48080
+ hub ? originOf2(hub) : machineOrigin(ctx),
48081
+ out.installed
48082
+ );
48083
+ for (const n of skill.notes) say(ctx, [n]);
48084
+ if (skill.failedUrl) skillFailure.set(ctx, skill.failedUrl);
47533
48085
  return true;
47534
48086
  }
48087
+ var skillFailure = /* @__PURE__ */ new WeakMap();
48088
+ function reportSkillFailure(ctx) {
48089
+ const url2 = skillFailure.get(ctx);
48090
+ if (!url2) return false;
48091
+ sayErr(ctx, [
48092
+ `Could not fetch the skill from ${url2}.`,
48093
+ `The bus tools are set up. Rerun ${BUS_CMD} install to write the skill.`
48094
+ ]);
48095
+ return true;
48096
+ }
48097
+ function machineOrigin(ctx) {
48098
+ const m = readMachine(ctx.home);
48099
+ return m.state === "ok" ? originOf2(m.hub) : void 0;
48100
+ }
47535
48101
  async function skippedLines(ctx, h, reason) {
47536
48102
  if (h !== "opencode") return ctx.copy.skipped(h, tildeReason(ctx, h, reason));
47537
48103
  const v = await opencodeVersion(ctx.exec);
@@ -47545,7 +48111,7 @@ function shownSocket(ctx) {
47545
48111
  const real2 = `${canonicalHome(ctx.home)}/`;
47546
48112
  return tilde(
47547
48113
  ctx,
47548
- path.startsWith(real2) ? join18(ctx.home, path.slice(real2.length)) : path
48114
+ path.startsWith(real2) ? join20(ctx.home, path.slice(real2.length)) : path
47549
48115
  );
47550
48116
  }
47551
48117
  async function waitForDaemon(ctx) {
@@ -47596,12 +48162,12 @@ function rosterBlock(ctx, ns) {
47596
48162
  (a, b) => Number(a.state === "queued") - Number(b.state === "queued") || a.name.localeCompare(b.name)
47597
48163
  );
47598
48164
  const queued2 = rows.filter((r) => r.state === "queued").length;
47599
- const shown2 = rows.slice(0, ROSTER_ROWS);
48165
+ const shown3 = rows.slice(0, ROSTER_ROWS);
47600
48166
  const now = ctx.now();
47601
48167
  return {
47602
48168
  lines: [
47603
48169
  c.rosterHeader(ns.namespace, rows.length - queued2, queued2),
47604
- ...shown2.flatMap((r) => {
48170
+ ...shown3.flatMap((r) => {
47605
48171
  const says = c.rosterSays(r, now);
47606
48172
  return [c.rosterRow(r), ...says ? [says] : []];
47607
48173
  }),
@@ -47650,7 +48216,7 @@ var installSteps = (opts) => [
47650
48216
  busBin: ctx.service.argv?.()
47651
48217
  })
47652
48218
  ).includes("missing") ? "todo" : "done",
47653
- apply: harnessesStep
48219
+ apply: (ctx) => harnessesStep(ctx, opts.hub)
47654
48220
  },
47655
48221
  {
47656
48222
  name: "daemon",
@@ -47681,10 +48247,11 @@ async function install2(opts, ctx) {
47681
48247
  return results.every((r) => r.state === "done") ? 0 : 1;
47682
48248
  }
47683
48249
  const ok = await runSteps(steps, ctx, {
47684
- path: join18(ctx.home, "install.json"),
48250
+ path: join20(ctx.home, "install.json"),
47685
48251
  now: ctx.now
47686
48252
  });
47687
- return ok ? 0 : 1;
48253
+ const skillFailed = reportSkillFailure(ctx);
48254
+ return ok && !skillFailed ? 0 : 1;
47688
48255
  }
47689
48256
 
47690
48257
  // src/commands/status.ts
@@ -47829,7 +48396,7 @@ async function healthz(ctx, hub) {
47829
48396
  function claudeIsolates(path) {
47830
48397
  let text3;
47831
48398
  try {
47832
- text3 = readFileSync16(path, "utf8");
48399
+ text3 = readFileSync17(path, "utf8");
47833
48400
  } catch {
47834
48401
  return void 0;
47835
48402
  }
@@ -47896,7 +48463,7 @@ async function doctor(ctx) {
47896
48463
  const node2 = ctx.nodeVersion.replace(/^v/, "");
47897
48464
  if (Number(node2.split(".")[0]) >= MIN_NODE) pass(c.nodeOk(node2));
47898
48465
  else fail(c.nodeOld(node2));
47899
- const machineFile = tilde(ctx, join19(ctx.home, "machine.json"));
48466
+ const machineFile = tilde(ctx, join21(ctx.home, "machine.json"));
47900
48467
  const m = readMachine(ctx.home);
47901
48468
  if (m.state !== "ok") fail(c.noCredentials(machineFile));
47902
48469
  else if (m.revoked) fail(c.revokedCheck());
@@ -47966,8 +48533,8 @@ async function doctor(ctx) {
47966
48533
  if (wiring[h] === "configured") pass(c.wired(h, version2));
47967
48534
  else fail(c.notWired(h));
47968
48535
  if (h === "claude") {
47969
- const settings = join19(
47970
- ctx.env.CLAUDE_CONFIG_DIR ?? join19(ctx.userHome, ".claude"),
48536
+ const settings = join21(
48537
+ ctx.env.CLAUDE_CONFIG_DIR ?? join21(ctx.userHome, ".claude"),
47971
48538
  "settings.json"
47972
48539
  );
47973
48540
  const isolates = claudeIsolates(settings);
@@ -47979,9 +48546,10 @@ async function doctor(ctx) {
47979
48546
  const allow = globalFile(ctx.home);
47980
48547
  const list = readGlobalDirs(allow);
47981
48548
  if (list.error) warn(c.globalUnusable(tilde(ctx, allow), list.error));
47982
- const files = scanConfigFiles(ctx.cwd, { globalFile: allow }).filter(
47983
- (f) => f.file !== allow
47984
- );
48549
+ const files = scanConfigFiles(ctx.cwd, {
48550
+ globalFile: allow,
48551
+ namespacesFile: namespacesFile(ctx.home)
48552
+ }).filter((f) => f.file !== allow);
47985
48553
  if (files.length > 0) {
47986
48554
  n.warnings += files.length;
47987
48555
  say(ctx, configFileLines(ctx, files));
@@ -47992,13 +48560,13 @@ async function doctor(ctx) {
47992
48560
  }
47993
48561
 
47994
48562
  // src/commands/global.ts
47995
- import { realpathSync as realpathSync8, statSync as statSync10 } from "node:fs";
48563
+ import { realpathSync as realpathSync9, statSync as statSync10 } from "node:fs";
47996
48564
  import { resolve as resolve6 } from "node:path";
47997
48565
  function shown(ctx, path) {
47998
48566
  const t = tilde(ctx, path);
47999
48567
  if (t !== path) return t;
48000
48568
  try {
48001
- return tilde({ userHome: realpathSync8(ctx.userHome) }, path);
48569
+ return tilde({ userHome: realpathSync9(ctx.userHome) }, path);
48002
48570
  } catch {
48003
48571
  return path;
48004
48572
  }
@@ -48051,14 +48619,14 @@ async function global(opts, ctx) {
48051
48619
  }
48052
48620
 
48053
48621
  // src/commands/logs.ts
48054
- import { readFileSync as readFileSync17 } from "node:fs";
48055
- import { join as join20 } from "node:path";
48622
+ import { readFileSync as readFileSync18 } from "node:fs";
48623
+ import { join as join22 } from "node:path";
48056
48624
  var TAIL = 50;
48057
48625
  async function logs(ctx) {
48058
- const path = join20(ctx.home, "logs", "daemon.log");
48626
+ const path = join22(ctx.home, "logs", "daemon.log");
48059
48627
  let text3;
48060
48628
  try {
48061
- text3 = readFileSync17(path, "utf8");
48629
+ text3 = readFileSync18(path, "utf8");
48062
48630
  } catch {
48063
48631
  say(ctx, ctx.copy.noLog(tilde(ctx, path)));
48064
48632
  return 1;
@@ -48083,13 +48651,125 @@ async function mcp(harness, ctx, load = (h) => MCP_SERVER[h]()) {
48083
48651
  return void 0;
48084
48652
  }
48085
48653
 
48654
+ // src/commands/namespace.ts
48655
+ import { realpathSync as realpathSync10, statSync as statSync11 } from "node:fs";
48656
+ import { join as join23, resolve as resolve7 } from "node:path";
48657
+ init_src();
48658
+ function shown2(ctx, path) {
48659
+ const t = tilde(ctx, path);
48660
+ if (t !== path) return t;
48661
+ try {
48662
+ return tilde({ userHome: realpathSync10(ctx.userHome) }, path);
48663
+ } catch {
48664
+ return path;
48665
+ }
48666
+ }
48667
+ async function namespace(opts, ctx) {
48668
+ const c = ctx.copy;
48669
+ say(ctx, c.header(ctx.version), "");
48670
+ const file2 = namespacesFile(ctx.home);
48671
+ const { entries, error: error62 } = readApprovals(file2);
48672
+ if (error62) {
48673
+ sayErr(ctx, c.nsUnusable(tilde(ctx, file2), error62));
48674
+ return 1;
48675
+ }
48676
+ if (opts.sub === "list") {
48677
+ say(
48678
+ ctx,
48679
+ entries.length ? c.nsList(entries.map((e) => ({ ...e, dir: shown2(ctx, e.dir) }))) : c.nsNone()
48680
+ );
48681
+ return 0;
48682
+ }
48683
+ const given = resolve7(ctx.cwd, opts.dir);
48684
+ let real2;
48685
+ try {
48686
+ real2 = canonicalPath(given);
48687
+ } catch {
48688
+ }
48689
+ if (opts.sub === "revoke") {
48690
+ const keep = entries.filter(
48691
+ (e) => e.dir !== given && e.dir !== real2 && !(real2 && sameDir(e.dir, real2))
48692
+ );
48693
+ if (keep.length === entries.length) {
48694
+ say(ctx, c.nsNotListed(shown2(ctx, real2 ?? given)));
48695
+ return 0;
48696
+ }
48697
+ writeApprovals(keep, ctx.home);
48698
+ for (const e of entries.filter((x) => !keep.includes(x)))
48699
+ logApproval(
48700
+ { action: "revoke", ...e, tty: Boolean(ctx.stdinIsTTY) },
48701
+ ctx.home
48702
+ );
48703
+ say(ctx, c.nsRevoked(shown2(ctx, real2 ?? given)));
48704
+ return 0;
48705
+ }
48706
+ if (!real2 || !statSync11(real2).isDirectory()) {
48707
+ sayErr(ctx, c.nsNotDir(shown2(ctx, real2 ?? given)));
48708
+ return 1;
48709
+ }
48710
+ const cfgFile = join23(real2, CONFIG_FILE);
48711
+ const own2 = readOwnFile(cfgFile, process.getuid?.(), {
48712
+ allowGroupWrite: true
48713
+ });
48714
+ if (own2.state === "none") {
48715
+ sayErr(ctx, c.nsNoFile(shown2(ctx, real2)));
48716
+ return 1;
48717
+ }
48718
+ if (own2.state === "unsafe") {
48719
+ sayErr(ctx, c.nsFileUnusable(shown2(ctx, cfgFile), own2.why));
48720
+ return 1;
48721
+ }
48722
+ let ns;
48723
+ try {
48724
+ const parsed = BusConfigSchema.safeParse(JSON.parse(own2.text));
48725
+ if (parsed.success) ns = parsed.data.namespace;
48726
+ } catch {
48727
+ }
48728
+ if (!ns) {
48729
+ say(ctx, c.nsNoNamespace(shown2(ctx, cfgFile)));
48730
+ return 1;
48731
+ }
48732
+ if (isApproved(real2, ns, entries)) {
48733
+ say(ctx, c.nsAlready(shown2(ctx, real2), plain2(ns)));
48734
+ return 0;
48735
+ }
48736
+ if (!opts.yes) {
48737
+ if (!ctx.stdinIsTTY || !ctx.readLine) {
48738
+ sayErr(ctx, c.nsNeedTty(approveCommand(real2)));
48739
+ return 1;
48740
+ }
48741
+ say(ctx, c.nsAsk(shown2(ctx, real2), plain2(ns)));
48742
+ const answer = (await ctx.readLine(c.nsPrompt())).trim().toLowerCase();
48743
+ if (answer !== "y" && answer !== "yes") {
48744
+ say(ctx, c.nsDeclined());
48745
+ return 1;
48746
+ }
48747
+ }
48748
+ const next = [
48749
+ ...entries.filter((e) => !sameDir(e.dir, real2)),
48750
+ { dir: real2, namespace: ns }
48751
+ ];
48752
+ writeApprovals(next, ctx.home);
48753
+ logApproval(
48754
+ {
48755
+ action: "approve",
48756
+ dir: real2,
48757
+ namespace: ns,
48758
+ tty: Boolean(ctx.stdinIsTTY)
48759
+ },
48760
+ ctx.home
48761
+ );
48762
+ say(ctx, c.nsApproved(shown2(ctx, real2), plain2(ns)));
48763
+ return 0;
48764
+ }
48765
+
48086
48766
  // src/commands/uninstall.ts
48087
- import { join as join22 } from "node:path";
48767
+ import { join as join25 } from "node:path";
48088
48768
 
48089
48769
  // src/steps/purge.ts
48090
48770
  init_src3();
48091
- import { lstatSync as lstatSync10, readdirSync as readdirSync4, rmdirSync, rmSync as rmSync7 } from "node:fs";
48092
- import { join as join21 } from "node:path";
48771
+ import { lstatSync as lstatSync11, readdirSync as readdirSync5, rmdirSync as rmdirSync2, rmSync as rmSync8 } from "node:fs";
48772
+ import { join as join24 } from "node:path";
48093
48773
  var FILES = [
48094
48774
  "machine.json",
48095
48775
  "install.json",
@@ -48121,16 +48801,16 @@ var FOLDERS = [
48121
48801
  ];
48122
48802
  function kind(path) {
48123
48803
  try {
48124
- const st = lstatSync10(path);
48804
+ const st = lstatSync11(path);
48125
48805
  return st.isDirectory() ? "dir" : st.isSocket() ? "socket" : "other";
48126
48806
  } catch {
48127
48807
  return void 0;
48128
48808
  }
48129
48809
  }
48130
- var remove2 = (path, k) => rmSync7(path, { recursive: k === "dir", force: true });
48810
+ var remove2 = (path, k) => rmSync8(path, { recursive: k === "dir", force: true });
48131
48811
  var rmdirIfEmpty = (path) => {
48132
48812
  try {
48133
- rmdirSync(path);
48813
+ rmdirSync2(path);
48134
48814
  return true;
48135
48815
  } catch {
48136
48816
  return false;
@@ -48138,14 +48818,14 @@ var rmdirIfEmpty = (path) => {
48138
48818
  };
48139
48819
  function purgeShort(dir, removed) {
48140
48820
  if (kind(dir) !== "dir" || unsafeSocketDir(dir)) return;
48141
- const ret = join21(dir, "claude-return");
48821
+ const ret = join24(dir, "claude-return");
48142
48822
  for (const [d, ours2] of [
48143
48823
  [ret, (_n, p) => kind(p) === "socket"],
48144
48824
  [dir, (n) => /^daemon\.sock(\.keep-\d+)?$/.test(n)]
48145
48825
  ]) {
48146
48826
  if (kind(d) !== "dir") continue;
48147
- for (const name of readdirSync4(d)) {
48148
- const path = join21(d, name);
48827
+ for (const name of readdirSync5(d)) {
48828
+ const path = join24(d, name);
48149
48829
  const k = kind(path);
48150
48830
  if (k === void 0 || k === "dir" || !ours2(name, path)) continue;
48151
48831
  remove2(path, k);
@@ -48158,7 +48838,7 @@ function purgeShort(dir, removed) {
48158
48838
  function purge(home2, opts) {
48159
48839
  let entries;
48160
48840
  try {
48161
- entries = readdirSync4(home2);
48841
+ entries = readdirSync5(home2);
48162
48842
  } catch {
48163
48843
  return { removed: [], leftDir: false };
48164
48844
  }
@@ -48170,21 +48850,21 @@ function purge(home2, opts) {
48170
48850
  ...FILES,
48171
48851
  ...entries.filter((n) => TEMP.some((re) => re.test(n)))
48172
48852
  ]) {
48173
- const path = join21(home2, name);
48853
+ const path = join24(home2, name);
48174
48854
  const k = kind(path);
48175
48855
  if (k === void 0 || k === "dir") continue;
48176
48856
  remove2(path, k);
48177
48857
  removed.push(name);
48178
48858
  }
48179
48859
  for (const folder of FOLDERS) {
48180
- const dir = join21(home2, folder.path);
48860
+ const dir = join24(home2, folder.path);
48181
48861
  if (kind(dir) !== "dir") continue;
48182
- for (const name of readdirSync4(dir)) {
48183
- const path = join21(dir, name);
48862
+ for (const name of readdirSync5(dir)) {
48863
+ const path = join24(dir, name);
48184
48864
  const k = kind(path);
48185
48865
  if (k === void 0 || !folder.ours(name, path)) continue;
48186
48866
  remove2(path, k);
48187
- removed.push(join21(folder.path, name));
48867
+ removed.push(join24(folder.path, name));
48188
48868
  }
48189
48869
  if (rmdirIfEmpty(dir)) removed.push(folder.path);
48190
48870
  }
@@ -48215,6 +48895,14 @@ async function uninstall2(opts, ctx) {
48215
48895
  codexApp: ctx.codexApp
48216
48896
  });
48217
48897
  if (r.removed.length > 0) say(ctx, c.removedFrom(r.removed));
48898
+ try {
48899
+ const skills = uninstallSkill({ home: ctx.userHome, env: ctx.env });
48900
+ for (const n of skills.notes) say(ctx, [n]);
48901
+ } catch (e) {
48902
+ say(ctx, [
48903
+ `Could not remove the skill files: ${e instanceof Error ? e.message : String(e)}`
48904
+ ]);
48905
+ }
48218
48906
  if (r.folderOnly.includes("opencode")) say(ctx, c.removedPluginFolder());
48219
48907
  if (r.removed.length + r.folderOnly.length === 0) say(ctx, c.noneWired());
48220
48908
  for (const s of r.skipped)
@@ -48228,7 +48916,7 @@ async function uninstall2(opts, ctx) {
48228
48916
  r.opencodeRestarted ? c.restartedUnload() : c.opencodeNotRunningUnload()
48229
48917
  );
48230
48918
  if (!opts.purge) {
48231
- say(ctx, "", c.kept(tilde(ctx, join22(ctx.home, "machine.json"))));
48919
+ say(ctx, "", c.kept(tilde(ctx, join25(ctx.home, "machine.json"))));
48232
48920
  return 0;
48233
48921
  }
48234
48922
  const home2 = tilde(ctx, ctx.home);
@@ -48239,7 +48927,7 @@ async function uninstall2(opts, ctx) {
48239
48927
  } catch {
48240
48928
  }
48241
48929
  const out = purge(ctx.home, {
48242
- isDefault: ctx.home === join22(ctx.userHome, ".oa-bus")
48930
+ isDefault: ctx.home === join25(ctx.userHome, ".oa-bus")
48243
48931
  });
48244
48932
  if ("refused" in out) {
48245
48933
  sayErr(ctx, c.purgeRefused(home2));
@@ -48264,16 +48952,19 @@ var COMMANDS = /* @__PURE__ */ new Set([
48264
48952
  "doctor",
48265
48953
  "uninstall",
48266
48954
  "global",
48955
+ "namespace",
48267
48956
  "version"
48268
48957
  ]);
48269
48958
  var HARNESSES2 = ["claude", "opencode", "codex", "pi"];
48270
48959
  var GLOBAL_USAGE = `usage: ${BUS_CMD} global <add|rm> <dir>, or global list`;
48960
+ var NAMESPACE_USAGE = `usage: ${BUS_CMD} namespace approve [dir], namespace revoke <dir>, or namespace list`;
48271
48961
  var COMMON = /* @__PURE__ */ new Set(["no-color", "version", "home"]);
48272
48962
  var FLAGS = {
48273
48963
  install: ["instance", "no-open", "yes", "check", "no-service"],
48274
48964
  login: ["instance", "no-open"],
48275
48965
  daemon: ["instance"],
48276
- uninstall: ["purge"]
48966
+ uninstall: ["purge"],
48967
+ namespace: ["yes"]
48277
48968
  };
48278
48969
  function parse7(argv) {
48279
48970
  const { values, positionals, tokens: tokens2 } = parseArgs({
@@ -48299,7 +48990,16 @@ function parse7(argv) {
48299
48990
  if (cmd === "mcp" && rest.length === 0)
48300
48991
  throw new Error(`usage: ${BUS_CMD} mcp <claude|opencode|codex|pi>`);
48301
48992
  if (cmd === "global" && rest.length < takes) throw new Error(GLOBAL_USAGE);
48302
- const extra = rest[takes];
48993
+ if (cmd === "namespace") {
48994
+ const sub = rest[0];
48995
+ const max = sub === "list" ? 1 : sub === "approve" ? 2 : 2;
48996
+ const min = sub === "revoke" ? 2 : 1;
48997
+ if (!["approve", "revoke", "list"].includes(sub ?? "") || rest.length < min)
48998
+ throw new Error(NAMESPACE_USAGE);
48999
+ if (rest[max] !== void 0)
49000
+ throw new Error(`unexpected argument: ${rest[max]}`);
49001
+ }
49002
+ const extra = cmd === "namespace" ? void 0 : rest[takes];
48303
49003
  if (extra !== void 0) throw new Error(`unexpected argument: ${extra}`);
48304
49004
  for (const name of ["home", "instance"])
48305
49005
  if (values[name] === "") throw new Error(`--${name} needs a value`);
@@ -48335,6 +49035,14 @@ function route(cmd, values, positionals) {
48335
49035
  if ((sub === "add" || sub === "rm") && dir) return { cmd, sub, dir };
48336
49036
  throw new Error(GLOBAL_USAGE);
48337
49037
  }
49038
+ case "namespace": {
49039
+ const [sub, dir] = positionals;
49040
+ if (sub === "list") return { cmd, sub };
49041
+ if (sub === "revoke" && dir) return { cmd, sub, dir };
49042
+ if (sub === "approve")
49043
+ return { cmd, sub, dir: dir ?? ".", yes: values.yes };
49044
+ throw new Error(NAMESPACE_USAGE);
49045
+ }
48338
49046
  case "install":
48339
49047
  return {
48340
49048
  cmd,
@@ -48365,7 +49073,7 @@ async function main(argv, makeCtx = realCtx) {
48365
49073
  return 2;
48366
49074
  }
48367
49075
  const ctx = makeCtx(cmd.noColor);
48368
- if (cmd.home) ctx.home = resolve7(cmd.home);
49076
+ if (cmd.home) ctx.home = resolve8(cmd.home);
48369
49077
  try {
48370
49078
  return await dispatch(cmd, ctx);
48371
49079
  } catch (e) {
@@ -48417,6 +49125,8 @@ async function dispatch(cmd, ctx) {
48417
49125
  return uninstall2({ purge: cmd.purge }, ctx);
48418
49126
  case "global":
48419
49127
  return global(cmd, ctx);
49128
+ case "namespace":
49129
+ return namespace(cmd, ctx);
48420
49130
  case "version":
48421
49131
  say(ctx, ctx.copy.header(ctx.version));
48422
49132
  return 0;