1
import process from 'node:process';
2
-import { Effect, Option } from 'effect';
2
+import { Array as Arr, Data, Effect, HashSet, Option } from 'effect';
3
import { Command, HelpDoc, ValidationError } from '@effect/cli';
4
+import {
5
+ hasCommandName,
6
+ listSubcommandNames,
7
+ preflightParse,
8
+ type AnyCommandDescriptor,
9
+} from './command-introspection';
10
import { $defaultCmd } from './$default.cmd';
11
import { getVersion } from 'src/effects/version';
12
import { versionCmd } from './version.cmd';
23
import { installCmd } from './install.cmd';
24
import { localToolsCmd } from './local-tools/local-tools.cmd';
25
import { generateCmd } from './generate/generate.cmd';
20
-import { buildDevCommand } from './dev.cmd';
26
+import { buildDevCommand, devSubcommands } from './dev.cmd';
27
import {
28
runParallelToolsExecuteFromArgv,
29
showToolsExecuteInputHelp,
30
+ TOOLS_EXECUTE_VALUE_OPTIONS,
31
} from './tools/commands/tools.execute.cmd';
32
import {
33
printRootHelp,
56
} from 'src/services/command-project';
57
import { CLI_EXPERIMENTAL_FEATURES } from 'src/constants';
58
import { installSkill, type SkillInstallTarget } from 'src/effects/install-skill';
52
-import {
53
- experimental,
54
- type CommandVisibility,
55
- type TaggedValue,
56
- tagged,
57
- visibleValues,
58
-} from './feature-tags';
59
-
60
-// eslint-disable-next-line @typescript-eslint/no-explicit-any
61
-const ROOT_COMMANDS: ReadonlyArray<TaggedValue<Command.Command<any, any, any, any>>> = [
59
+import { experimental, type CommandVisibility, tagged, visibleValues } from './feature-tags';
60
+
61
+const ROOT_COMMANDS = [
62
tagged(versionCmd),
63
tagged(upgradeCmd),
64
tagged(whoamiCmd),
84
tagged(configCmd),
85
];
86
87
-export const buildRootCommand = (visibility: CommandVisibility) => {
88
- const subcommands = [...visibleValues(ROOT_COMMANDS, visibility), buildDevCommand(visibility)];
89
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
90
- return $defaultCmd.pipe(Command.withSubcommands(subcommands as any));
91
-};
92
-
93
-const formatSubcommandChoices = (choices: ReadonlyArray<string>) =>
94
- choices.map(choice => `'${choice}'`).join(', ');
95
-
96
-/**
97
- * Internal shape of an `@effect/cli` command descriptor. The public
98
- * `CommandDescriptor.getSubcommands` helper flattens nested subcommand trees
99
- * and only returns the *parent* Standard node for each branch, which means we
100
- * can't use it to walk deeper than one level. Walking the `_tag`-based
101
- * internal tree directly is the only way to recover the full descendable
102
- * structure without losing subcommand context on descent.
103
- */
104
-type InternalDescriptor =
105
- | { _tag: 'Standard'; name: string }
106
- | { _tag: 'GetUserInput'; name: string }
107
- | { _tag: 'Map'; command: InternalDescriptor }
108
- | {
109
- _tag: 'Subcommands';
110
- parent: InternalDescriptor;
111
- children: ReadonlyArray<InternalDescriptor>;
112
- };
113
-
114
-type UnwrappedDescriptor = Exclude<InternalDescriptor, { _tag: 'Map' }>;
115
-
116
-const unwrapMaps = (cmd: InternalDescriptor): UnwrappedDescriptor => {
117
- let current: InternalDescriptor = cmd;
118
- while (current._tag === 'Map') {
119
- current = current.command;
120
- }
121
- return current;
122
-};
123
-
124
-const getCommandName = (cmd: InternalDescriptor): string => {
125
- const unwrapped = unwrapMaps(cmd);
126
- if (unwrapped._tag === 'Subcommands') {
127
- return getCommandName(unwrapped.parent);
128
- }
129
- return unwrapped.name;
130
-};
131
-
132
-const getChildEntries = (
133
- cmd: InternalDescriptor
134
-): ReadonlyArray<readonly [string, InternalDescriptor]> => {
135
- const unwrapped = unwrapMaps(cmd);
136
- if (unwrapped._tag !== 'Subcommands') {
137
- return [];
138
- }
139
- return unwrapped.children.map(child => [getCommandName(child), child] as const);
87
+const getVisibleRootCommands = (visibility: CommandVisibility) => {
88
+ type RootCommand = (typeof ROOT_COMMANDS)[number]['value'];
89
+ return Arr.append(
90
+ visibleValues<RootCommand>(ROOT_COMMANDS, visibility),
91
+ buildDevCommand(visibility)
92
+ );
93
};
94
142
-const findNestedSubcommandMismatch = (
143
- argv: ReadonlyArray<string>,
144
- rootCommand: ReturnType<typeof buildRootCommand>
145
-): ReturnType<typeof ValidationError.commandMismatch> | undefined => {
146
- const args = argv.slice(2);
147
- let current: InternalDescriptor = rootCommand.descriptor as unknown as InternalDescriptor;
148
- const path = ['composio'];
149
-
150
- for (const token of args) {
151
- if (!token || token === '--' || token === '--help' || token === '-h' || token.startsWith('-')) {
152
- return undefined;
153
- }
154
-
155
- const children = getChildEntries(current);
156
- if (children.length === 0) {
157
- return undefined;
158
- }
159
-
160
- const match = children.find(([name]) => name === token);
161
- if (match) {
162
- current = match[1];
163
- path.push(token);
164
- continue;
165
- }
95
+export const buildRootCommand = (visibility: CommandVisibility) =>
96
+ $defaultCmd.pipe(Command.withSubcommands(getVisibleRootCommands(visibility)));
97
167
- if (path.length === 1) {
168
- return undefined;
169
- }
98
+const ROOT_INSTALL_SKILL_FLAGS = HashSet.make('--install-skill', '--instal-skill');
99
+const SKILL_INSTALL_TARGETS: ReadonlyArray<SkillInstallTarget> = ['claude', 'codex', 'openclaw'];
100
171
- const available = children.map(([name]) => name).sort();
172
- return ValidationError.commandMismatch(
173
- HelpDoc.p(
174
- `Invalid subcommand for ${path.join(' ')} - use one of ${formatSubcommandChoices(available)}`
175
- )
176
- );
177
- }
101
+class RootCommandError extends Data.TaggedError('commands/RootCommandError')<{
102
+ readonly message: string;
103
+}> {}
104
179
- return undefined;
105
+type RootInstallSkillRequest = {
106
+ readonly skillName?: string;
107
+ readonly target: SkillInstallTarget;
108
};
109
182
-const ROOT_INSTALL_SKILL_FLAGS = ['--install-skill', '--instal-skill'] as const;
183
-const SKILL_INSTALL_TARGETS = [
184
- 'claude',
185
- 'codex',
186
- 'openclaw',
187
-] as const satisfies ReadonlyArray<SkillInstallTarget>;
188
-
189
-type RootInstallSkillRequest =
190
- | {
191
- _tag: 'parsed';
192
- skillName?: string;
193
- target: SkillInstallTarget;
194
- }
195
- | { _tag: 'error'; message: string };
196
-
110
const isSkillInstallTarget = (value: string): value is SkillInstallTarget =>
198
- (SKILL_INSTALL_TARGETS as ReadonlyArray<string>).includes(value);
199
-
200
-export const parseRootInstallSkillRequest = (
201
- argv: ReadonlyArray<string>
202
-): RootInstallSkillRequest | undefined => {
203
- const args = argv.slice(2);
204
- for (let i = 0; i < args.length; i += 1) {
205
- const token = args[i];
206
- if (!token) continue;
207
-
208
- if ((ROOT_INSTALL_SKILL_FLAGS as ReadonlyArray<string>).includes(token)) {
209
- const rawValues: string[] = [];
210
- for (let j = i + 1; j < args.length; j += 1) {
211
- const next = args[j];
212
- if (!next) continue;
213
- if (next.startsWith('-')) break;
214
- rawValues.push(next);
111
+ SKILL_INSTALL_TARGETS.some(target => target === value);
112
+
113
+const rootCommandError = (message: string) => Effect.fail(new RootCommandError({ message }));
114
+
115
+const findRootInstallSkillValues = (
116
+ args: ReadonlyArray<string>
117
+): Option.Option<ReadonlyArray<string>> =>
118
+ Arr.matchLeft(args, {
119
+ onEmpty: Option.none,
120
+ onNonEmpty: (token, tail) => {
121
+ if (HashSet.has(ROOT_INSTALL_SKILL_FLAGS, token)) {
122
+ return Option.some(Arr.takeWhile(tail, value => !value.startsWith('-')));
123
}
216
-
217
- if (rawValues.length === 0) {
218
- return {
219
- _tag: 'error',
220
- message:
221
- 'Missing target for --install-skill. Usage: composio --install-skill [skill-name] <claude|codex|openclaw>',
222
- };
124
+ if (token === '--log-level') {
125
+ return findRootInstallSkillValues(Arr.drop(tail, 1));
126
}
224
-
225
- if (rawValues.length === 1) {
226
- const [target] = rawValues;
227
- if (!isSkillInstallTarget(target)) {
228
- return {
229
- _tag: 'error',
230
- message:
231
- 'Invalid target for --install-skill. Expected one of: claude, codex, openclaw.',
232
- };
233
- }
234
- return { _tag: 'parsed', target };
127
+ if (token.startsWith('--log-level=') || token.startsWith('-')) {
128
+ return findRootInstallSkillValues(tail);
129
}
130
+ return Option.none();
131
+ },
132
+ });
133
237
- if (rawValues.length === 2) {
238
- const [skillName, target] = rawValues;
239
- if (!isSkillInstallTarget(target)) {
240
- return {
241
- _tag: 'error',
242
- message:
243
- 'Invalid target for --install-skill. Expected one of: claude, codex, openclaw.',
244
- };
245
- }
246
- return { _tag: 'parsed', skillName, target };
134
+const parseRootInstallSkillValues = (
135
+ rawValues: ReadonlyArray<string>
136
+): Effect.Effect<RootInstallSkillRequest, RootCommandError> =>
137
+ Arr.match(rawValues, {
138
+ onEmpty: () =>
139
+ rootCommandError(
140
+ 'Missing target for --install-skill. Usage: composio --install-skill [skill-name] <claude|codex|openclaw>'
141
+ ),
142
+ onNonEmpty: ([first, second, ...rest]) => {
143
+ if (rest.length > 0) {
144
+ return rootCommandError(
145
+ 'Too many arguments for --install-skill. Usage: composio --install-skill [skill-name] <claude|codex|openclaw>'
146
+ );
147
}
148
+ const target = second ?? first;
149
+ if (!isSkillInstallTarget(target)) {
150
+ return rootCommandError(
151
+ 'Invalid target for --install-skill. Expected one of: claude, codex, openclaw.'
152
+ );
153
+ }
154
+ return Effect.succeed(second === undefined ? { target } : { skillName: first, target });
155
+ },
156
+ });
157
249
- return {
250
- _tag: 'error',
251
- message:
252
- 'Too many arguments for --install-skill. Usage: composio --install-skill [skill-name] <claude|codex|openclaw>',
253
- };
254
- }
158
+export const parseRootInstallSkillRequest = (
159
+ argv: ReadonlyArray<string>
160
+): Effect.Effect<Option.Option<RootInstallSkillRequest>, RootCommandError> =>
161
+ Option.match(findRootInstallSkillValues(Arr.drop(argv, 2)), {
162
+ onNone: () => Effect.succeed(Option.none()),
163
+ onSome: values => Effect.map(parseRootInstallSkillValues(values), Option.some),
164
+ });
165
256
- if (token === '--log-level') {
257
- i += 1;
258
- continue;
259
- }
166
+const scopeCommandMismatch = (
167
+ commandPath: string,
168
+ descriptor: AnyCommandDescriptor,
169
+ error: unknown
170
+) => {
171
+ if (!ValidationError.isValidationError(error) || !ValidationError.isCommandMismatch(error)) {
172
+ return error;
173
+ }
174
+ const childNames = listSubcommandNames(descriptor).map(name => `'${name}'`);
175
+ if (childNames.length === 0) return error;
176
+
177
+ const oneOf = childNames.length === 1 ? '' : ' one of';
178
+ return ValidationError.commandMismatch(
179
+ HelpDoc.p(
180
+ `Invalid subcommand for composio ${commandPath} - use${oneOf} ${childNames.join(', ')}`
181
+ )
182
+ );
183
+};
184
261
- if (token.startsWith('--log-level=')) {
262
- continue;
263
- }
185
+const refineRootCommandMismatch = (
186
+ argv: ReadonlyArray<string>,
187
+ visibility: CommandVisibility,
188
+ originalError: ValidationError.ValidationError
189
+) => {
190
+ const rootCommandName = argv[2];
191
+ if (!rootCommandName || !ValidationError.isCommandMismatch(originalError)) {
192
+ return Effect.fail(originalError);
193
+ }
194
265
- if (!token.startsWith('-')) {
266
- return undefined;
267
- }
195
+ const rootCommand = Arr.findFirst(getVisibleRootCommands(visibility), command =>
196
+ hasCommandName(command, rootCommandName)
197
+ );
198
+ if (Option.isNone(rootCommand)) {
199
+ return Effect.fail(originalError);
200
}
269
- return undefined;
201
+
202
+ const nestedCommandName = argv[3];
203
+ const nestedDevCommand =
204
+ rootCommandName === 'dev' && visibility.isDevModeEnabled && nestedCommandName
205
+ ? Arr.findFirst(devSubcommands, command => hasCommandName(command, nestedCommandName))
206
+ : Option.none();
207
+ const descriptor = Option.match(nestedDevCommand, {
208
+ onNone: () => rootCommand.value.descriptor,
209
+ onSome: command => command.descriptor,
210
+ });
211
+ const commandPath = Option.isSome(nestedDevCommand)
212
+ ? `${rootCommandName} ${nestedCommandName}`
213
+ : rootCommandName;
214
+
215
+ return Effect.fail(scopeCommandMismatch(commandPath, descriptor, originalError));
216
};
217
272
-const parseExecuteInputHelpSlug = (argv: ReadonlyArray<string>): string | undefined => {
273
- const args = argv.slice(2);
218
+export const parseExecuteInputHelpSlug = (argv: ReadonlyArray<string>): string | undefined => {
219
+ const args = Arr.drop(argv, 2);
220
const isRootExecute = args[0] === 'execute';
221
const isDevExecute = args[0] === 'dev' && args[1] === 'playground-execute';
222
if (!isRootExecute && !isDevExecute) return undefined;
224
const hasHelp = args.includes('--help') || args.includes('-h');
225
if (!hasHelp) return undefined;
226
281
- const tail = isRootExecute ? args.slice(1) : args.slice(2);
282
- for (let i = 0; i < tail.length; i += 1) {
283
- const token = tail[i];
284
- if (!token) continue;
285
-
286
- // Stop option parsing after "--" and treat next positional as slug.
287
- if (token === '--') {
288
- const candidate = tail[i + 1];
289
- return candidate && !candidate.startsWith('-') ? candidate : undefined;
290
- }
291
-
292
- // Ignore help flags.
293
- if (token === '--help' || token === '-h') {
294
- continue;
295
- }
296
-
297
- // Skip known execute option values.
298
- if (
299
- token === '--data' ||
300
- token === '-d' ||
301
- token === '--parallel' ||
302
- token === '-p' ||
303
- token === '--user-id' ||
304
- token === '--project-name'
305
- ) {
306
- i += 1;
307
- continue;
308
- }
309
- if (
310
- token.startsWith('--data=') ||
311
- token.startsWith('-d=') ||
312
- token === '--parallel' ||
313
- token === '-p' ||
314
- token.startsWith('--user-id=') ||
315
- token.startsWith('--project-name=')
316
- ) {
317
- continue;
318
- }
319
-
320
- // Skip unknown flags.
321
- if (token.startsWith('-')) {
322
- continue;
323
- }
324
-
325
- // First positional token is the slug.
326
- return token;
327
- }
227
+ const findSlug = (tail: ReadonlyArray<string>): string | undefined =>
228
+ Arr.matchLeft(tail, {
229
+ onEmpty: () => undefined,
230
+ onNonEmpty: (token, rest) => {
231
+ if (token === '--') {
232
+ return Option.getOrUndefined(
233
+ Option.filter(Arr.head(rest), candidate => !candidate.startsWith('-'))
234
+ );
235
+ }
236
+ if (token === '--help' || token === '-h') {
237
+ return findSlug(rest);
238
+ }
239
+ if (HashSet.has(TOOLS_EXECUTE_VALUE_OPTIONS, token)) {
240
+ return findSlug(Arr.drop(rest, 1));
241
+ }
242
+ if (token.startsWith('-')) {
243
+ return findSlug(rest);
244
+ }
245
+ return token;
246
+ },
247
+ });
248
329
- return undefined;
249
+ return findSlug(Arr.drop(args, isRootExecute ? 1 : 2));
250
};
251
252
const normalizeVersionShortFlag = (argv: ReadonlyArray<string>): ReadonlyArray<string> => {
258
};
259
260
const normalizeListenStreamFlag = (argv: ReadonlyArray<string>): ReadonlyArray<string> => {
341
- const head = argv.slice(0, 2);
342
- const args = argv.slice(2);
261
+ const head = Arr.take(argv, 2);
262
+ const args = Arr.drop(argv, 2);
263
const isListen = args[0] === 'listen';
264
if (!isListen) {
265
return argv;
266
}
267
348
- const normalized: string[] = [...head];
349
- for (let i = 0; i < args.length; i += 1) {
350
- const token = args[i];
351
- if (token !== '--stream') {
352
- normalized.push(token ?? '');
353
- continue;
354
- }
355
-
356
- const next = args[i + 1];
357
- if (next === undefined || next.startsWith('-')) {
358
- normalized.push('--stream=');
359
- continue;
360
- }
268
+ return Arr.appendAll(
269
+ head,
270
+ Arr.map(args, (token, index) => {
271
+ const next = args[index + 1];
272
+ return token === '--stream' && (next === undefined || next.startsWith('-'))
273
+ ? '--stream='
274
+ : token;
275
+ })
276
+ );
277
+};
278
362
- normalized.push(token);
279
+const parseBooleanFlag = (argument: string, name: string): Option.Option<boolean> => {
280
+ if (argument === name || argument === `${name}=true`) {
281
+ return Option.some(true);
282
}
364
-
365
- return normalized;
283
+ return argument === `${name}=false` ? Option.some(false) : Option.none();
284
};
285
286
const normalizeHiddenDebugFlags = (argv: ReadonlyArray<string>): ReadonlyArray<string> => {
369
- const normalized: string[] = [...argv.slice(0, 2)];
370
- const args = argv.slice(2);
287
+ const retainedArgs: Array<string> = [];
288
let perfDebug: boolean | undefined;
289
let toolDebug: boolean | undefined;
290
let acpOnly: boolean | undefined;
291
375
- for (const arg of args) {
376
- if (arg === '--perf-debug') {
377
- perfDebug = true;
378
- continue;
379
- }
380
- if (arg === '--tool-debug') {
381
- toolDebug = true;
382
- continue;
383
- }
384
- if (arg === '--perf-debug=false') {
385
- perfDebug = false;
292
+ for (const argument of Arr.drop(argv, 2)) {
293
+ const parsedPerfDebug = Option.getOrUndefined(parseBooleanFlag(argument, '--perf-debug'));
294
+ if (parsedPerfDebug !== undefined) {
295
+ perfDebug = parsedPerfDebug;
296
continue;
297
}
388
- if (arg === '--tool-debug=false') {
389
- toolDebug = false;
298
+ const parsedToolDebug = Option.getOrUndefined(parseBooleanFlag(argument, '--tool-debug'));
299
+ if (parsedToolDebug !== undefined) {
300
+ toolDebug = parsedToolDebug;
301
continue;
302
}
392
- if (arg === '--perf-debug=true') {
393
- perfDebug = true;
303
+ const parsedAcpOnly = Option.getOrUndefined(parseBooleanFlag(argument, '--acp-only'));
304
+ if (parsedAcpOnly !== undefined) {
305
+ acpOnly = parsedAcpOnly;
306
continue;
307
}
396
- if (arg === '--tool-debug=true') {
397
- toolDebug = true;
398
- continue;
399
- }
400
- if (arg === '--acp-only') {
401
- acpOnly = true;
402
- continue;
403
- }
404
- if (arg === '--acp-only=false') {
405
- acpOnly = false;
406
- continue;
407
- }
408
- if (arg === '--acp-only=true') {
409
- acpOnly = true;
410
- continue;
411
- }
412
- normalized.push(arg);
308
+ retainedArgs.push(argument);
309
}
310
311
resetRuntimeDebugFlags();
313
...(perfDebug === undefined ? {} : { perfDebug }),
314
...(toolDebug === undefined ? {} : { toolDebug }),
315
});
316
+ // The hidden --acp-only flag is stripped from argv before @effect/cli parses it, so its value
317
+ // travels to run.cmd.ts through the environment; effect/Config cannot write or delete env vars.
318
if (acpOnly === undefined) {
319
delete process.env.COMPOSIO_RUN_ACP_ONLY;
320
} else {
321
process.env.COMPOSIO_RUN_ACP_ONLY = acpOnly ? '1' : '0';
322
}
323
426
- return normalized;
324
+ return Arr.appendAll(Arr.take(argv, 2), retainedArgs);
325
};
326
327
const isRootHelp = (argv: ReadonlyArray<string>): boolean => {
351
};
352
353
const normalizeDangerouslyAllowFlag = (argv: ReadonlyArray<string>) => {
456
- const normalized: string[] = [...argv.slice(0, 2)];
354
+ const retainedArgs: Array<string> = [];
355
let dangerouslyAllow = false;
458
-
459
- for (const arg of argv.slice(2)) {
460
- if (arg === '--dangerously-allow') {
356
+ for (const argument of Arr.drop(argv, 2)) {
357
+ if (argument === '--dangerously-allow') {
358
dangerouslyAllow = true;
462
- continue;
359
+ } else {
360
+ retainedArgs.push(argument);
361
}
464
- normalized.push(arg);
362
}
363
364
return {
468
- argv: normalized,
365
+ argv: Arr.appendAll(Arr.take(argv, 2), retainedArgs),
366
dangerouslyAllow,
367
};
368
};
389
return false;
390
};
391
392
+const printCommandHintGraph = Effect.suspend(() =>
393
+ Effect.flatMap(TerminalUI, ui =>
394
+ ui.output(JSON.stringify(renderCommandHintGraph(), null, 2), { force: true })
395
+ )
396
+);
397
+
398
+const printDebugApiInfo = Effect.gen(function* () {
399
+ const ui = yield* TerminalUI;
400
+ const confirmed = yield* ui.confirm(
401
+ 'This will print your current CLI API key and scoped identifiers to stdout. Continue?',
402
+ { defaultValue: false }
403
+ );
404
+ if (!confirmed) {
405
+ return yield* rootCommandError('Aborted printing API credentials.');
406
+ }
407
+ const ctx = yield* ComposioUserContext;
408
+ const apiKey = Option.getOrUndefined(ctx.data.apiKey);
409
+ if (!apiKey) {
410
+ return yield* rootCommandError('No user API key found in the current CLI session.');
411
+ }
412
+ const orgId = Option.getOrUndefined(ctx.data.orgId);
413
+ const consumerProject = yield* resolveCommandProject({ mode: 'consumer' }).pipe(
414
+ Effect.mapError(formatResolveCommandProjectError),
415
+ Effect.option
416
+ );
417
+ return yield* ui.output(
418
+ JSON.stringify(
419
+ {
420
+ apiKey,
421
+ orgId: orgId ?? null,
422
+ consumerUserId:
423
+ Option.isSome(consumerProject) && consumerProject.value.projectType === 'CONSUMER'
424
+ ? (consumerProject.value.consumerUserId ?? null)
425
+ : null,
426
+ },
427
+ null,
428
+ 2
429
+ ),
430
+ { force: true }
431
+ );
432
+});
433
+
434
+const printDetectedMaster = Effect.suspend(() =>
435
+ Effect.flatMap(TerminalUI, ui =>
436
+ ui.output(JSON.stringify({ master: detectMaster() }, null, 2), { force: true })
437
+ )
438
+);
439
+
440
+const printDevModeDisabled = Effect.gen(function* () {
441
+ const ui = yield* TerminalUI;
442
+ yield* ui.log.error('Developer mode is off.');
443
+ yield* ui.log.step('Run `composio dev --mode on` in an interactive terminal to enable it.');
444
+});
445
+
446
export const runWithConfig = Effect.gen(function* () {
447
const cliUserConfig = yield* ComposioCliUserConfig;
448
const visibility: CommandVisibility = {
457
version,
458
});
459
509
- return (argv: ReadonlyArray<string>) => {
510
- const { argv: argvWithoutDangerouslyAllow, dangerouslyAllow } =
511
- normalizeDangerouslyAllowFlag(argv);
512
- const normalizedArgv = normalizeHiddenDebugFlags(
513
- normalizeListenStreamFlag(normalizeVersionShortFlag(argvWithoutDangerouslyAllow))
514
- );
460
+ const routeRootCommand = (normalizedArgv: ReadonlyArray<string>, dangerouslyAllow: boolean) => {
461
const args = normalizedArgv.slice(2);
516
- const installSkillRequest = parseRootInstallSkillRequest(normalizedArgv);
517
- if (installSkillRequest) {
518
- if (installSkillRequest._tag === 'error') {
519
- return Effect.fail(new Error(installSkillRequest.message));
520
- }
521
- return installSkill({
522
- skillName: installSkillRequest.skillName,
523
- target: installSkillRequest.target,
524
- });
525
- }
462
if (isRootHelp(normalizedArgv)) {
463
return printRootHelp(visibility, parseHelpLevel(normalizedArgv[3]) ?? 'default');
464
}
467
const helpLevel = parseHelpLevel(normalizedArgv[normalizedArgv.length - 1]) ?? 'default';
468
return printSubcommandHelp(subHelp, visibility, helpLevel);
469
}
534
- const nestedMismatch = findNestedSubcommandMismatch(normalizedArgv, rootCommand);
535
- if (nestedMismatch) {
536
- return Effect.fail(nestedMismatch);
537
- }
470
const parallelExecute = runParallelToolsExecuteFromArgv(normalizedArgv);
471
if (parallelExecute) {
472
return parallelExecute;
473
}
474
if (isGenerateGraph(normalizedArgv)) {
543
- return Effect.sync(() => {
544
- // eslint-disable-next-line no-restricted-syntax -- migrated with the seam-rules slice (PR 6 of this stack)
545
- process.stdout.write(`${JSON.stringify(renderCommandHintGraph(), null, 2)}\n`);
546
- });
475
+ return printCommandHintGraph;
476
}
477
if (isDebugApiInfo(normalizedArgv)) {
549
- return Effect.gen(function* () {
550
- const ui = yield* TerminalUI;
551
- const confirmed = yield* ui.confirm(
552
- 'This will print your current CLI API key and scoped identifiers to stdout. Continue?',
553
- { defaultValue: false }
554
- );
555
- if (!confirmed) {
556
- return yield* Effect.fail(new Error('Aborted printing API credentials.'));
557
- }
558
- const ctx = yield* ComposioUserContext;
559
- const apiKey = Option.getOrUndefined(ctx.data.apiKey);
560
- if (!apiKey) {
561
- return yield* Effect.fail(new Error('No user API key found in the current CLI session.'));
562
- }
563
- const orgId = Option.getOrUndefined(ctx.data.orgId);
564
- const consumerProject = yield* resolveCommandProject({ mode: 'consumer' }).pipe(
565
- Effect.mapError(formatResolveCommandProjectError),
566
- Effect.option
567
- );
568
- return yield* Effect.sync(() => {
569
- // eslint-disable-next-line no-restricted-syntax -- migrated with the seam-rules slice (PR 6 of this stack)
570
- process.stdout.write(
571
- `${JSON.stringify(
572
- {
573
- apiKey,
574
- orgId: orgId ?? null,
575
- consumerUserId:
576
- Option.isSome(consumerProject) && consumerProject.value.projectType === 'CONSUMER'
577
- ? (consumerProject.value.consumerUserId ?? null)
578
- : null,
579
- },
580
- null,
581
- 2
582
- )}\n`
583
- );
584
- });
585
- });
478
+ return printDebugApiInfo;
479
}
480
if (isDebugWhoIsMyMaster(normalizedArgv)) {
588
- return Effect.sync(() => {
589
- // eslint-disable-next-line no-restricted-syntax -- migrated with the seam-rules slice (PR 6 of this stack)
590
- process.stdout.write(`${JSON.stringify({ master: detectMaster() }, null, 2)}\n`);
591
- });
481
+ return printDetectedMaster;
482
}
483
const executeHelpSlug = parseExecuteInputHelpSlug(normalizedArgv);
484
if (executeHelpSlug) {
485
return showToolsExecuteInputHelp(executeHelpSlug);
486
}
487
if (!visibility.isDevModeEnabled && args[0] === 'dev' && !isDevModeOnlyInvocation(args)) {
598
- return Effect.gen(function* () {
599
- const ui = yield* TerminalUI;
600
- yield* ui.log.error('Developer mode is off.');
601
- yield* ui.log.step('Run `composio dev --mode on` in an interactive terminal to enable it.');
602
- });
488
+ return printDevModeDisabled;
489
}
490
if (isDangerousDevCommand(args)) {
491
return Effect.gen(function* () {
505
return yield* run(normalizedArgv);
506
});
507
}
622
- return run(normalizedArgv);
508
+ return preflightParse(rootCommand, normalizedArgv).pipe(
509
+ Effect.matchEffect({
510
+ onFailure: error =>
511
+ ValidationError.isCommandMismatch(error)
512
+ ? refineRootCommandMismatch(normalizedArgv, visibility, error)
513
+ : run(normalizedArgv),
514
+ onSuccess: () => run(normalizedArgv),
515
+ })
516
+ );
517
+ };
518
+
519
+ return (argv: ReadonlyArray<string>) => {
520
+ const { argv: argvWithoutDangerouslyAllow, dangerouslyAllow } =
521
+ normalizeDangerouslyAllowFlag(argv);
522
+ const normalizedArgv = normalizeHiddenDebugFlags(
523
+ normalizeListenStreamFlag(normalizeVersionShortFlag(argvWithoutDangerouslyAllow))
524
+ );
525
+
526
+ return parseRootInstallSkillRequest(normalizedArgv).pipe(
527
+ Effect.flatMap(
528
+ Option.match({
529
+ onNone: () => routeRootCommand(normalizedArgv, dangerouslyAllow),
530
+ onSome: installSkill,
531
+ })
532
+ )
533
+ );
534
};
535
});