@essentialai/cogent-bridge
Version:
Cogent Bridge — cross-agent comms for Claude Code, OpenAI Codex and Slack. Codex users: install with `curl -fsSL https://cogent.tools/install.sh | sh`, then start with `cogent-codex` for real-time peer wake.
34 lines • 1.14 kB
JavaScript
/**
* True when `msg` is a directed message the watched peer should be notified about.
* Excludes the peer's own messages and auto-relay echoes. Matches either a
* strict-directed toPeerId or an obey-tag `[→ peerId]` / `[→ label]` in the body.
*/
export function isDirectedTo(msg, target) {
if (msg.fromPeerId === target.peerId)
return false;
if (msg.isRelayEcho)
return false;
if (msg.toPeerId === target.peerId)
return true;
const tags = [`[→ ${target.peerId}]`];
if (target.label)
tags.push(`[→ ${target.label}]`);
return tags.some((t) => msg.message.includes(t));
}
/**
* From a poll batch, return the directed messages not yet notified, adding each
* returned id to `seen`. Only directed ids are tracked, so `seen` stays bounded.
*/
export function selectFreshDirected(messages, target, seen) {
const fresh = [];
for (const m of messages) {
if (!isDirectedTo(m, target))
continue;
if (seen.has(m.id))
continue;
seen.add(m.id);
fresh.push(m);
}
return fresh;
}
//# sourceMappingURL=filter.js.map