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.

83 lines • 4.65 kB
import { CloudWsClient, MessageInbox } from "./cloud/index.js"; import { HttpClient } from "./cloud/http-client.js"; import { type PresenceOutcome } from "./services/peer-presence.js"; export { autoRelay } from "./services/auto-relay.js"; export declare let cloudWsClient: CloudWsClient | null; export declare let cloudInbox: MessageInbox | null; export declare let cloudHttpClient: HttpClient | null; /** * Is this process in cloud mode? Needed by index.ts to decide whether to * advertise `cogent://inbox` — which must happen even when the inbox does not * exist YET (deferred join), so it cannot be inferred from `cloudInbox`. */ export declare function isCloudMode(): boolean; /** Register the MCP host notifier; binds now and again after any inbox swap. */ export declare function setInboxNotifier(fn: () => void): void; /** * Re-register a peer after it was evicted by the server's stale cleanup. * Called by both HeartbeatService (on 404) and CloudWsClient (on WS upgrade 404). * Debounced: only one re-registration can run at a time. */ export declare function triggerReRegistration(): Promise<void>; /** * Evaluate this agent's PRESENCE on its channel and, when it is `offline` with a peer it * owns, bring it back `online`. See services/peer-presence.ts for the state vocabulary, * how an agent ends up offline, and why restoring it is safe. * * Fire-and-forget from index.ts AFTER the transport connects — it performs network I/O * and must never precede the `initialize` handshake (scripts/startup-nonblocking-test.mjs). */ /** * The exact positional argument tuple for a presence restore's registerPeer call. * * 🔴 EXTRACTED SO IT CAN BE TESTED. registerPeer's trailing parameters are OPTIONAL, and * per the TypeScript vault (concepts/Optional_Parameters -> sources/.../0281) omitting one * "will provide the function with an `undefined` value parameter" — silently. Measured: * deleting `peerSecret` from the call site left BOTH `tsc --noEmit` AND the presence unit * tests at exit 0, because those tests cover the module, not this wiring. A dropped * ownership proof means a peer owned by an earlier token can never be reclaimed, and the * agent stays offline. The type system cannot see it; this tuple + its test can. */ export declare function presenceRegisterArgs(p: { peerId: string; sessionId: string; cwd: string; label: string; peerSecret?: string; }): [string, string, string, string, string, "agent", undefined, undefined, string, string, string | undefined]; /** Stop a pending presence retry (shutdown, tests). */ export declare function cancelPresenceRetry(): void; export declare function restorePeerPresence(attempt?: number): Promise<PresenceOutcome>; /** Test seam: is a label still waiting to be resolved post-connect? */ export declare function hasPendingLabelResolve(): boolean; /** * Resolve a `COGENT_SESSION_ID` label to a session UUID, AFTER the transport is * connected, and upgrade the deferred backend if we also hold a matching token. * * Fire-and-forget by design (index.ts calls it with `void`), exactly like * runPreflights(): the server is already answering `initialize`, so a slow or * dead relay costs the user nothing. Never throws. * * When no matching persisted token exists we stay deferred and say so — the * user's first cogent_join_session / cogent_create_session completes the wiring. */ export declare function resolvePendingLabel(): Promise<void>; export declare function reinitCloudBackend(endpoint: string, sessionId: string, token: string): Promise<void>; export declare function runStartup(): Promise<void>; /** * Platform CLI flag + OS-sandbox preflight (audit gap 5). SPAWNS the vendor CLI * (`codex exec resume --help` / `claude --help`, each capped at 10s) and probes * the sandbox — so it MUST run AFTER `server.connect(transport)`, never before, * or a slow spawn on a cold host delays the MCP `initialize` response and the * client closes the connection ("connection closed: initialize response"). * * Everything here is warn-only diagnostics (verifies the binary resolves and its * --help documents every flag auto-relay emits — catching codex's historical * exit-2 on --color/--sandbox/--full-auto or a renamed claude flag) plus the * COGENT_CODEX_SANDBOX_FALLBACK recovery. All of it is consulted only later, at * wake/auto-relay time, so deferring it a few hundred ms past connect is safe. * Runs in BOTH cloud and local modes (auto-relay drives the agent CLI in cloud * mode too). Never throws. */ export declare function runPreflights(): Promise<void>; //# sourceMappingURL=startup.d.ts.map