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 no-browser link flow to print raw redirect URLs (#3030)
## Summary - Added a shared redirect URL display helper for `connected-accounts link`. - In `--no-browser` mode, the CLI now prints the raw redirect URL via forced stdout output so merged-stream shells can capture it reliably. - Preserved the existing note-based UI for interactive flows. - Added coverage for the raw redirect URL path in the link command tests. ## Testing - Added a test asserting `composio dev connected-accounts link gmail --no-browser` forces the redirect URL through `output()`. - Not run: full CLI test suite. - Not run: typecheck / lint.
Rahul Tarak committed
Mar 26, 2026 at 17:53 UTC
691de3c8935c4ed677dd9afd41370aee64721572
3 files changed
+113
-9
ts/packages/cli/src/commands/connected-accounts/commands/connected-accounts.link.cmd.ts
+26
-5
@@ -46,6 +46,25 @@ const noWait = Options.boolean('no-wait').pipe(
46
Options.withDescription('Do not wait for authorization; only print link info')
47
);
48
49
+const showRedirectUrl = (
50
+ ui: TerminalUI,
51
+ redirectUrl: string,
52
+ noBrowser: boolean,
53
+ options?: { readonly emitRaw?: boolean }
54
+) =>
55
+ Effect.gen(function* () {
56
+ if (noBrowser) {
57
+ yield* ui.log.info('Please authorize using the following URL:');
58
+ } else {
59
+ yield* ui.log.step('Redirecting you to the authorization page');
60
+ }
61
+
62
+ yield* ui.note(redirectUrl, 'Redirect URL');
63
+ if (options?.emitRaw) {
64
+ yield* ui.output(redirectUrl, noBrowser ? { force: true } : undefined);
65
+ }
66
+ });
67
+
68
const waitForActiveConnection = (
69
ui: TerminalUI,
70
client: RawComposioClient,
@@ -54,7 +73,7 @@ const waitForActiveConnection = (
73
noBrowser: boolean
74
) =>
75
Effect.gen(function* () {
57
- yield* ui.note(redirectUrl, 'Redirect URL');
76
+ yield* showRedirectUrl(ui, redirectUrl, noBrowser, { emitRaw: noBrowser });
77
78
if (!noBrowser) {
79
let urlSchemeValid = false;
@@ -265,7 +284,7 @@ const runConnectedAccountsLink = (params: {
284
285
const { connectedAccountId: connId, redirectUrl } = validatedLink.value;
286
if (params.noWait) {
268
- yield* ui.note(redirectUrl, 'Redirect URL');
287
+ yield* showRedirectUrl(ui, redirectUrl, params.noBrowser);
288
yield* ui.output(
289
JSON.stringify(
290
{
@@ -277,7 +296,8 @@ const runConnectedAccountsLink = (params: {
296
},
297
null,
298
2
280
- )
299
+ ),
300
+ { force: true }
301
);
302
} else {
303
yield* waitForActiveConnection(ui, client, connId, redirectUrl, params.noBrowser);
@@ -344,7 +364,7 @@ const runConnectedAccountsLink = (params: {
364
yield* invalidateConsumerConnectedToolkitsCache().pipe(Effect.catchAll(() => Effect.void));
365
366
if (params.noWait) {
347
- yield* ui.note(redirectUrl, 'Redirect URL');
367
+ yield* showRedirectUrl(ui, redirectUrl, params.noBrowser);
368
yield* ui.output(
369
JSON.stringify(
370
{
@@ -357,7 +377,8 @@ const runConnectedAccountsLink = (params: {
377
},
378
null,
379
2
360
- )
380
+ ),
381
+ { force: true }
382
);
383
yield* appendCliSessionHistory({
384
orgId: resolvedProject.projectType === 'CONSUMER' ? resolvedProject.orgId : undefined,
ts/packages/cli/src/services/terminal-ui.ts
+6
-3
@@ -30,7 +30,10 @@ export interface TerminalUI {
30
*
31
* Use this for values that scripts should capture (API keys, version strings, etc.).
32
*/
33
- readonly output: (data: string) => Effect.Effect<void>;
33
+ readonly output: (
34
+ data: string,
35
+ options?: { readonly force?: boolean }
36
+ ) => Effect.Effect<void>;
37
38
/** Display a session start marker (e.g., `┌ title`). Writes to stderr. */
39
readonly intro: (title: string) => Effect.Effect<void>;
@@ -153,9 +156,9 @@ const silentSpinnerHandle: SpinnerHandle = {
156
};
157
158
const makeLive: TerminalUI = {
156
- output: data =>
159
+ output: (data, options) =>
160
Effect.sync(() => {
158
- if (!isInteractive) {
161
+ if (options?.force || !isInteractive) {
162
process.stdout.write(`${data}\n`);
163
}
164
}),
ts/packages/cli/test/src/commands/connected-accounts/connected-accounts.link.cmd.test.ts
+81
-1
@@ -1,9 +1,10 @@
1
import { describe, expect, layer } from '@effect/vitest';
2
-import { ConfigProvider, Effect } from 'effect';
2
+import { ConfigProvider, Console, Effect } from 'effect';
3
import { extendConfigProvider } from 'src/services/config';
4
import { cli, TestLive, MockConsole } from 'test/__utils__';
5
import type { TestLiveInput } from 'test/__utils__/services/test-layer';
6
import type { ConnectedAccountItem } from 'src/models/connected-accounts';
7
+import { TerminalUI } from 'src/services/terminal-ui';
8
9
const extractJsonObject = (output: string): Record<string, unknown> | null => {
10
const jsonMatch = output.match(/\{[\s\S]*"status"[\s\S]*\}/);
@@ -38,6 +39,36 @@ const testConfigProvider = ConfigProvider.fromMap(
39
new Map([['COMPOSIO_USER_API_KEY', 'test_api_key']])
40
).pipe(extendConfigProvider);
41
42
+const RecordingTerminalUI = TerminalUI.of({
43
+ output: (data, options) =>
44
+ Console.log(
45
+ JSON.stringify({
46
+ channel: options?.force ? 'FORCED' : 'NORMAL',
47
+ data,
48
+ })
49
+ ),
50
+ intro: title => Console.log(title),
51
+ outro: message => Console.log(message),
52
+ log: {
53
+ info: message => Console.log(message),
54
+ success: message => Console.log(message),
55
+ warn: message => Console.log(message),
56
+ error: message => Console.log(message),
57
+ step: message => Console.log(message),
58
+ message: message => Console.log(message),
59
+ },
60
+ note: (message, title) => Console.log(title ? `[${title}] ${message}` : message),
61
+ confirm: () => Effect.succeed(true),
62
+ select: (_message, options) => Effect.succeed(options[0].value),
63
+ withSpinner: (_message, effect) => effect,
64
+ useMakeSpinner: (_message, use) =>
65
+ use({
66
+ message: () => Effect.void,
67
+ stop: () => Effect.void,
68
+ error: () => Effect.void,
69
+ }),
70
+});
71
+
72
describe('CLI: composio dev connected-accounts link', () => {
73
layer(
74
TestLive({
@@ -60,6 +91,55 @@ describe('CLI: composio dev connected-accounts link', () => {
91
);
92
});
93
94
+ layer(
95
+ TestLive({
96
+ baseConfigProvider: testConfigProvider,
97
+ connectedAccountsData,
98
+ fixture: 'global-test-user-id',
99
+ terminalUI: RecordingTerminalUI,
100
+ })
101
+ )('[Given] --no-browser [Then] emits a forced raw redirect URL for merged-stream shells', it => {
102
+ it.scoped('forces the redirect URL through output()', () =>
103
+ Effect.gen(function* () {
104
+ yield* cli(['link', 'gmail', '--no-browser']);
105
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
106
+ const output = lines.join('\n');
107
+
108
+ expect(output).toContain('"channel":"FORCED"');
109
+ expect(output).toContain('https://app.composio.dev/link?token=lt_test_token');
110
+ })
111
+ );
112
+ });
113
+
114
+ layer(
115
+ TestLive({
116
+ baseConfigProvider: testConfigProvider,
117
+ connectedAccountsData,
118
+ fixture: 'global-test-user-id',
119
+ terminalUI: RecordingTerminalUI,
120
+ })
121
+ )('[Given] --no-browser --no-wait [Then] stdout remains JSON-only', it => {
122
+ it.scoped('does not emit the raw redirect URL before the pending JSON payload', () =>
123
+ Effect.gen(function* () {
124
+ yield* cli(['link', 'gmail', '--no-browser', '--no-wait']);
125
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
126
+ const forcedLines = lines
127
+ .map(line => {
128
+ try {
129
+ return JSON.parse(line) as { channel?: string; data?: string };
130
+ } catch {
131
+ return null;
132
+ }
133
+ })
134
+ .filter(line => line?.channel === 'FORCED');
135
+
136
+ expect(forcedLines).toHaveLength(1);
137
+ expect(forcedLines[0]?.data).toContain('"status": "pending"');
138
+ expect(forcedLines[0]?.data?.trim().startsWith('{')).toBe(true);
139
+ })
140
+ );
141
+ });
142
+
143
layer(
144
TestLive({
145
baseConfigProvider: testConfigProvider,