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

[codex] bundle bun support files for standalone binaries (#3059)

## Summary - bundle the shipped `composio run` companion services with direct `Bun.build(..., target: "bun")` output instead of reusing the shared `dist` graph - rebuild the Claude ACP support files as Bun-bundled runtime assets and invalidate the cached adapter layout so stale raw files are not reused - add runtime validation for shipped support files, wire the MCP helper through the workspace `@composio/json-schema-to-zod` package, and cover the static-import expectation in tests ## Why Standalone binaries were still relying on external runtime dependencies from companion support files. On a clean machine this surfaced as failures like `Cannot find package 'decompress'` from the generated companion modules. The fix is to make every shipped support file self-contained for Bun and package exactly that tree into the binary archives. ## Validation - `pnpm run typecheck` - `pnpm exec vitest run test/src/services/run-subagent-output-mcp.test.ts test/src/services/run-subagent-acp.test.ts` - `pnpm run build:binary:all` - `pnpm run build:binary:package` - unpacked `dist/binaries/composio-darwin-aarch64.zip` and verified `experimental_subAgent(..., { target: "codex", schema: ... })` - unpacked `dist/binaries/composio-darwin-aarch64.zip` and verified `experimental_subAgent(..., { target: "claude", schema: ... })` --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Rahul Tarak committed Mar 27, 2026 at 11:56 UTC b763753df5ed937d98d137dd42539547116e2cab
7 files changed +363 -56
.changeset/bundle-bun-support.md new
+5
@@ -0,0 +1,5 @@
1 +---
2 +"@composio/cli": patch
3 +---
4 +
5 +fix: bundle bun support files into CLI binary so standalone builds work without external bun dependencies
pnpm-lock.yaml
+69 -14
@@ -703,16 +703,16 @@ importers:
703 version: link:../../packages/providers/llamaindex
704 '@llamaindex/openai':
705 specifier: ^0.4.20
706 - version: 0.4.22(@llamaindex/core@0.6.22)(@llamaindex/env@0.1.30)(ws@8.19.0)(zod@4.3.6)
706 + version: 0.4.22(@llamaindex/core@0.6.22)(@llamaindex/env@0.1.30)(ws@8.19.0)(zod@3.25.76)
707 '@llamaindex/workflow':
708 specifier: ^1.1.24
709 - version: 1.1.24(@llamaindex/core@0.6.22)(@llamaindex/env@0.1.30)(@modelcontextprotocol/sdk@1.26.0(@cfworker/json-schema@4.1.1)(zod@4.3.6))(hono@4.11.9)(zod@4.3.6)
709 + version: 1.1.24(@llamaindex/core@0.6.22)(@llamaindex/env@0.1.30)(@modelcontextprotocol/sdk@1.26.0(@cfworker/json-schema@4.1.1)(zod@3.25.76))(hono@4.11.9)(zod@3.25.76)
710 dotenv:
711 specifier: ^16.4.1
712 version: 16.6.1
713 llamaindex:
714 specifier: ^0.12.0
715 - version: 0.12.1(@modelcontextprotocol/sdk@1.26.0(@cfworker/json-schema@4.1.1)(zod@4.3.6))(hono@4.11.9)(tree-sitter@0.22.4)(web-tree-sitter@0.24.7)(zod@4.3.6)
715 + version: 0.12.1(@modelcontextprotocol/sdk@1.26.0(@cfworker/json-schema@4.1.1)(zod@3.25.76))(hono@4.11.9)(tree-sitter@0.22.4)(web-tree-sitter@0.24.7)(zod@3.25.76)
716 devDependencies:
717 '@types/bun':
718 specifier: ^1.2.9
@@ -1058,6 +1058,9 @@ importers:
1058 '@composio/core':
1059 specifier: workspace:*
1060 version: link:../core
1061 + '@composio/json-schema-to-zod':
1062 + specifier: workspace:*
1063 + version: link:../json-schema-to-zod
1064 '@composio/ts-builders':
1065 specifier: workspace:*
1066 version: link:../ts-builders
@@ -1339,7 +1342,7 @@ importers:
1342 dependencies:
1343 llamaindex:
1344 specifier: ^0.12.0
1342 - version: 0.12.1(@modelcontextprotocol/sdk@1.26.0(@cfworker/json-schema@4.1.1)(zod@4.3.6))(hono@4.11.9)(tree-sitter@0.22.4)(web-tree-sitter@0.24.7)(zod@4.3.6)
1345 + version: 0.12.1(tree-sitter@0.22.4)(web-tree-sitter@0.24.7)(zod@4.3.6)
1346 devDependencies:
1347 '@composio/core':
1348 specifier: workspace:*
@@ -7664,26 +7667,43 @@ snapshots:
7667 tree-sitter: 0.22.4
7668 web-tree-sitter: 0.24.7
7669
7667 - '@llamaindex/openai@0.4.22(@llamaindex/core@0.6.22)(@llamaindex/env@0.1.30)(ws@8.19.0)(zod@4.3.6)':
7670 + '@llamaindex/openai@0.4.22(@llamaindex/core@0.6.22)(@llamaindex/env@0.1.30)(ws@8.19.0)(zod@3.25.76)':
7671 dependencies:
7672 '@llamaindex/core': 0.6.22
7673 '@llamaindex/env': 0.1.30
7671 - openai: 5.23.2(ws@8.19.0)(zod@4.3.6)
7674 + openai: 5.23.2(ws@8.19.0)(zod@3.25.76)
7675 transitivePeerDependencies:
7676 - ws
7677 - zod
7678
7676 - '@llamaindex/workflow-core@1.3.3(@modelcontextprotocol/sdk@1.26.0(@cfworker/json-schema@4.1.1)(zod@4.3.6))(hono@4.11.9)(zod@4.3.6)':
7679 + '@llamaindex/workflow-core@1.3.3(@modelcontextprotocol/sdk@1.26.0(@cfworker/json-schema@4.1.1)(zod@3.25.76))(hono@4.11.9)(zod@3.25.76)':
7680 optionalDependencies:
7678 - '@modelcontextprotocol/sdk': 1.26.0(@cfworker/json-schema@4.1.1)(zod@4.3.6)
7681 + '@modelcontextprotocol/sdk': 1.26.0(@cfworker/json-schema@4.1.1)(zod@3.25.76)
7682 hono: 4.11.9
7683 + zod: 3.25.76
7684 +
7685 + '@llamaindex/workflow-core@1.3.3(zod@4.3.6)':
7686 + optionalDependencies:
7687 zod: 4.3.6
7688
7682 - '@llamaindex/workflow@1.1.24(@llamaindex/core@0.6.22)(@llamaindex/env@0.1.30)(@modelcontextprotocol/sdk@1.26.0(@cfworker/json-schema@4.1.1)(zod@4.3.6))(hono@4.11.9)(zod@4.3.6)':
7689 + '@llamaindex/workflow@1.1.24(@llamaindex/core@0.6.22)(@llamaindex/env@0.1.30)(@modelcontextprotocol/sdk@1.26.0(@cfworker/json-schema@4.1.1)(zod@3.25.76))(hono@4.11.9)(zod@3.25.76)':
7690 dependencies:
7691 '@llamaindex/core': 0.6.22
7692 '@llamaindex/env': 0.1.30
7686 - '@llamaindex/workflow-core': 1.3.3(@modelcontextprotocol/sdk@1.26.0(@cfworker/json-schema@4.1.1)(zod@4.3.6))(hono@4.11.9)(zod@4.3.6)
7693 + '@llamaindex/workflow-core': 1.3.3(@modelcontextprotocol/sdk@1.26.0(@cfworker/json-schema@4.1.1)(zod@3.25.76))(hono@4.11.9)(zod@3.25.76)
7694 + transitivePeerDependencies:
7695 + - '@modelcontextprotocol/sdk'
7696 + - hono
7697 + - next
7698 + - p-retry
7699 + - rxjs
7700 + - zod
7701 +
7702 + '@llamaindex/workflow@1.1.24(@llamaindex/core@0.6.22)(@llamaindex/env@0.1.30)(zod@4.3.6)':
7703 + dependencies:
7704 + '@llamaindex/core': 0.6.22
7705 + '@llamaindex/env': 0.1.30
7706 + '@llamaindex/workflow-core': 1.3.3(zod@4.3.6)
7707 transitivePeerDependencies:
7708 - '@modelcontextprotocol/sdk'
7709 - hono
@@ -8617,6 +8637,14 @@ snapshots:
8637 optionalDependencies:
8638 vite: 7.3.1(@types/node@22.19.11)(tsx@4.21.0)(yaml@2.8.2)
8639
8640 + '@vitest/mocker@3.2.4(vite@7.3.1(@types/node@24.10.13)(tsx@4.21.0)(yaml@2.8.2))':
8641 + dependencies:
8642 + '@vitest/spy': 3.2.4
8643 + estree-walker: 3.0.3
8644 + magic-string: 0.30.21
8645 + optionalDependencies:
8646 + vite: 7.3.1(@types/node@24.10.13)(tsx@4.21.0)(yaml@2.8.2)
8647 +
8648 '@vitest/pretty-format@3.2.4':
8649 dependencies:
8650 tinyrainbow: 2.0.0
@@ -8646,7 +8674,7 @@ snapshots:
8674 sirv: 3.0.2
8675 tinyglobby: 0.2.15
8676 tinyrainbow: 2.0.0
8649 - vitest: 3.2.4(@types/node@22.19.11)(@vitest/ui@3.2.4)(tsx@4.21.0)(yaml@2.8.2)
8677 + vitest: 3.2.4(@types/node@24.10.13)(@vitest/ui@3.2.4)(tsx@4.21.0)(yaml@2.8.2)
8678
8679 '@vitest/utils@3.2.4':
8680 dependencies:
@@ -10054,12 +10082,34 @@ snapshots:
10082 rfdc: 1.4.1
10083 wrap-ansi: 9.0.2
10084
10057 - llamaindex@0.12.1(@modelcontextprotocol/sdk@1.26.0(@cfworker/json-schema@4.1.1)(zod@4.3.6))(hono@4.11.9)(tree-sitter@0.22.4)(web-tree-sitter@0.24.7)(zod@4.3.6):
10085 + llamaindex@0.12.1(@modelcontextprotocol/sdk@1.26.0(@cfworker/json-schema@4.1.1)(zod@3.25.76))(hono@4.11.9)(tree-sitter@0.22.4)(web-tree-sitter@0.24.7)(zod@3.25.76):
10086 + dependencies:
10087 + '@llamaindex/core': 0.6.22
10088 + '@llamaindex/env': 0.1.30
10089 + '@llamaindex/node-parser': 2.0.22(@llamaindex/core@0.6.22)(@llamaindex/env@0.1.30)(tree-sitter@0.22.4)(web-tree-sitter@0.24.7)
10090 + '@llamaindex/workflow': 1.1.24(@llamaindex/core@0.6.22)(@llamaindex/env@0.1.30)(@modelcontextprotocol/sdk@1.26.0(@cfworker/json-schema@4.1.1)(zod@3.25.76))(hono@4.11.9)(zod@3.25.76)
10091 + '@types/lodash': 4.17.23
10092 + '@types/node': 24.10.13
10093 + lodash: 4.17.23
10094 + magic-bytes.js: 1.13.0
10095 + transitivePeerDependencies:
10096 + - '@huggingface/transformers'
10097 + - '@modelcontextprotocol/sdk'
10098 + - gpt-tokenizer
10099 + - hono
10100 + - next
10101 + - p-retry
10102 + - rxjs
10103 + - tree-sitter
10104 + - web-tree-sitter
10105 + - zod
10106 +
10107 + llamaindex@0.12.1(tree-sitter@0.22.4)(web-tree-sitter@0.24.7)(zod@4.3.6):
10108 dependencies:
10109 '@llamaindex/core': 0.6.22
10110 '@llamaindex/env': 0.1.30
10111 '@llamaindex/node-parser': 2.0.22(@llamaindex/core@0.6.22)(@llamaindex/env@0.1.30)(tree-sitter@0.22.4)(web-tree-sitter@0.24.7)
10062 - '@llamaindex/workflow': 1.1.24(@llamaindex/core@0.6.22)(@llamaindex/env@0.1.30)(@modelcontextprotocol/sdk@1.26.0(@cfworker/json-schema@4.1.1)(zod@4.3.6))(hono@4.11.9)(zod@4.3.6)
10112 + '@llamaindex/workflow': 1.1.24(@llamaindex/core@0.6.22)(@llamaindex/env@0.1.30)(zod@4.3.6)
10113 '@types/lodash': 4.17.23
10114 '@types/node': 24.10.13
10115 lodash: 4.17.23
@@ -10339,6 +10389,11 @@ snapshots:
10389 is-inside-container: 1.0.0
10390 wsl-utils: 0.1.0
10391
10392 + openai@5.23.2(ws@8.19.0)(zod@3.25.76):
10393 + optionalDependencies:
10394 + ws: 8.19.0
10395 + zod: 3.25.76
10396 +
10397 openai@5.23.2(ws@8.19.0)(zod@4.3.6):
10398 optionalDependencies:
10399 ws: 8.19.0
@@ -11436,7 +11491,7 @@ snapshots:
11491 dependencies:
11492 '@types/chai': 5.2.3
11493 '@vitest/expect': 3.2.4
11439 - '@vitest/mocker': 3.2.4(vite@7.3.1(@types/node@22.19.11)(tsx@4.21.0)(yaml@2.8.2))
11494 + '@vitest/mocker': 3.2.4(vite@7.3.1(@types/node@24.10.13)(tsx@4.21.0)(yaml@2.8.2))
11495 '@vitest/pretty-format': 3.2.4
11496 '@vitest/runner': 3.2.4
11497 '@vitest/snapshot': 3.2.4
ts/packages/cli/package.json
+1
@@ -74,6 +74,7 @@
74 "@clack/prompts": "catalog:",
75 "@composio/client": "catalog:",
76 "@composio/core": "workspace:*",
77 + "@composio/json-schema-to-zod": "workspace:*",
78 "@composio/ts-builders": "workspace:*",
79 "@effect/cli": "catalog:",
80 "@effect/platform-bun": "catalog:",
ts/packages/cli/scripts/_acp-adapters.ts
+43 -11
@@ -1,9 +1,7 @@
1 import { chmod, copyFile, mkdir, mkdtemp, readFile, rename, rm, writeFile } from 'node:fs/promises';
2 import { createRequire } from 'node:module';
3 import * as path from 'node:path';
4 -import process from 'node:process';
4 import decompress from 'decompress';
6 -import { $ } from 'bun';
5 import { RUN_CODEX_ACP_BINARY_TARGETS } from '../src/services/run-companion-modules';
6
7 const GENERATED_ROOT_DIR = path.resolve('./.generated');
@@ -12,6 +10,7 @@ const ACP_ADAPTERS_MANIFEST_PATH = path.join(GENERATED_ROOT_DIR, 'acp-adapters.m
10 const REGISTRY_BASE_URL = 'https://registry.npmjs.org';
11 const USER_AGENT = 'composio-cli-acp-vendor/1';
12 const ACP_ADAPTERS_PREFIX = 'acp-adapters/';
13 +const ACP_ADAPTERS_CACHE_FORMAT_VERSION = 2;
14
15 type PackageJson = {
16 readonly bin?: Readonly<Record<string, string>>;
@@ -26,6 +25,7 @@ type RegistryVersionManifest = {
25 };
26
27 type AcpAdaptersManifest = {
28 + readonly cacheFormatVersion: number;
29 readonly claude: {
30 readonly packageName: '@zed-industries/claude-code-acp';
31 readonly version: string;
@@ -107,6 +107,7 @@ const buildCacheManifest = async (): Promise<AcpAdaptersManifest> => {
107 }
108
109 return {
110 + cacheFormatVersion: ACP_ADAPTERS_CACHE_FORMAT_VERSION,
111 claude: {
112 packageName: '@zed-industries/claude-code-acp',
113 version: claudePackage.version,
@@ -177,20 +178,51 @@ const downloadTarball = async (url: string, targetPath: string): Promise<void> =
178 await writeFile(targetPath, new Uint8Array(await response.arrayBuffer()));
179 };
180
180 -const buildClaudeAdapterBundle = async (cacheDir: string): Promise<void> => {
181 - const outputPath = path.join(cacheDir, 'claude-code-acp.mjs');
182 - const entryPath = await resolveClaudeAdapterEntryPath();
183 - const result =
184 - await $`${process.execPath} build ${entryPath} --target node --outfile ${outputPath}`.quiet();
185 - if (result.exitCode !== 0) {
186 - throw new Error('Failed to bundle claude-code-acp.mjs.');
181 +const bundleBunRuntimeFile = async ({
182 + entryPath,
183 + outputPath,
184 +}: {
185 + readonly entryPath: string;
186 + readonly outputPath: string;
187 +}): Promise<void> => {
188 + const result = await Bun.build({
189 + entrypoints: [entryPath],
190 + outdir: path.dirname(outputPath),
191 + naming: path.basename(outputPath),
192 + target: 'bun',
193 + format: 'esm',
194 + packages: 'bundle',
195 + sourcemap: 'none',
196 + });
197 +
198 + if (!result.success) {
199 + const details = result.logs
200 + .map(log => log.message)
201 + .filter(message => message.length > 0)
202 + .join('\n');
203 + throw new Error(
204 + details.length > 0
205 + ? `Failed to bundle ${path.basename(outputPath)}:\n${details}`
206 + : `Failed to bundle ${path.basename(outputPath)}.`
207 + );
208 }
209
210 await chmod(outputPath, 0o755);
211 +};
212 +
213 +const buildClaudeAdapterBundle = async (cacheDir: string): Promise<void> => {
214 + const outputPath = path.join(cacheDir, 'claude-code-acp.mjs');
215 + const entryPath = await resolveClaudeAdapterEntryPath();
216 + await bundleBunRuntimeFile({
217 + entryPath,
218 + outputPath,
219 + });
220
221 const cliOutputPath = path.join(cacheDir, 'cli.js');
192 - await copyFile(resolveClaudeAgentSdkCliPath(), cliOutputPath);
193 - await chmod(cliOutputPath, 0o755);
222 + await bundleBunRuntimeFile({
223 + entryPath: resolveClaudeAgentSdkCliPath(),
224 + outputPath: cliOutputPath,
225 + });
226 };
227
228 const extractCodexBinaryFromTarball = async ({
ts/packages/cli/scripts/_shared.ts
+241 -29
@@ -1,14 +1,29 @@
1 -import { chmod, copyFile, mkdir, readdir, stat, writeFile } from 'node:fs/promises';
1 +import { builtinModules } from 'node:module';
2 +import { chmod, copyFile, mkdir, readdir, rm, stat, writeFile } from 'node:fs/promises';
3 import * as path from 'node:path';
4 import process from 'node:process';
5 import { Cause, Effect, Exit } from 'effect';
6 import type { Teardown } from '@effect/platform/Runtime';
6 -import {
7 - collectRunCompanionAssetRelativePaths,
8 - RUN_COMPANION_MODULE_BASENAMES,
9 -} from '../src/services/run-companion-modules';
7 +import { RUN_COMPANION_MODULE_BASENAMES } from '../src/services/run-companion-modules';
8 import { materializeAcpAdaptersCache } from './_acp-adapters';
9
10 +const RUN_COMPANION_SERVICE_ENTRY_MAP = Object.fromEntries(
11 + RUN_COMPANION_MODULE_BASENAMES.map(name => [`services/${name}`, `src/services/${name}.ts`])
12 +) satisfies Record<string, string>;
13 +
14 +const allowedRuntimeSpecifiers = new Set(
15 + builtinModules.flatMap(specifier =>
16 + specifier.startsWith('node:')
17 + ? [specifier, specifier.slice('node:'.length)]
18 + : [specifier, `node:${specifier}`]
19 + )
20 +);
21 +
22 +const importStatementPattern = /(?:^|[;\n])\s*import\s+(?:[^'"`\n]+?\s+from\s+)?["']([^"']+)["']/gm;
23 +const exportStatementPattern =
24 + /(?:^|[;\n])\s*export\s+(?:\*\s+from\s+|\{[^}\n]+\}\s+from\s+)["']([^"']+)["']/gm;
25 +const runtimeImportCallPattern = /(?:^|[^\w$.])(?:__require|require|import)\(\s*["']([^"']+)["']/g;
26 +
27 const copyDirectoryRecursive = async (sourceDir: string, targetDir: string): Promise<void> => {
28 await mkdir(targetDir, { recursive: true });
29
@@ -30,9 +45,228 @@ const copyDirectoryRecursive = async (sourceDir: string, targetDir: string): Pro
45 const copyBundledAcpAdapters = async (outputDir: string): Promise<void> => {
46 const acpAdaptersCacheDir = await materializeAcpAdaptersCache();
47 const acpOutputDir = path.join(outputDir, 'acp-adapters');
48 + await rm(acpOutputDir, { force: true, recursive: true });
49 await copyDirectoryRecursive(acpAdaptersCacheDir, acpOutputDir);
50 };
51
52 +const isAllowedRuntimeSpecifier = (specifier: string): boolean =>
53 + specifier.startsWith('.') ||
54 + specifier.startsWith('/') ||
55 + specifier.startsWith('data:') ||
56 + specifier === 'bun' ||
57 + specifier.startsWith('bun:') ||
58 + allowedRuntimeSpecifiers.has(specifier);
59 +
60 +const stripStringsAndComments = (source: string): string => {
61 + let result = '';
62 + let index = 0;
63 +
64 + const appendSpace = (char: string) => {
65 + result += char === '\n' ? '\n' : ' ';
66 + };
67 +
68 + while (index < source.length) {
69 + const char = source[index];
70 + const next = source[index + 1];
71 +
72 + if (char === "'" || char === '"' || char === '`') {
73 + const quote = char;
74 + appendSpace(char);
75 + index += 1;
76 +
77 + while (index < source.length) {
78 + const current = source[index];
79 + appendSpace(current);
80 + index += 1;
81 +
82 + if (current === '\\') {
83 + if (index < source.length) {
84 + appendSpace(source[index]!);
85 + index += 1;
86 + }
87 + continue;
88 + }
89 +
90 + if (current === quote) {
91 + break;
92 + }
93 + }
94 +
95 + continue;
96 + }
97 +
98 + if (char === '/' && next === '/') {
99 + appendSpace(char);
100 + appendSpace(next);
101 + index += 2;
102 +
103 + while (index < source.length) {
104 + const current = source[index];
105 + appendSpace(current);
106 + index += 1;
107 + if (current === '\n') {
108 + break;
109 + }
110 + }
111 +
112 + continue;
113 + }
114 +
115 + if (char === '/' && next === '*') {
116 + appendSpace(char);
117 + appendSpace(next);
118 + index += 2;
119 +
120 + while (index < source.length) {
121 + const current = source[index];
122 + const following = source[index + 1];
123 + appendSpace(current);
124 + index += 1;
125 + if (current === '*' && following === '/') {
126 + appendSpace(following);
127 + index += 1;
128 + break;
129 + }
130 + }
131 +
132 + continue;
133 + }
134 +
135 + result += char;
136 + index += 1;
137 + }
138 +
139 + return result;
140 +};
141 +
142 +const collectBundledSpecifiers = (source: string): ReadonlyArray<string> => {
143 + const sanitizedSource = stripStringsAndComments(source);
144 + const specifiers = new Set<string>();
145 +
146 + for (const pattern of [
147 + importStatementPattern,
148 + exportStatementPattern,
149 + runtimeImportCallPattern,
150 + ]) {
151 + for (const match of sanitizedSource.matchAll(pattern)) {
152 + const specifier = match[1];
153 + if (specifier) {
154 + specifiers.add(specifier);
155 + }
156 + }
157 + }
158 +
159 + return [...specifiers];
160 +};
161 +
162 +const collectJavaScriptFiles = async (directory: string): Promise<ReadonlyArray<string>> => {
163 + const collected: string[] = [];
164 +
165 + const walk = async (directory: string): Promise<void> => {
166 + for (const entry of await readdir(directory, { withFileTypes: true })) {
167 + const entryPath = path.join(directory, entry.name);
168 + if (entry.isDirectory()) {
169 + await walk(entryPath);
170 + continue;
171 + }
172 +
173 + if (/\.(?:m?js|cjs)$/.test(entry.name)) {
174 + collected.push(entryPath);
175 + }
176 + }
177 + };
178 +
179 + await walk(directory);
180 + return collected.sort();
181 +};
182 +
183 +const collectRuntimeFiles = async (rootDir: string): Promise<ReadonlyArray<string>> => {
184 + const collected = new Set<string>();
185 +
186 + for (const baseName of RUN_COMPANION_MODULE_BASENAMES) {
187 + const wrapperPath = path.join(rootDir, `${baseName}.mjs`);
188 + if (await Bun.file(wrapperPath).exists()) {
189 + collected.add(wrapperPath);
190 + }
191 + }
192 +
193 + for (const relativeDir of ['services', 'acp-adapters']) {
194 + const absoluteDir = path.join(rootDir, relativeDir);
195 + const exists = await stat(absoluteDir)
196 + .then(stats => stats.isDirectory())
197 + .catch(() => false);
198 + if (!exists) {
199 + continue;
200 + }
201 +
202 + for (const filePath of await collectJavaScriptFiles(absoluteDir)) {
203 + collected.add(filePath);
204 + }
205 + }
206 +
207 + return [...collected].sort();
208 +};
209 +
210 +const assertBundledRuntimeFiles = async (rootDir: string): Promise<void> => {
211 + const files = await collectRuntimeFiles(rootDir);
212 + const violations: string[] = [];
213 +
214 + for (const filePath of files) {
215 + const source = await Bun.file(filePath).text();
216 + for (const specifier of collectBundledSpecifiers(source)) {
217 + if (!specifier || isAllowedRuntimeSpecifier(specifier)) {
218 + continue;
219 + }
220 +
221 + violations.push(`${path.relative(rootDir, filePath)} -> ${specifier}`);
222 + }
223 + }
224 +
225 + if (violations.length > 0) {
226 + throw new Error(
227 + [
228 + 'Generated runtime support files still reference external packages:',
229 + ...violations.map(violation => ` - ${violation}`),
230 + ].join('\n')
231 + );
232 + }
233 +};
234 +
235 +const buildCompanionServiceBundles = async (outputDir: string): Promise<void> => {
236 + const servicesOutputDir = path.join(outputDir, 'services');
237 + await rm(servicesOutputDir, { force: true, recursive: true });
238 + await mkdir(servicesOutputDir, { recursive: true });
239 +
240 + for (const [entryName, entryPath] of Object.entries(RUN_COMPANION_SERVICE_ENTRY_MAP)) {
241 + const relativeOutputPath = `${entryName}.mjs`;
242 + const outputDirectory = path.join(outputDir, path.dirname(relativeOutputPath));
243 + const outputFileName = path.basename(relativeOutputPath);
244 + await mkdir(outputDirectory, { recursive: true });
245 +
246 + const result = await Bun.build({
247 + entrypoints: [path.resolve(entryPath)],
248 + outdir: outputDirectory,
249 + naming: outputFileName,
250 + target: 'bun',
251 + format: 'esm',
252 + packages: 'bundle',
253 + sourcemap: 'none',
254 + });
255 +
256 + if (!result.success) {
257 + const details = result.logs
258 + .map(log => log.message)
259 + .filter(message => message.length > 0)
260 + .join('\n');
261 + throw new Error(
262 + details.length > 0
263 + ? `Failed to bundle ${entryName}:\n${details}`
264 + : `Failed to bundle ${entryName}.`
265 + );
266 + }
267 + }
268 +};
269 +
270 /**
271 * Shared teardown for all CLI scripts.
272 *
@@ -49,30 +283,7 @@ export const buildCompanionModules = (outputDir: string) =>
283 Effect.gen(function* () {
284 yield* Effect.tryPromise(() => mkdir(outputDir, { recursive: true }));
285
52 - const compiledRootDir = path.resolve('./dist');
53 - const companionRelativePaths = collectRunCompanionAssetRelativePaths(compiledRootDir);
54 - if (companionRelativePaths.length === 0) {
55 - return yield* Effect.fail(
56 - new Error('Missing compiled run companion modules. Run `pnpm build:packages` first.')
57 - );
58 - }
59 -
60 - for (const relativePath of companionRelativePaths) {
61 - const sourcePath = path.join(compiledRootDir, relativePath);
62 - const targetPath = path.join(outputDir, relativePath);
63 -
64 - yield* Effect.tryPromise(async () => {
65 - if (!(await Bun.file(sourcePath).exists())) {
66 - throw new Error(`Missing companion module: ${sourcePath}`);
67 - }
68 - if (path.resolve(sourcePath) === path.resolve(targetPath)) {
69 - return;
70 - }
71 -
72 - await mkdir(path.dirname(targetPath), { recursive: true });
73 - await copyFile(sourcePath, targetPath);
74 - });
75 - }
286 + yield* Effect.tryPromise(() => buildCompanionServiceBundles(outputDir));
287
288 for (const name of RUN_COMPANION_MODULE_BASENAMES) {
289 const wrapperPath = path.join(outputDir, `${name}.mjs`);
@@ -81,4 +292,5 @@ export const buildCompanionModules = (outputDir: string) =>
292 }
293
294 yield* Effect.tryPromise(() => copyBundledAcpAdapters(outputDir));
295 + yield* Effect.tryPromise(() => assertBundledRuntimeFiles(outputDir));
296 });
ts/packages/cli/src/services/run-subagent-output-mcp.ts
+2 -2
@@ -1,6 +1,6 @@
1 import * as fs from 'node:fs';
2 import process from 'node:process';
3 -import { jsonSchemaToZodSchema } from '@composio/core';
3 +import { jsonSchemaToZod } from '@composio/json-schema-to-zod';
4 import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
5 import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
6 import {
@@ -22,7 +22,7 @@ const main = async (): Promise<void> => {
22 const resultFilePath = readFlag('--result-file');
23 const schemaText = fs.readFileSync(schemaFilePath, 'utf8');
24 const structuredSchema = JSON.parse(schemaText) as Record<string, unknown>;
25 - const toolInputSchema = jsonSchemaToZodSchema(buildStructuredOutputToolSchema(structuredSchema));
25 + const toolInputSchema = jsonSchemaToZod(buildStructuredOutputToolSchema(structuredSchema));
26
27 const server = new McpServer({
28 name: 'composio-subagent-output',
ts/packages/cli/test/src/services/run-subagent-output-mcp.test.ts
+2
@@ -11,6 +11,8 @@ describe('run-subagent-output-mcp source', () => {
11
12 expect(source).toContain("from '@modelcontextprotocol/sdk/server/mcp.js'");
13 expect(source).toContain("from '@modelcontextprotocol/sdk/server/stdio.js'");
14 + expect(source).toContain("from '@composio/json-schema-to-zod'");
15 + expect(source).not.toContain("from '@composio/core'");
16 expect(source).not.toContain('@modelcontextprotocol/sdk/package.json');
17 expect(source).not.toContain('createRequire(import.meta.url)');
18 });