@devries-cameron20 / composio Mirror · read-only / commits / b3e5df565
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, 22:15 UTC

fix(cli): patch BetterSwiftAX constants for binary builds (#3347)

## Summary - Broaden the Beeper iMessage macOS build patch so BetterSwiftAX `kAX...` constants compile on GitHub `macos-15`/`macos-15-intel`. - Pin the fixed `platform-imessage` submodule source and add Swift 6.2 / Peekaboo dependency patching for the CLI binary workflow. - Package and verify macOS local-tool sidecars plus `release-tag.txt` in CLI release zips. - Fix installed beta metadata/upgrade behavior so `--version`, update checks, and beta-default experimental flags use the installed release tag. - Let `LOCAL_*` execution bypass remote auth/project/schema validation. - Add runtime self-heal for missing installed `local-tools-binaries`: if an old upgrader installs the fixed beta binary without sidecars, first local-tool execution downloads the matching release zip, verifies checksum when available, and restores the sidecars. ## Validation - `pnpm --filter @composio/cli-local-tools build:beeper-imessage -- --target darwin-arm64` - `pnpm --filter @composio/cli-local-tools build:beeper-imessage -- --target darwin-x64` - `pnpm --filter @composio/cli-local-tools build:peekaboo -- --target darwin-arm64` - `pnpm --filter @composio/cli-local-tools build:peekaboo -- --target darwin-x64` - `pnpm --filter @composio/cli-local-tools typecheck:tsc` - `pnpm --filter @composio/cli-local-tools test` - `pnpm --filter @composio/cli typecheck:tsc` - `pnpm --filter @composio/cli build:binary` - Targeted CLI tests for execute/config/upgrade/version/update-check paths. - Packaged binary smoke test confirmed bundled Beeper sidecar works. - Repair smoke test: copied only the new `composio` binary plus `release-tag.txt` into a temp install with no `local-tools-binaries`; `execute LOCAL_BEEPER_IMESSAGE_VERSION -d '{}'` restored sidecars from `@composio/cli@0.2.29-beta.235` and succeeded. ## Release workflow - Beta build run `25405049712` succeeded for commit `9d0910c909b7b257d0f17b6d082980952d1e6c59` and published `@composio/cli@0.2.29-beta.235`. - This PR now includes one follow-up commit (`2c32cff4c`) to cover the old-upgrader/missing-sidecars incremental upgrade path; normal branch CI and beta build run `25406984535` are running again.

Rahul Tarak committed May 5, 2026 at 16:45 UTC b3e5df565ef0091912d294567e83350a821c6291
16 files changed +587 -75
.github/workflows/build-cli-binaries.yml
+23
@@ -231,6 +231,16 @@ jobs:
231 - name: Install dependencies
232 run: pnpm install --frozen-lockfile
233
234 + - name: Setup Swift 6.2 for local-tool sidecars
235 + if: matrix.local_tools_target != ''
236 + uses: swift-actions/setup-swift@v2
237 + with:
238 + swift-version: '6.2'
239 +
240 + - name: Verify Swift toolchain
241 + if: matrix.local_tools_target != ''
242 + run: swift --version
243 +
244 - name: Build packages
245 run: pnpm build:packages
246
@@ -265,8 +275,21 @@ jobs:
275
276 - name: Create archive
277 working-directory: ts/packages/cli
278 + env:
279 + RELEASE_TAG: ${{ needs.prepare.outputs.release_tag }}
280 run: pnpm build:binary:package
281
282 + - name: Verify release metadata in archive
283 + working-directory: ts/packages/cli
284 + run: unzip -p dist/binaries/${{ matrix.artifact }}.zip ${{ matrix.artifact }}/release-tag.txt | grep -Fx '${{ needs.prepare.outputs.release_tag }}'
285 +
286 + - name: Verify local-tool sidecars in archive
287 + if: matrix.local_tools_target != ''
288 + working-directory: ts/packages/cli
289 + run: |
290 + unzip -Z1 dist/binaries/${{ matrix.artifact }}.zip | grep -F "local-tools-binaries/beeper-imessage/${{ matrix.local_tools_target }}/imessage-cli"
291 + unzip -Z1 dist/binaries/${{ matrix.artifact }}.zip | grep -F "local-tools-binaries/peekaboo/${{ matrix.local_tools_target }}/peekaboo"
292 +
293 - name: Upload artifact
294 uses: actions/upload-artifact@v6
295 with:
pnpm-lock.yaml
+6
@@ -1216,6 +1216,9 @@ importers:
1216 '@modelcontextprotocol/sdk':
1217 specifier: ^1.26.0
1218 version: 1.26.0(@cfworker/json-schema@4.1.1)(zod@4.3.6)
1219 + decompress:
1220 + specifier: ^4.2.1
1221 + version: 4.2.1
1222 zod:
1223 specifier: 'catalog:'
1224 version: 4.3.6
@@ -1223,6 +1226,9 @@ importers:
1226 specifier: 'catalog:'
1227 version: 3.25.1(zod@4.3.6)
1228 devDependencies:
1229 + '@types/decompress':
1230 + specifier: ^4.2.7
1231 + version: 4.2.7
1232 '@types/node':
1233 specifier: ^24.0.1
1234 version: 24.10.13
ts/packages/cli-local-tools/package.json
+2
@@ -45,10 +45,12 @@
45 },
46 "dependencies": {
47 "@modelcontextprotocol/sdk": "^1.26.0",
48 + "decompress": "^4.2.1",
49 "zod": "catalog:",
50 "zod-to-json-schema": "catalog:"
51 },
52 "devDependencies": {
53 + "@types/decompress": "^4.2.7",
54 "@types/node": "^24.0.1",
55 "chrome-devtools-mcp": "0.24.0",
56 "tsdown": "catalog:",
ts/packages/cli-local-tools/scripts/build-beeper-imessage-binaries.ts
+55 -51
@@ -38,47 +38,34 @@ const exists = async (filePath: string): Promise<boolean> =>
38 const readJson = async <T>(filePath: string): Promise<T> =>
39 JSON.parse(await fs.readFile(filePath, 'utf8')) as T;
40
41 -// BetterSwiftAX 0.1.0 references AXWebConstants added in newer macOS SDKs.
42 -// The constants are plain CFString subrole names, so patch the resolved package
43 -// checkout to string literals before building on GitHub macos-15 runners.
44 -const betterSwiftAxSubroleFallbacks = [
45 - ['kAXLandmarkComplementarySubrole', 'AXLandmarkComplementary'],
46 - ['kAXLandmarkContentInfoSubrole', 'AXLandmarkContentInfo'],
47 - ['kAXLandmarkMainSubrole', 'AXLandmarkMain'],
48 - ['kAXLandmarkNavigationSubrole', 'AXLandmarkNavigation'],
49 - ['kAXLandmarkRegionSubrole', 'AXLandmarkRegion'],
50 - ['kAXLandmarkSearchSubrole', 'AXLandmarkSearch'],
51 - ['kAXMathFenceOperatorSubrole', 'AXMathFenceOperator'],
52 - ['kAXMathFencedSubrole', 'AXMathFenced'],
53 - ['kAXMathFractionSubrole', 'AXMathFraction'],
54 - ['kAXMathIdentifierSubrole', 'AXMathIdentifier'],
55 - ['kAXMathMultiscriptSubrole', 'AXMathMultiscript'],
56 - ['kAXMathNumberSubrole', 'AXMathNumber'],
57 - ['kAXMathOperatorSubrole', 'AXMathOperator'],
58 - ['kAXMathRootSubrole', 'AXMathRoot'],
59 - ['kAXMathRowSubrole', 'AXMathRow'],
60 - ['kAXMathSeparatorOperatorSubrole', 'AXMathSeparatorOperator'],
61 - ['kAXMathSquareRootSubrole', 'AXMathSquareRoot'],
62 - ['kAXMathSubscriptSuperscriptSubrole', 'AXMathSubscriptSuperscript'],
63 - ['kAXMathTableCellSubrole', 'AXMathTableCell'],
64 - ['kAXMathTableRowSubrole', 'AXMathTableRow'],
65 - ['kAXMathTableSubrole', 'AXMathTable'],
66 - ['kAXMathTextSubrole', 'AXMathText'],
67 - ['kAXMathUnderOverSubrole', 'AXMathUnderOver'],
68 - ['kAXMeterSubrole', 'AXMeter'],
69 - ['kAXRubyInlineSubrole', 'AXRubyInline'],
70 - ['kAXRubyTextSubrole', 'AXRubyText'],
71 - ['kAXSubscriptStyleGroupSubrole', 'AXSubscriptStyleGroup'],
72 - ['kAXSummarySubrole', 'AXSummary'],
73 - ['kAXSuperscriptStyleGroupSubrole', 'AXSuperscriptStyleGroup'],
74 - ['kAXTabPanelSubrole', 'AXTabPanel'],
75 - ['kAXTermSubrole', 'AXTerm'],
76 - ['kAXTimeGroupSubrole', 'AXTimeGroup'],
77 - ['kAXUserInterfaceTooltipSubrole', 'AXUserInterfaceTooltip'],
78 - ['kAXVideoSubrole', 'AXVideo'],
79 - ['kAXWebApplicationSubrole', 'AXWebApplication'],
41 +// BetterSwiftAX 0.1.0 references Accessibility constants that are not
42 +// consistently exported by the macOS SDK on GitHub runners. Swift exposes AX
43 +// constants as Strings whose values are the constant name without the `k` prefix
44 +// and category suffix, so patch the resolved package checkout to literals before
45 +// compiling sidecar binaries.
46 +const betterSwiftAxFallbackFiles = [
47 + 'Accessibility+Action.swift',
48 + 'Accessibility+AttributeKey.swift',
49 + 'Accessibility+Notification.swift',
50 + 'Accessibility+ParameterizedAttributeKey.swift',
51 + 'Accessibility+Role.swift',
52 + 'Accessibility+Subrole.swift',
53 + 'Accessibility+Value.swift',
54 ] as const;
55
56 +const betterSwiftAxConstantReferencePattern =
57 + /\bkAX[A-Za-z0-9]+(?:Action|ParameterizedAttribute|Attribute|Notification|Subrole|Role|Value)\b/g;
58 +const betterSwiftAxConstantPattern =
59 + /^kAX(.+?)(Action|ParameterizedAttribute|Attribute|Notification|Subrole|Role|Value)$/;
60 +
61 +const betterSwiftAxConstantLiteral = (constantName: string): string => {
62 + const match = betterSwiftAxConstantPattern.exec(constantName);
63 + if (!match) {
64 + throw new Error(`Unsupported BetterSwiftAX constant fallback: ${constantName}`);
65 + }
66 + return `"AX${match[1]}"`;
67 +};
68 +
69 const ensurePlatform = () => {
70 if (process.platform !== 'darwin') {
71 throw new Error(
@@ -125,26 +112,43 @@ const copyLicense = async () => {
112 const patchBetterSwiftAxForCurrentSdk = async () => {
113 await $`swift package resolve`.cwd(submodulePath);
114
128 - const sourcePath = path.join(
115 + const checkoutRoot = path.join(
116 submodulePath,
130 - '.build/checkouts/BetterSwiftAX/Sources/AccessibilityControl/Accessibility+Subrole.swift'
117 + '.build/checkouts/BetterSwiftAX/Sources/AccessibilityControl'
118 );
132 - if (!(await exists(sourcePath))) {
119 + if (!(await exists(checkoutRoot))) {
120 throw new Error(
134 - 'Swift package resolution completed but BetterSwiftAX Accessibility+Subrole.swift was not found.'
121 + 'Swift package resolution completed but the BetterSwiftAX AccessibilityControl checkout was not found.'
122 );
123 }
124
138 - const source = await fs.readFile(sourcePath, 'utf8');
139 - let patched = source;
140 - for (const [constantName, stringValue] of betterSwiftAxSubroleFallbacks) {
141 - patched = patched.replaceAll(`= ${constantName}`, `= ("${stringValue}" as CFString)`);
125 + let replacementCount = 0;
126 + for (const fileName of betterSwiftAxFallbackFiles) {
127 + const sourcePath = path.join(checkoutRoot, fileName);
128 + if (!(await exists(sourcePath))) {
129 + throw new Error(
130 + `Swift package resolution completed but BetterSwiftAX ${fileName} was not found.`
131 + );
132 + }
133 +
134 + const source = await fs.readFile(sourcePath, 'utf8');
135 + let fileReplacementCount = 0;
136 + const patched = source.replace(betterSwiftAxConstantReferencePattern, constantName => {
137 + fileReplacementCount += 1;
138 + return betterSwiftAxConstantLiteral(constantName);
139 + });
140 +
141 + if (patched !== source) {
142 + await fs.chmod(sourcePath, 0o644).catch(() => undefined);
143 + await fs.writeFile(sourcePath, patched, 'utf8');
144 + replacementCount += fileReplacementCount;
145 + }
146 }
147
144 - if (patched !== source) {
145 - await fs.chmod(sourcePath, 0o644).catch(() => undefined);
146 - await fs.writeFile(sourcePath, patched, 'utf8');
147 - console.log('Patched BetterSwiftAX subrole constants for older macOS SDKs.');
148 + if (replacementCount > 0) {
149 + console.log(
150 + `Patched ${replacementCount} BetterSwiftAX Accessibility constants for the current macOS SDK.`
151 + );
152 }
153 };
154
ts/packages/cli-local-tools/scripts/build-peekaboo-binaries.ts
+87
@@ -39,6 +39,54 @@ const exists = async (filePath: string): Promise<boolean> =>
39 const readJson = async <T>(filePath: string): Promise<T> =>
40 JSON.parse(await fs.readFile(filePath, 'utf8')) as T;
41
42 +const swiftConfigurationPatchReplacements = [
43 + {
44 + filePath: 'Sources/Configuration/Providers/Files/FileProvider.swift',
45 + oldText: `self._snapshot = try snapshotType.init(
46 + data: fileContents!.bytes,
47 + providerName: providerName,
48 + parsingOptions: parsingOptions
49 + )`,
50 + newText: `self._snapshot = try fileContents!.withUnsafeBytes { bytes in
51 + try snapshotType.init(
52 + data: RawSpan(_unsafeBytes: bytes),
53 + providerName: providerName,
54 + parsingOptions: parsingOptions
55 + )
56 + }`,
57 + },
58 + {
59 + filePath: 'Sources/Configuration/Providers/Files/ReloadingFileProvider.swift',
60 + oldText: `initialSnapshot = try snapshotType.init(
61 + data: data.bytes,
62 + providerName: providerName,
63 + parsingOptions: parsingOptions
64 + )`,
65 + newText: `initialSnapshot = try data.withUnsafeBytes { bytes in
66 + try snapshotType.init(
67 + data: RawSpan(_unsafeBytes: bytes),
68 + providerName: providerName,
69 + parsingOptions: parsingOptions
70 + )
71 + }`,
72 + },
73 + {
74 + filePath: 'Sources/Configuration/Providers/Files/ReloadingFileProvider.swift',
75 + oldText: `newSnapshot = try Snapshot.init(
76 + data: data.bytes,
77 + providerName: providerName,
78 + parsingOptions: parsingOptions
79 + )`,
80 + newText: `newSnapshot = try data.withUnsafeBytes { bytes in
81 + try Snapshot.init(
82 + data: RawSpan(_unsafeBytes: bytes),
83 + providerName: providerName,
84 + parsingOptions: parsingOptions
85 + )
86 + }`,
87 + },
88 +] as const;
89 +
90 const ensurePlatform = () => {
91 if (process.platform !== 'darwin') {
92 throw new Error(
@@ -91,8 +139,47 @@ const copyLicense = async () => {
139 throw new Error('No upstream license file found in Peekaboo submodule.');
140 };
141
142 +const patchSwiftConfigurationForCurrentToolchain = async () => {
143 + await $`swift package resolve`.cwd(cliPackagePath);
144 +
145 + const checkoutRoot = path.join(cliPackagePath, '.build/checkouts/swift-configuration');
146 + if (!(await exists(checkoutRoot))) {
147 + throw new Error(
148 + 'Swift package resolution completed but the swift-configuration checkout was not found.'
149 + );
150 + }
151 +
152 + let replacementCount = 0;
153 + for (const replacement of swiftConfigurationPatchReplacements) {
154 + const sourcePath = path.join(checkoutRoot, replacement.filePath);
155 + if (!(await exists(sourcePath))) {
156 + throw new Error(
157 + `Swift package resolution completed but ${replacement.filePath} was not found.`
158 + );
159 + }
160 +
161 + const source = await fs.readFile(sourcePath, 'utf8');
162 + if (!source.includes(replacement.oldText)) {
163 + if (source.includes(replacement.newText)) continue;
164 + throw new Error(`Unable to patch swift-configuration file: ${replacement.filePath}`);
165 + }
166 +
167 + const patched = source.replaceAll(replacement.oldText, replacement.newText);
168 + await fs.chmod(sourcePath, 0o644).catch(() => undefined);
169 + await fs.writeFile(sourcePath, patched, 'utf8');
170 + replacementCount += 1;
171 + }
172 +
173 + if (replacementCount > 0) {
174 + console.log(
175 + `Patched ${replacementCount} swift-configuration Data.bytes usages for the current Swift toolchain.`
176 + );
177 + }
178 +};
179 +
180 const buildTarget = async (target: Target) => {
181 console.log(`Building peekaboo for ${target.platform} (${target.swiftArch})...`);
182 + await patchSwiftConfigurationForCurrentToolchain();
183 await $`swift build --arch ${target.swiftArch} -c release -Xswiftc -Osize -Xswiftc -wmo -Xlinker -dead_strip`.cwd(
184 cliPackagePath
185 );
ts/packages/cli-local-tools/src/bundled-binaries.ts
+214
@@ -1,7 +1,9 @@
1 import fsSync from 'node:fs';
2 import fs from 'node:fs/promises';
3 +import os from 'node:os';
4 import path from 'node:path';
5 import { fileURLToPath } from 'node:url';
6 +import decompress from 'decompress';
7 import { detectCliPlatform, supportsCliPlatform } from './platform';
8 import type {
9 LocalBundledBinaryDeclaration,
@@ -11,6 +13,25 @@ import type {
13 } from './types';
14
15 const DEFAULT_BUNDLE_DIR = 'local-tools-binaries';
16 +const RELEASE_TAG_FILENAME = 'release-tag.txt';
17 +
18 +const DEFAULT_GITHUB_CONFIG = {
19 + apiBaseUrl: 'https://api.github.com',
20 + owner: 'ComposioHQ',
21 + repo: 'composio',
22 +} as const;
23 +
24 +type GitHubReleaseAsset = {
25 + readonly name: string;
26 + readonly browser_download_url: string;
27 +};
28 +
29 +type GitHubRelease = {
30 + readonly tag_name: string;
31 + readonly assets: ReadonlyArray<GitHubReleaseAsset>;
32 +};
33 +
34 +let localToolsRepairPromise: Promise<boolean> | null = null;
35
36 export interface LocalBundledBinaryResolution {
37 readonly id: string;
@@ -56,6 +77,185 @@ const binaryExists = async (filePath: string): Promise<boolean> => {
77 }
78 };
79
80 +const readTextFileIfPresent = async (filePath: string): Promise<string | undefined> => {
81 + try {
82 + const value = (await fs.readFile(filePath, 'utf8')).trim();
83 + return value.length > 0 ? value : undefined;
84 + } catch {
85 + return undefined;
86 + }
87 +};
88 +
89 +const resolveBinaryAssetName = (): string | undefined => {
90 + switch (`${process.platform}-${process.arch}`) {
91 + case 'darwin-arm64':
92 + return 'composio-darwin-aarch64.zip';
93 + case 'darwin-x64':
94 + return 'composio-darwin-x64.zip';
95 + case 'linux-x64':
96 + return 'composio-linux-x64.zip';
97 + case 'linux-arm64':
98 + return 'composio-linux-aarch64.zip';
99 + default:
100 + return undefined;
101 + }
102 +};
103 +
104 +const fetchGitHubJson = async <T>({
105 + url,
106 + accessToken,
107 +}: {
108 + readonly url: string;
109 + readonly accessToken?: string;
110 +}): Promise<T> => {
111 + const response = await fetch(url, {
112 + headers: {
113 + Accept: 'application/vnd.github+json',
114 + 'User-Agent': 'composio-cli-local-tools-repair',
115 + ...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),
116 + },
117 + });
118 + if (!response.ok) {
119 + throw new Error(`GitHub request failed: HTTP ${response.status}`);
120 + }
121 + return (await response.json()) as T;
122 +};
123 +
124 +const downloadAsset = async (
125 + asset: GitHubReleaseAsset,
126 + accessToken?: string
127 +): Promise<Uint8Array> => {
128 + const response = await fetch(asset.browser_download_url, {
129 + headers: accessToken ? { Authorization: `Bearer ${accessToken}` } : undefined,
130 + });
131 + if (!response.ok) {
132 + throw new Error(`Failed to download ${asset.name}: HTTP ${response.status}`);
133 + }
134 + return new Uint8Array(await response.arrayBuffer());
135 +};
136 +
137 +const fetchChecksums = async (
138 + release: GitHubRelease,
139 + accessToken?: string
140 +): Promise<Map<string, string> | undefined> => {
141 + const checksumsAsset = release.assets.find(asset => asset.name === 'checksums.txt');
142 + if (!checksumsAsset) return undefined;
143 +
144 + const response = await fetch(checksumsAsset.browser_download_url, {
145 + headers: accessToken ? { Authorization: `Bearer ${accessToken}` } : undefined,
146 + });
147 + if (!response.ok) return undefined;
148 +
149 + const checksums = new Map<string, string>();
150 + const text = await response.text();
151 + for (const line of text.split('\n')) {
152 + const trimmed = line.trim();
153 + if (!trimmed) continue;
154 + const parts = trimmed.split(/\s+/);
155 + if (parts.length >= 2) {
156 + checksums.set(parts[1]!, parts[0]!);
157 + }
158 + }
159 + return checksums;
160 +};
161 +
162 +const verifyChecksum = async ({
163 + data,
164 + expectedHash,
165 + fileName,
166 +}: {
167 + readonly data: Uint8Array;
168 + readonly expectedHash: string;
169 + readonly fileName: string;
170 +}): Promise<void> => {
171 + const digest = await crypto.subtle.digest('SHA-256', data.slice().buffer);
172 + const actualHash = Array.from(new Uint8Array(digest))
173 + .map(byte => byte.toString(16).padStart(2, '0'))
174 + .join('');
175 + if (actualHash !== expectedHash) {
176 + throw new Error(
177 + `Checksum mismatch while repairing ${fileName}\n Expected: ${expectedHash}\n Actual: ${actualHash}`
178 + );
179 + }
180 +};
181 +
182 +const isStandaloneBunExecutable = (): boolean => {
183 + const currentFilePath = fileURLToPath(import.meta.url);
184 + return currentFilePath.startsWith('/$bunfs/');
185 +};
186 +
187 +const repairInstalledLocalToolsBundle = async (): Promise<boolean> => {
188 + if (process.env.COMPOSIO_LOCAL_TOOLS_BIN_DIR?.trim() || !isStandaloneBunExecutable()) {
189 + return false;
190 + }
191 +
192 + const installDirectory = path.dirname(process.execPath);
193 + const releaseTag =
194 + process.env.GITHUB_TAG?.trim() ||
195 + (await readTextFileIfPresent(path.join(installDirectory, RELEASE_TAG_FILENAME)));
196 + if (!releaseTag) return false;
197 +
198 + const assetName = resolveBinaryAssetName();
199 + if (!assetName) return false;
200 +
201 + const githubConfig = {
202 + apiBaseUrl:
203 + process.env.GITHUB_API_BASE_URL ||
204 + process.env.COMPOSIO_GITHUB_API_BASE_URL ||
205 + DEFAULT_GITHUB_CONFIG.apiBaseUrl,
206 + owner:
207 + process.env.GITHUB_OWNER || process.env.COMPOSIO_GITHUB_OWNER || DEFAULT_GITHUB_CONFIG.owner,
208 + repo: process.env.GITHUB_REPO || process.env.COMPOSIO_GITHUB_REPO || DEFAULT_GITHUB_CONFIG.repo,
209 + accessToken: process.env.GITHUB_ACCESS_TOKEN || process.env.COMPOSIO_GITHUB_ACCESS_TOKEN,
210 + };
211 +
212 + const release = await fetchGitHubJson<GitHubRelease>({
213 + url: `${githubConfig.apiBaseUrl}/repos/${githubConfig.owner}/${githubConfig.repo}/releases/tags/${encodeURIComponent(releaseTag)}`,
214 + accessToken: githubConfig.accessToken,
215 + });
216 + const asset = release.assets.find(candidate => candidate.name === assetName);
217 + if (!asset) return false;
218 +
219 + const archiveData = await downloadAsset(asset, githubConfig.accessToken);
220 + const expectedChecksum = (await fetchChecksums(release, githubConfig.accessToken))?.get(
221 + asset.name
222 + );
223 + if (expectedChecksum) {
224 + await verifyChecksum({
225 + data: archiveData,
226 + expectedHash: expectedChecksum,
227 + fileName: asset.name,
228 + });
229 + }
230 +
231 + const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'composio-local-tools-repair-'));
232 + try {
233 + const zipPath = path.join(tempDir, asset.name);
234 + const extractDir = path.join(tempDir, 'extract');
235 + await fs.writeFile(zipPath, archiveData);
236 + await decompress(zipPath, extractDir);
237 +
238 + const archiveBundleRoot = path.join(
239 + extractDir,
240 + path.parse(asset.name).name,
241 + DEFAULT_BUNDLE_DIR
242 + );
243 + if (!(await binaryExists(archiveBundleRoot))) return false;
244 +
245 + const installBundleRoot = path.join(installDirectory, DEFAULT_BUNDLE_DIR);
246 + await fs.rm(installBundleRoot, { force: true, recursive: true });
247 + await fs.cp(archiveBundleRoot, installBundleRoot, { recursive: true });
248 + return true;
249 + } finally {
250 + await fs.rm(tempDir, { force: true, recursive: true });
251 + }
252 +};
253 +
254 +const maybeRepairInstalledLocalToolsBundle = async (): Promise<boolean> => {
255 + localToolsRepairPromise ??= repairInstalledLocalToolsBundle().catch(() => false);
256 + return localToolsRepairPromise;
257 +};
258 +
259 const findDeclaration = (
260 toolkit: LocalToolkitDeclaration,
261 id: string
@@ -93,6 +293,20 @@ export const resolveBundledBinary = async (
293 }
294 }
295
296 + if (bundledPaths.length > 0 && (await maybeRepairInstalledLocalToolsBundle())) {
297 + for (const bundledPath of bundledPaths) {
298 + if (await binaryExists(bundledPath)) {
299 + return {
300 + id: ref.bundledBinary,
301 + path: bundledPath,
302 + platform: currentPlatform,
303 + exists: true,
304 + source: 'bundled',
305 + };
306 + }
307 + }
308 + }
309 +
310 if (
311 ref.fallbackCommand &&
312 hasPathSeparator(ref.fallbackCommand) &&
ts/packages/cli-local-tools/vendor/platform-imessage
+1 -1
@@ -1 +1 @@
1 -Subproject commit 364445a1b3089ad9fe293d5951efe160c5677c42
1 +Subproject commit a199162cff3f9e0a0c8ef29f271a3238fb87f69f
ts/packages/cli/scripts/package-binaries.ts
+9 -2
@@ -19,13 +19,14 @@ import { Config, ConfigProvider, Console, Effect, Logger, Layer, LogLevel } from
19 import { BunContext, BunRuntime } from '@effect/platform-bun';
20 import { LOCAL_TOOLS_BINARY_ASSET_DIRNAME, teardown } from './_shared';
21 import { $ } from 'bun';
22 -import { readdir, stat } from 'node:fs/promises';
22 +import { readdir, stat, writeFile } from 'node:fs/promises';
23 import path from 'node:path';
24 import { collectExpectedRunCompanionAssetRelativePaths } from '../src/services/run-companion-modules';
25
26 const BINARIES_DIR = './dist/binaries';
27 const COMPANIONS_DIR = path.join(BINARIES_DIR, 'companions');
28 const LOCAL_TOOLS_BINARY_ASSETS_DIR = path.join(BINARIES_DIR, LOCAL_TOOLS_BINARY_ASSET_DIRNAME);
29 +const RELEASE_TAG = process.env.RELEASE_TAG?.trim();
30
31 /**
32 * Known binary artifact names (without extension).
@@ -81,9 +82,15 @@ export function packageBinaries() {
82 await $`mkdir -p ${targetDirectory}`.quiet();
83 await $`cp ${path.join(COMPANIONS_DIR, relativePath)} ${path.join(nestedDir, relativePath)}`.quiet();
84 }
84 - if (await Bun.file(LOCAL_TOOLS_BINARY_ASSETS_DIR).exists()) {
85 + const hasLocalToolsBinaryAssets = await stat(LOCAL_TOOLS_BINARY_ASSETS_DIR)
86 + .then(stats => stats.isDirectory())
87 + .catch(() => false);
88 + if (hasLocalToolsBinaryAssets) {
89 await $`cp -R ${LOCAL_TOOLS_BINARY_ASSETS_DIR} ${path.join(nestedDir, LOCAL_TOOLS_BINARY_ASSET_DIRNAME)}`.quiet();
90 }
91 + if (RELEASE_TAG) {
92 + await writeFile(path.join(nestedDir, 'release-tag.txt'), `${RELEASE_TAG}\n`, 'utf8');
93 + }
94 const previousCwd = process.cwd();
95 process.chdir(tempDir);
96 try {
ts/packages/cli/src/commands/tools/commands/tools.execute.cmd.ts
+43 -17
@@ -973,19 +973,55 @@ const resolveExplicitConnectedAccount = (params: {
973
974 const resolveExecuteContext = (params: RunToolsExecuteParams) =>
975 Effect.gen(function* () {
976 + const ui = yield* TerminalUI;
977 + const executor = yield* ToolsExecutor;
978 + const input = (yield* resolveInput(params.data)) ?? '{}';
979 + const parsedArgs = yield* parseArguments(input);
980 + const cliConfig = yield* ComposioCliUserConfig;
981 +
982 + if (
983 + isLocalToolSlug(params.slug) &&
984 + !cliConfig.isExperimentalFeatureEnabled(CLI_EXPERIMENTAL_FEATURES.LOCAL_TOOLS)
985 + ) {
986 + return yield* Effect.fail(
987 + new Error(
988 + `Local tools are experimental. Enable them with \`composio config experimental ${CLI_EXPERIMENTAL_FEATURES.LOCAL_TOOLS} on\` before executing ${params.slug}.`
989 + )
990 + );
991 + }
992 +
993 + if (isLocalToolSlug(params.slug)) {
994 + if (Option.isSome(params.file)) {
995 + return yield* Effect.fail(new Error('--file is not supported for local tools yet.'));
996 + }
997 + return {
998 + ui,
999 + executor,
1000 + resolvedProject: {
1001 + orgId: 'local',
1002 + projectId: 'local',
1003 + projectType: 'DEVELOPER',
1004 + },
1005 + args: parsedArgs,
1006 + resolvedUserId: 'local',
1007 + selectedConnectedAccountId: undefined,
1008 + executeOutputDir: process.env.COMPOSIO_RUN_OUTPUT_DIR?.trim() || undefined,
1009 + executeParams: {
1010 + userId: 'local',
1011 + arguments: parsedArgs,
1012 + },
1013 + } satisfies ResolvedExecuteContext;
1014 + }
1015 +
1016 const resolvedProject = yield* resolveCommandProject({
1017 mode: params.projectMode,
1018 projectName:
1019 params.surface === 'root' ? undefined : Option.getOrUndefined(params.projectName),
1020 }).pipe(Effect.mapError(formatResolveCommandProjectError));
981 - const ui = yield* TerminalUI;
982 - const executor = yield* ToolsExecutor;
1021 const clientSingleton = yield* ComposioClientSingleton;
1022 const userContext = yield* ComposioUserContext;
1023 const projectContext = yield* ProjectContext;
1024
987 - const input = (yield* resolveInput(params.data)) ?? '{}';
988 - const parsedArgs = yield* parseArguments(input);
1025 const localProjectContext = yield* projectContext.resolve.pipe(
1026 Effect.catchAll(() => Effect.succeed(Option.none()))
1027 );
@@ -1012,17 +1048,6 @@ const resolveExecuteContext = (params: RunToolsExecuteParams) =>
1048 orgId: resolvedProject.orgId,
1049 projectId: resolvedProject.projectId,
1050 });
1015 - const cliConfig = yield* ComposioCliUserConfig;
1016 - if (
1017 - isLocalToolSlug(params.slug) &&
1018 - !cliConfig.isExperimentalFeatureEnabled(CLI_EXPERIMENTAL_FEATURES.LOCAL_TOOLS)
1019 - ) {
1020 - return yield* Effect.fail(
1021 - new Error(
1022 - `Local tools are experimental. Enable them with \`composio config experimental ${CLI_EXPERIMENTAL_FEATURES.LOCAL_TOOLS} on\` before executing ${params.slug}.`
1023 - )
1024 - );
1025 - }
1051 const accountSelector = cliConfig.isExperimentalFeatureEnabled(
1052 CLI_EXPERIMENTAL_FEATURES.MULTI_ACCOUNT
1053 )
@@ -1219,7 +1244,8 @@ const runExecuteWithSpinner = (params: {
1244 readonly skipChecks: boolean;
1245 }) =>
1246 Effect.gen(function* () {
1222 - const verificationDisabled = params.skipChecks || params.skipToolParamsCheck;
1247 + const verificationDisabled =
1248 + params.skipChecks || params.skipToolParamsCheck || isLocalToolSlug(params.slug);
1249 const cachedDefinition = verificationDisabled
1250 ? null
1251 : yield* getCachedToolInputDefinition(params.slug);
@@ -1464,7 +1490,7 @@ const runExecuteWithSpinner = (params: {
1490
1491 const runToolsExecute = (params: RunToolsExecuteParams) =>
1492 Effect.gen(function* () {
1467 - if (!(yield* requireAuth)) return;
1493 + if (!isLocalToolSlug(params.slug) && !(yield* requireAuth)) return;
1494
1495 const cliConfig = yield* ComposioCliUserConfig;
1496 if (
ts/packages/cli/src/effects/version.ts
+2 -1
@@ -1,8 +1,9 @@
1 import { Effect, Option } from 'effect';
2 import { DEBUG_OVERRIDE_CONFIG } from 'src/effects/debug-config';
3 import * as constants from 'src/constants';
4 +import { resolveInstalledCliVersion } from 'src/services/run-companion-modules';
5
6 export const getVersion = Effect.map(
7 DEBUG_OVERRIDE_CONFIG.VERSION,
7 - Option.getOrElse(() => constants.APP_VERSION)
8 + Option.getOrElse(() => resolveInstalledCliVersion(process.execPath, constants.APP_VERSION))
9 );
ts/packages/cli/src/services/run-companion-modules.ts
+14
@@ -250,6 +250,20 @@ export const readInstalledReleaseTag = (execPath: string) =>
250 path.join(resolveCompanionInstallDirectory(execPath), RUN_COMPANION_RELEASE_TAG_FILENAME)
251 );
252
253 +export const normalizeCliReleaseVersion = (releaseIdentifier: string): string => {
254 + const trimmed = releaseIdentifier.trim();
255 + if (trimmed.startsWith('@composio/cli@')) {
256 + return trimmed.slice('@composio/cli@'.length);
257 + }
258 + if (/^v\d+\.\d+\.\d+(?:[-+].*)?$/.test(trimmed)) {
259 + return trimmed.slice(1);
260 + }
261 + return trimmed;
262 +};
263 +
264 +export const resolveInstalledCliVersion = (execPath: string, fallbackVersion: string): string =>
265 + normalizeCliReleaseVersion(readInstalledReleaseTag(execPath) ?? fallbackVersion);
266 +
267 export const writeInstalledReleaseTag = (installDir: string, releaseTag: string) => {
268 fs.writeFileSync(
269 path.join(installDir, RUN_COMPANION_RELEASE_TAG_FILENAME),
ts/packages/cli/src/services/update-check.ts
+2 -1
@@ -5,6 +5,7 @@ import { dirname, join } from 'node:path';
5 import semver from 'semver';
6 import { bold, cyanBright, dim } from 'src/ui/colors';
7 import { APP_VERSION, GITHUB_REPO } from '../constants';
8 +import { resolveInstalledCliVersion } from './run-companion-modules';
9
10 /**
11 * Background update check for @composio/cli.
@@ -66,7 +67,7 @@ function getCurrentBinaryAssetName(): string | undefined {
67
68 const defaultConfig: UpdateCheckConfig = {
69 stateFile: join(_home, 'update-check.json'),
69 - currentVersion: APP_VERSION,
70 + currentVersion: resolveInstalledCliVersion(process.execPath, APP_VERSION),
71 checkIntervalMs: CHECK_INTERVAL_MS,
72 releasesUrl: `${GITHUB_REPO.API_BASE_URL}/repos/${GITHUB_REPO.OWNER}/${GITHUB_REPO.REPO}/releases?per_page=100`,
73 binaryAssetName: getCurrentBinaryAssetName(),
ts/packages/cli/src/services/upgrade-binary.ts
+24
@@ -1,6 +1,7 @@
1 import { Data, Effect, Config, Option } from 'effect';
2 import { HttpClient, FileSystem } from '@effect/platform';
3 import * as path from 'node:path';
4 +import { cp as copyPath, rm as removePath } from 'node:fs/promises';
5 import { APP_VERSION } from '../constants';
6 import { DEBUG_OVERRIDE_CONFIG } from 'src/effects/debug-config';
7 import { GITHUB_CONFIG } from 'src/effects/github-config';
@@ -28,6 +29,7 @@ export class UpgradeBinaryError extends Data.TaggedError('services/UpgradeBinary
29 * CLI binary name constant
30 */
31 export const CLI_BINARY_NAME = 'composio';
32 +const LOCAL_TOOLS_BINARY_ASSET_DIRNAME = 'local-tools-binaries';
33
34 const getBinaryAssetName = (platformArch: PlatformArch) =>
35 `${CLI_BINARY_NAME}-${platformArch.platform}-${platformArch.arch}.zip`;
@@ -494,6 +496,28 @@ export class UpgradeBinary extends Effect.Service<UpgradeBinary>()('services/Upg
496 );
497 }
498
499 + const localToolsAssetSource = path.join(sourceDirectory, LOCAL_TOOLS_BINARY_ASSET_DIRNAME);
500 + const localToolsAssetExists = yield* fs
501 + .exists(localToolsAssetSource)
502 + .pipe(Effect.catchAll(() => Effect.succeed(false)));
503 + if (localToolsAssetExists) {
504 + const localToolsAssetTarget = path.join(
505 + targetDirectory,
506 + LOCAL_TOOLS_BINARY_ASSET_DIRNAME
507 + );
508 + yield* Effect.tryPromise({
509 + try: async () => {
510 + await removePath(localToolsAssetTarget, { recursive: true, force: true });
511 + await copyPath(localToolsAssetSource, localToolsAssetTarget, { recursive: true });
512 + },
513 + catch: error =>
514 + new UpgradeBinaryError({
515 + cause: error as Error,
516 + message: 'Failed to replace local-tool binary assets',
517 + }),
518 + });
519 + }
520 +
521 if (options.releaseTag) {
522 yield* Effect.try({
523 try: () => writeInstalledReleaseTag(targetDirectory, options.releaseTag!),
ts/packages/cli/test/src/commands/tools/tools.execute.cmd.test.ts
+28
@@ -65,6 +65,34 @@ describe('CLI: composio execute', () => {
65 recordedSessionCreateParams = [];
66 });
67
68 + layer(
69 + TestLive({
70 + stdin: { isTTY: true, data: '' },
71 + toolsExecutor: {
72 + respondWith: {
73 + successful: true,
74 + data: { ok: true, echoed: 'local' },
75 + error: null,
76 + logId: '',
77 + },
78 + },
79 + })
80 + )('[Given] a local tool slug without auth [Then] it executes locally', it => {
81 + it.scoped('does not require login or Tool Router context', () =>
82 + Effect.gen(function* () {
83 + yield* cli(['execute', 'LOCAL_BEEPER_IMESSAGE_VERSION', '-d', '{ value: 1 }']);
84 +
85 + const lines = yield* MockConsole.getLines({ stripAnsi: true });
86 + const output = parseLastJson(lines);
87 + expect(output).toMatchObject({
88 + successful: true,
89 + data: { ok: true, echoed: 'local' },
90 + error: null,
91 + });
92 + })
93 + );
94 + });
95 +
96 layer(
97 TestLive({
98 baseConfigProvider: testConfigProvider,
ts/packages/cli/test/src/services/cli-user-config.test.ts
+27 -1
@@ -1,7 +1,7 @@
1 import path from 'node:path';
2 import * as tempy from 'tempy';
3 import fs from 'node:fs';
4 -import { describe, it } from '@effect/vitest';
4 +import { describe, it, vi } from '@effect/vitest';
5 import { assertEquals } from '@effect/vitest/utils';
6 import { FileSystem } from '@effect/platform';
7 import { BunFileSystem } from '@effect/platform-bun';
@@ -44,6 +44,32 @@ describe('ComposioCliUserConfig', () => {
44 }).pipe(Effect.provide(CliUserConfigTest));
45 });
46
47 + it.scoped('uses installed beta release metadata for experimental defaults', () => {
48 + const cwd = tempy.temporaryDirectory();
49 + const installDir = tempy.temporaryDirectory();
50 + const fakeExecPath = path.join(installDir, 'composio');
51 + fs.writeFileSync(fakeExecPath, 'fake binary');
52 + fs.writeFileSync(path.join(installDir, 'release-tag.txt'), '@composio/cli@1.2.4-beta.5\n');
53 + const execPathSpy = vi.spyOn(process, 'execPath', 'get').mockReturnValue(fakeExecPath);
54 + const map = new Map() satisfies Map<string, string>;
55 + const NodeOsTest = Layer.succeed(NodeOs, defaultNodeOs({ homedir: cwd }));
56 + const CliUserConfigTest = Layer.provideMerge(
57 + ComposioCliUserConfigLive,
58 + Layer.mergeAll(BunFileSystem.layer, NodeOsTest, withMapConfigProvider(map))
59 + );
60 +
61 + return Effect.gen(function* () {
62 + try {
63 + const config = yield* ComposioCliUserConfig;
64 + assertEquals(config.channel, 'beta');
65 + assertEquals(config.isExperimentalFeatureEnabled('listen'), true);
66 + assertEquals(config.isExperimentalFeatureEnabled('local_tools'), true);
67 + } finally {
68 + execPathSpy.mockRestore();
69 + }
70 + }).pipe(Effect.provide(CliUserConfigTest));
71 + });
72 +
73 it.scoped('defaults experimental features on in beta releases', () => {
74 const cwd = tempy.temporaryDirectory();
75 const map = new Map([['DEBUG_OVERRIDE_VERSION', '1.2.3-beta.4']]) satisfies Map<string, string>;
ts/packages/cli/test/src/services/upgrade-binary.test.ts
+50 -1
@@ -2,13 +2,14 @@ import { describe, expect, it, vi } from '@effect/vitest';
2 import { ConfigProvider, Effect, Layer } from 'effect';
3 import { FetchHttpClient } from '@effect/platform';
4 import { BunFileSystem } from '@effect/platform-bun';
5 -import { mkdtempSync, writeFileSync } from 'node:fs';
5 +import { existsSync, mkdirSync, readFileSync, mkdtempSync, writeFileSync } from 'node:fs';
6 import { tmpdir } from 'node:os';
7 import path from 'node:path';
8 import { withHttpServer } from 'test/__utils__/http-server';
9 import { TerminalUI } from 'src/services/terminal-ui';
10 import { UpgradeBinary, UpgradeBinaryError } from 'src/services/upgrade-binary';
11 import { NodeOs } from 'src/services/node-os';
12 +import { collectExpectedRunCompanionAssetRelativePaths } from 'src/services/run-companion-modules';
13
14 const TerminalUINoop = Layer.succeed(
15 TerminalUI,
@@ -349,6 +350,54 @@ describe('UpgradeBinary', () => {
350 }
351 });
352
353 + it('copies local-tool bundled binary assets during local-target upgrades', async () => {
354 + const installDir = mkdtempSync(path.join(tmpdir(), 'composio-local-tool-upgrade-target-'));
355 + const sourceDir = mkdtempSync(path.join(tmpdir(), 'composio-local-tool-upgrade-source-'));
356 + const fakeExecPath = path.join(installDir, 'composio');
357 + const sourceBinaryPath = path.join(sourceDir, 'composio');
358 + const sourceLocalToolPath = path.join(
359 + sourceDir,
360 + 'local-tools-binaries',
361 + 'beeper-imessage',
362 + 'darwin-arm64',
363 + 'imessage-cli'
364 + );
365 + const installedLocalToolPath = path.join(
366 + installDir,
367 + 'local-tools-binaries',
368 + 'beeper-imessage',
369 + 'darwin-arm64',
370 + 'imessage-cli'
371 + );
372 +
373 + writeFileSync(fakeExecPath, 'old-binary');
374 + writeFileSync(sourceBinaryPath, 'new-binary');
375 + mkdirSync(path.dirname(sourceLocalToolPath), { recursive: true });
376 + writeFileSync(sourceLocalToolPath, 'imessage-sidecar');
377 +
378 + for (const relativePath of collectExpectedRunCompanionAssetRelativePaths(sourceDir)) {
379 + const companionPath = path.join(sourceDir, relativePath);
380 + mkdirSync(path.dirname(companionPath), { recursive: true });
381 + writeFileSync(companionPath, 'support-file');
382 + }
383 +
384 + vi.stubGlobal('Bun', { which: vi.fn(() => null) });
385 + const execPathSpy = vi.spyOn(process, 'execPath', 'get').mockReturnValue(fakeExecPath);
386 +
387 + try {
388 + const result = await runUpgradeSuccess([['DEBUG_OVERRIDE_UPGRADE_TARGET', sourceBinaryPath]]);
389 +
390 + expect(result).toBeUndefined();
391 + expect(readFileSync(fakeExecPath, 'utf8')).toBe('new-binary');
392 + expect(existsSync(installedLocalToolPath)).toBe(true);
393 + expect(readFileSync(installedLocalToolPath, 'utf8')).toBe('imessage-sidecar');
394 + } finally {
395 + execPathSpy.mockRestore();
396 + vi.unstubAllGlobals();
397 + vi.restoreAllMocks();
398 + }
399 + });
400 +
401 it('uses the installed beta release tag when comparing beta updates', async () => {
402 const installDir = mkdtempSync(path.join(tmpdir(), 'composio-beta-upgrade-'));
403 const fakeExecPath = path.join(installDir, 'composio');