Skip to content

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

fix(cli): simplify and harden plugin setup

jkomyno42db6d13e199
diff --git a/ts/e2e-tests/cli/setup-plugins/e2e.test.ts b/ts/e2e-tests/cli/setup-plugins/e2e.test.ts
index 2dd03167b..71f97113d 100644
--- a/ts/e2e-tests/cli/setup-plugins/e2e.test.ts
+++ b/ts/e2e-tests/cli/setup-plugins/e2e.test.ts
@@ -17,14 +17,22 @@ cp fixtures/fake-agent-host.sh /tmp/bin/${host}
chmod +x /tmp/bin/${host}
${
host === 'claude'
- ? `mkdir -p /tmp/.claude/skills/composio-cli /tmp/.agents/skills/composio-cli
-printf '@composio/cli@%s\n' "$(composio --version)" > /tmp/.agents/skills/composio-cli/.composio-release-tag`
+ ? `mkdir -p /tmp/.claude/skills /tmp/.agents/skills/composio-cli
+printf '%s\n' '# composio-cli' > /tmp/.agents/skills/composio-cli/SKILL.md
+printf '@composio/cli@%s\n' "$(composio --version)" > /tmp/.agents/skills/composio-cli/.composio-release-tag
+ln -s ../../.agents/skills/composio-cli /tmp/.claude/skills/composio-cli`
: ''
}
export HOST_STATE_DIR=/tmp/host-state
export PATH=/tmp/bin:$PATH
-composio setup --target ${host} --yes > first.json
-composio setup --target ${host} --yes > second.json
+composio setup --target ${host} --yes
+composio setup --target ${host} --yes
+${
+ host === 'claude'
+ ? `test -L /tmp/.claude/skills/composio-cli
+test -r /tmp/.claude/skills/composio-cli/SKILL.md`
+ : ''
+}
cp /tmp/host-state/commands.log commands.log
`;
@@ -33,8 +41,8 @@ e2e(import.meta.url, {
cli: ['current'],
},
defineTests: ({ runCmd }) => {
- let claude: E2ETestResultWithFiles<'first.json' | 'second.json' | 'commands.log'>;
- let codex: E2ETestResultWithFiles<'first.json' | 'second.json' | 'commands.log'>;
+ let claude: E2ETestResultWithFiles<'commands.log'>;
+ let codex: E2ETestResultWithFiles<'commands.log'>;
let unavailable: E2ETestResult;
beforeAll(async () => {
@@ -42,11 +50,11 @@ e2e(import.meta.url, {
// these fresh-container cases sequential to avoid same-millisecond names.
claude = await runCmd({
command: setupFixture('claude'),
- files: ['first.json', 'second.json', 'commands.log'],
+ files: ['commands.log'],
});
codex = await runCmd({
command: setupFixture('codex'),
- files: ['first.json', 'second.json', 'commands.log'],
+ files: ['commands.log'],
});
unavailable = await runCmd('composio setup --target auto --yes');
}, TIMEOUTS.FIXTURE);
@@ -66,25 +74,13 @@ e2e(import.meta.url, {
'codex plugin marketplace add https://github.com/ComposioHQ/composio-plugin-openai.git --json',
installCommand: 'codex plugin add composio@composio --json',
},
- ])('$host setup', ({ host, result, marketplaceCommand, installCommand }) => {
- it('installs once, is idempotent, and reports ready status', () => {
+ ])('$host setup', ({ result, marketplaceCommand, installCommand }) => {
+ it('installs once and is idempotent', () => {
const execution = result();
expect(execution.exitCode).toBe(0);
expect(execution.stdout).toBe('');
expect(execution.stderr).toBe('');
- const first = JSON.parse(execution.files['first.json']) as {
- success: boolean;
- targets: Array<{ target: string; changed: boolean; cli_skill_ready: boolean }>;
- };
- const second = JSON.parse(execution.files['second.json']) as typeof first;
- expect(first.success).toBe(true);
- expect(first.targets).toContainEqual(
- expect.objectContaining({ target: host, changed: true, cli_skill_ready: true })
- );
- expect(second.targets).toContainEqual(
- expect.objectContaining({ target: host, changed: false, cli_skill_ready: true })
- );
const commands = execution.files['commands.log'].trim().split('\n');
expect(commands.filter(command => command === marketplaceCommand)).toHaveLength(1);
expect(commands.filter(command => command === installCommand)).toHaveLength(1);
diff --git a/ts/e2e-tests/cli/setup-plugins/fixtures/fake-agent-host.sh b/ts/e2e-tests/cli/setup-plugins/fixtures/fake-agent-host.sh
index 93936a454..8c156d8e1 100644
--- a/ts/e2e-tests/cli/setup-plugins/fixtures/fake-agent-host.sh
+++ b/ts/e2e-tests/cli/setup-plugins/fixtures/fake-agent-host.sh
@@ -21,7 +21,7 @@ case "$host:$command" in
;;
"claude:plugin list --json")
if [ -f "$state_dir/claude-plugin" ]; then
- printf '%s\n' '[{"id":"composio@composio","installed":true,"enabled":true}]'
+ printf '%s\n' '[{"id":"composio@composio","scope":"user","enabled":true}]'
else
printf '%s\n' '[]'
fi
@@ -32,7 +32,7 @@ case "$host:$command" in
"claude:plugin install composio@composio --scope user")
touch "$state_dir/claude-plugin"
;;
- "claude:plugin enable composio@composio")
+ "claude:plugin enable composio@composio --scope user")
touch "$state_dir/claude-plugin"
;;
"codex:--version")
diff --git a/ts/packages/cli/src/commands/setup.cmd.ts b/ts/packages/cli/src/commands/setup.cmd.ts
index 58a4eae7f..90def390e 100644
--- a/ts/packages/cli/src/commands/setup.cmd.ts
+++ b/ts/packages/cli/src/commands/setup.cmd.ts
@@ -7,6 +7,7 @@ import {
type SetupTarget,
} from 'src/services/setup';
import { TerminalUI } from 'src/services/terminal-ui';
+import { isInteractiveTerminal } from 'src/utils/stdio';
const target = Options.choice('target', SETUP_TARGETS).pipe(
Options.withDefault('auto' as SetupTarget),
@@ -24,6 +25,12 @@ const setupBaseCmd = Command.make('setup', { target, yes }, ({ target, yes }) =>
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 targets = yield* resolveSetupTargets(target);
if (!yes) {
const confirmed = yield* ui.confirm(`Install Composio for ${targets.join(' and ')}?`, {
@@ -37,26 +44,21 @@ const setupBaseCmd = Command.make('setup', { target, yes }, ({ target, yes }) =>
const results = yield* installSetupTargets(targets);
for (const result of results) {
- yield* ui.log.success(
- result.plugin_changed
- ? `Configured and enabled the Composio plugin for ${result.target}.`
- : `The Composio plugin for ${result.target} is already installed and enabled.`
- );
- if (result.target === 'claude') {
- if (!result.skill_changed) {
- yield* ui.log.success('The composio-cli skill for Claude Code is already installed.');
- }
- } else {
+ 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.target === 'codex') {
yield* ui.log.success('The Codex plugin includes the composio-cli skill.');
+ continue;
+ }
+ if (!result.skill_changed) {
+ yield* ui.log.success('The composio-cli skill for Claude Code is already installed.');
}
}
- yield* ui.output(
- JSON.stringify({
- success: true,
- targets: results,
- })
- );
yield* ui.outro('Composio setup complete.');
})
);
diff --git a/ts/packages/cli/src/services/command-runner.ts b/ts/packages/cli/src/services/command-runner.ts
index 6aca7f342..d07343a87 100644
--- a/ts/packages/cli/src/services/command-runner.ts
+++ b/ts/packages/cli/src/services/command-runner.ts
@@ -1,5 +1,5 @@
import { Command } from '@effect/platform';
-import { Effect, Stream } from 'effect';
+import { Effect, Stream, String } from 'effect';
export interface CommandResult {
readonly exitCode: number;
@@ -8,7 +8,7 @@ export interface CommandResult {
}
const collectText = (stream: Stream.Stream<Uint8Array, unknown>) =>
- Stream.runFold(stream, '', (output, chunk) => output + new TextDecoder().decode(chunk));
+ stream.pipe(Stream.decodeText(), Stream.runFold(String.empty, String.concat));
export class CommandRunner extends Effect.Service<CommandRunner>()('services/CommandRunner', {
sync: () => ({
diff --git a/ts/packages/cli/src/services/setup-skill-installer.ts b/ts/packages/cli/src/services/setup-skill-installer.ts
index 6b47d6445..055638c1e 100644
--- a/ts/packages/cli/src/services/setup-skill-installer.ts
+++ b/ts/packages/cli/src/services/setup-skill-installer.ts
@@ -1,7 +1,12 @@
-import { Effect } from 'effect';
import fs from 'node:fs';
import path from 'node:path';
-import { installSkill, readInstalledSkillReleaseTag } from 'src/effects/install-skill';
+import { Effect } from 'effect';
+import {
+ installSkill,
+ readInstalledSkillReleaseTag,
+ resolveInstalledSkillName,
+ resolveTargetSkillPath,
+} from 'src/effects/install-skill';
import { APP_VERSION } from 'src/constants';
import { readInstalledReleaseTag } from 'src/services/run-companion-modules';
import { NodeOs } from './node-os';
@@ -12,16 +17,22 @@ export const resolveSetupSkillReleaseTag = (
): string => readInstalledReleaseTag(execPath) ?? `@composio/cli@${fallbackVersion}`;
export const isClaudeSkillCurrent = (home: string, releaseTag: string): boolean => {
- const target = path.join(home, '.claude', 'skills', 'composio-cli');
- const skillDir = path.join(home, '.agents', 'skills', 'composio-cli');
- return fs.existsSync(target) && readInstalledSkillReleaseTag(skillDir) === releaseTag;
+ const skillName = resolveInstalledSkillName();
+ const target = resolveTargetSkillPath({ home, skillName, target: 'claude' });
+ if (readInstalledSkillReleaseTag(target) !== releaseTag) return false;
+ try {
+ fs.readFileSync(path.join(target, 'SKILL.md'), 'utf8');
+ return true;
+ } catch {
+ return false;
+ }
};
export class SetupSkillInstaller extends Effect.Service<SetupSkillInstaller>()(
'services/SetupSkillInstaller',
{
sync: () => ({
- isClaudeSkillInstalled: Effect.gen(function* () {
+ isClaudeSkillReady: Effect.gen(function* () {
const os = yield* NodeOs;
return isClaudeSkillCurrent(os.homedir, resolveSetupSkillReleaseTag());
}),
diff --git a/ts/packages/cli/src/services/setup.ts b/ts/packages/cli/src/services/setup.ts
index ff04ad314..dfac808e2 100644
--- a/ts/packages/cli/src/services/setup.ts
+++ b/ts/packages/cli/src/services/setup.ts
@@ -7,19 +7,19 @@ export const SETUP_TARGETS = ['auto', 'claude', 'codex', 'all'] as const;
export type SetupTarget = (typeof SETUP_TARGETS)[number];
export type AgentHost = Exclude<SetupTarget, 'auto' | 'all'>;
-export const CLAUDE_PLUGIN_MARKETPLACE = {
+const CLAUDE_PLUGIN_MARKETPLACE = {
name: 'composio',
source: 'https://github.com/ComposioHQ/composio-plugin-cc.git',
plugin: 'composio@composio',
} as const;
-export const CODEX_PLUGIN_MARKETPLACE = {
+const CODEX_PLUGIN_MARKETPLACE = {
name: 'composio',
source: 'https://github.com/ComposioHQ/composio-plugin-openai.git',
plugin: 'composio@composio',
} as const;
-export interface SetupTargetStatus {
+interface SetupTargetStatus {
readonly target: AgentHost;
readonly available: boolean;
readonly marketplace_configured: boolean;
@@ -29,7 +29,7 @@ export interface SetupTargetStatus {
readonly cli_skill_ready: boolean;
}
-export interface SetupTargetResult extends SetupTargetStatus {
+interface SetupTargetResult extends SetupTargetStatus {
readonly changed: boolean;
readonly plugin_changed: boolean;
readonly skill_changed: boolean;
@@ -44,48 +44,65 @@ interface SetupTargetAdapter {
readonly marketplaceAddArgs: ReadonlyArray<string>;
readonly pluginInstallArgs: ReadonlyArray<string>;
readonly pluginEnableArgs: ReadonlyArray<string>;
+ readonly marketplaceRecordsKey?: string;
+ readonly pluginRecordsKey?: string;
+ readonly pluginScope?: string;
+ readonly marketplaceRemoveCommand: string;
+ readonly skillSource: 'bundled' | 'standalone';
}
interface InspectedSetupTarget extends SetupTargetStatus {
readonly marketplace_conflict: boolean;
}
-const CLAUDE_ADAPTER: SetupTargetAdapter = {
- target: 'claude',
- executable: 'claude',
- marketplace: CLAUDE_PLUGIN_MARKETPLACE,
- marketplaceListArgs: ['plugin', 'marketplace', 'list', '--json'],
- pluginListArgs: ['plugin', 'list', '--json'],
- marketplaceAddArgs: [
- 'plugin',
- 'marketplace',
- 'add',
- CLAUDE_PLUGIN_MARKETPLACE.source,
- '--scope',
- 'user',
- ],
- pluginInstallArgs: ['plugin', 'install', CLAUDE_PLUGIN_MARKETPLACE.plugin, '--scope', 'user'],
- pluginEnableArgs: ['plugin', 'enable', CLAUDE_PLUGIN_MARKETPLACE.plugin],
+const ADAPTERS: Readonly<Record<AgentHost, SetupTargetAdapter>> = {
+ claude: {
+ target: 'claude',
+ executable: 'claude',
+ marketplace: CLAUDE_PLUGIN_MARKETPLACE,
+ marketplaceListArgs: ['plugin', 'marketplace', 'list', '--json'],
+ pluginListArgs: ['plugin', 'list', '--json'],
+ marketplaceAddArgs: [
+ 'plugin',
+ 'marketplace',
+ 'add',
+ CLAUDE_PLUGIN_MARKETPLACE.source,
+ '--scope',
+ 'user',
+ ],
+ pluginInstallArgs: ['plugin', 'install', CLAUDE_PLUGIN_MARKETPLACE.plugin, '--scope', 'user'],
+ pluginEnableArgs: ['plugin', 'enable', CLAUDE_PLUGIN_MARKETPLACE.plugin, '--scope', 'user'],
+ pluginScope: 'user',
+ marketplaceRemoveCommand: 'claude plugin marketplace remove composio --scope user',
+ skillSource: 'standalone',
+ },
+ codex: {
+ target: 'codex',
+ executable: 'codex',
+ marketplace: CODEX_PLUGIN_MARKETPLACE,
+ marketplaceListArgs: ['plugin', 'marketplace', 'list', '--json'],
+ pluginListArgs: ['plugin', 'list', '--json'],
+ marketplaceAddArgs: ['plugin', 'marketplace', 'add', CODEX_PLUGIN_MARKETPLACE.source, '--json'],
+ pluginInstallArgs: ['plugin', 'add', CODEX_PLUGIN_MARKETPLACE.plugin, '--json'],
+ // Codex has no separate enable command. Re-adding is its native install/repair path.
+ pluginEnableArgs: ['plugin', 'add', CODEX_PLUGIN_MARKETPLACE.plugin, '--json'],
+ marketplaceRecordsKey: 'marketplaces',
+ pluginRecordsKey: 'installed',
+ marketplaceRemoveCommand: 'codex plugin marketplace remove composio --json',
+ skillSource: 'bundled',
+ },
};
-const CODEX_ADAPTER: SetupTargetAdapter = {
- target: 'codex',
- executable: 'codex',
- marketplace: CODEX_PLUGIN_MARKETPLACE,
- marketplaceListArgs: ['plugin', 'marketplace', 'list', '--json'],
- pluginListArgs: ['plugin', 'list', '--json'],
- marketplaceAddArgs: ['plugin', 'marketplace', 'add', CODEX_PLUGIN_MARKETPLACE.source, '--json'],
- pluginInstallArgs: ['plugin', 'add', CODEX_PLUGIN_MARKETPLACE.plugin, '--json'],
- // Codex has no separate enable command. Re-adding is its native install/repair path.
- pluginEnableArgs: ['plugin', 'add', CODEX_PLUGIN_MARKETPLACE.plugin, '--json'],
-};
+const ADAPTER_LIST = Object.values(ADAPTERS);
+const SETUP_COMMAND_TIMEOUT = '2 minutes';
-const ADAPTERS: ReadonlyArray<SetupTargetAdapter> = [CLAUDE_ADAPTER, CODEX_ADAPTER];
+const asRecord = (value: unknown): Record<string, unknown> | undefined => {
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) return undefined;
+ return value as Record<string, unknown>;
+};
-const asRecord = (value: unknown): Record<string, unknown> | undefined =>
- value !== null && typeof value === 'object' && !Array.isArray(value)
- ? (value as Record<string, unknown>)
- : undefined;
+const isRecord = (value: unknown): value is Record<string, unknown> =>
+ asRecord(value) !== undefined;
const parseJson = (value: string): unknown => {
try {
@@ -95,14 +112,34 @@ const parseJson = (value: string): unknown => {
}
};
-const recordsFrom = (value: unknown, key?: string): ReadonlyArray<Record<string, unknown>> => {
- const selected = key ? asRecord(value)?.[key] : value;
- return Array.isArray(selected)
- ? selected.flatMap(item => {
- const record = asRecord(item);
- return record ? [record] : [];
- })
- : [];
+const recordsFrom = (
+ value: unknown,
+ key?: string
+): ReadonlyArray<Record<string, unknown>> | undefined => {
+ let selected = value;
+ if (key) {
+ const record = asRecord(value);
+ if (!record) return undefined;
+ selected = record[key];
+ }
+ if (!Array.isArray(selected) || !selected.every(isRecord)) return undefined;
+ return selected;
+};
+
+const readString = (
+ record: Record<string, unknown> | undefined,
+ key: string
+): string | undefined => {
+ const value = record?.[key];
+ if (typeof value !== 'string') return undefined;
+ return value;
+};
+
+const firstString = (...values: ReadonlyArray<unknown>): string | undefined => {
+ for (const value of values) {
+ if (typeof value === 'string') return value;
+ }
+ return undefined;
};
const normalizeGitHubRepository = (value: string): string | undefined => {
@@ -110,13 +147,18 @@ const normalizeGitHubRepository = (value: string): string | undefined => {
if (!trimmed) return undefined;
let repository = trimmed;
- const scpStyle = /^git@github\.com:(.+)$/i.exec(repository);
- if (scpStyle) {
- repository = scpStyle[1] ?? '';
- } else if (/^[a-z][a-z0-9+.-]*:\/\//i.test(repository)) {
+ if (/^[a-z][a-z0-9+.-]*:\/\//i.test(repository)) {
try {
const url = new URL(repository);
- if (url.hostname.toLowerCase() !== 'github.com') return undefined;
+ const isCanonicalGitHubUrl =
+ url.protocol === 'https:' &&
+ url.hostname.toLowerCase() === 'github.com' &&
+ url.port === '' &&
+ url.username === '' &&
+ url.password === '' &&
+ url.search === '' &&
+ url.hash === '';
+ if (!isCanonicalGitHubUrl) return undefined;
repository = url.pathname;
} catch {
return undefined;
@@ -134,24 +176,22 @@ const normalizeGitHubRepository = (value: string): string | undefined => {
const marketplaceState = (
adapter: SetupTargetAdapter,
output: string
-): { readonly configured: boolean; readonly conflicting: boolean } => {
+): { readonly configured: boolean; readonly conflicting: boolean } | undefined => {
const parsed = parseJson(output);
- const records = recordsFrom(parsed, adapter.target === 'codex' ? 'marketplaces' : undefined);
+ const records = recordsFrom(parsed, adapter.marketplaceRecordsKey);
+ if (!records) return undefined;
const expected = normalizeGitHubRepository(adapter.marketplace.source);
const sourceMatches = (record: Record<string, unknown>) => {
- const repo = typeof record.repo === 'string' ? record.repo : undefined;
- const url = typeof record.url === 'string' ? record.url : undefined;
const nestedSource = asRecord(record.source);
const marketplaceSource = asRecord(record.marketplaceSource);
- const source =
- (typeof record.source === 'string' ? record.source : undefined) ??
- (typeof nestedSource?.repo === 'string' ? nestedSource.repo : undefined) ??
- (typeof nestedSource?.source === 'string' ? nestedSource.source : undefined) ??
- (typeof marketplaceSource?.source === 'string' ? marketplaceSource.source : undefined);
- return [repo, url, source].some(
- candidate =>
- typeof candidate === 'string' && normalizeGitHubRepository(candidate) === expected
+ const source = firstString(
+ record.source,
+ readString(nestedSource, 'repo'),
+ readString(nestedSource, 'source'),
+ readString(marketplaceSource, 'source')
);
+ const candidates = [readString(record, 'repo'), readString(record, 'url'), source];
+ return candidates.some(candidate => normalizeGitHubRepository(candidate ?? '') === expected);
};
const configured = records.some(sourceMatches);
const conflicting = records.some(
@@ -163,12 +203,14 @@ const marketplaceState = (
const pluginState = (
adapter: SetupTargetAdapter,
output: string
-): { readonly installed: boolean; readonly enabled: boolean } => {
+): { readonly installed: boolean; readonly enabled: boolean } | undefined => {
const parsed = parseJson(output);
- const records = recordsFrom(parsed, adapter.target === 'codex' ? 'installed' : undefined);
+ const records = recordsFrom(parsed, adapter.pluginRecordsKey);
+ if (!records) return undefined;
const plugin = records.find(record => {
const id = record.id ?? record.pluginId;
- return id === adapter.marketplace.plugin;
+ const scopeMatches = !adapter.pluginScope || record.scope === adapter.pluginScope;
+ return id === adapter.marketplace.plugin && scopeMatches;
});
if (!plugin || plugin.installed === false) return { installed: false, enabled: false };
return { installed: true, enabled: plugin.enabled !== false };
@@ -177,16 +219,57 @@ const pluginState = (
const capture = (executable: string, args: ReadonlyArray<string>) =>
Effect.gen(function* () {
const runner = yield* CommandRunner;
- return yield* runner
- .capture(Command.make(executable, ...args))
- .pipe(Effect.catchAll(() => Effect.succeed<CommandResult | undefined>(undefined)));
+ return yield* runner.capture(Command.make(executable, ...args)).pipe(
+ Effect.timeoutFail({
+ duration: SETUP_COMMAND_TIMEOUT,
+ onTimeout: () => new Error(`${executable} command timed out.`),
+ }),
+ Effect.catchAll(() => Effect.succeed<CommandResult | undefined>(undefined))
+ );
});
+const isAdapterAvailable = (adapter: SetupTargetAdapter) =>
+ capture(adapter.executable, ['--version']).pipe(
+ Effect.map(result => result !== undefined && result.exitCode === 0)
+ );
+
+const commandFailureSuffix = (result: CommandResult): string => {
+ const detail = result.stderr.trim() || result.stdout.trim();
+ if (detail) return `: ${detail}`;
+ return ` (exit ${result.exitCode})`;
+};
+
+const errorMessage = (error: unknown): string => {
+ if (error instanceof Error) return error.message;
+ return String(error);
+};
+
+const requireInspection = <T>(
+ adapter: SetupTargetAdapter,
+ operation: string,
+ result: CommandResult | undefined,
+ parse: (output: string) => T | undefined
+) => {
+ if (!result) {
+ return Effect.fail(new Error(`Failed to inspect ${adapter.target} ${operation}.`));
+ }
+ if (result.exitCode !== 0) {
+ return Effect.fail(
+ new Error(`Failed to inspect ${adapter.target} ${operation}${commandFailureSuffix(result)}.`)
+ );
+ }
+ const inspected = parse(result.stdout);
+ if (!inspected) {
+ return Effect.fail(new Error(`${adapter.target} returned invalid JSON for ${operation}.`));
+ }
+ return Effect.succeed(inspected);
+};
+
const inspectAdapter = (adapter: SetupTargetAdapter) =>
Effect.gen(function* () {
const skillInstaller = yield* SetupSkillInstaller;
- const version = yield* capture(adapter.executable, ['--version']);
- if (!version || version.exitCode !== 0) {
+ const available = yield* isAdapterAvailable(adapter);
+ if (!available) {
return {
target: adapter.target,
available: false,
@@ -202,103 +285,115 @@ const inspectAdapter = (adapter: SetupTargetAdapter) =>
capture(adapter.executable, adapter.marketplaceListArgs),
capture(adapter.executable, adapter.pluginListArgs),
]);
- const plugin =
- plugins && plugins.exitCode === 0
- ? pluginState(adapter, plugins.stdout)
- : { installed: false, enabled: false };
-
+ const plugin = yield* requireInspection(adapter, 'plugins', plugins, output =>
+ pluginState(adapter, output)
+ );
const pluginReady = plugin.installed && plugin.enabled;
- const marketplace =
- marketplaces && marketplaces.exitCode === 0
- ? marketplaceState(adapter, marketplaces.stdout)
- : { configured: false, conflicting: false };
+ const marketplace = yield* requireInspection(adapter, 'marketplaces', marketplaces, output =>
+ marketplaceState(adapter, output)
+ );
+ let cliSkillReady = pluginReady;
+ if (adapter.skillSource === 'standalone') {
+ cliSkillReady = yield* skillInstaller.isClaudeSkillReady;
+ }
return {
target: adapter.target,
available: true,
marketplace_configured: marketplace.configured,
plugin_installed: plugin.installed,
plugin_enabled: plugin.enabled,
- // Codex loads the composio-cli skill from the plugin package itself. Claude's
- // plugin uses the standalone skill installed from the matching CLI release.
- cli_skill_ready:
- adapter.target === 'codex' ? pluginReady : yield* skillInstaller.isClaudeSkillInstalled,
+ cli_skill_ready: cliSkillReady,
marketplace_conflict: marketplace.conflicting,
} satisfies InspectedSetupTarget;
});
+interface SetupStep {
+ readonly args: ReadonlyArray<string>;
+ readonly operation: string;
+}
+
+const pluginRepairStep = (
+ adapter: SetupTargetAdapter,
+ status: InspectedSetupTarget
+): SetupStep | undefined => {
+ if (!status.marketplace_configured || !status.plugin_installed) {
+ return {
+ args: adapter.pluginInstallArgs,
+ operation: `Installing the ${adapter.target} plugin`,
+ };
+ }
+ if (!status.plugin_enabled) {
+ return {
+ args: adapter.pluginEnableArgs,
+ operation: `Enabling the ${adapter.target} plugin`,
+ };
+ }
+ return undefined;
+};
+
+const isSetupReady = (status: SetupTargetStatus): boolean =>
+ status.available &&
+ status.marketplace_configured &&
+ status.plugin_installed &&
+ status.plugin_enabled &&
+ status.cli_skill_ready;
+
const runRequired = (adapter: SetupTargetAdapter, args: ReadonlyArray<string>, operation: string) =>
Effect.gen(function* () {
const runner = yield* CommandRunner;
- const result = yield* runner.capture(Command.make(adapter.executable, ...args));
+ const result = yield* runner.capture(Command.make(adapter.executable, ...args)).pipe(
+ Effect.timeoutFail({
+ duration: SETUP_COMMAND_TIMEOUT,
+ onTimeout: () => new Error(`${operation} timed out after ${SETUP_COMMAND_TIMEOUT}.`),
+ })
+ );
if (result.exitCode !== 0) {
- const detail = result.stderr.trim() || result.stdout.trim();
- return yield* Effect.fail(
- new Error(`${operation} failed${detail ? `: ${detail}` : ` (exit ${result.exitCode})`}`)
- );
+ return yield* Effect.fail(new Error(`${operation} failed${commandFailureSuffix(result)}`));
}
});
-const installAdapter = (adapter: SetupTargetAdapter) =>
- Effect.gen(function* () {
- const initial = yield* inspectAdapter(adapter);
- if (!initial.available) {
- return yield* Effect.fail(
- new Error(
- `${adapter.executable} is not installed or not available on PATH. Install it and rerun \`composio setup --target ${adapter.target}\`.`
- )
- );
- }
- if (initial.marketplace_conflict) {
- const removeCommand =
- adapter.target === 'claude'
- ? 'claude plugin marketplace remove composio --scope user'
- : 'codex plugin marketplace remove composio --json';
- return yield* Effect.fail(
- new Error(
- `The ${adapter.target} marketplace named "composio" points to a different source. Run \`${removeCommand}\`, then rerun \`composio setup --target ${adapter.target}\`.`
- )
- );
- }
+const validateInitialState = (adapter: SetupTargetAdapter, initial: InspectedSetupTarget) => {
+ if (!initial.available) {
+ return Effect.fail(
+ new Error(
+ `${adapter.executable} is not installed or not available on PATH. Install it and rerun \`composio setup --target ${adapter.target}\`.`
+ )
+ );
+ }
+ if (initial.marketplace_conflict) {
+ return Effect.fail(
+ new Error(
+ `The ${adapter.target} marketplace named "composio" points to a different source. Run \`${adapter.marketplaceRemoveCommand}\`, then rerun \`composio setup --target ${adapter.target}\`.`
+ )
+ );
+ }
+ return Effect.void;
+};
- let pluginChanged = false;
+const installAdapter = (adapter: SetupTargetAdapter, initial: InspectedSetupTarget) =>
+ Effect.gen(function* () {
+ const steps: SetupStep[] = [];
if (!initial.marketplace_configured) {
- yield* runRequired(
- adapter,
- adapter.marketplaceAddArgs,
- `Adding the ${adapter.target} marketplace`
- );
- pluginChanged = true;
+ steps.push({
+ args: adapter.marketplaceAddArgs,
+ operation: `Adding the ${adapter.target} marketplace`,
+ });
}
- if (!initial.plugin_installed) {
- yield* runRequired(
- adapter,
- adapter.pluginInstallArgs,
- `Installing the ${adapter.target} plugin`
- );
- pluginChanged = true;
- } else if (!initial.plugin_enabled) {
- yield* runRequired(
- adapter,
- adapter.pluginEnableArgs,
- `Enabling the ${adapter.target} plugin`
- );
- pluginChanged = true;
+ const repairStep = pluginRepairStep(adapter, initial);
+ if (repairStep) steps.push(repairStep);
+ for (const step of steps) {
+ yield* runRequired(adapter, step.args, step.operation);
}
+ const pluginChanged = steps.length > 0;
const skillInstaller = yield* SetupSkillInstaller;
- const skillChanged =
- adapter.target === 'claude' && !initial.cli_skill_ready
- ? yield* skillInstaller.ensureClaudeSkill
- : false;
+ let skillChanged = false;
+ if (adapter.skillSource === 'standalone' && !initial.cli_skill_ready) {
+ skillChanged = yield* skillInstaller.ensureClaudeSkill;
+ }
const final = yield* inspectAdapter(adapter);
- if (
- !final.available ||
- !final.marketplace_configured ||
- !final.plugin_installed ||
- !final.plugin_enabled ||
- !final.cli_skill_ready
- ) {
+ if (!isSetupReady(final)) {
return yield* Effect.fail(
new Error(
`Setup commands completed, but ${adapter.target} did not report the Composio plugin and CLI skill as ready. Rerun \`composio setup --target ${adapter.target}\` or inspect the native ${adapter.target} plugin configuration.`
@@ -319,14 +414,24 @@ const installAdapter = (adapter: SetupTargetAdapter) =>
} satisfies SetupTargetResult;
});
-const inspectSetupTargets = Effect.all(ADAPTERS.map(inspectAdapter));
+const FIXED_TARGETS: Readonly<Partial<Record<SetupTarget, ReadonlyArray<AgentHost>>>> = {
+ claude: ['claude'],
+ codex: ['codex'],
+ all: ['claude', 'codex'],
+};
export const resolveSetupTargets = (target: SetupTarget) =>
Effect.gen(function* () {
- if (target === 'claude' || target === 'codex') return [target] as const;
- if (target === 'all') return ['claude', 'codex'] as const;
+ const fixedTargets = FIXED_TARGETS[target];
+ if (fixedTargets) return fixedTargets;
- const statuses = yield* inspectSetupTargets;
+ const statuses = yield* Effect.all(
+ ADAPTER_LIST.map(adapter =>
+ isAdapterAvailable(adapter).pipe(
+ Effect.map(available => ({ target: adapter.target, available }))
+ )
+ )
+ );
const detected = statuses.filter(status => status.available).map(status => status.target);
if (detected.length === 0) {
return yield* Effect.fail(
@@ -339,7 +444,23 @@ export const resolveSetupTargets = (target: SetupTarget) =>
});
export const installSetupTargets = (targets: ReadonlyArray<AgentHost>) =>
- Effect.forEach(targets, target => {
- const adapter = ADAPTERS.find(candidate => candidate.target === target);
- return installAdapter(adapter as SetupTargetAdapter);
+ Effect.gen(function* () {
+ const inspected = yield* Effect.forEach(targets, target => inspectAdapter(ADAPTERS[target]));
+ yield* Effect.forEach(inspected, status =>
+ validateInitialState(ADAPTERS[status.target], status)
+ );
+ const completed: SetupTargetResult[] = [];
+ for (const status of inspected) {
+ const result = yield* installAdapter(ADAPTERS[status.target], status).pipe(
+ Effect.mapError(error => {
+ if (completed.length === 0) return error;
+ const targets = completed.map(item => item.target).join(', ');
+ return new Error(
+ `Setup completed for ${targets} before a later target failed: ${errorMessage(error)}`
+ );
+ })
+ );
+ completed.push(result);
+ }
+ return completed;
});
diff --git a/ts/packages/cli/test/__utils__/services/test-layer.ts b/ts/packages/cli/test/__utils__/services/test-layer.ts
index cba02a181..595af6936 100644
--- a/ts/packages/cli/test/__utils__/services/test-layer.ts
+++ b/ts/packages/cli/test/__utils__/services/test-layer.ts
@@ -1257,7 +1257,7 @@ export const TestLayer = (input?: TestLiveInput) =>
SetupSkillInstaller,
input?.setupSkillInstaller ??
new SetupSkillInstaller({
- isClaudeSkillInstalled: Effect.succeed(false),
+ isClaudeSkillReady: Effect.succeed(false),
ensureClaudeSkill: Effect.succeed(false),
})
);
diff --git a/ts/packages/cli/test/src/commands/setup.cmd.test.ts b/ts/packages/cli/test/src/commands/setup.cmd.test.ts
index df980b911..c4bbc4b92 100644
--- a/ts/packages/cli/test/src/commands/setup.cmd.test.ts
+++ b/ts/packages/cli/test/src/commands/setup.cmd.test.ts
@@ -1,10 +1,10 @@
import { Command, CommandExecutor } from '@effect/platform';
import { describe, expect, layer } from '@effect/vitest';
-import { Effect, Exit } from 'effect';
+import { Cause, Effect, Exit, Fiber, TestClock } from 'effect';
import { afterEach, vi } from 'vitest';
import { CommandRunner } from 'src/services/command-runner';
import { SetupSkillInstaller } from 'src/services/setup-skill-installer';
-import { cli, MockConsole, TestLive } from 'test/__utils__';
+import { cli, TestLive } from 'test/__utils__';
type AgentHost = 'claude' | 'codex';
type MarketplaceState = 'missing' | 'canonical' | 'conflict';
@@ -14,8 +14,55 @@ interface FakeHostState {
available: boolean;
marketplace: MarketplaceState;
plugin: PluginState;
+ pluginScope: 'user' | 'project';
}
+interface HostOutputFormatter {
+ readonly version: string;
+ readonly marketplace: (state: MarketplaceState, source: string) => unknown;
+ readonly plugin: (installed: boolean, enabled: boolean, scope: 'user' | 'project') => unknown;
+}
+
+const MARKETPLACE_SOURCES: Readonly<Record<AgentHost, string>> = {
+ claude: 'https://github.com/ComposioHQ/composio-plugin-cc.git',
+ codex: 'ComposioHQ/composio-plugin-openai',
+};
+
+const HOST_OUTPUT_FORMATTERS: Readonly<Record<AgentHost, HostOutputFormatter>> = {
+ claude: {
+ version: '2.1.0',
+ marketplace: (state, source) => {
+ if (state === 'missing') return [];
+ return [{ name: 'composio', source: { source: 'github', repo: source } }];
+ },
+ plugin: (installed, enabled, scope) => {
+ if (!installed) return [];
+ return [{ id: 'composio@composio', scope, enabled }];
+ },
+ },
+ codex: {
+ version: 'codex-cli 0.144.1',
+ marketplace: (state, source) => {
+ if (state === 'missing') return { marketplaces: [] };
+ return {
+ marketplaces: [
+ {
+ name: 'composio',
+ marketplaceSource: { sourceType: 'git', source },
+ },
+ ],
+ };
+ },
+ plugin: (installed, enabled) => {
+ if (!installed) return { installed: [], available: [] };
+ return {
+ installed: [{ pluginId: 'composio@composio', installed, enabled }],
+ available: [],
+ };
+ },
+ },
+};
+
const commandParts = (command: Command.Command): ReadonlyArray<string> => {
const first = Command.flatten(command)[0];
return [first.command, ...first.args];
@@ -42,15 +89,17 @@ const makeRunner = (
const makeSkillInstaller = (initiallyReady = false, failInstall = false) => {
let ready = initiallyReady;
+ const ensureClaudeSkill = () => {
+ if (failInstall) return Effect.fail(new Error('skill download failed'));
+ return Effect.sync(() => {
+ const changed = !ready;
+ ready = true;
+ return changed;
+ });
+ };
return new SetupSkillInstaller({
- isClaudeSkillInstalled: Effect.sync(() => ready),
- ensureClaudeSkill: failInstall
- ? Effect.fail(new Error('skill download failed'))
- : Effect.sync(() => {
- const changed = !ready;
- ready = true;
- return changed;
- }),
+ isClaudeSkillReady: Effect.sync(() => ready),
+ ensureClaudeSkill: ensureClaudeSkill(),
});
};
@@ -58,11 +107,17 @@ const defaultHostState = (): FakeHostState => ({
available: false,
marketplace: 'missing',
plugin: 'missing',
+ pluginScope: 'user',
});
const makeFakeHosts = (
initial: Partial<Record<AgentHost, Partial<FakeHostState>>>,
- options: { readonly noOp?: boolean; readonly failOn?: string } = {}
+ options: {
+ readonly noOp?: boolean;
+ readonly failOn?: string;
+ readonly malformedOn?: string;
+ readonly marketplaceSource?: Partial<Record<AgentHost, string>>;
+ } = {}
) => {
const state: Record<AgentHost, FakeHostState> = {
claude: { ...defaultHostState(), ...initial.claude },
@@ -72,40 +127,20 @@ const makeFakeHosts = (
const marketplaceOutput = (host: AgentHost): string => {
const current = state[host].marketplace;
- const source =
- current === 'canonical'
- ? host === 'claude'
- ? 'https://github.com/ComposioHQ/composio-plugin-cc.git'
- : 'ComposioHQ/composio-plugin-openai'
- : 'someone-else/not-composio';
- if (host === 'claude') {
- return current === 'missing'
- ? '[]'
- : JSON.stringify([{ name: 'composio', source: { source: 'github', repo: source } }]);
+ let source = 'someone-else/not-composio';
+ if (current === 'canonical') {
+ source = options.marketplaceSource?.[host] ?? MARKETPLACE_SOURCES[host];
}
- return JSON.stringify({
- marketplaces:
- current === 'missing'
- ? []
- : [
- {
- name: 'composio',
- marketplaceSource: { sourceType: 'git', source },
- },
- ],
- });
+ return JSON.stringify(HOST_OUTPUT_FORMATTERS[host].marketplace(current, source));
};
const pluginOutput = (host: AgentHost): string => {
const current = state[host].plugin;
const installed = current !== 'missing';
const enabled = current === 'enabled';
- return host === 'claude'
- ? JSON.stringify(installed ? [{ id: 'composio@composio', installed, enabled }] : [])
- : JSON.stringify({
- installed: installed ? [{ pluginId: 'composio@composio', installed, enabled }] : [],
- available: [],
- });
+ return JSON.stringify(
+ HOST_OUTPUT_FORMATTERS[host].plugin(installed, enabled, state[host].pluginScope)
+ );
};
const runner = makeRunner(parts => {
@@ -113,9 +148,14 @@ const makeFakeHosts = (
const host = parts[0] as AgentHost;
const command = parts.join(' ');
if (parts[1] === '--version') {
- return state[host].available
- ? { stdout: host === 'claude' ? '2.1.0' : 'codex-cli 0.144.1' }
- : { exitCode: 127, stderr: 'not found' };
+ if (!state[host].available) return { exitCode: 127, stderr: 'not found' };
+ return { stdout: HOST_OUTPUT_FORMATTERS[host].version };
+ }
+ if (options.failOn && command.includes(options.failOn)) {
+ return { exitCode: 2, stderr: 'native operation failed' };
+ }
+ if (options.malformedOn && command.includes(options.malformedOn)) {
+ return { stdout: '{not-json' };
}
if (command === `${host} plugin marketplace list --json`) {
return { stdout: marketplaceOutput(host) };
@@ -123,9 +163,6 @@ const makeFakeHosts = (
if (command === `${host} plugin list --json`) {
return { stdout: pluginOutput(host) };
}
- if (options.failOn && command.includes(options.failOn)) {
- return { exitCode: 2, stderr: 'native operation failed' };
- }
if (!options.noOp && command.includes('plugin marketplace add')) {
state[host].marketplace = 'canonical';
}
@@ -136,6 +173,7 @@ const makeFakeHosts = (
command === 'codex plugin add composio@composio --json')
) {
state[host].plugin = 'enabled';
+ state[host].pluginScope = 'user';
}
return {};
});
@@ -183,7 +221,6 @@ describe('CLI: composio setup', () => {
marketplace: 'canonical',
plugin: 'enabled',
});
- expect((yield* MockConsole.getLines()).join('\n')).toContain('"success":true');
})
);
});
@@ -197,9 +234,6 @@ describe('CLI: composio setup', () => {
yield* cli(['setup', '--target', 'codex', '--yes']);
expect(existingCodex.commands.some(parts => parts.includes('add'))).toBe(false);
- const output = (yield* MockConsole.getLines()).join('\n');
- expect(output).toContain('"changed":false');
- expect(output).toContain('"success":true');
})
);
});
@@ -219,7 +253,16 @@ describe('CLI: composio setup', () => {
yield* cli(['setup', '--target', host, '--yes']);
expect(disabled.state[host].plugin).toBe('enabled');
- expect((yield* MockConsole.getLines()).join('\n')).toContain('"plugin_enabled":true');
+ if (host === 'claude') {
+ expect(disabled.commands).toContainEqual([
+ 'claude',
+ 'plugin',
+ 'enable',
+ 'composio@composio',
+ '--scope',
+ 'user',
+ ]);
+ }
})
);
});
@@ -261,9 +304,10 @@ describe('CLI: composio setup', () => {
Effect.gen(function* () {
yield* cli(['setup', '--target', 'auto', '--yes']);
- const output = (yield* MockConsole.getLines()).join('\n');
- expect(output).toContain('"target":"claude"');
- expect(output).not.toContain('"target":"codex"');
+ expect(autoClaude.commands.some(parts => parts[0] === 'claude')).toBe(true);
+ expect(
+ autoClaude.commands.some(parts => parts[0] === 'codex' && parts[1] !== '--version')
+ ).toBe(false);
})
);
});
@@ -282,9 +326,90 @@ describe('CLI: composio setup', () => {
Effect.gen(function* () {
yield* cli(['setup', '--target', 'auto', '--yes']);
- const output = (yield* MockConsole.getLines()).join('\n');
- expect(output).toContain('"target":"claude"');
- expect(output).toContain('"target":"codex"');
+ expect(autoBoth.commands.some(parts => parts[0] === 'claude')).toBe(true);
+ expect(autoBoth.commands.some(parts => parts[0] === 'codex')).toBe(true);
+ })
+ );
+ });
+
+ const allTargets = makeFakeHosts({
+ claude: { available: true },
+ codex: { available: true },
+ });
+ layer(
+ TestLive({
+ commandRunner: allTargets.runner,
+ setupSkillInstaller: makeSkillInstaller(),
+ })
+ )('explicit all-host setup', it => {
+ it.scoped('configures both supported hosts', () =>
+ Effect.gen(function* () {
+ yield* cli(['setup', '--target', 'all', '--yes']);
+
+ expect(allTargets.state.claude).toMatchObject({
+ marketplace: 'canonical',
+ plugin: 'enabled',
+ });
+ expect(allTargets.state.codex).toMatchObject({
+ marketplace: 'canonical',
+ plugin: 'enabled',
+ });
+ })
+ );
+ });
+
+ const projectScopedClaude = makeFakeHosts({
+ claude: {
+ available: true,
+ marketplace: 'canonical',
+ plugin: 'enabled',
+ pluginScope: 'project',
+ },
+ });
+ layer(
+ TestLive({
+ commandRunner: projectScopedClaude.runner,
+ setupSkillInstaller: makeSkillInstaller(true),
+ })
+ )('project-scoped Claude plugin', it => {
+ it.scoped('installs the required user-scoped plugin', () =>
+ Effect.gen(function* () {
+ yield* cli(['setup', '--target', 'claude', '--yes']);
+
+ expect(projectScopedClaude.commands).toContainEqual([
+ 'claude',
+ 'plugin',
+ 'install',
+ 'composio@composio',
+ '--scope',
+ 'user',
+ ]);
+ expect(projectScopedClaude.state.claude.pluginScope).toBe('user');
+ })
+ );
+ });
+
+ const missingMarketplaceWithPlugin = makeFakeHosts({
+ claude: { available: true, marketplace: 'missing', plugin: 'enabled' },
+ });
+ layer(
+ TestLive({
+ commandRunner: missingMarketplaceWithPlugin.runner,
+ setupSkillInstaller: makeSkillInstaller(true),
+ })
+ )('plugin from a removed marketplace', it => {
+ it.scoped('reinstalls after restoring the canonical marketplace', () =>
+ Effect.gen(function* () {
+ yield* cli(['setup', '--target', 'claude', '--yes']);
+
+ expect(missingMarketplaceWithPlugin.commands).toContainEqual([
+ 'claude',
+ 'plugin',
+ 'install',
+ 'composio@composio',
+ '--scope',
+ 'user',
+ ]);
})
);
});
@@ -312,6 +437,157 @@ describe('CLI: composio setup', () => {
);
});
+ for (const unsafeSource of [
+ 'http://github.com/ComposioHQ/composio-plugin-cc.git',
+ 'https://[email protected]/ComposioHQ/composio-plugin-cc.git',
+ 'https://github.com/ComposioHQ/composio-plugin-cc.git?token=secret',
+ ]) {
+ const unsafeMarketplace = makeFakeHosts(
+ { claude: { available: true, marketplace: 'canonical' } },
+ { marketplaceSource: { claude: unsafeSource } }
+ );
+ layer(TestLive({ commandRunner: unsafeMarketplace.runner }))(
+ `unsafe marketplace source: ${unsafeSource}`,
+ it => {
+ it.scoped('rejects a non-canonical GitHub URL', () =>
+ Effect.gen(function* () {
+ const exit = yield* Effect.exit(cli(['setup', '--target', 'claude', '--yes']));
+
+ expect(Exit.isFailure(exit)).toBe(true);
+ expect(
+ unsafeMarketplace.commands.some(parts =>
+ ['add', 'install', 'enable'].some(operation => parts.includes(operation))
+ )
+ ).toBe(false);
+ })
+ );
+ }
+ );
+ }
+
+ const failedInspection = makeFakeHosts(
+ { claude: { available: true } },
+ { failOn: 'plugin list --json' }
+ );
+ layer(TestLive({ commandRunner: failedInspection.runner }))('failed native inspection', it => {
+ it.scoped('fails before running setup mutations', () =>
+ Effect.gen(function* () {
+ const exit = yield* Effect.exit(cli(['setup', '--target', 'claude', '--yes']));
+
+ expect(Exit.isFailure(exit)).toBe(true);
+ expect(
+ failedInspection.commands.some(parts =>
+ ['add', 'install', 'enable'].some(operation => parts.includes(operation))
+ )
+ ).toBe(false);
+ })
+ );
+ });
+
+ const malformedInspection = makeFakeHosts(
+ { codex: { available: true } },
+ { malformedOn: 'plugin marketplace list --json' }
+ );
+ layer(TestLive({ commandRunner: malformedInspection.runner }))(
+ 'malformed native inspection',
+ it => {
+ it.scoped('fails before running setup mutations', () =>
+ Effect.gen(function* () {
+ const exit = yield* Effect.exit(cli(['setup', '--target', 'codex', '--yes']));
+
+ expect(Exit.isFailure(exit)).toBe(true);
+ expect(malformedInspection.commands.some(parts => parts.includes('add'))).toBe(false);
+ })
+ );
+ }
+ );
+
+ const preflightConflict = makeFakeHosts({
+ claude: { available: true },
+ codex: { available: true, marketplace: 'conflict' },
+ });
+ layer(
+ TestLive({
+ commandRunner: preflightConflict.runner,
+ setupSkillInstaller: makeSkillInstaller(),
+ })
+ )('multi-host preflight', it => {
+ it.scoped('does not mutate an earlier host when a later host conflicts', () =>
+ Effect.gen(function* () {
+ const exit = yield* Effect.exit(cli(['setup', '--target', 'all', '--yes']));
+
+ expect(Exit.isFailure(exit)).toBe(true);
+ expect(preflightConflict.state.claude).toMatchObject({
+ marketplace: 'missing',
+ plugin: 'missing',
+ });
+ })
+ );
+ });
+
+ const laterMutationFailure = makeFakeHosts(
+ {
+ claude: { available: true },
+ codex: { available: true },
+ },
+ { failOn: 'codex plugin add composio@composio --json' }
+ );
+ layer(
+ TestLive({
+ commandRunner: laterMutationFailure.runner,
+ setupSkillInstaller: makeSkillInstaller(),
+ })
+ )('multi-host mutation failure', it => {
+ it.scoped('reports hosts completed before a later target fails', () =>
+ Effect.gen(function* () {
+ const exit = yield* Effect.exit(cli(['setup', '--target', 'all', '--yes']));
+
+ expect(Exit.isFailure(exit)).toBe(true);
+ if (Exit.isFailure(exit)) {
+ expect(Cause.pretty(exit.cause)).toContain(
+ 'Setup completed for claude before a later target failed'
+ );
+ }
+ expect(laterMutationFailure.state.claude).toMatchObject({
+ marketplace: 'canonical',
+ plugin: 'enabled',
+ });
+ })
+ );
+ });
+
+ const nonInteractive = makeFakeHosts({ claude: { available: true } });
+ layer(TestLive({ commandRunner: nonInteractive.runner }))('non-interactive approval', it => {
+ it.scoped('requires --yes before inspecting or 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);
+ })
+ );
+ });
+
+ const hangingRunner = new CommandRunner({
+ run: () => Effect.succeed(CommandExecutor.ExitCode(0)),
+ capture: () => Effect.never,
+ });
+ layer(TestLive({ commandRunner: hangingRunner }))('hung native host', it => {
+ it.scoped('times out instead of blocking setup forever', () =>
+ Effect.gen(function* () {
+ const fiber = yield* cli(['setup', '--target', 'claude', '--yes']).pipe(
+ Effect.exit,
+ Effect.fork
+ );
+ yield* Effect.yieldNow();
+ yield* TestClock.adjust('2 minutes');
+ const exit = yield* Fiber.join(fiber);
+
+ expect(Exit.isFailure(exit)).toBe(true);
+ })
+ );
+ });
+
const noOp = makeFakeHosts({ claude: { available: true } }, { noOp: true });
layer(TestLive({ commandRunner: noOp.runner, setupSkillInstaller: makeSkillInstaller() }))(
'post-install verification',
diff --git a/ts/packages/cli/test/src/services/setup-skill-installer.test.ts b/ts/packages/cli/test/src/services/setup-skill-installer.test.ts
index 9afd09055..15f49838f 100644
--- a/ts/packages/cli/test/src/services/setup-skill-installer.test.ts
+++ b/ts/packages/cli/test/src/services/setup-skill-installer.test.ts
@@ -1,4 +1,4 @@
-import { mkdirSync, writeFileSync } from 'node:fs';
+import { mkdirSync, symlinkSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import { describe, expect, it } from 'vitest';
import * as tempy from 'tempy';
@@ -29,12 +29,14 @@ describe('SetupSkillInstaller', () => {
const home = tempy.temporaryDirectory();
const target = path.join(home, '.claude', 'skills', 'composio-cli');
const skillDir = path.join(home, '.agents', 'skills', 'composio-cli');
- mkdirSync(target, { recursive: true });
mkdirSync(skillDir, { recursive: true });
+ mkdirSync(path.dirname(target), { recursive: true });
+ symlinkSync(path.relative(path.dirname(target), skillDir), target);
writeFileSync(
path.join(skillDir, SKILL_RELEASE_TAG_FILENAME),
'@composio/[email protected]\n'
);
+ writeFileSync(path.join(skillDir, 'SKILL.md'), '# composio-cli\n');
expect(isClaudeSkillCurrent(home, '@composio/[email protected]')).toBe(true);
expect(isClaudeSkillCurrent(home, '@composio/[email protected]')).toBe(false);
@@ -46,4 +48,13 @@ describe('SetupSkillInstaller', () => {
expect(isClaudeSkillCurrent(home, '@composio/[email protected]')).toBe(false);
});
+
+ it('treats a release marker without a readable skill as stale', () => {
+ const home = tempy.temporaryDirectory();
+ const target = path.join(home, '.claude', 'skills', 'composio-cli');
+ mkdirSync(target, { recursive: true });
+ writeFileSync(path.join(target, SKILL_RELEASE_TAG_FILENAME), '@composio/[email protected]\n');
+
+ expect(isClaudeSkillCurrent(home, '@composio/[email protected]')).toBe(false);
+ });
});