UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

90 lines • 3.9 kB
/** * In-process wire contract for config-watch extensions. * * Event emitters are intentionally untyped, so consumers must use these guards * before accepting a payload from `pi.events`. */ export const configWatchChannels = { register: "config-watch:register", unregister: "config-watch:unregister", ready: "config-watch:ready", changed: "config-watch:changed", reloaded: "config-watch:reloaded", rejected: "config-watch:rejected", }; export const CONFIG_WATCH_REGISTER = configWatchChannels.register; export const CONFIG_WATCH_UNREGISTER = configWatchChannels.unregister; export const CONFIG_WATCH_READY = configWatchChannels.ready; export const CONFIG_WATCH_CHANGED = configWatchChannels.changed; export const CONFIG_WATCH_RELOADED = configWatchChannels.reloaded; export const CONFIG_WATCH_REJECTED = configWatchChannels.rejected; function isRecord(value) { return typeof value === "object" && value !== null && !Array.isArray(value); } function isStringArray(value) { return Array.isArray(value) && value.every((entry) => typeof entry === "string"); } export function isConfigWatchTarget(value) { return (isRecord(value) && typeof value.path === "string" && (value.kind === "file" || value.kind === "dir") && (value.filterGlobs === undefined || isStringArray(value.filterGlobs))); } export function isConfigWatchRegistration(value) { return (isRecord(value) && typeof value.id === "string" && typeof value.displayName === "string" && Array.isArray(value.targets) && value.targets.every(isConfigWatchTarget) && (value.validate === undefined || typeof value.validate === "function")); } export function isConfigWatchValidation(value) { if (!isRecord(value) || typeof value.ok !== "boolean") return false; return value.ok || isStringArray(value.errors); } export function isConfigWatchUnregistration(value) { return isRecord(value) && typeof value.id === "string"; } export function isConfigWatchChanged(value) { return (isRecord(value) && typeof value.registrationId === "string" && isStringArray(value.paths) && typeof value.deferred === "boolean"); } export function isConfigWatchReloaded(value) { return isRecord(value) && typeof value.registrationId === "string" && isStringArray(value.paths); } export function isConfigWatchRejected(value) { return (isRecord(value) && typeof value.registrationId === "string" && isStringArray(value.paths) && isStringArray(value.errors)); } /** * Matches plain file names, path suffixes, and a leading-star suffix pattern. * This intentionally does not implement a full glob language. * * A leading `/` anchors the glob to the watch root, which is the only way to * express "this immediate child" for a recursive target. Without it a bare * `.omo` glob on an ancestor watch matches every `.omo` directory in the whole * subtree. */ export function matchesConfigWatchFilter(path, filterGlobs) { if (filterGlobs === undefined || filterGlobs.length === 0) return true; const normalizedPath = path.replaceAll("\\", "/"); const basename = normalizedPath.slice(normalizedPath.lastIndexOf("/") + 1); return filterGlobs.some((filterGlob) => { if (filterGlob.startsWith("/")) return normalizedPath === filterGlob.slice(1); if (filterGlob.startsWith("*")) return normalizedPath.endsWith(filterGlob.slice(1)); return basename === filterGlob || normalizedPath.endsWith(`/${filterGlob}`); }); } /** Returns registrations keyed by ID, with later duplicate registrations taking precedence. */ export function resolveConfigWatchRegistrations(registrations) { return [...new Map([...registrations].map((registration) => [registration.id, registration])).values()]; } //# sourceMappingURL=protocol.js.map