@open-artifacts/bus 0.162.1 → 0.163.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.162.1";
14
+ const CLIENT_VERSION = "0.163.0";
15
15
 
16
16
  type Frame = Json & { type: string; id: string };
17
17
  type Ctx = {
@@ -27493,6 +27493,11 @@ var WaitingCounts = external_exports.strictObject({
27493
27493
  type: external_exports.literal("waiting_counts"),
27494
27494
  counts: external_exports.record(AgentRefSchema, external_exports.number().int().min(1).max(100)).refine((c) => Object.keys(c).length <= MAX_WAITING_QUERY, "too many refs")
27495
27495
  });
27496
+ var Acked = external_exports.strictObject({
27497
+ ...base,
27498
+ type: external_exports.literal("acked"),
27499
+ msg_id: MsgIdSchema
27500
+ });
27496
27501
  var MAX_FOLLOWS = 200;
27497
27502
  var FollowEntry = external_exports.strictObject({
27498
27503
  artifact_id: external_exports.string().min(1).max(64),
@@ -27672,7 +27677,8 @@ var ServerFrameSchema = external_exports.discriminatedUnion("type", [
27672
27677
  Unfollowed,
27673
27678
  Follows,
27674
27679
  LinkBound,
27675
- WaitingCounts
27680
+ WaitingCounts,
27681
+ Acked
27676
27682
  ]);
27677
27683
  var FrameSchema = external_exports.discriminatedUnion("type", [
27678
27684
  Hello,
@@ -27705,7 +27711,8 @@ var FrameSchema = external_exports.discriminatedUnion("type", [
27705
27711
  Unfollowed,
27706
27712
  Follows,
27707
27713
  LinkBound,
27708
- WaitingCounts
27714
+ WaitingCounts,
27715
+ Acked
27709
27716
  ]);
27710
27717
  var MAX_RAW_FRAME_CHARS = 2 * LIMITS.maxMessageBytes + 4096;
27711
27718
 
@@ -27724,7 +27731,7 @@ var base2 = { v: external_exports.literal(V), id: external_exports.string().min(
27724
27731
  var late = { late: external_exports.array(external_exports.string().min(1)).optional() };
27725
27732
  var isWellFormed2 = (s) => s.isWellFormed();
27726
27733
  var WELL_FORMED = { message: "text is not well-formed unicode" };
27727
- var CLIENT_VERSION = true ? "0.162.1" : "0.0.0";
27734
+ var CLIENT_VERSION = true ? "0.163.0" : "0.0.0";
27728
27735
  var clientVersion = {
27729
27736
  client_version: external_exports.string().min(1).max(64).optional()
27730
27737
  };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oa-bus",
3
- "version": "0.162.1",
3
+ "version": "0.163.0",
4
4
  "type": "module",
5
5
  "openclaw": {
6
6
  "extensions": [
package/dist/index.js CHANGED
@@ -20559,7 +20559,16 @@ var init_caps = __esm({
20559
20559
  * not delivered, until that ack. A socket without it keeps today's rule:
20560
20560
  * accepted by the socket is delivered.
20561
20561
  */
20562
- noticeAck: "notice_ack"
20562
+ noticeAck: "notice_ack",
20563
+ /**
20564
+ * Confirmed acks (#2198): a mail `ack` from a socket listing it is answered
20565
+ * by `acked {msg_id}` once the hub has durably settled the receipt, or, for
20566
+ * an id that can no longer settle (a repeat, unknown, not this machine's),
20567
+ * by the same opaque frame. Only on the link the ack came in on. Notice
20568
+ * acks are not answered. A daemon listing it keeps an ack record until the
20569
+ * hub confirmed it, and sends it again on a new link otherwise.
20570
+ */
20571
+ ackConfirm: "ack_confirm"
20563
20572
  };
20564
20573
  MAX_CAPS = 16;
20565
20574
  CapTokenSchema = external_exports.string().regex(/^[a-z][a-z0-9_-]{0,31}$/);
@@ -21319,7 +21328,7 @@ function decode3(raw, schema, caps) {
21319
21328
  function decodeServerFrame(raw) {
21320
21329
  return decode3(raw, ServerFrameSchema, SERVER_CAPS);
21321
21330
  }
21322
- var PING, PONG, isWellFormed, WellFormedText, FrameIdSchema, base, BodySchema, InlineBodySchema, distinct, Hello, AgentUp, AgentDown, Sessions, Send, Ack, Refuse, List, Fetch, Status, Rename, FollowRefSchema, Follow, Unfollow, Following, LINK_PROOF_HEADER, LinkProofSchema, LinkProofHashSchema, LinkBind, LinkBound, MAX_WAITING_QUERY, WaitingQuery, WaitingCounts, MAX_FOLLOWS, FollowEntry, Followed, Unfollowed, Follows, HelloOk, AgentOk, Renamed, ReceiptFrame, RosterAgent, Roster, BodyFrame, AGENT_CAP_MESSAGES, ErrorFrame, Notice, Deliver, ReceiptUpdate, RosterChanged, ClientFrameSchema, ServerFrameSchema, FrameSchema, MAX_RAW_FRAME_CHARS, SERVER_CAPS, MAX_OBJECT_TOKENS, ID_PREFIX_RE;
21331
+ var PING, PONG, isWellFormed, WellFormedText, FrameIdSchema, base, BodySchema, InlineBodySchema, distinct, Hello, AgentUp, AgentDown, Sessions, Send, Ack, Refuse, List, Fetch, Status, Rename, FollowRefSchema, Follow, Unfollow, Following, LINK_PROOF_HEADER, LinkProofSchema, LinkProofHashSchema, LinkBind, LinkBound, MAX_WAITING_QUERY, WaitingQuery, WaitingCounts, Acked, MAX_FOLLOWS, FollowEntry, Followed, Unfollowed, Follows, HelloOk, AgentOk, Renamed, ReceiptFrame, RosterAgent, Roster, BodyFrame, AGENT_CAP_MESSAGES, ErrorFrame, Notice, Deliver, ReceiptUpdate, RosterChanged, ClientFrameSchema, ServerFrameSchema, FrameSchema, MAX_RAW_FRAME_CHARS, SERVER_CAPS, MAX_OBJECT_TOKENS, ID_PREFIX_RE;
21323
21332
  var init_protocol = __esm({
21324
21333
  "../bus-protocol/src/protocol.ts"() {
21325
21334
  "use strict";
@@ -21497,6 +21506,11 @@ var init_protocol = __esm({
21497
21506
  type: external_exports.literal("waiting_counts"),
21498
21507
  counts: external_exports.record(AgentRefSchema, external_exports.number().int().min(1).max(100)).refine((c) => Object.keys(c).length <= MAX_WAITING_QUERY, "too many refs")
21499
21508
  });
21509
+ Acked = external_exports.strictObject({
21510
+ ...base,
21511
+ type: external_exports.literal("acked"),
21512
+ msg_id: MsgIdSchema
21513
+ });
21500
21514
  MAX_FOLLOWS = 200;
21501
21515
  FollowEntry = external_exports.strictObject({
21502
21516
  artifact_id: external_exports.string().min(1).max(64),
@@ -21680,7 +21694,8 @@ var init_protocol = __esm({
21680
21694
  Unfollowed,
21681
21695
  Follows,
21682
21696
  LinkBound,
21683
- WaitingCounts
21697
+ WaitingCounts,
21698
+ Acked
21684
21699
  ]);
21685
21700
  FrameSchema = external_exports.discriminatedUnion("type", [
21686
21701
  Hello,
@@ -21713,7 +21728,8 @@ var init_protocol = __esm({
21713
21728
  Unfollowed,
21714
21729
  Follows,
21715
21730
  LinkBound,
21716
- WaitingCounts
21731
+ WaitingCounts,
21732
+ Acked
21717
21733
  ]);
21718
21734
  MAX_RAW_FRAME_CHARS = 2 * LIMITS.maxMessageBytes + 4096;
21719
21735
  SERVER_CAPS = { depth: 5, tokens: 65536, structural: 131072 };
@@ -21787,7 +21803,7 @@ var init_frames = __esm({
21787
21803
  late = { late: external_exports.array(external_exports.string().min(1)).optional() };
21788
21804
  isWellFormed2 = (s) => s.isWellFormed();
21789
21805
  WELL_FORMED = { message: "text is not well-formed unicode" };
21790
- CLIENT_VERSION = true ? "0.162.1" : "0.0.0";
21806
+ CLIENT_VERSION = true ? "0.163.0" : "0.0.0";
21791
21807
  clientVersion = {
21792
21808
  client_version: external_exports.string().min(1).max(64).optional()
21793
21809
  };
@@ -42460,6 +42476,44 @@ import {
42460
42476
  } from "node:fs";
42461
42477
  import { dirname as dirname4, join as join9 } from "node:path";
42462
42478
  var NOTICE_WATCH_MS = 6 * 60 * 60 * 1e3;
42479
+ var AckTracker = class {
42480
+ constructor(max = 1e3, ttlMs = 5 * 6e4, now = Date.now) {
42481
+ this.max = max;
42482
+ this.ttlMs = ttlMs;
42483
+ this.now = now;
42484
+ }
42485
+ max;
42486
+ ttlMs;
42487
+ now;
42488
+ #m = /* @__PURE__ */ new Map();
42489
+ get size() {
42490
+ return this.#m.size;
42491
+ }
42492
+ track(frameId2, msg) {
42493
+ const t = this.now();
42494
+ for (const [k, v] of this.#m) {
42495
+ if (t - v.at <= this.ttlMs) break;
42496
+ this.#m.delete(k);
42497
+ }
42498
+ this.#m.set(frameId2, { msg, at: t });
42499
+ while (this.#m.size > this.max) {
42500
+ const oldest = this.#m.keys().next().value;
42501
+ if (oldest === void 0) break;
42502
+ this.#m.delete(oldest);
42503
+ }
42504
+ }
42505
+ /** The msg_id this frame id acked, once: undefined when unknown, evicted or expired. */
42506
+ take(frameId2) {
42507
+ const v = this.#m.get(frameId2);
42508
+ if (!v) return void 0;
42509
+ this.#m.delete(frameId2);
42510
+ return this.now() - v.at <= this.ttlMs ? v.msg : void 0;
42511
+ }
42512
+ clear() {
42513
+ this.#m.clear();
42514
+ }
42515
+ };
42516
+ var CONFIRM_SAVE_MS = 250;
42463
42517
  var TAKEN_SCAN_BUDGET = 2 * 1024 * 1024;
42464
42518
  var snap = (r) => ({
42465
42519
  state: r.state,
@@ -42512,6 +42566,19 @@ function userTexts(line) {
42512
42566
  var startsWithHead = (text3, head) => text3.startsWith(`${head}
42513
42567
 
42514
42568
  `);
42569
+ function replayAcks(ids, send, live, room, after = (fn) => {
42570
+ setTimeout(fn, 1e3).unref();
42571
+ }) {
42572
+ let i = 0;
42573
+ const step2 = () => {
42574
+ if (!live()) return;
42575
+ const n = Math.max(0, room());
42576
+ for (const id of ids.slice(i, i + n)) send(id);
42577
+ i += n;
42578
+ if (i < ids.length) after(step2);
42579
+ };
42580
+ step2();
42581
+ }
42515
42582
  var TakenWatch = class {
42516
42583
  constructor(opts) {
42517
42584
  this.opts = opts;
@@ -42532,6 +42599,8 @@ var TakenWatch = class {
42532
42599
  /** Ids (or `maybe:<id>`) an earlier build's marker file lists. */
42533
42600
  #legacy = /* @__PURE__ */ new Set();
42534
42601
  #now;
42602
+ /** A confirmation save waiting for its tick. */
42603
+ #pending;
42535
42604
  /** The record's state, or none. */
42536
42605
  state(id) {
42537
42606
  return this.#recs.get(id)?.state ?? (this.#legacy.has(id) || this.#legacy.has(`maybe:${id}`) ? "queued" : void 0);
@@ -42638,6 +42707,37 @@ var TakenWatch = class {
42638
42707
  this.#save();
42639
42708
  return atEof ? "missing" : "pending";
42640
42709
  }
42710
+ /**
42711
+ * Ids of `taken` records within retention whose ack the hub has not
42712
+ * confirmed, newest first. A new link with BUS_CAPS.ackConfirm sends them
42713
+ * again: `acked` only means the frame was queued locally, which proves
42714
+ * nothing about the hub. The hub's ack is idempotent.
42715
+ */
42716
+ unconfirmedIds() {
42717
+ const now = this.#now();
42718
+ const out = [];
42719
+ for (const [id, r] of this.#recs)
42720
+ if (r.state === "taken" && r.head !== void 0 && r.confirmed !== true && now - r.at <= (r.ttlMs ?? this.opts.ttlMs ?? MAILBOX_RETAIN_MS))
42721
+ out.push([id, r.at]);
42722
+ return out.sort((a, b) => b[1] - a[1]).map(([id]) => id);
42723
+ }
42724
+ /** The hub confirmed the ack of `id`: done, never sent again. */
42725
+ confirm(id) {
42726
+ const r = this.#recs.get(id);
42727
+ if (!r || r.state !== "taken" || r.confirmed) return;
42728
+ r.confirmed = true;
42729
+ r.acked = true;
42730
+ if (this.#pending) return;
42731
+ this.#pending = setTimeout(() => this.flush(), CONFIRM_SAVE_MS);
42732
+ this.#pending.unref();
42733
+ }
42734
+ /** Writes the coalesced confirmations now (a stop calls it). */
42735
+ flush() {
42736
+ if (!this.#pending) return;
42737
+ clearTimeout(this.#pending);
42738
+ this.#pending = void 0;
42739
+ this.#save();
42740
+ }
42641
42741
  /** Reads each watched record's new rollout lines; acks what a turn took. */
42642
42742
  check() {
42643
42743
  if (!this.#recs.size) return;
@@ -42684,9 +42784,15 @@ var TakenWatch = class {
42684
42784
  let acked = false;
42685
42785
  for (const id of taken) {
42686
42786
  try {
42687
- this.opts.onTaken(id);
42787
+ const sent = this.opts.onTaken(id, () => {
42788
+ const r2 = this.#recs.get(id);
42789
+ if (r2?.acked) {
42790
+ r2.acked = void 0;
42791
+ this.#save();
42792
+ }
42793
+ });
42688
42794
  const r = this.#recs.get(id);
42689
- if (r) {
42795
+ if (sent === true && r) {
42690
42796
  r.acked = true;
42691
42797
  acked = true;
42692
42798
  }
@@ -42772,6 +42878,7 @@ var TakenWatch = class {
42772
42878
  ...typeof p.scannedTo === "number" ? { scannedTo: p.scannedTo } : {},
42773
42879
  ...p.skip === true ? { skip: true } : {},
42774
42880
  ...p.acked === true ? { acked: true } : {},
42881
+ ...p.confirmed === true ? { confirmed: true } : {},
42775
42882
  ...typeof p.ino === "number" ? { ino: p.ino } : {},
42776
42883
  ...typeof p.sig === "string" ? { sig: p.sig } : {}
42777
42884
  };
@@ -43670,8 +43777,15 @@ function createDeliver(ctx) {
43670
43777
  * A transport vouches for a delivery whose attempt already settled (a
43671
43778
  * late ack): recorded and acked, so the hub's retry injects nothing.
43672
43779
  */
43673
- delivered: (msgId) => {
43674
- if (seen2.add(msgId)) ack(msgId);
43780
+ delivered: (msgId, onUnsent, onQueued) => {
43781
+ seen2.add(msgId);
43782
+ const id = frameId();
43783
+ const ok = ctx.hub.send(
43784
+ { v: 1, id, type: "ack", msg_id: msgId },
43785
+ onUnsent
43786
+ );
43787
+ if (ok) onQueued?.(id);
43788
+ return ok;
43675
43789
  }
43676
43790
  };
43677
43791
  }
@@ -43729,6 +43843,10 @@ var FramePacer = class {
43729
43843
  n += s.lanes.reduce((m, l) => m + l.length, 0) + (s.barrier ? 1 : 0);
43730
43844
  return n;
43731
43845
  }
43846
+ /** How many more frames fit before the queue is half full: bulk work (an ack replay) feeds on this, so live traffic keeps the other half. */
43847
+ get headroom() {
43848
+ return Math.max(0, Math.floor(this.#max / 2) - this.size);
43849
+ }
43732
43850
  /** False when the frame itself was dropped for space. */
43733
43851
  push(frame, data, onUnsent) {
43734
43852
  const e = { frame, data, onUnsent };
@@ -43869,7 +43987,8 @@ var HUB_HELLO_CAPS = [
43869
43987
  BUS_CAPS.link,
43870
43988
  BUS_CAPS.waiting,
43871
43989
  BUS_CAPS.waitingQuery,
43872
- BUS_CAPS.noticeAck
43990
+ BUS_CAPS.noticeAck,
43991
+ BUS_CAPS.ackConfirm
43873
43992
  ];
43874
43993
  var HubConnection = class {
43875
43994
  constructor(opts) {
@@ -43925,6 +44044,10 @@ var HubConnection = class {
43925
44044
  cancel(id) {
43926
44045
  return this.#pacer.remove(id);
43927
44046
  }
44047
+ /** Frames bulk work may still queue; see FramePacer.headroom. */
44048
+ get headroom() {
44049
+ return this.#pacer.headroom;
44050
+ }
43928
44051
  get open() {
43929
44052
  return this.#ws?.readyState === wrapper_default.OPEN;
43930
44053
  }
@@ -45909,7 +46032,7 @@ function readQueue(home2, thread, head) {
45909
46032
  }
45910
46033
 
45911
46034
  // ../bus-daemon/src/transports/codex.ts
45912
- var CODEX_QUEUE_TIMEOUT_MS = 1e4;
46035
+ var CODEX_QUEUE_TIMEOUT_MS = 3e4;
45913
46036
  var CODEX_TEXT_CAP = 64 * 1024;
45914
46037
  var codexBinFile = (busHome2) => join16(busHome2, "codex.json");
45915
46038
  var codexBinPin = (bin) => `${JSON.stringify({ bin }, null, 2)}
@@ -46992,10 +47115,14 @@ async function runDaemon(deps2 = {}) {
46992
47115
  )
46993
47116
  });
46994
47117
  const codexIndexHome = cx.home ?? codexHome();
47118
+ const codexAckIds = new AckTracker();
47119
+ const sendCodexAck = (id, unsent) => delivery.delivered(id, unsent, (fid) => {
47120
+ if (hubAckConfirm) codexAckIds.track(fid, id);
47121
+ });
46995
47122
  const codexTaken = new TakenWatch({
46996
47123
  home: codexIndexHome,
46997
47124
  file: cx.takenFile ?? join18(home(), "codex-pending.json"),
46998
- onTaken: (id) => delivery.delivered(id),
47125
+ onTaken: (id, unsent) => sendCodexAck(id, unsent),
46999
47126
  log
47000
47127
  });
47001
47128
  const codex = new CodexTransport({
@@ -47377,7 +47504,7 @@ async function runDaemon(deps2 = {}) {
47377
47504
  const delivery = createDeliver({
47378
47505
  agents,
47379
47506
  ...cl.retryDelaysMs ? { retryDelaysMs: cl.retryDelaysMs } : {},
47380
- hub: { send: (f) => hub.send(f) },
47507
+ hub: { send: (f, unsent) => hub.send(f, unsent) },
47381
47508
  transports: {
47382
47509
  "claude-code": (agent, mail) => claude2.deliver(agent, mail),
47383
47510
  opencode: (agent, mail) => opencode.deliver(agent, mail),
@@ -47404,6 +47531,8 @@ async function runDaemon(deps2 = {}) {
47404
47531
  let hubLink = false;
47405
47532
  let hubLinkArg = false;
47406
47533
  let hubHelloed = false;
47534
+ let hubAckConfirm = false;
47535
+ let codexReplayLink = 0;
47407
47536
  let hubVersion;
47408
47537
  let hubWaiting = false;
47409
47538
  let hubWaitingQuery = false;
@@ -47520,6 +47649,13 @@ async function runDaemon(deps2 = {}) {
47520
47649
  return;
47521
47650
  case "link_bound":
47522
47651
  return;
47652
+ case "acked": {
47653
+ if (!hubAckConfirm) return;
47654
+ const sent2 = codexAckIds.take(frame.id);
47655
+ if (sent2 !== void 0 && sent2 === frame.msg_id)
47656
+ codexTaken.confirm(sent2);
47657
+ return;
47658
+ }
47523
47659
  case "waiting_counts":
47524
47660
  waitingAsks.get(frame.id)?.(frame.counts);
47525
47661
  return;
@@ -47535,11 +47671,21 @@ async function runDaemon(deps2 = {}) {
47535
47671
  hubWaitingQuery = frame.caps?.includes(BUS_CAPS.waitingQuery) ?? false;
47536
47672
  hubLink = frame.caps?.includes(BUS_CAPS.link) ?? false;
47537
47673
  hubLinkArg = frame.caps?.includes(BUS_CAPS.linkArg) ?? false;
47674
+ hubAckConfirm = frame.caps?.includes(BUS_CAPS.ackConfirm) ?? false;
47538
47675
  hubHelloed = true;
47539
47676
  for (const rec of agents.all())
47540
47677
  if (rec.live && rec.replaces !== void 0) announceUp(rec);
47541
47678
  for (const rec of agents.all()) flushRename(rec);
47542
47679
  outbox.flush();
47680
+ if (hubAckConfirm) {
47681
+ const link2 = ++codexReplayLink;
47682
+ replayAcks(
47683
+ codexTaken.unconfirmedIds(),
47684
+ (id) => void sendCodexAck(id),
47685
+ () => hubHelloed && link2 === codexReplayLink,
47686
+ () => hub.headroom
47687
+ );
47688
+ }
47543
47689
  return;
47544
47690
  }
47545
47691
  },
@@ -47591,6 +47737,8 @@ async function runDaemon(deps2 = {}) {
47591
47737
  hubFollow = false;
47592
47738
  hubLink = false;
47593
47739
  hubLinkArg = false;
47740
+ hubAckConfirm = false;
47741
+ codexAckIds.clear();
47594
47742
  hubWaitingQuery = false;
47595
47743
  hubHelloed = false;
47596
47744
  statusRelay.dropped();
@@ -48467,6 +48615,7 @@ async function runDaemon(deps2 = {}) {
48467
48615
  for (const t of limited.values()) clearTimeout(t);
48468
48616
  for (const t of restoreTimers) clearTimeout(t);
48469
48617
  hub.stop();
48618
+ codexTaken.flush();
48470
48619
  receipts.release();
48471
48620
  await new Promise((r) => setImmediate(r));
48472
48621
  pending.failAll("hub_unavailable", "the daemon is stopping");
@@ -50128,7 +50277,7 @@ var noService = {
50128
50277
  remove: async () => ({}),
50129
50278
  cli: () => ["oa-bus"]
50130
50279
  };
50131
- var VERSION = true ? "0.162.1" : JSON.parse(
50280
+ var VERSION = true ? "0.163.0" : JSON.parse(
50132
50281
  readFileSync16(new URL("../package.json", import.meta.url), "utf8")
50133
50282
  ).version;
50134
50283
  var which = (cmd) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@open-artifacts/bus",
3
3
  "type": "module",
4
- "version": "0.162.1",
4
+ "version": "0.163.0",
5
5
  "description": "The Open Artifacts bus: your AI agents reach each other across machines.",
6
6
  "license": "MIT",
7
7
  "repository": {