Skip to content

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

haxzief91fa999430a
diff --git a/ts/packages/cli/src/commands/triggers/commands/triggers.listen.cmd.ts b/ts/packages/cli/src/commands/triggers/commands/triggers.listen.cmd.ts
index 20aac8010..0e384eb85 100644
--- a/ts/packages/cli/src/commands/triggers/commands/triggers.listen.cmd.ts
+++ b/ts/packages/cli/src/commands/triggers/commands/triggers.listen.cmd.ts
@@ -1,12 +1,17 @@
import { Command, Options } from '@effect/cli';
import { Deferred, Effect, Option, Runtime } from 'effect';
import path from 'node:path';
+import process from 'node:process';
import { promises as fs } from 'node:fs';
import { requireAuth } from 'src/effects/require-auth';
import { TerminalUI } from 'src/services/terminal-ui';
import { TriggersRealtime } from 'src/services/triggers-realtime';
import { matchesTriggerListenFilters } from '../filter';
-import { formatTriggerListenSummary } from '../format';
+import {
+ formatTriggerListenSummary,
+ formatTriggerListenTableHeader,
+ formatTriggerListenTableRow,
+} from '../format';
import { parseTriggerListenEvent } from '../parse';
import type { TriggerListenFilters } from '../types';
@@ -127,23 +132,16 @@ const detectWebhookPayloadVersion = (eventData: Record<string, unknown>): 'V1' |
return 'V1';
};
-const TABLE_COLUMNS = [
- { key: 'timestamp', width: 25 },
- { key: 'trigger_id', width: 16 },
- { key: 'trigger_slug', width: 28 },
- { key: 'toolkit', width: 12 },
- { key: 'user_id', width: 24 },
- { key: 'connected_account_id', width: 24 },
-] as const;
-
-const formatTableCell = (value: string, width: number): string => {
- if (value.length <= width) return value.padEnd(width, ' ');
- if (width <= 1) return value.slice(0, width);
- return `${value.slice(0, width - 1)}…`;
-};
-
-const formatTableRow = (columns: ReadonlyArray<{ value: string; width: number }>): string =>
- columns.map(col => formatTableCell(col.value, col.width)).join(' | ');
+const emitTableLine = (line: string, ui: TerminalUI): Effect.Effect<void> =>
+ Effect.gen(function* () {
+ if (process.stdout.isTTY) {
+ yield* Effect.sync(() => {
+ process.stderr.write(`${line}\n`);
+ });
+ return;
+ }
+ yield* ui.output(line);
+ });
export const triggersCmd$Listen = Command.make(
'listen',
@@ -253,32 +251,19 @@ export const triggersCmd$Listen = Command.make(
matchingEvents += 1;
if (table) {
if (!tableHeaderPrinted) {
- yield* ui.log.message(
- formatTableRow(TABLE_COLUMNS.map(col => ({ value: col.key, width: col.width })))
- );
+ yield* emitTableLine(formatTriggerListenTableHeader(), ui);
tableHeaderPrinted = true;
}
- const tableLine = formatTableRow([
- {
- value:
- typeof eventData.timestamp === 'string'
- ? eventData.timestamp
- : new Date().toISOString(),
- width: TABLE_COLUMNS[0].width,
- },
- { value: parsed.id, width: TABLE_COLUMNS[1].width },
- { value: parsed.triggerSlug, width: TABLE_COLUMNS[2].width },
- { value: parsed.toolkitSlug, width: TABLE_COLUMNS[3].width },
- { value: parsed.userId || '-', width: TABLE_COLUMNS[4].width },
- {
- value: parsed.metadata.connectedAccount.id || '-',
- width: TABLE_COLUMNS[5].width,
- },
- ]);
+ const tableLine = formatTriggerListenTableRow({
+ timestamp:
+ typeof eventData.timestamp === 'string'
+ ? eventData.timestamp
+ : new Date().toISOString(),
+ event: parsed,
+ });
- yield* ui.log.message(tableLine);
- yield* ui.output(tableLine);
+ yield* emitTableLine(tableLine, ui);
} else if (json) {
yield* ui.note(formatTriggerListenSummary(parsed), `Event #${matchingEvents}`);
yield* ui.log.message(JSON.stringify(eventData, null, 2));
diff --git a/ts/packages/cli/src/commands/triggers/format.ts b/ts/packages/cli/src/commands/triggers/format.ts
index b6eecaa75..2ed47e18d 100644
--- a/ts/packages/cli/src/commands/triggers/format.ts
+++ b/ts/packages/cli/src/commands/triggers/format.ts
@@ -1,4 +1,6 @@
import type { TriggerListenEvent } from './types';
+import { bold, gray } from 'src/ui/colors';
+import { truncate } from 'src/ui/truncate';
export const formatTriggerListenSummary = (event: TriggerListenEvent): string => {
const userId = event.userId || '-';
@@ -11,3 +13,46 @@ export const formatTriggerListenSummary = (event: TriggerListenEvent): string =>
`User Id: ${userId}`,
].join('\n');
};
+
+const TRIGGER_TABLE = {
+ timestamp: 24,
+ triggerId: 20,
+ triggerSlug: 22,
+ toolkit: 8,
+ userId: 16,
+ connectedAccountId: 20,
+} as const;
+
+export const formatTriggerListenTableHeader = (): string =>
+ [
+ bold('Timestamp'.padEnd(TRIGGER_TABLE.timestamp)),
+ bold('Trigger Id'.padEnd(TRIGGER_TABLE.triggerId)),
+ bold('Trigger Slug'.padEnd(TRIGGER_TABLE.triggerSlug)),
+ bold('Toolkit'.padEnd(TRIGGER_TABLE.toolkit)),
+ bold('User Id'.padEnd(TRIGGER_TABLE.userId)),
+ bold('Connected Account Id'),
+ ].join(' ');
+
+export const formatTriggerListenTableRow = ({
+ timestamp,
+ event,
+}: {
+ timestamp: string;
+ event: TriggerListenEvent;
+}): string => {
+ const connectedAccountId = event.metadata.connectedAccount.id || '-';
+ const userId = event.userId || '-';
+ const timestampCell = truncate(timestamp, TRIGGER_TABLE.timestamp).padEnd(
+ TRIGGER_TABLE.timestamp
+ );
+ const triggerIdCell = truncate(event.id, TRIGGER_TABLE.triggerId).padEnd(TRIGGER_TABLE.triggerId);
+
+ return [
+ gray(timestampCell),
+ triggerIdCell,
+ truncate(event.triggerSlug, TRIGGER_TABLE.triggerSlug).padEnd(TRIGGER_TABLE.triggerSlug),
+ truncate(event.toolkitSlug, TRIGGER_TABLE.toolkit).padEnd(TRIGGER_TABLE.toolkit),
+ truncate(userId, TRIGGER_TABLE.userId).padEnd(TRIGGER_TABLE.userId),
+ truncate(connectedAccountId, TRIGGER_TABLE.connectedAccountId),
+ ].join(' ');
+};
diff --git a/ts/packages/cli/test/src/commands/triggers/triggers.listen.cmd.test.ts b/ts/packages/cli/test/src/commands/triggers/triggers.listen.cmd.test.ts
index 59b666aca..350035eb9 100644
--- a/ts/packages/cli/test/src/commands/triggers/triggers.listen.cmd.test.ts
+++ b/ts/packages/cli/test/src/commands/triggers/triggers.listen.cmd.test.ts
@@ -144,16 +144,16 @@ describe('CLI: composio triggers listen', () => {
const lines = yield* MockConsole.getLines({ stripAnsi: true });
const output = lines.join('\n');
- expect(output).toContain('timestamp');
- expect(output).toContain('trigger_id');
- expect(output).toContain('trigger_slug');
- expect(output).toContain('toolkit');
- expect(output).toContain('user_id');
- expect(output).toContain('connected_account_id');
+ expect(output).toContain('Timestamp');
+ expect(output).toContain('Trigger Id');
+ expect(output).toContain('Trigger Slug');
+ expect(output).toContain('Toolkit');
+ expect(output).toContain('User Id');
+ expect(output).toContain('Connected Account Id');
expect(output).not.toContain('Event #1');
expect(output).not.toContain('Trigger:');
expect(output).toContain('trg_123');
- expect(output).toContain('GMAIL_NEW_GMAIL_MESSAGE');
+ expect(output).toContain('GMAIL_NEW_GMAIL_');
expect(output).toContain('GMAIL');
expect(output).toContain('user_123');
expect(output).toContain('con_123');