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, 12:15 UTC
perf(cli): defer the TypeScript compiler and generation pipeline
`composio --version` drops from 622ms to 408ms, and eager module evaluation from 363.8ms to 130.0ms, measured on the pinned toolchain (Bun 1.4.1+4661e494f, linux-x64, best of 7, analytics disabled). `commands/index.ts` builds the root command tree from every `.cmd.ts` module, so evaluating any one command evaluated all of them. Two of those modules reached the TypeScript compiler and the code generation pipeline, which nothing but `composio generate` and `composio run` ever calls: 155.8ms -> 8.0ms commands/run.cmd 63.5ms -> 2.5ms commands/generate The command tree itself is untouched. `Command.withHandler(input => Effect)` already runs lazily, so moving these imports inside the handler bodies is enough. Specs, flags, descriptions, subcommand wiring and `root-help.ts` introspection all still resolve eagerly, which is why parsing, help rendering and "did you mean" suggestions cannot shift. run.cmd.ts was the CLI's only consumer of `import ts from 'typescript'`, through three source rewrites that `composio run` applies to a user script. Those move to `run-source-transforms.ts`, which the handler imports dynamically. The test suite imports them from the new path. ts.generate.cmd.ts and py.generate.cmd.ts pulled `src/generation/*` at module scope. Both now resolve it inside the handler, immediately before the first use. A rejected import of a module bundled into this binary is an impossible invariant rather than a recoverable failure, so these use `Effect.promise` rather than `Effect.tryPromise`. The module registry memoizes each import, so repeat calls within one run cost nothing. Behavior is unchanged, checked rather than assumed. Eleven invocations, covering `--help` at root and for generate, generate ts, generate py, run, tools and execute, plus `version`, `--version`, an unknown command and an unknown flag, produce byte-identical stdout, stderr and exit codes before and after. Verified with typecheck (src and test), oxlint, validate:boundaries, validate:skills, and the full package suite: 1326 passed, 1 skipped. `test/src/cli-main.test.ts` times out in this container and does so identically on the parent commit (25.6s and 25.2s there, 24.5s and 24.3s here) because it spawns the CLI from source against a 15s timeout. Not caused by this change. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EzaE7oGVgziJ5nRvBhcci2