UNPKG

@code-yeongyu/senpi

Version:

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

66 lines • 2.32 kB
import { isAbsolute, relative } from "node:path"; export const STATUS_KEY = "ext:nested-agents:status"; export const WIDGET_KEY = "ext:nested-agents:widget"; export function updateStatus(ctx, cache, sessionKey, hasErrors) { if (!ctx.hasUI || !ctx.ui?.setStatus) return; const count = cache.getCacheSize(sessionKey); if (count === 0) { ctx.ui.setStatus(STATUS_KEY, undefined); return; } const theme = ctx.ui.theme ?? identityTheme; let text = theme.fg("dim", `🤖 ${count}`); if (hasErrors) text += theme.fg("warning", " ⚠️"); ctx.ui.setStatus(STATUS_KEY, text); } export function clearStatus(ctx) { if (!ctx.hasUI || !ctx.ui?.setStatus) return; ctx.ui.setStatus(STATUS_KEY, undefined); } export function updateWidget(ctx, visible, files) { if (!ctx.hasUI || !ctx.ui?.setWidget) return; if (!visible || files.length === 0) { ctx.ui.setWidget(WIDGET_KEY, undefined); return; } const theme = ctx.ui.theme ?? identityTheme; const lines = [theme.fg("accent", "Nested Context:")]; for (const file of files) { const display = displayPath(ctx.cwd, file.absolutePath); const text = file.truncated ? ` ${display} (truncated)` : ` ${display}`; lines.push(theme.fg(file.truncated ? "warning" : "dim", text)); } ctx.ui.setWidget(WIDGET_KEY, lines, { placement: "aboveEditor" }); } export function clearWidget(ctx) { if (!ctx.hasUI || !ctx.ui?.setWidget) return; ctx.ui.setWidget(WIDGET_KEY, undefined); } export function buildDebugRecord(input) { return { sessionKey: input.sessionKey, cacheSize: input.cache.getCacheSize(input.sessionKey), injectedDirectories: input.cache.listInjected(input.sessionKey), injectedFiles: input.files.map((f) => ({ path: f.absolutePath, truncated: f.truncated, })), }; } function displayPath(cwd, absolutePath) { if (!isAbsolute(absolutePath)) return absolutePath; const rel = relative(cwd, absolutePath); if (rel === "" || rel === ".." || rel.startsWith("../") || isAbsolute(rel)) return absolutePath; return rel; } const identityTheme = { fg: (_color, text) => text, }; //# sourceMappingURL=reporter.js.map