refactor: decompose cmdAgentInfo and generic_wait_for_instance into focused helpers (#976)

Extract printAgentQuickStart from cmdAgentInfo (63 -> 43 lines), paralleling
the existing printCloudQuickStart pattern. Extract _poll_instance_once and
_report_instance_timeout from generic_wait_for_instance (52 -> 20 lines),
eliminating duplicated elapsed/sleep/increment code in the polling loop.

Agent: complexity-hunter

Co-authored-by: A <6723574+louisgv@users.noreply.github.com>
Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
A 2026-02-13 11:48:07 -08:00 committed by GitHub
parent 1d9a2dbad1
commit fff84779dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 74 additions and 62 deletions

View file

@ -1380,30 +1380,8 @@ export async function cmdAgentInfo(agent: string): Promise<void> {
// Prioritize clouds where the user already has credentials
const { sortedClouds, credCount } = prioritizeCloudsByCredentials(implClouds, manifest);
// Show quick-start with best available cloud (prefer one with credentials)
if (sortedClouds.length > 0) {
const exampleCloud = sortedClouds[0];
const cloudDef = manifest.clouds[exampleCloud];
const authVars = parseAuthEnvVars(cloudDef.auth);
const hasCreds = hasCloudCredentials(cloudDef.auth);
const hasOpenRouterKey = !!process.env.OPENROUTER_API_KEY;
const allReady = hasOpenRouterKey && (hasCreds || authVars.length === 0);
console.log();
if (allReady) {
console.log(pc.bold("Quick start:") + " " + pc.green("credentials detected -- ready to go"));
console.log(` ${pc.cyan(`spawn ${agentKey} ${exampleCloud}`)}`);
} else {
console.log(pc.bold("Quick start:"));
console.log(formatAuthVarLine("OPENROUTER_API_KEY", "https://openrouter.ai/settings/keys"));
if (authVars.length > 0) {
for (let i = 0; i < authVars.length; i++) {
// Only show the URL hint on the first auth var to avoid repetition
console.log(formatAuthVarLine(authVars[i], i === 0 ? cloudDef.url : undefined));
}
}
console.log(` ${pc.cyan(`spawn ${agentKey} ${exampleCloud}`)}`);
}
printAgentQuickStart(manifest, agentKey, sortedClouds[0]);
}
console.log();
@ -1431,6 +1409,31 @@ export async function cmdAgentInfo(agent: string): Promise<void> {
console.log();
}
/** Print quick-start instructions for an agent, using the best available cloud */
function printAgentQuickStart(manifest: Manifest, agentKey: string, exampleCloud: string): void {
const cloudDef = manifest.clouds[exampleCloud];
const authVars = parseAuthEnvVars(cloudDef.auth);
const hasCreds = hasCloudCredentials(cloudDef.auth);
const hasOpenRouterKey = !!process.env.OPENROUTER_API_KEY;
const allReady = hasOpenRouterKey && (hasCreds || authVars.length === 0);
console.log();
if (allReady) {
console.log(pc.bold("Quick start:") + " " + pc.green("credentials detected -- ready to go"));
console.log(` ${pc.cyan(`spawn ${agentKey} ${exampleCloud}`)}`);
} else {
console.log(pc.bold("Quick start:"));
console.log(formatAuthVarLine("OPENROUTER_API_KEY", "https://openrouter.ai/settings/keys"));
if (authVars.length > 0) {
for (let i = 0; i < authVars.length; i++) {
// Only show the URL hint on the first auth var to avoid repetition
console.log(formatAuthVarLine(authVars[i], i === 0 ? cloudDef.url : undefined));
}
}
console.log(` ${pc.cyan(`spawn ${agentKey} ${exampleCloud}`)}`);
}
}
// ── Cloud Info ─────────────────────────────────────────────────────────────────
/** Print quick-start auth instructions for a cloud provider */