@open-artifacts/bus 0.138.0 → 0.140.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.138.0";
14
+ const CLIENT_VERSION = "0.140.0";
15
15
 
16
16
  type Frame = Json & { type: string; id: string };
17
17
  type Ctx = {
@@ -396,6 +396,28 @@ const statusSetText = (state: string, label?: string): string =>
396
396
  const earlierStatusText = (message: string): string =>
397
397
  `Your previous status did not reach the user. ${message}`;
398
398
 
399
+ /** The `follow` result (#1317). */
400
+ const followText = (url: string): string =>
401
+ `Following ${url}. You get a notice here when it changes.`;
402
+
403
+ /** The `unfollow` result. */
404
+ const unfollowText = (removed: boolean, artifact: string): string =>
405
+ removed
406
+ ? `Stopped following ${artifact}.`
407
+ : `You were not following ${artifact}.`;
408
+
409
+ /** The `following` result: one line per artifact, newest first. */
410
+ const followingText = (
411
+ follows: readonly { url: string; followed_at: string }[],
412
+ ): string =>
413
+ follows.length
414
+ ? follows.map((f) => `${f.url} (since ${f.followed_at})`).join("\n")
415
+ : "You are not following any artifacts.";
416
+
417
+ /** What an agent sees when its daemon is too old for the follow frames. */
418
+ const FOLLOW_OLD_DAEMON =
419
+ "This oa-bus daemon is too old to follow artifacts. Ask the user to update oa-bus.";
420
+
399
421
  /** @oa/bus-protocol BAD_NS_CHARS: control, bidi and zero-width characters. */
400
422
  const BAD_LABEL_CHARS =
401
423
  // biome-ignore lint/suspicious/noControlCharactersInRegex: rejecting them is the point
@@ -513,6 +535,10 @@ export const copy = {
513
535
  statusLabelTooLong,
514
536
  statusSetText,
515
537
  earlierStatusText,
538
+ followText,
539
+ unfollowText,
540
+ followingText,
541
+ FOLLOW_OLD_DAEMON,
516
542
  displayKind,
517
543
  statusSaysText,
518
544
  rosterLine,
@@ -602,6 +628,35 @@ const TOOLS = [
602
628
  additionalProperties: false,
603
629
  },
604
630
  },
631
+ {
632
+ name: "oabus_follow",
633
+ label: "Open Artifacts bus: follow artifact",
634
+ description:
635
+ "Follow an Open Artifacts artifact, by id or link, to get a notice when it changes.",
636
+ parameters: {
637
+ type: "object",
638
+ properties: { artifact: { type: "string" } },
639
+ required: ["artifact"],
640
+ additionalProperties: false,
641
+ },
642
+ },
643
+ {
644
+ name: "oabus_unfollow",
645
+ label: "Open Artifacts bus: unfollow artifact",
646
+ description: "Stop following an artifact, by id or link.",
647
+ parameters: {
648
+ type: "object",
649
+ properties: { artifact: { type: "string" } },
650
+ required: ["artifact"],
651
+ additionalProperties: false,
652
+ },
653
+ },
654
+ {
655
+ name: "oabus_following",
656
+ label: "Open Artifacts bus: list follows",
657
+ description: "List the artifacts you follow.",
658
+ parameters: none,
659
+ },
605
660
  ] as const;
606
661
 
607
662
  const STATES = ["working", "idle", "blocked", "waiting_on_owner"];
@@ -915,7 +970,7 @@ function open(
915
970
  // #1295: this asset decodes away rows and the new refusals.
916
971
  // #1525: and a config file that is pending approval.
917
972
  // #1635: and may send a rename.
918
- caps: ["mailbox", "pending", "rename"],
973
+ caps: ["mailbox", "pending", "rename", "follow"],
919
974
  attest: start ? { proc_start: start } : {},
920
975
  }),
921
976
  );
@@ -1202,11 +1257,42 @@ export default function oaBus(pi: Pi): void {
1202
1257
  return stripTerminalControls(String(r.body));
1203
1258
  }
1204
1259
  if (name === "oabus_set_status") return statusTool(args, link);
1260
+ if (
1261
+ name === "oabus_follow" ||
1262
+ name === "oabus_unfollow" ||
1263
+ name === "oabus_following"
1264
+ )
1265
+ return followTool(name.slice("oabus_".length), args, link);
1205
1266
  const r = await link.request({ type: "self", row: true });
1206
1267
  if (r.type !== "agent") failed(r);
1207
1268
  return selfText((r.agent ?? null) as Json | null);
1208
1269
  };
1209
1270
 
