@open-artifacts/bus 0.134.0 → 0.135.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/assets/oa-bus.ts CHANGED
@@ -11,7 +11,7 @@ import { StringDecoder } from "node:string_decoder";
11
11
  type Json = Record<string, unknown>;
12
12
 
13
13
  /** The IPC marker (CONTRACT.md): the package version, stamped by the CLI's bundler. */
14
- const CLIENT_VERSION = "0.134.0";
14
+ const CLIENT_VERSION = "0.135.0";
15
15
 
16
16
  type Frame = Json & { type: string; id: string };
17
17
  type Ctx = {
@@ -733,15 +733,27 @@ function procStart(): string | undefined {
733
733
  }
734
734
  }
735
735
 
736
- /** A session name as a bus name: lowercase words joined by `-`; the kind when nothing is left. */
736
+ /**
737
+ * A session name as typed (#1635), made a valid bus name the way the hub
738
+ * (BusNameSchema) wants one. Accents fold away (NFKD, combining marks
739
+ * dropped). Letters, digits, single spaces, `.` `_` `-` keep their place and
740
+ * case. A run of any other character becomes `-` only between two kept
741
+ * non-space characters (`docs/readme` gives `docs-readme`); elsewhere it is
742
+ * dropped. Starts with a letter or digit, ends with a letter, digit, `_` or
743
+ * `-`, at most 64 characters; the kind when nothing is left. The hub would
744
+ * turn a name with any other character into `agent-N`.
745
+ */
737
746
  function nameOf(title: string | undefined, kind: string): string {
738
- const slug = (title ?? "")
739
- .toLowerCase()
740
- .replace(/[^a-z0-9]+/g, "-")
741
- .replace(/^-+/, "")
747
+ const cut = (title ?? "")
748
+ .normalize("NFKD")
749
+ .replace(/[\u0300-\u036f]/g, "")
750
+ .replace(/([A-Za-z0-9._-])[^A-Za-z0-9 ._-]+(?=[A-Za-z0-9._-])/g, "$1-")
751
+ .replace(/[^A-Za-z0-9 ._-]+/g, "")
752
+ .replace(/ {2,}/g, " ")
753
+ .replace(/^[ ._-]+/, "")
742
754
  .slice(0, 64)
743
- .replace(/-+$/, "");
744
- return slug || kind;
755
+ .replace(/[ .]+$/, "");
756
+ return cut || kind;
745
757
  }
746
758
 
747
759
  type Identity = { ref: string; cwd: string; name: string; kind: "pi" | "omp" };
@@ -7,6 +7,7 @@ queued.
7
7
 
8
8
  import os
9
9
  import re
10
+ import sys
10
11
  import threading
11
12
 
12
13
  from . import copy
