@cotal-ai/workspace 0.133.11 → 0.133.13

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.
Files changed (49) hide show
  1. package/build/Release/darwin-arm64/build.json +1 -1
  2. package/build/Release/darwin-x64/build.json +1 -1
  3. package/build/Release/win32-arm64/build.json +1 -1
  4. package/build/Release/win32-x64/build.json +1 -1
  5. package/dist/control/actions.d.ts +141 -0
  6. package/dist/control/actions.d.ts.map +1 -0
  7. package/dist/control/actions.js +192 -0
  8. package/dist/control/actions.js.map +1 -0
  9. package/dist/control/dial-retry.d.ts +33 -0
  10. package/dist/control/dial-retry.d.ts.map +1 -0
  11. package/dist/control/dial-retry.js +70 -0
  12. package/dist/control/dial-retry.js.map +1 -0
  13. package/dist/control/index.d.ts +5 -0
  14. package/dist/control/index.d.ts.map +1 -0
  15. package/dist/control/index.js +5 -0
  16. package/dist/control/index.js.map +1 -0
  17. package/dist/control/manager.d.ts +291 -0
  18. package/dist/control/manager.d.ts.map +1 -0
  19. package/dist/control/manager.js +769 -0
  20. package/dist/control/manager.js.map +1 -0
  21. package/dist/control/seat.d.ts +168 -0
  22. package/dist/control/seat.d.ts.map +1 -0
  23. package/dist/control/seat.js +225 -0
  24. package/dist/control/seat.js.map +1 -0
  25. package/dist/launch.d.ts +94 -0
  26. package/dist/launch.d.ts.map +1 -0
  27. package/dist/launch.js +58 -0
  28. package/dist/launch.js.map +1 -0
  29. package/dist/maintenance.d.ts +7 -0
  30. package/dist/maintenance.d.ts.map +1 -1
  31. package/dist/maintenance.js +24 -0
  32. package/dist/maintenance.js.map +1 -1
  33. package/dist/output.d.ts +2 -0
  34. package/dist/output.d.ts.map +1 -1
  35. package/dist/output.js +5 -0
  36. package/dist/output.js.map +1 -1
  37. package/dist/view/index.d.ts +3 -0
  38. package/dist/view/index.d.ts.map +1 -0
  39. package/dist/view/index.js +3 -0
  40. package/dist/view/index.js.map +1 -0
  41. package/dist/view/mesh-view.d.ts +225 -0
  42. package/dist/view/mesh-view.d.ts.map +1 -0
  43. package/dist/view/mesh-view.js +550 -0
  44. package/dist/view/mesh-view.js.map +1 -0
  45. package/dist/view/observer.d.ts +26 -0
  46. package/dist/view/observer.d.ts.map +1 -0
  47. package/dist/view/observer.js +26 -0
  48. package/dist/view/observer.js.map +1 -0
  49. package/package.json +18 -4
