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.

78 lines • 4.2 kB
import { z } from "zod"; import { successResult, errorResult, BridgeError, BridgeErrorCode } from "../errors.js"; import { readWakeLog } from "../services/wake-log.js"; import { listWakeInFlight } from "../services/wake-inflight.js"; /** * `cogent_wake_log` — answers "what has been woken in this directory, and what did it touch?" * * WHY (external bug report, 2026-09-03). Wakes run with --dangerously-skip-permissions in the * peer's real worktree and with --no-session-persistence, so nothing records the turn. A * reporter watched coherent code appear in a live repo for ~20 hours and had to parse session * JSONL, grep every transcript on the box, run lsof and a file watcher, and finally correlate * relay durationMs values against file mtimes to establish it was their own peer and not an * intruder. They nearly discarded the work. * * This tool is that investigation, as one call. */ export function registerWakeLogTool(server) { server.registerTool("cogent_wake_log", { title: "Wake Log", description: "Show the auto-resume (wake) sessions Cogent has run in this working directory: which peer's " + "message triggered each one, when, how long it took, the outcome, and WHICH FILES IT CHANGED. " + "Use this when files changed with no corresponding edit in your session, when you need to " + "establish who authored a change before committing it, or to check whether a wake is running now.", inputSchema: { limit: z .number() .int() .positive() .optional() .describe("Return only the most recent N wakes (default: all retained)."), peerId: z .string() .optional() .describe("Your local peer id. Required to list wakes running RIGHT NOW — in-flight markers are " + "keyed per peer, and two peers can share one directory."), cwd: z .string() .optional() .describe("Directory to inspect (default: this bridge's working directory)."), }, annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false, }, }, async ({ limit, peerId, cwd }) => { try { const target = cwd ?? process.cwd(); const wakes = readWakeLog(target, limit); // The headline number. `filesChanged: null` means "not a git worktree, could not // tell" and is deliberately NOT counted as a mutation — an unknown must never be // reported as a finding. const mutatingWakeCount = wakes.filter((w) => Array.isArray(w.filesChanged) && w.filesChanged.length > 0).length; // In-flight markers are per-peer by design (wake-inflight note 2), so without a // peerId there is nothing safe to read. Say so rather than returning a // reassuring empty list that reads as "nothing is running". const active = peerId ? listWakeInFlight(peerId, target) : []; return successResult({ cwd: target, count: wakes.length, mutatingWakeCount, wakes, active, ...(peerId ? {} : { activeHint: "Pass peerId to see wakes running right now (markers are per-peer)." }), note: "filesChanged is a git snapshot diff across each wake's window. If you were editing the " + "same tree at the same time, your edits appear here too — it is what changed while the " + "wake ran, not proof of authorship. null means the directory is not a git worktree.", }); } catch (err) { return errorResult(new BridgeError(BridgeErrorCode.STATE_CORRUPT, `Could not read the wake log: ${err instanceof Error ? err.message : String(err)}`, "The log lives at ~/.cogent/wake-log/<sha256(cwd)[..16]>.jsonl — check it is readable.")); } }); } //# sourceMappingURL=wake-log.js.map