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.

46 lines • 2.28 kB
import os from "node:os"; import path from "node:path"; /** * Base directory where Claude Code keeps its config + session transcripts. * * Honors `CLAUDE_CONFIG_DIR`, which — per the Claude Code docs (sessions.md) — * REPLACES `~/.claude` entirely; transcripts then live at * `<base>/projects/<escaped-cwd>/<sessionId>.jsonl`. Read at call time so a * relocated dir is picked up without a restart. `CLAUDE_CONFIG_DIR` holding * multiple dirs is undocumented, so we treat it as a single path (no list * parsing — YAGNI until Claude Code documents it). * * Without this, the wake resolver scans the default `~/.claude` while a user who * set `CLAUDE_CONFIG_DIR=/custom` has their sessions under `/custom/projects/…` * → zero candidates → "no candidate sessions found for cwd" → wake never fires. */ export function claudeConfigDir() { const override = process.env.CLAUDE_CONFIG_DIR?.trim(); return override ? override : path.join(os.homedir(), ".claude"); } /** * Base directory where Codex keeps its state + session rollouts. Honors * `CODEX_HOME` (which relocates `~/.codex`), falling back to `~/.codex`; rollouts * live under `<base>/sessions/**.jsonl`. Same rationale as {@link claudeConfigDir}. */ export function codexHomeDir() { const override = process.env.CODEX_HOME?.trim(); return override ? override : path.join(os.homedir(), ".codex"); } /** * Build the env for a resumed agent subprocess. * * The vendor's own session-context vars (keys starting with `vendorPrefix`, e.g. * "CLAUDE" / "CODEX") are stripped so the child does not believe it is nested * inside the parent session (nesting hangs the resume) — EXCEPT the keys listed in * `preserve` (the config-dir override, e.g. `CLAUDE_CONFIG_DIR` / `CODEX_HOME`, * which the child needs to LOCATE the session when the user relocated it). * `MCP_TRANSPORT` is always dropped. Pure + fully unit-tested; the callers layer * `COGENT_CHECK_ON_STOP=0` on top. */ export function buildResumeEnv(source, vendorPrefix, preserve) { const keep = new Set(preserve); return Object.fromEntries(Object.entries(source).filter(([key]) => (!key.startsWith(vendorPrefix) || keep.has(key)) && key !== "MCP_TRANSPORT")); } //# sourceMappingURL=agent-config.js.map