diff --git a/pi-extension.ts b/pi-extension.ts index c94673a..61019fa 100644 --- a/pi-extension.ts +++ b/pi-extension.ts @@ -55,6 +55,14 @@ function isDirty(content: string): boolean { return content.includes("## dirty") && !content.includes("## dirty\n-"); } +function renderProgressBar(completed: number, total: number, currentFile?: string, width = 20): string { + const pct = total > 0 ? completed / total : 0; + const filled = Math.round(width * pct); + const bar = "█".repeat(filled) + "░".repeat(width - filled); + const file = currentFile ? ` → ${currentFile}` : ""; + return `[${bar}] ${completed}/${total}${file}`; +} + export default function (pi: ExtensionAPI) { pi.registerTool({ name: "project_map_init", @@ -83,10 +91,10 @@ export default function (pi: ExtensionAPI) { llmClient: client, cacheDir: ctx.cwd, onProgress: (info) => { - const pct = info.total > 0 ? Math.round((info.completed / info.total) * 100) : 0; + const bar = renderProgressBar(info.completed, info.total, info.currentFile); _onUpdate?.({ - content: [{ type: "text", text: `${info.message} (${pct}%)` }], - details: { progress: pct, file: info.currentFile, dir: info.dir }, + content: [{ type: "text", text: bar }], + details: { progress: info.total > 0 ? Math.round((info.completed / info.total) * 100) : 0, file: info.currentFile, dir: info.dir }, }); }, }); @@ -215,10 +223,10 @@ export default function (pi: ExtensionAPI) { llmClient: client, cacheDir: ctx.cwd, onProgress: (info) => { - const pct = info.total > 0 ? Math.round((info.completed / info.total) * 100) : 0; + const bar = renderProgressBar(info.completed, info.total, info.currentFile); _onUpdate?.({ - content: [{ type: "text", text: `${info.message} (${pct}%)` }], - details: { progress: pct, file: info.currentFile, dir: info.dir }, + content: [{ type: "text", text: bar }], + details: { progress: info.total > 0 ? Math.round((info.completed / info.total) * 100) : 0, file: info.currentFile, dir: info.dir }, }); }, });