@devries-cameron20 / composio Mirror · read-only / commits / 8891a6635
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.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 13:30 UTC

fix(cli): bare --stream, dead Slack slug in help, tools info exit code, unknown listen slug

- listen: rewrite a bare `--stream` to `--stream ''` instead of `--stream=`; @effect/cli only accepts `--flag=value` with a non-empty value, so the previous rewrite failed with "Received unknown argument: '--stream='". - help: replace SLACK_SEND_A_MESSAGE_TO_A_SLACK_CHANNEL (404 from the API) with SLACK_SEND_MESSAGE and its `markdown_text` input; use SLACK_CHANNEL_MESSAGE_RECEIVED with `channel_id` for the listen `-p` example since SLACK_RECEIVE_MESSAGE has an empty config schema. - handle-http-error: set process.exitCode = 1 and print the message plainly when stderr is not a TTY, so `tools info <bad-slug>` no longer prints nothing and exits 0. - listen: when no active connected account matches, retrieve the trigger type and report an unknown slug on 404 instead of a missing connection. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

2nishantg committed Sep 3, 2026 at 18:12 UTC 8891a663577450d56665bbf3d8c29afb9b9a18cf
8 files changed +174 -9
ts/packages/cli/skills-src/composio-cli/index.ts
+1 -1
@@ -147,7 +147,7 @@ const commands: SkillCommand[] = [
147 'Use `listen` for temporary trigger subscriptions in consumer projects, especially when background agents should consume new event payloads from artifact files.',
148 examples: [
149 {
150 - code: "composio listen GMAIL_NEW_GMAIL_MESSAGE\ncomposio listen SLACK_RECEIVE_MESSAGE -p '{ trigger_config: { channel: \"C123\" } }'\ncomposio listen GMAIL_NEW_GMAIL_MESSAGE --stream\ncomposio listen GMAIL_NEW_GMAIL_MESSAGE --stream '.data.threadId'\ncomposio listen GMAIL_NEW_GMAIL_MESSAGE --timeout 5m\ncomposio listen GMAIL_NEW_GMAIL_MESSAGE -p @trigger.json --max-events 5",
150 + code: "composio listen GMAIL_NEW_GMAIL_MESSAGE\ncomposio listen SLACK_CHANNEL_MESSAGE_RECEIVED -p '{ trigger_config: { channel_id: \"C123\" } }'\ncomposio listen GMAIL_NEW_GMAIL_MESSAGE --stream\ncomposio listen GMAIL_NEW_GMAIL_MESSAGE --stream '.data.threadId'\ncomposio listen GMAIL_NEW_GMAIL_MESSAGE --timeout 5m\ncomposio listen GMAIL_NEW_GMAIL_MESSAGE -p @trigger.json --max-events 5",
151 },
152 ],
153 flags: [
ts/packages/cli/src/commands/index.ts
+8 -3
@@ -267,13 +267,18 @@ const normalizeListenStreamFlag = (argv: ReadonlyArray<string>): ReadonlyArray<s
267 return argv;
268 }
269
270 + // `--stream` is documented as taking an optional value, but @effect/cli text options always
271 + // require one. A bare `--stream` therefore has to be rewritten. `--stream=` cannot be used for
272 + // that: @effect/cli only recognizes `--flag=value` when the value is non-empty, so `--stream=`
273 + // surfaces as "Received unknown argument". Passing an explicit empty string as the next token
274 + // parses cleanly and the listen command treats an empty path as "stream the whole payload".
275 return Arr.appendAll(
276 head,
272 - Arr.map(args, (token, index) => {
277 + Arr.flatMap(args, (token, index) => {
278 const next = args[index + 1];
279 return token === '--stream' && (next === undefined || next.startsWith('-'))
275 - ? '--stream='
276 - : token;
280 + ? ['--stream', '']
281 + : [token];
282 })
283 );
284 };
ts/packages/cli/src/commands/listen.cmd.ts
+36
@@ -34,6 +34,7 @@ export class ListenCommandError extends Data.TaggedError('commands/ListenCommand
34 | 'project_context'
35 | 'connected_accounts'
36 | 'connected_account_not_found'
37 + | 'unknown_trigger'
38 | 'create_trigger'
39 | 'disable_trigger';
40 readonly message: string;
@@ -144,6 +145,39 @@ const assertSupportedListenParams = (params: {
145 )
146 : Effect.void;
147
148 +const isNotFoundError = (cause: unknown): boolean =>
149 + Predicate.hasProperty(cause, 'status') && cause.status === 404;
150 +
151 +/**
152 + * Fails with an `unknown_trigger` error when `slug` is not a known trigger type.
153 + *
154 + * Only called once no active connected account matched, so a mistyped slug is reported as such
155 + * instead of as a missing connection for the toolkit inferred from its prefix.
156 + */
157 +const assertTriggerTypeExists = (params: {
158 + client: RawComposioClient;
159 + slug: string;
160 + toolkitSlug: string;
161 +}) =>
162 + Effect.tryPromise({
163 + try: () => params.client.triggersTypes.retrieve(params.slug),
164 + catch: cause => cause,
165 + }).pipe(
166 + Effect.asVoid,
167 + Effect.catchAll(cause =>
168 + isNotFoundError(cause)
169 + ? new ListenCommandError({
170 + reason: 'unknown_trigger',
171 + message: `Unknown trigger slug "${params.slug}". List available slugs with \`composio triggers list <toolkit>\`.`,
172 + slug: params.slug,
173 + toolkitSlug: params.toolkitSlug,
174 + cause,
175 + })
176 + : // Any other failure is inconclusive; fall through to the connected-account error.
177 + Effect.void
178 + )
179 + );
180 +
181 const resolveConnectedAccountIdForTrigger = (params: {
182 client: RawComposioClient;
183 slug: string;
@@ -197,6 +231,8 @@ const resolveConnectedAccountIdForTrigger = (params: {
231 return selectedAccount.id;
232 }
233
234 + yield* assertTriggerTypeExists({ client: params.client, slug: params.slug, toolkitSlug });
235 +
236 const choices = formatConnectedAccountChoices(selectableAccounts);
237 const suffix =
238 Option.isSome(params.account) && choices.length > 0
ts/packages/cli/src/commands/root-help.ts
+4 -4
@@ -486,7 +486,7 @@ const SUBCOMMAND_HELP: Record<string, SubcommandHelp | TaggedValue<SubcommandHel
486 `composio execute GITHUB_CREATE_ISSUE --account work -d '{ owner: "acme", repo: "app", title: "Bug report", body: "Steps to reproduce..." }'`,
487 '',
488 '# Preview what a tool call would send without executing',
489 - `composio execute SLACK_SEND_A_MESSAGE_TO_A_SLACK_CHANNEL --dry-run -d '{ channel: "general", text: "Hello team" }'`,
489 + `composio execute SLACK_SEND_MESSAGE --dry-run -d '{ channel: "general", markdown_text: "Hello team" }'`,
490 '',
491 '# Check what inputs a tool needs',
492 'composio execute GMAIL_SEND_EMAIL --get-schema',
@@ -539,7 +539,7 @@ const SUBCOMMAND_HELP: Record<string, SubcommandHelp | TaggedValue<SubcommandHel
539 'composio listen GMAIL_NEW_GMAIL_MESSAGE -p @trigger.json --max-events 5',
540 'composio listen GMAIL_NEW_GMAIL_MESSAGE --account work --timeout 5m',
541 "composio listen GMAIL_NEW_GMAIL_MESSAGE --timeout 1hr --stream '.data.threadId'",
542 - 'composio listen SLACK_RECEIVE_MESSAGE -p \'{ trigger_config: { channel: "C123" } }\'',
542 + 'composio listen SLACK_CHANNEL_MESSAGE_RECEIVED -p \'{ trigger_config: { channel_id: "C123" } }\'',
543 'composio listen GMAIL_NEW_GMAIL_MESSAGE -p @trigger.json --stream',
544 "composio listen GMAIL_NEW_GMAIL_MESSAGE -p @trigger.json --stream '.data.threadId'",
545 ],
@@ -767,7 +767,7 @@ const SUBCOMMAND_HELP: Record<string, SubcommandHelp | TaggedValue<SubcommandHel
767 '# Sequential: chain tool outputs across services',
768 `composio run '`,
769 ` const issue = await execute("GITHUB_CREATE_ISSUE", { owner: "acme", repo: "app", title: "Deploy v2" });`,
770 - ` await execute("SLACK_SEND_A_MESSAGE_TO_A_SLACK_CHANNEL", { channel: "eng", text: "Created: " + issue.data.html_url });`,
770 + ` await execute("SLACK_SEND_MESSAGE", { channel: "eng", markdown_text: "Created: " + issue.data.html_url });`,
771 `'`,
772 '',
773 '# Parallel: fetch from multiple services at once with Promise.all',
@@ -1526,7 +1526,7 @@ export function printRootHelp(
1526 '',
1527 ` ${dim('# Execute multiple tools in parallel')}`,
1528 ` ${name} execute -p GMAIL_SEND_EMAIL -d '{ recipient_email: "a@b.com", subject: "Hi" }' \\`,
1529 - ` SLACK_SEND_A_MESSAGE_TO_A_SLACK_CHANNEL -d '{ channel: "general", text: "Hello" }'`,
1529 + ` SLACK_SEND_MESSAGE -d '{ channel: "general", markdown_text: "Hello" }'`,
1530 '',
1531 ` ${dim('# Call an API directly through proxy')}`,
1532 ` ${name} proxy https://gmail.googleapis.com/gmail/v1/users/me/profile --toolkit gmail`,
ts/packages/cli/src/effects/handle-http-error.ts
+13
@@ -1,3 +1,4 @@
1 +import process from 'node:process';
2 import { Effect } from 'effect';
3 import type { HttpServerError } from 'src/services/composio-clients';
4 import type { TerminalUI } from 'src/services/terminal-ui';
@@ -13,6 +14,10 @@ const noSuggestions: ReadonlyArray<Suggestion> = [];
14 * Create an HttpServerError handler that logs the structured error details
15 * (or a fallback message) and a contextual hint, then returns a fallback value.
16 *
17 + * The process exit code is set to 1 so callers such as scripts and agents can
18 + * detect the failure. Decorated logs only render when stderr is a TTY, so the
19 + * error message is also written plainly to stderr when it is not.
20 + *
21 * Used by info/delete/create commands that share the same error-handling shape.
22 *
23 * When `searchForSuggestions` is provided, the handler will attempt to find
@@ -48,6 +53,14 @@ export const handleHttpServerError =
53 ) =>
54 (e: HttpServerError) =>
55 Effect.gen(function* () {
56 + process.exitCode = 1;
57 +
58 + const message = e.details ? e.details.message : opts.fallbackMessage;
59 + const { canDecorate } = yield* ui.capabilities;
60 + if (!canDecorate) {
61 + yield* ui.error(message);
62 + }
63 +
64 if (e.details) {
65 yield* ui.log.error(e.details.message);
66 yield* ui.log.step(e.details.suggestedFix);
ts/packages/cli/test/__utils__/services/test-layer.ts
+13
@@ -1092,6 +1092,19 @@ export const TestLayer = (input?: TestLiveInput) =>
1092 return {};
1093 },
1094 },
1095 + triggersTypes: {
1096 + retrieve: async (slug: string) => {
1097 + const found = toolkitsData.triggerTypes.find(
1098 + trigger => trigger.slug.toUpperCase() === slug.toUpperCase()
1099 + );
1100 + if (!found) {
1101 + throw Object.assign(new Error(`404 Trigger type "${slug}" not found`), {
1102 + status: 404,
1103 + });
1104 + }
1105 + return found;
1106 + },
1107 + },
1108 triggerInstances: {
1109 upsert: async (
1110 triggerSlug: string,
ts/packages/cli/test/src/commands/listen.cmd.test.ts
+76
@@ -59,6 +59,45 @@ describe('CLI: composio listen', () => {
59 expect(output).not.toContain('Temporary trigger disabled');
60 })
61 );
62 +
63 + it.scoped('[Then] a bare --stream flag prints the whole event payload inline', () =>
64 + Effect.gen(function* () {
65 + yield* enableListen;
66 + yield* cli([
67 + 'listen',
68 + 'composio.connected_account.expired',
69 + '--max-events',
70 + '1',
71 + '--stream',
72 + ]);
73 +
74 + const lines = yield* MockConsole.getLines({ stripAnsi: true });
75 + const output = lines.join('\n');
76 +
77 + expect(output).not.toContain('Received unknown argument');
78 + expect(output).toContain('stream: ');
79 + expect(output).toContain('"data":{"id":"con_expired_1"}');
80 + })
81 + );
82 +
83 + it.scoped('[Then] a bare --stream flag followed by another option is not swallowed', () =>
84 + Effect.gen(function* () {
85 + yield* enableListen;
86 + yield* cli([
87 + 'listen',
88 + 'composio.connected_account.expired',
89 + '--stream',
90 + '--max-events',
91 + '1',
92 + ]);
93 +
94 + const lines = yield* MockConsole.getLines({ stripAnsi: true });
95 + const output = lines.join('\n');
96 +
97 + expect(output).toContain('stream: ');
98 + expect(output).toContain('Stopped after receiving 1 event.');
99 + })
100 + );
101 });
102
103 layer(
@@ -129,6 +168,20 @@ describe('CLI: composio listen', () => {
168 TestLive({
169 baseConfigProvider: testConfigProvider,
170 fixture: 'global-test-user-id',
171 + toolkitsData: {
172 + triggerTypes: [
173 + {
174 + slug: 'GMAIL_NEW_GMAIL_MESSAGE',
175 + name: 'New Gmail Message',
176 + description: 'Fires when a new email arrives.',
177 + instructions: '',
178 + type: 'poll',
179 + config: {},
180 + payload: {},
181 + toolkit: { name: 'Gmail', slug: 'gmail' },
182 + },
183 + ],
184 + },
185 })
186 )('listen validation and domain failures', it => {
187 it.scoped('reports malformed trigger params as CLI input validation', () =>
@@ -183,5 +236,28 @@ describe('CLI: composio listen', () => {
236 }
237 })
238 );
239 +
240 + it.scoped('reports an unknown trigger slug instead of a missing connection', () =>
241 + Effect.gen(function* () {
242 + yield* enableListen;
243 + const exit = yield* Effect.exit(cli(['listen', 'BOGUS_SLUG_XYZ']));
244 +
245 + expect(Exit.isFailure(exit)).toBe(true);
246 + if (Exit.isFailure(exit)) {
247 + const failure = Cause.squash(exit.cause);
248 + expect(failure).toBeInstanceOf(ListenCommandError);
249 + if (failure instanceof ListenCommandError) {
250 + expect(failure).toMatchObject({
251 + reason: 'unknown_trigger',
252 + slug: 'BOGUS_SLUG_XYZ',
253 + toolkitSlug: 'bogus',
254 + });
255 + expect(failure.message).toContain('Unknown trigger slug "BOGUS_SLUG_XYZ"');
256 + expect(failure.message).toContain('composio triggers list <toolkit>');
257 + expect(failure.message).not.toContain('composio link');
258 + }
259 + }
260 + })
261 + );
262 });
263 });
ts/packages/cli/test/src/commands/tools/tools.info.cmd.test.ts
+23 -1
@@ -1,4 +1,4 @@
1 -import { describe, expect, layer } from '@effect/vitest';
1 +import { afterEach, describe, expect, layer } from '@effect/vitest';
2 import { ConfigProvider, Effect } from 'effect';
3 import { extendConfigProvider } from 'src/services/config';
4 import { cli, TestLive, MockConsole } from 'test/__utils__';
@@ -89,6 +89,10 @@ const testConfigProvider = ConfigProvider.fromMap(
89 ).pipe(extendConfigProvider);
90
91 describe('CLI: composio tools info', () => {
92 + afterEach(() => {
93 + process.exitCode = undefined;
94 + });
95 +
96 layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))(
97 '[Given] valid slug [Then] displays tool info',
98 it => {
@@ -168,6 +172,24 @@ describe('CLI: composio tools info', () => {
172 expect(output).toContain('not found');
173 })
174 );
175 +
176 + it.scoped('exits non-zero and reports the missing tool', () =>
177 + Effect.gen(function* () {
178 + yield* cli(['tools', 'info', 'NONEXISTENT_TOOL']);
179 + const lines = yield* MockConsole.getLines({ stripAnsi: true });
180 +
181 + expect(lines.join('\n')).toContain('Tool "NONEXISTENT_TOOL" not found.');
182 + expect(process.exitCode).toBe(1);
183 + })
184 + );
185 +
186 + it.scoped('keeps a zero exit code for a valid slug', () =>
187 + Effect.gen(function* () {
188 + yield* cli(['tools', 'info', 'GMAIL_SEND_EMAIL']);
189 +
190 + expect(process.exitCode).toBeUndefined();
191 + })
192 + );
193 }
194 );
195