Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Implement abortable prompt handling in fix command for improved user …
…experience
  • Loading branch information
aadesh18 committed Apr 27, 2026
commit 5acbcbd78f518bf05f83fc146c410a9d1e017932
30 changes: 17 additions & 13 deletions packages/stack-cli/src/commands/fix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ type FixOptions = {
const MAX_ERROR_LENGTH = 8000;
const MAX_STDIN_BYTES = MAX_ERROR_LENGTH * 4;

async function abortablePrompt<T>(promise: Promise<T>): Promise<T> {
try {
return await promise;
} catch (error: unknown) {
if (error != null && typeof error === "object" && "name" in error && (error as { name: unknown }).name === "ExitPromptError") {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
console.log("\nAborted.");
process.exit(0);
}
throw error;
}
}

async function readStdin(): Promise<string> {
if (process.stdin.isTTY) return "";
const chunks: Buffer[] = [];
Expand All @@ -39,15 +51,7 @@ export function registerFixCommand(program: Command) {
.option("--output-dir <dir>", "Directory of the project to fix (defaults to cwd)")
.option("-y, --yes", "Skip the confirmation prompt")
.action(async (opts: FixOptions) => {
try {
await runFix(opts);
} catch (error: unknown) {
if (error != null && typeof error === "object" && "name" in error && error.name === "ExitPromptError") {
console.log("\nAborted.");
process.exit(0);
}
throw error;
}
await runFix(opts);
});
}

Expand All @@ -63,10 +67,10 @@ async function runFix(opts: FixOptions) {
if (isNonInteractiveEnv()) {
throw new CliError("No error provided. Pass --error \"...\" or pipe the error to stdin.");
}
errorText = (await input({
errorText = (await abortablePrompt(input({
message: "Paste the Stack Auth error you want fixed:",
validate: (v) => v.trim().length > 0 || "Error text is required",
})).trim();
}))).trim();
}

if (errorText.length > MAX_ERROR_LENGTH) {
Expand All @@ -79,10 +83,10 @@ async function runFix(opts: FixOptions) {

if (!opts.yes && !isNonInteractiveEnv()) {
console.log(`Working directory: ${outputDir}`);
const ok = await confirm({
const ok = await abortablePrompt(confirm({
message: "Run the AI agent to fix this error?",
default: true,
});
}));
if (!ok) {
console.log("Aborted.");
return;
Expand Down