feat: add live progress streaming to init/reinit tools
- InitOptions.onProgress callback for directory-level progress - generateDirectoryMap reports per-file progress (→ filename) - initProject reports [N/M] Analyzing <path> (X files)... - pi-extension wires _onUpdate to onProgress for live Pi UI updates - User sees real-time feedback instead of silent long waits
This commit is contained in:
+12
-2
@@ -78,7 +78,12 @@ export default function (pi: ExtensionAPI) {
|
||||
try {
|
||||
const targetPath = params.path || ctx.cwd;
|
||||
const client = getPiLLMClient(ctx);
|
||||
await initProject(targetPath, { verbose: false, llmClient: client, cacheDir: ctx.cwd });
|
||||
await initProject(targetPath, {
|
||||
verbose: false,
|
||||
llmClient: client,
|
||||
cacheDir: ctx.cwd,
|
||||
onProgress: (msg) => _onUpdate?.({ content: [{ type: "text", text: msg }] }),
|
||||
});
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
@@ -199,7 +204,12 @@ export default function (pi: ExtensionAPI) {
|
||||
try {
|
||||
const targetPath = params.path || ctx.cwd;
|
||||
const client = getPiLLMClient(ctx);
|
||||
await reinitPath(targetPath, { verbose: false, llmClient: client, cacheDir: ctx.cwd });
|
||||
await reinitPath(targetPath, {
|
||||
verbose: false,
|
||||
llmClient: client,
|
||||
cacheDir: ctx.cwd,
|
||||
onProgress: (msg) => _onUpdate?.({ content: [{ type: "text", text: msg }] }),
|
||||
});
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
|
||||
+9
-2
@@ -16,6 +16,7 @@ export interface InitOptions {
|
||||
verbose?: boolean;
|
||||
llmClient?: LLMClient;
|
||||
cacheDir?: string;
|
||||
onProgress?: (message: string) => void;
|
||||
}
|
||||
|
||||
export async function initProject(
|
||||
@@ -23,11 +24,15 @@ export async function initProject(
|
||||
options: InitOptions = {},
|
||||
): Promise<void> {
|
||||
const entries = discoverProject(rootPath);
|
||||
options.onProgress?.(`Scanning ${entries.length} directories...`);
|
||||
|
||||
for (const entry of entries) {
|
||||
await generateDirectoryMap(entry, options.llmClient, options.cacheDir);
|
||||
for (let i = 0; i < entries.length; i++) {
|
||||
const entry = entries[i];
|
||||
options.onProgress?.(`[${i + 1}/${entries.length}] Analyzing ${entry.relativePath} (${entry.files.length} files)...`);
|
||||
await generateDirectoryMap(entry, options.llmClient, options.cacheDir, options.onProgress);
|
||||
}
|
||||
|
||||
options.onProgress?.(`Generated ${entries.length} .pi-map.md files`);
|
||||
if (options.verbose !== false) {
|
||||
console.log(`Generated ${entries.length} .pi-map.md files`);
|
||||
}
|
||||
@@ -37,12 +42,14 @@ export async function generateDirectoryMap(
|
||||
entry: DirectoryEntry,
|
||||
llmClient?: LLMClient,
|
||||
cacheDir?: string,
|
||||
onProgress?: (message: string) => void,
|
||||
): Promise<FileEntry[]> {
|
||||
// Process files in parallel (4 concurrent) with retry logic
|
||||
const fileData = await processFiles(
|
||||
entry.files,
|
||||
async (file) => {
|
||||
const filePath = join(entry.dirPath, file);
|
||||
onProgress?.(` → ${file}`);
|
||||
const llmData = await extractFileLLM(filePath, llmClient, cacheDir);
|
||||
const astData = await extractFileAST(filePath);
|
||||
return mergeFileData(file, llmData, astData);
|
||||
|
||||
Reference in New Issue
Block a user