1271
+ /** follow, unfollow and following (#1317). Refusals are the hub's or daemon's copy, as-is. */
1272
+ const followTool = async (
1273
+ name: string,
1274
+ args: Json,
1275
+ link: Link,
1276
+ ): Promise<string> => {
1277
+ const artifact =
1278
+ typeof args.artifact === "string" ? args.artifact.trim() : "";
1279
+ if (name !== "following" && !artifact)
1280
+ throw new Error("oa-bus: artifact is required (an id or a link)");
1281
+ const r = await link.request(
1282
+ name === "following" ? { type: name } : { type: name, artifact },
1283
+ );
1284
+ if (r.type === "followed") return followText(String(r.url));
1285
+ if (r.type === "unfollowed")
1286
+ return unfollowText(r.removed === true, artifact);
1287
+ if (r.type === "follows")
1288
+ return followingText(
1289
+ (r.follows ?? []) as { url: string; followed_at: string }[],
1290
+ );
1291
+ if (r.type === "error" && r.code === "bad_frame")
1292
+ throw new Error(FOLLOW_OLD_DAEMON);
1293
+ return failed(r);
1294
+ };
1295
+
1210
1296
  /** set_status. Arguments are checked first. Refusals are the daemon's copy, as-is. */
1211
1297
  const statusTool = async (args: Json, link: Link): Promise<string> => {
1212
1298
  const state = String(args.state ?? "");
@@ -343,6 +343,23 @@ def earlier_status_text(message):
343
343
  return f"Your previous status did not reach the user. {message}"
344
344
 
345
345
 
346
+ def follow_text(url):
347
+ return f"Following {url}. You get a notice here when it changes."
348
+
349
+
350
+ def unfollow_text(removed, artifact):
351
+ return f"Stopped following {artifact}." if removed else f"You were not following {artifact}."
352
+
353
+
354
+ def following_text(follows):
355
+ if not follows:
356
+ return "You are not following any artifacts."
357
+ return "\n".join(f"{f['url']} (since {f['followed_at']})" for f in follows)
358
+
359
+
360
+ FOLLOW_OLD_DAEMON = "This oa-bus daemon is too old to follow artifacts. Ask the user to update oa-bus."
361
+
362
+
346
363
  def status_label_too_long(n):
347
364
  return (
348
365
  f"oa-bus: that label is {n} characters, and the limit is 64. "
@@ -130,7 +130,18 @@ def _base(frame, types):
130
130
 
131
131
  # --- Frames the plugin sends.
132
132
 
133
- ADAPTER_TYPES = ("hello", "send", "list", "self", "fetch", "ack", "set_status")
133
+ ADAPTER_TYPES = (
134
+ "hello",
135
+ "send",
136
+ "list",
137
+ "self",
138
+ "fetch",
139
+ "ack",
140
+ "set_status",
141
+ "follow",
142
+ "unfollow",
143
+ "following",
144
+ )
134
145
 
135
146
 
136
147
  def check_adapter_frame(frame):
@@ -184,10 +195,17 @@ def check_adapter_frame(frame):
184
195
  lambda v: _is_str(v, 1, 128) and len([*v]) <= 64 and v == v.strip(),
185
196
  "a label of 1 to 64 characters",
186
197
  )
198
+ elif t == "follow" or t == "unfollow":
199
+ _need(
200
+ frame,
201
+ "artifact",
202
+ lambda v: _is_str(v, 1, 2048) and well_formed(v),
203
+ "a well-formed artifact id or link",
204
+ )
187
205
  elif t == "self":
188
206
  if "row" in frame and frame["row"] is not True:
189
207
  _fail("row: expected true")
190
- if t in ("send", "list", "self", "fetch", "set_status"):
208
+ if t in ("send", "list", "self", "fetch", "set_status", "follow", "unfollow", "following"):
191
209
  _opt(frame, "late", lambda v: v is True, "true")
192
210
  return frame
193
211
 
@@ -204,6 +222,9 @@ DAEMON_TYPES = (
204
222
  "notice",
205
223
  "error",
206
224
  "status_set",
225
+ "followed",
226
+ "unfollowed",
227
+ "follows",
207
228
  )
208
229
 
209
230
 
@@ -280,6 +301,26 @@ def parse_daemon_frame(frame):
280
301
  elif t == "error":
281
302
  _need(frame, "code", _is_str, "a string")
282
303
  _need(frame, "message", _is_str, "a string")
304
+ elif t == "followed":
305
+ _need(frame, "artifact_id", _is_str, "a string")
306
+ _need(frame, "url", _is_str, "a string")
307
+ _need(frame, "followed_at", _is_str, "a string")
308
+ elif t == "unfollowed":
309
+ _need(frame, "removed", lambda v: isinstance(v, bool), "a boolean")
310
+ elif t == "follows":
311
+ _need(
312
+ frame,
313
+ "follows",
314
+ lambda v: isinstance(v, list)
315
+ and all(
316
+ isinstance(f, dict)
317
+ and _is_str(f.get("artifact_id"))
318
+ and _is_str(f.get("url"))
319
+ and _is_str(f.get("followed_at"))
320
+ for f in v
321
+ ),
322
+ "a list of follows",
323
+ )
283
324
  elif t == "status_set":
284
325
  _opt(
285
326
  frame,
@@ -44,7 +44,7 @@ class Link:
44
44
  "pid": pid,
45
45
  "cwd": cwd,
46
46
  "proposed_name": name,
47
- "caps": ["mailbox", "pending"],
47
+ "caps": ["mailbox", "pending", "follow"],
48
48
  "attest": {"proc_start": proc_start} if proc_start else {},
49
49
  }
50
50
  self._home = home if home is not None else bus_home()
@@ -70,6 +70,31 @@ TOOLS = [
70
70
  "additionalProperties": False,
71
71
  },
72
72
  },
