@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.
47 lines • 1.75 kB
JavaScript
import { execFile } from "node:child_process";
import { promisify } from "node:util";
const pexecFile = promisify(execFile);
const defaultRunner = async (cmd, args) => {
await pexecFile(cmd, args);
};
/** Strip characters that would break an AppleScript double-quoted string literal. */
function sanitize(s) {
return s.replace(/["\\]/g, "'").replace(/[\r\n]+/g, " ").slice(0, 200);
}
/**
* Build the platform-appropriate notifier command, or null on an unsupported OS
* (the caller then falls back to stdout). macOS uses `osascript`; Linux uses
* `notify-send`. Args are passed as an argv array (no shell), so only the
* AppleScript string literal needs sanitizing.
*/
export function notifierCommand(platform, title, body) {
if (platform === "darwin") {
const script = `display notification "${sanitize(body)}" with title "${sanitize(title)}"`;
return { cmd: "osascript", args: ["-e", script] };
}
if (platform === "linux") {
return { cmd: "notify-send", args: [title, body] };
}
return null;
}
/**
* Fire an OS notification. Never rejects: an unsupported platform or a failing
* command falls back to a stdout line (with a terminal bell), so the watch loop
* is never broken by a notifier problem.
*/
export async function notify(title, body, opts = {}) {
const platform = opts.platform ?? process.platform;
const runner = opts.runner ?? defaultRunner;
const cmd = notifierCommand(platform, title, body);
if (!cmd) {
process.stdout.write(`\x07🔔 ${title}: ${body}\n`);
return;
}
try {
await runner(cmd.cmd, cmd.args);
}
catch {
process.stdout.write(`\x07🔔 ${title}: ${body}\n`);
}
}
//# sourceMappingURL=notifier.js.map