@devries-cameron20 / composio-1 / commits / f91fa9994
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): align triggers table output with tools list style

Reuse command formatter helpers for trigger table rows, switch table mode to plain line emission to avoid extra vertical spacing, and update tests for title-cased headers with truncated slug display. Co-authored-by: Cursor <cursoragent@cursor.com>

haxzie committed Feb 23, 2026 at 18:38 UTC f91fa999430aec2950d644ff6bce002fafcf7fbe
3 files changed +77 -47
ts/packages/cli/src/commands/triggers/commands/triggers.listen.cmd.ts
+25 -40
@@ -1,12 +1,17 @@
1 import { Command, Options } from '@effect/cli';
2 import { Deferred, Effect, Option, Runtime } from 'effect';
3 import path from 'node:path';
4 +import process from 'node:process';
5 import { promises as fs } from 'node:fs';
6 import { requireAuth } from 'src/effects/require-auth';
7 import { TerminalUI } from 'src/services/terminal-ui';
8 import { TriggersRealtime } from 'src/services/triggers-realtime';
9 import { matchesTriggerListenFilters } from '../filter';
9 -import { formatTriggerListenSummary } from '../format';
10 +import {
11 + formatTriggerListenSummary,
12 + formatTriggerListenTableHeader,
13 + formatTriggerListenTableRow,
14 +} from '../format';
15 import { parseTriggerListenEvent } from '../parse';
16 import type { TriggerListenFilters } from '../types';
17
@@ -127,23 +132,16 @@ const detectWebhookPayloadVersion = (eventData: Record<string, unknown>): 'V1' |
132 return 'V1';
133 };
134
130 -const TABLE_COLUMNS = [
131 - { key: 'timestamp', width: 25 },
132 - { key: 'trigger_id', width: 16 },
133 - { key: 'trigger_slug', width: 28 },
134 - { key: 'toolkit', width: 12 },
135 - { key: 'user_id', width: 24 },
136 - { key: 'connected_account_id', width: 24 },
137 -] as const;
138 -
139 -const formatTableCell = (value: string, width: number): string => {
140 - if (value.length <= width) return value.padEnd(width, ' ');
141 - if (width <= 1) return value.slice(0, width);
142 - return `${value.slice(0, width - 1)}…`;
143 -};
144 -
145 -const formatTableRow = (columns: ReadonlyArray<{ value: string; width: number }>): string =>
146 - columns.map(col => formatTableCell(col.value, col.width)).join(' | ');
135 +const emitTableLine = (line: string, ui: TerminalUI): Effect.Effect<void> =>
136 + Effect.gen(function* () {
137 + if (process.stdout.isTTY) {
138 + yield* Effect.sync(() => {
139 + process.stderr.write(`${line}\n`);
140 + });
141 + return;
142 + }
143 + yield* ui.output(line);
144 + });
145
146 export const triggersCmd$Listen = Command.make(
147 'listen',
@@ -253,32 +251,19 @@ export const triggersCmd$Listen = Command.make(
251 matchingEvents += 1;
252 if (table) {
253 if (!tableHeaderPrinted) {
256 - yield* ui.log.message(
257 - formatTableRow(TABLE_COLUMNS.map(col => ({ value: col.key, width: col.width })))
258 - );
254 + yield* emitTableLine(formatTriggerListenTableHeader(), ui);
255 tableHeaderPrinted = true;
256 }
257
262 - const tableLine = formatTableRow([
263 - {
264 - value:
265 - typeof eventData.timestamp === 'string'
266 - ? eventData.timestamp
267 - : new Date().toISOString(),
268 - width: TABLE_COLUMNS[0].width,
269 - },
270 - { value: parsed.id, width: TABLE_COLUMNS[1].width },
271 - { value: parsed.triggerSlug, width: TABLE_COLUMNS[2].width },
272 - { value: parsed.toolkitSlug, width: TABLE_COLUMNS[3].width },
273 - { value: parsed.userId || '-', width: TABLE_COLUMNS[4].width },
274 - {
275 - value: parsed.metadata.connectedAccount.id || '-',
276 - width: TABLE_COLUMNS[5].width,
277 - },
278 - ]);
258 + const tableLine = formatTriggerListenTableRow({
259 + timestamp:
260 + typeof eventData.timestamp === 'string'
261 + ? eventData.timestamp
262 + : new Date().toISOString(),
263 + event: parsed,
264 + });
265
280 - yield* ui.log.message(tableLine);
281 - yield* ui.output(tableLine);
266 + yield* emitTableLine(tableLine, ui);
267 } else if (json) {
268 yield* ui.note(formatTriggerListenSummary(parsed), `Event #${matchingEvents}`);
269 yield* ui.log.message(JSON.stringify(eventData, null, 2));
ts/packages/cli/src/commands/triggers/format.ts
+45
@@ -1,4 +1,6 @@
1 import type { TriggerListenEvent } from './types';
2 +import { bold, gray } from 'src/ui/colors';
3 +import { truncate } from 'src/ui/truncate';
4
5 export const formatTriggerListenSummary = (event: TriggerListenEvent): string => {
6 const userId = event.userId || '-';
@@ -11,3 +13,46 @@ export const formatTriggerListenSummary = (event: TriggerListenEvent): string =>
13 `User Id: ${userId}`,
14 ].join('\n');
15 };
16 +
17 +const TRIGGER_TABLE = {
18 + timestamp: 24,
19 + triggerId: 20,
20 + triggerSlug: 22,
21 + toolkit: 8,
22 + userId: 16,
23 + connectedAccountId: 20,
24 +} as const;
25 +
26 +export const formatTriggerListenTableHeader = (): string =>
27 + [
28 + bold('Timestamp'.padEnd(TRIGGER_TABLE.timestamp)),
29 + bold('Trigger Id'.padEnd(TRIGGER_TABLE.triggerId)),
30 + bold('Trigger Slug'.padEnd(TRIGGER_TABLE.triggerSlug)),
31 + bold('Toolkit'.padEnd(TRIGGER_TABLE.toolkit)),
32 + bold('User Id'.padEnd(TRIGGER_TABLE.userId)),
33 + bold('Connected Account Id'),
34 + ].join(' ');
35 +
36 +export const formatTriggerListenTableRow = ({
37 + timestamp,
38 + event,
39 +}: {
40 + timestamp: string;
41 + event: TriggerListenEvent;
42 +}): string => {
43 + const connectedAccountId = event.metadata.connectedAccount.id || '-';
44 + const userId = event.userId || '-';
45 + const timestampCell = truncate(timestamp, TRIGGER_TABLE.timestamp).padEnd(
46 + TRIGGER_TABLE.timestamp
47 + );
48 + const triggerIdCell = truncate(event.id, TRIGGER_TABLE.triggerId).padEnd(TRIGGER_TABLE.triggerId);
49 +
50 + return [
51 + gray(timestampCell),
52 + triggerIdCell,
53 + truncate(event.triggerSlug, TRIGGER_TABLE.triggerSlug).padEnd(TRIGGER_TABLE.triggerSlug),
54 + truncate(event.toolkitSlug, TRIGGER_TABLE.toolkit).padEnd(TRIGGER_TABLE.toolkit),
55 + truncate(userId, TRIGGER_TABLE.userId).padEnd(TRIGGER_TABLE.userId),
56 + truncate(connectedAccountId, TRIGGER_TABLE.connectedAccountId),
57 + ].join(' ');
58 +};
ts/packages/cli/test/src/commands/triggers/triggers.listen.cmd.test.ts
+7 -7
@@ -144,16 +144,16 @@ describe('CLI: composio triggers listen', () => {
144 const lines = yield* MockConsole.getLines({ stripAnsi: true });
145 const output = lines.join('\n');
146
147 - expect(output).toContain('timestamp');
148 - expect(output).toContain('trigger_id');
149 - expect(output).toContain('trigger_slug');
150 - expect(output).toContain('toolkit');
151 - expect(output).toContain('user_id');
152 - expect(output).toContain('connected_account_id');
147 + expect(output).toContain('Timestamp');
148 + expect(output).toContain('Trigger Id');
149 + expect(output).toContain('Trigger Slug');
150 + expect(output).toContain('Toolkit');
151 + expect(output).toContain('User Id');
152 + expect(output).toContain('Connected Account Id');
153 expect(output).not.toContain('Event #1');
154 expect(output).not.toContain('Trigger:');
155 expect(output).toContain('trg_123');
156 - expect(output).toContain('GMAIL_NEW_GMAIL_MESSAGE');
156 + expect(output).toContain('GMAIL_NEW_GMAIL_');
157 expect(output).toContain('GMAIL');
158 expect(output).toContain('user_123');
159 expect(output).toContain('con_123');