73
+ {
74
+ "name": "oabus_follow",
75
+ "description": "Follow an Open Artifacts artifact, by id or link, to get a notice when it changes.",
76
+ "parameters": {
77
+ "type": "object",
78
+ "properties": {"artifact": {"type": "string"}},
79
+ "required": ["artifact"],
80
+ "additionalProperties": False,
81
+ },
82
+ },
83
+ {
84
+ "name": "oabus_unfollow",
85
+ "description": "Stop following an artifact, by id or link.",
86
+ "parameters": {
87
+ "type": "object",
88
+ "properties": {"artifact": {"type": "string"}},
89
+ "required": ["artifact"],
90
+ "additionalProperties": False,
91
+ },
92
+ },
93
+ {
94
+ "name": "oabus_following",
95
+ "description": "List the artifacts you follow.",
96
+ "parameters": _NONE,
97
+ },
73
98
  ]
74
99
 
75
100
 
@@ -155,12 +180,31 @@ def run(name, args, link):
155
180
  return copy.strip_terminal_controls(str(r["body"]))
156
181
  if name == "oabus_set_status":
157
182
  return _status(args, link)
183
+ if name in ("oabus_follow", "oabus_unfollow", "oabus_following"):
184
+ return _follow(name[len("oabus_") :], args, link)
158
185
  r = link.request({"type": "self", "row": True})
159
186
  if r["type"] != "agent":
160
187
  _failed(r)
161
188
  return copy.self_text(r.get("agent"))
162
189
 
163
190
 
191
+ def _follow(name, args, link):
192
+ """follow, unfollow and following (#1317). Refusals are the hub's or daemon's copy, as-is."""
193
+ artifact = args.get("artifact").strip() if isinstance(args.get("artifact"), str) else ""
194
+ if name != "following" and not artifact:
195
+ raise ToolError("oa-bus: artifact is required (an id or a link)")
196
+ r = link.request({"type": name} if name == "following" else {"type": name, "artifact": artifact})
197
+ if r["type"] == "followed":
198
+ return copy.follow_text(str(r["url"]))
199
+ if r["type"] == "unfollowed":
200
+ return copy.unfollow_text(r["removed"] is True, artifact)
201
+ if r["type"] == "follows":
202
+ return copy.following_text(r["follows"])
203
+ if r["type"] == "error" and r.get("code") == "bad_frame":
204
+ raise ToolError(copy.FOLLOW_OLD_DAEMON)
205
+ _failed(r)
206
+
207
+
164
208
  def _status(args, link):
165
209
  """set_status. Arguments are checked first. Refusals are the daemon's copy, as-is."""
166
210
  state = str(args.get("state") or "")
