Skip to content

Commit c95ff32

Browse files
committed
fix: prevent expert command from hanging when using --prompt-file without context
- No longer scans all files by default with --prompt-file - Only uses prompt content when no files/preset specified - Shows helpful message about adding context with -f or --preset - Bump version to 0.4.3
1 parent 577b85c commit c95ff32

File tree

2 files changed

+42
-25
lines changed

2 files changed

+42
-25
lines changed

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "promptcode-cli",
3-
"version": "0.4.2",
3+
"version": "0.4.3",
44
"description": "CLI tool for PromptCode - Generate AI-ready prompts from codebases",
55
"bin": {
66
"promptcode": "./dist/promptcode"

packages/cli/src/commands/expert.ts

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,13 @@ export async function expertCommand(question: string | undefined, options: Exper
189189
} else {
190190
throw new Error(`Preset not found: ${options.preset}\nCreate it with: promptcode preset --create ${options.preset}`);
191191
}
192+
} else if (options.promptFile) {
193+
// When using prompt-file without files/preset, don't scan any files by default
194+
// The user can specify files/preset if they want context
195+
patterns = [];
196+
console.log(chalk.gray('💡 No files specified. Use -f or --preset to include code context.'));
192197
} else {
193-
// Default to all files
198+
// Default to all files only when not using prompt-file
194199
patterns = ['**/*'];
195200
}
196201

@@ -216,33 +221,45 @@ export async function expertCommand(question: string | undefined, options: Exper
216221
console.log(chalk.green(`✓ Saved file patterns to preset: ${options.savePreset}`));
217222
}
218223

219-
// Scan files
220-
const files = await scanFiles({
221-
cwd: projectPath,
222-
patterns,
223-
respectGitignore: true,
224-
workspaceName: path.basename(projectPath)
225-
});
224+
// Scan files only if patterns exist
225+
let files: any[] = [];
226+
let result: any;
226227

227-
if (files.length === 0) {
228-
if (spin) {
229-
spin.fail('No files found matching patterns');
230-
spin.stop(); // Ensure cleanup
228+
if (patterns.length > 0) {
229+
files = await scanFiles({
230+
cwd: projectPath,
231+
patterns,
232+
respectGitignore: true,
233+
workspaceName: path.basename(projectPath)
234+
});
235+
236+
if (files.length === 0) {
237+
if (spin) {
238+
spin.fail('No files found matching patterns');
239+
spin.stop(); // Ensure cleanup
240+
}
241+
console.error(chalk.yellow('\nTips:'));
242+
console.error(chalk.gray(' - Check if the path exists: ' + patterns.join(', ')));
243+
console.error(chalk.gray(' - Try using absolute paths or glob patterns'));
244+
console.error(chalk.gray(' - Make sure .gitignore is not excluding your files'));
245+
return;
231246
}
232-
console.error(chalk.yellow('\nTips:'));
233-
console.error(chalk.gray(' - Check if the path exists: ' + patterns.join(', ')));
234-
console.error(chalk.gray(' - Try using absolute paths or glob patterns'));
235-
console.error(chalk.gray(' - Make sure .gitignore is not excluding your files'));
236-
return;
247+
248+
// Build context with files
249+
result = await buildPrompt(files, '', {
250+
includeFiles: true,
251+
includeInstructions: false,
252+
includeFileContents: true
253+
});
254+
} else {
255+
// No files to scan - create minimal result for prompt-only queries
256+
result = {
257+
prompt: '',
258+
tokenCount: 0,
259+
fileCount: 0
260+
};
237261
}
238262

239-
// Build context
240-
const result = await buildPrompt(files, '', {
241-
includeFiles: true,
242-
includeInstructions: false,
243-
includeFileContents: true
244-
});
245-
246263
// Model already validated earlier, just use it
247264

248265
/* ──────────────────────────────────────────────────────────

0 commit comments

Comments
 (0)