@open-artifacts/bus 0.141.0 → 0.143.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.141.0";
14
+ const CLIENT_VERSION = "0.143.0";
15
15
 
16
16
  type Frame = Json & { type: string; id: string };
17
17
  type Ctx = {
@@ -28817,7 +28817,7 @@ var base = { v: external_exports.literal(V), id: external_exports.string().min(1
28817
28817
  var late = { late: external_exports.array(external_exports.string().min(1)).optional() };
28818
28818
  var isWellFormed = (s) => s.isWellFormed();
28819
28819
  var WELL_FORMED = { message: "text is not well-formed unicode" };
28820
- var CLIENT_VERSION = true ? "0.141.0" : "0.0.0";
28820
+ var CLIENT_VERSION = true ? "0.143.0" : "0.0.0";
28821
28821
  var clientVersion = {
28822
28822
  client_version: external_exports.string().min(1).max(64).optional()
28823
28823
  };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oa-bus",
3
- "version": "0.141.0",
3
+ "version": "0.143.0",
4
4
  "type": "module",
5
5
  "openclaw": {
6
6
  "extensions": [
package/dist/index.js CHANGED
@@ -31425,7 +31425,14 @@ var init_caps = __esm({
31425
31425
  * it (any other gets `bad_frame`, as an old hub would) and lists it in
31426
31426
  * `hello_ok.caps`; a client sends them only when it did.
31427
31427
  */
31428
- follow: "follow"
31428
+ follow: "follow",
31429
+ /**
31430
+ * Session links (#1822): the client may send `link_bind` and decodes
31431
+ * `link_bound`. The hub answers it only on a socket whose hello listed it
31432
+ * (any other gets `bad_frame`, as an old hub would) and lists it in
31433
+ * `hello_ok.caps`; a client sends it only when it did.
31434
+ */
31435
+ link: "link"
31429
31436
  };
31430
31437
  MAX_CAPS = 16;
31431
31438
  CapTokenSchema = external_exports.string().regex(/^[a-z][a-z0-9_-]{0,31}$/);
@@ -32185,7 +32192,7 @@ function decode3(raw, schema, caps) {
32185
32192
  function decodeServerFrame(raw) {
32186
32193
  return decode3(raw, ServerFrameSchema, SERVER_CAPS);
32187
32194
  }
32188
- 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, 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;
32195
+ 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, LinkProofSchema, LinkProofHashSchema, LinkBind, LinkBound, 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;
32189
32196
  var init_protocol2 = __esm({
32190
32197
  "../bus-protocol/src/protocol.ts"() {
32191
32198
  "use strict";
@@ -32339,6 +32346,18 @@ var init_protocol2 = __esm({
32339
32346
  type: external_exports.literal("following"),
32340
32347
  from_ref: AgentRefSchema
32341
32348
  });
32349
+ LinkProofSchema = external_exports.string().regex(/^[A-Za-z0-9_-]{43}$/);
32350
+ LinkProofHashSchema = external_exports.string().regex(/^[0-9a-f]{64}$/);
32351
+ LinkBind = external_exports.strictObject({
32352
+ ...base,
32353
+ type: external_exports.literal("link_bind"),
32354
+ agent_ref: AgentRefSchema,
32355
+ hash: LinkProofHashSchema
32356
+ });
32357
+ LinkBound = external_exports.strictObject({
32358
+ ...base,
32359
+ type: external_exports.literal("link_bound")
32360
+ });
32342
32361
  MAX_FOLLOWS = 200;
32343
32362
  FollowEntry = external_exports.strictObject({
32344
32363
  artifact_id: external_exports.string().min(1).max(64),
@@ -32498,7 +32517,8 @@ var init_protocol2 = __esm({
32498
32517
  Rename,
32499
32518
  Follow,
32500
32519
  Unfollow,
32501
- Following
32520
+ Following,
32521
+ LinkBind
32502
32522
  ]);
32503
32523
  ServerFrameSchema = external_exports.discriminatedUnion("type", [
32504
32524
  HelloOk,
@@ -32513,7 +32533,8 @@ var init_protocol2 = __esm({
32513
32533
  Renamed,
32514
32534
  Followed,
32515
32535
  Unfollowed,
32516
- Follows
32536
+ Follows,
32537
+ LinkBound
32517
32538
  ]);
32518
32539
  FrameSchema = external_exports.discriminatedUnion("type", [
32519
32540
  Hello,
@@ -32530,6 +32551,7 @@ var init_protocol2 = __esm({
32530
32551
  Follow,
32531
32552
  Unfollow,
32532
32553
  Following,
32554
+ LinkBind,
32533
32555
  HelloOk,
32534
32556
  AgentOk,
32535
32557
  ReceiptFrame,
@@ -32542,7 +32564,8 @@ var init_protocol2 = __esm({
32542
32564
  Renamed,
32543
32565
  Followed,
32544
32566
  Unfollowed,
32545
- Follows
32567
+ Follows,
32568
+ LinkBound
32546
32569
  ]);
32547
32570
  MAX_RAW_FRAME_CHARS = 2 * LIMITS.maxMessageBytes + 4096;
32548
32571
  SERVER_CAPS = { depth: 5, tokens: 65536, structural: 131072 };
@@ -32616,7 +32639,7 @@ var init_frames = __esm({
32616
32639
  late = { late: external_exports.array(external_exports.string().min(1)).optional() };
32617
32640
  isWellFormed2 = (s) => s.isWellFormed();
32618
32641
  WELL_FORMED = { message: "text is not well-formed unicode" };
32619
- CLIENT_VERSION = true ? "0.141.0" : "0.0.0";
32642
+ CLIENT_VERSION = true ? "0.143.0" : "0.0.0";
32620
32643
  clientVersion = {
32621
32644
  client_version: external_exports.string().min(1).max(64).optional()
32622
32645
  };
@@ -38701,7 +38724,7 @@ import { join as join18 } from "node:path";
38701
38724
 
38702
38725
  // ../bus-daemon/src/index.ts
38703
38726
  init_src3();
38704
- import { lstatSync as lstatSync7, realpathSync as realpathSync7, writeFileSync as writeFileSync4 } from "node:fs";
38727
+ import { lstatSync as lstatSync7, realpathSync as realpathSync7, writeFileSync as writeFileSync5 } from "node:fs";
38705
38728
  import { basename as basename5, isAbsolute as isAbsolute6, join as join14 } from "node:path";
38706
38729
 
38707
38730
  // ../bus-adapter-opencode/src/version.ts
@@ -39171,10 +39194,36 @@ function codexAttestor(deps2 = {}) {
39171
39194
  });
39172
39195
  return still;
39173
39196
  };
39197
+ const restore = ({ thread, pid, start }) => {
39198
+ const home2 = deps2.home ?? codexHome();
39199
+ const proc = procs([pid]).get(pid);
39200
+ if (!proc || basename2(proc.comm) !== "codex" || proc.start !== start)
39201
+ return void 0;
39202
+ const was = pinned.get(pid);
39203
+ if (was !== void 0 && was !== start) return void 0;
39204
+ const row = threadRow(home2, thread);
39205
+ const rollout = row?.rollout_path ?? globRollout(home2, thread);
39206
+ if (!rollout || !plainFile(rollout)) return void 0;
39207
+ const meta3 = metaOf2(rollout, thread);
39208
+ if (!meta3 || typeof meta3.cwd !== "string" || !isAbsolute(meta3.cwd))
39209
+ return void 0;
39210
+ if (isSubagent(row ? row.source : meta3.source) || isSubagent(meta3.source) || SPAWNED_SOURCES.has(String(meta3.thread_source)))
39211
+ return void 0;
39212
+ const had = was !== void 0;
39213
+ pinned.set(pid, start);
39214
+ proofs.set(`${pid}\0${start}\0${thread}`, { cwd: meta3.cwd, rollout });
39215
+ if (sweep([{ thread, pid }], true).has(thread)) return { cwd: meta3.cwd };
39216
+ proofs.delete(`${pid}\0${start}\0${thread}`);
39217
+ if (!had && ![...proofs.keys()].some((k) => k.startsWith(`${pid}\0`)))
39218
+ pinned.delete(pid);
39219
+ return void 0;
39220
+ };
39174
39221
  return {
39175
39222
  attest: (hello) => check2(hello, true),
39176
39223
  attestNow: (hello) => check2(hello, false),
39177
- sweep
39224
+ sweep,
39225
+ startOf: (pid) => pinned.get(pid),
39226
+ restore
39178
39227
  };
39179
39228
  }
39180
39229
  function advance(scan2) {
@@ -39697,9 +39746,10 @@ function defaultOpenSessions() {
39697
39746
  });
39698
39747
  }
39699
39748
 
39700
- // ../bus-daemon/src/codex-names.ts
39701
- import { closeSync as closeSync3, constants as constants2, fstatSync as fstatSync3, openSync as openSync3, readSync as readSync2 } from "node:fs";
39702
- import { join as join7 } from "node:path";
39749
+ // ../bus-daemon/src/codex-agents.ts
39750
+ init_src();
39751
+ init_zod();
39752
+ import { chmodSync as chmodSync3, renameSync as renameSync2, writeFileSync } from "node:fs";
39703
39753
 
39704
39754
  // ../bus-daemon/src/own-file.ts
39705
39755
  import {
@@ -39795,7 +39845,51 @@ function readOwnFile(file2, uid = process.getuid?.(), opts = {}) {
39795
39845
  }
39796
39846
  }
39797
39847
 
39848
+ // ../bus-daemon/src/codex-agents.ts
39849
+ var CodexAgentSchema = external_exports.strictObject({
39850
+ /** Joined into the thread's lock path: a real ref, never `../`. */
39851
+ ref: AgentRefSchema,
39852
+ pid: external_exports.number().int().positive(),
39853
+ /** The process start as `ps` printed it when pinned. */
39854
+ procStart: external_exports.string().min(1).max(100),
39855
+ proposedName: external_exports.string().min(1).max(200),
39856
+ sentName: external_exports.string().max(200).optional(),
39857
+ busName: external_exports.string().min(1).max(200)
39858
+ });
39859
+ var FileSchema = external_exports.strictObject({
39860
+ v: external_exports.literal(1),
39861
+ agents: external_exports.array(external_exports.unknown())
39862
+ });
39863
+ function readCodexAgents(file2, uid = process.getuid?.()) {
39864
+ try {
39865
+ const f = readOwnFile(file2, uid);
39866
+ if (f.state !== "ok") return [];
39867
+ const top = FileSchema.safeParse(JSON.parse(f.text));
39868
+ if (!top.success) return [];
39869
+ const seen2 = /* @__PURE__ */ new Set();
39870
+ const out = [];
39871
+ for (const raw of top.data.agents) {
39872
+ if (out.length >= LIMITS.maxAgentsPerMachine) break;
39873
+ const one2 = CodexAgentSchema.safeParse(raw);
39874
+ if (!one2.success || seen2.has(one2.data.ref)) continue;
39875
+ seen2.add(one2.data.ref);
39876
+ out.push(one2.data);
39877
+ }
39878
+ return out;
39879
+ } catch {
39880
+ return [];
39881
+ }
39882
+ }
39883
+ function writeCodexAgents(file2, agents) {
39884
+ const tmp = `${file2}.${process.pid}.tmp`;
39885
+ writeFileSync(tmp, JSON.stringify({ v: 1, agents }), { mode: 384 });
39886
+ chmodSync3(tmp, 384);
39887
+ renameSync2(tmp, file2);
39888
+ }
39889
+
39798
39890
  // ../bus-daemon/src/codex-names.ts
39891
+ import { closeSync as closeSync3, constants as constants2, fstatSync as fstatSync3, openSync as openSync3, readSync as readSync2 } from "node:fs";
39892
+ import { join as join7 } from "node:path";
39799
39893
  var CODEX_INDEX_MAX_BYTES = 1024 * 1024;
39800
39894
  var codexThreadNames = (home2, opts = {}) => {
39801
39895
  const uid = "uid" in opts ? opts.uid : process.getuid?.();
@@ -39863,13 +39957,13 @@ import { dirname as dirname5, join as join10 } from "node:path";
39863
39957
  // ../bus-daemon/src/global.ts
39864
39958
  import { randomBytes } from "node:crypto";
39865
39959
  import {
39866
- chmodSync as chmodSync3,
39960
+ chmodSync as chmodSync4,
39867
39961
  closeSync as closeSync4,
39868
39962
  lstatSync as lstatSync4,
39869
39963
  mkdirSync as mkdirSync4,
39870
39964
  openSync as openSync4,
39871
39965
  realpathSync as realpathSync3,
39872
- renameSync as renameSync2,
39966
+ renameSync as renameSync3,
39873
39967
  statSync as statSync6,
39874
39968
  unlinkSync,
39875
39969
  writeSync
@@ -39942,7 +40036,7 @@ function sameDir(entry, dir) {
39942
40036
  }
39943
40037
  function writeGlobalDirs(dirs, h = home()) {
39944
40038
  mkdirSync4(h, { recursive: true, mode: 448 });
39945
- chmodSync3(h, 448);
40039
+ chmodSync4(h, 448);
39946
40040
  const tmp = join8(h, `.global.json.${randomBytes(8).toString("hex")}.tmp`);
39947
40041
  const fd = openSync4(tmp, "wx", 384);
39948
40042
  try {
@@ -39955,8 +40049,8 @@ function writeGlobalDirs(dirs, h = home()) {
39955
40049
  }
39956
40050
  closeSync4(fd);
39957
40051
  try {
39958
- chmodSync3(tmp, 384);
39959
- renameSync2(tmp, globalFile(h));
40052
+ chmodSync4(tmp, 384);
40053
+ renameSync3(tmp, globalFile(h));
39960
40054
  } catch (e) {
39961
40055
  unlinkSync(tmp);
39962
40056
  throw e;
@@ -39973,11 +40067,11 @@ import { basename as basename4, dirname as dirname4, resolve as resolve2 } from
39973
40067
  import { randomBytes as randomBytes2 } from "node:crypto";
39974
40068
  import {
39975
40069
  appendFileSync,
39976
- chmodSync as chmodSync4,
40070
+ chmodSync as chmodSync5,
39977
40071
  closeSync as closeSync5,
39978
40072
  mkdirSync as mkdirSync5,
39979
40073
  openSync as openSync5,
39980
- renameSync as renameSync3,
40074
+ renameSync as renameSync4,
39981
40075
  unlinkSync as unlinkSync2,
39982
40076
  writeSync as writeSync2
39983
40077
  } from "node:fs";
@@ -40005,7 +40099,7 @@ function isApproved(dir, namespace2, entries) {
40005
40099
  }
40006
40100
  function writeApprovals(entries, h = home()) {
40007
40101
  mkdirSync5(h, { recursive: true, mode: 448 });
40008
- chmodSync4(h, 448);
40102
+ chmodSync5(h, 448);
40009
40103
  const tmp = join9(h, `.namespaces.json.${randomBytes2(8).toString("hex")}.tmp`);
40010
40104
  const fd = openSync5(tmp, "wx", 384);
40011
40105
  try {
@@ -40018,8 +40112,8 @@ function writeApprovals(entries, h = home()) {
40018
40112
  }
40019
40113
  closeSync5(fd);
40020
40114
  try {
40021
- chmodSync4(tmp, 384);
40022
- renameSync3(tmp, namespacesFile(h));
40115
+ chmodSync5(tmp, 384);
40116
+ renameSync4(tmp, namespacesFile(h));
40023
40117
  } catch (e) {
40024
40118
  unlinkSync2(tmp);
40025
40119
  throw e;
@@ -40032,7 +40126,7 @@ function logApproval(entry, h = home(), now = /* @__PURE__ */ new Date()) {
40032
40126
  const line = `${now.toISOString()} ${entry.action} dir=${JSON.stringify(entry.dir)} namespace=${JSON.stringify(entry.namespace)} tty=${entry.tty ? "yes" : "no"}
40033
40127
  `;
40034
40128
  appendFileSync(file2, line, { mode: 384 });
40035
- chmodSync4(file2, 384);
40129
+ chmodSync5(file2, 384);
40036
40130
  }
40037
40131
 
40038
40132
  // ../bus-daemon/src/namespace.ts
@@ -41589,11 +41683,11 @@ function routeLocal(frame, hello, reply, ctx) {
41589
41683
  init_src2();
41590
41684
  init_src();
41591
41685
  import {
41592
- chmodSync as chmodSync5,
41686
+ chmodSync as chmodSync6,
41593
41687
  readFileSync as readFileSync7,
41594
- renameSync as renameSync4,
41688
+ renameSync as renameSync5,
41595
41689
  rmSync as rmSync2,
41596
- writeFileSync
41690
+ writeFileSync as writeFileSync2
41597
41691
  } from "node:fs";
41598
41692
  var metaOf = ({
41599
41693
  at: _,
@@ -41815,12 +41909,12 @@ var SentStore = class {
41815
41909
  const tmp = `${this.file}.${process.pid}.tmp`;
41816
41910
  try {
41817
41911
  rmSync2(tmp, { force: true });
41818
- writeFileSync(tmp, JSON.stringify(Object.fromEntries(this.#all)), {
41912
+ writeFileSync2(tmp, JSON.stringify(Object.fromEntries(this.#all)), {
41819
41913
  mode: 384,
41820
41914
  flag: "wx"
41821
41915
  });
41822
- chmodSync5(tmp, 384);
41823
- renameSync4(tmp, this.file);
41916
+ chmodSync6(tmp, 384);
41917
+ renameSync5(tmp, this.file);
41824
41918
  } catch (e) {
41825
41919
  this.#log?.(
41826
41920
  `sent file write failed: ${e instanceof Error ? e.message : String(e)}`
@@ -41996,20 +42090,20 @@ init_src3();
41996
42090
  init_src();
41997
42091
  import { createHash as createHash4, randomUUID } from "node:crypto";
41998
42092
  import {
41999
- chmodSync as chmodSync7,
42093
+ chmodSync as chmodSync8,
42000
42094
  lstatSync as lstatSync5,
42001
42095
  mkdirSync as mkdirSync6,
42002
42096
  readFileSync as readFileSync9,
42003
- renameSync as renameSync6,
42097
+ renameSync as renameSync7,
42004
42098
  rmSync as rmSync3,
42005
- writeFileSync as writeFileSync3
42099
+ writeFileSync as writeFileSync4
42006
42100
  } from "node:fs";
42007
42101
  import { createServer as createServer2 } from "node:net";
42008
42102
  import { dirname as dirname6, join as join11 } from "node:path";
42009
42103
  import { createInterface } from "node:readline";
42010
42104
 
42011
42105
  // ../bus-daemon/src/transports/held.ts
42012
- import { chmodSync as chmodSync6, readFileSync as readFileSync8, renameSync as renameSync5, writeFileSync as writeFileSync2 } from "node:fs";
42106
+ import { chmodSync as chmodSync7, readFileSync as readFileSync8, renameSync as renameSync6, writeFileSync as writeFileSync3 } from "node:fs";
42013
42107
  var HeldStore = class {
42014
42108
  constructor(file2, opts = {}) {
42015
42109
  this.file = file2;
@@ -42047,9 +42141,9 @@ var HeldStore = class {
42047
42141
  }
42048
42142
  #write(all) {
42049
42143
  const tmp = `${this.file}.${process.pid}.tmp`;
42050
- writeFileSync2(tmp, JSON.stringify(all), { mode: 384 });
42051
- chmodSync6(tmp, 384);
42052
- renameSync5(tmp, this.file);
42144
+ writeFileSync3(tmp, JSON.stringify(all), { mode: 384 });
42145
+ chmodSync7(tmp, 384);
42146
+ renameSync6(tmp, this.file);
42053
42147
  }
42054
42148
  };
42055
42149
 
@@ -42386,7 +42480,7 @@ var ClaudeTransport = class {
42386
42480
  if (unsafe) throw new UnsafeDir(unsafe);
42387
42481
  } else {
42388
42482
  mkdirSync6(this.opts.socketsDir, { recursive: true, mode: 448 });
42389
- chmodSync7(this.opts.socketsDir, 448);
42483
+ chmodSync8(this.opts.socketsDir, 448);
42390
42484
  }
42391
42485
  rmSync3(path, { force: true });
42392
42486
  this.#paths.set(key2, path);
@@ -42418,7 +42512,7 @@ var ClaudeTransport = class {
42418
42512
  sink.server.once("error", reject);
42419
42513
  sink.server.listen(path, () => resolve13());
42420
42514
  });
42421
- chmodSync7(path, 384);
42515
+ chmodSync8(path, 384);
42422
42516
  return sink;
42423
42517
  }
42424
42518
  /** Paths of the sinks bound or binding now, by key. */
@@ -42458,9 +42552,9 @@ var ClaudeTransport = class {
42458
42552
  const out = /* @__PURE__ */ Object.create(null);
42459
42553
  for (const [k, v] of keep) out[k] = v;
42460
42554
  const tmp = `${file2}.${process.pid}.tmp`;
42461
- writeFileSync3(tmp, JSON.stringify(out), { mode: 384 });
42462
- chmodSync7(tmp, 384);
42463
- renameSync6(tmp, file2);
42555
+ writeFileSync4(tmp, JSON.stringify(out), { mode: 384 });
42556
+ chmodSync8(tmp, 384);
42557
+ renameSync7(tmp, file2);
42464
42558
  return out;
42465
42559
  } catch (e) {
42466
42560
  this.opts.log?.(
@@ -43750,7 +43844,7 @@ async function runDaemon(deps2 = {}) {
43750
43844
  log(`this machine was revoked; run \`${BUS_CMD} install\``);
43751
43845
  process.exitCode = 1;
43752
43846
  try {
43753
- writeFileSync4(
43847
+ writeFileSync5(
43754
43848
  deps2.revokedFile ?? join14(home(), "revoked"),
43755
43849
  revokedMarker(cfg.machine_token),
43756
43850
  { mode: 384 }
@@ -44010,6 +44104,7 @@ async function runDaemon(deps2 = {}) {
44010
44104
  live: true
44011
44105
  });
44012
44106
  if (rec.kind === "opencode") ocServiceStart.set(rec.ref, ocStart(pid));
44107
+ if (rec.kind === "codex") persistCodex();
44013
44108
  if (rec.kind === "claude-code") void claude.revive(rec.ref);
44014
44109
  conns.set(rec.ref, (conns.get(rec.ref) ?? 0) + 1);
44015
44110
  announceUp(rec);
@@ -44134,11 +44229,78 @@ async function runDaemon(deps2 = {}) {
44134
44229
  deps2.onSocketLost?.();
44135
44230
  }, deps2.socketCheckMs ?? 6e4);
44136
44231
  socketWatch.unref();
44232
+ const codexAgentsFile = cx.agentsFile ?? join14(home(), "codex-agents.json");
44233
+ let codexSaved;
44234
+ const persistCodex = () => {
44235
+ const rows = [];
44236
+ for (const a of agents.all()) {
44237
+ if (a.kind !== "codex" || !a.live) continue;
44238
+ const procStart = codexCheck.startOf(a.pid);
44239
+ if (procStart === void 0) continue;
44240
+ rows.push({
44241
+ ref: a.ref,
44242
+ pid: a.pid,
44243
+ procStart,
44244
+ proposedName: a.proposedName,
44245
+ ...a.sentName !== void 0 ? { sentName: a.sentName } : {},
44246
+ busName: a.busName
44247
+ });
44248
+ }
44249
+ const text3 = JSON.stringify(rows);
44250
+ if (codexSaved === void 0 ? rows.length === 0 : text3 === codexSaved)
44251
+ return;
44252
+ try {
44253
+ writeCodexAgents(codexAgentsFile, rows);
44254
+ codexSaved = text3;
44255
+ } catch (e) {
44256
+ log(
44257
+ `could not save the live Codex threads: ${e instanceof Error ? e.message : String(e)}`
44258
+ );
44259
+ }
44260
+ };
44261
+ const restoreCodex = () => {
44262
+ if (deps2.attest) return;
44263
+ for (const r of readCodexAgents(codexAgentsFile)) {
44264
+ if (agents.byRef(r.ref)) continue;
44265
+ let proven;
44266
+ try {
44267
+ proven = codexCheck.restore({
44268
+ thread: r.ref,
44269
+ pid: r.pid,
44270
+ start: r.procStart
44271
+ });
44272
+ } catch {
44273
+ }
44274
+ if (!proven) continue;
44275
+ let ns;
44276
+ try {
44277
+ ns = resolveNs(proven.cwd, true);
44278
+ } catch {
44279
+ continue;
44280
+ }
44281
+ if (!WireNamespaceSchema.safeParse(ns.namespace).success) continue;
44282
+ agents.up({
44283
+ ref: r.ref,
44284
+ kind: "codex",
44285
+ proposedName: r.proposedName,
44286
+ busName: r.busName,
44287
+ namespace: ns.namespace,
44288
+ global: ns.global,
44289
+ pid: r.pid,
44290
+ procStart: r.procStart,
44291
+ cwd: proven.cwd,
44292
+ live: true,
44293
+ ...r.sentName !== void 0 ? { sentName: r.sentName } : {}
44294
+ });
44295
+ seenAt.set(r.ref, ++seenSeq);
44296
+ if (debug) log(`restored codex thread ${r.ref.slice(0, 8)} pid ${r.pid}`);
44297
+ }
44298
+ };
44137
44299
  const syncCodex = () => {
44138
44300
  renameCodexThreads();
44139
44301
  const live = agents.all().filter((a) => a.kind === "codex" && a.live).map((a) => ({ thread: a.ref, pid: a.pid }));
44140
44302
  codexTicks = (codexTicks + 1) % relockEvery;
44141
- if (!live.length || deps2.attest) return;
44303
+ if (!live.length || deps2.attest) return persistCodex();
44142
44304
  const still = codexCheck.sweep(live, codexTicks === 0);
44143
44305
  let closed = false;
44144
44306
  for (const { thread } of live) {
@@ -44148,6 +44310,7 @@ async function runDaemon(deps2 = {}) {
44148
44310
  closed = true;
44149
44311
  }
44150
44312
  if (closed) announceSessions();
44313
+ persistCodex();
44151
44314
  };
44152
44315
  const sync = () => {
44153
44316
  for (const rec of agents.all()) if (rec.live) flushRename(rec);
@@ -44165,6 +44328,7 @@ async function runDaemon(deps2 = {}) {
44165
44328
  }
44166
44329
  }
44167
44330
  };
44331
+ restoreCodex();
44168
44332
  sync();
44169
44333
  const watcher = setInterval(sync, cl.syncMs ?? 2e3);
44170
44334
  watcher.unref();
@@ -45087,15 +45251,15 @@ var realDeps = {
45087
45251
  init_src();
45088
45252
  import { createHash as createHash5 } from "node:crypto";
45089
45253
  import {
45090
- chmodSync as chmodSync9,
45254
+ chmodSync as chmodSync10,
45091
45255
  cpSync,
45092
45256
  existsSync as existsSync3,
45093
45257
  lstatSync as lstatSync9,
45094
45258
  mkdirSync as mkdirSync8,
45095
45259
  realpathSync as realpathSync8,
45096
- renameSync as renameSync8,
45260
+ renameSync as renameSync9,
45097
45261
  rmSync as rmSync4,
45098
- writeFileSync as writeFileSync6
45262
+ writeFileSync as writeFileSync7
45099
45263
  } from "node:fs";
45100
45264
  import { basename as basename6, dirname as dirname8, isAbsolute as isAbsolute7, join as join16, resolve as resolve4 } from "node:path";
45101
45265
  import { fileURLToPath } from "node:url";
@@ -46136,11 +46300,11 @@ function remove(path, text3, doc) {
46136
46300
 
46137
46301
  // src/steps/step.ts
46138
46302
  import {
46139
- chmodSync as chmodSync8,
46303
+ chmodSync as chmodSync9,
46140
46304
  mkdirSync as mkdirSync7,
46141
46305
  readFileSync as readFileSync12,
46142
- renameSync as renameSync7,
46143
- writeFileSync as writeFileSync5
46306
+ renameSync as renameSync8,
46307
+ writeFileSync as writeFileSync6
46144
46308
  } from "node:fs";
46145
46309
  import { dirname as dirname7 } from "node:path";
46146
46310
  function readInstallFile(path) {
@@ -46156,10 +46320,10 @@ function updateInstallFile(path, patch) {
46156
46320
  const next = { ...readInstallFile(path), ...patch };
46157
46321
  mkdirSync7(dirname7(path), { recursive: true, mode: 448 });
46158
46322
  const tmp = `${path}.${process.pid}.tmp`;
46159
- writeFileSync5(tmp, `${JSON.stringify(next, null, 2)}
46323
+ writeFileSync6(tmp, `${JSON.stringify(next, null, 2)}
46160
46324
  `, { mode: 384 });
46161
- chmodSync8(tmp, 384);
46162
- renameSync7(tmp, path);
46325
+ chmodSync9(tmp, 384);
46326
+ renameSync8(tmp, path);
46163
46327
  }
46164
46328
  async function runSteps(steps, ctx, record7) {
46165
46329
  for (const step2 of steps) {
@@ -46315,7 +46479,7 @@ function installCli(home2, src, node2) {
46315
46479
  const bin = join16(home2, "bin");
46316
46480
  const tmp = `${bin}.${process.pid}.tmp`;
46317
46481
  mkdirSync8(home2, { recursive: true, mode: 448 });
46318
- chmodSync9(home2, 448);
46482
+ chmodSync10(home2, 448);
46319
46483
  rmSync4(tmp, { recursive: true, force: true });
46320
46484
  mkdirSync8(tmp);
46321
46485
  if (src.kind === "bundle") {
@@ -46323,16 +46487,16 @@ function installCli(home2, src, node2) {
46323
46487
  for (const name of ["dist", "assets", "package.json"])
46324
46488
  if (existsSync3(join16(pkg, name)))
46325
46489
  cpSync(join16(pkg, name), join16(tmp, name), { recursive: true });
46326
- } else writeFileSync6(join16(tmp, entryName(src)), shim(src));
46327
- chmodSync9(tmp, 448);
46490
+ } else writeFileSync7(join16(tmp, entryName(src)), shim(src));
46491
+ chmodSync10(tmp, 448);
46328
46492
  if (node2 !== void 0) {
46329
- writeFileSync6(join16(tmp, "node"), launcherText(node2), { mode: 448 });
46330
- chmodSync9(join16(tmp, "node"), 448);
46493
+ writeFileSync7(join16(tmp, "node"), launcherText(node2), { mode: 448 });
46494
+ chmodSync10(join16(tmp, "node"), 448);
46331
46495
  }
46332
46496
  if (!existsSync3(join16(tmp, "package.json")))
46333
- writeFileSync6(join16(tmp, "package.json"), '{ "type": "module" }\n');
46497
+ writeFileSync7(join16(tmp, "package.json"), '{ "type": "module" }\n');
46334
46498
  rmSync4(bin, { recursive: true, force: true });
46335
- renameSync8(tmp, bin);
46499
+ renameSync9(tmp, bin);
46336
46500
  return join16(bin, entryName(src));
46337
46501
  }
46338
46502
  var present = (path) => {
@@ -46347,8 +46511,8 @@ function writeReplacing(path, text3) {
46347
46511
  mkdirSync8(dirname8(path), { recursive: true });
46348
46512
  const tmp = `${path}.${process.pid}.tmp`;
46349
46513
  try {
46350
- writeFileSync6(tmp, text3, { mode: 420 });
46351
- renameSync8(tmp, path);
46514
+ writeFileSync7(tmp, text3, { mode: 420 });
46515
+ renameSync9(tmp, path);
46352
46516
  } catch (e) {
46353
46517
  rmSync4(tmp, { force: true });
46354
46518
  throw e;
@@ -46596,7 +46760,7 @@ var noService = {
46596
46760
  remove: async () => ({}),
46597
46761
  cli: () => ["oa-bus"]
46598
46762
  };
46599
- var VERSION = true ? "0.141.0" : JSON.parse(
46763
+ var VERSION = true ? "0.143.0" : JSON.parse(
46600
46764
  readFileSync13(new URL("../package.json", import.meta.url), "utf8")
46601
46765
  ).version;
46602
46766
  var which = (cmd) => {
@@ -46854,16 +47018,16 @@ var OPENCODE_TUI_PLUGIN = fileURLToPath2(
46854
47018
  // src/steps/adapters.ts
46855
47019
  import { randomBytes as randomBytes4 } from "node:crypto";
46856
47020
  import {
46857
- chmodSync as chmodSync11,
47021
+ chmodSync as chmodSync12,
46858
47022
  existsSync as existsSync8,
46859
47023
  lstatSync as lstatSync14,
46860
47024
  mkdirSync as mkdirSync11,
46861
47025
  readFileSync as readFileSync19,
46862
47026
  readlinkSync,
46863
- renameSync as renameSync11,
47027
+ renameSync as renameSync12,
46864
47028
  rmSync as rmSync9,
46865
47029
  statSync as statSync11,
46866
- writeFileSync as writeFileSync9
47030
+ writeFileSync as writeFileSync10
46867
47031
  } from "node:fs";
46868
47032
  import { dirname as dirname11, join as join23, resolve as resolve8 } from "node:path";
46869
47033
  import { isDeepStrictEqual } from "node:util";
@@ -48112,10 +48276,10 @@ import {
48112
48276
  readdirSync as readdirSync5,
48113
48277
  readFileSync as readFileSync15,
48114
48278
  realpathSync as realpathSync9,
48115
- renameSync as renameSync9,
48279
+ renameSync as renameSync10,
48116
48280
  rmdirSync,
48117
48281
  rmSync as rmSync5,
48118
- writeFileSync as writeFileSync7
48282
+ writeFileSync as writeFileSync8
48119
48283
  } from "node:fs";
48120
48284
  import {
48121
48285
  basename as basename7,
@@ -48325,15 +48489,15 @@ async function installHermes(deps2) {
48325
48489
  mkdirSync9(join19(tmp, f, ".."), { recursive: true });
48326
48490
  cpSync2(join19(shipped, f), join19(tmp, f));
48327
48491
  }
48328
- writeFileSync7(
48492
+ writeFileSync8(
48329
48493
  join19(tmp, HERMES_MARKER),
48330
48494
  `managed by the Open Artifacts bus installer: edits are replaced on reinstall. ${pluginHash(shipped)}
48331
48495
  `
48332
48496
  );
48333
48497
  if (keepHabits)
48334
- writeFileSync7(join19(tmp, HERMES_HABITS_MARKER), HABITS_MARKER_TEXT);
48498
+ writeFileSync8(join19(tmp, HERMES_HABITS_MARKER), HABITS_MARKER_TEXT);
48335
48499
  if (state === "stale") rmSync5(dest, { recursive: true, force: true });
48336
- renameSync9(tmp, dest);
48500
+ renameSync10(tmp, dest);
48337
48501
  } catch (e) {
48338
48502
  rmSync5(tmp, { recursive: true, force: true });
48339
48503
  throw e;
@@ -48400,18 +48564,18 @@ import { fileURLToPath as fileURLToPath5 } from "node:url";
48400
48564
 
48401
48565
  // src/steps/skill.ts
48402
48566
  import {
48403
- chmodSync as chmodSync10,
48567
+ chmodSync as chmodSync11,
48404
48568
  existsSync as existsSync5,
48405
48569
  lstatSync as lstatSync11,
48406
48570
  mkdirSync as mkdirSync10,
48407
48571
  readdirSync as readdirSync6,
48408
48572
  readFileSync as readFileSync16,
48409
48573
  realpathSync as realpathSync10,
48410
- renameSync as renameSync10,
48574
+ renameSync as renameSync11,
48411
48575
  rmdirSync as rmdirSync2,
48412
48576
  rmSync as rmSync6,
48413
48577
  statSync as statSync10,
48414
- writeFileSync as writeFileSync8
48578
+ writeFileSync as writeFileSync9
48415
48579
  } from "node:fs";
48416
48580
  import { dirname as dirname10, join as join20 } from "node:path";
48417
48581
  var SKILL_MARKER = "<!-- managed by the Open Artifacts bus installer: edits are replaced on reinstall. -->";
@@ -48535,9 +48699,9 @@ var writeAtomic = (path, text3) => {
48535
48699
  mode = statSync10(path).mode & 4095;
48536
48700
  } catch {
48537
48701
  }
48538
- writeFileSync8(tmp, text3);
48539
- if (mode !== void 0) chmodSync10(tmp, mode);
48540
- renameSync10(tmp, path);
48702
+ writeFileSync9(tmp, text3);
48703
+ if (mode !== void 0) chmodSync11(tmp, mode);
48704
+ renameSync11(tmp, path);
48541
48705
  } catch (e) {
48542
48706
  try {
48543
48707
  rmSync6(tmp, { force: true });
@@ -49538,9 +49702,9 @@ function writeAtomic2(path, data, mode) {
49538
49702
  }
49539
49703
  const tmp = `${dest}.${process.pid}.${randomBytes4(4).toString("hex")}.tmp`;
49540
49704
  try {
49541
- writeFileSync9(tmp, data, { mode: m, flag: "wx" });
49542
- chmodSync11(tmp, m);
49543
- renameSync11(tmp, dest);
49705
+ writeFileSync10(tmp, data, { mode: m, flag: "wx" });
49706
+ chmodSync12(tmp, m);
49707
+ renameSync12(tmp, dest);
49544
49708
  } catch (e) {
49545
49709
  rmSync9(tmp, { force: true });
49546
49710
  throw e;
@@ -50198,11 +50362,11 @@ function habitsLine(ctx) {
50198
50362
  init_src();
50199
50363
  import { randomBytes as randomBytes5 } from "node:crypto";
50200
50364
  import {
50201
- chmodSync as chmodSync12,
50365
+ chmodSync as chmodSync13,
50202
50366
  closeSync as closeSync7,
50203
50367
  mkdirSync as mkdirSync12,
50204
50368
  openSync as openSync7,
50205
- renameSync as renameSync12,
50369
+ renameSync as renameSync13,
50206
50370
  rmSync as rmSync10,
50207
50371
  unlinkSync as unlinkSync3,
50208
50372
  writeSync as writeSync3
@@ -50254,7 +50418,7 @@ function checkVerificationUri(uri, hub) {
50254
50418
  }
50255
50419
  function writeMachineFile(home2, body) {
50256
50420
  mkdirSync12(home2, { recursive: true, mode: 448 });
50257
- chmodSync12(home2, 448);
50421
+ chmodSync13(home2, 448);
50258
50422
  const tmp = join25(home2, `.machine.json.${randomBytes5(8).toString("hex")}.tmp`);
50259
50423
  const fd = openSync7(tmp, "wx", 384);
50260
50424
  try {
@@ -50266,8 +50430,8 @@ function writeMachineFile(home2, body) {
50266
50430
  }
50267
50431
  closeSync7(fd);
50268
50432
  try {
50269
- chmodSync12(tmp, 384);
50270
- renameSync12(tmp, join25(home2, "machine.json"));
50433
+ chmodSync13(tmp, 384);
50434
+ renameSync13(tmp, join25(home2, "machine.json"));
50271
50435
  } catch (e) {
50272
50436
  unlinkSync3(tmp);
50273
50437
  throw e;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@open-artifacts/bus",
3
3
  "type": "module",
4
- "version": "0.141.0",
4
+ "version": "0.143.0",
5
5
  "description": "The Open Artifacts bus: your AI agents reach each other across machines.",
6
6
  "license": "MIT",
7
7
  "repository": {