UNPKG

@code-yeongyu/senpi

Version:

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

45 lines • 1.99 kB
import * as path from "node:path"; import { getSessionsDir } from "../../../../config.js"; import { indexSessions } from "./indexer.js"; import { HistorySearchOverlay } from "./overlay.js"; export function resolveSearchRoot(currentSessionDir, defaultSessionsRoot = getSessionsDir(), pathImpl = path) { const defaultRoot = pathImpl.resolve(defaultSessionsRoot); if (!currentSessionDir) return defaultRoot; const current = pathImpl.resolve(currentSessionDir); if (current === defaultRoot) return defaultRoot; const rel = pathImpl.relative(defaultRoot, current); if (rel && !rel.startsWith("..") && !pathImpl.isAbsolute(rel)) return defaultRoot; return current; } export default function historySearchExtension(pi) { pi.registerCommand("history", { description: "Search prompt history across sessions", handler: async (_args, ctx) => { if (!ctx.hasUI) { ctx.ui.notify("No UI available", "info"); return; } let entries; try { const searchRoot = resolveSearchRoot(ctx.sessionManager.getSessionDir()); entries = await indexSessions(searchRoot); } catch (error) { const message = error instanceof Error ? error.message : String(error); ctx.ui.notify(`Failed to read prompt history: ${message}`, "error"); return; } if (entries.length === 0) { ctx.ui.notify("No prompt history found", "info"); return; } const selected = await ctx.ui.custom((tui, theme, _keybindings, done) => new HistorySearchOverlay({ tui, entries, theme, done }), { overlay: true, overlayOptions: { width: "90%", maxHeight: "80%", minWidth: 60, margin: 2 } }); if (selected) ctx.ui.setEditorText(selected.text); }, }); } //# sourceMappingURL=index.js.map