Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
fix(cli): require binary asset for update notice (#3285)
## Summary\n- switch the passive CLI update check from tag refs to GitHub releases\n- only cache/show a latest CLI version when the stable release includes the current platform binary asset\n- update update-check tests for release asset filtering\n\n## Tests\n- pnpm --filter @composio/cli typecheck\n- pnpm --filter @composio/cli test -- test/src/services/update-check.test.ts\n\n## Notes\n- No worktree was created per request; changes are on branch pi/update-check-release-binary-guard.
Rahul Tarak committed
Apr 24, 2026 at 23:56 UTC
69f9ee998009610b8d67d65d3b592702d6b0dda7
2 files changed
+143
-74
ts/packages/cli/src/services/update-check.ts
+58
-23
@@ -1,6 +1,6 @@
1
import { readFileSync, mkdirSync } from 'node:fs';
2
import { writeFile } from 'node:fs/promises';
3
-import { homedir } from 'node:os';
3
+import { arch as getArch, homedir, platform as getPlatform } from 'node:os';
4
import { dirname, join } from 'node:path';
5
import semver from 'semver';
6
import { bold, cyanBright, dim } from 'src/ui/colors';
@@ -16,16 +16,22 @@ import { APP_VERSION, GITHUB_REPO } from '../constants';
16
* checkForUpdateInBackground() — fire-and-forget fetch, no await
17
*
18
* Strategy:
19
- * Uses GitHub's `git/matching-refs` API with the prefix
20
- * `tags/@composio/cli@` so only CLI tags are returned (tiny payload,
21
- * no monorepo noise). The result is cached to ~/.composio/update-check.json
22
- * and refreshed at most once every 24 hours.
19
+ * Uses GitHub's releases API and only considers stable @composio/cli releases
20
+ * that include the binary asset for the current platform. The result is cached
21
+ * to ~/.composio/update-check.json and refreshed at most once every 24 hours.
22
*/
23
24
const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000; // 24 hours
25
27
-/** Matches `refs/tags/@composio/cli@<semver>` — excludes prereleases. */
28
-const CLI_REF_RE = /^refs\/tags\/@composio\/cli@(\d+\.\d+\.\d+)$/;
26
+/** Matches `@composio/cli@<semver>` — excludes prereleases. */
27
+const CLI_RELEASE_TAG_RE = /^@composio\/cli@(\d+\.\d+\.\d+)$/;
28
+
29
+export interface UpdateCheckRelease {
30
+ tag_name?: unknown;
31
+ prerelease?: unknown;
32
+ draft?: unknown;
33
+ assets?: unknown;
34
+}
35
36
export interface UpdateCheckState {
37
lastChecked: string; // ISO-8601
@@ -39,34 +45,63 @@ export interface UpdateCheckConfig {
45
readonly stateFile: string;
46
readonly currentVersion: string;
47
readonly checkIntervalMs: number;
42
- readonly refsUrl: string;
48
+ readonly releasesUrl: string;
49
+ readonly binaryAssetName: string | undefined;
50
readonly accessToken: string | undefined;
51
readonly fetchFn: (url: string, init?: RequestInit) => Promise<Response>;
52
}
53
54
const _home = join(homedir(), '.composio');
55
56
+function getCurrentBinaryAssetName(): string | undefined {
57
+ const platform = getPlatform();
58
+ const rawArch = getArch();
59
+ if (platform !== 'darwin' && platform !== 'linux') return undefined;
60
+
61
+ const arch = rawArch === 'arm64' || rawArch === 'aarch64' ? 'aarch64' : rawArch;
62
+ if (arch !== 'x64' && arch !== 'aarch64') return undefined;
63
+
64
+ return `composio-${platform}-${arch}.zip`;
65
+}
66
+
67
const defaultConfig: UpdateCheckConfig = {
68
stateFile: join(_home, 'update-check.json'),
69
currentVersion: APP_VERSION,
70
checkIntervalMs: CHECK_INTERVAL_MS,
53
- refsUrl: `${GITHUB_REPO.API_BASE_URL}/repos/${GITHUB_REPO.OWNER}/${GITHUB_REPO.REPO}/git/matching-refs/tags/@composio/cli@`,
71
+ releasesUrl: `${GITHUB_REPO.API_BASE_URL}/repos/${GITHUB_REPO.OWNER}/${GITHUB_REPO.REPO}/releases?per_page=100`,
72
+ binaryAssetName: getCurrentBinaryAssetName(),
73
accessToken: process.env.COMPOSIO_GITHUB_ACCESS_TOKEN,
74
fetchFn: fetch,
75
};
76
77
// ── Pure helpers ────────────────────────────────────────────────────────
78
60
-/** Extract the highest stable semver from a GitHub matching-refs response. */
61
-export function parseLatestVersionFromRefs(refs: unknown): string | undefined {
62
- if (!Array.isArray(refs)) return undefined;
79
+/** Extract the highest stable semver from GitHub releases that include the required binary. */
80
+export function parseLatestVersionFromReleases(
81
+ releases: unknown,
82
+ binaryAssetName: string | undefined
83
+): string | undefined {
84
+ if (!binaryAssetName || !Array.isArray(releases)) return undefined;
85
86
let latest: string | undefined;
65
- for (const ref of refs) {
66
- if (typeof ref !== 'object' || ref === null || !('ref' in ref) || typeof ref.ref !== 'string')
67
- continue;
68
-
69
- const match = CLI_REF_RE.exec(ref.ref);
87
+ for (const release of releases) {
88
+ if (typeof release !== 'object' || release === null) continue;
89
+
90
+ const candidate = release as UpdateCheckRelease;
91
+ if (typeof candidate.tag_name !== 'string') continue;
92
+ if (candidate.prerelease === true || candidate.draft === true) continue;
93
+ if (!Array.isArray(candidate.assets)) continue;
94
+
95
+ const hasRequiredBinary = candidate.assets.some(
96
+ asset =>
97
+ typeof asset === 'object' &&
98
+ asset !== null &&
99
+ 'name' in asset &&
100
+ asset.name === binaryAssetName
101
+ );
102
+ if (!hasRequiredBinary) continue;
103
+
104
+ const match = CLI_RELEASE_TAG_RE.exec(candidate.tag_name);
105
if (!match) continue;
106
107
const version = match[1];
@@ -105,8 +140,8 @@ export function createUpdateChecker(config: UpdateCheckConfig) {
140
}
141
142
/**
108
- * Fetch the latest @composio/cli tag from GitHub via the lightweight
109
- * `git/matching-refs` endpoint, then write the result to the state file.
143
+ * Fetch the latest @composio/cli release from GitHub, requiring the current
144
+ * platform binary asset before writing the result to the state file.
145
*
146
* Returns the internal promise so tests can await completion.
147
* The public wrapper discards it (fire-and-forget).
@@ -135,7 +170,7 @@ export function createUpdateChecker(config: UpdateCheckConfig) {
170
}
171
172
// Always persist lastChecked to prevent retry loops when the fetch
138
- // fails or returns no matching tags.
173
+ // fails or returns no matching releases with a matching binary.
174
const writeState = (latestVersion?: string): Promise<void> => {
175
try {
176
const stateDir = dirname(config.stateFile);
@@ -154,13 +189,13 @@ export function createUpdateChecker(config: UpdateCheckConfig) {
189
};
190
191
return config
157
- .fetchFn(config.refsUrl, { headers, signal: AbortSignal.timeout(10_000) })
192
+ .fetchFn(config.releasesUrl, { headers, signal: AbortSignal.timeout(10_000) })
193
.then(res => {
194
if (!res.ok) throw new Error(`HTTP ${res.status}`);
195
return res.json();
196
})
162
- .then((refs: unknown) => {
163
- const latestVersion = parseLatestVersionFromRefs(refs);
197
+ .then((releases: unknown) => {
198
+ const latestVersion = parseLatestVersionFromReleases(releases, config.binaryAssetName);
199
return writeState(latestVersion);
200
})
201
.catch(() => {
ts/packages/cli/test/src/services/update-check.test.ts
+85
-51
@@ -5,7 +5,7 @@ import { tmpdir } from 'node:os';
5
import { withHttpServer } from 'test/__utils__/http-server';
6
import {
7
createUpdateChecker,
8
- parseLatestVersionFromRefs,
8
+ parseLatestVersionFromReleases,
9
type UpdateCheckConfig,
10
type UpdateCheckState,
11
} from 'src/services/update-check';
@@ -27,7 +27,8 @@ function makeConfig(overrides?: Partial<UpdateCheckConfig>): UpdateCheckConfig {
27
stateFile: join(tempDir, '.composio', 'update-check.json'),
28
currentVersion: '0.2.0',
29
checkIntervalMs: 24 * 60 * 60 * 1000,
30
- refsUrl: 'http://unused.test',
30
+ releasesUrl: 'http://unused.test',
31
+ binaryAssetName: 'composio-darwin-aarch64.zip',
32
accessToken: undefined,
33
fetchFn: () => Promise.reject(new Error('fetch not configured')),
34
...overrides,
@@ -40,63 +41,90 @@ function writeState(config: UpdateCheckConfig, state: UpdateCheckState): void {
41
writeFileSync(config.stateFile, JSON.stringify(state));
42
}
43
43
-/** Create a GitHub matching-refs response body. */
44
-function makeRefsPayload(versions: string[]) {
44
+/** Create a GitHub releases response body. */
45
+function makeReleasesPayload(versions: string[], assetName = 'composio-darwin-aarch64.zip') {
46
return versions.map(v => ({
46
- ref: `refs/tags/@composio/cli@${v}`,
47
- node_id: 'unused',
48
- url: 'unused',
49
- object: { sha: 'abc', type: 'tag', url: 'unused' },
47
+ tag_name: `@composio/cli@${v}`,
48
+ prerelease: v.includes('-'),
49
+ draft: false,
50
+ assets: [{ name: assetName, browser_download_url: 'unused' }],
51
}));
52
}
53
53
-// ── parseLatestVersionFromRefs (pure) ───────────────────────────────────
54
+// ── parseLatestVersionFromReleases (pure) ───────────────────────────────
55
+
56
+describe('parseLatestVersionFromReleases', () => {
57
+ const binaryAssetName = 'composio-darwin-aarch64.zip';
58
55
-describe('parseLatestVersionFromRefs', () => {
59
it('returns undefined for non-array input', () => {
57
- expect(parseLatestVersionFromRefs(null)).toBeUndefined();
58
- expect(parseLatestVersionFromRefs('string')).toBeUndefined();
59
- expect(parseLatestVersionFromRefs(42)).toBeUndefined();
60
+ expect(parseLatestVersionFromReleases(null, binaryAssetName)).toBeUndefined();
61
+ expect(parseLatestVersionFromReleases('string', binaryAssetName)).toBeUndefined();
62
+ expect(parseLatestVersionFromReleases(42, binaryAssetName)).toBeUndefined();
63
});
64
62
- it('returns undefined when no refs match the CLI pattern', () => {
63
- const refs = [
64
- { ref: 'refs/tags/@composio/core@1.0.0' },
65
- { ref: 'refs/tags/v1.0.0' },
66
- { ref: 'refs/heads/main' },
65
+ it('returns undefined when no releases match the CLI pattern', () => {
66
+ const releases = [
67
+ { tag_name: '@composio/core@1.0.0', assets: [{ name: binaryAssetName }] },
68
+ { tag_name: 'v1.0.0', assets: [{ name: binaryAssetName }] },
69
+ { tag_name: '@composio/cli@0.2.0-beta.1', assets: [{ name: binaryAssetName }] },
70
];
68
- expect(parseLatestVersionFromRefs(refs)).toBeUndefined();
71
+ expect(parseLatestVersionFromReleases(releases, binaryAssetName)).toBeUndefined();
72
});
73
74
it('returns the single matching version', () => {
72
- const refs = makeRefsPayload(['0.2.1']);
73
- expect(parseLatestVersionFromRefs(refs)).toBe('0.2.1');
75
+ const releases = makeReleasesPayload(['0.2.1']);
76
+ expect(parseLatestVersionFromReleases(releases, binaryAssetName)).toBe('0.2.1');
77
+ });
78
+
79
+ it('returns the highest semver, not the first element', () => {
80
+ const releases = makeReleasesPayload(['0.1.0', '0.10.0', '0.9.0', '0.2.0']);
81
+ expect(parseLatestVersionFromReleases(releases, binaryAssetName)).toBe('0.10.0');
82
});
83
76
- it('returns the highest semver, not the last element', () => {
77
- // GitHub returns refs sorted lexicographically — 0.10.0 < 0.9.0 lexically
78
- // but 0.10.0 > 0.9.0 in semver.
79
- const refs = makeRefsPayload(['0.1.0', '0.10.0', '0.9.0', '0.2.0']);
80
- expect(parseLatestVersionFromRefs(refs)).toBe('0.10.0');
84
+ it('excludes prerelease and draft releases', () => {
85
+ const releases = [
86
+ ...makeReleasesPayload(['0.2.0']),
87
+ {
88
+ tag_name: '@composio/cli@0.3.0',
89
+ prerelease: true,
90
+ draft: false,
91
+ assets: [{ name: binaryAssetName }],
92
+ },
93
+ {
94
+ tag_name: '@composio/cli@0.4.0',
95
+ prerelease: false,
96
+ draft: true,
97
+ assets: [{ name: binaryAssetName }],
98
+ },
99
+ ];
100
+ expect(parseLatestVersionFromReleases(releases, binaryAssetName)).toBe('0.2.0');
101
});
102
83
- it('excludes prerelease tags', () => {
84
- const refs = [
85
- { ref: 'refs/tags/@composio/cli@0.2.0' },
86
- { ref: 'refs/tags/@composio/cli@0.3.0-beta.1' },
103
+ it('requires the platform binary asset', () => {
104
+ const releases = [
105
+ ...makeReleasesPayload(['0.4.0'], 'composio-linux-x64.zip'),
106
+ ...makeReleasesPayload(['0.3.0']),
107
];
88
- expect(parseLatestVersionFromRefs(refs)).toBe('0.2.0');
108
+ expect(parseLatestVersionFromReleases(releases, binaryAssetName)).toBe('0.3.0');
109
+ });
110
+
111
+ it('returns undefined when no binary asset name is known', () => {
112
+ expect(
113
+ parseLatestVersionFromReleases(makeReleasesPayload(['0.2.1']), undefined)
114
+ ).toBeUndefined();
115
});
116
91
- it('skips malformed ref objects', () => {
92
- const refs = [
117
+ it('skips malformed release objects', () => {
118
+ const releases = [
119
null,
120
42,
95
- { noRef: true },
96
- { ref: 123 },
97
- { ref: 'refs/tags/@composio/cli@0.5.0' },
121
+ { noTagName: true },
122
+ { tag_name: 123 },
123
+ { tag_name: '@composio/cli@0.5.0' },
124
+ { tag_name: '@composio/cli@0.6.0', assets: [{ noName: true }] },
125
+ { tag_name: '@composio/cli@0.7.0', assets: [{ name: binaryAssetName }] },
126
];
99
- expect(parseLatestVersionFromRefs(refs)).toBe('0.5.0');
127
+ expect(parseLatestVersionFromReleases(releases, binaryAssetName)).toBe('0.7.0');
128
});
129
});
130
@@ -201,7 +229,7 @@ describe('checkForUpdate', () => {
229
const config = makeConfig({
230
fetchFn: vi.fn().mockResolvedValue({
231
ok: true,
204
- json: () => Promise.resolve(makeRefsPayload(['0.3.0'])),
232
+ json: () => Promise.resolve(makeReleasesPayload(['0.3.0'])),
233
}) as unknown as typeof fetch,
234
});
235
writeState(config, { lastChecked: stale, latestVersion: '0.2.0' });
@@ -218,7 +246,7 @@ describe('checkForUpdate', () => {
246
const config = makeConfig({
247
fetchFn: vi.fn().mockResolvedValue({
248
ok: true,
221
- json: () => Promise.resolve(makeRefsPayload(['0.4.0', '0.3.0'])),
249
+ json: () => Promise.resolve(makeReleasesPayload(['0.4.0', '0.3.0'])),
250
}) as unknown as typeof fetch,
251
});
252
const { checkForUpdate } = createUpdateChecker(config);
@@ -234,7 +262,7 @@ describe('checkForUpdate', () => {
262
const config = makeConfig({
263
fetchFn: vi.fn().mockResolvedValue({
264
ok: true,
237
- json: () => Promise.resolve(makeRefsPayload(['0.5.0'])),
265
+ json: () => Promise.resolve(makeReleasesPayload(['0.5.0'])),
266
}) as unknown as typeof fetch,
267
});
268
mkdirSync(dirname(config.stateFile), { recursive: true });
@@ -247,11 +275,14 @@ describe('checkForUpdate', () => {
275
expect(state.latestVersion).toBe('0.5.0');
276
});
277
250
- it('still writes lastChecked when no CLI tags are found', async () => {
278
+ it('still writes lastChecked when no CLI releases with the required binary are found', async () => {
279
const config = makeConfig({
280
fetchFn: vi.fn().mockResolvedValue({
281
ok: true,
254
- json: () => Promise.resolve([{ ref: 'refs/tags/@composio/core@1.0.0' }]),
282
+ json: () =>
283
+ Promise.resolve([
284
+ { tag_name: '@composio/core@1.0.0', assets: [{ name: 'composio-darwin-aarch64.zip' }] },
285
+ ]),
286
}) as unknown as typeof fetch,
287
});
288
const { checkForUpdate } = createUpdateChecker(config);
@@ -261,15 +292,18 @@ describe('checkForUpdate', () => {
292
expect(existsSync(config.stateFile)).toBe(true);
293
const state: UpdateCheckState = JSON.parse(readFileSync(config.stateFile, 'utf-8'));
294
expect(state.lastChecked).toBeDefined();
264
- // Falls back to currentVersion since no previous state and no tags found
295
+ // Falls back to currentVersion since no previous state and no matching releases found
296
expect(state.latestVersion).toBe(config.currentVersion);
297
});
298
268
- it('preserves previous latestVersion when no CLI tags are found', async () => {
299
+ it('preserves previous latestVersion when no CLI releases with the required binary are found', async () => {
300
const config = makeConfig({
301
fetchFn: vi.fn().mockResolvedValue({
302
ok: true,
272
- json: () => Promise.resolve([{ ref: 'refs/tags/@composio/core@1.0.0' }]),
303
+ json: () =>
304
+ Promise.resolve([
305
+ { tag_name: '@composio/core@1.0.0', assets: [{ name: 'composio-darwin-aarch64.zip' }] },
306
+ ]),
307
}) as unknown as typeof fetch,
308
});
309
const stale = new Date(Date.now() - 25 * 60 * 60 * 1000).toISOString();
@@ -318,7 +352,7 @@ describe('checkForUpdate', () => {
352
it('sends Authorization header when accessToken is set', async () => {
353
const fetchFn = vi.fn().mockResolvedValue({
354
ok: true,
321
- json: () => Promise.resolve(makeRefsPayload(['0.2.1'])),
355
+ json: () => Promise.resolve(makeReleasesPayload(['0.2.1'])),
356
});
357
const config = makeConfig({
358
accessToken: 'ghp_secret123',
@@ -336,7 +370,7 @@ describe('checkForUpdate', () => {
370
it('does not send Authorization header when accessToken is undefined', async () => {
371
const fetchFn = vi.fn().mockResolvedValue({
372
ok: true,
339
- json: () => Promise.resolve(makeRefsPayload(['0.2.1'])),
373
+ json: () => Promise.resolve(makeReleasesPayload(['0.2.1'])),
374
});
375
const config = makeConfig({
376
accessToken: undefined,
@@ -358,10 +392,10 @@ describe('checkForUpdate with real HTTP', () => {
392
await withHttpServer(
393
(_req, res) => {
394
res.writeHead(200, { 'Content-Type': 'application/json' });
361
- res.end(JSON.stringify(makeRefsPayload(['0.1.26', '0.2.0', '0.2.1'])));
395
+ res.end(JSON.stringify(makeReleasesPayload(['0.1.26', '0.2.0', '0.2.1'])));
396
},
397
async baseUrl => {
364
- const config = makeConfig({ refsUrl: baseUrl, fetchFn: fetch });
398
+ const config = makeConfig({ releasesUrl: baseUrl, fetchFn: fetch });
399
const { checkForUpdate } = createUpdateChecker(config);
400
401
await checkForUpdate();
@@ -379,11 +413,11 @@ describe('checkForUpdate with real HTTP', () => {
413
(req, res) => {
414
receivedAuth = req.headers.authorization;
415
res.writeHead(200, { 'Content-Type': 'application/json' });
382
- res.end(JSON.stringify(makeRefsPayload(['0.2.1'])));
416
+ res.end(JSON.stringify(makeReleasesPayload(['0.2.1'])));
417
},
418
async baseUrl => {
419
const config = makeConfig({
386
- refsUrl: baseUrl,
420
+ releasesUrl: baseUrl,
421
accessToken: 'ghp_test_token',
422
fetchFn: fetch,
423
});