@open-artifacts/bus 0.138.0 → 0.139.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.139.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,15 @@ 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
+ * Follows (#1317): the client may send `follow`, `unfollow` and `following`
31414
+ * and decodes `followed`, `unfollowed`, `follows` and the `follow_limit`
31415
+ * error. The hub answers those frames only on a socket whose hello listed
31416
+ * it (any other gets `bad_frame`, as an old hub would) and lists it in
31417
+ * `hello_ok.caps`; a client sends them only when it did.
31418
+ */
31419
+ follow: "follow"
31412
31420
  };
31413
31421
  MAX_CAPS = 16;
31414
31422
  CapTokenSchema = external_exports.string().regex(/^[a-z][a-z0-9_-]{0,31}$/);
@@ -32057,7 +32065,7 @@ function decode3(raw, schema, caps) {
32057
32065
  function decodeServerFrame(raw) {
32058
32066
  return decode3(raw, ServerFrameSchema, SERVER_CAPS);
32059
32067
  }
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;
32068
+ 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
32069
  var init_protocol2 = __esm({
32062
32070
  "../bus-protocol/src/protocol.ts"() {
32063
32071
  "use strict";
@@ -32193,6 +32201,45 @@ var init_protocol2 = __esm({
32193
32201
  /** A tool rename is `chosen`; a harness reverting to its fallback is `default`. Absent means `chosen`. */
32194
32202
  name_kind: NameKindSchema.optional()
32195
32203
  });
32204
+ FollowRefSchema = WellFormedText.pipe(external_exports.string().min(1).max(2048));
32205
+ Follow = external_exports.strictObject({
32206
+ ...base,
32207
+ type: external_exports.literal("follow"),
32208
+ from_ref: AgentRefSchema,
32209
+ artifact: FollowRefSchema
32210
+ });
32211
+ Unfollow = external_exports.strictObject({
32212
+ ...base,
32213
+ type: external_exports.literal("unfollow"),
32214
+ from_ref: AgentRefSchema,
32215
+ artifact: FollowRefSchema
32216
+ });
32217
+ Following = external_exports.strictObject({
32218
+ ...base,
32219
+ type: external_exports.literal("following"),
32220
+ from_ref: AgentRefSchema
32221
+ });
32222
+ MAX_FOLLOWS = 200;
32223
+ FollowEntry = external_exports.strictObject({
32224
+ artifact_id: external_exports.string().min(1).max(64),
32225
+ url: external_exports.string().min(1).max(2048),
32226
+ followed_at: IsoTimeSchema
32227
+ });
32228
+ Followed = external_exports.strictObject({
32229
+ ...base,
32230
+ type: external_exports.literal("followed"),
32231
+ ...FollowEntry.shape
32232
+ });
32233
+ Unfollowed = external_exports.strictObject({
32234
+ ...base,
32235
+ type: external_exports.literal("unfollowed"),
32236
+ removed: external_exports.boolean()
32237
+ });
32238
+ Follows = external_exports.strictObject({
32239
+ ...base,
32240
+ type: external_exports.literal("follows"),
32241
+ follows: external_exports.array(FollowEntry).max(MAX_FOLLOWS)
32242
+ });
32196
32243
  HelloOk = external_exports.strictObject({
32197
32244
  ...base,
32198
32245
  type: external_exports.literal("hello_ok"),
@@ -32277,7 +32324,9 @@ var init_protocol2 = __esm({
32277
32324
  "not_found",
32278
32325
  "too_large",
32279
32326
  "rate_limited",
32280
- "internal"
32327
+ "internal",
32328
+ /** Only to a socket whose hello listed `BUS_CAPS.follow` (#1317). */
32329
+ "follow_limit"
32281
32330
  ]),
32282
32331
  message: WellFormedText.pipe(external_exports.string().max(1024))
32283
32332
  });
@@ -32326,7 +32375,10 @@ var init_protocol2 = __esm({
32326
32375
  List,
32327
32376
  Fetch,
32328
32377
  Status,
32329
- Rename
32378
+ Rename,
32379
+ Follow,
32380
+ Unfollow,
32381
+ Following
32330
32382
  ]);
32331
32383
  ServerFrameSchema = external_exports.discriminatedUnion("type", [
32332
32384
  HelloOk,
@@ -32338,7 +32390,10 @@ var init_protocol2 = __esm({
32338
32390
  Deliver,
32339
32391
  ReceiptUpdate,
32340
32392
  RosterChanged,
32341
- Renamed
32393
+ Renamed,
32394
+ Followed,
32395
+ Unfollowed,
32396
+ Follows
32342
32397
  ]);
32343
32398
  FrameSchema = external_exports.discriminatedUnion("type", [
32344
32399
  Hello,
@@ -32352,6 +32407,9 @@ var init_protocol2 = __esm({
32352
32407
  Fetch,
32353
32408
  Status,
32354
32409
  Rename,
32410
+ Follow,
32411
+ Unfollow,
32412
+ Following,
32355
32413
  HelloOk,
32356
32414
  AgentOk,
32357
32415
  ReceiptFrame,
@@ -32361,7 +32419,10 @@ var init_protocol2 = __esm({
32361
32419
  Deliver,
32362
32420
  ReceiptUpdate,
32363
32421
  RosterChanged,
32364
- Renamed
32422
+ Renamed,
32423
+ Followed,
32424
+ Unfollowed,
32425
+ Follows
32365
32426
  ]);
32366
32427
  MAX_RAW_FRAME_CHARS = 2 * LIMITS.maxMessageBytes + 4096;
32367
32428
  SERVER_CAPS = { depth: 5, tokens: 65536, structural: 131072 };
@@ -32417,7 +32478,7 @@ var init_src = __esm({
32417
32478
  });
32418
32479
 
32419
32480
  // ../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;
32481
+ 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
32482
  var init_frames = __esm({
32422
32483
  "../bus-ipc/src/frames.ts"() {
32423
32484
  "use strict";
@@ -32434,7 +32495,7 @@ var init_frames = __esm({
32434
32495
  late = { late: external_exports.array(external_exports.string().min(1)).optional() };
32435
32496
  isWellFormed2 = (s) => s.isWellFormed();
32436
32497
  WELL_FORMED = { message: "text is not well-formed unicode" };
32437
- CLIENT_VERSION = true ? "0.138.0" : "0.0.0";
32498
+ CLIENT_VERSION = true ? "0.139.0" : "0.0.0";
32438
32499
  clientVersion = {
32439
32500
  client_version: external_exports.string().min(1).max(64).optional()
32440
32501
  };
@@ -32453,7 +32514,15 @@ var init_frames = __esm({
32453
32514
  * adapter that listed it, and an adapter sends the frame only to a daemon
32454
32515
  * whose welcome listed it, so neither side meets a frame its decoder lacks.
32455
32516
  */
32456
- rename: "rename"
32517
+ rename: "rename",
32518
+ /**
32519
+ * `follow` (#1317): the adapter may send `follow`, `unfollow` and
32520
+ * `following`. The daemon lists `follow` in `welcome.caps` only for an
32521
+ * adapter that listed it, and an adapter sends the frames only to a daemon
32522
+ * whose welcome listed it. The adapter tools are offered either way: a
32523
+ * daemon without it answers them with a plain "update" error instead.
32524
+ */
32525
+ follow: "follow"
32457
32526
  };
32458
32527
  Hello2 = external_exports.object({
32459
32528
  ...base2,
@@ -32557,6 +32626,23 @@ var init_frames = __esm({
32557
32626
  type: external_exports.literal("rename"),
32558
32627
  name: external_exports.string().min(1).max(64).refine(isWellFormed2, WELL_FORMED)
32559
32628
  });
32629
+ Follow2 = external_exports.object({
32630
+ ...base2,
32631
+ ...optIn,
32632
+ type: external_exports.literal("follow"),
32633
+ artifact: external_exports.string().min(1).max(2048).refine(isWellFormed2, WELL_FORMED)
32634
+ });
32635
+ Unfollow2 = external_exports.object({
32636
+ ...base2,
32637
+ ...optIn,
32638
+ type: external_exports.literal("unfollow"),
32639
+ artifact: external_exports.string().min(1).max(2048).refine(isWellFormed2, WELL_FORMED)
32640
+ });
32641
+ Following2 = external_exports.object({
32642
+ ...base2,
32643
+ ...optIn,
32644
+ type: external_exports.literal("following")
32645
+ });
32560
32646
  StatusRequest = external_exports.object({
32561
32647
  ...base2,
32562
32648
  ...clientVersion,
@@ -32573,7 +32659,10 @@ var init_frames = __esm({
32573
32659
  Fetch2,
32574
32660
  Ack2,
32575
32661
  SetStatus,
32576
- Rename2
32662
+ Rename2,
32663
+ Follow2,
32664
+ Unfollow2,
32665
+ Following2
32577
32666
  ]);
32578
32667
  ConfigFile = external_exports.object({
32579
32668
  file: external_exports.string(),
@@ -32612,7 +32701,7 @@ var init_frames = __esm({
32612
32701
  bus_name: external_exports.string(),
32613
32702
  namespace: external_exports.string(),
32614
32703
  global: external_exports.boolean(),
32615
- /** What this daemon accepts (ADAPTER_CAPS), only for an adapter that listed `rename`. */
32704
+ /** What this daemon accepts (ADAPTER_CAPS), only for an adapter that listed `rename` or `follow`. */
32616
32705
  caps: external_exports.array(external_exports.string().max(32)).max(16).optional()
32617
32706
  });
32618
32707
  Receipt = external_exports.object({
@@ -32649,6 +32738,29 @@ var init_frames = __esm({
32649
32738
  earlier: external_exports.object({ code: external_exports.string(), message: external_exports.string() }).optional(),
32650
32739
  ...late
32651
32740
  });
32741
+ FollowEntry2 = external_exports.object({
32742
+ artifact_id: external_exports.string(),
32743
+ url: external_exports.string(),
32744
+ followed_at: external_exports.string()
32745
+ });
32746
+ Followed2 = external_exports.object({
32747
+ ...base2,
32748
+ type: external_exports.literal("followed"),
32749
+ ...FollowEntry2.shape,
32750
+ ...late
32751
+ });
32752
+ Unfollowed2 = external_exports.object({
32753
+ ...base2,
32754
+ type: external_exports.literal("unfollowed"),
32755
+ removed: external_exports.boolean(),
32756
+ ...late
32757
+ });
32758
+ Follows2 = external_exports.object({
32759
+ ...base2,
32760
+ type: external_exports.literal("follows"),
32761
+ follows: external_exports.array(FollowEntry2),
32762
+ ...late
32763
+ });
32652
32764
  Body = external_exports.object({
32653
32765
  ...base2,
32654
32766
  type: external_exports.literal("body"),
@@ -32740,7 +32852,10 @@ var init_frames = __esm({
32740
32852
  Notice2,
32741
32853
  ErrorFrame2,
32742
32854
  StatusReply,
32743
- StatusSet
32855
+ StatusSet,
32856
+ Followed2,
32857
+ Unfollowed2,
32858
+ Follows2
32744
32859
  ]);
32745
32860
  }
32746
32861
  });
@@ -33141,7 +33256,7 @@ function selfText(agent) {
33141
33256
  };
33142
33257
  return JSON.stringify(shown4, null, 2);
33143
33258
  }
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;
33259
+ 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
33260
  var init_copy = __esm({
33146
33261
  "../bus-ipc/src/copy.ts"() {
33147
33262
  "use strict";
@@ -33243,6 +33358,10 @@ ${neutralizeBody(m.body)}`;
33243
33358
  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
33359
  statusSetText = (state, label) => `Your status is now ${state}${label ? `: "${label}"` : ""}. The user sees it as your own report.`;
33245
33360
  earlierStatusText = (message) => `Your previous status did not reach the user. ${message}`;
33361
+ followText = (url2) => `Following ${url2}. You get a notice here when it changes.`;
33362
+ unfollowText = (removed, artifact) => removed ? `Stopped following ${artifact}.` : `You were not following ${artifact}.`;
33363
+ followingText = (follows) => follows.length ? follows.map((f) => `${f.url} (since ${f.followed_at})`).join("\n") : "You are not following any artifacts.";
33364
+ FOLLOW_OLD_DAEMON = "This oa-bus daemon is too old to follow artifacts. Ask the user to update oa-bus.";
33246
33365
  STATUS_STALE_MS = 10 * 6e4;
33247
33366
  agoText = (ms) => {
33248
33367
  const mins = Math.round(ms / 6e4);
@@ -33593,6 +33712,8 @@ async function callTool(name, args, client, signal) {
33593
33712
  async function run(name, args, request) {
33594
33713
  try {
33595
33714
  if (name === "set_status") return await statusTool(args, request);
33715
+ if (name === "follow" || name === "unfollow" || name === "following")
33716
+ return await followTool(name, args, request);
33596
33717
  if (name === "list_agents") {
33597
33718
  const r = await request({ type: "list" });
33598
33719
  if (r.type !== "roster") return failed(r);
@@ -33684,6 +33805,18 @@ ${earlierStatusText(r.earlier.message)}` : done,
33684
33805
  return text(STATUS_COPY.bad_frame, true);
33685
33806
  return text(r.message, true);
33686
33807
  }
33808
+ async function followTool(name, args, request) {
33809
+ const artifact = typeof args.artifact === "string" ? args.artifact.trim() : "";
33810
+ if (name !== "following" && !artifact)
33811
+ return text("oa-bus: artifact is required (an id or a link)", true);
33812
+ const r = name === "following" ? await request({ type: "following" }) : await request({ type: name, artifact });
33813
+ if (r.type === "followed") return text(followText(r.url));
33814
+ if (r.type === "unfollowed") return text(unfollowText(r.removed, artifact));
33815
+ if (r.type === "follows") return text(followingText(r.follows));
33816
+ if (r.type === "error" && r.code === "bad_frame")
33817
+ return text(FOLLOW_OLD_DAEMON, true);
33818
+ return failed(r);
33819
+ }
33687
33820
  async function namespacesOf(name, request) {
33688
33821
  try {
33689
33822
  const r = await request({ type: "list" });
@@ -33787,6 +33920,31 @@ var init_tools = __esm({
33787
33920
  required: ["state"],
33788
33921
  additionalProperties: false
33789
33922
  }
33923
+ },
33924
+ {
33925
+ name: "follow",
33926
+ description: "Follow an Open Artifacts artifact, by id or link, to get a notice when it changes.",
33927
+ inputSchema: {
33928
+ type: "object",
33929
+ properties: { artifact: { type: "string" } },
33930
+ required: ["artifact"],
33931
+ additionalProperties: false
33932
+ }
33933
+ },
33934
+ {
33935
+ name: "unfollow",
33936
+ description: "Stop following an artifact, by id or link.",
33937
+ inputSchema: {
33938
+ type: "object",
33939
+ properties: { artifact: { type: "string" } },
33940
+ required: ["artifact"],
33941
+ additionalProperties: false
33942
+ }
33943
+ },
33944
+ {
33945
+ name: "following",
33946
+ description: "List the artifacts you follow.",
33947
+ inputSchema: none
33790
33948
  }
33791
33949
  ];
33792
33950
  text = (t, isError) => ({
@@ -33845,7 +34003,7 @@ function codexHello(call, pid, ppid) {
33845
34003
  pid,
33846
34004
  ...call.cwd ? { cwd: call.cwd } : {},
33847
34005
  proposed_name: "codex",
33848
- caps: [ADAPTER_CAPS.mailbox, ADAPTER_CAPS.pending],
34006
+ caps: [ADAPTER_CAPS.mailbox, ADAPTER_CAPS.pending, ADAPTER_CAPS.follow],
33849
34007
  codex: {
33850
34008
  thread_id: call.threadId,
33851
34009
  call_id: call.callId,
@@ -34088,7 +34246,7 @@ function sessionHello(session, pid, cwd) {
34088
34246
  pid,
34089
34247
  cwd,
34090
34248
  proposed_name: fitName(session.name, 64) || void 0,
34091
- caps: [ADAPTER_CAPS.mailbox, ADAPTER_CAPS.pending],
34249
+ caps: [ADAPTER_CAPS.mailbox, ADAPTER_CAPS.pending, ADAPTER_CAPS.follow],
34092
34250
  attest: {
34093
34251
  session_id: session.sessionId,
34094
34252
  socket_path: session.socketPath ?? void 0
@@ -37981,7 +38139,7 @@ async function handleToolCall(input2) {
37981
38139
  pid: process.pid,
37982
38140
  cwd: session.directory,
37983
38141
  proposed_name: nameOf(session.title),
37984
- caps: [ADAPTER_CAPS.mailbox, ADAPTER_CAPS.pending],
38142
+ caps: [ADAPTER_CAPS.mailbox, ADAPTER_CAPS.pending, ADAPTER_CAPS.follow],
37985
38143
  attest: { session_id: sessionId }
37986
38144
  });
37987
38145
  let client;
@@ -40323,7 +40481,7 @@ var HubConnection = class {
40323
40481
  // Reply ids: the hub then names each sender's agent (deliver.from_id).
40324
40482
  // Mailboxes: the hub then sends queued/since, away rows and the new
40325
40483
  // refusals, and honours agent_up.replaces (#1295).
40326
- caps: [BUS_CAPS.ids, BUS_CAPS.mailbox, BUS_CAPS.links]
40484
+ caps: [BUS_CAPS.ids, BUS_CAPS.mailbox, BUS_CAPS.links, BUS_CAPS.follow]
40327
40485
  });
40328
40486
  this.#guard("sessions", () => {
40329
40487
  this.send({
@@ -40818,6 +40976,10 @@ var Pending = class {
40818
40976
  };
40819
40977
  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
40978
  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.";
40979
+ var FOLLOW_COPY = {
40980
+ down: "The hub is not connected right now. Try again in a moment.",
40981
+ old_hub: "This Open Artifacts hub is too old to follow artifacts. Ask the user to update it."
40982
+ };
40821
40983
  var CAP_COPY = {
40822
40984
  machine: MACHINE_CAP_COPY,
40823
40985
  member: MEMBER_CAP_COPY
@@ -40916,6 +41078,47 @@ function routeLocal(frame, hello, reply, ctx) {
40916
41078
  (f) => reply({ ...f, v: 1, id: frame.id })
40917
41079
  );
40918
41080
  }
41081
+ case "follow":
41082
+ case "unfollow":
41083
+ case "following": {
41084
+ if (!hello.caps?.includes(ADAPTER_CAPS.follow))
41085
+ return {
41086
+ type: "error",
41087
+ code: "bad_frame",
41088
+ message: "follow is not supported on this connection"
41089
+ };
41090
+ const cap = ctx.limited?.(ref);
41091
+ if (cap)
41092
+ return { type: "error", code: "rate_limited", message: CAP_COPY[cap] };
41093
+ const support = ctx.followSupport?.() ?? "down";
41094
+ if (support !== "ok")
41095
+ return {
41096
+ type: "error",
41097
+ code: support === "old_hub" ? "unsupported" : "hub_unavailable",
41098
+ message: FOLLOW_COPY[support]
41099
+ };
41100
+ const build = (id2) => frame.type === "following" ? { v: 1, id: id2, type: "following", from_ref: ref } : {
41101
+ v: 1,
41102
+ id: id2,
41103
+ type: frame.type,
41104
+ from_ref: ref,
41105
+ artifact: frame.artifact
41106
+ };
41107
+ if (!ClientFrameSchema.safeParse(build("probe")).success)
41108
+ return {
41109
+ type: "error",
41110
+ code: "bad_frame",
41111
+ message: "the frame is not valid on the hub wire"
41112
+ };
41113
+ const id = ctx.pending.open(frame.id, reply);
41114
+ if (ctx.hub.send(build(id))) return void 0;
41115
+ ctx.pending.cancel(id);
41116
+ return {
41117
+ type: "error",
41118
+ code: "hub_unavailable",
41119
+ message: FOLLOW_COPY.down
41120
+ };
41121
+ }
40919
41122
  case "list":
40920
41123
  case "send":
40921
41124
  case "fetch": {
@@ -42816,6 +43019,7 @@ async function runDaemon(deps2 = {}) {
42816
43019
  let hubDroppedAt;
42817
43020
  let hubIds = false;
42818
43021
  let hubMailbox = false;
43022
+ let hubFollow = false;
42819
43023
  let hubHelloed = false;
42820
43024
  let hubVersion;
42821
43025
  const hub = new HubConnection({
@@ -42918,6 +43122,9 @@ async function runDaemon(deps2 = {}) {
42918
43122
  return;
42919
43123
  }
42920
43124
  case "roster":
43125
+ case "followed":
43126
+ case "unfollowed":
43127
+ case "follows":
42921
43128
  pending.settle(frame);
42922
43129
  return;
42923
43130
  case "body":
@@ -42927,6 +43134,7 @@ async function runDaemon(deps2 = {}) {
42927
43134
  hubVersion = frame.server_version;
42928
43135
  hubIds = frame.caps?.includes(BUS_CAPS.ids) ?? false;
42929
43136
  hubMailbox = frame.caps?.includes(BUS_CAPS.mailbox) ?? false;
43137
+ hubFollow = frame.caps?.includes(BUS_CAPS.follow) ?? false;
42930
43138
  hubHelloed = true;
42931
43139
  for (const rec of agents.all())
42932
43140
  if (rec.live && rec.replaces !== void 0) announceUp(rec);
@@ -42978,6 +43186,7 @@ async function runDaemon(deps2 = {}) {
42978
43186
  hubVersion = void 0;
42979
43187
  hubIds = false;
42980
43188
  hubMailbox = false;
43189
+ hubFollow = false;
42981
43190
  hubHelloed = false;
42982
43191
  statusRelay.dropped();
42983
43192
  receipts.release();
@@ -43107,7 +43316,14 @@ async function runDaemon(deps2 = {}) {
43107
43316
  };
43108
43317
  },
43109
43318
  onHello: (hello, closed) => {
43110
- const capsFor = (h) => (h.kind === "pi" || h.kind === "omp") && h.caps?.includes(ADAPTER_CAPS.rename) ? { caps: [ADAPTER_CAPS.rename] } : {};
43319
+ const capsFor = (h) => {
43320
+ const listed2 = [
43321
+ ...(h.kind === "pi" || h.kind === "omp") && h.caps?.includes(ADAPTER_CAPS.rename) ? [ADAPTER_CAPS.rename] : [],
43322
+ // #1317: whether the hub takes follows is answered per request.
43323
+ ...h.caps?.includes(ADAPTER_CAPS.follow) ? [ADAPTER_CAPS.follow] : []
43324
+ ];
43325
+ return listed2.length > 0 ? { caps: listed2 } : {};
43326
+ };
43111
43327
  if (hello.cwd === void 0 && hello.kind !== "codex")
43112
43328
  return { error: "cwd is required" };
43113
43329
  const attested = (pid) => {
@@ -43235,6 +43451,7 @@ async function runDaemon(deps2 = {}) {
43235
43451
  limited: (ref) => limited.has(ref) ? caps.get(ref) ?? "machine" : void 0,
43236
43452
  version: version2,
43237
43453
  configFiles,
43454
+ followSupport: () => !hub.open || !hubHelloed ? "down" : hubFollow ? "ok" : "old_hub",
43238
43455
  renamed: (ref, name) => {
43239
43456
  const rec = agents.byRef(ref);
43240
43457
  if (rec) renameFromAdapter(rec, name);
@@ -45727,7 +45944,7 @@ var noService = {
45727
45944
  remove: async () => ({}),
45728
45945
  cli: () => ["oa-bus"]
45729
45946
  };
45730
- var VERSION = true ? "0.138.0" : JSON.parse(
45947
+ var VERSION = true ? "0.139.0" : JSON.parse(
45731
45948
  readFileSync13(new URL("../package.json", import.meta.url), "utf8")
45732
45949
  ).version;
45733
45950
  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.139.0",
5
5
  "description": "The Open Artifacts bus: your AI agents reach each other across machines.",
6
6
  "license": "MIT",
7
7
  "repository": {