@devries-cameron20 / composio Mirror · read-only / commits / b148eda4e
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 18:30 UTC

fix(cli): prompt only for missing plugins

Kshitij Jhunjhunwala committed Jul 14, 2026 at 15:23 UTC b148eda4e62e8e10540118a294584c8c96b351c2
5 files changed +169 -56
ts/packages/cli/src/commands/setup.cmd.ts
+65 -17
@@ -1,9 +1,13 @@
1 import { Command, Options } from '@effect/cli';
2 import { Effect } from 'effect';
3 import {
4 + detectSetupTargets,
5 + inspectSetupTargets,
6 installSetupTargets,
5 - resolveSetupTargets,
7 + isSetupPluginReady,
8 + isSetupReady,
9 SETUP_TARGETS,
10 + type AgentHost,
11 type SetupTarget,
12 } from 'src/services/setup';
13 import { TerminalUI } from 'src/services/terminal-ui';
@@ -25,6 +29,14 @@ const ifPresent = Options.boolean('if-present').pipe(
29 Options.withDescription('Exit successfully when automatic detection finds no supported host')
30 );
31
32 +const TARGET_LABELS: Readonly<Record<AgentHost, string>> = {
33 + claude: 'Claude Code',
34 + codex: 'Codex',
35 +};
36 +
37 +const formatTargets = (targets: ReadonlyArray<AgentHost>): string =>
38 + targets.map(target => TARGET_LABELS[target]).join(' and ');
39 +
40 const setupBaseCmd = Command.make(
41 'setup',
42 { target, yes, ifPresent },
@@ -33,34 +45,70 @@ const setupBaseCmd = Command.make(
45 const ui = yield* TerminalUI;
46 yield* ui.intro('composio setup');
47
36 - if (!yes && !isInteractiveTerminal()) {
37 - return yield* Effect.fail(
38 - new Error('Non-interactive setup requires `--yes` to approve local changes.')
48 + const detections = yield* detectSetupTargets(target);
49 + const detected = detections.filter(result => result.available).map(result => result.target);
50 + const notDetected = detections
51 + .filter(result => !result.available)
52 + .map(result => result.target);
53 +
54 + if (detected.length > 0) {
55 + yield* ui.log.success(`${formatTargets(detected)} detected.`);
56 + }
57 + if (notDetected.length > 0) {
58 + yield* ui.log.info(`${formatTargets(notDetected)} not detected.`);
59 + }
60 + if (detected.length === 0) {
61 + if (!ifPresent || target !== 'auto') {
62 + return yield* Effect.fail(
63 + new Error(
64 + 'No supported agent host was detected. Install Claude Code or Codex, then rerun `composio setup`.'
65 + )
66 + );
67 + }
68 + yield* ui.outro('No supported agent host detected; plugin setup skipped.');
69 + return;
70 + }
71 +
72 + const inspected = yield* inspectSetupTargets(detections);
73 + for (const status of inspected.filter(isSetupPluginReady)) {
74 + yield* ui.log.success(
75 + `The Composio plugin for ${TARGET_LABELS[status.target]} is already installed and enabled.`
76 );
77 }
78
42 - const targets = yield* resolveSetupTargets(target, { allowEmpty: ifPresent });
43 - if (targets.length === 0) {
44 - yield* ui.outro('No supported agent host detected; plugin setup skipped.');
79 + const pending = inspected.filter(status => !isSetupReady(status));
80 + if (pending.length === 0) {
81 + yield* ui.outro('Composio setup complete.');
82 return;
83 }
47 - if (!yes) {
48 - const confirmed = yield* ui.confirm(`Install Composio for ${targets.join(' and ')}?`, {
49 - defaultValue: true,
50 - });
84 +
85 + const pendingPlugins = pending.filter(status => !isSetupPluginReady(status));
86 + if (!yes && pendingPlugins.length > 0) {
87 + if (!isInteractiveTerminal()) {
88 + return yield* Effect.fail(
89 + new Error('Non-interactive setup requires `--yes` to approve local changes.')
90 + );
91 + }
92 +
93 + const prompt = `Install the Composio plugin for ${formatTargets(pendingPlugins.map(status => status.target))}?`;
94 + const confirmed = yield* ui.confirm(prompt, { defaultValue: true });
95 if (!confirmed) {
96 yield* ui.outro('Setup cancelled.');
97 return;
98 }
99 }
100
57 - const results = yield* installSetupTargets(targets);
101 + const results = yield* installSetupTargets(pending);
102 for (const result of results) {
59 - let pluginMessage = `The Composio plugin for ${result.target} is already installed and enabled.`;
60 - if (result.plugin_changed) {
61 - pluginMessage = `Configured and enabled the Composio plugin for ${result.target}.`;
62 - }
63 - yield* ui.log.success(pluginMessage);
103 + if (!result.plugin_changed) continue;
104 +
105 + const initial = pending.find(status => status.target === result.target)!;
106 + let action = 'configured and enabled';
107 + if (!initial.plugin_installed) action = 'installed and enabled';
108 + else if (!initial.plugin_enabled) action = 'enabled';
109 + yield* ui.log.success(
110 + `Successfully ${action} the Composio plugin for ${TARGET_LABELS[result.target]}.`
111 + );
112 }
113
114 yield* ui.outro('Composio setup complete.');
ts/packages/cli/src/effects/install-skill.ts
+5 -1
@@ -119,6 +119,7 @@ export const installSkill = (options?: {
119 readonly channel?: SkillReleaseChannel;
120 readonly target?: SkillInstallTarget;
121 readonly skillName?: string;
122 + readonly silent?: boolean;
123 }) =>
124 Effect.gen(function* () {
125 const os = yield* NodeOs;
@@ -216,7 +217,9 @@ export const installSkill = (options?: {
217 Effect.ensuring(fs.remove(tmpDir, { recursive: true, force: true }).pipe(Effect.orDie))
218 );
219
219 - yield* ui.log.success(`Installed ${skillName} skill for ${resolveTargetLabel(target)}`);
220 + if (!options?.silent) {
221 + yield* ui.log.success(`Installed ${skillName} skill for ${resolveTargetLabel(target)}`);
222 + }
223 });
224
225 /**
@@ -227,6 +230,7 @@ export const installSkillSafe = (options?: {
230 readonly channel?: SkillReleaseChannel;
231 readonly target?: SkillInstallTarget;
232 readonly skillName?: string;
233 + readonly silent?: boolean;
234 }) =>
235 installSkill(options).pipe(
236 Effect.sandbox,
ts/packages/cli/src/services/setup-skill-installer.ts
+1
@@ -63,6 +63,7 @@ export class SetupSkillInstaller extends Effect.Service<SetupSkillInstaller>()(
63 yield* installSkill({
64 target: 'claude',
65 releaseTag,
66 + silent: true,
67 });
68 return true;
69 }),
ts/packages/cli/src/services/setup.ts
+31 -31
@@ -19,7 +19,7 @@ const CODEX_PLUGIN_MARKETPLACE = {
19 plugin: 'composio@composio',
20 } as const;
21
22 -interface SetupTargetStatus {
22 +export interface SetupTargetStatus {
23 readonly target: AgentHost;
24 readonly available: boolean;
25 readonly marketplace_configured: boolean;
@@ -29,7 +29,7 @@ interface SetupTargetStatus {
29 readonly cli_skill_ready: boolean;
30 }
31
32 -interface SetupTargetResult extends SetupTargetStatus {
32 +export interface SetupTargetResult extends SetupTargetStatus {
33 readonly changed: boolean;
34 readonly plugin_changed: boolean;
35 readonly skill_changed: boolean;
@@ -51,7 +51,7 @@ interface SetupTargetAdapter {
51 readonly skillSource: 'bundled' | 'standalone';
52 }
53
54 -interface InspectedSetupTarget extends SetupTargetStatus {
54 +export interface InspectedSetupTarget extends SetupTargetStatus {
55 readonly marketplace_conflict: boolean;
56 }
57
@@ -265,10 +265,10 @@ const requireInspection = <T>(
265 return Effect.succeed(inspected);
266 };
267
268 -const inspectAdapter = (adapter: SetupTargetAdapter) =>
268 +const inspectAdapter = (adapter: SetupTargetAdapter, knownAvailable?: boolean) =>
269 Effect.gen(function* () {
270 const skillInstaller = yield* SetupSkillInstaller;
271 - const available = yield* isAdapterAvailable(adapter);
271 + const available = knownAvailable ?? (yield* isAdapterAvailable(adapter));
272 if (!available) {
273 return {
274 target: adapter.target,
@@ -331,12 +331,14 @@ const pluginRepairStep = (
331 return undefined;
332 };
333
334 -const isSetupReady = (status: SetupTargetStatus): boolean =>
334 +export const isSetupPluginReady = (status: SetupTargetStatus): boolean =>
335 status.available &&
336 status.marketplace_configured &&
337 status.plugin_installed &&
338 - status.plugin_enabled &&
339 - status.cli_skill_ready;
338 + status.plugin_enabled;
339 +
340 +export const isSetupReady = (status: SetupTargetStatus): boolean =>
341 + isSetupPluginReady(status) && status.cli_skill_ready;
342
343 const runRequired = (adapter: SetupTargetAdapter, args: ReadonlyArray<string>, operation: string) =>
344 Effect.gen(function* () {
@@ -420,39 +422,37 @@ const FIXED_TARGETS: Readonly<Partial<Record<SetupTarget, ReadonlyArray<AgentHos
422 all: ['claude', 'codex'],
423 };
424
423 -export const resolveSetupTargets = (
424 - target: SetupTarget,
425 - options: { readonly allowEmpty?: boolean } = {}
426 -) =>
427 - Effect.gen(function* () {
428 - const fixedTargets = FIXED_TARGETS[target];
429 - if (fixedTargets) return fixedTargets;
425 +export interface SetupTargetDetection {
426 + readonly target: AgentHost;
427 + readonly available: boolean;
428 +}
429
431 - const statuses = yield* Effect.all(
432 - ADAPTER_LIST.map(adapter =>
433 - isAdapterAvailable(adapter).pipe(
434 - Effect.map(available => ({ target: adapter.target, available }))
430 +export const detectSetupTargets = (target: SetupTarget) =>
431 + Effect.gen(function* () {
432 + const targets = FIXED_TARGETS[target] ?? ADAPTER_LIST.map(adapter => adapter.target);
433 + return yield* Effect.all(
434 + targets.map(target =>
435 + isAdapterAvailable(ADAPTERS[target]).pipe(
436 + Effect.map(available => ({ target, available }) satisfies SetupTargetDetection)
437 )
438 )
439 );
438 - const detected = statuses.filter(status => status.available).map(status => status.target);
439 - if (detected.length === 0) {
440 - if (options.allowEmpty) return detected;
441 - return yield* Effect.fail(
442 - new Error(
443 - 'No supported agent host was detected. Install Claude Code or Codex, or pass `--target claude|codex` after installing it.'
444 - )
445 - );
446 - }
447 - return detected;
440 });
441
450 -export const installSetupTargets = (targets: ReadonlyArray<AgentHost>) =>
442 +export const inspectSetupTargets = (detections: ReadonlyArray<SetupTargetDetection>) =>
443 Effect.gen(function* () {
452 - const inspected = yield* Effect.forEach(targets, target => inspectAdapter(ADAPTERS[target]));
444 + const inspected = yield* Effect.forEach(
445 + detections.filter(detection => detection.available),
446 + detection => inspectAdapter(ADAPTERS[detection.target], true)
447 + );
448 yield* Effect.forEach(inspected, status =>
449 validateInitialState(ADAPTERS[status.target], status)
450 );
451 + return inspected;
452 + });
453 +
454 +export const installSetupTargets = (inspected: ReadonlyArray<InspectedSetupTarget>) =>
455 + Effect.gen(function* () {
456 const completed: SetupTargetResult[] = [];
457 for (const status of inspected) {
458 const result = yield* installAdapter(ADAPTERS[status.target], status).pipe(
ts/packages/cli/test/src/commands/setup.cmd.test.ts
+67 -7
@@ -221,6 +221,12 @@ describe('CLI: composio setup', () => {
221 marketplace: 'canonical',
222 plugin: 'enabled',
223 });
224 +
225 + const output = (yield* MockConsole.getLines()).join('\n');
226 + expect(output).toContain('Claude Code detected.');
227 + expect(output).toContain(
228 + 'Successfully installed and enabled the Composio plugin for Claude Code.'
229 + );
230 })
231 );
232 });
@@ -238,6 +244,39 @@ describe('CLI: composio setup', () => {
244 );
245 });
246
247 + const existingClaudeWithStaleSkill = makeFakeHosts({
248 + claude: { available: true, marketplace: 'canonical', plugin: 'enabled' },
249 + });
250 + let staleSkillRepaired = false;
251 + let staleSkillReady = false;
252 + const staleSkillInstaller = new SetupSkillInstaller({
253 + isClaudeSkillReady: Effect.sync(() => staleSkillReady),
254 + ensureClaudeSkill: Effect.sync(() => {
255 + staleSkillRepaired = true;
256 + staleSkillReady = true;
257 + return true;
258 + }),
259 + });
260 + layer(
261 + TestLive({
262 + commandRunner: existingClaudeWithStaleSkill.runner,
263 + setupSkillInstaller: staleSkillInstaller,
264 + })
265 + )('existing Claude plugin with stale skill', it => {
266 + it.scoped('repairs the skill silently without requiring plugin approval', () =>
267 + Effect.gen(function* () {
268 + yield* cli(['setup', '--target', 'claude']);
269 +
270 + expect(staleSkillRepaired).toBe(true);
271 + const output = (yield* MockConsole.getLines()).join('\n');
272 + expect(output).toContain(
273 + 'The Composio plugin for Claude Code is already installed and enabled.'
274 + );
275 + expect(output).not.toContain('skill');
276 + })
277 + );
278 + });
279 +
280 for (const host of ['claude', 'codex'] as const) {
281 const disabled = makeFakeHosts({
282 [host]: { available: true, marketplace: 'canonical', plugin: 'disabled' },
@@ -308,6 +347,10 @@ describe('CLI: composio setup', () => {
347 expect(
348 autoClaude.commands.some(parts => parts[0] === 'codex' && parts[1] !== '--version')
349 ).toBe(false);
350 +
351 + const output = (yield* MockConsole.getLines()).join('\n');
352 + expect(output).toContain('Claude Code detected.');
353 + expect(output).toContain('Codex not detected.');
354 })
355 );
356 });
@@ -324,18 +367,17 @@ describe('CLI: composio setup', () => {
367 )('automatic setup with both hosts', it => {
368 it.scoped('selects both detected hosts and reports only plugin status', () =>
369 Effect.gen(function* () {
327 - yield* cli(['setup', '--target', 'auto', '--yes']);
370 + yield* cli(['setup', '--target', 'auto']);
371
372 expect(autoBoth.commands.some(parts => parts[0] === 'claude')).toBe(true);
373 expect(autoBoth.commands.some(parts => parts[0] === 'codex')).toBe(true);
374
375 const output = (yield* MockConsole.getLines()).join('\n');
376 + expect(output).toContain('Claude Code and Codex detected.');
377 expect(output).toContain(
334 - 'The Composio plugin for claude is already installed and enabled.'
335 - );
336 - expect(output).toContain(
337 - 'The Composio plugin for codex is already installed and enabled.'
378 + 'The Composio plugin for Claude Code is already installed and enabled.'
379 );
380 + expect(output).toContain('The Composio plugin for Codex is already installed and enabled.');
381 expect(output).not.toContain('composio-cli skill');
382 })
383 );
@@ -438,6 +480,18 @@ describe('CLI: composio setup', () => {
480 cli(['setup', '--target', 'auto', '--yes', '--if-present'])
481 );
482 expect(Exit.isSuccess(exit)).toBe(true);
483 +
484 + const output = (yield* MockConsole.getLines()).join('\n');
485 + expect(output).toContain('Claude Code and Codex not detected.');
486 + })
487 + );
488 +
489 + it.scoped('does not skip an explicitly requested missing host', () =>
490 + Effect.gen(function* () {
491 + const exit = yield* Effect.exit(
492 + cli(['setup', '--target', 'claude', '--yes', '--if-present'])
493 + );
494 + expect(Exit.isFailure(exit)).toBe(true);
495 })
496 );
497 });
@@ -576,12 +630,18 @@ describe('CLI: composio setup', () => {
630
631 const nonInteractive = makeFakeHosts({ claude: { available: true } });
632 layer(TestLive({ commandRunner: nonInteractive.runner }))('non-interactive approval', it => {
579 - it.scoped('requires --yes before inspecting or mutating hosts', () =>
633 + it.scoped('inspects first but requires --yes before mutating hosts', () =>
634 Effect.gen(function* () {
635 const exit = yield* Effect.exit(cli(['setup', '--target', 'claude']));
636
637 expect(Exit.isFailure(exit)).toBe(true);
584 - expect(nonInteractive.commands).toHaveLength(0);
638 + expect(nonInteractive.commands).toContainEqual(['claude', '--version']);
639 + expect(nonInteractive.commands).toContainEqual(['claude', 'plugin', 'list', '--json']);
640 + expect(
641 + nonInteractive.commands.some(parts =>
642 + ['add', 'install', 'enable'].some(operation => parts.includes(operation))
643 + )
644 + ).toBe(false);
645 })
646 );
647 });