@devries-cameron20 / composio Mirror · read-only / commits / 67867aea1
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 22, 03:15 UTC

feat(cli): add --no-wait and --key flags to login command (#2906)

## Summary Adds new flags to `composio login` for agent/auth flows: ### `--no-wait` - Print login URL and session info (JSON) then exit without opening browser or waiting - Output is jq-parseable for scripting ### `--key <key>` - Complete login using session key from `composio login --no-wait` - **Without `--no-wait`**: Polls until session is linked (same as browser flow after printing URL) - **With `--no-wait`**: Checks once and fails if not linked ### Usage flow ```bash # 1. Get login URL and session key composio login --no-wait # 2. Open the URL in browser and complete login # 3. Complete login (polls until linked) composio login --key <key> # Or check once and fail if not linked composio login --key <key> --no-wait ``` ### Files changed - `login.cmd.ts` - Added flags and `loginWithKey` flow - `root-help.ts` - Updated usage - Tests, README, AGENTS.md, snapshot Made with [Cursor](https://cursor.com)

Musthaq Ahamad committed Mar 13, 2026 at 18:17 UTC 67867aea11c6238938e2c47da8f9f07dcc60b826
7 files changed +239 -42
.changeset/full-dragons-greet.md new
+5
@@ -0,0 +1,5 @@
1 +---
2 +'@composio/cli': patch
3 +---
4 +
5 +Add login flags for agent/auth flows: `--no-wait` (print URL/session info and exit), `--key` (complete login with session key; polls until linked unless `--no-wait` is also passed)
ts/packages/cli/AGENTS.md
+10 -10
@@ -27,16 +27,16 @@ Errors are captured via the custom `effect-errors/` module, which provides sourc
27
28 Each command is declared with `@effect/cli`'s `Command.make()` pattern:
29
30 -| Command | Description |
31 -| ------------------------------- | ---------------------------------------------------------- |
32 -| `composio version` | Display CLI version |
33 -| `composio whoami` | Show logged-in user's API key |
34 -| `composio login [--no-browser]` | OAuth2 login with browser redirect |
35 -| `composio logout` | Clear stored API key |
36 -| `composio upgrade` | Self-update binary from GitHub releases |
37 -| `composio generate` | Auto-detect project language, delegate to `ts` or `py` |
38 -| `composio ts generate` | Generate TypeScript type stubs for toolkits/tools/triggers |
39 -| `composio py generate` | Generate Python type stubs |
30 +| Command | Description |
31 +| -------------------------------------------------------- | ---------------------------------------------------------- |
32 +| `composio version` | Display CLI version |
33 +| `composio whoami` | Show logged-in user's API key |
34 +| `composio login [--no-browser] [--no-wait] [--key text]` | Login with browser redirect |
35 +| `composio logout` | Clear stored API key |
36 +| `composio upgrade` | Self-update binary from GitHub releases |
37 +| `composio generate` | Auto-detect project language, delegate to `ts` or `py` |
38 +| `composio ts generate` | Generate TypeScript type stubs for toolkits/tools/triggers |
39 +| `composio py generate` | Generate Python type stubs |
40
41 Options use `Options.text()`, `Options.boolean()`, `Options.choice()`, `Options.directory()` with Effect Schema validation.
42
ts/packages/cli/README.md
+1 -1
@@ -29,7 +29,7 @@ composio [--log-level all|trace|debug|info|warning|error|fatal|none]
29 | ---------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
30 | `composio version` | Display the current CLI version. |
31 | `composio whoami` | Show the currently logged-in user/account. |
32 -| `composio login [--no-browser]` | Log in to the Composio SDK. |
32 +| `composio login [--no-browser] [--no-wait] [--key text]` | Log in to the Composio SDK. |
33 | `composio logout` | Log out from the Composio SDK. |
34 | `composio generate [-o, --output-dir <directory>] [--toolkits <toolkit>] [--type-tools]` | Auto-detect the project language (Python or TypeScript) and generate type stubs for toolkits, tools, and triggers. |
35 | `composio py` | Python project-specific commands. |
ts/packages/cli/src/commands/login.cmd.ts
+197 -19
@@ -1,5 +1,5 @@
1 import { Command, Options } from '@effect/cli';
2 -import { Effect, Option, Schedule } from 'effect';
2 +import { DateTime, Effect, Option, Schedule } from 'effect';
3 import open from 'open';
4 import {
5 ComposioSessionRepository,
@@ -16,6 +16,18 @@ export const noBrowser = Options.boolean('no-browser').pipe(
16 Options.withDescription('Login without browser interaction')
17 );
18
19 +const noWait = Options.boolean('no-wait').pipe(
20 + Options.withDefault(false),
21 + Options.withDescription(
22 + 'Print login URL and session info, then exit without opening browser or waiting'
23 + )
24 +);
25 +
26 +const keyOpt = Options.text('key').pipe(
27 + Options.withDescription('Complete login using session key from composio login --no-wait'),
28 + Options.optional
29 +);
30 +
31 const yesOpt = Options.boolean('yes').pipe(
32 Options.withAlias('y'),
33 Options.withDefault(false),
@@ -129,6 +141,132 @@ const storeCredentials = (params: {
141 }
142 });
143
144 +/**
145 + * Completes login using an existing session key (from composio login --no-wait).
146 + * Fetches the session, optionally polls until linked, then stores credentials.
147 + *
148 + * When noWait is false: polls until session is linked (same as browser flow).
149 + * When noWait is true: checks once and fails if not linked.
150 + */
151 +const loginWithKey = (params: { key: string; noWait: boolean; skipOrgProjectPicker: boolean }) =>
152 + Effect.gen(function* () {
153 + const ui = yield* TerminalUI;
154 + const ctx = yield* ComposioUserContext;
155 + const client = yield* ComposioSessionRepository;
156 +
157 + const getSessionEffect = client
158 + .getSession({ id: params.key })
159 + .pipe(
160 + Effect.catchAll(() =>
161 + Effect.fail(
162 + new Error(
163 + 'Session not found or expired. Run `composio login --no-wait` to get a new session.'
164 + )
165 + )
166 + )
167 + );
168 +
169 + let linkedSession;
170 + if (params.noWait) {
171 + const session = yield* getSessionEffect;
172 + if (session.status !== 'linked') {
173 + yield* ui.log.error('Login not complete. Open the URL and finish authentication.');
174 + yield* ui.log.info('Then run `composio login --key <key>` again.');
175 + return yield* Effect.fail(new Error('Session not yet linked'));
176 + }
177 + linkedSession = session;
178 + } else {
179 + linkedSession = yield* ui.useMakeSpinner('Waiting for login...', spinner =>
180 + Effect.retry(
181 + Effect.gen(function* () {
182 + const currentSession = yield* getSessionEffect;
183 + if (currentSession.status === 'linked') {
184 + return currentSession;
185 + }
186 + return yield* Effect.fail(
187 + new Error(`Session status is still '${currentSession.status}', waiting for 'linked'`)
188 + );
189 + }),
190 + Schedule.exponential('0.3 seconds').pipe(
191 + Schedule.intersect(Schedule.recurs(15)),
192 + Schedule.intersect(Schedule.spaced('5 seconds'))
193 + )
194 + ).pipe(
195 + Effect.tap(() => spinner.stop('Login successful')),
196 + Effect.tapError(() => spinner.error('Login timed out. Please try again.'))
197 + )
198 + );
199 + }
200 + const uakApiKey = linkedSession.api_key;
201 +
202 + const uakSessionInfo = yield* getSessionInfoByUserApiKey({
203 + baseURL: ctx.data.baseURL,
204 + userApiKey: uakApiKey,
205 + });
206 +
207 + const xProjectId = uakSessionInfo.project.nano_id;
208 + const xOrgId = uakSessionInfo.project.org.id;
209 +
210 + const willRunPicker = !params.skipOrgProjectPicker;
211 + yield* storeCredentials({
212 + baseURL: ctx.data.baseURL,
213 + uakApiKey,
214 + initialOrgId: xOrgId,
215 + initialProjectId: xProjectId,
216 + fallbackEmail: linkedSession.account.email,
217 + skipHints: willRunPicker,
218 + skipOutput: willRunPicker,
219 + });
220 +
221 + if (willRunPicker) {
222 + const result = yield* runOrgProjectSelection({
223 + apiKey: uakApiKey,
224 + baseURL: ctx.data.baseURL,
225 + }).pipe(
226 + Effect.catchAll(error =>
227 + Effect.gen(function* () {
228 + yield* Effect.logDebug('Org/project picker failed:', error);
229 + yield* ui.log.warn('Could not load org/project list. Using session defaults.');
230 + return undefined;
231 + })
232 + )
233 + );
234 + if (result) {
235 + const sessionUserId = uakSessionInfo.org_member.user_id ?? uakSessionInfo.org_member.id;
236 + const testUserId = sessionUserId ? `pg-test-${sessionUserId}` : undefined;
237 + yield* ctx.login(
238 + uakApiKey,
239 + result.org.id,
240 + result.project.id,
241 + testUserId ?? Option.getOrUndefined(ctx.data.testUserId)
242 + );
243 + yield* ui.log.success(
244 + `Default org/project set to "${result.org.name}" / "${result.project.name}".`
245 + );
246 + }
247 + const finalOrgId = result?.org.id ?? xOrgId;
248 + const finalProjectId = result?.project.id ?? xProjectId;
249 + const finalOrgName = result?.org.name ?? uakSessionInfo.project.org.name ?? '';
250 + const finalProjectName = result?.project.name ?? uakSessionInfo.project.name ?? '';
251 + yield* ui.output(
252 + JSON.stringify({
253 + email: linkedSession.account.email ?? undefined,
254 + org_id: finalOrgId,
255 + project_id: finalProjectId,
256 + org_name: finalOrgName,
257 + project_name: finalProjectName,
258 + })
259 + );
260 + yield* ui.log.info(
261 + 'Run `composio init` in your project directory to set up project context.'
262 + );
263 + yield* ui.log.info(
264 + 'To switch your default global org/project later, run `composio orgs switch`.'
265 + );
266 + yield* ui.outro("You're all set!");
267 + }
268 + });
269 +
270 /**
271 * Runs the browser-based login flow: creates a CLI session, opens the browser,
272 * polls until linked, enriches via session/info, and stores credentials.
@@ -143,6 +281,8 @@ export const browserLogin = (params: {
281 scope: 'user' | 'project';
282 /** When true, don't open browser — just show the URL. */
283 noBrowser: boolean;
284 + /** When true, print URL/session info and exit without waiting (implies noBrowser). */
285 + noWait?: boolean;
286 /** When true (login only), skip org/project picker and use session defaults. When false, prompt for org/project. */
287 skipOrgProjectPicker?: boolean;
288 }) =>
@@ -159,16 +299,31 @@ export const browserLogin = (params: {
299
300 const url = `${ctx.data.webURL}?cliKey=${session.id}`;
301
162 - if (params.noBrowser) {
302 + const effectiveNoBrowser = params.noBrowser || params.noWait;
303 + if (effectiveNoBrowser) {
304 yield* ui.log.info('Please login using the following URL:');
305 } else {
306 yield* ui.log.step('Redirecting you to the login page');
307 }
308
309 yield* ui.note(url, 'Login URL');
310 +
311 + if (params.noWait) {
312 + const loginInfo = {
313 + status: 'pending',
314 + message: 'Complete login by opening the URL',
315 + login_url: url,
316 + cli_key: session.id,
317 + expires_at: DateTime.formatIso(session.expiresAt),
318 + };
319 + yield* ui.note(JSON.stringify(loginInfo, null, 2), 'Login info');
320 + yield* ui.output(JSON.stringify(loginInfo, null, 2));
321 + return;
322 + }
323 +
324 yield* ui.output(url);
325
171 - if (!params.noBrowser) {
326 + if (!effectiveNoBrowser) {
327 yield* Effect.tryPromise(() => open(url, { wait: false })).pipe(
328 Effect.catchAll(error =>
329 Effect.gen(function* () {
@@ -286,34 +441,57 @@ export const browserLogin = (params: {
441 *
442 * Browser-based: Opens browser for OAuth flow (default).
443 * Use --no-browser to skip auto-opening the browser and print the URL instead.
444 + * Use --no-wait to print login URL and session info (JSON) then exit without opening browser or waiting.
445 + * Use --key to complete login with a session key from --no-wait. Without --no-wait, polls until linked;
446 + * with --no-wait, checks once and fails if not linked.
447 * Use -y to skip org/project picker and use session defaults.
448 *
449 * @example
450 * ```bash
451 * composio login
452 * composio login --no-browser
453 + * composio login --no-wait
454 + * composio login --key <key>
455 + * composio login --key <key> --no-wait
456 * composio login -y
457 * ```
458 */
298 -export const loginCmd = Command.make('login', { noBrowser, yes: yesOpt }, ({ noBrowser, yes }) =>
299 - Effect.gen(function* () {
300 - const ui = yield* TerminalUI;
301 - const ctx = yield* ComposioUserContext;
459 +export const loginCmd = Command.make(
460 + 'login',
461 + { noBrowser, noWait, key: keyOpt, yes: yesOpt },
462 + ({ noBrowser, noWait, key, yes }) =>
463 + Effect.gen(function* () {
464 + const ui = yield* TerminalUI;
465 + const ctx = yield* ComposioUserContext;
466
303 - yield* ui.intro('composio login');
467 + yield* ui.intro('composio login');
468
305 - if (ctx.isLoggedIn()) {
306 - // Allow re-login when orgId/projectId are not yet set (old CLI login without multi-project support)
307 - if (Option.isSome(ctx.data.orgId) && Option.isSome(ctx.data.projectId)) {
308 - yield* ui.log.warn(`You're already logged in!`);
309 - yield* ui.outro(
310 - 'If you want to log in with a different account, please run `composio logout` first.'
311 - );
469 + if (Option.isSome(key)) {
470 + yield* loginWithKey({
471 + key: key.value,
472 + noWait,
473 + skipOrgProjectPicker: true,
474 + });
475 return;
476 }
314 - yield* ui.log.step('Re-authenticating for multi-project support...');
315 - }
477
317 - yield* browserLogin({ scope: 'user', noBrowser, skipOrgProjectPicker: yes });
318 - })
478 + if (ctx.isLoggedIn()) {
479 + // Allow re-login when orgId/projectId are not yet set (old CLI login without multi-project support)
480 + if (Option.isSome(ctx.data.orgId) && Option.isSome(ctx.data.projectId)) {
481 + yield* ui.log.warn(`You're already logged in!`);
482 + yield* ui.outro(
483 + 'If you want to log in with a different account, please run `composio logout` first.'
484 + );
485 + return;
486 + }
487 + yield* ui.log.step('Re-authenticating for multi-project support...');
488 + }
489 +
490 + yield* browserLogin({
491 + scope: 'user',
492 + noBrowser,
493 + noWait,
494 + skipOrgProjectPicker: yes,
495 + });
496 + })
497 ).pipe(Command.withDescription('Log in to the Composio SDK.'));
ts/packages/cli/src/commands/root-help.ts
+9 -1
@@ -27,9 +27,17 @@ const BASIC_COMMANDS: ReadonlyArray<BasicCommand> = [
27 {
28 name: 'login',
29 description: 'Log in to the Composio CLI session.',
30 - usage: 'login [--no-browser] [-y, --yes]',
30 + usage: 'login [--no-browser] [--no-wait] [--key text] [-y, --yes]',
31 options: [
32 { name: '--no-browser', description: 'Login without browser interaction' },
33 + {
34 + name: '--no-wait',
35 + description: 'Print login URL and session info, then exit (no browser, no waiting)',
36 + },
37 + {
38 + name: '--key',
39 + description: 'Complete login using session key from --no-wait',
40 + },
41 { name: '-y, --yes', description: 'Skip org/project picker; use session defaults' },
42 ],
43 },
ts/packages/cli/test/src/commands/__snapshots__/$default.cmd.test.ts.snap
+3 -1
@@ -22,9 +22,11 @@ BASIC COMMANDS
22
23 login
24 Log in to the Composio CLI session.
25 - Usage: composio login [--no-browser] [-y, --yes]
25 + Usage: composio login [--no-browser] [--no-wait] [--key text] [-y, --yes]
26 Options:
27 --no-browser Login without browser interaction
28 + --no-wait Print login URL and session info, then exit (no browser, no waiting)
29 + --key Complete login using session key from --no-wait
30 -y, --yes Skip org/project picker; use session defaults
31
32 logout
ts/packages/cli/test/src/commands/login.cmd.test.ts
+14 -10
@@ -12,16 +12,20 @@ describe('CLI: composio login', () => {
12
13 describe('login --help', () => {
14 layer(TestLive())(it => {
15 - it.scoped('[Then] shows --no-browser and -y/--yes (skip picker), no --api-key', () =>
16 - Effect.gen(function* () {
17 - yield* cli(['login', '--help']);
18 - const lines = yield* MockConsole.getLines();
19 - const output = lines.join('\n');
20 - expect(output).toContain('--no-browser');
21 - expect(output).toContain('--yes');
22 - expect(output).toContain('-y');
23 - expect(output).not.toContain('--api-key');
24 - })
15 + it.scoped(
16 + '[Then] shows --no-browser, --no-wait, --key and -y/--yes (skip picker), no --api-key',
17 + () =>
18 + Effect.gen(function* () {
19 + yield* cli(['login', '--help']);
20 + const lines = yield* MockConsole.getLines();
21 + const output = lines.join('\n');
22 + expect(output).toContain('--no-browser');
23 + expect(output).toContain('--no-wait');
24 + expect(output).toContain('--key');
25 + expect(output).toContain('--yes');
26 + expect(output).toContain('-y');
27 + expect(output).not.toContain('--api-key');
28 + })
29 );
30 });
31 });