/** * @file openInChanges.ts — asks the Workspace page to open a file in its * Changes panel: a chat's "Edited N files" card names absolute paths deep in * a pane, the panel lives on the page, so the request travels as a window * event (like the sidebar's `LIVE_RUNS_EVENT`). The page opens the panel and * that file there, if the panel shows the same workspace; else nothing. * @author Nguyễn Ngọc Trí Vĩ */ export const OPEN_IN_CHANGES_EVENT = "agenthub:open-in-changes"; /** A file to open: its workspace, and its path relative to the panel's folder. */ export type OpenInChanges = { laneId: number; path: string }; /** Opens `path` (absolute) when it lies under `cwd`, the pane's folder — the * folder the Changes panel reads for it. False when it does not. */ export function openInChanges(laneId: number, cwd: string, path: string): boolean { const base = cwd.replace(/\/+$/, ""); if (!base || !path.startsWith(`${base}/`)) return false; const detail: OpenInChanges = { laneId, path: path.slice(base.length + 1) }; window.dispatchEvent(new CustomEvent(OPEN_IN_CHANGES_EVENT, { detail })); return true; }