-
Notifications
You must be signed in to change notification settings - Fork 51
feat(cli): implement iterate agents list — detect installed AI CLIs
#465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,73 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Command } from 'commander'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import kleur from 'kleur'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { exec } from '@profullstack/sh1pt-core'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| interface AgentDef { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| binary: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| versionArgs: string[]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| installHint: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| authHint: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| const KNOWN_AGENTS: AgentDef[] = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: 'claude', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| binary: 'claude', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| versionArgs: ['--version'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| installHint: 'mise use npm:@anthropic-ai/claude-code', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| authHint: 'run `claude /login`', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: 'codex', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| binary: 'codex', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| versionArgs: ['--version'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| installHint: 'npm install -g @openai/codex', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| authHint: 'set OPENAI_API_KEY env var', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: 'qwen', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| binary: 'qwen', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| versionArgs: ['--version'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| installHint: 'pip install qwen-agent', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| authHint: 'set DASHSCOPE_API_KEY env var', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| interface AgentStatus { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| installed: boolean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| version?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| installHint: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| authHint: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| async function checkAgent(agent: AgentDef): Promise<AgentStatus> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const noop = () => {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const result = await exec(agent.binary, agent.versionArgs, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| log: noop, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| throwOnNonZero: false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (result.exitCode === 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: agent.id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| installed: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| version: result.stdout.trim() || undefined, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| installHint: agent.installHint, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| authHint: agent.authHint, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // binary not found | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+52
to
+63
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: agent.id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| installed: false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| installHint: agent.installHint, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| authHint: agent.authHint, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const agentsCmd = new Command('agents') | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| .description('Orchestrate AI coding CLIs (Claude Code, Codex, Qwen) — generate, edit, and talk') | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -10,12 +78,29 @@ export const agentsCmd = new Command('agents') | |||||||||||||||||||||||||||||||||||||||||||||||||||
| agentsCmd | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| .command('list') | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| .description('Which agent CLIs are installed on this machine') | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| .action(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const agents = ['claude', 'codex', 'qwen']; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const a of agents) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // TODO: resolve adapter, call check(), render real status | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(` ${kleur.gray('○')} ${kleur.bold(a)} ${kleur.dim('run `sh1pt agents setup --agent ' + a + '`')}`); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| .option('--json', 'output as JSON') | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| .action(async (opts: { json?: boolean }) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const results = await Promise.all(KNOWN_AGENTS.map(checkAgent)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (opts.json) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(JSON.stringify(results, null, 2)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const r of results) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (r.installed) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ver = r.version ? kleur.dim(` v${r.version}`) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(` ${kleur.green('●')} ${kleur.bold(r.id)}${ver}`); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ` ${kleur.gray('○')} ${kleur.bold(r.id)} ${kleur.dim('not installed — ' + r.installHint)}` | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| const installed = results.filter((r) => r.installed).length; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(kleur.dim(`${installed}/${results.length} agent(s) installed. Run \`sh1pt agents setup\` to install missing agents.`)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| agentsCmd | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vprefix is prepended to the raw, un-parsed stdout of--version. In practiceclaude --versionoutputs something like"Claude Code 1.2.3"(the full tool name), so the displayed string becomesvClaude Code 1.2.3— not the cleanv1.2.3the PR description promises. The JSON output has the same issue:versioncontains the entire first-line dump rather than just the semver. A simple regex extracts the version number regardless of the prefix the CLI adds.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!