@devries-cameron20 / composio Mirror · read-only / commits / 7873b990a
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 21, 08:30 UTC

refactor(cli): move `debug` into the directory shape (#4974)

This PR: - turns the unlisted `debug.cmd.ts` into the group entry `debug/debug.cmd.ts` and gives each diagnostic its own directory: `debug/generate-graph/`, `debug/api-info/` (cmd, handler, format), and `debug/who-is-my-master/`. All three stay `Command.unlisted` - keeps `api-info`'s behavior: the confirmation defaults to no, a missing key and a declined prompt are `CommandInputError`s for `debug` with the same messages, and only `missing_org` / `missing_developer_project` project failures fall back to `consumerUserId: null`. `consumerUserIdOf` is now an `Option` pipeline - adds one `.cmd.test.ts` per subcommand (graph JSON, detected master, declined / logged-out / confirmed `api-info`) and handler tests for `consumerUserIdOf` and the Codex/Claude/user detection table - removes `debug.cmd.ts` from `COMMAND_TEST_EXEMPTIONS` (15 to 14) Part of U9 of the CLI command-layout series. No user-visible change, so no CHANGELOG entry. Verified locally on the branch tip: | Check | Result | | --- | --- | | `pnpm --filter @composio/cli typecheck` | passes | | `pnpm --filter @composio/cli test` (skills, boundaries, command tests, Vitest) | 165 files, 1911 passed, 1 skipped | | `validate:command-tests` | 14 exemptions (was 15) | | `lint:effect` | 0 diagnostics | | `oxlint`, prettier on touched files | clean | | Binary smoke | `--help` of `debug` and each subcommand, `debug generate-graph`, `debug who-is-my-master`, headless `debug api-info` (aborts, exit 1), root `--help`: identical to an `origin/next` (231122de1) binary |

Alberto Schiabel committed Oct 20, 2026 at 16:29 UTC 7873b990a5bcd808ed736a04cf29b4843d6fba67
17 files changed +352 -80
ts/packages/cli/scripts/command-tests.ts
-1
@@ -19,7 +19,6 @@ const TEST_SUFFIX = '.cmd.test.ts';
19 // test/src/commands/. Both use forward slashes.
20 export const COMMAND_TEST_EXEMPTIONS: readonly CommandTestExemption[] = [
21 { command: 'connections/commands/connections.remove.cmd.ts', reason: 'no test yet' },
22 - { command: 'debug.cmd.ts', reason: 'no test yet' },
22 { command: 'signup.cmd.ts', reason: 'no test yet' },
23 { command: 'triggers/commands/triggers.listen.cmd.ts', reason: 'no test yet' },
24 { command: 'upgrade.cmd.ts', reason: 'no test yet' },
ts/packages/cli/src/commands/debug.cmd.ts deleted
-78
@@ -1,78 +0,0 @@
1 -import { commandInputError } from 'src/commands/errors';
2 -import { Command } from 'effect/cli';
3 -import { Effect, Option } from 'effect';
4 -import { TerminalUI } from 'src/services/terminal-ui';
5 -import { renderCommandHintGraph } from 'src/services/command-hints';
6 -import { ComposioUserContext } from 'src/services/user-context';
7 -import { detectMasterFromHost } from 'src/services/master-detector';
8 -import { resolveCommandProject, type ResolvedCommandProject } from 'src/services/command-project';
9 -
10 -const debugError = commandInputError('debug');
11 -
12 -const printCommandHintGraph = Effect.suspend(() =>
13 - Effect.flatMap(TerminalUI, ui =>
14 - ui.output(JSON.stringify(renderCommandHintGraph(), null, 2), { force: true })
15 - )
16 -);
17 -
18 -// Only a consumer project carries the playground user the API key acts for.
19 -const consumerUserIdOf = (project: ResolvedCommandProject | undefined): string | null => {
20 - if (project?.projectType !== 'CONSUMER') return null;
21 - return project.consumerUserId ?? null;
22 -};
23 -
24 -const printDebugApiInfo = Effect.gen(function* () {
25 - const ui = yield* TerminalUI;
26 - const confirmed = yield* ui.confirm(
27 - 'This will print your current CLI API key and scoped identifiers to stdout. Continue?',
28 - { defaultValue: false }
29 - );
30 - if (!confirmed) {
31 - return yield* debugError('Aborted printing API credentials.');
32 - }
33 - const ctx = yield* ComposioUserContext;
34 - const apiKey = Option.getOrUndefined(ctx.data.apiKey);
35 - if (!apiKey) {
36 - return yield* debugError('No user API key found in the current CLI session.');
37 - }
38 - const orgId = Option.getOrUndefined(ctx.data.orgId);
39 - // A project the user has not set up yet is a legitimate "none" here; a failed lookup is not,
40 - // and keeps its typed error so cli-main prints it and exits non-zero.
41 - const consumerProject = yield* resolveCommandProject({ mode: 'consumer' }).pipe(
42 - Effect.map(Option.some),
43 - Effect.catchTag('services/ProjectResolutionError', error =>
44 - error.reason === 'missing_org' || error.reason === 'missing_developer_project'
45 - ? Effect.succeed(Option.none())
46 - : Effect.fail(error)
47 - )
48 - );
49 - const consumerUserId = consumerUserIdOf(Option.getOrUndefined(consumerProject));
50 - return yield* ui.output(
51 - JSON.stringify(
52 - {
53 - apiKey,
54 - orgId: orgId ?? null,
55 - consumerUserId,
56 - },
57 - null,
58 - 2
59 - ),
60 - { force: true }
61 - );
62 -});
63 -
64 -const printDetectedMaster = Effect.gen(function* () {
65 - const ui = yield* TerminalUI;
66 - const master = yield* detectMasterFromHost;
67 - yield* ui.output(JSON.stringify({ master }, null, 2), { force: true });
68 -});
69 -
70 -export const debugCmd = Command.make('debug').pipe(
71 - Command.unlisted,
72 - Command.withDescription('Internal CLI diagnostics.'),
73 - Command.withSubcommands([
74 - Command.make('generate-graph', {}, () => printCommandHintGraph).pipe(Command.unlisted),
75 - Command.make('api-info', {}, () => printDebugApiInfo).pipe(Command.unlisted),
76 - Command.make('who-is-my-master', {}, () => printDetectedMaster).pipe(Command.unlisted),
77 - ])
78 -);
ts/packages/cli/src/commands/debug/api-info/debug.api-info.cmd.ts new
+6
@@ -0,0 +1,6 @@
1 +import { Command } from 'effect/cli';
2 +import { runDebugApiInfo } from './debug.api-info.handler';
3 +
4 +export const debugCmd$ApiInfo = Command.make('api-info', {}, runDebugApiInfo).pipe(
5 + Command.unlisted
6 +);
ts/packages/cli/src/commands/debug/api-info/debug.api-info.format.ts new
+25
@@ -0,0 +1,25 @@
1 +// --- stderr -----------------------------------------------------------------------------------
2 +
3 +export const CONFIRM_PRINT_CREDENTIALS_MESSAGE =
4 + 'This will print your current CLI API key and scoped identifiers to stdout. Continue?';
5 +
6 +// --- usage messages ---------------------------------------------------------------------------
7 +
8 +export const ABORTED_MESSAGE = 'Aborted printing API credentials.';
9 +export const NO_API_KEY_MESSAGE = 'No user API key found in the current CLI session.';
10 +
11 +// --- stdout -----------------------------------------------------------------------------------
12 +
13 +/** The credentials and identifiers `debug api-info` prints. */
14 +export type DebugApiInfo = {
15 + readonly apiKey: string;
16 + readonly orgId: string | null;
17 + readonly consumerUserId: string | null;
18 +};
19 +
20 +export const formatDebugApiInfo = (info: DebugApiInfo) =>
21 + JSON.stringify(
22 + { apiKey: info.apiKey, orgId: info.orgId, consumerUserId: info.consumerUserId },
23 + null,
24 + 2
25 + );
ts/packages/cli/src/commands/debug/api-info/debug.api-info.handler.ts new
+62
@@ -0,0 +1,62 @@
1 +import { Effect, Option } from 'effect';
2 +import { commandInputError } from 'src/commands/errors';
3 +import { resolveCommandProject, type ResolvedCommandProject } from 'src/services/command-project';
4 +import { TerminalUI } from 'src/services/terminal-ui';
5 +import { ComposioUserContext } from 'src/services/user-context';
6 +import {
7 + ABORTED_MESSAGE,
8 + CONFIRM_PRINT_CREDENTIALS_MESSAGE,
9 + NO_API_KEY_MESSAGE,
10 + formatDebugApiInfo,
11 +} from './debug.api-info.format';
12 +
13 +const debugError = commandInputError('debug');
14 +
15 +/** Only a consumer project carries the playground user the API key acts for. */
16 +export const consumerUserIdOf = (project: Option.Option<ResolvedCommandProject>): string | null =>
17 + project.pipe(
18 + Option.filter(resolved => resolved.projectType === 'CONSUMER'),
19 + Option.flatMapNullishOr(resolved => resolved.consumerUserId),
20 + Option.getOrNull
21 + );
22 +
23 +/**
24 + * The consumer project, when there is one. A project the user has not set up yet is a legitimate
25 + * "none" here; a failed lookup is not, and keeps its typed error so cli-main prints it and exits
26 + * non-zero.
27 + */
28 +const resolveConsumerProject = resolveCommandProject({ mode: 'consumer' }).pipe(
29 + Effect.map(Option.some),
30 + Effect.catchTag('services/ProjectResolutionError', error =>
31 + error.reason === 'missing_org' || error.reason === 'missing_developer_project'
32 + ? Effect.succeed(Option.none<ResolvedCommandProject>())
33 + : Effect.fail(error)
34 + )
35 +);
36 +
37 +/**
38 + * Prints the CLI's API key, current org, and consumer user id as JSON, after the user confirms.
39 + * Nothing gates the command on login, so a missing key is reported here.
40 + */
41 +export const runDebugApiInfo = () =>
42 + Effect.gen(function* () {
43 + const ui = yield* TerminalUI;
44 + const confirmed = yield* ui.confirm(CONFIRM_PRINT_CREDENTIALS_MESSAGE, { defaultValue: false });
45 + if (!confirmed) {
46 + return yield* debugError(ABORTED_MESSAGE);
47 + }
48 + const ctx = yield* ComposioUserContext;
49 + const apiKey = yield* Effect.fromOption(
50 + Option.filter(ctx.data.apiKey, key => key.length > 0),
51 + () => debugError(NO_API_KEY_MESSAGE)
52 + );
53 + const consumerProject = yield* resolveConsumerProject;
54 + yield* ui.output(
55 + formatDebugApiInfo({
56 + apiKey,
57 + orgId: Option.getOrNull(ctx.data.orgId),
58 + consumerUserId: consumerUserIdOf(consumerProject),
59 + }),
60 + { force: true }
61 + );
62 + });
ts/packages/cli/src/commands/debug/debug.cmd.ts new
+10
@@ -0,0 +1,10 @@
1 +import { Command } from 'effect/cli';
2 +import { debugCmd$ApiInfo } from './api-info/debug.api-info.cmd';
3 +import { debugCmd$GenerateGraph } from './generate-graph/debug.generate-graph.cmd';
4 +import { debugCmd$WhoIsMyMaster } from './who-is-my-master/debug.who-is-my-master.cmd';
5 +
6 +export const debugCmd = Command.make('debug').pipe(
7 + Command.unlisted,
8 + Command.withDescription('Internal CLI diagnostics.'),
9 + Command.withSubcommands([debugCmd$GenerateGraph, debugCmd$ApiInfo, debugCmd$WhoIsMyMaster])
10 +);
ts/packages/cli/src/commands/debug/generate-graph/debug.generate-graph.cmd.ts new
+8
@@ -0,0 +1,8 @@
1 +import { Command } from 'effect/cli';
2 +import { runDebugGenerateGraph } from './debug.generate-graph.handler';
3 +
4 +export const debugCmd$GenerateGraph = Command.make(
5 + 'generate-graph',
6 + {},
7 + runDebugGenerateGraph
8 +).pipe(Command.unlisted);
ts/packages/cli/src/commands/debug/generate-graph/debug.generate-graph.handler.ts new
+10
@@ -0,0 +1,10 @@
1 +import { Effect } from 'effect';
2 +import { renderCommandHintGraph } from 'src/services/command-hints';
3 +import { TerminalUI } from 'src/services/terminal-ui';
4 +
5 +/** Prints the command-hint graph as indented JSON. */
6 +export const runDebugGenerateGraph = () =>
7 + Effect.gen(function* () {
8 + const ui = yield* TerminalUI;
9 + yield* ui.output(JSON.stringify(renderCommandHintGraph(), null, 2), { force: true });
10 + });
ts/packages/cli/src/commands/debug/who-is-my-master/debug.who-is-my-master.cmd.ts new
+8
@@ -0,0 +1,8 @@
1 +import { Command } from 'effect/cli';
2 +import { runDebugWhoIsMyMaster } from './debug.who-is-my-master.handler';
3 +
4 +export const debugCmd$WhoIsMyMaster = Command.make(
5 + 'who-is-my-master',
6 + {},
7 + runDebugWhoIsMyMaster
8 +).pipe(Command.unlisted);
ts/packages/cli/src/commands/debug/who-is-my-master/debug.who-is-my-master.handler.ts new
+11
@@ -0,0 +1,11 @@
1 +import { Effect } from 'effect';
2 +import { detectMasterFromHost } from 'src/services/master-detector';
3 +import { TerminalUI } from 'src/services/terminal-ui';
4 +
5 +/** Prints which agent, if any, drives this process. */
6 +export const runDebugWhoIsMyMaster = () =>
7 + Effect.gen(function* () {
8 + const ui = yield* TerminalUI;
9 + const master = yield* detectMasterFromHost;
10 + yield* ui.output(JSON.stringify({ master }, null, 2), { force: true });
11 + });
ts/packages/cli/src/commands/index.ts
+1 -1
@@ -39,7 +39,7 @@ import { ComposioCliUserConfig } from 'src/services/cli-user-config';
39 import { CLI_EXPERIMENTAL_FEATURES } from 'src/constants';
40 import { experimental, type CommandVisibility, tagged, visibleValues } from './feature-tags';
41 import { withBackgroundUpdateCheck } from './background-update-check';
42 -import { debugCmd } from './debug.cmd';
42 +import { debugCmd } from './debug/debug.cmd';
43 import { normalizeListenStreamFlag, normalizeRunScriptArgs } from './argv-compat';
44 import { configureCliAnalyticsReleaseVersion } from 'src/analytics/events';
45 import { CommandSurface } from './surface';
ts/packages/cli/test/__fixtures__/user-config-with-empty-api-key/.composio/user_data.json new
+5
@@ -0,0 +1,5 @@
1 +{
2 + "api_key": "",
3 + "org_id": "org_1",
4 + "project_id": "project_1"
5 +}
ts/packages/cli/test/src/commands/debug/api-info/debug.api-info.cmd.test.ts new
+87
@@ -0,0 +1,87 @@
1 +import { describe, expect, layer } from '@effect/vitest';
2 +import { Effect } from 'effect';
3 +import {
4 + ABORTED_MESSAGE,
5 + NO_API_KEY_MESSAGE,
6 +} from 'src/commands/debug/api-info/debug.api-info.format';
7 +import { TerminalUI } from 'src/services/terminal-ui';
8 +import { cli, MockConsole, TestLive } from 'test/__utils__';
9 +import { terminalUITestImpl } from 'test/__utils__/services/terminal-ui-test';
10 +
11 +// The fixture stores `uak_test_key` with current org `org_1`.
12 +const LOGGED_IN_FIXTURE = 'user-config-with-global-context';
13 +
14 +/** A headless terminal that answers yes to every confirmation. */
15 +const confirmingUI = TerminalUI.of({
16 + ...terminalUITestImpl,
17 + confirm: () => Effect.succeed(true),
18 +});
19 +
20 +describe('CLI: composio debug api-info', () => {
21 + layer(TestLive({ fixture: LOGGED_IN_FIXTURE }))('[Given] the confirmation is declined', it => {
22 + it.effect('[Then] fails with a usage error and prints nothing on stdout', () =>
23 + Effect.gen(function* () {
24 + const error = yield* cli(['debug', 'api-info']).pipe(Effect.flip);
25 +
26 + expect(error).toMatchObject({
27 + _tag: 'commands/CommandInputError',
28 + command: 'debug',
29 + message: ABORTED_MESSAGE,
30 + });
31 + expect(yield* MockConsole.getLines({ stream: 'stdout' })).toEqual([]);
32 + })
33 + );
34 + });
35 +
36 + layer(TestLive({ terminalUI: confirmingUI }))('[Given] no stored login', it => {
37 + it.effect('[Then] fails with a usage error naming the missing key', () =>
38 + Effect.gen(function* () {
39 + const error = yield* cli(['debug', 'api-info']).pipe(Effect.flip);
40 +
41 + expect(error).toMatchObject({
42 + _tag: 'commands/CommandInputError',
43 + command: 'debug',
44 + message: NO_API_KEY_MESSAGE,
45 + });
46 + })
47 + );
48 + });
49 +
50 + layer(TestLive({ fixture: 'user-config-with-empty-api-key', terminalUI: confirmingUI }))(
51 + '[Given] a stored login whose key is empty',
52 + it => {
53 + it.effect('[Then] fails naming the missing key and prints nothing on stdout', () =>
54 + Effect.gen(function* () {
55 + const error = yield* cli(['debug', 'api-info']).pipe(Effect.flip);
56 +
57 + expect(error).toMatchObject({
58 + _tag: 'commands/CommandInputError',
59 + command: 'debug',
60 + message: NO_API_KEY_MESSAGE,
61 + });
62 + expect(yield* MockConsole.getLines({ stream: 'stdout' })).toEqual([]);
63 + })
64 + );
65 + }
66 + );
67 +
68 + layer(TestLive({ fixture: LOGGED_IN_FIXTURE, terminalUI: confirmingUI }))(
69 + '[Given] a stored login and a confirmation',
70 + it => {
71 + it.effect('[Then] prints the key, org, and consumer user id as indented JSON', () =>
72 + Effect.gen(function* () {
73 + yield* cli(['debug', 'api-info']);
74 +
75 + const stdout = yield* MockConsole.getLines({ stream: 'stdout' });
76 + expect(stdout).toHaveLength(1);
77 + expect(JSON.parse(stdout[0] ?? '')).toEqual({
78 + apiKey: 'uak_test_key',
79 + orgId: 'org_1',
80 + consumerUserId: 'consumer-user-org_1',
81 + });
82 + expect(stdout[0]).toContain('\n "apiKey"');
83 + })
84 + );
85 + }
86 + );
87 +});
ts/packages/cli/test/src/commands/debug/api-info/debug.api-info.handler.test.ts new
+32
@@ -0,0 +1,32 @@
1 +import { describe, expect, it } from 'vitest';
2 +import { Option } from 'effect';
3 +import { consumerUserIdOf } from 'src/commands/debug/api-info/debug.api-info.handler';
4 +import type { ResolvedCommandProject } from 'src/services/command-project';
5 +
6 +const project = (overrides: Partial<ResolvedCommandProject>): ResolvedCommandProject => ({
7 + orgId: 'org_1',
8 + projectId: 'project_1',
9 + projectType: 'CONSUMER',
10 + source: 'consumer-default',
11 + ...overrides,
12 +});
13 +
14 +describe('debug api-info handler: consumerUserIdOf', () => {
15 + // Only a consumer project carries the playground user the API key acts for.
16 + it.each([
17 + { name: 'no project', input: Option.none(), expected: null },
18 + {
19 + name: 'a consumer project with a user',
20 + input: Option.some(project({ consumerUserId: 'consumer-user-org_1' })),
21 + expected: 'consumer-user-org_1',
22 + },
23 + { name: 'a consumer project without a user', input: Option.some(project({})), expected: null },
24 + {
25 + name: 'a developer project with a user',
26 + input: Option.some(project({ projectType: 'DEVELOPER', consumerUserId: 'ignored' })),
27 + expected: null,
28 + },
29 + ])('[Given] $name [Then] returns $expected', ({ input, expected }) => {
30 + expect(consumerUserIdOf(input)).toBe(expected);
31 + });
32 +});
ts/packages/cli/test/src/commands/debug/generate-graph/debug.generate-graph.cmd.test.ts new
+19
@@ -0,0 +1,19 @@
1 +import { describe, expect, layer } from '@effect/vitest';
2 +import { Effect } from 'effect';
3 +import { renderCommandHintGraph } from 'src/services/command-hints';
4 +import { cli, MockConsole, TestLive } from 'test/__utils__';
5 +
6 +describe('CLI: composio debug generate-graph', () => {
7 + layer(TestLive())(it => {
8 + it.effect('[Then] prints the command-hint graph as indented JSON on stdout', () =>
9 + Effect.gen(function* () {
10 + yield* cli(['debug', 'generate-graph']);
11 +
12 + expect(yield* MockConsole.getLines({ stream: 'stdout' })).toEqual([
13 + JSON.stringify(renderCommandHintGraph(), null, 2),
14 + ]);
15 + expect(yield* MockConsole.getLines({ stream: 'stderr' })).toEqual([]);
16 + })
17 + );
18 + });
19 +});
ts/packages/cli/test/src/commands/debug/who-is-my-master/debug.who-is-my-master.cmd.test.ts new
+20
@@ -0,0 +1,20 @@
1 +import { describe, expect, layer } from '@effect/vitest';
2 +import { Effect } from 'effect';
3 +import { detectMasterFromHost } from 'src/services/master-detector';
4 +import { cli, MockConsole, TestLive } from 'test/__utils__';
5 +
6 +describe('CLI: composio debug who-is-my-master', () => {
7 + layer(TestLive())(it => {
8 + // The host environment decides the answer, so the test reads it through the same detector.
9 + it.effect('[Then] prints the detected master as indented JSON on stdout', () =>
10 + Effect.gen(function* () {
11 + const master = yield* detectMasterFromHost;
12 + yield* cli(['debug', 'who-is-my-master']);
13 +
14 + expect(yield* MockConsole.getLines({ stream: 'stdout' })).toEqual([
15 + JSON.stringify({ master }, null, 2),
16 + ]);
17 + })
18 + );
19 + });
20 +});
ts/packages/cli/test/src/commands/debug/who-is-my-master/debug.who-is-my-master.handler.test.ts new
+48
@@ -0,0 +1,48 @@
1 +import { describe, expect, it } from '@effect/vitest';
2 +import { ConfigProvider, Effect, Layer } from 'effect';
3 +import { runDebugWhoIsMyMaster } from 'src/commands/debug/who-is-my-master/debug.who-is-my-master.handler';
4 +import { TerminalUI } from 'src/services/terminal-ui';
5 +import { terminalUITestImpl } from 'test/__utils__/services/terminal-ui-test';
6 +
7 +/** A headless terminal whose stdout data lands in `outputs`, over exactly `env`. */
8 +const masterTest = (env: Record<string, string>) => {
9 + const outputs: Array<string> = [];
10 + const layer = Layer.mergeAll(
11 + Layer.succeed(
12 + TerminalUI,
13 + TerminalUI.of({
14 + ...terminalUITestImpl,
15 + output: data =>
16 + Effect.sync(() => {
17 + outputs.push(data);
18 + }),
19 + })
20 + ),
21 + ConfigProvider.layer(ConfigProvider.fromEnvRecord(env))
22 + );
23 + return { layer, outputs };
24 +};
25 +
26 +describe('runDebugWhoIsMyMaster', () => {
27 + it.effect.each<{
28 + readonly name: string;
29 + readonly env: Record<string, string>;
30 + readonly master: string;
31 + }>([
32 + { name: 'a CODEX_* variable', env: { CODEX_HOME: '/codex' }, master: 'codex' },
33 + { name: 'a CLAUDE_* variable', env: { CLAUDE_CODE_ENTRYPOINT: 'cli' }, master: 'claude' },
34 + {
35 + name: 'both (Codex wins)',
36 + env: { CODEX_HOME: '/codex', CLAUDE_CODE_ENTRYPOINT: 'cli' },
37 + master: 'codex',
38 + },
39 + { name: 'neither', env: {}, master: 'user' },
40 + ])('[Given] $name [Then] prints `$master`', ({ env, master }) => {
41 + const { layer, outputs } = masterTest(env);
42 + return Effect.gen(function* () {
43 + yield* runDebugWhoIsMyMaster();
44 +
45 + expect(outputs).toEqual([JSON.stringify({ master }, null, 2)]);
46 + }).pipe(Effect.provide(layer));
47 + });
48 +});