fix(install): safer agent selection for first-time users

Before: first-time users (no history) saw "All detected agents"
as the first option in the agent picker. Mashing Enter would
install to all 32 agents, writing files across every adapter's
config dir. Selecting "Select specific agents" also pre-ticked
all 32 agents, requiring the user to un-tick by hand.

After:
- Default option is "Just <detected> (detected)" — one agent,
  low blast radius.
- "Select specific agents" moves above "All detected agents"
  and pre-ticks only the detected agent.
- "All detected agents" gets a second confirm gate
  ("Install to all N agents?") with initialValue: false.
- Hint text on "All" warns "use only if you know".

Returning users still see "Same as last time (Recommended)" as
the first option; their flow is unchanged.

Non-TTY path is unchanged (still auto-detects a single agent).

Wire detectAgent() through quickAgentSelect so the picker can
label and pre-select the detected agent. Empty selection from
the confirm gate is treated as cancellation.
This commit is contained in:
Rohit Ghumare
2026-04-20 21:58:44 +01:00
parent c8d0bbc844
commit 97ee4b9a43
2 changed files with 44 additions and 11 deletions
+6
View File
@@ -357,6 +357,7 @@ export class InstallCommand extends Command {
if (isInteractive) {
const allAgentTypes = getAllAdapters().map((a) => a.type);
const lastAgents = getLastAgents();
const detectedAgent = await detectAgent().catch(() => undefined);
step(`Detected ${allAgentTypes.length} agents`);
@@ -364,6 +365,7 @@ export class InstallCommand extends Command {
message: "Install to",
agents: allAgentTypes,
lastSelected: lastAgents,
detected: detectedAgent,
});
if (isCancel(agentResult)) {
@@ -372,6 +374,10 @@ export class InstallCommand extends Command {
}
const targetAgents = (agentResult as { agents: string[] }).agents as AgentType[];
if (targetAgents.length === 0) {
cancel("Installation cancelled");
return { agents: null, exitCode: 0 };
}
saveLastAgents(targetAgents);
return { agents: targetAgents, exitCode: 0 };
}
+38 -11
View File
@@ -117,9 +117,11 @@ export async function quickAgentSelect(options: {
message?: string;
agents: string[];
lastSelected?: string[];
}): Promise<{ agents: string[]; method: 'last' | 'all' | 'select' } | symbol> {
const { agents, lastSelected = [] } = options;
detected?: string;
}): Promise<{ agents: string[]; method: 'last' | 'all' | 'select' | 'detected' } | symbol> {
const { agents, lastSelected = [], detected } = options;
const hasLast = lastSelected.length > 0 && lastSelected.some(a => agents.includes(a));
const hasDetected = !!detected && agents.includes(detected);
const selectOptions: Array<{ value: string; label: string; hint?: string }> = [];
@@ -130,21 +132,29 @@ export async function quickAgentSelect(options: {
selectOptions.push({
value: 'last',
label: `Same as last time (Recommended)`,
label: 'Same as last time (Recommended)',
hint: `${agentList}${more}`,
});
}
selectOptions.push({
value: 'all',
label: 'All detected agents',
hint: `${agents.length} agent${agents.length !== 1 ? 's' : ''}`,
});
if (hasDetected) {
selectOptions.push({
value: 'detected',
label: `Just ${formatAgent(detected!)} (detected)`,
hint: detected,
});
}
selectOptions.push({
value: 'select',
label: 'Select specific agents',
hint: 'Choose manually',
hint: 'Choose manually, spacebar to toggle',
});
selectOptions.push({
value: 'all',
label: 'All detected agents',
hint: `${agents.length} agent${agents.length !== 1 ? 's' : ''} — use only if you know`,
});
const result = await clack.select({
@@ -156,20 +166,37 @@ export async function quickAgentSelect(options: {
return result;
}
const method = result as 'last' | 'all' | 'select';
const method = result as 'last' | 'all' | 'select' | 'detected';
if (method === 'last') {
return { agents: lastSelected.filter(a => agents.includes(a)), method };
}
if (method === 'detected') {
return { agents: [detected!], method };
}
if (method === 'all') {
const confirmed = await clack.confirm({
message: `Install to all ${agents.length} agents?`,
initialValue: false,
});
if (clack.isCancel(confirmed) || !confirmed) {
return clack.isCancel(confirmed) ? confirmed : { agents: [], method: 'all' };
}
return { agents, method };
}
const initialValues = lastSelected.length > 0
? lastSelected.filter(a => agents.includes(a))
: hasDetected ? [detected!] : [];
const selected = await agentMultiselect({
message: 'Select agents',
agents,
initialValues: lastSelected.length > 0 ? lastSelected : agents,
initialValues,
});
if (clack.isCancel(selected)) {