UNPKG

@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.

62 lines • 3.2 kB
import { peerInfoToAgentCard } from "@essentialai/cogent"; import { getBackend, isCloudDeferred } from "../backend/index.js"; import { getConfig } from "../config.js"; import { successResult, errorResult } from "../errors.js"; import { logger } from "../logger.js"; export function registerListPeersTool(server) { server.registerTool("cogent_list_peers", { title: "List Peers", description: "List all currently registered Claude Code peers on the bridge. " + "Returns peer IDs, session IDs, working directories, labels, and flags peers " + "as potentially stale if idle beyond the configured timeout.", inputSchema: {}, annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false, }, }, async () => { try { // SECURITY: an unjoined cloud agent (deferred FileBackend placeholder) // must not surface the host-global local peer list — it belongs to no // channel. Return empty. See cogent_get_history / backend.isCloudDeferred. if (isCloudDeferred(getConfig().COGENT_ENDPOINT)) { return successResult({ peers: [], count: 0, notJoined: true, hint: "Not connected to a channel yet — call cogent_join_session (or cogent_register_peer) first. Local peers are withheld to prevent cross-channel disclosure.", }); } const backend = getBackend(); const peers = await backend.listPeers(); const staleTimeout = getConfig().COGENT_STALE_TIMEOUT_MS; const now = Date.now(); // The `...peer` spread surfaces every PeerInfo field returned by the // backend — including the optional `mode` ("observer" | "agent") added // in 3.2.0 (Phase 17 OBS-02). Operators can distinguish passive // watchers from agents at a glance. No explicit projection needed: // pre-3.2.0 backends omit the field (treated as "agent" by consumers). // A2A Agent Card per peer (card-only compliance): each peer's standard A2A // Agent Card, computed from its role/capabilities. In local mode there is no // relay URL, so the interface url uses a `local://` base to keep the shape uniform. const endpoint = getConfig().COGENT_ENDPOINT ?? "local://cogent"; const enriched = peers.map(peer => ({ ...peer, potentiallyStale: staleTimeout > 0 && (now - new Date(peer.lastSeenAt).getTime()) > staleTimeout, agentCard: peerInfoToAgentCard(peer, { endpoint, sessionId: peer.sessionId, clientVersion: peer.clientVersion, }), })); return successResult({ peers: enriched, count: enriched.length }); } catch (err) { logger.error("list-peers failed", { error: err }); return errorResult(err); } }); } //# sourceMappingURL=list-peers.js.map