import { notificationToDesktopText, type NotificationInput } from "./notify-protocol.ts"; import type { Runtime } from "./runtime.ts"; export const CMUX_SURFACE_ID_PATTERN = /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/iu; export function isInsideTmux(env: Readonly> = process.env): boolean { return Boolean(env.TMUX); } export function isInsideZellij(env: Readonly> = process.env): boolean { return Boolean(env.ZELLIJ); } export function wrapTmuxPassthrough(payload: string): string { return `\x1bPtmux;${payload.replaceAll("\x1b", "\x1b\x1b")}\x1b\\`; } export function sendCmuxNotification(input: NotificationInput, runtime: Runtime): boolean { const surface = runtime.env.CMUX_SURFACE_ID?.trim(); if (!surface || !CMUX_SURFACE_ID_PATTERN.test(surface)) return false; const { title, body } = notificationToDesktopText(input); try { return runtime.spawnDetached("cmux", ["notify", "--surface", surface, "--title", title, "--body", body]); } catch { return false; } }