@@ -37,9 +38,11 @@ def codex_app_server_active():
37
38
  """
38
39
  try:
39
40
  from hermes_cli.codex_runtime_switch import get_current_runtime
40
- from hermes_cli.config import load_config
41
+ from hermes_cli import config
41
42
 
42
- return get_current_runtime(load_config()) == "codex_app_server"
43
+ # Read-only callers skip the defensive deepcopy; older Hermes has only load_config.
44
+ load = getattr(config, "load_config_readonly", None) or config.load_config
45
+ return get_current_runtime(load()) == "codex_app_server"
43
46
  except Exception:
44
47
  return None
45
48
 
@@ -58,7 +61,48 @@ def context_reaches_model(user_message, history):
58
61
  last = next((m for m in reversed(history) if isinstance(m, dict) and m.get("role") == "user"), None)
59
62
  # Equal text: a voice turn's API-facing content differs from its clean text, and a
60
63
  # message appended after the current one by compaction would differ too.
61
- return last is not None and isinstance(last.get("content"), str) and last["content"] == user_message
64
+ if last is None or not isinstance(last.get("content"), str):
65
+ return False
66
+ return _is_gateway_wrapped(last["content"], user_message)
67
+
68
+
69
+ def _is_gateway_wrapped(content, user_message):
70
+ """Whether `content` is `user_message` as the Hermes gateway composes it.
71
+
72
+ The gateway may prepend a timestamp (gateway/message_timestamps.py, when
73
+ gateway.message_timestamps is on) and then, outside it, the Telegram observed group
74
+ context (gateway/run.py _wrap_current_message_with_observed_context). Only those two
75
+ exact shapes count; any other prefix means the text is not the current turn's.
76
+ """
77
+ if content == user_message:
78
+ return True
79
+ rest = content
80
+ run = sys.modules.get("gateway.run") # already loaded in a gateway process; never import it
81
+ obs = getattr(run, "_OBSERVED_GROUP_CONTEXT_HEADER", None)
82
+ cur = getattr(run, "_CURRENT_ADDRESSED_MESSAGE_HEADER", None)
83
+ if isinstance(obs, str) and isinstance(cur, str) and obs and cur and rest.startswith(obs + "\n"):
84
+ marker = "\n\n" + cur + "\n"
85
+ at = rest.find(marker, len(obs))
86
+ if at < 0:
87
+ return False
88
+ rest = rest[at + len(marker) :]
89
+ if rest == user_message:
90
+ return True
91
+ if not user_message or not rest.endswith(user_message):
92
+ return False
93
+ prefix = rest[: -len(user_message)]
94
+ if not prefix:
95
+ return True
96
+ # The gateway loads it for every text message before the turn runs; never import it here
97
+ # (this runs under the plugin's lock).
98
+ strip = getattr(sys.modules.get("gateway.message_timestamps"), "strip_leading_message_timestamps", None)
99
+ if not callable(strip):
100
+ return False
101
+ try:
102
+ # The prefix must be nothing but gateway timestamps.
103
+ return strip(prefix + "\0")[0] == "\0"
104
+ except Exception:
105
+ return False
62
106
 
63
107
 
64
108
  # Hermes has no always-on instruction file for the bus, so these two lines ride in the turn's
package/dist/index.js CHANGED
@@ -31799,6 +31799,7 @@ var init_kinds = __esm({
31799
31799
  "pi",
31800
31800
  "omp",
31801
31801
  "hermes",
31802
+ "openclaw",
31802
31803
  "codex"
31803
31804
  ];
31804
31805
  AgentKindSchema = external_exports.enum(AGENT_KINDS);
@@ -32427,7 +32428,7 @@ var init_frames = __esm({
32427
32428
  late = { late: external_exports.array(external_exports.string().min(1)).optional() };
32428
32429
  isWellFormed2 = (s) => s.isWellFormed();
32429
32430
  WELL_FORMED = { message: "text is not well-formed unicode" };
32430
- CLIENT_VERSION = true ? "0.134.0" : "0.0.0";
32431
+ CLIENT_VERSION = true ? "0.135.0" : "0.0.0";
32431
32432
  clientVersion = {
32432
32433
  client_version: external_exports.string().min(1).max(64).optional()
32433
32434
  };
@@ -39019,7 +39020,7 @@ function psRows(pids) {
39019
39020
  function holdingFiles(pairs) {
39020
39021
  if (!pairs.length) return [];
39021
39022
  if (process.platform === "linux") return holdingLinux(pairs);
39022
- const real2 = (f) => {
39023
+ const real3 = (f) => {
39023
39024
  try {
39024
39025
  return realpathSync2(f);
39025
39026
  } catch {
@@ -39049,7 +39050,7 @@ function holdingFiles(pairs) {
39049
39050
  }
39050
39051
  }
39051
39052
  return pairs.map(({ pid: pid2, file: file2 }) => {
39052
- const r = real2(file2);
39053
+ const r = real3(file2);
39053
39054
  return r !== void 0 && (holders.get(r)?.has(pid2) ?? false);
39054
39055
  });
39055
39056
  }
@@ -39144,9 +39145,19 @@ function sessionFiles(dir) {
39144
39145
  }
39145
39146
  var alive = (s, deps2) => deps2.isRunning(s.pid) && deps2.procStart(s.pid, s.stamp) === s.procStart;
39146
39147
  var strip = ({ stamp: _, ...s }) => s;
39147
- function liveClaudeSessions(deps2) {
39148
+ function liveClaudeFiles(deps2) {
39148
39149
  return sessionFiles(deps2.dir).filter((s) => alive(s, deps2)).map(strip);
39149
39150
  }
39151
+ function liveClaudeSessions(deps2, preferPid) {
39152
+ const byRef = /* @__PURE__ */ new Map();
39153
+ const rank = (s) => (s.pid === preferPid?.(s.ref) ? 4 : 0) + (s.socketPath !== "" ? 2 : 0) + (s.name !== `claude-${s.pid}` ? 1 : 0);
39154
+ for (const s of liveClaudeFiles(deps2)) {
39155
+ const cur = byRef.get(s.ref);
39156
+ if (!cur || rank(s) > rank(cur) || rank(s) === rank(cur) && s.pid < cur.pid)
39157
+ byRef.set(s.ref, s);
39158
+ }
39159
+ return [...byRef.values()];
39160
+ }
39150
39161
  function claudeTarget(ref, deps2) {
39151
39162
  const s = sessionFiles(deps2.dir).find(
39152
39163
  (x) => x.ref === ref && x.socketPath && alive(x, deps2)
@@ -39211,6 +39222,11 @@ function attest(hello, deps2 = {}) {
39211
39222
  }
39212
39223
  return { ok: true };
39213
39224
  }
39225
+ case "openclaw":
39226
+ return {
39227
+ ok: false,
39228
+ reason: "openclaw is not supported by this daemon yet"
39229
+ };
39214
39230
  case "codex":
39215
39231
  if (deps2.codex) return deps2.codex.attestNow(hello);
39216
39232
  defaultCodex ??= codexAttestor();
@@ -39415,13 +39431,13 @@ var idOf = (path, follow = true) => {
39415
39431
  };
39416
39432
  var loose = (p) => p.normalize("NFC").toLowerCase();
39417
39433
  function isGlobalDir(dir, dirs, onStale) {
39418
- let real2;
39434
+ let real3;
39419
39435
  try {
39420
- real2 = realpathSync3(dir);
39436
+ real3 = realpathSync3(dir);
39421
39437
  } catch {
39422
39438
  return false;
39423
39439
  }
39424
- const near = loose(real2);
39440
+ const near = loose(real3);
39425
39441
  const ids = /* @__PURE__ */ new Set();
39426
39442
  for (const entry of dirs) {
39427
39443
  const e = loose(entry);
@@ -39440,7 +39456,7 @@ function isGlobalDir(dir, dirs, onStale) {
39440
39456
  if (id !== void 0) ids.add(id);
39441
39457
  }
39442
39458
  if (ids.size === 0) return false;
39443
- for (let d = real2; ; d = dirname3(d)) {
39459
+ for (let d = real3; ; d = dirname3(d)) {
39444
39460
  const id = idOf(d);
39445
39461
  if (id !== void 0 && ids.has(id)) return true;
39446
39462
  if (dirname3(d) === d) return false;
@@ -39824,18 +39840,18 @@ var ConfigIssues = class {
39824
39840
  function scanConfigFiles(cwd, opts = {}) {
39825
39841
  const uid = opts.uid ?? process.getuid?.();
39826
39842
  const out = [];
39827
- let real2 = cwd;
39843
+ let real3 = cwd;
39828
39844
  try {
39829
- real2 = realpathSync5(cwd);
39845
+ real3 = realpathSync5(cwd);
39830
39846
  } catch {
39831
39847
  }
39832
- for (const file2 of configPaths(real2)) {
39848
+ for (const file2 of configPaths(real3)) {
39833
39849
  const issue2 = inspectConfig(file2, uid, opts.group);
39834
39850
  if (issue2) out.push(issue2);
39835
39851
  }
39836
39852
  const seen2 = new ConfigIssues();
39837
39853
  try {
39838
- resolveNamespace(real2, {
39854
+ resolveNamespace(real3, {
39839
39855
  issues: seen2,
39840
39856
  allowMissing: true,
39841
39857
  ...opts.uid === void 0 ? {} : { uid: opts.uid },
@@ -41955,7 +41971,7 @@ function splitArgv0(args) {
41955
41971
  for (const m of args.matchAll(/(?:^|\/)codex(?=\s|$)/g))
41956
41972
  ends.push((m.index ?? 0) + m[0].length);
41957
41973
  if (!ends.length) return words(args).slice(1);
41958
- const real2 = ends.find((e) => {
41974
+ const real3 = ends.find((e) => {
41959
41975
  const p = args.slice(0, e);
41960
41976
  try {
41961
41977
  return isAbsolute5(p) && statSync7(p).isFile();
@@ -41963,7 +41979,7 @@ function splitArgv0(args) {
41963
41979
  return false;
41964
41980
  }
41965
41981
  });
41966
- return words(args.slice(real2 ?? ends[0]));
41982
+ return words(args.slice(real3 ?? ends[0]));
41967
41983
  }
41968
41984
  var execText = (cmd, args) => new Promise((resolve12) => {
41969
41985
  execFile(
@@ -42243,8 +42259,10 @@ var PiTransport = class {
42243
42259
  }
42244
42260
  opts;
42245
42261
  #waiting = /* @__PURE__ */ new Map();
42246
- /** Timed-out pushes: msg_id -> the session whose late ack still counts. */
42262
+ /** Timed-out pushes: msg_id -> the session whose late ack still counts, until its link closes. */
42247
42263
  #late = /* @__PURE__ */ new Map();
42264
+ /** The same ids per session, oldest first, for the cap and for dropRef. */
42265
+ #lateByRef = /* @__PURE__ */ new Map();
42248
42266
  async deliver(agent, mail) {
42249
42267
  const pushed = this.opts.push(agent.ref, {
42250
42268
  v: 1,
@@ -42283,12 +42301,15 @@ var PiTransport = class {
42283
42301
  }
42284
42302
  /** An ack that came after the timeout, from the session it was pushed to; true once. */
42285
42303
  lateAck(msgId, ref) {
42286
- if (this.#late.get(msgId)?.ref !== ref) return false;
42304
+ if (this.#late.get(msgId) !== ref) return false;
42287
42305
  this.#forget(msgId);
42288
42306
  return true;
42289
42307
  }
42290
42308
  /** The session's last connection closed: nothing it was pushed can be acked now. */
42291
42309
  dropRef(ref) {
42310
+ for (const msgId of this.#lateByRef.get(ref) ?? [])
42311
+ this.#late.delete(msgId);
42312
+ this.#lateByRef.delete(ref);
42292
42313
  for (const [msgId, w] of this.#waiting) {
42293
42314
  if (w.ref !== ref) continue;
42294
42315
  this.#waiting.delete(msgId);
@@ -42307,21 +42328,32 @@ var PiTransport = class {
42307
42328
  }
42308
42329
  #remember(msgId, ref) {
42309
42330
  this.#forget(msgId);
42310
- const timer = setTimeout(
42311
- () => this.#late.delete(msgId),
42312
- this.opts.lateAckMs ?? 6e4
42313
- );
42314
- timer.unref();
42315
- this.#late.set(msgId, { ref, timer });
42331
+ this.#late.set(msgId, ref);
42332
+ const ids = this.#lateByRef.get(ref) ?? /* @__PURE__ */ new Set();
42333
+ this.#lateByRef.set(ref, ids);
42334
+ ids.add(msgId);
42335
+ const cap = this.opts.lateAckCap ?? 1e3;
42336
+ while (ids.size > cap) {
42337
+ const oldest = ids.values().next().value;
42338
+ ids.delete(oldest);
42339
+ this.#late.delete(oldest);
42340
+ }
42316
42341
  }
42317
42342
  #forget(msgId) {
42318
- clearTimeout(this.#late.get(msgId)?.timer);
42343
+ const ref = this.#late.get(msgId);
42344
+ if (ref === void 0) return;
42319
42345
  this.#late.delete(msgId);
42346
+ const ids = this.#lateByRef.get(ref);
42347
+ ids?.delete(msgId);
42348
+ if (ids?.size === 0) this.#lateByRef.delete(ref);
42320
42349
  }
42321
42350
  };
42322
42351
 
42323
42352
  // ../bus-daemon/src/index.ts
42324
42353
  var NOTICE_RETRY_MS = 3e4;
42354
+ var RENAME_HOLD_MS = 60 * 6e4;
42355
+ var RENAME_WINDOW_MS = 6e4;
42356
+ var RENAME_WINDOW_MAX = 3;
42325
42357
  var LIMITED_RETRY_MS = 5 * 6e4;
42326
42358
  var LATE_WINDOW_MS = 60 * 6e4;
42327
42359
  var piLike = (kind3) => kind3 === "pi" || kind3 === "omp" || kind3 === "hermes";
@@ -42356,6 +42388,8 @@ async function runDaemon(deps2 = {}) {
42356
42388
  const announceSessions = () => {
42357
42389
  for (const ref of limited.keys())
42358
42390
  if (!agents.byRef(ref)?.live) clearLimited(ref);
42391
+ for (const m of [renameFrames, renameHeldUntil])
42392
+ for (const ref of m.keys()) if (!agents.byRef(ref)?.live) m.delete(ref);
42359
42393
  return hub.send({ v: 1, id: frameId(), type: "sessions", ...sessions() });
42360
42394
  };
42361
42395
  const upIds = /* @__PURE__ */ new Map();
@@ -42626,10 +42660,16 @@ async function runDaemon(deps2 = {}) {
42626
42660
  const seenAt = /* @__PURE__ */ new Map();
42627
42661
  let seenSeq = 0;
42628
42662
  const renameIds = /* @__PURE__ */ new Map();
42629
- const renameIfChanged = (rec, name) => {
42663
+ const renameFrames = /* @__PURE__ */ new Map();
42664
+ const renameHeldUntil = /* @__PURE__ */ new Map();
42665
+ const renameIfChanged = (rec, name, filePid) => {
42630
42666
  const was = rec.sessionName ?? rec.proposedName;
42667
+ if (name === "" || name === `claude-${filePid}`) return;
42631
42668
  rec.sessionName = name;
42632
- if (name === was || name === "" || name === `claude-${rec.pid}`) return;
42669
+ if (name === was) {
42670
+ if (rec.sentName !== rec.proposedName) flushRename(rec);
42671
+ return;
42672
+ }
42633
42673
  rec.proposedName = name;
42634
42674
  flushRename(rec);
42635
42675
  };
@@ -42643,8 +42683,15 @@ async function runDaemon(deps2 = {}) {
42643
42683
  const flushRename = (rec) => {
42644
42684
  if (!(rec.kind === "claude-code" || rec.kind === "pi" || rec.kind === "omp") || !rec.live || rec.sentName === void 0 || rec.sentName === rec.proposedName || !hub.open || !hubHelloed || rec.replaces !== void 0 || limited.has(rec.ref))
42645
42685
  return;
42686
+ if (Date.now() < (renameHeldUntil.get(rec.ref) ?? 0)) return;
42687
+ const now = Date.now();
42688
+ const recent = (renameFrames.get(rec.ref) ?? []).filter(
42689
+ (t) => now - t < RENAME_WINDOW_MS
42690
+ );
42691
+ renameFrames.set(rec.ref, recent);
42692
+ if (recent.length >= RENAME_WINDOW_MAX) return;
42646
42693
  const id = frameId();
42647
- renameIds.set(id, rec.ref);
42694
+ renameIds.set(id, { ref: rec.ref, prevSent: rec.sentName });
42648
42695
  if (hub.send({
42649
42696
  v: 1,
42650
42697
  id,
@@ -42652,12 +42699,16 @@ async function runDaemon(deps2 = {}) {
42652
42699
  agent_ref: rec.ref,
42653
42700
  proposed_name: fitName(rec.proposedName, 64),
42654
42701
  name_kind: "chosen"
42655
- }))
42702
+ })) {
42656
42703
  rec.sentName = rec.proposedName;
42657
- else renameIds.delete(id);
42704
+ recent.push(now);
42705
+ } else renameIds.delete(id);
42658
42706
  };
42659
42707
  const syncClaude = () => {
42660
- const live = liveClaudeSessions(claudeSessions);
42708
+ const live = liveClaudeSessions(
42709
+ claudeSessions,
42710
+ (ref) => agents.byRef(ref)?.pid
42711
+ );
42661
42712
  const liveRefs = new Set(live.map((s) => s.ref));
42662
42713
  const livePid = (ref, pid) => live.some((s) => s.ref === ref && s.pid === pid);
42663
42714
  for (const s of live) {
@@ -42670,7 +42721,7 @@ async function runDaemon(deps2 = {}) {
42670
42721
  prev.pid = s.pid;
42671
42722
  prev.procStart = s.procStart;
42672
42723
  }
42673
- renameIfChanged(prev, s.name);
42724
+ renameIfChanged(prev, s.name, s.pid);
42674
42725
  continue;
42675
42726
  }
42676
42727
  if (prev && prev.pid === s.pid) continue;
@@ -42814,9 +42865,15 @@ async function runDaemon(deps2 = {}) {
42814
42865
  return;
42815
42866
  case "error": {
42816
42867
  if (statusRelay.answer(frame)) return;
42817
- const renamedRef = renameIds.get(frame.id);
42818
- if (renamedRef !== void 0) {
42868
+ const renamed = renameIds.get(frame.id);
42869
+ if (renamed !== void 0) {
42870
+ const renamedRef = renamed.ref;
42819
42871
  renameIds.delete(frame.id);
42872
+ if (frame.code === "rate_limited") {
42873
+ renameHeldUntil.set(renamedRef, Date.now() + RENAME_HOLD_MS);
42874
+ const a = agents.byRef(renamedRef);
42875
+ if (a) a.sentName = renamed.prevSent;
42876
+ }
42820
42877
  log(
42821
42878
  `the hub did not rename ${renamedRef} to its session name: ${frame.code} ${frame.message}`
42822
42879
  );
@@ -43057,7 +43114,7 @@ async function runDaemon(deps2 = {}) {
43057
43114
  const pid = check2.pid ?? hello.pid;
43058
43115
  const prev = agents.byRef(hello.agent_ref);
43059
43116
  if (prev?.live && prev.kind === "claude-code" && prev.pid !== pid) {
43060
- const live = liveClaudeSessions(claudeSessions).filter(
43117
+ const live = liveClaudeFiles(claudeSessions).filter(
43061
43118
  (s) => s.ref === prev.ref
43062
43119
  );
43063
43120
  if (live.some((s) => s.pid === pid) && !live.some((s) => s.pid === prev.pid))
@@ -43099,7 +43156,10 @@ async function runDaemon(deps2 = {}) {
43099
43156
  };
43100
43157
  attested(pid);
43101
43158
  const proposedName = hello.proposed_name ?? hello.agent_ref;
43102
- const files2 = hello.kind === "claude-code" ? liveClaudeSessions(claudeSessions) : [];
43159
+ const files2 = hello.kind === "claude-code" ? liveClaudeSessions(
43160
+ claudeSessions,
43161
+ (r) => r === hello.agent_ref ? pid : agents.byRef(r)?.pid
43162
+ ) : [];
43103
43163
  const mine = files2.find(
43104
43164
  (x) => x.ref === hello.agent_ref && x.pid === pid
43105
43165
  );
@@ -43255,6 +43315,7 @@ async function runDaemon(deps2 = {}) {
43255
43315
  if (closed) announceSessions();
43256
43316
  };
43257
43317
  const sync = () => {
43318
+ for (const rec of agents.all()) if (rec.live) flushRename(rec);
43258
43319
  for (const [what, fn] of [
43259
43320
  ["claude", syncClaude],
43260
43321
  ["opencode", syncOpenCode],
@@ -43405,6 +43466,7 @@ var KIND_LABEL = {
43405
43466
  pi: "Pi",
43406
43467
  omp: "oh-my-pi",
43407
43468
  hermes: "Hermes",
43469
+ openclaw: "OpenClaw",
43408
43470
  codex: "Codex"
43409
43471
  };
43410
43472
  var kindLabel = (kind3) => Object.hasOwn(KIND_LABEL, kind3) ? KIND_LABEL[kind3] : displayKind(kind3);
@@ -45592,7 +45654,7 @@ var noService = {
45592
45654
  remove: async () => ({}),
45593
45655
  cli: () => ["oa-bus"]
45594
45656
  };
45595
- var VERSION = true ? "0.134.0" : JSON.parse(
45657
+ var VERSION = true ? "0.135.0" : JSON.parse(
45596
45658
  readFileSync13(new URL("../package.json", import.meta.url), "utf8")
45597
45659
  ).version;
45598
45660
  var which = (cmd) => {
@@ -47096,7 +47158,9 @@ import {
47096
47158
  mkdirSync as mkdirSync9,
47097
47159
  readdirSync as readdirSync4,
47098
47160
  readFileSync as readFileSync15,
47161
+ realpathSync as realpathSync8,
47099
47162
  renameSync as renameSync9,
47163
+ rmdirSync,
47100
47164
  rmSync as rmSync5,
47101
47165
  writeFileSync as writeFileSync7
47102
47166
  } from "node:fs";
@@ -47112,6 +47176,57 @@ var HERMES_PLUGIN_NAME = "oa-bus";
47112
47176
  var HERMES_MARKER = ".oa-bus-managed";
47113
47177
  var HERMES_NO_CLI = "no hermes binary found; its config may still list oa-bus";
47114
47178
  var HERMES_STAGING = ".oa-bus-staging";
47179
+ var real2 = (p) => {
47180
+ const rest = [];
47181
+ let cur = p;
47182
+ for (; ; ) {
47183
+ try {
47184
+ return join17(realpathSync8(cur), ...rest.reverse());
47185
+ } catch {
47186
+ const up = dirname9(cur);
47187
+ if (up === cur) return p;
47188
+ rest.push(basename7(cur));
47189
+ cur = up;
47190
+ }
47191
+ }
47192
+ };
47193
+ var STAGING_STALE_MS = 10 * 60 * 1e3;
47194
+ var STAGE_NAME = /^(\d+)-[0-9a-f]+$/;
47195
+ function pidAlive(pid) {
47196
+ try {
47197
+ process.kill(pid, 0);
47198
+ return true;
47199
+ } catch (e) {
47200
+ return e.code === "EPERM";
47201
+ }
47202
+ }
47203
+ function sweepStaging(staging, own2, o = {}) {
47204
+ const now = o.now ?? Date.now();
47205
+ const alive2 = o.alive ?? pidAlive;
47206
+ let names2;
47207
+ try {
47208
+ names2 = readdirSync4(staging);
47209
+ } catch {
47210
+ return;
47211
+ }
47212
+ for (const name of names2) {
47213
+ if (name === own2) continue;
47214
+ const path = join17(staging, name);
47215
+ let old;
47216
+ try {
47217
+ old = now - lstatSync9(path).mtimeMs > STAGING_STALE_MS;
47218
+ } catch {
47219
+ continue;
47220
+ }
47221
+ const m = STAGE_NAME.exec(name);
47222
+ if (m ? old || !alive2(Number(m[1])) : old) {
47223
+ try {
47224
+ rmSync5(path, { recursive: true, force: true });
47225
+ } catch {
47226
+ }
47227
+ }
47228
+ }
47229
+ }
47115
47230
  var tilded = (home2, v) => v === "~" ? home2 : resolve5(v.startsWith("~/") ? join17(home2, v.slice(2)) : v);
47116
47231
  function hermesHome(home2, env2) {
47117
47232
  const native = join17(home2, ".hermes");
@@ -47122,7 +47237,7 @@ function hermesHome(home2, env2) {
47122
47237
  const base3 = given ?? native;
47123
47238
  const root = (() => {
47124
47239
  if (given === void 0) return native;
47125
- const rel = relative(native, given);
47240
+ const rel = relative(real2(native), real2(given));
47126
47241
  if (rel === "" || !rel.startsWith("..") && !isAbsolute9(rel))
47127
47242
  return native;
47128
47243
  return given;
@@ -47218,11 +47333,17 @@ async function installHermes(deps2) {
47218
47333
  const plugins2 = join17(dest, "..");
47219
47334
  mkdirSync9(plugins2, { recursive: true });
47220
47335
  const staging = join17(plugins2, "..", HERMES_STAGING);
47221
- rmSync5(staging, { recursive: true, force: true });
47336
+ const own2 = `${process.pid}-${randomBytes3(4).toString("hex")}`;
47337
+ const st = lstatSync9(staging, { throwIfNoEntry: false });
47338
+ if (st !== void 0 && !st.isDirectory())
47339
+ throw new Error(
47340
+ `${staging} is not a plain folder; remove it and run the install again`
47341
+ );
47222
47342
  mkdirSync9(staging, { recursive: true });
47223
- const tmp = join17(staging, randomBytes3(4).toString("hex"));
47343
+ sweepStaging(staging, own2, deps2.staging);
47344
+ const tmp = join17(staging, own2);
47224
47345
  try {
47225
- mkdirSync9(tmp);
47346
+ mkdirSync9(tmp, { recursive: true });
47226
47347
  for (const f of files(shipped)) {
47227
47348
  mkdirSync9(join17(tmp, f, ".."), { recursive: true });
47228
47349
  cpSync2(join17(shipped, f), join17(tmp, f));
@@ -47238,7 +47359,10 @@ async function installHermes(deps2) {
47238
47359
  rmSync5(tmp, { recursive: true, force: true });
47239
47360
  throw e;
47240
47361
  } finally {
47241
- rmSync5(staging, { recursive: true, force: true });
47362
+ try {
47363
+ rmdirSync(staging);
47364
+ } catch {
47365
+ }
47242
47366
  }
47243
47367
  }
47244
47368
  if (await hermesEnabled(deps2)) return "done";
@@ -47825,7 +47949,7 @@ import {
47825
47949
  existsSync as existsSync7,
47826
47950
  lstatSync as lstatSync12,
47827
47951
  readFileSync as readFileSync18,
47828
- realpathSync as realpathSync9,
47952
+ realpathSync as realpathSync10,
47829
47953
  rmSync as rmSync8
47830
47954
  } from "node:fs";
47831
47955
  import { join as join20, resolve as resolve7, sep as sep2 } from "node:path";
@@ -47838,9 +47962,9 @@ import {
47838
47962
  mkdirSync as mkdirSync11,
47839
47963
  readdirSync as readdirSync5,
47840
47964
  readFileSync as readFileSync17,
47841
- realpathSync as realpathSync8,
47965
+ realpathSync as realpathSync9,
47842
47966
  renameSync as renameSync11,
47843
- rmdirSync,
47967
+ rmdirSync as rmdirSync2,
47844
47968
  rmSync as rmSync7,
47845
47969
  statSync as statSync10,
47846
47970
  writeFileSync as writeFileSync9
@@ -47950,7 +48074,7 @@ async function fetchSkillText(doFetch, url2) {
47950
48074
  }
47951
48075
  var targetOf = (path) => {
47952
48076
  try {
47953
- return lstatSync11(path).isSymbolicLink() ? realpathSync8(path) : path;
48077
+ return lstatSync11(path).isSymbolicLink() ? realpathSync9(path) : path;
47954
48078
  } catch {
47955
48079
  return path;
47956
48080
  }
@@ -48118,7 +48242,7 @@ var uninstallSkill = (deps2, harnesses = ["claude", "opencode", "pi", "omp", "co
48118
48242
  }
48119
48243
  rmSync7(targetOf(file2), { force: true });
48120
48244
  try {
48121
- rmdirSync(dir);
48245
+ rmdirSync2(dir);
48122
48246
  } catch {
48123
48247
  }
48124
48248
  written.push(file2);
@@ -48247,8 +48371,8 @@ var isLink = (path) => {
48247
48371
  function linkInfo(deps2, path) {
48248
48372
  try {
48249
48373
  if (!isLink(path)) return void 0;
48250
- const target2 = realpathSync9(path);
48251
- const homes = [deps2.home, realpathSync9(deps2.home)];
48374
+ const target2 = realpathSync10(path);
48375
+ const homes = [deps2.home, realpathSync10(deps2.home)];
48252
48376
  return {
48253
48377
  target: target2,
48254
48378
  outside: !homes.some((h) => target2.startsWith(`${h}${sep2}`))
@@ -48299,13 +48423,13 @@ function writeHabits(deps2, harnesses, opts = {}) {
48299
48423
  );
48300
48424
  continue;
48301
48425
  }
48302
- const real2 = targetOf(path);
48426
+ const real3 = targetOf(path);
48303
48427
  try {
48304
- const exists = existsSync7(real2);
48305
- const before = exists ? readFileSync18(real2, "utf8") : "";
48428
+ const exists = existsSync7(real3);
48429
+ const before = exists ? readFileSync18(real3, "utf8") : "";
48306
48430
  const fresh = blockState(before).state === "absent";
48307
48431
  const after = withHabits(before, habitsBlock());
48308
- if (after !== before) writeAtomic2(real2, after);
48432
+ if (after !== before) writeAtomic2(real3, after);
48309
48433
  if (fresh)
48310
48434
  files_[path] = {
48311
48435
  added: separatorFor(before),
@@ -48332,14 +48456,14 @@ function removeHabits(deps2, harnesses = HABITS_HARNESSES) {
48332
48456
  seen2.add(path);
48333
48457
  try {
48334
48458
  if (brokenLink(path) || !existsSync7(path)) continue;
48335
- const real2 = targetOf(path);
48336
- const before = readFileSync18(real2, "utf8");
48459
+ const real3 = targetOf(path);
48460
+ const before = readFileSync18(real3, "utf8");
48337
48461
  if (blockState(before).state === "absent") continue;
48338
48462
  const rec = kept[path];
48339
48463
  const after = withHabits(before, null, rec?.added);
48340
48464
  if (rec?.created && !isLink(path) && after.trim() === "")
48341
- rmSync8(real2, { force: true });
48342
- else writeAtomic2(real2, after);
48465
+ rmSync8(real3, { force: true });
48466
+ else writeAtomic2(real3, after);
48343
48467
  delete kept[path];
48344
48468
  files2.push(path);
48345
48469
  } catch (e) {
@@ -48987,10 +49111,10 @@ async function skippedLines(ctx, h, reason2) {
48987
49111
  }
48988
49112
  function shownSocket(ctx) {
48989
49113
  const path = daemonSocketPath(ctx.home);
48990
- const real2 = `${canonicalHome(ctx.home)}/`;
49114
+ const real3 = `${canonicalHome(ctx.home)}/`;
48991
49115
  return tilde(
48992
49116
  ctx,
48993
- path.startsWith(real2) ? join22(ctx.home, path.slice(real2.length)) : path
49117
+ path.startsWith(real3) ? join22(ctx.home, path.slice(real3.length)) : path
48994
49118
  );
48995
49119
  }
48996
49120
  async function waitForDaemon(ctx) {
@@ -49481,13 +49605,13 @@ async function doctor(ctx) {
49481
49605
  }
49482
49606
 
49483
49607
  // src/commands/global.ts
49484
- import { realpathSync as realpathSync10, statSync as statSync11 } from "node:fs";
49608
+ import { realpathSync as realpathSync11, statSync as statSync11 } from "node:fs";
49485
49609
  import { resolve as resolve8 } from "node:path";
49486
49610
  function shown2(ctx, path) {
49487
49611
  const t = tilde(ctx, path);
49488
49612
  if (t !== path) return t;
49489
49613
  try {
49490
- return tilde({ userHome: realpathSync10(ctx.userHome) }, path);
49614
+ return tilde({ userHome: realpathSync11(ctx.userHome) }, path);
49491
49615
  } catch {
49492
49616
  return path;
49493
49617
  }
@@ -49509,33 +49633,33 @@ async function global(opts, ctx) {
49509
49633
  return 0;
49510
49634
  }
49511
49635
  const given = resolve8(ctx.cwd, opts.dir);
49512
- let real2;
49636
+ let real3;
49513
49637
  try {
49514
- real2 = canonicalPath(given);
49638
+ real3 = canonicalPath(given);
49515
49639
  } catch {
49516
49640
  }
49517
49641
  if (opts.sub === "add") {
49518
- if (!real2 || !statSync11(real2).isDirectory()) {
49519
- sayErr(ctx, c.globalNotDir(shown2(ctx, real2 ?? given)));
49642
+ if (!real3 || !statSync11(real3).isDirectory()) {
49643
+ sayErr(ctx, c.globalNotDir(shown2(ctx, real3 ?? given)));
49520
49644
  return 1;
49521
49645
  }
49522
- if (isGlobalDir(real2, dirs)) {
49523
- say(ctx, c.globalAlready(shown2(ctx, real2)));
49646
+ if (isGlobalDir(real3, dirs)) {
49647
+ say(ctx, c.globalAlready(shown2(ctx, real3)));
49524
49648
  return 0;
49525
49649
  }
49526
- writeGlobalDirs([...dirs, real2], ctx.home);
49527
- say(ctx, c.globalAdded(shown2(ctx, real2)));
49650
+ writeGlobalDirs([...dirs, real3], ctx.home);
49651
+ say(ctx, c.globalAdded(shown2(ctx, real3)));
49528
49652
  return 0;
49529
49653
  }
49530
49654
  const keep = dirs.filter(
49531
- (d) => d !== given && d !== real2 && !(real2 && sameDir(d, real2))
49655
+ (d) => d !== given && d !== real3 && !(real3 && sameDir(d, real3))
49532
49656
  );
49533
49657
  if (keep.length === dirs.length) {
49534
- say(ctx, c.globalNotListed(shown2(ctx, real2 ?? given)));
49658
+ say(ctx, c.globalNotListed(shown2(ctx, real3 ?? given)));
49535
49659
  return 0;
49536
49660
  }
49537
49661
  writeGlobalDirs(keep, ctx.home);
49538
- say(ctx, c.globalRemoved(shown2(ctx, real2 ?? given)));
49662
+ say(ctx, c.globalRemoved(shown2(ctx, real3 ?? given)));
49539
49663
  return 0;
49540
49664
  }
49541
49665
 
@@ -49546,13 +49670,13 @@ init_src();
49546
49670
  function side(ctx, dir) {
49547
49671
  const given = resolve9(ctx.cwd, dir);
49548
49672
  try {
49549
- const real2 = canonicalPath(given);
49550
- if (!statSync12(real2).isDirectory()) return void 0;
49551
- const ns = resolveNamespace(real2, {
49673
+ const real3 = canonicalPath(given);
49674
+ if (!statSync12(real3).isDirectory()) return void 0;
49675
+ const ns = resolveNamespace(real3, {
49552
49676
  globalFile: globalFile(ctx.home),
49553
49677
  namespacesFile: namespacesFile(ctx.home)
49554
49678
  });
49555
- return { dir: real2, namespace: ns.namespace };
49679
+ return { dir: real3, namespace: ns.namespace };
49556
49680
  } catch {
49557
49681
  return void 0;
49558
49682
  }
@@ -49666,14 +49790,14 @@ async function mcp(harness, ctx, load = (h) => MCP_SERVER[h]()) {
49666
49790
  }
49667
49791
 
49668
49792
  // src/commands/namespace.ts
49669
- import { realpathSync as realpathSync11, statSync as statSync13 } from "node:fs";
49793
+ import { realpathSync as realpathSync12, statSync as statSync13 } from "node:fs";
49670
49794
  import { join as join25, resolve as resolve10 } from "node:path";
49671
49795
  init_src();
49672
49796
  function shown3(ctx, path) {
49673
49797
  const t = tilde(ctx, path);
49674
49798
  if (t !== path) return t;
49675
49799
  try {
49676
- return tilde({ userHome: realpathSync11(ctx.userHome) }, path);
49800
+ return tilde({ userHome: realpathSync12(ctx.userHome) }, path);
49677
49801
  } catch {
49678
49802
  return path;
49679
49803
  }
@@ -49695,17 +49819,17 @@ async function namespace(opts, ctx) {
49695
49819
  return 0;
49696
49820
  }
49697
49821
  const given = resolve10(ctx.cwd, opts.dir);
49698
- let real2;
49822
+ let real3;
49699
49823
  try {
49700
- real2 = canonicalPath(given);
49824
+ real3 = canonicalPath(given);
49701
49825
  } catch {
49702
49826
  }
49703
49827
  if (opts.sub === "revoke") {
49704
49828
  const keep = entries.filter(
49705
- (e) => e.dir !== given && e.dir !== real2 && !(real2 && sameDir(e.dir, real2))
49829
+ (e) => e.dir !== given && e.dir !== real3 && !(real3 && sameDir(e.dir, real3))
49706
49830
  );
49707
49831
  if (keep.length === entries.length) {
49708
- say(ctx, c.nsNotListed(shown3(ctx, real2 ?? given)));
49832
+ say(ctx, c.nsNotListed(shown3(ctx, real3 ?? given)));
49709
49833
  return 0;
49710
49834
  }
49711
49835
  writeApprovals(keep, ctx.home);
@@ -49714,19 +49838,19 @@ async function namespace(opts, ctx) {
49714
49838
  { action: "revoke", ...e, tty: Boolean(ctx.stdinIsTTY) },
49715
49839
  ctx.home
49716
49840
  );
49717
- say(ctx, c.nsRevoked(shown3(ctx, real2 ?? given)));
49841
+ say(ctx, c.nsRevoked(shown3(ctx, real3 ?? given)));
49718
49842
  return 0;
49719
49843
  }
49720
- if (!real2 || !statSync13(real2).isDirectory()) {
49721
- sayErr(ctx, c.nsNotDir(shown3(ctx, real2 ?? given)));
49844
+ if (!real3 || !statSync13(real3).isDirectory()) {
49845
+ sayErr(ctx, c.nsNotDir(shown3(ctx, real3 ?? given)));
49722
49846
  return 1;
49723
49847
  }
49724
- const cfgFile = join25(real2, CONFIG_FILE);
49848
+ const cfgFile = join25(real3, CONFIG_FILE);
49725
49849
  const own2 = readOwnFile(cfgFile, process.getuid?.(), {
49726
49850
  allowGroupWrite: true
49727
49851
  });
49728
49852
  if (own2.state === "none") {
49729
- sayErr(ctx, c.nsNoFile(shown3(ctx, real2)));
49853
+ sayErr(ctx, c.nsNoFile(shown3(ctx, real3)));
49730
49854
  return 1;
49731
49855
  }
49732
49856
  if (own2.state === "unsafe") {
@@ -49743,16 +49867,16 @@ async function namespace(opts, ctx) {
49743
49867
  say(ctx, c.nsNoNamespace(shown3(ctx, cfgFile)));
49744
49868
  return 1;
49745
49869
  }
49746
- if (isApproved(real2, ns, entries)) {
49747
- say(ctx, c.nsAlready(shown3(ctx, real2), plain2(ns)));
49870
+ if (isApproved(real3, ns, entries)) {
49871
+ say(ctx, c.nsAlready(shown3(ctx, real3), plain2(ns)));
49748
49872
  return 0;
49749
49873
  }
49750
49874
  if (!opts.yes) {
49751
49875
  if (!ctx.stdinIsTTY || !ctx.readLine) {
49752
- sayErr(ctx, c.nsNeedTty(approveCommand(real2)));
49876
+ sayErr(ctx, c.nsNeedTty(approveCommand(real3)));
49753
49877
  return 1;
49754
49878
  }
49755
- say(ctx, c.nsAsk(shown3(ctx, real2), plain2(ns)));
49879
+ say(ctx, c.nsAsk(shown3(ctx, real3), plain2(ns)));
49756
49880
  const answer = (await ctx.readLine(c.nsPrompt())).trim().toLowerCase();
49757
49881
  if (answer !== "y" && answer !== "yes") {
49758
49882
  say(ctx, c.nsDeclined());
@@ -49760,20 +49884,20 @@ async function namespace(opts, ctx) {
49760
49884
  }
49761
49885
  }
49762
49886
  const next = [
49763
- ...entries.filter((e) => !sameDir(e.dir, real2)),
49764
- { dir: real2, namespace: ns }
49887
+ ...entries.filter((e) => !sameDir(e.dir, real3)),
49888
+ { dir: real3, namespace: ns }
49765
49889
  ];
49766
49890
  writeApprovals(next, ctx.home);
49767
49891
  logApproval(
49768
49892
  {
49769
49893
  action: "approve",
49770
- dir: real2,
49894
+ dir: real3,
49771
49895
  namespace: ns,
49772
49896
  tty: Boolean(ctx.stdinIsTTY)
49773
49897
  },
49774
49898
  ctx.home
49775
49899
  );
49776
- say(ctx, c.nsApproved(shown3(ctx, real2), plain2(ns)));
49900
+ say(ctx, c.nsApproved(shown3(ctx, real3), plain2(ns)));
49777
49901
  return 0;
49778
49902
  }
49779
49903
 
@@ -49782,7 +49906,7 @@ import { join as join27 } from "node:path";
49782
49906
 
49783
49907
  // src/steps/purge.ts
49784
49908
  init_src3();
49785
- import { lstatSync as lstatSync13, readdirSync as readdirSync6, rmdirSync as rmdirSync2, rmSync as rmSync10 } from "node:fs";
49909
+ import { lstatSync as lstatSync13, readdirSync as readdirSync6, rmdirSync as rmdirSync3, rmSync as rmSync10 } from "node:fs";
49786
49910
  import { join as join26 } from "node:path";
49787
49911
  var FILES = [
49788
49912
  "machine.json",
@@ -49824,7 +49948,7 @@ function kind2(path) {
49824
49948
  var remove2 = (path, k) => rmSync10(path, { recursive: k === "dir", force: true });
49825
49949
  var rmdirIfEmpty = (path) => {
49826
49950
  try {
49827
- rmdirSync2(path);
49951
+ rmdirSync3(path);
49828
49952
  return true;
49829
49953
  } catch {
49830
49954
  return false;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@open-artifacts/bus",
3
3
  "type": "module",
4
- "version": "0.134.0",
4
+ "version": "0.135.0",
5
5
  "description": "The Open Artifacts bus: your AI agents reach each other across machines.",
6
6
  "license": "MIT",
7
7
  "repository": {