Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/lib/init/local-ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@ function safePath(cwd: string, relative: string): string {
return resolved;
}

/**
* Pre-compute directory listing before the first API call.
* Uses the same parameters the server's discover-context step would request.
*/
export function precomputeDirListing(directory: string): LocalOpResult {
return listDir({
type: "local-op",
operation: "list-dir",
cwd: directory,
params: { path: ".", recursive: true, maxDepth: 3, maxEntries: 500 },
});
}

export async function handleLocalOp(
payload: LocalOpPayload,
options: WizardOptions
Expand Down
19 changes: 16 additions & 3 deletions src/lib/init/wizard-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from "./constants.js";
import { formatError, formatResult } from "./formatters.js";
import { handleInteractive } from "./interactive.js";
import { handleLocalOp } from "./local-ops.js";
import { handleLocalOp, precomputeDirListing } from "./local-ops.js";
import type {
InteractivePayload,
LocalOpPayload,
Expand Down Expand Up @@ -153,9 +153,22 @@ export async function runWizard(options: WizardOptions): Promise<void> {

let result: WorkflowRunResult;
try {
spin.start("Connecting to wizard...");
spin.start("Scanning project...");
const listing = precomputeDirListing(directory);
const dirListing =
(
listing.data as {
entries: Array<{
name: string;
path: string;
type: "file" | "directory";
}>;
}
)?.entries ?? [];

spin.message("Connecting to wizard...");
result = (await run.startAsync({
inputData: { directory, force, yes, dryRun, features },
inputData: { directory, force, yes, dryRun, features, dirListing },
tracingOptions,
})) as WorkflowRunResult;
} catch (err) {
Expand Down
Loading