Skip to content

Commit fd0dd64

Browse files
committed
feat: offer automatic installation for missing coding assistants
- Add confirmation prompt asking if user wants automatic installation - Implement command execution using child_process.spawn - Add proper error handling and success/failure feedback - Verify installation success by checking availability after install
1 parent 87c3982 commit fd0dd64

File tree

1 file changed

+58
-3
lines changed

1 file changed

+58
-3
lines changed

src/config-collection/collect-config.ts

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { select, input, password } from "@inquirer/prompts";
1+
import { select, input, password, confirm } from "@inquirer/prompts";
22
import chalk from "chalk";
3+
import { spawn } from "child_process";
34
import type {
45
ProjectConfig,
56
AgentFramework,
@@ -66,15 +67,69 @@ export const collectConfig = async (): Promise<ProjectConfig> => {
6667
);
6768

6869
if (selectedCodingProvider) {
69-
const availability = await selectedCodingProvider.isAvailable();
70+
let availability = await selectedCodingProvider.isAvailable();
7071
if (!availability.installed && availability.installCommand) {
7172
console.log(
7273
chalk.yellow(
7374
`\n⚠️ ${selectedCodingProvider.displayName} is not installed.`
7475
)
7576
);
7677
console.log(chalk.gray("To install it, run:"));
77-
console.log(chalk.cyan(`${availability.installCommand}\n`));
78+
console.log(chalk.cyan(`${availability.installCommand}`));
79+
80+
const shouldInstall = await confirm({
81+
message: "Would you like me to install it for you?",
82+
default: true,
83+
});
84+
85+
if (shouldInstall) {
86+
console.log(chalk.gray("Installing..."));
87+
try {
88+
await new Promise<void>((resolve, reject) => {
89+
const [cmd, ...args] = availability.installCommand!.split(" ");
90+
const child = spawn(cmd, args, { stdio: "inherit" });
91+
92+
child.on("close", (code: number) => {
93+
if (code === 0) {
94+
resolve();
95+
} else {
96+
reject(
97+
new Error(`Installation failed with exit code ${code}`)
98+
);
99+
}
100+
});
101+
102+
child.on("error", reject);
103+
});
104+
105+
// Check availability again after installation
106+
availability = await selectedCodingProvider.isAvailable();
107+
if (availability.installed) {
108+
console.log(
109+
chalk.green(
110+
`✅ ${selectedCodingProvider.displayName} installed successfully!\n`
111+
)
112+
);
113+
} else {
114+
console.log(
115+
chalk.red(
116+
`❌ Installation may have failed. Please try installing manually.\n`
117+
)
118+
);
119+
}
120+
} catch (error) {
121+
console.log(
122+
chalk.red(
123+
`❌ Installation failed: ${
124+
error instanceof Error ? error.message : "Unknown error"
125+
}`
126+
)
127+
);
128+
console.log(chalk.gray("Please try installing manually.\n"));
129+
}
130+
} else {
131+
console.log();
132+
}
78133
}
79134
}
80135

0 commit comments

Comments
 (0)