package/dist/index.js CHANGED
@@ -31408,7 +31408,24 @@ var init_caps = __esm({
31408
31408
  * only when its hello listed it, and lists it in `hello_ok.caps`; any other
31409
31409
  * socket sees today's isolation.
31410
31410
  */
31411
- links: "links"
31411
+ links: "links",
31412
+ /**
31413
+ * Scoped role reach (#1346): a role the member gave reach to other
31414
+ * namespaces lets its holder see and message the agents there (each row
31415
+ * carries its own `namespace`; a name in two namespaces is `ambiguous`
31416
+ * until the send names `to_namespace`), and those agents reply to it. The
31417
+ * hub widens a socket's roster and routing only when its hello listed it,
31418
+ * and lists it in `hello_ok.caps`; any other socket sees today's behaviour.
31419
+ */
31420
+ reach: "reach",
31421
+ /**
31422
+ * Follows (#1317): the client may send `follow`, `unfollow` and `following`
31423
+ * and decodes `followed`, `unfollowed`, `follows` and the `follow_limit`
31424
+ * error. The hub answers those frames only on a socket whose hello listed
31425
+ * it (any other gets `bad_frame`, as an old hub would) and lists it in
31426
+ * `hello_ok.caps`; a client sends them only when it did.
31427
+ */
31428
+ follow: "follow"
31412
31429
  };
31413
31430
  MAX_CAPS = 16;
31414
31431
  CapTokenSchema = external_exports.string().regex(/^[a-z][a-z0-9_-]{0,31}$/);
@@ -32057,7 +32074,7 @@ function decode3(raw, schema, caps) {
32057
32074
  function decodeServerFrame(raw) {
32058
32075
  return decode3(raw, ServerFrameSchema, SERVER_CAPS);
32059
32076
  }
32060
- var PING, PONG, isWellFormed, WellFormedText, FrameIdSchema, base, BodySchema, InlineBodySchema, distinct, Hello, AgentUp, AgentDown, Sessions, Send, Ack, Refuse, List, Fetch, Status, Rename, 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;
32077
+ 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;
32061
32078
  var init_protocol2 = __esm({
32062
32079
  "../bus-protocol/src/protocol.ts"() {
32063
32080
  "use strict";
@@ -32193,6 +32210,45 @@ var init_protocol2 = __esm({
32193
32210
  /** A tool rename is `chosen`; a harness reverting to its fallback is `default`. Absent means `chosen`. */
32194
32211
  name_kind: NameKindSchema.optional()
32195
32212
  });
32213
+ FollowRefSchema = WellFormedText.pipe(external_exports.string().min(1).max(2048));
32214
+ Follow = external_exports.strictObject({
32215
+ ...base,
32216
+ type: external_exports.literal("follow"),
32217
+ from_ref: AgentRefSchema,
32218
+ artifact: FollowRefSchema
32219
+ });
32220
+ Unfollow = external_exports.strictObject({
32221
+ ...base,
32222
+ type: external_exports.literal("unfollow"),
32223
+ from_ref: AgentRefSchema,
32224
+ artifact: FollowRefSchema
32225
+ });
32226
+ Following = external_exports.strictObject({
32227
+ ...base,
32228
+ type: external_exports.literal("following"),
32229
+ from_ref: AgentRefSchema
32230
+ });
32231
+ MAX_FOLLOWS = 200;
32232
+ FollowEntry = external_exports.strictObject({
32233
+ artifact_id: external_exports.string().min(1).max(64),
32234
+ url: external_exports.string().min(1).max(2048),
32235
+ followed_at: IsoTimeSchema
32236
+ });
32237
+ Followed = external_exports.strictObject({
32238
+ ...base,
32239
+ type: external_exports.literal("followed"),
32240
+ ...FollowEntry.shape
32241
+ });
32242
+ Unfollowed = external_exports.strictObject({
32243
+ ...base,
32244
+ type: external_exports.literal("unfollowed"),
32245
+ removed: external_exports.boolean()
32246
+ });
32247
+ Follows = external_exports.strictObject({
32248
+ ...base,
32249
+ type: external_exports.literal("follows"),
32250
+ follows: external_exports.array(FollowEntry).max(MAX_FOLLOWS)
32251
+ });
32196
32252
  HelloOk = external_exports.strictObject({
32197
32253
  ...base,
32198
32254
  type: external_exports.literal("hello_ok"),
@@ -32277,7 +32333,9 @@ var init_protocol2 = __esm({
32277
32333
  "not_found",
32278
32334
  "too_large",
32279
32335
  "rate_limited",
32280
- "internal"
32336
+ "internal",
32337
+ /** Only to a socket whose hello listed `BUS_CAPS.follow` (#1317). */
32338
+ "follow_limit"
32281
32339
  ]),
32282
32340
  message: WellFormedText.pipe(external_exports.string().max(1024))
32283
32341
  });
@@ -32326,7 +32384,10 @@ var init_protocol2 = __esm({
32326
32384
  List,
32327
32385
  Fetch,
32328
32386
  Status,
32329
- Rename
32387
+ Rename,
32388
+ Follow,
32389
+ Unfollow,
32390
+ Following
32330
32391
  ]);
32331
32392
  ServerFrameSchema = external_exports.discriminatedUnion("type", [
32332
32393
  HelloOk,
@@ -32338,7 +32399,10 @@ var init_protocol2 = __esm({
32338
32399
  Deliver,
32339
32400
  ReceiptUpdate,
32340
32401
  RosterChanged,
32341
- Renamed
32402
+ Renamed,
32403
+ Followed,
32404
+ Unfollowed,
32405
+ Follows
32342
32406
  ]);
32343
32407
  FrameSchema = external_exports.discriminatedUnion("type", [
32344
32408
  Hello,
@@ -32352,6 +32416,9 @@ var init_protocol2 = __esm({
32352
32416
  Fetch,
32353
32417
  Status,
32354
32418
  Rename,
32419
+ Follow,
32420
+ Unfollow,
32421
+ Following,
32355
32422
  HelloOk,
32356
32423
  AgentOk,
32357
32424
  ReceiptFrame,
@@ -32361,7 +32428,10 @@ var init_protocol2 = __esm({
32361
32428
  Deliver,
32362
32429
  ReceiptUpdate,
32363
32430
  RosterChanged,
32364
- Renamed
32431
+ Renamed,
32432
+ Followed,
32433
+ Unfollowed,
32434
+ Follows
32365
32435
  ]);
32366
32436
  MAX_RAW_FRAME_CHARS = 2 * LIMITS.maxMessageBytes + 4096;
32367
32437
  SERVER_CAPS = { depth: 5, tokens: 65536, structural: 131072 };
@@ -32417,7 +32487,7 @@ var init_src = __esm({
32417
32487
  });
32418
32488
 
32419
32489
  // ../bus-ipc/src/frames.ts
32420
- var V, MAX_BODY_BYTES, MAX_LINE_BYTES, INLINE_CAP_BYTES, KIND, KIND_TOKEN, AGENT_REF, base2, late, isWellFormed2, WELL_FORMED, CLIENT_VERSION, clientVersion, ADAPTER_CAPS, Hello2, SPAWNED_SOURCES, optIn, Send2, List2, Self, Fetch2, Ack2, SetStatus, Rename2, StatusRequest, AdapterFrame, ConfigFile, AgentInfo, Welcome, Receipt, Roster2, Agent, StatusSet, Body, Deliver2, Notice2, ErrorFrame2, StatusReply, DaemonFrame;
32490
+ var V, MAX_BODY_BYTES, MAX_LINE_BYTES, INLINE_CAP_BYTES, KIND, KIND_TOKEN, AGENT_REF, base2, late, isWellFormed2, WELL_FORMED, CLIENT_VERSION, clientVersion, ADAPTER_CAPS, Hello2, SPAWNED_SOURCES, optIn, Send2, List2, Self, Fetch2, Ack2, SetStatus, Rename2, Follow2, Unfollow2, Following2, StatusRequest, AdapterFrame, ConfigFile, AgentInfo, Welcome, Receipt, Roster2, Agent, StatusSet, FollowEntry2, Followed2, Unfollowed2, Follows2, Body, Deliver2, Notice2, ErrorFrame2, StatusReply, DaemonFrame;
32421
32491
  var init_frames = __esm({
32422
32492
  "../bus-ipc/src/frames.ts"() {
32423
32493
  "use strict";
@@ -32434,7 +32504,7 @@ var init_frames = __esm({
32434
32504
  late = { late: external_exports.array(external_exports.string().min(1)).optional() };
32435
32505
  isWellFormed2 = (s) => s.isWellFormed();
32436
32506
  WELL_FORMED = { message: "text is not well-formed unicode" };
32437
- CLIENT_VERSION = true ? "0.138.0" : "0.0.0";
32507
+ CLIENT_VERSION = true ? "0.140.0" : "0.0.0";
32438
32508
  clientVersion = {
32439
32509
  client_version: external_exports.string().min(1).max(64).optional()
32440
32510
  };
@@ -32453,7 +32523,15 @@ var init_frames = __esm({
32453
32523
  * adapter that listed it, and an adapter sends the frame only to a daemon
32454
32524
  * whose welcome listed it, so neither side meets a frame its decoder lacks.
32455
32525
  */
32456
- rename: "rename"
32526
+ rename: "rename",
32527
+ /**
32528
+ * `follow` (#1317): the adapter may send `follow`, `unfollow` and
32529
+ * `following`. The daemon lists `follow` in `welcome.caps` only for an
32530
+ * adapter that listed it, and an adapter sends the frames only to a daemon
32531
+ * whose welcome listed it. The adapter tools are offered either way: a
32532
+ * daemon without it answers them with a plain "update" error instead.
32533
+ */
32534
+ follow: "follow"
32457
32535
  };
32458
32536
  Hello2 = external_exports.object({
32459
32537
  ...base2,
@@ -32557,6 +32635,23 @@ var init_frames = __esm({
32557
32635
  type: external_exports.literal("rename"),
32558
32636
  name: external_exports.string().min(1).max(64).refine(isWellFormed2, WELL_FORMED)
32559
32637
  });
32638
+ Follow2 = external_exports.object({
32639
+ ...base2,
32640
+ ...optIn,
32641
+ type: external_exports.literal("follow"),
32642
+ artifact: external_exports.string().min(1).max(2048).refine(isWellFormed2, WELL_FORMED)
32643
+ });
32644
+ Unfollow2 = external_exports.object({
32645
+ ...base2,
32646
+ ...optIn,
32647
+ type: external_exports.literal("unfollow"),
32648
+ artifact: external_exports.string().min(1).max(2048).refine(isWellFormed2, WELL_FORMED)
32649
+ });
32650
+ Following2 = external_exports.object({
32651
+ ...base2,
32652
+ ...optIn,
32653
+ type: external_exports.literal("following")
32654
+ });
32560
32655
  StatusRequest = external_exports.object({
32561
32656
  ...base2,
32562
32657
  ...clientVersion,
@@ -32573,7 +32668,10 @@ var init_frames = __esm({
32573
32668
  Fetch2,
32574
32669
  Ack2,
32575
32670
  SetStatus,
32576
- Rename2
32671
+ Rename2,
32672
+ Follow2,
32673
+ Unfollow2,
32674
+ Following2
32577
32675
  ]);
32578
32676
  ConfigFile = external_exports.object({
32579
32677
  file: external_exports.string(),
@@ -32612,7 +32710,7 @@ var init_frames = __esm({
32612
32710
  bus_name: external_exports.string(),
32613
32711
  namespace: external_exports.string(),
32614
32712
  global: external_exports.boolean(),
32615
- /** What this daemon accepts (ADAPTER_CAPS), only for an adapter that listed `rename`. */
32713
+ /** What this daemon accepts (ADAPTER_CAPS), only for an adapter that listed `rename` or `follow`. */
32616
32714
  caps: external_exports.array(external_exports.string().max(32)).max(16).optional()
32617
32715
  });
32618
32716
  Receipt = external_exports.object({
@@ -32649,6 +32747,29 @@ var init_frames = __esm({
32649
32747
  earlier: external_exports.object({ code: external_exports.string(), message: external_exports.string() }).optional(),
32650
32748
  ...late
32651
32749
  });
32750
+ FollowEntry2 = external_exports.object({
32751
+ artifact_id: external_exports.string(),
32752
+ url: external_exports.string(),
32753
+ followed_at: external_exports.string()
32754
+ });
32755
+ Followed2 = external_exports.object({
32756
+ ...base2,
32757
+ type: external_exports.literal("followed"),
32758
+ ...FollowEntry2.shape,
32759
+ ...late
32760
+ });
32761
+ Unfollowed2 = external_exports.object({
32762
+ ...base2,
32763
+ type: external_exports.literal("unfollowed"),
32764
+ removed: external_exports.boolean(),
32765
+ ...late
32766
+ });
32767
+ Follows2 = external_exports.object({
32768
+ ...base2,
32769
+ type: external_exports.literal("follows"),
32770
+ follows: external_exports.array(FollowEntry2),
32771
+ ...late
32772
+ });
32652
32773
  Body = external_exports.object({
32653
32774
  ...base2,
32654
32775
  type: external_exports.literal("body"),
@@ -32740,7 +32861,10 @@ var init_frames = __esm({
32740
32861
  Notice2,
32741
32862
  ErrorFrame2,
32742
32863
  StatusReply,
32743
- StatusSet
32864
+ StatusSet,
32865
+ Followed2,
32866
+ Unfollowed2,
32867
+ Follows2
32744
32868
  ]);
32745
32869
  }
32746
32870
  });
@@ -33141,7 +33265,7 @@ function selfText(agent) {
33141
33265
  };
33142
33266
  return JSON.stringify(shown4, null, 2);
33143
33267
  }
33144
- 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;
33268
+ 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, followText, unfollowText, followingText, FOLLOW_OLD_DAEMON, STATUS_STALE_MS, agoText, displayLabel, awayTime, replyGoneText;
33145
33269
  var init_copy = __esm({
33146
33270
  "../bus-ipc/src/copy.ts"() {
33147
33271
  "use strict";
@@ -33243,6 +33367,10 @@ ${neutralizeBody(m.body)}`;
33243
33367
  statusLabelTooLong = (n) => `oa-bus: that label is ${n} characters, and the limit is ${LIMITS.maxLabelChars}. Your status did not change. Send a shorter one.`;
33244
33368
  statusSetText = (state, label) => `Your status is now ${state}${label ? `: "${label}"` : ""}. The user sees it as your own report.`;
33245
33369
  earlierStatusText = (message) => `Your previous status did not reach the user. ${message}`;
33370
+ followText = (url2) => `Following ${url2}. You get a notice here when it changes.`;
33371
+ unfollowText = (removed, artifact) => removed ? `Stopped following ${artifact}.` : `You were not following ${artifact}.`;
33372
+ followingText = (follows) => follows.length ? follows.map((f) => `${f.url} (since ${f.followed_at})`).join("\n") : "You are not following any artifacts.";
33373
+ FOLLOW_OLD_DAEMON = "This oa-bus daemon is too old to follow artifacts. Ask the user to update oa-bus.";
33246
33374
  STATUS_STALE_MS = 10 * 6e4;
33247
33375
  agoText = (ms) => {
33248
33376
  const mins = Math.round(ms / 6e4);
@@ -33593,6 +33721,8 @@ async function callTool(name, args, client, signal) {
33593
33721
  async function run(name, args, request) {
33594
33722
  try {
33595
33723
  if (name === "set_status") return await statusTool(args, request);
33724
+ if (name === "follow" || name === "unfollow" || name === "following")
33725
+ return await followTool(name, args, request);
33596
33726
  if (name === "list_agents") {
33597
33727
  const r = await request({ type: "list" });
33598
33728
  if (r.type !== "roster") return failed(r);
@@ -33684,6 +33814,18 @@ ${earlierStatusText(r.earlier.message)}` : done,
33684
33814
  return text(STATUS_COPY.bad_frame, true);
33685
33815
  return text(r.message, true);
33686
33816
  }
33817
+ async function followTool(name, args, request) {
33818
+ const artifact = typeof args.artifact === "string" ? args.artifact.trim() : "";
33819
+ if (name !== "following" && !artifact)
33820
+ return text("oa-bus: artifact is required (an id or a link)", true);
33821
+ const r = name === "following" ? await request({ type: "following" }) : await request({ type: name, artifact });
33822
+ if (r.type === "followed") return text(followText(r.url));
33823
+ if (r.type === "unfollowed") return text(unfollowText(r.removed, artifact));
33824
+ if (r.type === "follows") return text(followingText(r.follows));
33825
+ if (r.type === "error" && r.code === "bad_frame")
33826
+ return text(FOLLOW_OLD_DAEMON, true);
33827
+ return failed(r);
33828
+ }
33687
33829
  async function namespacesOf(name, request) {
33688
33830
  try {
33689
33831
  const r = await request({ type: "list" });
@@ -33787,6 +33929,31 @@ var init_tools = __esm({
33787
33929
  required: ["state"],
33788
33930
  additionalProperties: false
33789
33931
  }
33932
+ },
33933
+ {
33934
+ name: "follow",
33935
+ description: "Follow an Open Artifacts artifact, by id or link, to get a notice when it changes.",
33936
+ inputSchema: {
33937
+ type: "object",
33938
+ properties: { artifact: { type: "string" } },
33939
+ required: ["artifact"],
33940
+ additionalProperties: false
33941
+ }
33942
+ },
33943
+ {
33944
+ name: "unfollow",
33945
+ description: "Stop following an artifact, by id or link.",
33946
+ inputSchema: {
33947
+ type: "object",
33948
+ properties: { artifact: { type: "string" } },
33949
+ required: ["artifact"],
33950
+ additionalProperties: false
33951
+ }
33952
+ },
33953
+ {
33954
+ name: "following",
33955
+ description: "List the artifacts you follow.",
33956
+ inputSchema: none
33790
33957
  }
33791
33958
  ];
33792
33959
  text = (t, isError) => ({
@@ -33845,7 +34012,7 @@ function codexHello(call, pid, ppid) {
33845
34012
  pid,
33846
34013
  ...call.cwd ? { cwd: call.cwd } : {},
33847
34014
  proposed_name: "codex",
33848
- caps: [ADAPTER_CAPS.mailbox, ADAPTER_CAPS.pending],
34015
+ caps: [ADAPTER_CAPS.mailbox, ADAPTER_CAPS.pending, ADAPTER_CAPS.follow],
33849
34016
  codex: {
33850
34017
  thread_id: call.threadId,
33851
34018
  call_id: call.callId,
@@ -34088,7 +34255,7 @@ function sessionHello(session, pid, cwd) {
34088
34255
  pid,
34089
34256
  cwd,
34090
34257
  proposed_name: fitName(session.name, 64) || void 0,
34091
- caps: [ADAPTER_CAPS.mailbox, ADAPTER_CAPS.pending],
34258
+ caps: [ADAPTER_CAPS.mailbox, ADAPTER_CAPS.pending, ADAPTER_CAPS.follow],
34092
34259
  attest: {
34093
34260
  session_id: session.sessionId,
34094
34261
  socket_path: session.socketPath ?? void 0
@@ -37981,7 +38148,7 @@ async function handleToolCall(input2) {
37981
38148
  pid: process.pid,
37982
38149
  cwd: session.directory,
37983
38150
  proposed_name: nameOf(session.title),
37984
- caps: [ADAPTER_CAPS.mailbox, ADAPTER_CAPS.pending],
38151
+ caps: [ADAPTER_CAPS.mailbox, ADAPTER_CAPS.pending, ADAPTER_CAPS.follow],
37985
38152
  attest: { session_id: sessionId }
37986
38153
  });
37987
38154
  let client;
@@ -40323,7 +40490,7 @@ var HubConnection = class {
40323
40490
  // Reply ids: the hub then names each sender's agent (deliver.from_id).
40324
40491
  // Mailboxes: the hub then sends queued/since, away rows and the new
40325
40492
  // refusals, and honours agent_up.replaces (#1295).
40326
- caps: [BUS_CAPS.ids, BUS_CAPS.mailbox, BUS_CAPS.links]
40493
+ caps: [BUS_CAPS.ids, BUS_CAPS.mailbox, BUS_CAPS.links, BUS_CAPS.follow]
40327
40494
  });
40328
40495
  this.#guard("sessions", () => {
40329
40496
  this.send({
@@ -40818,6 +40985,10 @@ var Pending = class {
40818
40985
  };
40819
40986
  var MACHINE_CAP_COPY = "This machine has too many agents on the bus right now. Close a session you no longer need; this one retries in a few minutes.";
40820
40987
  var MEMBER_CAP_COPY = "Your bus has too many agents right now. Close a session you no longer need; this one retries in a few minutes.";
40988
+ var FOLLOW_COPY = {
40989
+ down: "The hub is not connected right now. Try again in a moment.",
40990
+ old_hub: "This Open Artifacts hub is too old to follow artifacts. Ask the user to update it."
40991
+ };
40821
40992
  var CAP_COPY = {
40822
40993
  machine: MACHINE_CAP_COPY,
40823
40994
  member: MEMBER_CAP_COPY
@@ -40916,6 +41087,47 @@ function routeLocal(frame, hello, reply, ctx) {
40916
41087
  (f) => reply({ ...f, v: 1, id: frame.id })
40917
41088
  );
40918
41089
  }
41090
+ case "follow":
41091
+ case "unfollow":
41092
+ case "following": {
41093
+ if (!hello.caps?.includes(ADAPTER_CAPS.follow))
41094
+ return {
41095
+ type: "error",
41096
+ code: "bad_frame",
41097
+ message: "follow is not supported on this connection"
41098
+ };
41099
+ const cap = ctx.limited?.(ref);
41100
+ if (cap)
41101
+ return { type: "error", code: "rate_limited", message: CAP_COPY[cap] };
41102
+ const support = ctx.followSupport?.() ?? "down";
41103
+ if (support !== "ok")
41104
+ return {
41105
+ type: "error",
41106
+ code: support === "old_hub" ? "unsupported" : "hub_unavailable",
41107
+ message: FOLLOW_COPY[support]
41108
+ };
41109
+ const build = (id2) => frame.type === "following" ? { v: 1, id: id2, type: "following", from_ref: ref } : {
41110
+ v: 1,
41111
+ id: id2,
41112
+ type: frame.type,
41113
+ from_ref: ref,
41114
+ artifact: frame.artifact
41115
+ };
41116
+ if (!ClientFrameSchema.safeParse(build("probe")).success)
41117
+ return {
41118
+ type: "error",
41119
+ code: "bad_frame",
41120
+ message: "the frame is not valid on the hub wire"
41121
+ };
41122
+ const id = ctx.pending.open(frame.id, reply);
41123
+ if (ctx.hub.send(build(id))) return void 0;
41124
+ ctx.pending.cancel(id);
41125
+ return {
41126
+ type: "error",
41127
+ code: "hub_unavailable",
41128
+ message: FOLLOW_COPY.down
41129
+ };
41130
+ }
40919
41131
  case "list":
40920
41132
  case "send":
40921
41133
  case "fetch": {
@@ -42816,6 +43028,7 @@ async function runDaemon(deps2 = {}) {
42816
43028
  let hubDroppedAt;
42817
43029
  let hubIds = false;
42818
43030
  let hubMailbox = false;
43031
+ let hubFollow = false;
42819
43032
  let hubHelloed = false;
42820
43033
  let hubVersion;
42821
43034
  const hub = new HubConnection({
@@ -42918,6 +43131,9 @@ async function runDaemon(deps2 = {}) {
42918
43131
  return;
42919
43132
  }
42920
43133
  case "roster":
43134
+ case "followed":
43135
+ case "unfollowed":
43136
+ case "follows":
42921
43137
  pending.settle(frame);
42922
43138
  return;
42923
43139
  case "body":
@@ -42927,6 +43143,7 @@ async function runDaemon(deps2 = {}) {
42927
43143
  hubVersion = frame.server_version;
42928
43144
  hubIds = frame.caps?.includes(BUS_CAPS.ids) ?? false;
42929
43145
  hubMailbox = frame.caps?.includes(BUS_CAPS.mailbox) ?? false;
43146
+ hubFollow = frame.caps?.includes(BUS_CAPS.follow) ?? false;
42930
43147
  hubHelloed = true;
42931
43148
  for (const rec of agents.all())
42932
43149
  if (rec.live && rec.replaces !== void 0) announceUp(rec);
@@ -42978,6 +43195,7 @@ async function runDaemon(deps2 = {}) {
42978
43195
  hubVersion = void 0;
42979
43196
  hubIds = false;
42980
43197
  hubMailbox = false;
43198
+ hubFollow = false;
42981
43199
  hubHelloed = false;
42982
43200
  statusRelay.dropped();
42983
43201
  receipts.release();
@@ -43107,7 +43325,14 @@ async function runDaemon(deps2 = {}) {
43107
43325
  };
43108
43326
  },
43109
43327
  onHello: (hello, closed) => {
43110
- const capsFor = (h) => (h.kind === "pi" || h.kind === "omp") && h.caps?.includes(ADAPTER_CAPS.rename) ? { caps: [ADAPTER_CAPS.rename] } : {};
43328
+ const capsFor = (h) => {
43329
+ const listed2 = [
43330
+ ...(h.kind === "pi" || h.kind === "omp") && h.caps?.includes(ADAPTER_CAPS.rename) ? [ADAPTER_CAPS.rename] : [],
43331
+ // #1317: whether the hub takes follows is answered per request.
43332
+ ...h.caps?.includes(ADAPTER_CAPS.follow) ? [ADAPTER_CAPS.follow] : []
43333
+ ];
43334
+ return listed2.length > 0 ? { caps: listed2 } : {};
43335
+ };
43111
43336
  if (hello.cwd === void 0 && hello.kind !== "codex")
43112
43337
  return { error: "cwd is required" };
43113
43338
  const attested = (pid) => {
@@ -43235,6 +43460,7 @@ async function runDaemon(deps2 = {}) {
43235
43460
  limited: (ref) => limited.has(ref) ? caps.get(ref) ?? "machine" : void 0,
43236
43461
  version: version2,
43237
43462
  configFiles,
43463
+ followSupport: () => !hub.open || !hubHelloed ? "down" : hubFollow ? "ok" : "old_hub",
43238
43464
  renamed: (ref, name) => {
43239
43465
  const rec = agents.byRef(ref);
43240
43466
  if (rec) renameFromAdapter(rec, name);
@@ -45727,7 +45953,7 @@ var noService = {
45727
45953
  remove: async () => ({}),
45728
45954
  cli: () => ["oa-bus"]
45729
45955
  };
45730
- var VERSION = true ? "0.138.0" : JSON.parse(
45956
+ var VERSION = true ? "0.140.0" : JSON.parse(
45731
45957
  readFileSync13(new URL("../package.json", import.meta.url), "utf8")
45732
45958
  ).version;
45733
45959
  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.138.0",
4
+ "version": "0.140.0",
5
5
  "description": "The Open Artifacts bus: your AI agents reach each other across machines.",
6
6
  "license": "MIT",
7
7
  "repository": {