@devries-cameron20 / composio-1 / commits / 46f6449d3
Fork 0

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

refactor(cli): move `tools info` and `tools list` into the directory shape (#4992)

This PR: - moves `tools list` to `tools/list/tools.list.{cmd,handler,format}.ts` and `tools info` to `tools/info/tools.info.{cmd,handler,format}.ts`; each `.cmd.ts` now holds only the argument, flags, description and `Command.make(name, flags, handler)` - `runToolsInfo` routes the missing-slug, not-found and found cases with `Option.match`; `runToolsList` routes the empty and non-empty pages with `Array.match`. Strings, streams and exit codes are unchanged - the only change in `tools/tools.cmd.ts` is its two import paths. `tools.execute.cmd.ts` stays in `tools/commands/` for U4 (#4849, #4754) - moves both `.cmd.test.ts` suites to `test/src/commands/tools/{info,list}/` and adds `tools.info.handler.test.ts` (3 cases: missing slug, exact stdout JSON keys, not found with suggestions and exit 1) and `tools.list.handler.test.ts` (8 cases: filters passed through, limit clamping, stdout JSON, the page-count line, empty-toolkit warnings) - part of the CLI command-layout series (legacy-shape cleanup before U10); no user-visible change, so no CHANGELOG entry ## Context Verified: CLI `pnpm run typecheck`, `pnpm run test` (189 files, 2052 passed; `validate:command-tests` still reports 2 exemptions; `root-help-consistency.test.ts` passes), `lint:effect` (0 errors), oxlint (exit 0), prettier, and root `pnpm typecheck`. Binary smoke: I built the binary on `origin/next` and on this branch and ran both with an isolated HOME. The run covered 29 invocations (`--help`/`help` pages for `tools`, `dev triggers` and `dev logs`, logged-out runs, and parse errors) plus 9 runs with a fake key against an unreachable base URL (`tools info` with and without a slug, `tools list`). stdout, stderr and exit codes are byte-identical; the only difference is minified function names in stack frames, which the comparison masks.

Alberto Schiabel committed Oct 20, 2026 at 19:11 UTC 46f6449d39f138dff37c919650219f626faad9dc
13 files changed +564 -200
ts/packages/cli/src/commands/tools/commands/tools.info.cmd.ts deleted
-113
@@ -1,113 +0,0 @@
1 -import { Argument, Command } from 'effect/cli';
2 -import { Effect, Option } from 'effect';
3 -import { ComposioToolkitsRepository } from 'src/services/composio-clients';
4 -import { TerminalUI } from 'src/services/terminal-ui';
5 -import { handleClientApiError } from 'src/effects/handle-http-error';
6 -import { CLIENT_API_ERROR_TAGS } from 'src/services/composio-errors';
7 -import { getOrFetchToolInputDefinition } from 'src/services/tool-input-validation';
8 -import { normalizeFileUploadSchema } from 'src/services/tool-file-uploads';
9 -import { bold } from 'src/ui/colors';
10 -import { commandHintExample, commandHintStep } from 'src/services/command-hints';
11 -
12 -const slug = Argument.String('slug').pipe(
13 - Argument.withDescription('Tool slug (e.g. "GMAIL_SEND_EMAIL")'),
14 - Argument.optional
15 -);
16 -
17 -/**
18 - * View details of a specific tool including input/output schemas.
19 - *
20 - * @example
21 - * ```bash
22 - * composio tools info "GMAIL_SEND_EMAIL"
23 - * ```
24 - */
25 -export const toolsCmd$Info = Command.make('info', { slug }, ({ slug }) =>
26 - Effect.gen(function* () {
27 - const ui = yield* TerminalUI;
28 - const repo = yield* ComposioToolkitsRepository;
29 -
30 - // Missing slug guard
31 - if (Option.isNone(slug)) {
32 - yield* ui.log.warn('Missing required argument: <slug>');
33 - yield* ui.log.step(
34 - 'Try specifying a tool slug, e.g.:\n> composio tools info "GMAIL_SEND_EMAIL"'
35 - );
36 - return;
37 - }
38 -
39 - const slugValue = slug.value;
40 -
41 - const toolOpt = yield* ui
42 - .withSpinner(`Fetching tool "${slugValue}"...`, repo.getToolDetailed(slugValue))
43 - .pipe(
44 - Effect.asSome,
45 - Effect.catchTag(
46 - CLIENT_API_ERROR_TAGS,
47 - handleClientApiError(ui, {
48 - fallbackMessage: `Tool "${slugValue}" not found.`,
49 - hint: [
50 - commandHintStep('Browse available toolkits', 'dev.toolkits.list'),
51 - commandHintStep('Then list tools', 'root.tools.list'),
52 - ].join('\n'),
53 - fallbackValue: Option.none(),
54 - searchForSuggestions: () =>
55 - repo.searchTools({ search: slugValue, limit: 3 }).pipe(
56 - Effect.map(r =>
57 - r.items.map(s => ({
58 - label: `${s.slug} — ${s.description}`,
59 - command: `> composio tools info "${s.slug}"`,
60 - }))
61 - )
62 - ),
63 - })
64 - )
65 - );
66 -
67 - if (Option.isNone(toolOpt)) {
68 - return;
69 - }
70 -
71 - const tool = toolOpt.value;
72 - const definition = yield* getOrFetchToolInputDefinition(slugValue);
73 - const displaySchema = normalizeFileUploadSchema(definition.schema);
74 -
75 - const summary = [
76 - `${bold('Slug:')} ${tool.slug}`,
77 - `${bold('Name:')} ${tool.name}`,
78 - `${bold('Toolkit:')} ${tool.toolkit.slug}`,
79 - `${bold('Version:')} ${definition.version ?? '-'}`,
80 - `${bold('Description:')} ${tool.description}`,
81 - `${bold('Schema Cache:')} ${definition.schemaPath}`,
82 - ].join('\n');
83 -
84 - yield* ui.note(summary, `Tool: ${tool.name}`);
85 - yield* ui.log.step(
86 - `Inspect schema with jq:\n> jq '{required: (.inputSchema.required // []), keys: (.inputSchema.properties | keys)}' "${definition.schemaPath}"`
87 - );
88 - yield* ui.log.step(
89 - `Then execute it:\n> ${commandHintExample('root.execute', {
90 - slug: tool.slug,
91 - })} --dry-run`
92 - );
93 - yield* ui.output(
94 - JSON.stringify(
95 - {
96 - slug: tool.slug,
97 - name: tool.name,
98 - description: tool.description,
99 - toolkit: tool.toolkit.slug,
100 - version: definition.version,
101 - schemaPath: definition.schemaPath,
102 - inputSchema: displaySchema,
103 - },
104 - null,
105 - 2
106 - )
107 - );
108 - })
109 -).pipe(
110 - Command.withDescription(
111 - 'View a brief summary of a tool and show the CLI-facing input schema used by `composio execute`.'
112 - )
113 -);
ts/packages/cli/src/commands/tools/commands/tools.list.cmd.ts deleted
-85
@@ -1,85 +0,0 @@
1 -import { Argument, Command, Flag } from 'effect/cli';
2 -import { Effect, Option } from 'effect';
3 -import { ComposioToolkitsRepository } from 'src/services/composio-clients';
4 -import { TerminalUI } from 'src/services/terminal-ui';
5 -import { commandHintStep } from 'src/services/command-hints';
6 -import { isRemoteCustomToolkitSlug } from 'src/utils/remote-custom-toolkit';
7 -import { clampLimit } from 'src/ui/clamp-limit';
8 -import { formatToolsTable, formatToolsJson } from '../format';
9 -
10 -const toolkit = Argument.String('toolkit').pipe(
11 - Argument.withDescription('Toolkit slug to list tools for (e.g. "gmail")')
12 -);
13 -
14 -const query = Flag.String('query').pipe(
15 - Flag.withDescription('Text search by name, slug, or description'),
16 - Flag.optional
17 -);
18 -
19 -const tags = Flag.String('tags').pipe(
20 - Flag.withDescription('Filter by tags (e.g. "important")'),
21 - Flag.optional
22 -);
23 -
24 -const limit = Flag.Int('limit').pipe(
25 - Flag.withDefault(30),
26 - Flag.withDescription('Number of results per page (1-1000)')
27 -);
28 -
29 -/**
30 - * List available tools for a toolkit with optional filters.
31 - *
32 - * @example
33 - * ```bash
34 - * composio tools list gmail
35 - * composio tools list gmail --query "send email"
36 - * composio tools list gmail --tags "important" --limit 10
37 - * ```
38 - */
39 -export const toolsCmd$List = Command.make(
40 - 'list',
41 - { toolkit, query, tags, limit },
42 - ({ toolkit, query, tags, limit }) =>
43 - Effect.gen(function* () {
44 - const ui = yield* TerminalUI;
45 - const repo = yield* ComposioToolkitsRepository;
46 -
47 - const clampedLimit = clampLimit(limit);
48 -
49 - const result = yield* ui.withSpinner(
50 - 'Fetching tools...',
51 - repo.searchTools({
52 - search: Option.getOrUndefined(query),
53 - toolkit_slug: toolkit,
54 - tags: Option.getOrUndefined(tags),
55 - limit: clampedLimit,
56 - })
57 - );
58 -
59 - if (result.items.length === 0) {
60 - yield* ui.log.warn(
61 - isRemoteCustomToolkitSlug(toolkit)
62 - ? `No tools found in toolkit "${toolkit}". Custom toolkit tools are served by the Tool Router. ${commandHintStep('Discover them with', 'root.search', { toolkits: toolkit })}`
63 - : `No tools found in toolkit "${toolkit}". Verify the toolkit slug with:\n> composio dev toolkits list`
64 - );
65 - return;
66 - }
67 -
68 - const showing = result.items.length;
69 - const totalPages = result.total_pages;
70 -
71 - yield* ui.log.info(
72 - totalPages > 1
73 - ? `Listing ${showing} tools (page 1 of ${totalPages})\n\n${formatToolsTable(result.items)}`
74 - : `Listing ${showing} tools\n\n${formatToolsTable(result.items)}`
75 - );
76 -
77 - // Next step hint
78 - const firstSlug = result.items[0]?.slug;
79 - if (firstSlug) {
80 - yield* ui.log.step(`To inspect a tool:\n> composio tools info "${firstSlug}"`);
81 - }
82 -
83 - yield* ui.output(formatToolsJson(result.items));
84 - })
85 -).pipe(Command.withDescription('List available tools for a toolkit.'));
ts/packages/cli/src/commands/tools/info/tools.info.cmd.ts new
+13
@@ -0,0 +1,13 @@
1 +import { Argument, Command } from 'effect/cli';
2 +import { runToolsInfo } from './tools.info.handler';
3 +
4 +const slug = Argument.String('slug').pipe(
5 + Argument.withDescription('Tool slug (e.g. "GMAIL_SEND_EMAIL")'),
6 + Argument.optional
7 +);
8 +
9 +export const toolsCmd$Info = Command.make('info', { slug }, runToolsInfo).pipe(
10 + Command.withDescription(
11 + 'View a brief summary of a tool and show the CLI-facing input schema used by `composio execute`.'
12 + )
13 +);
ts/packages/cli/src/commands/tools/info/tools.info.format.ts new
+65
@@ -0,0 +1,65 @@
1 +import type { ToolRetrieveResponse } from '@composio/client/resources/tools';
2 +import { commandHintExample } from 'src/services/command-hints';
3 +import { bold } from 'src/ui/colors';
4 +
5 +/** The cached input definition `tools info` reports: where it lives and which version it is. */
6 +export type ToolInfoDefinition = {
7 + readonly schemaPath: string;
8 + readonly version: string | null;
9 +};
10 +
11 +// --- stderr -----------------------------------------------------------------------------------
12 +
13 +export const MISSING_SLUG_MESSAGE = 'Missing required argument: <slug>';
14 +export const MISSING_SLUG_HINT =
15 + 'Try specifying a tool slug, e.g.:\n> composio tools info "GMAIL_SEND_EMAIL"';
16 +
17 +export const fetchingToolMessage = (slug: string) => `Fetching tool "${slug}"...`;
18 +export const toolNotFoundMessage = (slug: string) => `Tool "${slug}" not found.`;
19 +
20 +/** One "did you mean" suggestion for a slug that was not found. */
21 +export const toolSuggestion = (tool: { readonly slug: string; readonly description: string }) => ({
22 + label: `${tool.slug} — ${tool.description}`,
23 + command: `> composio tools info "${tool.slug}"`,
24 +});
25 +
26 +/** The note body: slug, name, toolkit, version, description, and the schema cache path. */
27 +export const formatToolInfoSummary = (tool: ToolRetrieveResponse, definition: ToolInfoDefinition) =>
28 + [
29 + `${bold('Slug:')} ${tool.slug}`,
30 + `${bold('Name:')} ${tool.name}`,
31 + `${bold('Toolkit:')} ${tool.toolkit.slug}`,
32 + `${bold('Version:')} ${definition.version ?? '-'}`,
33 + `${bold('Description:')} ${tool.description}`,
34 + `${bold('Schema Cache:')} ${definition.schemaPath}`,
35 + ].join('\n');
36 +
37 +export const toolInfoNoteTitle = (tool: ToolRetrieveResponse) => `Tool: ${tool.name}`;
38 +
39 +export const inspectSchemaHint = (definition: ToolInfoDefinition) =>
40 + `Inspect schema with jq:\n> jq '{required: (.inputSchema.required // []), keys: (.inputSchema.properties | keys)}' "${definition.schemaPath}"`;
41 +
42 +export const executeToolHint = (tool: ToolRetrieveResponse) =>
43 + `Then execute it:\n> ${commandHintExample('root.execute', { slug: tool.slug })} --dry-run`;
44 +
45 +// --- stdout -----------------------------------------------------------------------------------
46 +
47 +/** The tool and the CLI-facing input schema `composio execute` validates against. */
48 +export const formatToolInfoJson = (
49 + tool: ToolRetrieveResponse,
50 + definition: ToolInfoDefinition,
51 + inputSchema: unknown
52 +) =>
53 + JSON.stringify(
54 + {
55 + slug: tool.slug,
56 + name: tool.name,
57 + description: tool.description,
58 + toolkit: tool.toolkit.slug,
59 + version: definition.version,
60 + schemaPath: definition.schemaPath,
61 + inputSchema,
62 + },
63 + null,
64 + 2
65 + );
ts/packages/cli/src/commands/tools/info/tools.info.handler.ts new
+98
@@ -0,0 +1,98 @@
1 +import type { ToolRetrieveResponse } from '@composio/client/resources/tools';
2 +import { Effect, Option } from 'effect';
3 +import { handleClientApiError } from 'src/effects/handle-http-error';
4 +import { commandHintStep } from 'src/services/command-hints';
5 +import { ComposioToolkitsRepository } from 'src/services/composio-clients';
6 +import { CLIENT_API_ERROR_TAGS } from 'src/services/composio-errors';
7 +import { TerminalUI } from 'src/services/terminal-ui';
8 +import { normalizeFileUploadSchema } from 'src/services/tool-file-uploads';
9 +import { getOrFetchToolInputDefinition } from 'src/services/tool-input-validation';
10 +import {
11 + MISSING_SLUG_HINT,
12 + MISSING_SLUG_MESSAGE,
13 + executeToolHint,
14 + fetchingToolMessage,
15 + formatToolInfoJson,
16 + formatToolInfoSummary,
17 + inspectSchemaHint,
18 + toolInfoNoteTitle,
19 + toolNotFoundMessage,
20 + toolSuggestion,
21 +} from './tools.info.format';
22 +
23 +/** The arguments of `composio tools info`. */
24 +export type ToolsInfoParams = {
25 + readonly slug: Option.Option<string>;
26 +};
27 +
28 +/** A missing slug is reported as a warning with an example; the command still exits 0. */
29 +const warnMissingSlug = Effect.gen(function* () {
30 + const ui = yield* TerminalUI;
31 + yield* ui.log.warn(MISSING_SLUG_MESSAGE);
32 + yield* ui.log.step(MISSING_SLUG_HINT);
33 +});
34 +
35 +/**
36 + * Fetches the tool, or reports the API failure with "did you mean" suggestions, sets exit
37 + * code 1, and yields nothing.
38 + */
39 +const fetchTool = (slug: string) =>
40 + Effect.gen(function* () {
41 + const ui = yield* TerminalUI;
42 + const repo = yield* ComposioToolkitsRepository;
43 + return yield* ui.withSpinner(fetchingToolMessage(slug), repo.getToolDetailed(slug)).pipe(
44 + Effect.asSome,
45 + Effect.catchTag(
46 + CLIENT_API_ERROR_TAGS,
47 + handleClientApiError(ui, {
48 + fallbackMessage: toolNotFoundMessage(slug),
49 + hint: [
50 + commandHintStep('Browse available toolkits', 'dev.toolkits.list'),
51 + commandHintStep('Then list tools', 'root.tools.list'),
52 + ].join('\n'),
53 + fallbackValue: Option.none<ToolRetrieveResponse>(),
54 + searchForSuggestions: () =>
55 + repo
56 + .searchTools({ search: slug, limit: 3 })
57 + .pipe(Effect.map(result => result.items.map(toolSuggestion))),
58 + })
59 + )
60 + );
61 + });
62 +
63 +const showTool = (slug: string, tool: ToolRetrieveResponse) =>
64 + Effect.gen(function* () {
65 + const ui = yield* TerminalUI;
66 + const definition = yield* getOrFetchToolInputDefinition(slug);
67 +
68 + yield* ui.note(formatToolInfoSummary(tool, definition), toolInfoNoteTitle(tool));
69 + yield* ui.log.step(inspectSchemaHint(definition));
70 + yield* ui.log.step(executeToolHint(tool));
71 + yield* ui.output(
72 + formatToolInfoJson(tool, definition, normalizeFileUploadSchema(definition.schema))
73 + );
74 + });
75 +
76 +/**
77 + * View a brief summary of a tool and the CLI-facing input schema `composio execute` uses.
78 + *
79 + * @example
80 + * ```bash
81 + * composio tools info "GMAIL_SEND_EMAIL"
82 + * ```
83 + */
84 +export const runToolsInfo = ({ slug }: ToolsInfoParams) =>
85 + Effect.gen(function* () {
86 + return yield* Option.match(slug, {
87 + onNone: () => warnMissingSlug,
88 + onSome: slugValue =>
89 + fetchTool(slugValue).pipe(
90 + Effect.flatMap(
91 + Option.match({
92 + onNone: () => Effect.void,
93 + onSome: tool => showTool(slugValue, tool),
94 + })
95 + )
96 + ),
97 + });
98 + });
ts/packages/cli/src/commands/tools/list/tools.list.cmd.ts new
+27
@@ -0,0 +1,27 @@
1 +import { Argument, Command, Flag } from 'effect/cli';
2 +import { runToolsList } from './tools.list.handler';
3 +
4 +const toolkit = Argument.String('toolkit').pipe(
5 + Argument.withDescription('Toolkit slug to list tools for (e.g. "gmail")')
6 +);
7 +
8 +const query = Flag.String('query').pipe(
9 + Flag.withDescription('Text search by name, slug, or description'),
10 + Flag.optional
11 +);
12 +
13 +const tags = Flag.String('tags').pipe(
14 + Flag.withDescription('Filter by tags (e.g. "important")'),
15 + Flag.optional
16 +);
17 +
18 +const limit = Flag.Int('limit').pipe(
19 + Flag.withDefault(30),
20 + Flag.withDescription('Number of results per page (1-1000)')
21 +);
22 +
23 +export const toolsCmd$List = Command.make(
24 + 'list',
25 + { toolkit, query, tags, limit },
26 + runToolsList
27 +).pipe(Command.withDescription('List available tools for a toolkit.'));
ts/packages/cli/src/commands/tools/list/tools.list.format.ts new
+26
@@ -0,0 +1,26 @@
1 +import type { Tool } from 'src/models/tools';
2 +import { commandHintStep } from 'src/services/command-hints';
3 +import { isRemoteCustomToolkitSlug } from 'src/utils/remote-custom-toolkit';
4 +import { formatToolsTable } from '../format';
5 +
6 +// --- stderr -----------------------------------------------------------------------------------
7 +
8 +export const FETCHING_TOOLS_MESSAGE = 'Fetching tools...';
9 +
10 +/**
11 + * The warning for a toolkit with no tools. A custom toolkit's tools are served by the Tool
12 + * Router, so it points at `composio search` instead of the toolkit list.
13 + */
14 +export const noToolsFoundMessage = (toolkit: string) =>
15 + isRemoteCustomToolkitSlug(toolkit)
16 + ? `No tools found in toolkit "${toolkit}". Custom toolkit tools are served by the Tool Router. ${commandHintStep('Discover them with', 'root.search', { toolkits: toolkit })}`
17 + : `No tools found in toolkit "${toolkit}". Verify the toolkit slug with:\n> composio dev toolkits list`;
18 +
19 +/** The count, the page position when there is more than one page, and the table. */
20 +export const formatToolsListing = (tools: ReadonlyArray<Tool>, totalPages: number) =>
21 + totalPages > 1
22 + ? `Listing ${tools.length} tools (page 1 of ${totalPages})\n\n${formatToolsTable(tools)}`
23 + : `Listing ${tools.length} tools\n\n${formatToolsTable(tools)}`;
24 +
25 +export const inspectToolHint = (slug: string) =>
26 + `To inspect a tool:\n> composio tools info "${slug}"`;
ts/packages/cli/src/commands/tools/list/tools.list.handler.ts new
+60
@@ -0,0 +1,60 @@
1 +import { Array as Arr, Effect, Option } from 'effect';
2 +import { ComposioToolkitsRepository } from 'src/services/composio-clients';
3 +import { TerminalUI } from 'src/services/terminal-ui';
4 +import { clampLimit } from 'src/ui/clamp-limit';
5 +import { formatToolsJson } from '../format';
6 +import {
7 + FETCHING_TOOLS_MESSAGE,
8 + formatToolsListing,
9 + inspectToolHint,
10 + noToolsFoundMessage,
11 +} from './tools.list.format';
12 +
13 +/** The arguments and flags of `composio tools list`. */
14 +export type ToolsListParams = {
15 + readonly toolkit: string;
16 + readonly query: Option.Option<string>;
17 + readonly tags: Option.Option<string>;
18 + readonly limit: number;
19 +};
20 +
21 +/**
22 + * List available tools for a toolkit with optional filters. Prints the first page only.
23 + *
24 + * @example
25 + * ```bash
26 + * composio tools list gmail
27 + * composio tools list gmail --query "send email"
28 + * composio tools list gmail --tags "important" --limit 10
29 + * ```
30 + */
31 +export const runToolsList = ({ toolkit, query, tags, limit }: ToolsListParams) =>
32 + Effect.gen(function* () {
33 + const ui = yield* TerminalUI;
34 + const repo = yield* ComposioToolkitsRepository;
35 +
36 + const result = yield* ui.withSpinner(
37 + FETCHING_TOOLS_MESSAGE,
38 + repo.searchTools({
39 + search: Option.getOrUndefined(query),
40 + toolkit_slug: toolkit,
41 + tags: Option.getOrUndefined(tags),
42 + limit: clampLimit(limit),
43 + })
44 + );
45 +
46 + yield* Arr.match(result.items, {
47 + onEmpty: () => ui.log.warn(noToolsFoundMessage(toolkit)),
48 + onNonEmpty: tools =>
49 + Effect.gen(function* () {
50 + yield* ui.log.info(formatToolsListing(tools, result.total_pages));
51 +
52 + const firstSlug = Arr.headNonEmpty(tools).slug;
53 + if (firstSlug) {
54 + yield* ui.log.step(inspectToolHint(firstSlug));
55 + }
56 +
57 + yield* ui.output(formatToolsJson(tools));
58 + }),
59 + });
60 + });
ts/packages/cli/src/commands/tools/tools.cmd.ts
+2 -2
@@ -1,7 +1,7 @@
1 import { requireLogin } from 'src/effects/require-auth';
2 import { Command } from 'effect/cli';
3 -import { toolsCmd$List } from './commands/tools.list.cmd';
4 -import { toolsCmd$Info } from './commands/tools.info.cmd';
3 +import { toolsCmd$List } from './list/tools.list.cmd';
4 +import { toolsCmd$Info } from './info/tools.info.cmd';
5
6 export const rootToolsCmd = Command.make('tools').pipe(
7 Command.withDescription('Browse and inspect tools before executing them.'),
ts/packages/cli/test/src/commands/tools/info/tools.info.cmd.test.ts renamed
ts/packages/cli/test/src/commands/tools/info/tools.info.handler.test.ts new
+111
@@ -0,0 +1,111 @@
1 +import { afterEach, describe, expect, it } from '@effect/vitest';
2 +import { ConfigProvider, Effect, Option } from 'effect';
3 +import { runToolsInfo } from 'src/commands/tools/info/tools.info.handler';
4 +import {
5 + MISSING_SLUG_HINT,
6 + MISSING_SLUG_MESSAGE,
7 + toolNotFoundMessage,
8 +} from 'src/commands/tools/info/tools.info.format';
9 +import type { Tools } from 'src/models/tools';
10 +import { TerminalUI } from 'src/services/terminal-ui';
11 +import { MockConsole, TestLive } from 'test/__utils__';
12 +import { terminalUITestImpl } from 'test/__utils__/services/terminal-ui-test';
13 +
14 +const TOOLS: Tools = [
15 + {
16 + name: 'Send Email',
17 + slug: 'GMAIL_SEND_EMAIL',
18 + description: 'Sends an email',
19 + tags: ['email'],
20 + available_versions: ['20260101_00'],
21 + input_parameters: {
22 + type: 'object',
23 + properties: { recipient: { type: 'string' } },
24 + required: ['recipient'],
25 + },
26 + output_parameters: { type: 'object', properties: {} },
27 + },
28 +];
29 +
30 +/**
31 + * The `TestLive` stack with the tool catalog above and a terminal whose stdout data lands in
32 + * `outputs`; `runToolsInfo` is called without argv.
33 + */
34 +const toolsInfoTest = () => {
35 + const outputs: Array<string> = [];
36 + const layer = TestLive({
37 + baseConfigProvider: ConfigProvider.fromEnv({
38 + env: { COMPOSIO_USER_API_KEY: 'test_api_key' },
39 + }),
40 + toolkitsData: { tools: TOOLS },
41 + terminalUI: TerminalUI.of({
42 + ...terminalUITestImpl,
43 + output: data =>
44 + Effect.sync(() => {
45 + outputs.push(data);
46 + }),
47 + }),
48 + });
49 + return { layer, outputs };
50 +};
51 +
52 +describe('runToolsInfo', () => {
53 + afterEach(() => {
54 + process.exitCode = undefined;
55 + });
56 +
57 + it.effect('[Given] no slug [Then] warns with an example and keeps exit code 0', () => {
58 + const { layer, outputs } = toolsInfoTest();
59 + return Effect.gen(function* () {
60 + yield* runToolsInfo({ slug: Option.none() });
61 +
62 + expect(yield* MockConsole.getLines()).toEqual([MISSING_SLUG_MESSAGE, MISSING_SLUG_HINT]);
63 + expect(outputs).toEqual([]);
64 + expect(process.exitCode).toBeUndefined();
65 + }).pipe(Effect.provide(layer));
66 + });
67 +
68 + it.effect('[Given] a known slug [Then] prints the tool and its cached input schema', () => {
69 + const { layer, outputs } = toolsInfoTest();
70 + return Effect.gen(function* () {
71 + yield* runToolsInfo({ slug: Option.some('GMAIL_SEND_EMAIL') });
72 +
73 + expect(outputs).toHaveLength(1);
74 + const printed = JSON.parse(outputs[0] ?? '{}') as Record<string, unknown>;
75 + expect(Object.keys(printed)).toEqual([
76 + 'slug',
77 + 'name',
78 + 'description',
79 + 'toolkit',
80 + 'version',
81 + 'schemaPath',
82 + 'inputSchema',
83 + ]);
84 + expect(printed).toMatchObject({
85 + slug: 'GMAIL_SEND_EMAIL',
86 + name: 'Send Email',
87 + description: 'Sends an email',
88 + toolkit: 'gmail',
89 + inputSchema: TOOLS[0]?.input_parameters,
90 + });
91 + expect(printed.schemaPath).toMatch(/\/tool_definitions\/GMAIL_SEND_EMAIL\.json$/);
92 + expect(process.exitCode).toBeUndefined();
93 + }).pipe(Effect.provide(layer));
94 + });
95 +
96 + it.effect(
97 + '[Given] an unknown slug [Then] reports it with suggestions, prints nothing, and exits 1',
98 + () => {
99 + const { layer, outputs } = toolsInfoTest();
100 + return Effect.gen(function* () {
101 + yield* runToolsInfo({ slug: Option.some('GMAIL_SEND') });
102 + const output = (yield* MockConsole.getLines({ stripAnsi: true })).join('\n');
103 +
104 + expect(output).toContain(toolNotFoundMessage('GMAIL_SEND'));
105 + expect(output).toContain('> composio tools info "GMAIL_SEND_EMAIL"');
106 + expect(outputs).toEqual([]);
107 + expect(process.exitCode).toBe(1);
108 + }).pipe(Effect.provide(layer));
109 + }
110 + );
111 +});
ts/packages/cli/test/src/commands/tools/list/tools.list.cmd.test.ts renamed
ts/packages/cli/test/src/commands/tools/list/tools.list.handler.test.ts new
+162
@@ -0,0 +1,162 @@
1 +import { describe, expect, it } from '@effect/vitest';
2 +import { Console, Effect, Layer, Option } from 'effect';
3 +import { runToolsList, type ToolsListParams } from 'src/commands/tools/list/tools.list.handler';
4 +import { noToolsFoundMessage } from 'src/commands/tools/list/tools.list.format';
5 +import type { Tools } from 'src/models/tools';
6 +import {
7 + ComposioToolkitsRepository,
8 + type ComposioToolkitsRepositoryShape,
9 +} from 'src/services/composio-clients';
10 +import { TerminalUI } from 'src/services/terminal-ui';
11 +import { MockConsole } from 'test/__utils__';
12 +import { resolveToolkitsTestData, toolkitCatalogMethods } from 'test/__utils__/layers/toolkits';
13 +import { terminalUITestImpl } from 'test/__utils__/services/terminal-ui-test';
14 +import { makeToolkitsRepositoryStub } from 'test/__utils__/services/toolkits-repository-stub';
15 +
16 +const tool = (slug: string, name: string, tags: ReadonlyArray<string> = []): Tools[number] => ({
17 + slug,
18 + name,
19 + description: `${name} description`,
20 + tags: [...tags],
21 + available_versions: ['20260101_00'],
22 + input_parameters: { type: 'object', properties: {} },
23 + output_parameters: { type: 'object', properties: {} },
24 +});
25 +
26 +const TOOLS: Tools = [
27 + tool('GMAIL_SEND_EMAIL', 'Send Email', ['email']),
28 + tool('GMAIL_CREATE_DRAFT', 'Create Draft', ['email']),
29 + tool('GMAIL_FETCH_EMAILS', 'Fetch Emails'),
30 +];
31 +
32 +type SearchToolsParams = Parameters<ComposioToolkitsRepositoryShape['searchTools']>[0];
33 +
34 +/**
35 + * What `runToolsList` reads: the tool catalog, whose `searchTools` requests land in
36 + * `requests`, and a headless terminal whose stdout data lands in `outputs`.
37 + */
38 +const toolsListTest = (tools: Tools = TOOLS) => {
39 + const outputs: Array<string> = [];
40 + const requests: Array<SearchToolsParams> = [];
41 + const catalog = toolkitCatalogMethods(resolveToolkitsTestData({ tools }));
42 + const layer = Layer.mergeAll(
43 + Layer.effect(Console.Console, MockConsole.make),
44 + Layer.succeed(
45 + TerminalUI,
46 + TerminalUI.of({
47 + ...terminalUITestImpl,
48 + output: data =>
49 + Effect.sync(() => {
50 + outputs.push(data);
51 + }),
52 + })
53 + ),
54 + Layer.succeed(
55 + ComposioToolkitsRepository,
56 + makeToolkitsRepositoryStub({
57 + searchTools: params =>
58 + Effect.suspend(() => {
59 + requests.push(params);
60 + return catalog.searchTools(params);
61 + }),
62 + })
63 + )
64 + );
65 + return { layer, outputs, requests };
66 +};
67 +
68 +const params = (overrides: Partial<ToolsListParams> = {}): ToolsListParams => ({
69 + toolkit: 'gmail',
70 + query: Option.none(),
71 + tags: Option.none(),
72 + limit: 30,
73 + ...overrides,
74 +});
75 +
76 +describe('runToolsList', () => {
77 + it.effect('[Given] filters [Then] passes them to the catalog search as given', () => {
78 + const { layer, requests } = toolsListTest();
79 + return Effect.gen(function* () {
80 + yield* runToolsList(
81 + params({ query: Option.some('send'), tags: Option.some('email,important') })
82 + );
83 +
84 + expect(requests).toEqual([
85 + { search: 'send', toolkit_slug: 'gmail', tags: 'email,important', limit: 30 },
86 + ]);
87 + }).pipe(Effect.provide(layer));
88 + });
89 +
90 + it.effect.each([
91 + { limit: 0, expected: 1 },
92 + { limit: -3, expected: 1 },
93 + { limit: 1001, expected: 1000 },
94 + ])('[Given] limit $limit [Then] requests $expected tools', ({ limit, expected }) => {
95 + const { layer, requests } = toolsListTest();
96 + return Effect.gen(function* () {
97 + yield* runToolsList(params({ limit }));
98 +
99 + expect(requests.map(request => request.limit)).toEqual([expected]);
100 + }).pipe(Effect.provide(layer));
101 + });
102 +
103 + it.effect('[Given] one page of tools [Then] lists them and prints them as JSON', () => {
104 + const { layer, outputs } = toolsListTest();
105 + return Effect.gen(function* () {
106 + yield* runToolsList(params());
107 + const lines = yield* MockConsole.getLines({ stripAnsi: true });
108 +
109 + expect(lines[0]).toBe('Fetching tools...');
110 + expect(lines[1]).toMatch(/^Listing 3 tools\n\n/);
111 + expect(lines[2]).toBe('To inspect a tool:\n> composio tools info "GMAIL_SEND_EMAIL"');
112 + expect(outputs.map(output => JSON.parse(output))).toEqual([
113 + [
114 + {
115 + slug: 'GMAIL_SEND_EMAIL',
116 + name: 'Send Email',
117 + description: 'Send Email description',
118 + tags: ['email'],
119 + },
120 + {
121 + slug: 'GMAIL_CREATE_DRAFT',
122 + name: 'Create Draft',
123 + description: 'Create Draft description',
124 + tags: ['email'],
125 + },
126 + {
127 + slug: 'GMAIL_FETCH_EMAILS',
128 + name: 'Fetch Emails',
129 + description: 'Fetch Emails description',
130 + tags: [],
131 + },
132 + ],
133 + ]);
134 + }).pipe(Effect.provide(layer));
135 + });
136 +
137 + it.effect('[Given] more tools than the limit [Then] names the first of several pages', () => {
138 + const { layer, outputs } = toolsListTest();
139 + return Effect.gen(function* () {
140 + yield* runToolsList(params({ limit: 2 }));
141 + const lines = yield* MockConsole.getLines({ stripAnsi: true });
142 +
143 + expect(lines[1]).toMatch(/^Listing 2 tools \(page 1 of 2\)\n\n/);
144 + expect(JSON.parse(outputs[0] ?? '[]')).toHaveLength(2);
145 + }).pipe(Effect.provide(layer));
146 + });
147 +
148 + it.effect.each(['gmail', 'custom_grain'])(
149 + '[Given] no tools in toolkit %s [Then] warns and prints nothing on stdout',
150 + toolkit => {
151 + const { layer, outputs } = toolsListTest([]);
152 + return Effect.gen(function* () {
153 + yield* runToolsList(params({ toolkit }));
154 +
155 + expect(outputs).toEqual([]);
156 + expect(yield* MockConsole.getLines({ stream: 'stderr' })).toEqual([
157 + noToolsFoundMessage(toolkit),
158 + ]);
159 + }).pipe(Effect.provide(layer));
160 + }
161 + );
162 +});