15
isSetupPluginReady,
16
isSetupReady,
17
SETUP_TARGETS,
18
- SetupCommandError,
18
uninstallSetupTargets,
19
type AgentHost,
21
- type SetupFailureReasonCode,
20
} from 'src/services/setup';
21
+import { SetupCommandError, type SetupFailureReasonCode } from 'src/services/setup-command-error';
22
import { TerminalUI } from 'src/services/terminal-ui';
23
import { SetupSkillInstaller } from 'src/services/setup-skill-installer';
24
import { cliInvocationContext } from 'src/services/runtime-cli-context';
50
const errorMessage = (error: unknown): string =>
51
Predicate.isError(error) ? error.message : String(error);
52
54
-type SetupOperation = 'setup' | 'uninstall';
55
-
56
-interface SetupCommandErrorParams {
57
- readonly message: string;
58
- readonly reasonCode: SetupFailureReasonCode;
59
- readonly cause?: unknown;
60
-}
61
-
62
-const operationOf = (uninstall: boolean): SetupOperation => {
63
- if (uninstall) return 'uninstall';
64
- return 'setup';
65
-};
53
+const setupCommandError = (
54
+ message: string,
55
+ operation: 'setup' | 'uninstall',
56
+ reasonCode: SetupFailureReasonCode,
57
+ cause?: unknown
58
+) =>
59
+ new SetupCommandError({
60
+ message,
61
+ operation,
62
+ reasonCode,
63
+ ...(cause === undefined ? {} : { cause }),
64
+ });
65
66
const setupBaseCmd = Command.make(
67
'setup',
68
{ target, yes, ifPresent, uninstall },
70
- ({ target, yes, ifPresent, uninstall }) => {
71
- const operation = operationOf(uninstall);
72
- const setupCommandError = (params: SetupCommandErrorParams) =>
73
- new SetupCommandError({ operation, ...params });
74
-
75
- return Effect.gen(function* () {
69
+ ({ target, yes, ifPresent, uninstall }) =>
70
+ Effect.gen(function* () {
71
const ui = yield* TerminalUI;
72
const terminal = yield* ui.capabilities;
73
const { invocationOrigin } = yield* cliInvocationContext;
74
+ const operation = uninstall ? 'uninstall' : 'setup';
75
yield* ui.intro(uninstall ? 'composio setup --uninstall' : 'composio setup');
76
77
const detections = yield* detectSetupTargets(target);
109
yield* ui.log.info(`${formatTargets(notDetected)} not detected.`);
110
}
111
if (target === 'all' && notDetected.length > 0) {
116
- return yield* setupCommandError({
117
- message: `\`--target all\` requires Claude Code and Codex. Missing: ${formatTargets(notDetected)}. Install the missing agent host, or use \`--target auto\` to operate on detected hosts only.`,
118
- reasonCode: 'all_requires_both_hosts',
119
- });
112
+ return yield* setupCommandError(
113
+ `\`--target all\` requires Claude Code and Codex. Missing: ${formatTargets(notDetected)}. Install the missing agent host, or use \`--target auto\` to operate on detected hosts only.`,
114
+ operation,
115
+ 'all_requires_both_hosts'
116
+ );
117
}
118
if (unsupported.length > 0) {
119
const reason = unsupported
121
.filter((message): message is string => Boolean(message))
122
.join(' ');
123
if (target !== 'auto') {
127
- return yield* setupCommandError({ message: reason, reasonCode: 'unsupported_host' });
124
+ return yield* setupCommandError(reason, operation, 'unsupported_host');
125
}
126
yield* ui.log.warn(
127
`${formatTargets(unsupported.map(result => result.target))} plugin setup skipped. ${reason}`
141
);
142
return;
143
}
147
- return yield* setupCommandError({ message: reason, reasonCode: 'unsupported_host' });
144
+ return yield* setupCommandError(reason, operation, 'unsupported_host');
145
}
146
}
147
if (detected.length === 0) {
148
if (target === 'claude' || target === 'codex') {
152
- return yield* setupCommandError({
153
- message: `${target} is not installed or not available on PATH. Install it and rerun \`composio setup${uninstall ? ' --uninstall' : ''} --target ${target}\`.`,
154
- reasonCode: 'target_not_installed',
155
- });
149
+ return yield* setupCommandError(
150
+ `${target} is not installed or not available on PATH. Install it and rerun \`composio setup${uninstall ? ' --uninstall' : ''} --target ${target}\`.`,
151
+ operation,
152
+ 'target_not_installed'
153
+ );
154
}
155
if (!ifPresent || target !== 'auto') {
158
- return yield* setupCommandError({
159
- message: `No supported agent host was detected. Install Claude Code or Codex, then rerun \`composio setup${uninstall ? ' --uninstall' : ''}\`.`,
160
- reasonCode: 'no_host_detected',
161
- });
156
+ return yield* setupCommandError(
157
+ `No supported agent host was detected. Install Claude Code or Codex, then rerun \`composio setup${uninstall ? ' --uninstall' : ''}\`.`,
158
+ operation,
159
+ 'no_host_detected'
160
+ );
161
}
162
yield* trackCliEventEffect(
163
getSetupSkippedEvent({
175
176
const inspected = yield* inspectSetupTargets(detections, {
177
allowMarketplaceConflict: uninstall,
179
- operation,
178
+ operation: uninstall ? 'uninstall' : 'setup',
179
});
180
if (uninstall) {
181
const installed = inspected.filter(status => status.plugin_installed);
201
202
if (!yes && removable.length > 0) {
203
if (!terminal.canPrompt) {
205
- return yield* setupCommandError({
206
- message: 'Non-interactive uninstall requires `--yes` to approve local changes.',
207
- reasonCode: 'non_interactive_requires_yes',
208
- });
204
+ return yield* setupCommandError(
205
+ 'Non-interactive uninstall requires `--yes` to approve local changes.',
206
+ operation,
207
+ 'non_interactive_requires_yes'
208
+ );
209
}
210
const confirmed = yield* ui.confirm(
211
`Remove Composio from ${formatTargets(removable.map(status => status.target))}?`,
251
const pendingPlugins = pending.filter(status => !isSetupPluginReady(status));
252
if (!yes) {
253
if (!terminal.canPrompt) {
254
- return yield* setupCommandError({
255
- message: 'Non-interactive setup requires `--yes` to approve local changes.',
256
- reasonCode: 'non_interactive_requires_yes',
257
- });
254
+ return yield* setupCommandError(
255
+ 'Non-interactive setup requires `--yes` to approve local changes.',
256
+ operation,
257
+ 'non_interactive_requires_yes'
258
+ );
259
}
260
261
const prompt =
300
}).pipe(
301
Effect.mapError(error => {
302
if (error instanceof SetupCommandError) return error;
302
- return setupCommandError({
303
- message: errorMessage(error),
304
- reasonCode: 'unknown',
305
- cause: error,
306
- });
303
+ return setupCommandError(
304
+ errorMessage(error),
305
+ uninstall ? 'uninstall' : 'setup',
306
+ 'unknown',
307
+ error
308
+ );
309
})
308
- );
309
- }
310
+ )
311
);
312
313
export const setupCmd = setupBaseCmd.pipe(