@devries-cameron20 / composio-1 / commits / 90582e182
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.

refactor(cli): collapse `generate` into the directory shape (#4897)

This PR: - moves `generate`, `generate ts` and `generate py` into the directory shape under `src/commands/generate/` (`generate.{cmd,handler}.ts`, `ts/generate.ts.{cmd,handler,errors}.ts`, `py/generate.py.{cmd,handler,errors}.ts`), the layout https://github.com/ComposioHQ/composio/pull/4887 defines - deletes the phantom `_tsCmd$Generate` and `_pyCmd$Generate` commands, `GetCmdParams` (`src/type-utils.ts`), the two wrapper files `generate/generate.{ts,py}.cmd.ts`, and the `src/commands/ts/` and `src/commands/py/` directories; each handler declares its own params type and the three-argument `Command.make` proves the flags satisfy it - names the `--transpiled` default rule (`true` only without `--output-dir`) as `resolveTranspiled` with an `it.each` table over both axes, and makes `generate` call it instead of restating the rule - moves the `ts.generate` and `py.generate` suites to their mirrored paths unchanged, and removes the two `generate/*` entries from `COMMAND_TEST_EXEMPTIONS` (18 → 16) - bans Effect Do notation (`X.Do`, and `bind`/`bindTo`/`let` on `Effect`, `Array`, `Option`, `Result`, `Stream`) across CLI `src/` and `test/src/`, and `for`/`for…in`/`for…of` loops in CLI `test/src/`, both via `eslint-js/no-restricted-syntax` in `.oxlintrc.json`; the two existing `Arr.Do` tables and seven loops in test helpers are rewritten as explicit tables, `flatMap`, `forEach`, and `reduce` ## Context Unit U2 of the command-layout series; independent of the surface-service unit. No behavior or output change: `generate --help`, `generate ts --help` and `generate py --help` are byte-identical to `next`, and the flag renames (`outputOpt` → `outputDir`, `toolkitsOpt` → `toolkits`) are internal. Left as is: the TypeScript handler keeps its fetch and write helpers in one file rather than a separate `format.ts`, since what it renders is a handful of `ui.*` calls between spinner updates. Rebased onto `next` after https://github.com/ComposioHQ/composio/pull/4855 and https://github.com/ComposioHQ/composio/pull/4898 merged; the moved `ts`/`py` suites carry #4898's edits unchanged (git followed the renames, no conflict). Verified locally after the rebase: `pnpm typecheck`; the CLI suite (154 files, 1819 passed, 1 skipped; `validate:command-tests` reports 16 exemptions, down from 18; `validate:boundaries` unchanged); `oxlint ts/packages/cli` with zero errors, plus a probe file confirming the new rules flag `Arr.Do`/`Arr.bind` and all three loop forms without flagging `Function.prototype.bind`; `startup-imports.test.ts` still keeps the generation runtime off the startup path; help output for the three surfaces diffed empty against `next`.

Alberto Schiabel committed Oct 16, 2026 at 03:00 UTC 90582e182104af9ff4502899dea00c8e4e303267
22 files changed +267 -245
.oxlintrc.json
+36
@@ -193,6 +193,14 @@
193 ],
194 "eslint-js/no-restricted-syntax": [
195 "error",
196 + {
197 + "selector": "MemberExpression[property.name='Do']",
198 + "message": "Do notation is banned: use Effect.gen, or plain map/flatMap."
199 + },
200 + {
201 + "selector": "MemberExpression[object.name=/^(Effect|Arr|Array|Option|Result|Stream)$/][property.name=/^(bind|bindTo|let)$/]",
202 + "message": "Do notation is banned: use Effect.gen, or plain map/flatMap."
203 + },
204 {
205 "selector": "TryStatement",
206 "message": "Use Effect.try, Effect.tryPromise, or typed Effect error recovery instead of try/catch."
@@ -246,6 +254,18 @@
254 "max-lines-per-function": "off",
255 "eslint-js/no-restricted-syntax": [
256 "error",
257 + {
258 + "selector": "MemberExpression[property.name='Do']",
259 + "message": "Do notation is banned: use Effect.gen, or plain map/flatMap."
260 + },
261 + {
262 + "selector": "MemberExpression[object.name=/^(Effect|Arr|Array|Option|Result|Stream)$/][property.name=/^(bind|bindTo|let)$/]",
263 + "message": "Do notation is banned: use Effect.gen, or plain map/flatMap."
264 + },
265 + {
266 + "selector": ":matches(ForStatement, ForInStatement, ForOfStatement)",
267 + "message": "No for loops in tests: parameterize with it.each/describe.each, and use array methods in helpers."
268 + },
269 {
270 "selector": "MemberExpression[object.name='Effect'][property.name=/^run/]",
271 "message": "Run Effects through @effect/vitest (it.effect, it.live) instead of Effect.run* in tests."
@@ -321,6 +341,14 @@
341 ],
342 "eslint-js/no-restricted-syntax": [
343 "error",
344 + {
345 + "selector": "MemberExpression[property.name='Do']",
346 + "message": "Do notation is banned: use Effect.gen, or plain map/flatMap."
347 + },
348 + {
349 + "selector": "MemberExpression[object.name=/^(Effect|Arr|Array|Option|Result|Stream)$/][property.name=/^(bind|bindTo|let)$/]",
350 + "message": "Do notation is banned: use Effect.gen, or plain map/flatMap."
351 + },
352 {
353 "selector": "TryStatement",
354 "message": "Use Effect.try, Effect.tryPromise, or typed Effect error recovery instead of try/catch."
@@ -382,6 +410,14 @@
410 // TerminalUI is the sole CLI boundary for Node's stdout and stderr streams.
411 "eslint-js/no-restricted-syntax": [
412 "error",
413 + {
414 + "selector": "MemberExpression[property.name='Do']",
415 + "message": "Do notation is banned: use Effect.gen, or plain map/flatMap."
416 + },
417 + {
418 + "selector": "MemberExpression[object.name=/^(Effect|Arr|Array|Option|Result|Stream)$/][property.name=/^(bind|bindTo|let)$/]",
419 + "message": "Do notation is banned: use Effect.gen, or plain map/flatMap."
420 + },
421 {
422 "selector": "TryStatement",
423 "message": "Use Effect.try, Effect.tryPromise, or typed Effect error recovery instead of try/catch."
ts/packages/cli/scripts/command-tests.ts
-8
@@ -26,14 +26,6 @@ export const COMMAND_TEST_EXEMPTIONS: readonly CommandTestExemption[] = [
26 { command: 'artifacts.cmd.ts', reason: 'no test yet' },
27 { command: 'connections/commands/connections.remove.cmd.ts', reason: 'no test yet' },
28 { command: 'debug.cmd.ts', reason: 'no test yet' },
29 - {
30 - command: 'generate/generate.py.cmd.ts',
31 - reason: 'thin wrapper over py.generate; covered by py/py.generate.cmd.test.ts',
32 - },
33 - {
34 - command: 'generate/generate.ts.cmd.ts',
35 - reason: 'thin wrapper over ts.generate; covered by ts/ts.generate.cmd.test.ts',
36 - },
29 {
30 command: 'logs/commands/logs.triggers.cmd.ts',
31 reason: 'covered by logs.triggers.client.cmd.test.ts; split pending',
ts/packages/cli/src/commands/generate/generate.cmd.ts
+10 -42
@@ -1,14 +1,9 @@
1 import { Command, Flag } from 'effect/cli';
2 -import { Effect, Match, Option } from 'effect';
3 -import { ProjectEnvironmentDetector } from 'src/services/project-environment-detector';
4 -import { NodeProcess } from 'src/services/node-process';
5 -import { TerminalUI } from 'src/services/terminal-ui';
6 -import { generateTypescriptTypeStubs } from '../ts/commands/ts.generate.cmd';
7 -import { generatePythonTypeStubs } from '../py/commands/py.generate.cmd';
8 -import { generateCmd$Py } from './generate.py.cmd';
9 -import { generateCmd$Ts } from './generate.ts.cmd';
2 +import { runGenerate } from './generate.handler';
3 +import { generateCmd$Py } from './py/generate.py.cmd';
4 +import { generateCmd$Ts } from './ts/generate.ts.cmd';
5
11 -const outputOpt = Flag.optional(Flag.Directory('output-dir')).pipe(
6 +const outputDir = Flag.optional(Flag.Directory('output-dir')).pipe(
7 Flag.withAlias('o'),
8 Flag.withDescription('Output directory for type stubs')
9 );
@@ -20,7 +15,7 @@ const typeTools = Flag.Boolean('type-tools').pipe(
15 )
16 );
17
23 -const toolkitsOpt = Flag.String('toolkits').pipe(
18 +const toolkits = Flag.String('toolkits').pipe(
19 Flag.atLeast(0),
20 Flag.withDescription(
21 'Only generate types for specific toolkits (e.g., --toolkits gmail --toolkits slack)'
@@ -41,40 +36,13 @@ const toolkitsOpt = Flag.String('toolkits').pipe(
36 * composio generate ts --type-tools
37 * ```
38 */
44 -export const generateCmd = Command.make('generate', { outputOpt, typeTools, toolkitsOpt }).pipe(
39 +export const generateCmd = Command.make(
40 + 'generate',
41 + { outputDir, typeTools, toolkits },
42 + runGenerate
43 +).pipe(
44 Command.withDescription(
45 'Generate type stubs for toolkits, tools, and triggers, auto-detecting project language (TypeScript | Python)'
46 ),
48 - Command.withHandler(({ outputOpt, typeTools, toolkitsOpt }) =>
49 - Effect.gen(function* () {
50 - const ui = yield* TerminalUI;
51 - const process = yield* NodeProcess;
52 - const cwd = process.cwd;
53 -
54 - yield* Effect.logDebug('Identifying project type...');
55 - const envDetector = yield* ProjectEnvironmentDetector;
56 - const env = yield* envDetector.detectProjectEnvironment(cwd);
57 - const displayLang = env.kind === 'js' ? 'TypeScript' : 'Python';
58 - yield* ui.log.step(`Project type detected: ${displayLang}`);
59 -
60 - // Apply the same transpile default as `composio generate ts`:
61 - // transpile when writing to node_modules (no --output-dir)
62 - const shouldCompile = !Option.isSome(outputOpt);
63 -
64 - yield* Match.value(env.kind).pipe(
65 - Match.when('js', () =>
66 - generateTypescriptTypeStubs({
67 - outputOpt,
68 - compact: false,
69 - transpiled: shouldCompile,
70 - typeTools,
71 - toolkitsOpt,
72 - })
73 - ),
74 - Match.when('python', () => generatePythonTypeStubs({ outputOpt, toolkitsOpt })),
75 - Match.exhaustive
76 - );
77 - })
78 - ),
47 Command.withSubcommands([generateCmd$Py, generateCmd$Ts])
48 );
ts/packages/cli/src/commands/generate/generate.handler.ts new
+43
@@ -0,0 +1,43 @@
1 +import { Effect, Match, Option } from 'effect';
2 +import { ProjectEnvironmentDetector } from 'src/services/project-environment-detector';
3 +import { NodeProcess } from 'src/services/node-process';
4 +import { TerminalUI } from 'src/services/terminal-ui';
5 +import { generateTypescriptTypeStubs, resolveTranspiled } from './ts/generate.ts.handler';
6 +import { runGeneratePy } from './py/generate.py.handler';
7 +
8 +export type GenerateParams = {
9 + readonly outputDir: Option.Option<string>;
10 + readonly typeTools: boolean;
11 + readonly toolkits: ReadonlyArray<string>;
12 +};
13 +
14 +/**
15 + * Detects the project language in the current directory and runs the matching generator.
16 + */
17 +export const runGenerate = ({ outputDir, typeTools, toolkits }: GenerateParams) =>
18 + Effect.gen(function* () {
19 + const ui = yield* TerminalUI;
20 + const process = yield* NodeProcess;
21 + const cwd = process.cwd;
22 +
23 + yield* Effect.logDebug('Identifying project type...');
24 + const envDetector = yield* ProjectEnvironmentDetector;
25 + const env = yield* envDetector.detectProjectEnvironment(cwd);
26 + const displayLang = env.kind === 'js' ? 'TypeScript' : 'Python';
27 + yield* ui.log.step(`Project type detected: ${displayLang}`);
28 +
29 + yield* Match.value(env.kind).pipe(
30 + Match.when('js', () =>
31 + generateTypescriptTypeStubs({
32 + outputDir,
33 + compact: false,
34 + // `generate` has no --transpiled flag, so the `generate ts` default rule applies.
35 + transpiled: resolveTranspiled({ transpiled: false, outputDir }),
36 + typeTools,
37 + toolkits,
38 + })
39 + ),
40 + Match.when('python', () => runGeneratePy({ outputDir, toolkits })),
41 + Match.exhaustive
42 + );
43 + });
ts/packages/cli/src/commands/generate/generate.py.cmd.ts deleted
-10
@@ -1,10 +0,0 @@
1 -import { Command } from 'effect/cli';
2 -import { generatePythonTypeStubs, outputOpt, toolkitsOpt } from '../py/commands/py.generate.cmd';
3 -
4 -/**
5 - * `composio generate py` — Generate Python type stubs.
6 - */
7 -export const generateCmd$Py = Command.make('py', { outputOpt, toolkitsOpt }).pipe(
8 - Command.withDescription('Generate Python type stubs for toolkits, tools, and triggers.'),
9 - Command.withHandler(generatePythonTypeStubs)
10 -);
ts/packages/cli/src/commands/generate/generate.ts.cmd.ts deleted
-23
@@ -1,23 +0,0 @@
1 -import { Command } from 'effect/cli';
2 -import {
3 - outputOpt,
4 - compact,
5 - transpiled,
6 - typeTools,
7 - toolkitsOpt,
8 - handleTsGenerate,
9 -} from '../ts/commands/ts.generate.cmd';
10 -
11 -/**
12 - * `composio generate ts` — Generate TypeScript type stubs.
13 - */
14 -export const generateCmd$Ts = Command.make('ts', {
15 - outputOpt,
16 - compact,
17 - transpiled,
18 - typeTools,
19 - toolkitsOpt,
20 -}).pipe(
21 - Command.withDescription('Generate TypeScript type stubs for toolkits, tools, and triggers.'),
22 - Command.withHandler(handleTsGenerate)
23 -);
ts/packages/cli/src/commands/generate/py/generate.py.cmd.ts new
+21
@@ -0,0 +1,21 @@
1 +import { Command, Flag } from 'effect/cli';
2 +import { runGeneratePy } from './generate.py.handler';
3 +
4 +const outputDir = Flag.optional(Flag.Directory('output-dir')).pipe(
5 + Flag.withAlias('o'),
6 + Flag.withDescription('Output directory for the generated Python type stubs')
7 +);
8 +
9 +const toolkits = Flag.String('toolkits').pipe(
10 + Flag.atLeast(0),
11 + Flag.withDescription(
12 + 'Only generate types for specific toolkits (e.g., --toolkits gmail --toolkits slack)'
13 + )
14 +);
15 +
16 +/**
17 + * `composio generate py` — Generate Python type stubs.
18 + */
19 +export const generateCmd$Py = Command.make('py', { outputDir, toolkits }, runGeneratePy).pipe(
20 + Command.withDescription('Generate Python type stubs for toolkits, tools, and triggers.')
21 +);
ts/packages/cli/src/commands/generate/py/generate.py.errors.ts new
+9
@@ -0,0 +1,9 @@
1 +import { Data } from 'effect';
2 +
3 +export class PythonGenerationWriteError extends Data.TaggedError(
4 + 'commands/PythonGenerationWriteError'
5 +)<{
6 + readonly cause: unknown;
7 + readonly filePath: string;
8 + readonly message: string;
9 +}> {}
ts/packages/cli/src/commands/generate/py/generate.py.handler.ts renamed
+24 -45
@@ -1,11 +1,19 @@
1 -import { commandInputError } from 'src/commands/errors';
2 -import { Command, Flag } from 'effect/cli';
3 -import { Array, Data, Effect, Option, pipe, String } from 'effect';
1 +/**
2 + * The `composio generate py` command can be configured as follows:
3 + * - `--output-dir`: Output directory for the generated Python type stubs.
4 + * - `--toolkits`: Filter output to only include the specified toolkits. Can be specified multiple times (e.g., --toolkits gmail --toolkits slack)
5 + *
6 + * Environment variables:
7 + * - `COMPOSIO_TOOLKIT_VERSION_<TOOLKIT>`: Override a toolkit version (e.g., COMPOSIO_TOOLKIT_VERSION_GMAIL=20250901_00).
8 + * Use "latest" or unset to use the latest version.
9 + */
10 +
11 +import { Array, Effect, Option, pipe, String } from 'effect';
12 import * as FileSystem from 'effect/FileSystem';
13 import * as Path from 'effect/Path';
14 +import { commandInputError } from 'src/commands/errors';
15 import { ComposioToolkitsRepository } from 'src/services/composio-clients';
16 import { logMetrics } from 'src/effects/log-metrics';
8 -import type { GetCmdParams } from 'src/type-utils';
17 import { NodeProcess } from 'src/services/node-process';
18 import { pyFindComposioCoreGenerated } from 'src/effects/find-composio-core-generated';
19 import { generationOutcome, loadGenerationRuntime } from 'src/effects/generation-runtime';
@@ -15,45 +23,17 @@ import {
23 } from 'src/effects/toolkit-version-overrides';
24 import { validateToolkitVersionOverrides } from 'src/effects/validate-toolkit-versions';
25 import { TerminalUI } from 'src/services/terminal-ui';
26 +import { PythonGenerationWriteError } from './generate.py.errors';
27
19 -export class PythonGenerationWriteError extends Data.TaggedError(
20 - 'commands/PythonGenerationWriteError'
21 -)<{
22 - readonly cause: unknown;
23 - readonly filePath: string;
24 - readonly message: string;
25 -}> {}
28 +export type GeneratePyParams = {
29 + readonly outputDir: Option.Option<string>;
30 + readonly toolkits: ReadonlyArray<string>;
31 +};
32
33 const invalidGenerateValue = commandInputError('generate py');
34
29 -export const outputOpt = Flag.optional(Flag.Directory('output-dir')).pipe(
30 - Flag.withAlias('o'),
31 - Flag.withDescription('Output directory for the generated Python type stubs')
32 -);
33 -
34 -export const toolkitsOpt = Flag.String('toolkits').pipe(
35 - Flag.atLeast(0),
36 - Flag.withDescription(
37 - 'Only generate types for specific toolkits (e.g., --toolkits gmail --toolkits slack)'
38 - )
39 -);
40 -
41 -const _pyCmd$Generate = Command.make('generate', { outputOpt, toolkitsOpt }).pipe(
42 - Command.withDescription(
43 - 'Generate Python type stubs for toolkits, tools, and triggers from the Composio API.\n\n' +
44 - 'Environment Variables:\n' +
45 - ' COMPOSIO_TOOLKIT_VERSION_<TOOLKIT> Override toolkit version (e.g., COMPOSIO_TOOLKIT_VERSION_GMAIL=20250901_00)\n' +
46 - ' Use "latest" or unset to use the latest version.'
47 - )
48 -);
49 -
50 -export const pyCmd$Generate = _pyCmd$Generate.pipe(Command.withHandler(generatePythonTypeStubs));
51 -
52 -export function generatePythonTypeStubs({
53 - outputOpt,
54 - toolkitsOpt,
55 -}: GetCmdParams<typeof _pyCmd$Generate>) {
56 - return Effect.gen(function* () {
35 +export const runGeneratePy = (params: GeneratePyParams) =>
36 + Effect.gen(function* () {
37 const ui = yield* TerminalUI;
38 const process = yield* NodeProcess;
39 const cwd = process.cwd;
@@ -64,7 +44,7 @@ export function generatePythonTypeStubs({
44 yield* ui.intro('composio generate py');
45
46 // Determine the actual output directory
67 - const outputDir = yield* outputOpt.pipe(
47 + const outputDir = yield* params.outputDir.pipe(
48 Option.match({
49 // If no output directory is specified, use the default
50 onNone: () => pyFindComposioCoreGenerated(cwd),
@@ -92,8 +72,8 @@ export function generatePythonTypeStubs({
72 const versionOverrides = yield* getToolkitVersionOverrides;
73
74 // Validate toolkit slugs if specified
95 - const hasToolkitsFilter = Array.isReadonlyArrayNonEmpty(toolkitsOpt);
96 - const toolkitSlugsFilter = hasToolkitsFilter ? toolkitsOpt.map(s => s.toLowerCase()) : null;
75 + const hasToolkitsFilter = Array.isReadonlyArrayNonEmpty(params.toolkits);
76 + const toolkitSlugsFilter = hasToolkitsFilter ? params.toolkits.map(s => s.toLowerCase()) : null;
77
78 // Validate toolkit version overrides before fetching data
79 const { validatedOverrides } = yield* validateToolkitVersionOverrides({
@@ -108,7 +88,7 @@ export function generatePythonTypeStubs({
88 // Validate toolkit slugs if specified (separate from version validation)
89 const validatedToolkitSlugs = hasToolkitsFilter
90 ? yield* client
111 - .validateToolkits(toolkitsOpt)
91 + .validateToolkits(params.toolkits)
92 .pipe(
93 Effect.catchTag('services/InvalidToolkitsError', error =>
94 Effect.fail(
@@ -201,7 +181,7 @@ export function generatePythonTypeStubs({
181 })
182 );
183
204 - yield* Option.isNone(outputOpt)
184 + yield* Option.isNone(params.outputDir)
185 ? ui.note(
186 'from composio.generated.<toolkit_name> import <TOOLKIT_NAME>',
187 'Import your generated types'
@@ -217,4 +197,3 @@ export function generatePythonTypeStubs({
197
198 return outputDir;
199 });
220 -}
ts/packages/cli/src/commands/generate/ts/generate.ts.cmd.ts new
+42
@@ -0,0 +1,42 @@
1 +import { Command, Flag } from 'effect/cli';
2 +import { runGenerateTs } from './generate.ts.handler';
3 +
4 +const outputDir = Flag.optional(Flag.Directory('output-dir')).pipe(
5 + Flag.withAlias('o'),
6 + Flag.withDescription('Output directory for the generated TypeScript type stubs.')
7 +);
8 +
9 +const compact = Flag.Boolean('compact').pipe(
10 + Flag.withDefault(false),
11 + Flag.withDescription('Emit a single TypeScript file')
12 +);
13 +
14 +const transpiled = Flag.Boolean('transpiled').pipe(
15 + Flag.withDefault(false),
16 + Flag.withDescription('Whether to emit transpiled JavaScript alongside TypeScript files')
17 +);
18 +
19 +const typeTools = Flag.Boolean('type-tools').pipe(
20 + Flag.withDefault(false),
21 + Flag.withDescription(
22 + 'Generate typed input/output schemas for each tool (slower, fetches full tool definitions)'
23 + )
24 +);
25 +
26 +const toolkits = Flag.String('toolkits').pipe(
27 + Flag.atLeast(0),
28 + Flag.withDescription(
29 + 'Only generate types for specific toolkits (e.g., --toolkits gmail --toolkits slack)'
30 + )
31 +);
32 +
33 +/**
34 + * `composio generate ts` — Generate TypeScript type stubs.
35 + */
36 +export const generateCmd$Ts = Command.make(
37 + 'ts',
38 + { outputDir, compact, transpiled, typeTools, toolkits },
39 + runGenerateTs
40 +).pipe(
41 + Command.withDescription('Generate TypeScript type stubs for toolkits, tools, and triggers.')
42 +);
ts/packages/cli/src/commands/generate/ts/generate.ts.errors.ts new
+9
@@ -0,0 +1,9 @@
1 +import { Data } from 'effect';
2 +
3 +export class TypeScriptGenerationWriteError extends Data.TaggedError(
4 + 'commands/TypeScriptGenerationWriteError'
5 +)<{
6 + readonly cause: unknown;
7 + readonly filePath: string;
8 + readonly message: string;
9 +}> {}
ts/packages/cli/src/commands/generate/ts/generate.ts.handler.ts renamed
+31 -80
@@ -5,6 +5,10 @@
5 * - `--output-dir`: Output directory for the generated TypeScript type stubs.
6 * - `--toolkits`: Filter output to only include the specified toolkits. Can be specified multiple times (e.g., --toolkits gmail --toolkits slack)
7 *
8 + * Environment variables:
9 + * - `COMPOSIO_TOOLKIT_VERSION_<TOOLKIT>`: Override a toolkit version (e.g., COMPOSIO_TOOLKIT_VERSION_GMAIL=20250901_00).
10 + * Use "latest" or unset to use the latest version.
11 + *
12 * Invariants:
13 * - The `--output-dir` cannot refer to a path inside `node_modules`
14 * - If `--output-dir` is not specified, the command will use `findComposioCoreGeneratedPath` to locate the `@composio/core` package
@@ -15,18 +19,15 @@
19 * and stored along with the generated TypeScript files. CJS is not supported.
20 */
21
18 -import { Command, Flag } from 'effect/cli';
19 -import { Array, Data, Effect, Option, pipe } from 'effect';
22 +import { Array, Effect, Match, Option, pipe } from 'effect';
23 import * as FileSystem from 'effect/FileSystem';
24 import * as Path from 'effect/Path';
22 -import { Match } from 'effect';
25 import {
26 ComposioToolkitsRepository,
27 type ComposioToolkitsRepositoryShape,
28 } from 'src/services/composio-clients';
29 import { logMetrics } from 'src/effects/log-metrics';
30 import { NodeProcess } from 'src/services/node-process';
29 -import type { GetCmdParams } from 'src/type-utils';
31 import { jsFindComposioCoreGenerated } from 'src/effects/find-composio-core-generated';
32 import { generationOutcome, loadGenerationRuntime } from 'src/effects/generation-runtime';
33 import type { Toolkit } from 'src/models/toolkits';
@@ -41,61 +42,18 @@ import {
42 import { validateToolkitVersionOverrides } from 'src/effects/validate-toolkit-versions';
43 import { TerminalUI, type SpinnerHandle } from 'src/services/terminal-ui';
44 import { CommandInputError, commandInputError } from 'src/commands/errors';
44 -
45 -export class TypeScriptGenerationWriteError extends Data.TaggedError(
46 - 'commands/TypeScriptGenerationWriteError'
47 -)<{
48 - readonly cause: unknown;
49 - readonly filePath: string;
50 - readonly message: string;
51 -}> {}
45 +import { TypeScriptGenerationWriteError } from './generate.ts.errors';
46 +
47 +export type GenerateTsParams = {
48 + readonly outputDir: Option.Option<string>;
49 + readonly compact: boolean;
50 + readonly transpiled: boolean;
51 + readonly typeTools: boolean;
52 + readonly toolkits: ReadonlyArray<string>;
53 +};
54
55 const invalidGenerateValue = commandInputError('generate ts');
56
55 -export const outputOpt = Flag.optional(Flag.Directory('output-dir')).pipe(
56 - Flag.withAlias('o'),
57 - Flag.withDescription('Output directory for the generated TypeScript type stubs.')
58 -);
59 -
60 -export const compact = Flag.Boolean('compact').pipe(
61 - Flag.withDefault(false),
62 - Flag.withDescription('Emit a single TypeScript file')
63 -);
64 -
65 -export const transpiled = Flag.Boolean('transpiled').pipe(
66 - Flag.withDefault(false),
67 - Flag.withDescription('Whether to emit transpiled JavaScript alongside TypeScript files')
68 -);
69 -
70 -export const typeTools = Flag.Boolean('type-tools').pipe(
71 - Flag.withDefault(false),
72 - Flag.withDescription(
73 - 'Generate typed input/output schemas for each tool (slower, fetches full tool definitions)'
74 - )
75 -);
76 -
77 -export const toolkitsOpt = Flag.String('toolkits').pipe(
78 - Flag.atLeast(0),
79 - Flag.withDescription(
80 - 'Only generate types for specific toolkits (e.g., --toolkits gmail --toolkits slack)'
81 - )
82 -);
83 -
84 -const _tsCmd$Generate = Command.make('generate', {
85 - outputOpt,
86 - compact,
87 - transpiled: transpiled,
88 - typeTools,
89 - toolkitsOpt,
90 -}).pipe(
91 - Command.withDescription(
92 - 'Generate TypeScript types for toolkits, tools, and triggers from the Composio API.\n\n' +
93 - 'Environment Variables:\n' +
94 - ' COMPOSIO_TOOLKIT_VERSION_<TOOLKIT> Override toolkit version (e.g., COMPOSIO_TOOLKIT_VERSION_GMAIL=20250901_00)\n' +
95 - ' Use "latest" or unset to use the latest version.'
96 - )
97 -);
98 -
57 /**
58 * Result type for fetching toolkit data
59 */
@@ -342,39 +300,32 @@ function validateOutputDir(outputDir: string): Effect.Effect<string, CommandInpu
300 }
301
302 /**
345 - * Shared handler for TypeScript generation commands.
346 - * Resolves the `transpiled` default based on whether `--output-dir` was provided.
303 + * `--transpiled` defaults to true only when `--output-dir` is absent: the stubs then land
304 + * in `node_modules`, where JavaScript must exist alongside the TypeScript files. An explicit
305 + * `--transpiled` always wins.
306 */
348 -export const handleTsGenerate = (params: GetCmdParams<typeof _tsCmd$Generate>) => {
349 - // Determine if we should compile based on the rules:
350 - // - If --output-dir is specified, default transpiled to false unless overridden
351 - // - If no --output-dir, default transpiled to true unless overridden
352 - const shouldCompile = params.transpiled || !Option.isSome(params.outputOpt);
353 -
354 - return generateTypescriptTypeStubs({
355 - ...params,
356 - transpiled: shouldCompile,
357 - });
358 -};
307 +export const resolveTranspiled = ({
308 + transpiled,
309 + outputDir,
310 +}: Pick<GenerateTsParams, 'transpiled' | 'outputDir'>): boolean =>
311 + transpiled || Option.isNone(outputDir);
312 +
313 +export const runGenerateTs = (params: GenerateTsParams) =>
314 + generateTypescriptTypeStubs({ ...params, transpiled: resolveTranspiled(params) });
315
360 -export function generateTypescriptTypeStubs({
361 - outputOpt,
362 - compact,
363 - typeTools,
364 - transpiled = false,
365 - toolkitsOpt,
366 -}: GetCmdParams<typeof _tsCmd$Generate> & { transpiled?: boolean }) {
316 +export function generateTypescriptTypeStubs(params: GenerateTsParams) {
317 return Effect.gen(function* () {
318 const ui = yield* TerminalUI;
319 const fs = yield* FileSystem.FileSystem;
320 const process = yield* NodeProcess;
321 const cwd = process.cwd;
322 const client = yield* ComposioToolkitsRepository;
323 + const { compact, typeTools, transpiled } = params;
324
325 yield* ui.intro('composio generate ts');
326
327 // Determine the actual output directory
377 - const outputDir = yield* outputOpt.pipe(
328 + const outputDir = yield* params.outputDir.pipe(
329 Option.match({
330 // If no output directory is specified, use the default, and make sure it exists
331 onNone: () => jsFindComposioCoreGenerated(cwd),
@@ -391,8 +342,8 @@ export function generateTypescriptTypeStubs({
342 const versionOverrides = yield* getToolkitVersionOverrides;
343
344 // Normalize toolkit slugs if specified (lowercase for API filtering)
394 - const toolkitSlugsFilter = Array.isReadonlyArrayNonEmpty(toolkitsOpt)
395 - ? toolkitsOpt.map(s => s.toLowerCase())
345 + const toolkitSlugsFilter = Array.isReadonlyArrayNonEmpty(params.toolkits)
346 + ? params.toolkits.map(s => s.toLowerCase())
347 : null;
348
349 // Validate toolkit version overrides before fetching data
@@ -474,7 +425,7 @@ export function generateTypescriptTypeStubs({
425 })
426 );
427
477 - yield* Option.isNone(outputOpt)
428 + yield* Option.isNone(params.outputDir)
429 ? ui.note(
430 'import { Toolkits } from "@composio/core/generated"',
431 'Import your generated types'
ts/packages/cli/src/type-utils.ts deleted
-12
@@ -1,12 +0,0 @@
1 -import type { Command } from 'effect/cli';
2 -
3 -export type GetCmdParams<T> =
4 - T extends Command.Command<
5 - infer _Name extends string,
6 - infer P,
7 - infer _ContextInput,
8 - infer _E,
9 - infer _R
10 - >
11 - ? P
12 - : never;
ts/packages/cli/test/src/commands/generate/py/generate.py.cmd.test.ts renamed
ts/packages/cli/test/src/commands/generate/ts/generate.ts.cmd.test.ts renamed
ts/packages/cli/test/src/commands/generate/ts/generate.ts.handler.test.ts new
+19
@@ -0,0 +1,19 @@
1 +import { describe, expect, it } from 'vitest';
2 +import { Option } from 'effect';
3 +import { resolveTranspiled } from 'src/commands/generate/ts/generate.ts.handler';
4 +
5 +describe('generate ts handler: resolveTranspiled', () => {
6 + // The only combination that skips transpiling is an explicit --output-dir
7 + // without --transpiled: writing into node_modules always needs JavaScript.
8 + it.each([
9 + { transpiled: false, outputDir: Option.none<string>(), expected: true },
10 + { transpiled: true, outputDir: Option.none<string>(), expected: true },
11 + { transpiled: false, outputDir: Option.some('./generated'), expected: false },
12 + { transpiled: true, outputDir: Option.some('./generated'), expected: true },
13 + ])(
14 + '[Given] --transpiled=$transpiled, --output-dir=$outputDir.value [Then] transpiled resolves to $expected',
15 + ({ transpiled, outputDir, expected }) => {
16 + expect(resolveTranspiled({ transpiled, outputDir })).toBe(expected);
17 + }
18 + );
19 +});
ts/packages/cli/test/src/effects/generation-runtime.test.ts
+3 -3
@@ -14,9 +14,9 @@ import {
14 // exactly that.
15 const foreign = <E extends Error & { readonly _tag: string }>(error: E): E => {
16 const clone = Object.create(Error.prototype) as E;
17 - for (const key of Object.getOwnPropertyNames(error)) {
18 - Object.defineProperty(clone, key, Object.getOwnPropertyDescriptor(error, key)!);
19 - }
17 + Object.getOwnPropertyNames(error).forEach(key =>
18 + Object.defineProperty(clone, key, Object.getOwnPropertyDescriptor(error, key)!)
19 + );
20 // `stack` is a lazy accessor bound to the original instance; a real foreign
21 // instance owns its own, so give the clone a plain copy.
22 Object.defineProperty(clone, 'stack', { value: error.stack, configurable: true });
ts/packages/cli/test/src/scripts/validate-lint-boundaries.test.ts
+3 -3
@@ -13,9 +13,9 @@ import {
13 const temporaryDirectories: string[] = [];
14
15 afterEach(() => {
16 - for (const directory of temporaryDirectories.splice(0)) {
17 - fs.rmSync(directory, { force: true, recursive: true });
18 - }
16 + temporaryDirectories
17 + .splice(0)
18 + .forEach(directory => fs.rmSync(directory, { force: true, recursive: true }));
19 });
20
21 describe('lint boundary manifest', () => {
ts/packages/cli/test/src/services/composio-client-singleton.test.ts
+4 -4
@@ -53,10 +53,10 @@ const okResponse = () =>
53 // (djb2Hash + base36): the seeded cache key below must be byte-identical to what
54 // the service computes for process.cwd() when it looks up the CLI session.
55 const cwdHash = (cwd: string): string => {
56 - let hash = 5381;
57 - for (let index = 0; index < cwd.length; index += 1) {
58 - hash = (hash * 33) ^ cwd.charCodeAt(index);
59 - }
56 + const hash = Array.from({ length: cwd.length }, (_, index) => cwd.charCodeAt(index)).reduce(
57 + (acc, code) => (acc * 33) ^ code,
58 + 5381
59 + );
60 return Math.abs(hash >>> 0).toString(36);
61 };
62
ts/packages/cli/test/src/services/run-companion-modules.test.ts
+8 -7
@@ -34,23 +34,23 @@ const TEST_ARCHIVE_RELATIVE_PATHS = [
34 // What a complete install holds next to the executable.
35 const writeLiveCompanions = (installDirectory: string) => {
36 fs.mkdirSync(path.join(installDirectory, 'services'));
37 - for (const fileName of RUN_COMPANION_MODULE_FILENAMES) {
37 + RUN_COMPANION_MODULE_FILENAMES.forEach(fileName => {
38 fs.writeFileSync(
39 path.join(installDirectory, fileName),
40 `export * from "./services/${fileName}";\n`
41 );
42 fs.writeFileSync(path.join(installDirectory, 'services', fileName), 'export {};\n');
43 - }
43 + });
44 };
45
46 // What an install upgraded from an older release still holds: every legacy
47 // placeholder, empty.
48 const writeLegacyPlaceholders = (installDirectory: string) => {
49 - for (const relativePath of RUN_COMPANION_LEGACY_PLACEHOLDER_RELATIVE_PATHS) {
49 + RUN_COMPANION_LEGACY_PLACEHOLDER_RELATIVE_PATHS.forEach(relativePath => {
50 const filePath = path.join(installDirectory, relativePath);
51 fs.mkdirSync(path.dirname(filePath), { recursive: true });
52 fs.writeFileSync(filePath, '');
53 - }
53 + });
54 };
55
56 const stubRepairFetch = () => {
@@ -79,8 +79,9 @@ const mockArchiveContents = (missingRelativePath?: string) => {
79 extractZipMock.mockImplementation(
80 async (archivePath: string, options: { readonly dir: string }) => {
81 const packageDirectory = path.join(options.dir, path.parse(archivePath).name);
82 - for (const relativePath of TEST_ARCHIVE_RELATIVE_PATHS) {
83 - if (relativePath === missingRelativePath) continue;
82 + TEST_ARCHIVE_RELATIVE_PATHS.filter(
83 + relativePath => relativePath !== missingRelativePath
84 + ).forEach(relativePath => {
85 const filePath = path.join(packageDirectory, relativePath);
86 fs.mkdirSync(path.dirname(filePath), { recursive: true });
87 fs.writeFileSync(
@@ -89,7 +90,7 @@ const mockArchiveContents = (missingRelativePath?: string) => {
90 ? ''
91 : `new:${relativePath}`
92 );
92 - }
93 + });
94 }
95 );
96 };
ts/packages/cli/test/src/services/run-helpers-runtime.test.ts
+2 -2
@@ -44,14 +44,14 @@ describe('parseJson', () => {
44 describe('run-helpers-runtime', () => {
45 afterEach(() => {
46 vi.unstubAllGlobals();
47 - for (const name of installedGlobalNames) {
47 + installedGlobalNames.forEach(name => {
48 const descriptor = originalGlobalDescriptors.get(name);
49 if (descriptor) {
50 Object.defineProperty(globalThis, name, descriptor);
51 } else {
52 Reflect.deleteProperty(globalThis, name);
53 }
54 - }
54 + });
55 });
56
57 it('[Given] installed helpers [Then] every documented global is defined', async () => {
ts/packages/cli/test/src/services/terminal-ui.test.ts
+3 -6
@@ -3,7 +3,7 @@ import { describe, expect, it, layer } from '@effect/vitest';
3 import { beforeEach, vi } from 'vitest';
4 import * as p from '@clack/prompts';
5 import stringWidth from 'fast-string-width';
6 -import { Array as Arr, Data, Effect, pipe } from 'effect';
6 +import { Data, Effect } from 'effect';
7 import {
8 clampSpinnerMessage,
9 getTerminalCapabilities,
@@ -23,11 +23,8 @@ class TestFailure extends Data.TaggedError('test/TestFailure')<{
23
24 const booleanStates = [false, true] as const;
25
26 -const ttyCombinations = pipe(
27 - Arr.Do,
28 - Arr.bind('stdin', () => booleanStates),
29 - Arr.bind('stdout', () => booleanStates),
30 - Arr.bind('stderr', () => booleanStates)
26 +const ttyCombinations = booleanStates.flatMap(stdin =>
27 + booleanStates.flatMap(stdout => booleanStates.map(stderr => ({ stdin, stdout, stderr })))
28 );
29
30 /** An intentional Node.js Writable test double matching Clack's output contract. */