@devries-cameron20 / composio Mirror · read-only / commits / c5cc8e72e
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, 02:00 UTC

Improve login and whoami session details (#3044)

## Summary - Improve `composio login` success messaging to include the signed-in email and default org name when available. - Expand `composio whoami` to fetch session info from the user API key and print the current email and default org name alongside existing IDs. - Add CLI tests covering the new `whoami` session-info output and preserve the help output regression check. ## Testing - `pnpm test --filter cli` or the equivalent CLI test suite for the affected package. - Added/updated unit tests in `ts/packages/cli/test/src/commands/whoami.cmd.test.ts` and `ts/packages/cli/test/src/commands/$default.cmd.test.ts`. - Not run in this branch review context.

Rahul Tarak committed Mar 27, 2026 at 05:05 UTC c5cc8e72eb642a8273f80042ede572077bd3264b
5 files changed +117 -5
ts/packages/cli/src/commands/index.ts
+3 -1
@@ -188,7 +188,9 @@ const normalizeHiddenDebugFlags = (argv: ReadonlyArray<string>): ReadonlyArray<s
188
189 const isRootHelp = (argv: ReadonlyArray<string>): boolean => {
190 const args = argv.slice(2);
191 - return args.length === 1 && (args[0] === '--help' || args[0] === '-h');
191 + return (
192 + args.length === 0 || (args.length === 1 && (args[0] === '--help' || args[0] === '-h'))
193 + );
194 };
195
196 const isGenerateGraph = (argv: ReadonlyArray<string>): boolean => {
ts/packages/cli/src/commands/login.cmd.ts
+31 -3
@@ -42,6 +42,23 @@ const noSkillInstall = Options.boolean('no-skill-install').pipe(
42 Options.withDescription('Skip installing the composio-cli skill for Claude Code')
43 );
44
45 +const formatLoginSuccessMessage = (params: {
46 + email?: string;
47 + orgName?: string;
48 +}): string => {
49 + const { email, orgName } = params;
50 + if (email && orgName) {
51 + return `Logged in as ${email} in "${orgName}"`;
52 + }
53 + if (email) {
54 + return `Logged in as ${email}`;
55 + }
56 + if (orgName) {
57 + return `Logged in successfully in "${orgName}"`;
58 + }
59 + return 'Logged in successfully';
60 +};
61 +
62 /**
63 * Verifies credentials via session/info and stores them.
64 *
@@ -117,7 +134,8 @@ const storeCredentials = (params: {
134 });
135
136 const email = sessionInfo?.org_member.email || fallbackEmail || undefined;
120 - yield* ui.log.success(email ? `Logged in as ${email}` : 'Logged in successfully');
137 + const orgName = sessionInfo?.project.org.name || undefined;
138 + yield* ui.log.success(formatLoginSuccessMessage({ email, orgName }));
139 if (!skipHints) {
140 yield* ui.log.info(commandHintStep('Execute a tool directly', 'root.execute'));
141 yield* ui.log.info(commandHintStep('Switch your default org', 'root.orgs.switch'));
@@ -240,7 +258,12 @@ const loginWithKey = (params: { key: string; noWait: boolean; skipOrgProjectPick
258 yield* primeConsumerConnectedToolkitsCacheInBackground({
259 orgId: result.id,
260 });
243 - yield* ui.log.success(`Default org set to "${result.name}".`);
261 + yield* ui.log.success(
262 + formatLoginSuccessMessage({
263 + email: uakSessionInfo.org_member.email || linkedSession.account.email || undefined,
264 + orgName: result.name,
265 + })
266 + );
267 }
268 const finalOrgId = result?.id ?? xOrgId;
269 const finalOrgName = result?.name ?? uakSessionInfo.project.org.name ?? '';
@@ -400,7 +423,12 @@ export const browserLogin = (params: {
423 yield* primeConsumerConnectedToolkitsCacheInBackground({
424 orgId: result.id,
425 });
403 - yield* ui.log.success(`Default org set to "${result.name}".`);
426 + yield* ui.log.success(
427 + formatLoginSuccessMessage({
428 + email: uakSessionInfo.org_member.email || linkedSession.account.email || undefined,
429 + orgName: result.name,
430 + })
431 + );
432 }
433 const finalOrgId = result?.id ?? xOrgId;
434 const finalOrgName = result?.name ?? uakSessionInfo.project.org.name ?? '';
ts/packages/cli/src/commands/whoami.cmd.ts
+16 -1
@@ -1,5 +1,6 @@
1 import { Command } from '@effect/cli';
2 import { Effect, Option } from 'effect';
3 +import { getSessionInfoByUserApiKey } from 'src/services/composio-clients';
4 import { ComposioUserContext } from 'src/services/user-context';
5 import { TerminalUI } from 'src/services/terminal-ui';
6 import { commandHintStep } from 'src/services/command-hints';
@@ -23,13 +24,25 @@ export const whoamiCmd = Command.make('whoami', {}).pipe(
24 yield* ctx.data.apiKey.pipe(
25 Option.match({
26 onNone: () => ui.log.warn('You are not logged in yet. Please run `composio login`.'),
26 - onSome: () =>
27 + onSome: apiKey =>
28 Effect.gen(function* () {
29 const defaultOrgId = Option.getOrUndefined(ctx.data.orgId);
30 const testUserId = Option.getOrUndefined(ctx.data.testUserId);
31 + const sessionInfo = yield* getSessionInfoByUserApiKey({
32 + baseURL: ctx.data.baseURL,
33 + userApiKey: apiKey,
34 + }).pipe(Effect.option);
35 + const email = Option.map(sessionInfo, info => info.org_member.email).pipe(
36 + Option.getOrUndefined
37 + );
38 + const orgName = Option.map(sessionInfo, info => info.project.org.name).pipe(
39 + Option.getOrUndefined
40 + );
41
42 yield* ui.note(
43 [
44 + `Email: ${email ?? 'unknown'}`,
45 + `Default Org: ${orgName ?? 'unknown'}`,
46 `Default Org ID: ${defaultOrgId ?? 'not set'}`,
47 `Test User ID: ${testUserId ?? 'not set'}`,
48 ].join('\n'),
@@ -43,6 +56,8 @@ export const whoamiCmd = Command.make('whoami', {}).pipe(
56 );
57 yield* ui.output(
58 JSON.stringify({
59 + email: email ?? null,
60 + default_org_name: orgName ?? null,
61 default_org_id: defaultOrgId ?? null,
62 test_user_id: testUserId ?? null,
63 })
ts/packages/cli/test/src/commands/$default.cmd.test.ts
+12
@@ -39,6 +39,18 @@ describe('CLI: composio', () => {
39 );
40 });
41
42 + layer(TestLive())(it => {
43 + it.scoped('[Given] no args [Then] prints help message', () =>
44 + Effect.gen(function* () {
45 + yield* cli([]);
46 + const lines = yield* MockConsole.getLines({ stripAnsi: true });
47 + const output = lines.join('\n');
48 + expect(output).toContain('Usage:');
49 + expect(output).toContain('composio');
50 + })
51 + );
52 + });
53 +
54 layer(TestLive())(it => {
55 it.scoped('[Given] --help flag [Then] prints help message', () =>
56 Effect.gen(function* () {
ts/packages/cli/test/src/commands/whoami.cmd.test.ts
+55
@@ -2,8 +2,13 @@ import { describe, expect, layer } from '@effect/vitest';
2 import { ConfigProvider, Effect } from 'effect';
3 import { extendConfigProvider } from 'src/services/config';
4 import { cli, TestLive, MockConsole } from 'test/__utils__';
5 +import { afterEach, vi } from 'vitest';
6
7 describe('CLI: composio whoami', () => {
8 + afterEach(() => {
9 + vi.restoreAllMocks();
10 + });
11 +
12 const testConfigProvider = ConfigProvider.fromMap(
13 new Map([['COMPOSIO_USER_API_KEY', 'api_key_from_test_config_provider']])
14 ).pipe(extendConfigProvider);
@@ -18,6 +23,8 @@ describe('CLI: composio whoami', () => {
23 const output = lines.join('\n');
24 expect(output).not.toContain(`api_key_from_test_config_provider`);
25 expect(output).not.toContain(`global_user_api_key`);
26 + expect(output).toContain(`"email":null`);
27 + expect(output).toContain(`"default_org_name":null`);
28 expect(output).toContain(`"default_org_id":null`);
29 expect(output).toContain(`"test_user_id":null`);
30 })
@@ -34,9 +41,57 @@ describe('CLI: composio whoami', () => {
41 const output = lines.join('\n');
42 expect(output).not.toContain(`api_key_from_test_fixture`);
43 expect(output).not.toContain(`global_user_api_key`);
44 + expect(output).toContain(`"email":null`);
45 + expect(output).toContain(`"default_org_name":null`);
46 expect(output).toContain(`"default_org_id":null`);
47 expect(output).toContain(`"test_user_id":null`);
48 })
49 );
50 });
51 +
52 + layer(TestLive({ baseConfigProvider: testConfigProvider }))('with session info', it => {
53 + it.scoped('[Given] session info is available [Then] prints email and org name', () =>
54 + Effect.gen(function* () {
55 + vi.spyOn(globalThis, 'fetch').mockResolvedValue(
56 + new Response(
57 + JSON.stringify({
58 + project: {
59 + name: 'Test Project',
60 + id: 'proj_123',
61 + org_id: 'org_123',
62 + nano_id: 'proj_nano_123',
63 + email: 'project@example.com',
64 + created_at: '2026-03-27T00:00:00.000Z',
65 + updated_at: '2026-03-27T00:00:00.000Z',
66 + org: {
67 + name: 'Acme Org',
68 + id: 'org_123',
69 + plan: 'enterprise',
70 + },
71 + },
72 + org_member: {
73 + id: 'om_123',
74 + user_id: 'usr_123',
75 + email: 'person@example.com',
76 + name: 'Test Person',
77 + role: 'admin',
78 + },
79 + api_key: null,
80 + }),
81 + {
82 + status: 200,
83 + headers: { 'Content-Type': 'application/json' },
84 + }
85 + )
86 + );
87 +
88 + yield* cli(['whoami']);
89 +
90 + const lines = yield* MockConsole.getLines();
91 + const output = lines.join('\n');
92 + expect(output).toContain(`"email":"person@example.com"`);
93 + expect(output).toContain(`"default_org_name":"Acme Org"`);
94 + })
95 + );
96 + });
97 });