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.

fix(cli): suppress decoration when piped and remove makeSpinner

jkomynoeba0290679f8
diff --git a/ts/packages/cli/AGENTS.md b/ts/packages/cli/AGENTS.md
index 2acba2e80..bbd3c1705 100644
--- a/ts/packages/cli/AGENTS.md
+++ b/ts/packages/cli/AGENTS.md
@@ -161,12 +161,13 @@ The CLI follows the Unix convention of separating human-readable decoration from
### Rules
-1. **All `TerminalUI` methods except `output()` write to stderr** via Clack's `{ output: process.stderr }` option.
-2. **`ui.output(data)` writes to stdout** — use this for values that scripts should capture (API keys, version strings, generated paths).
-3. **Action commands** (login, logout, upgrade, generate) produce no stdout data — their output is purely decorative.
-4. **Data commands** (whoami, version) produce both decoration (stderr) and data (stdout).
-5. **Never write data to stderr** — decoration methods are for human context only.
-6. **Never write decoration to stdout** — it breaks pipes, `$(...)` captures, and `> file` redirects.
+1. **All `TerminalUI` methods except `output()` write to stderr** via Clack's `{ output: process.stderr }` option — but only in interactive mode.
+2. **`ui.output(data)` writes to stdout only when piped** — it checks `process.stdout.isTTY` and is a no-op in interactive terminals (the human already sees the data via decoration on stderr).
+3. **When stdout is piped, ALL decoration is suppressed** — `isInteractive` (`process.stdout.isTTY`) gates every decoration method. Only `ui.output()` writes in piped mode. This keeps `composio whoami | pbcopy` completely silent.
+4. **Action commands** (logout, upgrade) produce no stdout data — their output is purely decorative.
+5. **Data commands** (whoami, version, login, generate) call both decoration (stderr) and `ui.output()` (stdout). In interactive mode, only decoration is visible. In pipes/scripts, only the raw data is captured.
+6. **Never write data to stderr** — decoration methods are for human context only.
+7. **Never write decoration to stdout** — it breaks pipes, `$(...)` captures, and `> file` redirects.
### Pattern
@@ -183,13 +184,21 @@ yield * ui.log.step('Redirecting'); // Decoration → stderr
### How it works in practice
+The CLI checks `process.stdout.isTTY` once at startup to determine the output mode:
+
+- **Interactive** (`stdout` is TTY): decoration visible on stderr, `ui.output()` is a no-op.
+- **Piped** (`stdout` is NOT TTY): decoration suppressed, `ui.output()` writes raw data to stdout.
+
```bash
-composio whoami # Human sees pretty box AND plain key
-composio whoami 2>/dev/null # Only the API key (suppresses decoration)
-API_KEY=$(composio whoami) # Variable gets clean key, box shows in terminal
-composio whoami | pbcopy # Clipboard gets clean key
+composio whoami # Pretty box only (interactive)
+composio whoami | pbcopy # Silent — clipboard gets clean key
+API_KEY=$(composio whoami) # Silent — variable gets clean key
+composio whoami > file.txt # Silent — file gets clean key
+
+composio version # Decorated version (interactive)
+composio version | cat # Raw version string
-composio login # All decoration visible (nothing to pipe)
+composio login # All decoration visible, browser opens
composio login 2>/dev/null # Silent (but still opens browser, polls API)
```
diff --git a/ts/packages/cli/src/commands/$default.cmd.ts b/ts/packages/cli/src/commands/$default.cmd.ts
index 63e6d57ca..71748e9f7 100644
--- a/ts/packages/cli/src/commands/$default.cmd.ts
+++ b/ts/packages/cli/src/commands/$default.cmd.ts
@@ -2,7 +2,6 @@ import { Context, Schema, LogLevel, String, pipe, Layer, Effect } from 'effect';
import { Command, Options } from '@effect/cli';
import { setMinimumLogLevel } from 'src/effects/with-log-level';
import type { ConfigError } from 'effect/ConfigError';
-import { versionCmd } from './version.cmd';
const logLevelChoices = LogLevel.allLevels.map(level => String.toLowerCase(level._tag));
@@ -45,7 +44,6 @@ class $DefaultCmdContext extends Context.Tag('cli/$DefaultCmdContext')<
* ```
*/
export const $defaultCmd = Command.make('composio', { logLevel }).pipe(
- Command.withSubcommands([versionCmd]),
Command.withDescription(
`Composio CLI - A tool for managing Python and TypeScript composio.dev projects.`
),
diff --git a/ts/packages/cli/src/commands/login.cmd.ts b/ts/packages/cli/src/commands/login.cmd.ts
index 2cf3d5783..a60d8d777 100644
--- a/ts/packages/cli/src/commands/login.cmd.ts
+++ b/ts/packages/cli/src/commands/login.cmd.ts
@@ -51,6 +51,7 @@ export const loginCmd = Command.make('login', { noBrowser }, ({ noBrowser }) =>
}
yield* ui.note(url, 'Login URL');
+ yield* ui.output(url);
if (!noBrowser) {
// Open the given `url` in the default browser
@@ -64,34 +65,35 @@ export const loginCmd = Command.make('login', { noBrowser }, ({ noBrowser }) =>
);
}
- // Spinner during session polling
- const spinner = yield* ui.makeSpinner('Waiting for login...');
-
- // Retry operation until the session status is "linked" with exponential backoff
- const linkedSession = yield* Effect.retry(
- Effect.gen(function* () {
- const currentSession = yield* client.getSession({
- ...session,
- });
-
- // Check if session is linked
- if (currentSession.status === 'linked') {
- return currentSession;
- }
-
- // If still pending, fail to trigger retry
- return yield* Effect.fail(
- new Error(`Session status is still '${currentSession.status}', waiting for 'linked'`)
- );
- }),
- // Exponential backoff: start with 0.3s, max 5s, up to 15 retries
- Schedule.exponential('0.3 seconds').pipe(
- Schedule.intersect(Schedule.recurs(15)),
- Schedule.intersect(Schedule.spaced('5 seconds'))
+ // Retry operation until the session status is "linked" with exponential backoff.
+ // useMakeSpinner auto-cleans up the spinner on interruption (e.g., Ctrl+C).
+ const linkedSession = yield* ui.useMakeSpinner('Waiting for login...', spinner =>
+ Effect.retry(
+ Effect.gen(function* () {
+ const currentSession = yield* client.getSession({
+ ...session,
+ });
+
+ // Check if session is linked
+ if (currentSession.status === 'linked') {
+ return currentSession;
+ }
+
+ // If still pending, fail to trigger retry
+ return yield* Effect.fail(
+ new Error(`Session status is still '${currentSession.status}', waiting for 'linked'`)
+ );
+ }),
+ // Exponential backoff: start with 0.3s, max 5s, up to 15 retries
+ Schedule.exponential('0.3 seconds').pipe(
+ Schedule.intersect(Schedule.recurs(15)),
+ Schedule.intersect(Schedule.spaced('5 seconds'))
+ )
+ ).pipe(
+ Effect.tap(() => spinner.stop('Login successful')),
+ Effect.tapError(() => spinner.error('Login timed out. Please try again.'))
)
- ).pipe(Effect.tapError(() => spinner.error('Login timed out. Please try again.')));
-
- yield* spinner.stop('Login successful');
+ );
yield* Effect.logDebug(`Linked session: ${JSON.stringify(linkedSession)}`);
diff --git a/ts/packages/cli/src/commands/py/commands/py.generate.cmd.ts b/ts/packages/cli/src/commands/py/commands/py.generate.cmd.ts
index e1c7f5cef..d649abcae 100644
--- a/ts/packages/cli/src/commands/py/commands/py.generate.cmd.ts
+++ b/ts/packages/cli/src/commands/py/commands/py.generate.cmd.ts
@@ -182,6 +182,7 @@ export function generatePythonTypeStubs({
yield* logMetrics(metrics);
yield* ui.outro('Done');
+ yield* ui.output(outputDir);
return outputDir;
});
diff --git a/ts/packages/cli/src/commands/ts/commands/ts.generate.cmd.ts b/ts/packages/cli/src/commands/ts/commands/ts.generate.cmd.ts
index 8559800a0..2a98c6c52 100644
--- a/ts/packages/cli/src/commands/ts/commands/ts.generate.cmd.ts
+++ b/ts/packages/cli/src/commands/ts/commands/ts.generate.cmd.ts
@@ -456,6 +456,7 @@ export function generateTypescriptTypeStubs({
yield* logMetrics(metrics);
yield* ui.outro('Done');
+ yield* ui.output(outputDir);
return outputDir;
});
diff --git a/ts/packages/cli/src/commands/version.cmd.ts b/ts/packages/cli/src/commands/version.cmd.ts
index f67abbbcf..80d347b08 100644
--- a/ts/packages/cli/src/commands/version.cmd.ts
+++ b/ts/packages/cli/src/commands/version.cmd.ts
@@ -12,7 +12,7 @@ import { TerminalUI } from 'src/services/terminal-ui';
* ```
*/
export const versionCmd = Command.make('version', {}).pipe(
- Command.withDescription('Display your account information.'),
+ Command.withDescription('Display the current Composio CLI version.'),
Command.withHandler(() =>
Effect.gen(function* () {
const ui = yield* TerminalUI;
diff --git a/ts/packages/cli/src/services/terminal-ui.ts b/ts/packages/cli/src/services/terminal-ui.ts
index d74a794e8..b2c17fb53 100644
--- a/ts/packages/cli/src/services/terminal-ui.ts
+++ b/ts/packages/cli/src/services/terminal-ui.ts
@@ -1,10 +1,9 @@
import process from 'node:process';
-import type { Writable } from 'node:stream';
import * as p from '@clack/prompts';
import { Context, Effect, Exit, Layer } from 'effect';
// ---------------------------------------------------------------------------
-// SpinnerHandle — returned by `makeSpinner` for manual control
+// SpinnerHandle — returned by `useMakeSpinner` for manual control
// ---------------------------------------------------------------------------
export interface SpinnerHandle {
@@ -23,7 +22,12 @@ export interface SpinnerHandle {
export interface TerminalUI {
/**
* Write raw data to stdout for piping and scripting.
+ *
* This is the ONLY method that writes to stdout — everything else goes to stderr.
+ * When stdout is a TTY (interactive terminal), this is a no-op — the human already
+ * sees the data via decoration on stderr. When stdout is redirected (pipe, subshell,
+ * file), the raw value is written for machine consumption.
+ *
* Use this for values that scripts should capture (API keys, version strings, etc.).
*/
readonly output: (data: string) => Effect.Effect<void>;
@@ -65,15 +69,6 @@ export interface TerminalUI {
}
) => Effect.Effect<A, E, R>;
- /**
- * Create a controllable spinner for multi-step flows (e.g., login polling).
- * The caller is responsible for calling `stop()` or `error()`.
- *
- * WARNING: If the surrounding Effect fails, this spinner will NOT be cleaned up.
- * Use `useMakeSpinner` instead for automatic cleanup on error.
- */
- readonly makeSpinner: (message: string) => Effect.Effect<SpinnerHandle>;
-
/**
* Create a controllable spinner that is automatically stopped on error or interruption.
* The `use` function receives a SpinnerHandle and must return an Effect.
@@ -94,10 +89,16 @@ export const TerminalUI = Context.GenericTag<TerminalUI>('services/TerminalUI');
// ---------------------------------------------------------------------------
/**
- * All decoration (spinners, logs, notes, intro/outro) writes to stderr.
- * This keeps stdout clean for data output that scripts and pipes capture.
+ * Whether the CLI is running interactively (stdout is a TTY).
+ * When piped (stdout is NOT a TTY), all decoration is suppressed and only
+ * `output()` writes raw data to stdout for machine consumption.
*/
-const DECORATION: Writable = process.stderr;
+const isInteractive = !!process.stdout.isTTY;
+
+/** Run a decoration side-effect only in interactive mode. */
+function decorate(fn: () => void): void {
+ if (isInteractive) fn();
+}
function createClackSpinnerHandle(s: p.SpinnerResult, defaultMessage: string): SpinnerHandle {
return {
@@ -107,72 +108,85 @@ function createClackSpinnerHandle(s: p.SpinnerResult, defaultMessage: string): S
};
}
+/** No-op spinner handle used when decoration is suppressed (piped mode). */
+const silentSpinnerHandle: SpinnerHandle = {
+ message: () => Effect.void,
+ stop: () => Effect.void,
+ error: () => Effect.void,
+};
+
const makeLive: TerminalUI = {
output: data =>
Effect.sync(() => {
- process.stdout.write(`${data}\n`);
+ if (!isInteractive) {
+ process.stdout.write(`${data}\n`);
+ }
}),
- intro: title => Effect.sync(() => p.intro(title, { output: DECORATION })),
- outro: message => Effect.sync(() => p.outro(message, { output: DECORATION })),
+ intro: title => Effect.sync(() => decorate(() => p.intro(title, { output: process.stderr }))),
+ outro: message => Effect.sync(() => decorate(() => p.outro(message, { output: process.stderr }))),
log: {
- info: message => Effect.sync(() => p.log.info(message, { output: DECORATION })),
- success: message => Effect.sync(() => p.log.success(message, { output: DECORATION })),
- warn: message => Effect.sync(() => p.log.warn(message, { output: DECORATION })),
- error: message => Effect.sync(() => p.log.error(message, { output: DECORATION })),
- step: message => Effect.sync(() => p.log.step(message, { output: DECORATION })),
- message: message => Effect.sync(() => p.log.message(message, { output: DECORATION })),
+ info: message =>
+ Effect.sync(() => decorate(() => p.log.info(message, { output: process.stderr }))),
+ success: message =>
+ Effect.sync(() => decorate(() => p.log.success(message, { output: process.stderr }))),
+ warn: message =>
+ Effect.sync(() => decorate(() => p.log.warn(message, { output: process.stderr }))),
+ error: message =>
+ Effect.sync(() => decorate(() => p.log.error(message, { output: process.stderr }))),
+ step: message =>
+ Effect.sync(() => decorate(() => p.log.step(message, { output: process.stderr }))),
+ message: message =>
+ Effect.sync(() => decorate(() => p.log.message(message, { output: process.stderr }))),
},
- note: (message, title) => Effect.sync(() => p.note(message, title ?? '', { output: DECORATION })),
+ note: (message, title) =>
+ Effect.sync(() => decorate(() => p.note(message, title ?? '', { output: process.stderr }))),
withSpinner: (message, effect, options) =>
- Effect.acquireUseRelease(
- Effect.sync(() => {
- const s = p.spinner({ output: DECORATION });
- s.start(message);
- return s;
- }),
- () => effect,
- (s, exit) =>
- Effect.sync(() => {
- if (Exit.isSuccess(exit)) {
- const successMsg =
- typeof options?.successMessage === 'function'
- ? options.successMessage(exit.value)
- : (options?.successMessage ?? message);
- s.stop(successMsg);
- } else {
- s.error(options?.errorMessage ?? message);
- }
- })
- ),
-
- makeSpinner: message =>
- Effect.sync(() => {
- const s = p.spinner({ output: DECORATION });
- s.start(message);
- return createClackSpinnerHandle(s, message);
- }),
+ isInteractive
+ ? Effect.acquireUseRelease(
+ Effect.sync(() => {
+ const s = p.spinner({ output: process.stderr });
+ s.start(message);
+ return s;
+ }),
+ () => effect,
+ (s, exit) =>
+ Effect.sync(() => {
+ if (Exit.isSuccess(exit)) {
+ const successMsg =
+ typeof options?.successMessage === 'function'
+ ? options.successMessage(exit.value)
+ : (options?.successMessage ?? message);
+ s.stop(successMsg);
+ } else {
+ s.error(options?.errorMessage ?? message);
+ }
+ })
+ )
+ : effect,
useMakeSpinner: (message, use) =>
- Effect.acquireUseRelease(
- Effect.sync(() => {
- const s = p.spinner({ output: DECORATION });
- s.start(message);
- return { raw: s, handle: createClackSpinnerHandle(s, message) };
- }),
- ({ handle }) => use(handle),
- ({ raw }, exit) =>
- Effect.sync(() => {
- // Only clean up if the spinner is still active (user didn't call stop/error)
- // Clack spinners have an internal `isCancelled` state after stop/error/cancel
- if (Exit.isFailure(exit) && !raw.isCancelled) {
- raw.error(message);
- }
- })
- ),
+ isInteractive
+ ? Effect.acquireUseRelease(
+ Effect.sync(() => {
+ const s = p.spinner({ output: process.stderr });
+ s.start(message);
+ return { raw: s, handle: createClackSpinnerHandle(s, message) };
+ }),
+ ({ handle }) => use(handle),
+ ({ raw }, exit) =>
+ Effect.sync(() => {
+ // Only clean up if the spinner is still active (user didn't call stop/error)
+ // Clack spinners have an internal `isCancelled` state after stop/error/cancel
+ if (Exit.isFailure(exit) && !raw.isCancelled) {
+ raw.error(message);
+ }
+ })
+ )
+ : use(silentSpinnerHandle),
};
export const TerminalUILive = Layer.succeed(TerminalUI, makeLive);
diff --git a/ts/packages/cli/test/__utils__/services/terminal-ui-test.ts b/ts/packages/cli/test/__utils__/services/terminal-ui-test.ts
index b30cdf35a..b3467b0dc 100644
--- a/ts/packages/cli/test/__utils__/services/terminal-ui-test.ts
+++ b/ts/packages/cli/test/__utils__/services/terminal-ui-test.ts
@@ -37,16 +37,6 @@ export const TerminalUITest = Layer.succeed(
return result;
}),
- makeSpinner: message =>
- Effect.gen(function* () {
- void message;
- return {
- message: (_msg: string) => Effect.void,
- stop: (msg?: string) => (msg ? Console.log(msg) : Effect.void),
- error: (msg?: string) => (msg ? Console.error(msg) : Effect.void),
- };
- }),
-
useMakeSpinner: (message, use) =>
Effect.gen(function* () {
let stopped = false;
diff --git a/ts/packages/cli/test/src/commands/$default.cmd.test.ts b/ts/packages/cli/test/src/commands/$default.cmd.test.ts
index d203bf9a3..274b51a84 100644
--- a/ts/packages/cli/test/src/commands/$default.cmd.test.ts
+++ b/ts/packages/cli/test/src/commands/$default.cmd.test.ts
@@ -14,7 +14,9 @@ describe('CLI: composio', () => {
expect(result).toEqual(
ValidationError.commandMismatch(
- HelpDoc.p("Invalid subcommand for composio - use 'version'")
+ HelpDoc.p(
+ "Invalid subcommand for composio - use one of 'version', 'upgrade', 'whoami', 'login', 'logout', 'generate', 'py', 'ts'"
+ )
)
);
})
@@ -54,11 +56,7 @@ describe('CLI: composio', () => {
COMMANDS
- - version Display your account information.
-
- COMMANDS
-
- - version Display your account information.
+ - version Display the current Composio CLI version.
- upgrade Upgrade your Composio CLI to the latest available version.