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

next
ts 48 lines 1.66 KB
Raw
1 import type { Command } from 'effect/cli';
2 import { buildRootCommand } from 'src/commands';
3 import type { CommandVisibility } from 'src/commands/feature-tags';
4 import {
5 childIdentity,
6 type CommandIdentity,
7 ROOT_IDENTITY,
8 } from 'src/invocation/command-identity';
9
10 /** Developer mode on and every experimental feature enabled: the whole command tree. */
11 export const EVERY_FEATURE: CommandVisibility = {
12 isDevModeEnabled: true,
13 isExperimentalFeatureEnabled: () => true,
14 };
15
16 /** One command registration of the tree, as `withRegisteredSubcommands` identifies it. */
17 export interface Registration {
18 readonly identity: CommandIdentity;
19 readonly command: Command.Command.Any;
20 /** The registration, or a group above it, is `Command.unlisted`. */
21 readonly unlisted: boolean;
22 }
23
24 const subcommandsOf = (command: Command.Command.Any) =>
25 command.subcommands.flatMap(group => group.commands);
26
27 /**
28 * Every registration under `root` (the root first, then depth first in registration order),
29 * walked through the public `Command` fields only. `help`'s mirror of the tree is left out below
30 * `help` itself.
31 */
32 export const registrationsOf = (
33 root: Command.Command.Any = buildRootCommand(EVERY_FEATURE)
34 ): ReadonlyArray<Registration> => {
35 const walk = (
36 command: Command.Command.Any,
37 identity: CommandIdentity,
38 unlisted: boolean
39 ): ReadonlyArray<Registration> => [
40 { identity, command, unlisted },
41 ...(identity.path.length === 1 && identity.path[0] === 'help'
42 ? []
43 : subcommandsOf(command).flatMap(child =>
44 walk(child, childIdentity(identity, child), unlisted || child.unlisted)
45 )),
46 ];
47 return walk(root, ROOT_IDENTITY, false);
48 };