Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
fix(cli): prompt only for missing plugins
Kshitij Jhunjhunwalab148eda4e62e
diff --git a/ts/packages/cli/src/commands/setup.cmd.ts b/ts/packages/cli/src/commands/setup.cmd.tsindex 872a99788..f7c42b5b9 100644--- a/ts/packages/cli/src/commands/setup.cmd.ts+++ b/ts/packages/cli/src/commands/setup.cmd.ts@@ -1,9 +1,13 @@import { Command, Options } from '@effect/cli';import { Effect } from 'effect';import {+ detectSetupTargets,+ inspectSetupTargets,installSetupTargets,- resolveSetupTargets,+ isSetupPluginReady,+ isSetupReady,SETUP_TARGETS,+ type AgentHost,type SetupTarget,} from 'src/services/setup';import { TerminalUI } from 'src/services/terminal-ui';@@ -25,6 +29,14 @@ const ifPresent = Options.boolean('if-present').pipe(Options.withDescription('Exit successfully when automatic detection finds no supported host'));+const TARGET_LABELS: Readonly<Record<AgentHost, string>> = {+ claude: 'Claude Code',+ codex: 'Codex',+};++const formatTargets = (targets: ReadonlyArray<AgentHost>): string =>+ targets.map(target => TARGET_LABELS[target]).join(' and ');+const setupBaseCmd = Command.make('setup',{ target, yes, ifPresent },@@ -33,34 +45,70 @@ const setupBaseCmd = Command.make(const ui = yield* TerminalUI;yield* ui.intro('composio setup');- if (!yes && !isInteractiveTerminal()) {- return yield* Effect.fail(- new Error('Non-interactive setup requires `--yes` to approve local changes.')+ const detections = yield* detectSetupTargets(target);+ const detected = detections.filter(result => result.available).map(result => result.target);+ const notDetected = detections+ .filter(result => !result.available)+ .map(result => result.target);++ if (detected.length > 0) {+ yield* ui.log.success(`${formatTargets(detected)} detected.`);+ }+ if (notDetected.length > 0) {+ yield* ui.log.info(`${formatTargets(notDetected)} not detected.`);+ }+ if (detected.length === 0) {+ if (!ifPresent || target !== 'auto') {+ return yield* Effect.fail(+ new Error(+ 'No supported agent host was detected. Install Claude Code or Codex, then rerun `composio setup`.'+ )+ );+ }+ yield* ui.outro('No supported agent host detected; plugin setup skipped.');+ return;+ }++ const inspected = yield* inspectSetupTargets(detections);+ for (const status of inspected.filter(isSetupPluginReady)) {+ yield* ui.log.success(+ `The Composio plugin for ${TARGET_LABELS[status.target]} is already installed and enabled.`);}- const targets = yield* resolveSetupTargets(target, { allowEmpty: ifPresent });- if (targets.length === 0) {- yield* ui.outro('No supported agent host detected; plugin setup skipped.');+ const pending = inspected.filter(status => !isSetupReady(status));+ if (pending.length === 0) {+ yield* ui.outro('Composio setup complete.');return;}- if (!yes) {- const confirmed = yield* ui.confirm(`Install Composio for ${targets.join(' and ')}?`, {- defaultValue: true,- });++ const pendingPlugins = pending.filter(status => !isSetupPluginReady(status));+ if (!yes && pendingPlugins.length > 0) {+ if (!isInteractiveTerminal()) {+ return yield* Effect.fail(+ new Error('Non-interactive setup requires `--yes` to approve local changes.')+ );+ }++ const prompt = `Install the Composio plugin for ${formatTargets(pendingPlugins.map(status => status.target))}?`;+ const confirmed = yield* ui.confirm(prompt, { defaultValue: true });if (!confirmed) {yield* ui.outro('Setup cancelled.');return;}}- const results = yield* installSetupTargets(targets);+ const results = yield* installSetupTargets(pending);for (const result of results) {- let pluginMessage = `The Composio plugin for ${result.target} is already installed and enabled.`;- if (result.plugin_changed) {- pluginMessage = `Configured and enabled the Composio plugin for ${result.target}.`;- }- yield* ui.log.success(pluginMessage);+ if (!result.plugin_changed) continue;++ const initial = pending.find(status => status.target === result.target)!;+ let action = 'configured and enabled';+ if (!initial.plugin_installed) action = 'installed and enabled';+ else if (!initial.plugin_enabled) action = 'enabled';+ yield* ui.log.success(+ `Successfully ${action} the Composio plugin for ${TARGET_LABELS[result.target]}.`+ );}yield* ui.outro('Composio setup complete.');diff --git a/ts/packages/cli/src/effects/install-skill.ts b/ts/packages/cli/src/effects/install-skill.tsindex 8ee2086db..6786c3e9b 100644--- a/ts/packages/cli/src/effects/install-skill.ts+++ b/ts/packages/cli/src/effects/install-skill.ts@@ -119,6 +119,7 @@ export const installSkill = (options?: {readonly channel?: SkillReleaseChannel;readonly target?: SkillInstallTarget;readonly skillName?: string;+ readonly silent?: boolean;}) =>Effect.gen(function* () {const os = yield* NodeOs;@@ -216,7 +217,9 @@ export const installSkill = (options?: {Effect.ensuring(fs.remove(tmpDir, { recursive: true, force: true }).pipe(Effect.orDie)));- yield* ui.log.success(`Installed ${skillName} skill for ${resolveTargetLabel(target)}`);+ if (!options?.silent) {+ yield* ui.log.success(`Installed ${skillName} skill for ${resolveTargetLabel(target)}`);+ }});/**@@ -227,6 +230,7 @@ export const installSkillSafe = (options?: {readonly channel?: SkillReleaseChannel;readonly target?: SkillInstallTarget;readonly skillName?: string;+ readonly silent?: boolean;}) =>installSkill(options).pipe(Effect.sandbox,diff --git a/ts/packages/cli/src/services/setup-skill-installer.ts b/ts/packages/cli/src/services/setup-skill-installer.tsindex 27f48dcd4..9d58cc878 100644--- a/ts/packages/cli/src/services/setup-skill-installer.ts+++ b/ts/packages/cli/src/services/setup-skill-installer.ts@@ -63,6 +63,7 @@ export class SetupSkillInstaller extends Effect.Service<SetupSkillInstaller>()(yield* installSkill({target: 'claude',releaseTag,+ silent: true,});return true;}),diff --git a/ts/packages/cli/src/services/setup.ts b/ts/packages/cli/src/services/setup.tsindex ecd65468c..540567dcb 100644--- a/ts/packages/cli/src/services/setup.ts+++ b/ts/packages/cli/src/services/setup.ts@@ -19,7 +19,7 @@ const CODEX_PLUGIN_MARKETPLACE = {plugin: 'composio@composio',} as const;-interface SetupTargetStatus {+export interface SetupTargetStatus {readonly target: AgentHost;readonly available: boolean;readonly marketplace_configured: boolean;@@ -29,7 +29,7 @@ interface SetupTargetStatus {readonly cli_skill_ready: boolean;}-interface SetupTargetResult extends SetupTargetStatus {+export interface SetupTargetResult extends SetupTargetStatus {readonly changed: boolean;readonly plugin_changed: boolean;readonly skill_changed: boolean;@@ -51,7 +51,7 @@ interface SetupTargetAdapter {readonly skillSource: 'bundled' | 'standalone';}-interface InspectedSetupTarget extends SetupTargetStatus {+export interface InspectedSetupTarget extends SetupTargetStatus {readonly marketplace_conflict: boolean;}@@ -265,10 +265,10 @@ const requireInspection = <T>(return Effect.succeed(inspected);};-const inspectAdapter = (adapter: SetupTargetAdapter) =>+const inspectAdapter = (adapter: SetupTargetAdapter, knownAvailable?: boolean) =>Effect.gen(function* () {const skillInstaller = yield* SetupSkillInstaller;- const available = yield* isAdapterAvailable(adapter);+ const available = knownAvailable ?? (yield* isAdapterAvailable(adapter));if (!available) {return {target: adapter.target,@@ -331,12 +331,14 @@ const pluginRepairStep = (return undefined;};-const isSetupReady = (status: SetupTargetStatus): boolean =>+export const isSetupPluginReady = (status: SetupTargetStatus): boolean =>status.available &&status.marketplace_configured &&status.plugin_installed &&- status.plugin_enabled &&- status.cli_skill_ready;+ status.plugin_enabled;++export const isSetupReady = (status: SetupTargetStatus): boolean =>+ isSetupPluginReady(status) && status.cli_skill_ready;const runRequired = (adapter: SetupTargetAdapter, args: ReadonlyArray<string>, operation: string) =>Effect.gen(function* () {@@ -420,39 +422,37 @@ const FIXED_TARGETS: Readonly<Partial<Record<SetupTarget, ReadonlyArray<AgentHosall: ['claude', 'codex'],};-export const resolveSetupTargets = (- target: SetupTarget,- options: { readonly allowEmpty?: boolean } = {}-) =>- Effect.gen(function* () {- const fixedTargets = FIXED_TARGETS[target];- if (fixedTargets) return fixedTargets;+export interface SetupTargetDetection {+ readonly target: AgentHost;+ readonly available: boolean;+}- const statuses = yield* Effect.all(- ADAPTER_LIST.map(adapter =>- isAdapterAvailable(adapter).pipe(- Effect.map(available => ({ target: adapter.target, available }))+export const detectSetupTargets = (target: SetupTarget) =>+ Effect.gen(function* () {+ const targets = FIXED_TARGETS[target] ?? ADAPTER_LIST.map(adapter => adapter.target);+ return yield* Effect.all(+ targets.map(target =>+ isAdapterAvailable(ADAPTERS[target]).pipe(+ Effect.map(available => ({ target, available }) satisfies SetupTargetDetection))));- const detected = statuses.filter(status => status.available).map(status => status.target);- if (detected.length === 0) {- if (options.allowEmpty) return detected;- return yield* Effect.fail(- new Error(- 'No supported agent host was detected. Install Claude Code or Codex, or pass `--target claude|codex` after installing it.'- )- );- }- return detected;});-export const installSetupTargets = (targets: ReadonlyArray<AgentHost>) =>+export const inspectSetupTargets = (detections: ReadonlyArray<SetupTargetDetection>) =>Effect.gen(function* () {- const inspected = yield* Effect.forEach(targets, target => inspectAdapter(ADAPTERS[target]));+ const inspected = yield* Effect.forEach(+ detections.filter(detection => detection.available),+ detection => inspectAdapter(ADAPTERS[detection.target], true)+ );yield* Effect.forEach(inspected, status =>validateInitialState(ADAPTERS[status.target], status));+ return inspected;+ });++export const installSetupTargets = (inspected: ReadonlyArray<InspectedSetupTarget>) =>+ Effect.gen(function* () {const completed: SetupTargetResult[] = [];for (const status of inspected) {const result = yield* installAdapter(ADAPTERS[status.target], status).pipe(diff --git a/ts/packages/cli/test/src/commands/setup.cmd.test.ts b/ts/packages/cli/test/src/commands/setup.cmd.test.tsindex ba80c099e..564c7ebc0 100644--- a/ts/packages/cli/test/src/commands/setup.cmd.test.ts+++ b/ts/packages/cli/test/src/commands/setup.cmd.test.ts@@ -221,6 +221,12 @@ describe('CLI: composio setup', () => {marketplace: 'canonical',plugin: 'enabled',});++ const output = (yield* MockConsole.getLines()).join('\n');+ expect(output).toContain('Claude Code detected.');+ expect(output).toContain(+ 'Successfully installed and enabled the Composio plugin for Claude Code.'+ );}));});@@ -238,6 +244,39 @@ describe('CLI: composio setup', () => {);});+ const existingClaudeWithStaleSkill = makeFakeHosts({+ claude: { available: true, marketplace: 'canonical', plugin: 'enabled' },+ });+ let staleSkillRepaired = false;+ let staleSkillReady = false;+ const staleSkillInstaller = new SetupSkillInstaller({+ isClaudeSkillReady: Effect.sync(() => staleSkillReady),+ ensureClaudeSkill: Effect.sync(() => {+ staleSkillRepaired = true;+ staleSkillReady = true;+ return true;+ }),+ });+ layer(+ TestLive({+ commandRunner: existingClaudeWithStaleSkill.runner,+ setupSkillInstaller: staleSkillInstaller,+ })+ )('existing Claude plugin with stale skill', it => {+ it.scoped('repairs the skill silently without requiring plugin approval', () =>+ Effect.gen(function* () {+ yield* cli(['setup', '--target', 'claude']);++ expect(staleSkillRepaired).toBe(true);+ const output = (yield* MockConsole.getLines()).join('\n');+ expect(output).toContain(+ 'The Composio plugin for Claude Code is already installed and enabled.'+ );+ expect(output).not.toContain('skill');+ })+ );+ });+for (const host of ['claude', 'codex'] as const) {const disabled = makeFakeHosts({[host]: { available: true, marketplace: 'canonical', plugin: 'disabled' },@@ -308,6 +347,10 @@ describe('CLI: composio setup', () => {expect(autoClaude.commands.some(parts => parts[0] === 'codex' && parts[1] !== '--version')).toBe(false);++ const output = (yield* MockConsole.getLines()).join('\n');+ expect(output).toContain('Claude Code detected.');+ expect(output).toContain('Codex not detected.');}));});@@ -324,18 +367,17 @@ describe('CLI: composio setup', () => {)('automatic setup with both hosts', it => {it.scoped('selects both detected hosts and reports only plugin status', () =>Effect.gen(function* () {- yield* cli(['setup', '--target', 'auto', '--yes']);+ yield* cli(['setup', '--target', 'auto']);expect(autoBoth.commands.some(parts => parts[0] === 'claude')).toBe(true);expect(autoBoth.commands.some(parts => parts[0] === 'codex')).toBe(true);const output = (yield* MockConsole.getLines()).join('\n');+ expect(output).toContain('Claude Code and Codex detected.');expect(output).toContain(- 'The Composio plugin for claude is already installed and enabled.'- );- expect(output).toContain(- 'The Composio plugin for codex is already installed and enabled.'+ 'The Composio plugin for Claude Code is already installed and enabled.');+ expect(output).toContain('The Composio plugin for Codex is already installed and enabled.');expect(output).not.toContain('composio-cli skill');}));@@ -438,6 +480,18 @@ describe('CLI: composio setup', () => {cli(['setup', '--target', 'auto', '--yes', '--if-present']));expect(Exit.isSuccess(exit)).toBe(true);++ const output = (yield* MockConsole.getLines()).join('\n');+ expect(output).toContain('Claude Code and Codex not detected.');+ })+ );++ it.scoped('does not skip an explicitly requested missing host', () =>+ Effect.gen(function* () {+ const exit = yield* Effect.exit(+ cli(['setup', '--target', 'claude', '--yes', '--if-present'])+ );+ expect(Exit.isFailure(exit)).toBe(true);}));});@@ -576,12 +630,18 @@ describe('CLI: composio setup', () => {const nonInteractive = makeFakeHosts({ claude: { available: true } });layer(TestLive({ commandRunner: nonInteractive.runner }))('non-interactive approval', it => {- it.scoped('requires --yes before inspecting or mutating hosts', () =>+ it.scoped('inspects first but requires --yes before mutating hosts', () =>Effect.gen(function* () {const exit = yield* Effect.exit(cli(['setup', '--target', 'claude']));expect(Exit.isFailure(exit)).toBe(true);- expect(nonInteractive.commands).toHaveLength(0);+ expect(nonInteractive.commands).toContainEqual(['claude', '--version']);+ expect(nonInteractive.commands).toContainEqual(['claude', 'plugin', 'list', '--json']);+ expect(+ nonInteractive.commands.some(parts =>+ ['add', 'install', 'enable'].some(operation => parts.includes(operation))+ )+ ).toBe(false);}));});