@@ -0,0 +1,550 @@
1
+ // See docs/mesh-view.mdx.
2
+ import { EventEmitter } from "node:events";
3
+ import { deliveryOf, chatWildcard, isEventChannel, partsToText } from "@cotal-ai/core";
4
+ // ---- internals -------------------------------------------------------------
5
+ const STATUS_ORDER = { working: 0, waiting: 1, idle: 2, offline: 3 };
6
+ const BURST_MS = 400; // unicast burst-coalescing window
7
+ const TICK_MS = 75; // batch every source into one "change"
8
+ const CHANNELS_MS = 2000; // listChannels() refresh
9
+ const DEFAULT_WINDOW = 300;
10
+ const HISTORY_LIMIT = 50; // per-channel prefill depth
11
+ const DM_LOG_CAP = 1000; // raw DMs retained for the roll-up
12
+ const MEMBERSHIP_DEBOUNCE_MS = 150; // coalesce the watch's replay burst into one re-read (the web's 150 ms)
13
+ const BUCKET_MS = 4000; // activity series bucket width
14
+ const BUCKET_COUNT = 15; // activity series length → 15×4s = 60s window
15
+ function bodyText(msg) {
16
+ return partsToText(msg.parts);
17
+ }
18
+ /** The wire's reply link, mentions and context id, each present only when the message carries it. */
19
+ function threadFields(msg) {
20
+ return {
21
+ ...(msg.replyTo !== undefined ? { replyTo: msg.replyTo } : {}),
22
+ ...(msg.mentions?.length ? { mentions: [...msg.mentions] } : {}),
23
+ ...(msg.contextId !== undefined ? { contextId: msg.contextId } : {}),
24
+ };
25
+ }
26
+ /** Does this error say the membership feed's bucket does not exist (no delivery daemon ever
27
+ * provisioned it)? The JetStream "stream not found" answer, by API code and by message; anything
28
+ * else (a permission refusal, a timeout, a closed connection) is a failed read, not an absent feed. */
29
+ function feedAbsent(e) {
30
+ const err = e;
31
+ if (err?.api_error?.err_code === 10059)
32
+ return true;
33
+ if (err?.code === 404 || err?.code === "404")
34
+ return true;
35
+ return /stream not found/i.test(err?.message ?? "");
36
+ }
37
+ function sortRoster(r) {
38
+ // getRoster()/the "roster" event sort by name only — re-apply the status order here.
39
+ return [...r].sort((a, b) => (STATUS_ORDER[a.status] ?? 9) - (STATUS_ORDER[b.status] ?? 9) ||
40
+ a.card.name.localeCompare(b.card.name));
41
+ }
42
+ /**
43
+ * Events:
44
+ * - `"entry"` `(e: FeedEntry)` — one live feed row, as it lands (for the stream renderer).
45
+ * - `"presence"` `(ev: PresenceEvent)` — forwarded presence change (join/update/offline).
46
+ * - `"warning"` `(e: Error)` — a recoverable endpoint notice for the stream renderer.
47
+ * - `"change"` `(s: MeshSnapshot)` — a batched snapshot every ~75ms (for dashboards).
48
+ */
49
+ export class MeshView extends EventEmitter {
50
+ ep;
51
+ roster = [];
52
+ byId = new Map();
53
+ channelCounts = new Map();
54
+ arrivals = new Map();
55
+ feed = [];
56
+ seen = new Set(); // feed ids, for prefill ∪ live dedupe-by-id
57
+ pending = new Map();
58
+ dmLog = []; // raw unicast for the DM roll-up
59
+ recentTs = []; // tap arrivals in the last 1s → msgs/s
60
+ msgsPerSec = 0;
61
+ bucketCounts = new Array(BUCKET_COUNT).fill(0); // 60s volume series, oldest→newest
62
+ bucketEpoch = 0; // floor(now/BUCKET_MS) of the newest (last) bucket; 0 = uninitialized
63
+ /** The endpoint's full Cotal bind (`connection`) and its raw NATS socket edge (`transport`). A
64
+ * broker outage that nats.js rides out by reconnecting moves only the second, so the view is
65
+ * connected only while both hold. */
66
+ bound = false;
67
+ transport = false;
68
+ error;
69
+ presenceCurrent = true;
70
+ errorWhilePresenceStale = false;
71
+ warning;
72
+ dirty = true;
73
+ membership = {};
74
+ membershipWatch;
75
+ membershipTimer;
76
+ window;
77
+ tapSubject;
78
+ chatOnly;
79
+ timers = [];
80
+ onRoster = (r) => this.setRoster(r);
81
+ onPresence = (ev) => this.emit("presence", ev);
82
+ onError = (e) => {
83
+ this.error = e.message;
84
+ this.errorWhilePresenceStale = !this.presenceCurrent;
85
+ this.dirty = true;
86
+ };
87
+ /** A broker restart reconnects the transport without a new `connection`, and its errors (the
88
+ * presence stream missing until the space is provisioned again) arrive while the presence view
89
+ * is stale. When that view is current again the outage is over, so its error clears with it
90
+ * (AGENT-2889). An error raised while the view was current stays until the next connection. */
91
+ onPresenceView = (v) => {
92
+ const current = v.state === "current";
93
+ if (current && !this.presenceCurrent && this.errorWhilePresenceStale)
94
+ this.error = undefined;
95
+ this.presenceCurrent = current;
96
+ this.dirty = true;
97
+ };
98
+ /** A rebuilt connection clears the fault that dropped the old one, so the view reports itself
99
+ * connected again instead of keeping that error for good. */
100
+ onConnection = (s) => {
101
+ this.bound = s.connected;
102
+ if (s.connected)
103
+ this.error = undefined;
104
+ this.dirty = true;
105
+ };
106
+ onTransport = (s) => {
107
+ this.transport = s.connected;
108
+ this.dirty = true;
109
+ };
110
+ onWarning = (e) => {
111
+ this.warning = e.message;
112
+ this.dirty = true;
113
+ this.emit("warning", e);
114
+ };
115
+ constructor(ep, opts = {}) {
116
+ super();
117
+ this.ep = ep;
118
+ this.window = opts.window ?? DEFAULT_WINDOW;
119
+ this.tapSubject = opts.tapSubject;
120
+ // DMs are hidden only when the tap is narrowed to the chat subtree.
121
+ this.chatOnly = opts.tapSubject === chatWildcard(ep.space);
122
+ }
123
+ async start() {
124
+ // The error listener MUST be attached before start() — async faults surface as events.
125
+ this.ep.on("error", this.onError);
126
+ this.ep.on("warning", this.onWarning);
127
+ this.ep.on("connection", this.onConnection);
128
+ this.ep.on("transport", this.onTransport);
129
+ this.ep.on("roster", this.onRoster);
130
+ this.ep.on("presence", this.onPresence);
131
+ this.ep.on("presence-view", this.onPresenceView);
132
+ await this.ep.start();
133
+ this.bound = true;
134
+ this.setRoster(this.ep.getRoster());
135
+ this.ep.tap((subject, msg) => {
136
+ if (msg)
137
+ this.ingest(subject, msg);
138
+ }, this.tapSubject ? { subject: this.tapSubject } : undefined);
139
+ void this.prefill();
140
+ void this.refreshChannels();
141
+ void this.startMembership();
142
+ this.timers.push(setInterval(() => this.flush(), TICK_MS));
143
+ this.timers.push(setInterval(() => void this.refreshChannels(), CHANNELS_MS));
144
+ this.timers.push(setInterval(() => (this.dirty = true), 1000)); // refresh ages + decay rate
145
+ }
146
+ async stop() {
147
+ for (const t of this.timers)
148
+ clearInterval(t);
149
+ this.timers = [];
150
+ for (const b of this.pending.values())
151
+ clearTimeout(b.timer); // bursts hold live timers
152
+ this.pending.clear();
153
+ this.ep.off("error", this.onError);
154
+ this.ep.off("warning", this.onWarning);
155
+ this.ep.off("connection", this.onConnection);
156
+ this.ep.off("transport", this.onTransport);
157
+ this.ep.off("roster", this.onRoster);
158
+ this.ep.off("presence", this.onPresence);
159
+ this.ep.off("presence-view", this.onPresenceView);
160
+ clearTimeout(this.membershipTimer);
161
+ // The endpoint's stop deletes the watch's consumer over a live connection, and it is what settles
162
+ // the watch's own stop once the connection is closed for good, so it must not wait behind it.
163
+ const membership = this.membershipWatch?.stop().catch(() => undefined);
164
+ await this.ep.stop();
165
+ await membership;
166
+ }
167
+ /** Read the broker-authoritative membership feed and follow it. A membership fault is never
168
+ * a connection fault: it lands on `membership.unreadable` (with its reason), not on
169
+ * `status.error`, because the mesh is fine and only this viewer's read of one feed is not. */
170
+ async startMembership() {
171
+ await this.loadMembership();
172
+ try {
173
+ this.membershipWatch = await this.ep.watchMembership((change) => this.onMembershipChange(change), (e) => { this.membership = { ...this.membership, unreadable: `watch: ${e.message}` }; this.dirty = true; });
174
+ }
175
+ catch (e) {
176
+ // A feed that does not exist cannot be watched, and that is the traffic-only fact the read
177
+ // above already recorded; any other failure is this viewer's, named as such.
178
+ if (!feedAbsent(e))
179
+ this.membership = { ...this.membership, unreadable: `watch: ${e.message}` };
180
+ this.dirty = true;
181
+ }
182
+ }
183
+ /** A heartbeat moves only `asOf`, so it is copied into the last snapshot instead of costing a
184
+ * bucket re-read (#4904); a member change is read back in full, and a heartbeat that arrives
185
+ * while the last read failed is the retry. */
186
+ onMembershipChange(change) {
187
+ if (change.type === "replayed")
188
+ return;
189
+ if (change.type === "heartbeat" && change.update && this.membership.snapshot && this.membership.unreadable === undefined) {
190
+ this.membership = { snapshot: { ...this.membership.snapshot, asOf: change.asOf } };
191
+ this.dirty = true;
192
+ return;
193
+ }
194
+ this.scheduleMembership();
195
+ }
196
+ scheduleMembership() {
197
+ clearTimeout(this.membershipTimer);
198
+ this.membershipTimer = setTimeout(() => void this.loadMembership(), MEMBERSHIP_DEBOUNCE_MS);
199
+ }
200
+ /** One read of the feed. Three outcomes, kept distinct: a snapshot (readable, whatever it holds),
201
+ * an absent feed (readable in the sense that the mesh has no daemon writing one: an empty
202
+ * snapshot, traffic-only), and a failed read (`unreadable`, reason kept, last snapshot kept so
203
+ * the reason is shown against what was last known rather than against nothing). */
204
+ async loadMembership() {
205
+ try {
206
+ this.membership = { snapshot: await this.ep.readMembership() };
207
+ }
208
+ catch (e) {
209
+ this.membership = feedAbsent(e)
210
+ ? { snapshot: { asOf: undefined, members: [] } }
211
+ : { ...this.membership, unreadable: e.message };
212
+ }
213
+ this.dirty = true;
214
+ }
215
+ snapshot() {
216
+ const channels = [...this.channelCounts]
217
+ .map(([channel, messages]) => ({ channel, messages, arrivals: this.arrivals.get(channel) ?? 0 }))
218
+ .sort((a, b) => a.channel.localeCompare(b.channel));
219
+ return {
220
+ agents: this.roster.filter((p) => p.card.kind === "agent"),
221
+ endpoints: this.roster.filter((p) => p.card.kind !== "agent"),
222
+ channels,
223
+ feed: this.feed.slice(),
224
+ membership: { ...this.membership },
225
+ rates: { msgsPerSec: this.msgsPerSec, activity: this.bucketCounts.slice() },
226
+ status: {
227
+ connected: this.bound && this.transport,
228
+ space: this.ep.space,
229
+ dmVisible: !this.chatOnly,
230
+ error: this.error,
231
+ warning: this.warning,
232
+ },
233
+ signals: this.signals(),
234
+ nameOf: this.nameOf,
235
+ };
236
+ }
237
+ // Stable identity across snapshots; reads the live byId map.
238
+ nameOf = (id) => this.byId.get(id) ?? id.slice(0, 8);
239
+ // ---- sources -------------------------------------------------------------
240
+ setRoster(r) {
241
+ this.roster = sortRoster(r);
242
+ for (const p of r)
243
+ this.byId.set(p.card.id, p.card.name);
244
+ this.dirty = true;
245
+ }
246
+ /** Live read-only tap. Drops control/presence/trace frames (deliveryOf → null). A payload
247
+ * from.name is sender-chosen display text, not identity (#1399): the roster is the only writer
248
+ * of id→name, so a spoofed name can never re-key a thread or a label. */
249
+ ingest(subject, msg) {
250
+ const kind = deliveryOf(subject);
251
+ if (!kind)
252
+ return;
253
+ const now = Date.now();
254
+ this.recentTs.push(now);
255
+ this.roll(now);
256
+ this.bucketCounts[BUCKET_COUNT - 1]++;
257
+ if (kind === "unicast")
258
+ return this.coalesce(msg);
259
+ this.push({
260
+ id: msg.id,
261
+ ts: msg.ts,
262
+ from: msg.from,
263
+ delivery: kind === "anycast" ? "anycast" : "multicast", // "chat" → multicast
264
+ channel: kind === "anycast" ? undefined : msg.channel,
265
+ toService: kind === "anycast" ? msg.toService : undefined,
266
+ // MARKED, NEVER DROPPED. The channel-list filter below keeps event channels out of the tab
267
+ // strip and out of the history prefill, for a cost reason; the live feed is a different
268
+ // question and the answer here is different on purpose. Dropping an event row would delete
269
+ // the only traffic this release just taught the console to draw, and it would delete it
270
+ // silently, which is the failure mode this whole lane exists to remove. A surface that wants
271
+ // a chat-only feed can filter on this flag and say so in its own UI.
272
+ events: kind === "anycast" ? undefined : isEventChannel(msg.channel) || undefined,
273
+ ...threadFields(msg),
274
+ text: bodyText(msg),
275
+ });
276
+ }
277
+ /** Group a unicast burst with one sender, text and thread fields into one feed entry over
278
+ * BURST_MS, and retain each raw message for the DM roll-up. */
279
+ coalesce(msg) {
280
+ const body = bodyText(msg);
281
+ const thread = threadFields(msg);
282
+ if (msg.to)
283
+ this.recordDm({ ts: msg.ts, from: msg.from, toId: msg.to, text: body });
284
+ const key = JSON.stringify([msg.from.id, body, thread]);
285
+ let b = this.pending.get(key);
286
+ if (!b) {
287
+ b = {
288
+ from: msg.from,
289
+ body,
290
+ thread,
291
+ id: msg.id,
292
+ ts: msg.ts,
293
+ ids: [],
294
+ timer: setTimeout(() => this.flushBurst(key), BURST_MS),
295
+ };
296
+ this.pending.set(key, b);
297
+ }
298
+ b.ts = Math.min(b.ts, msg.ts); // earliest in the burst → deterministic order
299
+ if (msg.to)
300
+ b.ids.push(msg.to);
301
+ }
302
+ flushBurst(key) {
303
+ const b = this.pending.get(key);
304
+ if (!b)
305
+ return;
306
+ this.pending.delete(key);
307
+ this.push({
308
+ id: b.id,
309
+ ts: b.ts,
310
+ from: b.from,
311
+ delivery: "unicast",
312
+ toIds: [...b.ids],
313
+ toNames: b.ids.map((id) => this.nameOf(id)),
314
+ count: b.ids.length,
315
+ ...b.thread,
316
+ text: b.body,
317
+ });
318
+ }
319
+ /** Append to the feed, dedupe by id, keep it windowed, and notify stream consumers. */
320
+ push(e) {
321
+ if (this.seen.has(e.id))
322
+ return;
323
+ this.seen.add(e.id);
324
+ this.feed.push(e);
325
+ this.trim();
326
+ // Surface a brand-new channel as a tab now, not at the next poll. The third filter site, and it
327
+ // is not redundant: this one runs on live arrival, so without it an event channel would appear
328
+ // as a tab the moment a frame landed and then vanish at the next `refreshChannels`, which reads
329
+ // as a flickering bug rather than as a filter.
330
+ if (e.delivery === "multicast" && e.channel && !e.events) {
331
+ if (!this.channelCounts.has(e.channel))
332
+ this.channelCounts.set(e.channel, 1);
333
+ // Counted on ARRIVAL, not read back from the broker: the retained count is capped per sender
334
+ // and stops climbing under live traffic, so a badge derived from it goes quiet at the cap.
335
+ this.arrivals.set(e.channel, (this.arrivals.get(e.channel) ?? 0) + 1);
336
+ }
337
+ this.dirty = true;
338
+ this.emit("entry", e);
339
+ }
340
+ trim() {
341
+ if (this.feed.length <= this.window)
342
+ return;
343
+ for (const d of this.feed.splice(0, this.feed.length - this.window))
344
+ this.seen.delete(d.id);
345
+ }
346
+ recordDm(d) {
347
+ this.dmLog.push(d);
348
+ if (this.dmLog.length > DM_LOG_CAP)
349
+ this.dmLog.splice(0, this.dmLog.length - DM_LOG_CAP);
350
+ }
351
+ /** One-shot backlog: prefill each channel's history (multicast), plus the DM backlog when DMs
352
+ * are visible (god-view — `dmHistory` needs an admin cred), deduped by id, oldest-first. */
353
+ async prefill() {
354
+ let chans;
355
+ try {
356
+ chans = await this.ep.listChannels();
357
+ }
358
+ catch {
359
+ return;
360
+ }
361
+ // THE FILTER RUNS BEFORE THE HISTORY READ, AND THE ORDER IS THE WHOLE POINT.
362
+ //
363
+ // `listChannels()` derives an entry from every RETAINED CONCRETE SUBJECT, and the chat stream
364
+ // caps per subject rather than by age or count, so a session's last frames are retained
365
+ // indefinitely and this list grows by one row per agent that has ever run. Filtering after the
366
+ // fetch would enumerate every one of them, issue a `channelHistory` round trip each, and then
367
+ // throw the results away: unbounded work to display nothing. That is a performance defect
368
+ // rather than a cosmetic one, which is why it is filtered here and not in the loop below.
369
+ const chat = chans.filter((c) => !isEventChannel(c.channel));
370
+ const batches = await Promise.all(chat.map((c) => this.ep.channelHistory(c.channel, { limit: HISTORY_LIMIT }).catch(() => [])));
371
+ const history = [];
372
+ for (const msgs of batches)
373
+ for (const msg of msgs) {
374
+ if (!msg.channel || this.seen.has(msg.id))
375
+ continue;
376
+ this.seen.add(msg.id);
377
+ history.push({
378
+ id: msg.id,
379
+ ts: msg.ts,
380
+ from: msg.from,
381
+ delivery: "multicast",
382
+ channel: msg.channel,
383
+ ...threadFields(msg),
384
+ text: bodyText(msg),
385
+ });
386
+ }
387
+ if (history.length) {
388
+ this.feed = [...history, ...this.feed].sort((a, b) => a.ts - b.ts);
389
+ this.trim();
390
+ this.dirty = true;
391
+ }
392
+ if (!this.chatOnly)
393
+ await this.prefillDms();
394
+ }
395
+ /** Best-effort DM backlog for the roll-up — only meaningful for a god-view cred; a non-admin
396
+ * observer's `dmHistory` throws (ACL), which just leaves the DM lens live-only. A history
397
+ * row's from.name is payload text, never an id→name source (#1399). */
398
+ async prefillDms() {
399
+ let msgs;
400
+ try {
401
+ msgs = await this.ep.dmHistory({ limit: DM_LOG_CAP });
402
+ }
403
+ catch {
404
+ return;
405
+ }
406
+ // Merge backlog into the live dmLog, deduped by sender+recipient+ts (a live tap may already
407
+ // have collected backlog-adjacent messages), then keep it ordered and capped.
408
+ const key = (d) => d.from.id + ">" + d.toId + "@" + d.ts;
409
+ const have = new Set(this.dmLog.map(key));
410
+ for (const m of msgs) {
411
+ if (!m.to)
412
+ continue;
413
+ const d = { ts: m.ts, from: m.from, toId: m.to, text: bodyText(m) };
414
+ if (have.has(key(d)))
415
+ continue;
416
+ have.add(key(d));
417
+ this.dmLog.push(d);
418
+ }
419
+ this.dmLog.sort((a, b) => a.ts - b.ts);
420
+ if (this.dmLog.length > DM_LOG_CAP)
421
+ this.dmLog.splice(0, this.dmLog.length - DM_LOG_CAP);
422
+ this.dirty = true;
423
+ }
424
+ async refreshChannels() {
425
+ let chans;
426
+ try {
427
+ chans = await this.ep.listChannels();
428
+ }
429
+ catch {
430
+ return;
431
+ }
432
+ // Event channels are not chat tabs: one per agent that has ever run would bury the handful of
433
+ // channels a human actually talks on. Same classifier as the prefill, so the tab strip and the
434
+ // backlog cannot disagree about what a channel is. The map is REBUILT, not merged: a channel
435
+ // the broker no longer lists (deleted, its history purged and its registry entry gone) leaves
436
+ // the strip on this poll instead of lingering with its last count.
437
+ const next = new Map();
438
+ for (const { channel, messages } of chans)
439
+ if (!isEventChannel(channel))
440
+ next.set(channel, messages);
441
+ this.channelCounts = next;
442
+ for (const channel of this.arrivals.keys())
443
+ if (!next.has(channel))
444
+ this.arrivals.delete(channel);
445
+ this.dirty = true;
446
+ }
447
+ // ---- derived signals -----------------------------------------------------
448
+ signals() {
449
+ const agents = this.roster.filter((p) => p.card.kind === "agent");
450
+ const counts = { working: 0, waiting: 0, idle: 0, offline: 0 };
451
+ for (const p of agents)
452
+ if (p.status in counts)
453
+ counts[p.status]++;
454
+ // Name-ordered, deliberately not by `ts`: that is the last heartbeat, so sorting by it and
455
+ // presenting the result as a priority queue would imply an age we cannot compute.
456
+ const waiting = agents
457
+ .filter((p) => p.status === "waiting")
458
+ .sort((a, b) => a.card.name.localeCompare(b.card.name) || a.card.id.localeCompare(b.card.id));
459
+ const live = agents.filter((p) => p.status !== "offline");
460
+ return {
461
+ counts,
462
+ waiting,
463
+ stalestLiveTs: live.length ? Math.min(...live.map((p) => p.ts)) : undefined,
464
+ dms: this.rollupDms(),
465
+ };
466
+ }
467
+ /** Group raw DMs into per-peer rows; each peer lists its counterparties (conversations).
468
+ * Only pairs that actually talked — never the n² cross-product. Conversations key on the two
469
+ * AUTHENTICATED ids; display names, roles and statuses resolve through the roster by id, so a
470
+ * payload `from.name` cannot move a line into another peer's thread (#1399). */
471
+ rollupDms() {
472
+ const statusOf = (id) => this.roster.find((p) => p.card.id === id)?.status ?? "offline";
473
+ const roleOf = (id) => this.roster.find((p) => p.card.id === id)?.card.role;
474
+ const conv = new Map();
475
+ for (const d of this.dmLog) {
476
+ const a = d.from.id;
477
+ const b = d.toId;
478
+ if (!a || !b || a === b)
479
+ continue;
480
+ const parts = [a, b].sort();
481
+ const k = parts.join("\u0000");
482
+ let c = conv.get(k);
483
+ if (!c)
484
+ conv.set(k, (c = { parts, msgs: [], last: 0 }));
485
+ c.msgs.push({ ts: d.ts, from: this.nameOf(a), to: this.nameOf(b), text: d.text });
486
+ c.last = Math.max(c.last, d.ts);
487
+ }
488
+ const peers = new Map();
489
+ for (const c of conv.values()) {
490
+ c.msgs.sort((x, y) => x.ts - y.ts);
491
+ for (const id of c.parts) {
492
+ const other = c.parts[0] === id ? c.parts[1] : c.parts[0];
493
+ const name = this.nameOf(id);
494
+ let pe = peers.get(id);
495
+ if (!pe)
496
+ peers.set(id, (pe = { name, role: roleOf(id), status: statusOf(id), lastTs: 0, conversations: [] }));
497
+ pe.conversations.push({
498
+ with: this.nameOf(other),
499
+ role: roleOf(other),
500
+ status: statusOf(other),
501
+ lastTs: c.last,
502
+ messages: c.msgs,
503
+ });
504
+ pe.lastTs = Math.max(pe.lastTs, c.last);
505
+ }
506
+ }
507
+ for (const pe of peers.values())
508
+ pe.conversations.sort((a, b) => b.lastTs - a.lastTs);
509
+ return [...peers.values()].sort((a, b) => b.lastTs - a.lastTs);
510
+ }
511
+ /** Advance the activity ring to `now`: shift past buckets out the left, fill the gap with zeros,
512
+ * so idle time decays the series. The newest (last) bucket is always the current ~4s window. */
513
+ roll(now) {
514
+ const epoch = Math.floor(now / BUCKET_MS);
515
+ if (this.bucketEpoch === 0) {
516
+ this.bucketEpoch = epoch;
517
+ return;
518
+ }
519
+ const advance = epoch - this.bucketEpoch;
520
+ if (advance <= 0)
521
+ return;
522
+ if (advance >= BUCKET_COUNT) {
523
+ this.bucketCounts.fill(0);
524
+ }
525
+ else {
526
+ this.bucketCounts.splice(0, advance);
527
+ while (this.bucketCounts.length < BUCKET_COUNT)
528
+ this.bucketCounts.push(0);
529
+ }
530
+ this.bucketEpoch = epoch;
531
+ this.dirty = true;
532
+ }
533
+ /** The single batch point: recompute the rolling rate, then emit one snapshot if dirty. */
534
+ flush() {
535
+ const now = Date.now();
536
+ const cutoff = now - 1000;
537
+ while (this.recentTs.length && this.recentTs[0] < cutoff)
538
+ this.recentTs.shift();
539
+ this.roll(now); // decay the activity window even when no message arrived
540
+ if (this.recentTs.length !== this.msgsPerSec) {
541
+ this.msgsPerSec = this.recentTs.length;
542
+ this.dirty = true;
543
+ }
544
+ if (!this.dirty)
545
+ return;
546
+ this.dirty = false;
547
+ this.emit("change", this.snapshot());
548
+ }
549
+ }
550
+ //# sourceMappingURL=mesh-view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mesh-view.js","sourceRoot":"","sources":["../../src/view/mesh-view.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAE1B,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,MA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AAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC5B,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;YACrC,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,YAAY;gBAAE,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC5E,CAAC;QACD,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,2FAA2F;IACnF,KAAK;QACX,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC;QAC1B,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM;YAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QAChF,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,yDAAyD;QACzE,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,IAAI,CAAC,UAAU,EAAE,CAAC;YAC7C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;YACvC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QACpB,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,KAAK;YAAE,OAAO;QACxB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;IACvC,CAAC;CACF"}
@@ -0,0 +1,26 @@
1
+ import { CotalEndpoint } from "@cotal-ai/core";
2
+ import type { UserViewAuth } from "../connect.js";
3
+ /** How an observer authenticates: a static or open creds file, or the user-mode admin-view
4
+ * material (a bearer source, so a standing tap outlives one bearer's life, plus the pinned
5
+ * principal a source-mode endpoint requires). Never both. */
6
+ export interface ObserverAuth {
7
+ creds?: string;
8
+ user?: Pick<UserViewAuth, "source" | "sentinelCreds" | "owner" | "actor">;
9
+ }
10
+ export interface ObserverOptions {
11
+ space: string;
12
+ server: string;
13
+ /** The card name, which is also the `from` of anything the observer sends. */
14
+ name: string;
15
+ auth?: ObserverAuth;
16
+ /** Sign as the operator: role "operator" on the card, and a synthesized incarnation uid so the
17
+ * observer can invoke endpoint services such as the manager's `ps` and `stop`. On an open mesh
18
+ * the broker enforces nothing; on an authed mesh a read-only credential gets a clean publish
19
+ * denial. */
20
+ operator?: boolean;
21
+ }
22
+ /** A read-only endpoint over one space, invisible to peers: it registers no presence, binds no
23
+ * durables, and reads through tap, history and presence watch. It is returned unstarted; the
24
+ * caller's `MeshView` or lifecycle owns `start` and `stop`. */
25
+ export declare function openObserver({ space, server, name, auth, operator }: ObserverOptions): CotalEndpoint;
26
+ //# sourceMappingURL=observer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observer.d.ts","sourceRoot":"","sources":["../../src/view/observer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAoB,MAAM,gBAAgB,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD;;8DAE8D;AAC9D,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,GAAG,eAAe,GAAG,OAAO,GAAG,OAAO,CAAC,CAAC;CAC3E;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,8EAA8E;IAC9E,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB;;;kBAGc;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;gEAEgE;AAChE,wBAAgB,YAAY,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,IAAS,EAAE,QAAgB,EAAE,EAAE,eAAe,GAAG,aAAa,CAoBjH"}
@@ -0,0 +1,26 @@
1
+ import { CotalEndpoint, mintLifecycleUid } from "@cotal-ai/core";
2
+ /** A read-only endpoint over one space, invisible to peers: it registers no presence, binds no
3
+ * durables, and reads through tap, history and presence watch. It is returned unstarted; the
4
+ * caller's `MeshView` or lifecycle owns `start` and `stop`. */
5
+ export function openObserver({ space, server, name, auth = {}, operator = false }) {
6
+ const role = operator ? { role: "operator" } : {};
7
+ const ep = new CotalEndpoint({
8
+ space,
9
+ servers: server,
10
+ ...(operator ? { lifecycleUid: mintLifecycleUid() } : {}),
11
+ ...(auth.user
12
+ ? {
13
+ bearer: auth.user.source,
14
+ sentinelCreds: auth.user.sentinelCreds,
15
+ card: { owner: auth.user.owner, actor: auth.user.actor, name, ...role, kind: "endpoint" },
16
+ }
17
+ : { creds: auth.creds, card: { name, ...role, kind: "endpoint" } }),
18
+ channels: [],
19
+ consume: false,
20
+ registerPresence: false,
21
+ watchPresence: true,
22
+ });
23
+ ep.on("error", () => { });
24
+ return ep;
25
+ }
26
+ //# sourceMappingURL=observer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observer.js","sourceRoot":"","sources":["../../src/view/observer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAwBjE;;gEAEgE;AAChE,MAAM,UAAU,YAAY,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,EAAE,EAAE,QAAQ,GAAG,KAAK,EAAmB;IAChG,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAClD,MAAM,EAAE,GAAG,IAAI,aAAa,CAAC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