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
Co-authored-by: Kshitij Jhunjhunwala <kj@composio.dev>
jkomyno committed
Jul 14, 2026 at 15:51 UTC
42db6d13e199b623de115b5c084db29cbd98dba1
9 files changed
+670
-253
ts/e2e-tests/cli/setup-plugins/e2e.test.ts
+18
-22
@@ -17,14 +17,22 @@ cp fixtures/fake-agent-host.sh /tmp/bin/${host}
17
chmod +x /tmp/bin/${host}
18
${
19
host === 'claude'
20
- ? `mkdir -p /tmp/.claude/skills/composio-cli /tmp/.agents/skills/composio-cli
21
-printf '@composio/cli@%s\n' "$(composio --version)" > /tmp/.agents/skills/composio-cli/.composio-release-tag`
20
+ ? `mkdir -p /tmp/.claude/skills /tmp/.agents/skills/composio-cli
21
+printf '%s\n' '# composio-cli' > /tmp/.agents/skills/composio-cli/SKILL.md
22
+printf '@composio/cli@%s\n' "$(composio --version)" > /tmp/.agents/skills/composio-cli/.composio-release-tag
23
+ln -s ../../.agents/skills/composio-cli /tmp/.claude/skills/composio-cli`
24
: ''
25
}
26
export HOST_STATE_DIR=/tmp/host-state
27
export PATH=/tmp/bin:$PATH
26
-composio setup --target ${host} --yes > first.json
27
-composio setup --target ${host} --yes > second.json
28
+composio setup --target ${host} --yes
29
+composio setup --target ${host} --yes
30
+${
31
+ host === 'claude'
32
+ ? `test -L /tmp/.claude/skills/composio-cli
33
+test -r /tmp/.claude/skills/composio-cli/SKILL.md`
34
+ : ''
35
+}
36
cp /tmp/host-state/commands.log commands.log
37
`;
38
@@ -33,8 +41,8 @@ e2e(import.meta.url, {
41
cli: ['current'],
42
},
43
defineTests: ({ runCmd }) => {
36
- let claude: E2ETestResultWithFiles<'first.json' | 'second.json' | 'commands.log'>;
37
- let codex: E2ETestResultWithFiles<'first.json' | 'second.json' | 'commands.log'>;
44
+ let claude: E2ETestResultWithFiles<'commands.log'>;
45
+ let codex: E2ETestResultWithFiles<'commands.log'>;
46
let unavailable: E2ETestResult;
47
48
beforeAll(async () => {
@@ -42,11 +50,11 @@ e2e(import.meta.url, {
50
// these fresh-container cases sequential to avoid same-millisecond names.
51
claude = await runCmd({
52
command: setupFixture('claude'),
45
- files: ['first.json', 'second.json', 'commands.log'],
53
+ files: ['commands.log'],
54
});
55
codex = await runCmd({
56
command: setupFixture('codex'),
49
- files: ['first.json', 'second.json', 'commands.log'],
57
+ files: ['commands.log'],
58
});
59
unavailable = await runCmd('composio setup --target auto --yes');
60
}, TIMEOUTS.FIXTURE);
@@ -66,25 +74,13 @@ e2e(import.meta.url, {
74
'codex plugin marketplace add https://github.com/ComposioHQ/composio-plugin-openai.git --json',
75
installCommand: 'codex plugin add composio@composio --json',
76
},
69
- ])('$host setup', ({ host, result, marketplaceCommand, installCommand }) => {
70
- it('installs once, is idempotent, and reports ready status', () => {
77
+ ])('$host setup', ({ result, marketplaceCommand, installCommand }) => {
78
+ it('installs once and is idempotent', () => {
79
const execution = result();
80
expect(execution.exitCode).toBe(0);
81
expect(execution.stdout).toBe('');
82
expect(execution.stderr).toBe('');
83
76
- const first = JSON.parse(execution.files['first.json']) as {
77
- success: boolean;
78
- targets: Array<{ target: string; changed: boolean; cli_skill_ready: boolean }>;
79
- };
80
- const second = JSON.parse(execution.files['second.json']) as typeof first;
81
- expect(first.success).toBe(true);
82
- expect(first.targets).toContainEqual(
83
- expect.objectContaining({ target: host, changed: true, cli_skill_ready: true })
84
- );
85
- expect(second.targets).toContainEqual(
86
- expect.objectContaining({ target: host, changed: false, cli_skill_ready: true })
87
- );
84
const commands = execution.files['commands.log'].trim().split('\n');
85
expect(commands.filter(command => command === marketplaceCommand)).toHaveLength(1);
86
expect(commands.filter(command => command === installCommand)).toHaveLength(1);
ts/e2e-tests/cli/setup-plugins/fixtures/fake-agent-host.sh
+2
-2
@@ -21,7 +21,7 @@ case "$host:$command" in
21
;;
22
"claude:plugin list --json")
23
if [ -f "$state_dir/claude-plugin" ]; then
24
- printf '%s\n' '[{"id":"composio@composio","installed":true,"enabled":true}]'
24
+ printf '%s\n' '[{"id":"composio@composio","scope":"user","enabled":true}]'
25
else
26
printf '%s\n' '[]'
27
fi
@@ -32,7 +32,7 @@ case "$host:$command" in
32
"claude:plugin install composio@composio --scope user")
33
touch "$state_dir/claude-plugin"
34
;;
35
- "claude:plugin enable composio@composio")
35
+ "claude:plugin enable composio@composio --scope user")
36
touch "$state_dir/claude-plugin"
37
;;
38
"codex:--version")
ts/packages/cli/src/commands/setup.cmd.ts
+18
-16
@@ -7,6 +7,7 @@ import {
7
type SetupTarget,
8
} from 'src/services/setup';
9
import { TerminalUI } from 'src/services/terminal-ui';
10
+import { isInteractiveTerminal } from 'src/utils/stdio';
11
12
const target = Options.choice('target', SETUP_TARGETS).pipe(
13
Options.withDefault('auto' as SetupTarget),
@@ -24,6 +25,12 @@ const setupBaseCmd = Command.make('setup', { target, yes }, ({ target, yes }) =>
25
const ui = yield* TerminalUI;
26
yield* ui.intro('composio setup');
27
28
+ if (!yes && !isInteractiveTerminal()) {
29
+ return yield* Effect.fail(
30
+ new Error('Non-interactive setup requires `--yes` to approve local changes.')
31
+ );
32
+ }
33
+
34
const targets = yield* resolveSetupTargets(target);
35
if (!yes) {
36
const confirmed = yield* ui.confirm(`Install Composio for ${targets.join(' and ')}?`, {
@@ -37,26 +44,21 @@ const setupBaseCmd = Command.make('setup', { target, yes }, ({ target, yes }) =>
44
45
const results = yield* installSetupTargets(targets);
46
for (const result of results) {
40
- yield* ui.log.success(
41
- result.plugin_changed
42
- ? `Configured and enabled the Composio plugin for ${result.target}.`
43
- : `The Composio plugin for ${result.target} is already installed and enabled.`
44
- );
45
- if (result.target === 'claude') {
46
- if (!result.skill_changed) {
47
- yield* ui.log.success('The composio-cli skill for Claude Code is already installed.');
48
- }
49
- } else {
47
+ let pluginMessage = `The Composio plugin for ${result.target} is already installed and enabled.`;
48
+ if (result.plugin_changed) {
49
+ pluginMessage = `Configured and enabled the Composio plugin for ${result.target}.`;
50
+ }
51
+ yield* ui.log.success(pluginMessage);
52
+
53
+ if (result.target === 'codex') {
54
yield* ui.log.success('The Codex plugin includes the composio-cli skill.');
55
+ continue;
56
+ }
57
+ if (!result.skill_changed) {
58
+ yield* ui.log.success('The composio-cli skill for Claude Code is already installed.');
59
}
60
}
61
54
- yield* ui.output(
55
- JSON.stringify({
56
- success: true,
57
- targets: results,
58
- })
59
- );
62
yield* ui.outro('Composio setup complete.');
63
})
64
);
ts/packages/cli/src/services/command-runner.ts
+2
-2
@@ -1,5 +1,5 @@
1
import { Command } from '@effect/platform';
2
-import { Effect, Stream } from 'effect';
2
+import { Effect, Stream, String } from 'effect';
3
4
export interface CommandResult {
5
readonly exitCode: number;
@@ -8,7 +8,7 @@ export interface CommandResult {
8
}
9
10
const collectText = (stream: Stream.Stream<Uint8Array, unknown>) =>
11
- Stream.runFold(stream, '', (output, chunk) => output + new TextDecoder().decode(chunk));
11
+ stream.pipe(Stream.decodeText(), Stream.runFold(String.empty, String.concat));
12
13
export class CommandRunner extends Effect.Service<CommandRunner>()('services/CommandRunner', {
14
sync: () => ({
ts/packages/cli/src/services/setup-skill-installer.ts
+17
-6
@@ -1,7 +1,12 @@
1
-import { Effect } from 'effect';
1
import fs from 'node:fs';
2
import path from 'node:path';
4
-import { installSkill, readInstalledSkillReleaseTag } from 'src/effects/install-skill';
3
+import { Effect } from 'effect';
4
+import {
5
+ installSkill,
6
+ readInstalledSkillReleaseTag,
7
+ resolveInstalledSkillName,
8
+ resolveTargetSkillPath,
9
+} from 'src/effects/install-skill';
10
import { APP_VERSION } from 'src/constants';
11
import { readInstalledReleaseTag } from 'src/services/run-companion-modules';
12
import { NodeOs } from './node-os';
@@ -12,16 +17,22 @@ export const resolveSetupSkillReleaseTag = (
17
): string => readInstalledReleaseTag(execPath) ?? `@composio/cli@${fallbackVersion}`;
18
19
export const isClaudeSkillCurrent = (home: string, releaseTag: string): boolean => {
15
- const target = path.join(home, '.claude', 'skills', 'composio-cli');
16
- const skillDir = path.join(home, '.agents', 'skills', 'composio-cli');
17
- return fs.existsSync(target) && readInstalledSkillReleaseTag(skillDir) === releaseTag;
20
+ const skillName = resolveInstalledSkillName();
21
+ const target = resolveTargetSkillPath({ home, skillName, target: 'claude' });
22
+ if (readInstalledSkillReleaseTag(target) !== releaseTag) return false;
23
+ try {
24
+ fs.readFileSync(path.join(target, 'SKILL.md'), 'utf8');
25
+ return true;
26
+ } catch {
27
+ return false;
28
+ }
29
};
30
31
export class SetupSkillInstaller extends Effect.Service<SetupSkillInstaller>()(
32
'services/SetupSkillInstaller',
33
{
34
sync: () => ({
24
- isClaudeSkillInstalled: Effect.gen(function* () {
35
+ isClaudeSkillReady: Effect.gen(function* () {
36
const os = yield* NodeOs;
37
return isClaudeSkillCurrent(os.homedir, resolveSetupSkillReleaseTag());
38
}),
ts/packages/cli/src/services/setup.ts
+268
-147
@@ -7,19 +7,19 @@ export const SETUP_TARGETS = ['auto', 'claude', 'codex', 'all'] as const;
7
export type SetupTarget = (typeof SETUP_TARGETS)[number];
8
export type AgentHost = Exclude<SetupTarget, 'auto' | 'all'>;
9
10
-export const CLAUDE_PLUGIN_MARKETPLACE = {
10
+const CLAUDE_PLUGIN_MARKETPLACE = {
11
name: 'composio',
12
source: 'https://github.com/ComposioHQ/composio-plugin-cc.git',
13
plugin: 'composio@composio',
14
} as const;
15
16
-export const CODEX_PLUGIN_MARKETPLACE = {
16
+const CODEX_PLUGIN_MARKETPLACE = {
17
name: 'composio',
18
source: 'https://github.com/ComposioHQ/composio-plugin-openai.git',
19
plugin: 'composio@composio',
20
} as const;
21
22
-export interface SetupTargetStatus {
22
+interface SetupTargetStatus {
23
readonly target: AgentHost;
24
readonly available: boolean;
25
readonly marketplace_configured: boolean;
@@ -29,7 +29,7 @@ export interface SetupTargetStatus {
29
readonly cli_skill_ready: boolean;
30
}
31
32
-export interface SetupTargetResult extends SetupTargetStatus {
32
+interface SetupTargetResult extends SetupTargetStatus {
33
readonly changed: boolean;
34
readonly plugin_changed: boolean;
35
readonly skill_changed: boolean;
@@ -44,48 +44,65 @@ interface SetupTargetAdapter {
44
readonly marketplaceAddArgs: ReadonlyArray<string>;
45
readonly pluginInstallArgs: ReadonlyArray<string>;
46
readonly pluginEnableArgs: ReadonlyArray<string>;
47
+ readonly marketplaceRecordsKey?: string;
48
+ readonly pluginRecordsKey?: string;
49
+ readonly pluginScope?: string;
50
+ readonly marketplaceRemoveCommand: string;
51
+ readonly skillSource: 'bundled' | 'standalone';
52
}
53
54
interface InspectedSetupTarget extends SetupTargetStatus {
55
readonly marketplace_conflict: boolean;
56
}
57
53
-const CLAUDE_ADAPTER: SetupTargetAdapter = {
54
- target: 'claude',
55
- executable: 'claude',
56
- marketplace: CLAUDE_PLUGIN_MARKETPLACE,
57
- marketplaceListArgs: ['plugin', 'marketplace', 'list', '--json'],
58
- pluginListArgs: ['plugin', 'list', '--json'],
59
- marketplaceAddArgs: [
60
- 'plugin',
61
- 'marketplace',
62
- 'add',
63
- CLAUDE_PLUGIN_MARKETPLACE.source,
64
- '--scope',
65
- 'user',
66
- ],
67
- pluginInstallArgs: ['plugin', 'install', CLAUDE_PLUGIN_MARKETPLACE.plugin, '--scope', 'user'],
68
- pluginEnableArgs: ['plugin', 'enable', CLAUDE_PLUGIN_MARKETPLACE.plugin],
58
+const ADAPTERS: Readonly<Record<AgentHost, SetupTargetAdapter>> = {
59
+ claude: {
60
+ target: 'claude',
61
+ executable: 'claude',
62
+ marketplace: CLAUDE_PLUGIN_MARKETPLACE,
63
+ marketplaceListArgs: ['plugin', 'marketplace', 'list', '--json'],
64
+ pluginListArgs: ['plugin', 'list', '--json'],
65
+ marketplaceAddArgs: [
66
+ 'plugin',
67
+ 'marketplace',
68
+ 'add',
69
+ CLAUDE_PLUGIN_MARKETPLACE.source,
70
+ '--scope',
71
+ 'user',
72
+ ],
73
+ pluginInstallArgs: ['plugin', 'install', CLAUDE_PLUGIN_MARKETPLACE.plugin, '--scope', 'user'],
74
+ pluginEnableArgs: ['plugin', 'enable', CLAUDE_PLUGIN_MARKETPLACE.plugin, '--scope', 'user'],
75
+ pluginScope: 'user',
76
+ marketplaceRemoveCommand: 'claude plugin marketplace remove composio --scope user',
77
+ skillSource: 'standalone',
78
+ },
79
+ codex: {
80
+ target: 'codex',
81
+ executable: 'codex',
82
+ marketplace: CODEX_PLUGIN_MARKETPLACE,
83
+ marketplaceListArgs: ['plugin', 'marketplace', 'list', '--json'],
84
+ pluginListArgs: ['plugin', 'list', '--json'],
85
+ marketplaceAddArgs: ['plugin', 'marketplace', 'add', CODEX_PLUGIN_MARKETPLACE.source, '--json'],
86
+ pluginInstallArgs: ['plugin', 'add', CODEX_PLUGIN_MARKETPLACE.plugin, '--json'],
87
+ // Codex has no separate enable command. Re-adding is its native install/repair path.
88
+ pluginEnableArgs: ['plugin', 'add', CODEX_PLUGIN_MARKETPLACE.plugin, '--json'],
89
+ marketplaceRecordsKey: 'marketplaces',
90
+ pluginRecordsKey: 'installed',
91
+ marketplaceRemoveCommand: 'codex plugin marketplace remove composio --json',
92
+ skillSource: 'bundled',
93
+ },
94
};
95
71
-const CODEX_ADAPTER: SetupTargetAdapter = {
72
- target: 'codex',
73
- executable: 'codex',
74
- marketplace: CODEX_PLUGIN_MARKETPLACE,
75
- marketplaceListArgs: ['plugin', 'marketplace', 'list', '--json'],
76
- pluginListArgs: ['plugin', 'list', '--json'],
77
- marketplaceAddArgs: ['plugin', 'marketplace', 'add', CODEX_PLUGIN_MARKETPLACE.source, '--json'],
78
- pluginInstallArgs: ['plugin', 'add', CODEX_PLUGIN_MARKETPLACE.plugin, '--json'],
79
- // Codex has no separate enable command. Re-adding is its native install/repair path.
80
- pluginEnableArgs: ['plugin', 'add', CODEX_PLUGIN_MARKETPLACE.plugin, '--json'],
81
-};
96
+const ADAPTER_LIST = Object.values(ADAPTERS);
97
+const SETUP_COMMAND_TIMEOUT = '2 minutes';
98
83
-const ADAPTERS: ReadonlyArray<SetupTargetAdapter> = [CLAUDE_ADAPTER, CODEX_ADAPTER];
99
+const asRecord = (value: unknown): Record<string, unknown> | undefined => {
100
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) return undefined;
101
+ return value as Record<string, unknown>;
102
+};
103
85
-const asRecord = (value: unknown): Record<string, unknown> | undefined =>
86
- value !== null && typeof value === 'object' && !Array.isArray(value)
87
- ? (value as Record<string, unknown>)
88
- : undefined;
104
+const isRecord = (value: unknown): value is Record<string, unknown> =>
105
+ asRecord(value) !== undefined;
106
107
const parseJson = (value: string): unknown => {
108
try {
@@ -95,14 +112,34 @@ const parseJson = (value: string): unknown => {
112
}
113
};
114
98
-const recordsFrom = (value: unknown, key?: string): ReadonlyArray<Record<string, unknown>> => {
99
- const selected = key ? asRecord(value)?.[key] : value;
100
- return Array.isArray(selected)
101
- ? selected.flatMap(item => {
102
- const record = asRecord(item);
103
- return record ? [record] : [];
104
- })
105
- : [];
115
+const recordsFrom = (
116
+ value: unknown,
117
+ key?: string
118
+): ReadonlyArray<Record<string, unknown>> | undefined => {
119
+ let selected = value;
120
+ if (key) {
121
+ const record = asRecord(value);
122
+ if (!record) return undefined;
123
+ selected = record[key];
124
+ }
125
+ if (!Array.isArray(selected) || !selected.every(isRecord)) return undefined;
126
+ return selected;
127
+};
128
+
129
+const readString = (
130
+ record: Record<string, unknown> | undefined,
131
+ key: string
132
+): string | undefined => {
133
+ const value = record?.[key];
134
+ if (typeof value !== 'string') return undefined;
135
+ return value;
136
+};
137
+
138
+const firstString = (...values: ReadonlyArray<unknown>): string | undefined => {
139
+ for (const value of values) {
140
+ if (typeof value === 'string') return value;
141
+ }
142
+ return undefined;
143
};
144
145
const normalizeGitHubRepository = (value: string): string | undefined => {
@@ -110,13 +147,18 @@ const normalizeGitHubRepository = (value: string): string | undefined => {
147
if (!trimmed) return undefined;
148
149
let repository = trimmed;
113
- const scpStyle = /^git@github\.com:(.+)$/i.exec(repository);
114
- if (scpStyle) {
115
- repository = scpStyle[1] ?? '';
116
- } else if (/^[a-z][a-z0-9+.-]*:\/\//i.test(repository)) {
150
+ if (/^[a-z][a-z0-9+.-]*:\/\//i.test(repository)) {
151
try {
152
const url = new URL(repository);
119
- if (url.hostname.toLowerCase() !== 'github.com') return undefined;
153
+ const isCanonicalGitHubUrl =
154
+ url.protocol === 'https:' &&
155
+ url.hostname.toLowerCase() === 'github.com' &&
156
+ url.port === '' &&
157
+ url.username === '' &&
158
+ url.password === '' &&
159
+ url.search === '' &&
160
+ url.hash === '';
161
+ if (!isCanonicalGitHubUrl) return undefined;
162
repository = url.pathname;
163
} catch {
164
return undefined;
@@ -134,24 +176,22 @@ const normalizeGitHubRepository = (value: string): string | undefined => {
176
const marketplaceState = (
177
adapter: SetupTargetAdapter,
178
output: string
137
-): { readonly configured: boolean; readonly conflicting: boolean } => {
179
+): { readonly configured: boolean; readonly conflicting: boolean } | undefined => {
180
const parsed = parseJson(output);
139
- const records = recordsFrom(parsed, adapter.target === 'codex' ? 'marketplaces' : undefined);
181
+ const records = recordsFrom(parsed, adapter.marketplaceRecordsKey);
182
+ if (!records) return undefined;
183
const expected = normalizeGitHubRepository(adapter.marketplace.source);
184
const sourceMatches = (record: Record<string, unknown>) => {
142
- const repo = typeof record.repo === 'string' ? record.repo : undefined;
143
- const url = typeof record.url === 'string' ? record.url : undefined;
185
const nestedSource = asRecord(record.source);
186
const marketplaceSource = asRecord(record.marketplaceSource);
146
- const source =
147
- (typeof record.source === 'string' ? record.source : undefined) ??
148
- (typeof nestedSource?.repo === 'string' ? nestedSource.repo : undefined) ??
149
- (typeof nestedSource?.source === 'string' ? nestedSource.source : undefined) ??
150
- (typeof marketplaceSource?.source === 'string' ? marketplaceSource.source : undefined);
151
- return [repo, url, source].some(
152
- candidate =>
153
- typeof candidate === 'string' && normalizeGitHubRepository(candidate) === expected
187
+ const source = firstString(
188
+ record.source,
189
+ readString(nestedSource, 'repo'),
190
+ readString(nestedSource, 'source'),
191
+ readString(marketplaceSource, 'source')
192
);
193
+ const candidates = [readString(record, 'repo'), readString(record, 'url'), source];
194
+ return candidates.some(candidate => normalizeGitHubRepository(candidate ?? '') === expected);
195
};
196
const configured = records.some(sourceMatches);
197
const conflicting = records.some(
@@ -163,12 +203,14 @@ const marketplaceState = (
203
const pluginState = (
204
adapter: SetupTargetAdapter,
205
output: string
166
-): { readonly installed: boolean; readonly enabled: boolean } => {
206
+): { readonly installed: boolean; readonly enabled: boolean } | undefined => {
207
const parsed = parseJson(output);
168
- const records = recordsFrom(parsed, adapter.target === 'codex' ? 'installed' : undefined);
208
+ const records = recordsFrom(parsed, adapter.pluginRecordsKey);
209
+ if (!records) return undefined;
210
const plugin = records.find(record => {
211
const id = record.id ?? record.pluginId;
171
- return id === adapter.marketplace.plugin;
212
+ const scopeMatches = !adapter.pluginScope || record.scope === adapter.pluginScope;
213
+ return id === adapter.marketplace.plugin && scopeMatches;
214
});
215
if (!plugin || plugin.installed === false) return { installed: false, enabled: false };
216
return { installed: true, enabled: plugin.enabled !== false };
@@ -177,16 +219,57 @@ const pluginState = (
219
const capture = (executable: string, args: ReadonlyArray<string>) =>
220
Effect.gen(function* () {
221
const runner = yield* CommandRunner;
180
- return yield* runner
181
- .capture(Command.make(executable, ...args))
182
- .pipe(Effect.catchAll(() => Effect.succeed<CommandResult | undefined>(undefined)));
222
+ return yield* runner.capture(Command.make(executable, ...args)).pipe(
223
+ Effect.timeoutFail({
224
+ duration: SETUP_COMMAND_TIMEOUT,
225
+ onTimeout: () => new Error(`${executable} command timed out.`),
226
+ }),
227
+ Effect.catchAll(() => Effect.succeed<CommandResult | undefined>(undefined))
228
+ );
229
});
230
231
+const isAdapterAvailable = (adapter: SetupTargetAdapter) =>
232
+ capture(adapter.executable, ['--version']).pipe(
233
+ Effect.map(result => result !== undefined && result.exitCode === 0)
234
+ );
235
+
236
+const commandFailureSuffix = (result: CommandResult): string => {
237
+ const detail = result.stderr.trim() || result.stdout.trim();
238
+ if (detail) return `: ${detail}`;
239
+ return ` (exit ${result.exitCode})`;
240
+};
241
+
242
+const errorMessage = (error: unknown): string => {
243
+ if (error instanceof Error) return error.message;
244
+ return String(error);
245
+};
246
+
247
+const requireInspection = <T>(
248
+ adapter: SetupTargetAdapter,
249
+ operation: string,
250
+ result: CommandResult | undefined,
251
+ parse: (output: string) => T | undefined
252
+) => {
253
+ if (!result) {
254
+ return Effect.fail(new Error(`Failed to inspect ${adapter.target} ${operation}.`));
255
+ }
256
+ if (result.exitCode !== 0) {
257
+ return Effect.fail(
258
+ new Error(`Failed to inspect ${adapter.target} ${operation}${commandFailureSuffix(result)}.`)
259
+ );
260
+ }
261
+ const inspected = parse(result.stdout);
262
+ if (!inspected) {
263
+ return Effect.fail(new Error(`${adapter.target} returned invalid JSON for ${operation}.`));
264
+ }
265
+ return Effect.succeed(inspected);
266
+};
267
+
268
const inspectAdapter = (adapter: SetupTargetAdapter) =>
269
Effect.gen(function* () {
270
const skillInstaller = yield* SetupSkillInstaller;
188
- const version = yield* capture(adapter.executable, ['--version']);
189
- if (!version || version.exitCode !== 0) {
271
+ const available = yield* isAdapterAvailable(adapter);
272
+ if (!available) {
273
return {
274
target: adapter.target,
275
available: false,
@@ -202,103 +285,115 @@ const inspectAdapter = (adapter: SetupTargetAdapter) =>
285
capture(adapter.executable, adapter.marketplaceListArgs),
286
capture(adapter.executable, adapter.pluginListArgs),
287
]);
205
- const plugin =
206
- plugins && plugins.exitCode === 0
207
- ? pluginState(adapter, plugins.stdout)
208
- : { installed: false, enabled: false };
209
-
288
+ const plugin = yield* requireInspection(adapter, 'plugins', plugins, output =>
289
+ pluginState(adapter, output)
290
+ );
291
const pluginReady = plugin.installed && plugin.enabled;
211
- const marketplace =
212
- marketplaces && marketplaces.exitCode === 0
213
- ? marketplaceState(adapter, marketplaces.stdout)
214
- : { configured: false, conflicting: false };
292
+ const marketplace = yield* requireInspection(adapter, 'marketplaces', marketplaces, output =>
293
+ marketplaceState(adapter, output)
294
+ );
295
+ let cliSkillReady = pluginReady;
296
+ if (adapter.skillSource === 'standalone') {
297
+ cliSkillReady = yield* skillInstaller.isClaudeSkillReady;
298
+ }
299
return {
300
target: adapter.target,
301
available: true,
302
marketplace_configured: marketplace.configured,
303
plugin_installed: plugin.installed,
304
plugin_enabled: plugin.enabled,
221
- // Codex loads the composio-cli skill from the plugin package itself. Claude's
222
- // plugin uses the standalone skill installed from the matching CLI release.
223
- cli_skill_ready:
224
- adapter.target === 'codex' ? pluginReady : yield* skillInstaller.isClaudeSkillInstalled,
305
+ cli_skill_ready: cliSkillReady,
306
marketplace_conflict: marketplace.conflicting,
307
} satisfies InspectedSetupTarget;
308
});
309
310
+interface SetupStep {
311
+ readonly args: ReadonlyArray<string>;
312
+ readonly operation: string;
313
+}
314
+
315
+const pluginRepairStep = (
316
+ adapter: SetupTargetAdapter,
317
+ status: InspectedSetupTarget
318
+): SetupStep | undefined => {
319
+ if (!status.marketplace_configured || !status.plugin_installed) {
320
+ return {
321
+ args: adapter.pluginInstallArgs,
322
+ operation: `Installing the ${adapter.target} plugin`,
323
+ };
324
+ }
325
+ if (!status.plugin_enabled) {
326
+ return {
327
+ args: adapter.pluginEnableArgs,
328
+ operation: `Enabling the ${adapter.target} plugin`,
329
+ };
330
+ }
331
+ return undefined;
332
+};
333
+
334
+const isSetupReady = (status: SetupTargetStatus): boolean =>
335
+ status.available &&
336
+ status.marketplace_configured &&
337
+ status.plugin_installed &&
338
+ status.plugin_enabled &&
339
+ status.cli_skill_ready;
340
+
341
const runRequired = (adapter: SetupTargetAdapter, args: ReadonlyArray<string>, operation: string) =>
342
Effect.gen(function* () {
343
const runner = yield* CommandRunner;
232
- const result = yield* runner.capture(Command.make(adapter.executable, ...args));
344
+ const result = yield* runner.capture(Command.make(adapter.executable, ...args)).pipe(
345
+ Effect.timeoutFail({
346
+ duration: SETUP_COMMAND_TIMEOUT,
347
+ onTimeout: () => new Error(`${operation} timed out after ${SETUP_COMMAND_TIMEOUT}.`),
348
+ })
349
+ );
350
if (result.exitCode !== 0) {
234
- const detail = result.stderr.trim() || result.stdout.trim();
235
- return yield* Effect.fail(
236
- new Error(`${operation} failed${detail ? `: ${detail}` : ` (exit ${result.exitCode})`}`)
237
- );
351
+ return yield* Effect.fail(new Error(`${operation} failed${commandFailureSuffix(result)}`));
352
}
353
});
354
241
-const installAdapter = (adapter: SetupTargetAdapter) =>
242
- Effect.gen(function* () {
243
- const initial = yield* inspectAdapter(adapter);
244
- if (!initial.available) {
245
- return yield* Effect.fail(
246
- new Error(
247
- `${adapter.executable} is not installed or not available on PATH. Install it and rerun \`composio setup --target ${adapter.target}\`.`
248
- )
249
- );
250
- }
251
- if (initial.marketplace_conflict) {
252
- const removeCommand =
253
- adapter.target === 'claude'
254
- ? 'claude plugin marketplace remove composio --scope user'
255
- : 'codex plugin marketplace remove composio --json';
256
- return yield* Effect.fail(
257
- new Error(
258
- `The ${adapter.target} marketplace named "composio" points to a different source. Run \`${removeCommand}\`, then rerun \`composio setup --target ${adapter.target}\`.`
259
- )
260
- );
261
- }
355
+const validateInitialState = (adapter: SetupTargetAdapter, initial: InspectedSetupTarget) => {
356
+ if (!initial.available) {
357
+ return Effect.fail(
358
+ new Error(
359
+ `${adapter.executable} is not installed or not available on PATH. Install it and rerun \`composio setup --target ${adapter.target}\`.`
360
+ )
361
+ );
362
+ }
363
+ if (initial.marketplace_conflict) {
364
+ return Effect.fail(
365
+ new Error(
366
+ `The ${adapter.target} marketplace named "composio" points to a different source. Run \`${adapter.marketplaceRemoveCommand}\`, then rerun \`composio setup --target ${adapter.target}\`.`
367
+ )
368
+ );
369
+ }
370
+ return Effect.void;
371
+};
372
263
- let pluginChanged = false;
373
+const installAdapter = (adapter: SetupTargetAdapter, initial: InspectedSetupTarget) =>
374
+ Effect.gen(function* () {
375
+ const steps: SetupStep[] = [];
376
if (!initial.marketplace_configured) {
265
- yield* runRequired(
266
- adapter,
267
- adapter.marketplaceAddArgs,
268
- `Adding the ${adapter.target} marketplace`
269
- );
270
- pluginChanged = true;
377
+ steps.push({
378
+ args: adapter.marketplaceAddArgs,
379
+ operation: `Adding the ${adapter.target} marketplace`,
380
+ });
381
}
272
- if (!initial.plugin_installed) {
273
- yield* runRequired(
274
- adapter,
275
- adapter.pluginInstallArgs,
276
- `Installing the ${adapter.target} plugin`
277
- );
278
- pluginChanged = true;
279
- } else if (!initial.plugin_enabled) {
280
- yield* runRequired(
281
- adapter,
282
- adapter.pluginEnableArgs,
283
- `Enabling the ${adapter.target} plugin`
284
- );
285
- pluginChanged = true;
382
+ const repairStep = pluginRepairStep(adapter, initial);
383
+ if (repairStep) steps.push(repairStep);
384
+ for (const step of steps) {
385
+ yield* runRequired(adapter, step.args, step.operation);
386
}
387
+ const pluginChanged = steps.length > 0;
388
389
const skillInstaller = yield* SetupSkillInstaller;
289
- const skillChanged =
290
- adapter.target === 'claude' && !initial.cli_skill_ready
291
- ? yield* skillInstaller.ensureClaudeSkill
292
- : false;
390
+ let skillChanged = false;
391
+ if (adapter.skillSource === 'standalone' && !initial.cli_skill_ready) {
392
+ skillChanged = yield* skillInstaller.ensureClaudeSkill;
393
+ }
394
395
const final = yield* inspectAdapter(adapter);
295
- if (
296
- !final.available ||
297
- !final.marketplace_configured ||
298
- !final.plugin_installed ||
299
- !final.plugin_enabled ||
300
- !final.cli_skill_ready
301
- ) {
396
+ if (!isSetupReady(final)) {
397
return yield* Effect.fail(
398
new Error(
399
`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) =>
414
} satisfies SetupTargetResult;
415
});
416
322
-const inspectSetupTargets = Effect.all(ADAPTERS.map(inspectAdapter));
417
+const FIXED_TARGETS: Readonly<Partial<Record<SetupTarget, ReadonlyArray<AgentHost>>>> = {
418
+ claude: ['claude'],
419
+ codex: ['codex'],
420
+ all: ['claude', 'codex'],
421
+};
422
423
export const resolveSetupTargets = (target: SetupTarget) =>
424
Effect.gen(function* () {
326
- if (target === 'claude' || target === 'codex') return [target] as const;
327
- if (target === 'all') return ['claude', 'codex'] as const;
425
+ const fixedTargets = FIXED_TARGETS[target];
426
+ if (fixedTargets) return fixedTargets;
427
329
- const statuses = yield* inspectSetupTargets;
428
+ const statuses = yield* Effect.all(
429
+ ADAPTER_LIST.map(adapter =>
430
+ isAdapterAvailable(adapter).pipe(
431
+ Effect.map(available => ({ target: adapter.target, available }))
432
+ )
433
+ )
434
+ );
435
const detected = statuses.filter(status => status.available).map(status => status.target);
436
if (detected.length === 0) {
437
return yield* Effect.fail(
@@ -339,7 +444,23 @@ export const resolveSetupTargets = (target: SetupTarget) =>
444
});
445
446
export const installSetupTargets = (targets: ReadonlyArray<AgentHost>) =>
342
- Effect.forEach(targets, target => {
343
- const adapter = ADAPTERS.find(candidate => candidate.target === target);
344
- return installAdapter(adapter as SetupTargetAdapter);
447
+ Effect.gen(function* () {
448
+ const inspected = yield* Effect.forEach(targets, target => inspectAdapter(ADAPTERS[target]));
449
+ yield* Effect.forEach(inspected, status =>
450
+ validateInitialState(ADAPTERS[status.target], status)
451
+ );
452
+ const completed: SetupTargetResult[] = [];
453
+ for (const status of inspected) {
454
+ const result = yield* installAdapter(ADAPTERS[status.target], status).pipe(
455
+ Effect.mapError(error => {
456
+ if (completed.length === 0) return error;
457
+ const targets = completed.map(item => item.target).join(', ');
458
+ return new Error(
459
+ `Setup completed for ${targets} before a later target failed: ${errorMessage(error)}`
460
+ );
461
+ })
462
+ );
463
+ completed.push(result);
464
+ }
465
+ return completed;
466
});
ts/packages/cli/test/__utils__/services/test-layer.ts
+1
-1
@@ -1257,7 +1257,7 @@ export const TestLayer = (input?: TestLiveInput) =>
1257
SetupSkillInstaller,
1258
input?.setupSkillInstaller ??
1259
new SetupSkillInstaller({
1260
- isClaudeSkillInstalled: Effect.succeed(false),
1260
+ isClaudeSkillReady: Effect.succeed(false),
1261
ensureClaudeSkill: Effect.succeed(false),
1262
})
1263
);
ts/packages/cli/test/src/commands/setup.cmd.test.ts
+331
-55
@@ -1,10 +1,10 @@
1
import { Command, CommandExecutor } from '@effect/platform';
2
import { describe, expect, layer } from '@effect/vitest';
3
-import { Effect, Exit } from 'effect';
3
+import { Cause, Effect, Exit, Fiber, TestClock } from 'effect';
4
import { afterEach, vi } from 'vitest';
5
import { CommandRunner } from 'src/services/command-runner';
6
import { SetupSkillInstaller } from 'src/services/setup-skill-installer';
7
-import { cli, MockConsole, TestLive } from 'test/__utils__';
7
+import { cli, TestLive } from 'test/__utils__';
8
9
type AgentHost = 'claude' | 'codex';
10
type MarketplaceState = 'missing' | 'canonical' | 'conflict';
@@ -14,8 +14,55 @@ interface FakeHostState {
14
available: boolean;
15
marketplace: MarketplaceState;
16
plugin: PluginState;
17
+ pluginScope: 'user' | 'project';
18
}
19
20
+interface HostOutputFormatter {
21
+ readonly version: string;
22
+ readonly marketplace: (state: MarketplaceState, source: string) => unknown;
23
+ readonly plugin: (installed: boolean, enabled: boolean, scope: 'user' | 'project') => unknown;
24
+}
25
+
26
+const MARKETPLACE_SOURCES: Readonly<Record<AgentHost, string>> = {
27
+ claude: 'https://github.com/ComposioHQ/composio-plugin-cc.git',
28
+ codex: 'ComposioHQ/composio-plugin-openai',
29
+};
30
+
31
+const HOST_OUTPUT_FORMATTERS: Readonly<Record<AgentHost, HostOutputFormatter>> = {
32
+ claude: {
33
+ version: '2.1.0',
34
+ marketplace: (state, source) => {
35
+ if (state === 'missing') return [];
36
+ return [{ name: 'composio', source: { source: 'github', repo: source } }];
37
+ },
38
+ plugin: (installed, enabled, scope) => {
39
+ if (!installed) return [];
40
+ return [{ id: 'composio@composio', scope, enabled }];
41
+ },
42
+ },
43
+ codex: {
44
+ version: 'codex-cli 0.144.1',
45
+ marketplace: (state, source) => {
46
+ if (state === 'missing') return { marketplaces: [] };
47
+ return {
48
+ marketplaces: [
49
+ {
50
+ name: 'composio',
51
+ marketplaceSource: { sourceType: 'git', source },
52
+ },
53
+ ],
54
+ };
55
+ },
56
+ plugin: (installed, enabled) => {
57
+ if (!installed) return { installed: [], available: [] };
58
+ return {
59
+ installed: [{ pluginId: 'composio@composio', installed, enabled }],
60
+ available: [],
61
+ };
62
+ },
63
+ },
64
+};
65
+
66
const commandParts = (command: Command.Command): ReadonlyArray<string> => {
67
const first = Command.flatten(command)[0];
68
return [first.command, ...first.args];
@@ -42,15 +89,17 @@ const makeRunner = (
89
90
const makeSkillInstaller = (initiallyReady = false, failInstall = false) => {
91
let ready = initiallyReady;
92
+ const ensureClaudeSkill = () => {
93
+ if (failInstall) return Effect.fail(new Error('skill download failed'));
94
+ return Effect.sync(() => {
95
+ const changed = !ready;
96
+ ready = true;
97
+ return changed;
98
+ });
99
+ };
100
return new SetupSkillInstaller({
46
- isClaudeSkillInstalled: Effect.sync(() => ready),
47
- ensureClaudeSkill: failInstall
48
- ? Effect.fail(new Error('skill download failed'))
49
- : Effect.sync(() => {
50
- const changed = !ready;
51
- ready = true;
52
- return changed;
53
- }),
101
+ isClaudeSkillReady: Effect.sync(() => ready),
102
+ ensureClaudeSkill: ensureClaudeSkill(),
103
});
104
};
105
@@ -58,11 +107,17 @@ const defaultHostState = (): FakeHostState => ({
107
available: false,
108
marketplace: 'missing',
109
plugin: 'missing',
110
+ pluginScope: 'user',
111
});
112
113
const makeFakeHosts = (
114
initial: Partial<Record<AgentHost, Partial<FakeHostState>>>,
65
- options: { readonly noOp?: boolean; readonly failOn?: string } = {}
115
+ options: {
116
+ readonly noOp?: boolean;
117
+ readonly failOn?: string;
118
+ readonly malformedOn?: string;
119
+ readonly marketplaceSource?: Partial<Record<AgentHost, string>>;
120
+ } = {}
121
) => {
122
const state: Record<AgentHost, FakeHostState> = {
123
claude: { ...defaultHostState(), ...initial.claude },
@@ -72,40 +127,20 @@ const makeFakeHosts = (
127
128
const marketplaceOutput = (host: AgentHost): string => {
129
const current = state[host].marketplace;
75
- const source =
76
- current === 'canonical'
77
- ? host === 'claude'
78
- ? 'https://github.com/ComposioHQ/composio-plugin-cc.git'
79
- : 'ComposioHQ/composio-plugin-openai'
80
- : 'someone-else/not-composio';
81
- if (host === 'claude') {
82
- return current === 'missing'
83
- ? '[]'
84
- : JSON.stringify([{ name: 'composio', source: { source: 'github', repo: source } }]);
130
+ let source = 'someone-else/not-composio';
131
+ if (current === 'canonical') {
132
+ source = options.marketplaceSource?.[host] ?? MARKETPLACE_SOURCES[host];
133
}
86
- return JSON.stringify({
87
- marketplaces:
88
- current === 'missing'
89
- ? []
90
- : [
91
- {
92
- name: 'composio',
93
- marketplaceSource: { sourceType: 'git', source },
94
- },
95
- ],
96
- });
134
+ return JSON.stringify(HOST_OUTPUT_FORMATTERS[host].marketplace(current, source));
135
};
136
137
const pluginOutput = (host: AgentHost): string => {
138
const current = state[host].plugin;
139
const installed = current !== 'missing';
140
const enabled = current === 'enabled';
103
- return host === 'claude'
104
- ? JSON.stringify(installed ? [{ id: 'composio@composio', installed, enabled }] : [])
105
- : JSON.stringify({
106
- installed: installed ? [{ pluginId: 'composio@composio', installed, enabled }] : [],
107
- available: [],
108
- });
141
+ return JSON.stringify(
142
+ HOST_OUTPUT_FORMATTERS[host].plugin(installed, enabled, state[host].pluginScope)
143
+ );
144
};
145
146
const runner = makeRunner(parts => {
@@ -113,9 +148,14 @@ const makeFakeHosts = (
148
const host = parts[0] as AgentHost;
149
const command = parts.join(' ');
150
if (parts[1] === '--version') {
116
- return state[host].available
117
- ? { stdout: host === 'claude' ? '2.1.0' : 'codex-cli 0.144.1' }
118
- : { exitCode: 127, stderr: 'not found' };
151
+ if (!state[host].available) return { exitCode: 127, stderr: 'not found' };
152
+ return { stdout: HOST_OUTPUT_FORMATTERS[host].version };
153
+ }
154
+ if (options.failOn && command.includes(options.failOn)) {
155
+ return { exitCode: 2, stderr: 'native operation failed' };
156
+ }
157
+ if (options.malformedOn && command.includes(options.malformedOn)) {
158
+ return { stdout: '{not-json' };
159
}
160
if (command === `${host} plugin marketplace list --json`) {
161
return { stdout: marketplaceOutput(host) };
@@ -123,9 +163,6 @@ const makeFakeHosts = (
163
if (command === `${host} plugin list --json`) {
164
return { stdout: pluginOutput(host) };
165
}
126
- if (options.failOn && command.includes(options.failOn)) {
127
- return { exitCode: 2, stderr: 'native operation failed' };
128
- }
166
if (!options.noOp && command.includes('plugin marketplace add')) {
167
state[host].marketplace = 'canonical';
168
}
@@ -136,6 +173,7 @@ const makeFakeHosts = (
173
command === 'codex plugin add composio@composio --json')
174
) {
175
state[host].plugin = 'enabled';
176
+ state[host].pluginScope = 'user';
177
}
178
return {};
179
});
@@ -183,7 +221,6 @@ describe('CLI: composio setup', () => {
221
marketplace: 'canonical',
222
plugin: 'enabled',
223
});
186
- expect((yield* MockConsole.getLines()).join('\n')).toContain('"success":true');
224
})
225
);
226
});
@@ -197,9 +234,6 @@ describe('CLI: composio setup', () => {
234
yield* cli(['setup', '--target', 'codex', '--yes']);
235
236
expect(existingCodex.commands.some(parts => parts.includes('add'))).toBe(false);
200
- const output = (yield* MockConsole.getLines()).join('\n');
201
- expect(output).toContain('"changed":false');
202
- expect(output).toContain('"success":true');
237
})
238
);
239
});
@@ -219,7 +253,16 @@ describe('CLI: composio setup', () => {
253
yield* cli(['setup', '--target', host, '--yes']);
254
255
expect(disabled.state[host].plugin).toBe('enabled');
222
- expect((yield* MockConsole.getLines()).join('\n')).toContain('"plugin_enabled":true');
256
+ if (host === 'claude') {
257
+ expect(disabled.commands).toContainEqual([
258
+ 'claude',
259
+ 'plugin',
260
+ 'enable',
261
+ 'composio@composio',
262
+ '--scope',
263
+ 'user',
264
+ ]);
265
+ }
266
})
267
);
268
});
@@ -261,9 +304,10 @@ describe('CLI: composio setup', () => {
304
Effect.gen(function* () {
305
yield* cli(['setup', '--target', 'auto', '--yes']);
306
264
- const output = (yield* MockConsole.getLines()).join('\n');
265
- expect(output).toContain('"target":"claude"');
266
- expect(output).not.toContain('"target":"codex"');
307
+ expect(autoClaude.commands.some(parts => parts[0] === 'claude')).toBe(true);
308
+ expect(
309
+ autoClaude.commands.some(parts => parts[0] === 'codex' && parts[1] !== '--version')
310
+ ).toBe(false);
311
})
312
);
313
});
@@ -282,9 +326,90 @@ describe('CLI: composio setup', () => {
326
Effect.gen(function* () {
327
yield* cli(['setup', '--target', 'auto', '--yes']);
328
285
- const output = (yield* MockConsole.getLines()).join('\n');
286
- expect(output).toContain('"target":"claude"');
287
- expect(output).toContain('"target":"codex"');
329
+ expect(autoBoth.commands.some(parts => parts[0] === 'claude')).toBe(true);
330
+ expect(autoBoth.commands.some(parts => parts[0] === 'codex')).toBe(true);
331
+ })
332
+ );
333
+ });
334
+
335
+ const allTargets = makeFakeHosts({
336
+ claude: { available: true },
337
+ codex: { available: true },
338
+ });
339
+ layer(
340
+ TestLive({
341
+ commandRunner: allTargets.runner,
342
+ setupSkillInstaller: makeSkillInstaller(),
343
+ })
344
+ )('explicit all-host setup', it => {
345
+ it.scoped('configures both supported hosts', () =>
346
+ Effect.gen(function* () {
347
+ yield* cli(['setup', '--target', 'all', '--yes']);
348
+
349
+ expect(allTargets.state.claude).toMatchObject({
350
+ marketplace: 'canonical',
351
+ plugin: 'enabled',
352
+ });
353
+ expect(allTargets.state.codex).toMatchObject({
354
+ marketplace: 'canonical',
355
+ plugin: 'enabled',
356
+ });
357
+ })
358
+ );
359
+ });
360
+
361
+ const projectScopedClaude = makeFakeHosts({
362
+ claude: {
363
+ available: true,
364
+ marketplace: 'canonical',
365
+ plugin: 'enabled',
366
+ pluginScope: 'project',
367
+ },
368
+ });
369
+ layer(
370
+ TestLive({
371
+ commandRunner: projectScopedClaude.runner,
372
+ setupSkillInstaller: makeSkillInstaller(true),
373
+ })
374
+ )('project-scoped Claude plugin', it => {
375
+ it.scoped('installs the required user-scoped plugin', () =>
376
+ Effect.gen(function* () {
377
+ yield* cli(['setup', '--target', 'claude', '--yes']);
378
+
379
+ expect(projectScopedClaude.commands).toContainEqual([
380
+ 'claude',
381
+ 'plugin',
382
+ 'install',
383
+ 'composio@composio',
384
+ '--scope',
385
+ 'user',
386
+ ]);
387
+ expect(projectScopedClaude.state.claude.pluginScope).toBe('user');
388
+ })
389
+ );
390
+ });
391
+
392
+ const missingMarketplaceWithPlugin = makeFakeHosts({
393
+ claude: { available: true, marketplace: 'missing', plugin: 'enabled' },
394
+ });
395
+ layer(
396
+ TestLive({
397
+ commandRunner: missingMarketplaceWithPlugin.runner,
398
+ setupSkillInstaller: makeSkillInstaller(true),
399
+ })
400
+ )('plugin from a removed marketplace', it => {
401
+ it.scoped('reinstalls after restoring the canonical marketplace', () =>
402
+ Effect.gen(function* () {
403
+ yield* cli(['setup', '--target', 'claude', '--yes']);
404
+
405
+ expect(missingMarketplaceWithPlugin.commands).toContainEqual([
406
+ 'claude',
407
+ 'plugin',
408
+ 'install',
409
+ 'composio@composio',
410
+ '--scope',
411
+ 'user',
412
+ ]);
413
})
414
);
415
});
@@ -312,6 +437,157 @@ describe('CLI: composio setup', () => {
437
);
438
});
439
440
+ for (const unsafeSource of [
441
+ 'http://github.com/ComposioHQ/composio-plugin-cc.git',
442
+ 'https://token@github.com/ComposioHQ/composio-plugin-cc.git',
443
+ 'https://github.com/ComposioHQ/composio-plugin-cc.git?token=secret',
444
+ ]) {
445
+ const unsafeMarketplace = makeFakeHosts(
446
+ { claude: { available: true, marketplace: 'canonical' } },
447
+ { marketplaceSource: { claude: unsafeSource } }
448
+ );
449
+ layer(TestLive({ commandRunner: unsafeMarketplace.runner }))(
450
+ `unsafe marketplace source: ${unsafeSource}`,
451
+ it => {
452
+ it.scoped('rejects a non-canonical GitHub URL', () =>
453
+ Effect.gen(function* () {
454
+ const exit = yield* Effect.exit(cli(['setup', '--target', 'claude', '--yes']));
455
+
456
+ expect(Exit.isFailure(exit)).toBe(true);
457
+ expect(
458
+ unsafeMarketplace.commands.some(parts =>
459
+ ['add', 'install', 'enable'].some(operation => parts.includes(operation))
460
+ )
461
+ ).toBe(false);
462
+ })
463
+ );
464
+ }
465
+ );
466
+ }
467
+
468
+ const failedInspection = makeFakeHosts(
469
+ { claude: { available: true } },
470
+ { failOn: 'plugin list --json' }
471
+ );
472
+ layer(TestLive({ commandRunner: failedInspection.runner }))('failed native inspection', it => {
473
+ it.scoped('fails before running setup mutations', () =>
474
+ Effect.gen(function* () {
475
+ const exit = yield* Effect.exit(cli(['setup', '--target', 'claude', '--yes']));
476
+
477
+ expect(Exit.isFailure(exit)).toBe(true);
478
+ expect(
479
+ failedInspection.commands.some(parts =>
480
+ ['add', 'install', 'enable'].some(operation => parts.includes(operation))
481
+ )
482
+ ).toBe(false);
483
+ })
484
+ );
485
+ });
486
+
487
+ const malformedInspection = makeFakeHosts(
488
+ { codex: { available: true } },
489
+ { malformedOn: 'plugin marketplace list --json' }
490
+ );
491
+ layer(TestLive({ commandRunner: malformedInspection.runner }))(
492
+ 'malformed native inspection',
493
+ it => {
494
+ it.scoped('fails before running setup mutations', () =>
495
+ Effect.gen(function* () {
496
+ const exit = yield* Effect.exit(cli(['setup', '--target', 'codex', '--yes']));
497
+
498
+ expect(Exit.isFailure(exit)).toBe(true);
499
+ expect(malformedInspection.commands.some(parts => parts.includes('add'))).toBe(false);
500
+ })
501
+ );
502
+ }
503
+ );
504
+
505
+ const preflightConflict = makeFakeHosts({
506
+ claude: { available: true },
507
+ codex: { available: true, marketplace: 'conflict' },
508
+ });
509
+ layer(
510
+ TestLive({
511
+ commandRunner: preflightConflict.runner,
512
+ setupSkillInstaller: makeSkillInstaller(),
513
+ })
514
+ )('multi-host preflight', it => {
515
+ it.scoped('does not mutate an earlier host when a later host conflicts', () =>
516
+ Effect.gen(function* () {
517
+ const exit = yield* Effect.exit(cli(['setup', '--target', 'all', '--yes']));
518
+
519
+ expect(Exit.isFailure(exit)).toBe(true);
520
+ expect(preflightConflict.state.claude).toMatchObject({
521
+ marketplace: 'missing',
522
+ plugin: 'missing',
523
+ });
524
+ })
525
+ );
526
+ });
527
+
528
+ const laterMutationFailure = makeFakeHosts(
529
+ {
530
+ claude: { available: true },
531
+ codex: { available: true },
532
+ },
533
+ { failOn: 'codex plugin add composio@composio --json' }
534
+ );
535
+ layer(
536
+ TestLive({
537
+ commandRunner: laterMutationFailure.runner,
538
+ setupSkillInstaller: makeSkillInstaller(),
539
+ })
540
+ )('multi-host mutation failure', it => {
541
+ it.scoped('reports hosts completed before a later target fails', () =>
542
+ Effect.gen(function* () {
543
+ const exit = yield* Effect.exit(cli(['setup', '--target', 'all', '--yes']));
544
+
545
+ expect(Exit.isFailure(exit)).toBe(true);
546
+ if (Exit.isFailure(exit)) {
547
+ expect(Cause.pretty(exit.cause)).toContain(
548
+ 'Setup completed for claude before a later target failed'
549
+ );
550
+ }
551
+ expect(laterMutationFailure.state.claude).toMatchObject({
552
+ marketplace: 'canonical',
553
+ plugin: 'enabled',
554
+ });
555
+ })
556
+ );
557
+ });
558
+
559
+ const nonInteractive = makeFakeHosts({ claude: { available: true } });
560
+ layer(TestLive({ commandRunner: nonInteractive.runner }))('non-interactive approval', it => {
561
+ it.scoped('requires --yes before inspecting or mutating hosts', () =>
562
+ Effect.gen(function* () {
563
+ const exit = yield* Effect.exit(cli(['setup', '--target', 'claude']));
564
+
565
+ expect(Exit.isFailure(exit)).toBe(true);
566
+ expect(nonInteractive.commands).toHaveLength(0);
567
+ })
568
+ );
569
+ });
570
+
571
+ const hangingRunner = new CommandRunner({
572
+ run: () => Effect.succeed(CommandExecutor.ExitCode(0)),
573
+ capture: () => Effect.never,
574
+ });
575
+ layer(TestLive({ commandRunner: hangingRunner }))('hung native host', it => {
576
+ it.scoped('times out instead of blocking setup forever', () =>
577
+ Effect.gen(function* () {
578
+ const fiber = yield* cli(['setup', '--target', 'claude', '--yes']).pipe(
579
+ Effect.exit,
580
+ Effect.fork
581
+ );
582
+ yield* Effect.yieldNow();
583
+ yield* TestClock.adjust('2 minutes');
584
+ const exit = yield* Fiber.join(fiber);
585
+
586
+ expect(Exit.isFailure(exit)).toBe(true);
587
+ })
588
+ );
589
+ });
590
+
591
const noOp = makeFakeHosts({ claude: { available: true } }, { noOp: true });
592
layer(TestLive({ commandRunner: noOp.runner, setupSkillInstaller: makeSkillInstaller() }))(
593
'post-install verification',
ts/packages/cli/test/src/services/setup-skill-installer.test.ts
+13
-2
@@ -1,4 +1,4 @@
1
-import { mkdirSync, writeFileSync } from 'node:fs';
1
+import { mkdirSync, symlinkSync, writeFileSync } from 'node:fs';
2
import path from 'node:path';
3
import { describe, expect, it } from 'vitest';
4
import * as tempy from 'tempy';
@@ -29,12 +29,14 @@ describe('SetupSkillInstaller', () => {
29
const home = tempy.temporaryDirectory();
30
const target = path.join(home, '.claude', 'skills', 'composio-cli');
31
const skillDir = path.join(home, '.agents', 'skills', 'composio-cli');
32
- mkdirSync(target, { recursive: true });
32
mkdirSync(skillDir, { recursive: true });
33
+ mkdirSync(path.dirname(target), { recursive: true });
34
+ symlinkSync(path.relative(path.dirname(target), skillDir), target);
35
writeFileSync(
36
path.join(skillDir, SKILL_RELEASE_TAG_FILENAME),
37
'@composio/cli@0.2.20-beta.42\n'
38
);
39
+ writeFileSync(path.join(skillDir, 'SKILL.md'), '# composio-cli\n');
40
41
expect(isClaudeSkillCurrent(home, '@composio/cli@0.2.20-beta.42')).toBe(true);
42
expect(isClaudeSkillCurrent(home, '@composio/cli@0.2.20-beta.43')).toBe(false);
@@ -46,4 +48,13 @@ describe('SetupSkillInstaller', () => {
48
49
expect(isClaudeSkillCurrent(home, '@composio/cli@0.3.0')).toBe(false);
50
});
51
+
52
+ it('treats a release marker without a readable skill as stale', () => {
53
+ const home = tempy.temporaryDirectory();
54
+ const target = path.join(home, '.claude', 'skills', 'composio-cli');
55
+ mkdirSync(target, { recursive: true });
56
+ writeFileSync(path.join(target, SKILL_RELEASE_TAG_FILENAME), '@composio/cli@0.3.0\n');
57
+
58
+ expect(isClaudeSkillCurrent(home, '@composio/cli@0.3.0')).toBe(false);
59
+ });
60
});