Files
skills/orchestrator/templates/receipts.js
T
Kevin Veen-BirkenbachandClaude Opus 5.5 30b2a32095 feat(orchestrator): radio receipts inline (005 phase B)
Requirement 005: every radio message in the Stream and the radio log shows the avatars of the agents that read it, with read time and an ack badge where a receipt exists; receipt rows no longer appear as entries of their own, and the sender shows once. Read times come from seen marks, stamped only after a fresh presence pass no older than two sighting intervals; a stored time before its row is refused. An operator message links to its relay row through the ts radio.py prints first on stdout right after store(), checked against an exact row (sender Operator, relay text, targets, no to_sessions); a ts shared by two rows shows no readers. radio.py clips printed addresses; the hub keeps the first stdout line whole. Accepted MEDUSA false positives: MM-SCAN-058 at server.py:73, JB-SCAN-641 and JB-SCAN-616 at radio.py:389 (clip, the output sanitizer), FLA-SCAN-055 at radio.py:109. Committed below the 90/5 bar on the operator's word; the receipts e2e runs through the queue.

🎯 Fix: 89 %
💥 Break: 6 %
💸 Cost: –
⏱️ Time: –
🛡️ Security: 100 %
🏆 Score: 84
🚦 Gate: ⛔ fix 89 % < 90, break 6 % > 5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 17:19:39 +00:00

51 lines
2.2 KiB
JavaScript

const Receipts = (() => {
"use strict";
const SHOWN = 8;
/**
* @param {object} row a radio row of the state or the ref of a radio entry of the Stream, with readers and acks.
* @returns {object} shown and hidden: every reader with acked true where its receipt exists, the first SHOWN as avatars and the rest behind "+N".
*/
function strip(row) {
const acks = new Set(Array.isArray(row.acks) ? row.acks : []);
const readers = (Array.isArray(row.readers) ? row.readers : []).map((reader) => ({...reader, acked: acks.has(reader.session)}));
return {shown: readers.slice(0, SHOWN), hidden: readers.slice(SHOWN)};
}
/**
* @param {object} reader an entry of strip().
* @param {function(number): string} format renders a read time.
* @returns {string} the reader's name, its read time where the hub knows one, prefixed "about" where only a sighting gives it, and whether it acknowledged.
*/
function label(reader, format) {
const known = reader.read !== null && reader.read !== undefined;
const read = known ? `read ${reader.approximate ? "about " : ""}${format(reader.read)}` : "read";
return [reader.name, read, reader.acked ? "acknowledged" : ""].filter(Boolean).join(" · ");
}
/**
* @param {object} entry a Stream entry.
* @returns {string} its headline; a radio entry whose sender the route already shows names only the recipients.
*/
function headline(entry) {
if (entry.kind !== "radio" || !entry.agent) {
return entry.title;
}
return `→ ${entry.ref.to.length ? entry.ref.to.join(", ") : "all"}`;
}
/**
* @param {Array<object>} rows radio rows of the state.
* @returns {string} changes whenever a reader, its read time or an ack of any row does, so a log that redraws only on change shows them on the next poll.
*/
function signature(rows) {
const read = (reader) => `${reader.session}@${reader.read ?? ""}${reader.approximate ? "~" : ""}`;
return rows.map((row) => `${(row.readers || []).map(read).join(",")}/${(row.acks || []).join(",")}`).join("|");
}
return {SHOWN, strip, label, headline, signature};
})();
if (typeof module === "object" && module.exports) {
module.exports = Receipts;
}