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): only prefer ~/.local/bin when its composio entry is this executable
A bare exists-check let any leftover ~/.local/bin/composio (e.g. a pip or pipx install) win bin-dir resolution, so the PATH line pointed shells at a foreign program while the installer reported success. Prefer ~/.local/bin only when its entry realpath-resolves, following symlinks, to the running executable; otherwise fall through to the runtime executable's directory. The COMPOSIO_BIN_DIR override stays highest precedence.
jkomyno committed
Aug 3, 2026 at 20:23 UTC
6d0e14f155125742dd2447f510907b3e5a7bafc0
2 files changed
+90
-15
ts/packages/cli/src/commands/install.cmd.ts
+32
-9
@@ -85,13 +85,31 @@ const isDirOnPath = (pathEnv: string, dir: string): boolean =>
85
pathEnv.split(':').some(entry => entry === dir);
86
87
/**
88
- * Bin-dir resolution order: explicit env, then `~/.local/bin` when it already
89
- * holds a `composio` entry point, then the real binary's own directory.
88
+ * True when `candidate` resolves (following symlinks) to the running
89
+ * executable. A bare exists-check is not enough for bin-dir resolution: a
90
+ * leftover `composio` from another installer (e.g. pip) would win, and the
91
+ * PATH line would point shells at the wrong program.
92
+ */
93
+const resolvesToCurrentExecutable = (
94
+ candidate: string,
95
+ execPath: string,
96
+ fs: FileSystem.FileSystem
97
+): Effect.Effect<boolean> =>
98
+ Effect.zipWith(
99
+ fs.realPath(candidate),
100
+ fs.realPath(execPath).pipe(Effect.orElseSucceed(() => execPath)),
101
+ (candidateReal, execReal) => candidateReal === execReal
102
+ ).pipe(Effect.orElseSucceed(() => false));
103
+
104
+/**
105
+ * Bin-dir resolution order: explicit env, then `~/.local/bin` when its
106
+ * `composio` entry point is the running executable, then the real binary's
107
+ * own directory.
108
*/
109
const resolveBinDir = (params: {
110
readonly envBinDir: string | undefined;
111
readonly localBinDir: string;
94
- readonly localBinComposioExists: boolean;
112
+ readonly localBinComposioIsCurrentExecutable: boolean;
113
readonly execPath: string;
114
readonly path: Path.Path;
115
}): string => {
@@ -99,7 +117,7 @@ const resolveBinDir = (params: {
117
if (trimmedEnvBinDir && trimmedEnvBinDir.length > 0) {
118
return trimmedEnvBinDir;
119
}
102
- if (params.localBinComposioExists) {
120
+ if (params.localBinComposioIsCurrentExecutable) {
121
return params.localBinDir;
122
}
123
return params.path.dirname(params.execPath);
@@ -250,17 +268,22 @@ export const installShellIntegration = (params: {
268
269
yield* ui.intro('composio install');
270
253
- // Resolve the entry-point bin dir: explicit env, then an existing
254
- // ~/.local/bin/composio, then the runtime executable's own directory.
271
+ // Resolve the entry-point bin dir: explicit env, then a ~/.local/bin/composio
272
+ // that is this executable, then the runtime executable's own directory.
273
const envBinDir = yield* readOptionalEnv('COMPOSIO_BIN_DIR');
274
const localBinDir = path.join(os.homedir, '.local', 'bin');
257
- const localBinComposioExists = yield* fs.exists(path.join(localBinDir, 'composio'));
275
+ const execPath = params.execPath ?? nodeProcess.execPath;
276
+ const localBinComposioIsCurrentExecutable = yield* resolvesToCurrentExecutable(
277
+ path.join(localBinDir, 'composio'),
278
+ execPath,
279
+ fs
280
+ );
281
const binDir = path.normalize(
282
resolveBinDir({
283
envBinDir,
284
localBinDir,
262
- localBinComposioExists,
263
- execPath: params.execPath ?? nodeProcess.execPath,
285
+ localBinComposioIsCurrentExecutable,
286
+ execPath,
287
path,
288
})
289
);
ts/packages/cli/test/src/commands/install.cmd.test.ts
+58
-6
@@ -837,7 +837,7 @@ describe('CLI: composio install', () => {
837
});
838
});
839
840
- describe('[When] COMPOSIO_BIN_DIR is unset and ~/.local/bin already has a composio entry point', () => {
840
+ describe('[When] COMPOSIO_BIN_DIR is unset and ~/.local/bin/composio is the running executable', () => {
841
layer(TestLive())(it => {
842
it.scoped('[Then] the PATH line targets ~/.local/bin via a literal $HOME prefix', () =>
843
Effect.gen(function* () {
@@ -846,10 +846,11 @@ describe('CLI: composio install', () => {
846
vi.stubEnv('SHELL', '/bin/zsh');
847
848
const localBinDir = path.join(os.homedir, '.local', 'bin');
849
+ const localBinComposio = path.join(localBinDir, 'composio');
850
yield* fs.makeDirectory(localBinDir, { recursive: true });
850
- yield* fs.writeFileString(path.join(localBinDir, 'composio'), '');
851
+ yield* fs.writeFileString(localBinComposio, '#!/bin/sh\n');
852
852
- yield* install();
853
+ yield* install({ execPath: localBinComposio });
854
855
const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
856
expect(contents).toContain('export PATH="$HOME/.local/bin:$PATH"');
@@ -859,7 +860,57 @@ describe('CLI: composio install', () => {
860
});
861
});
862
862
- describe('[When] COMPOSIO_BIN_DIR is set and ~/.local/bin also already has a composio entry point', () => {
863
+ describe('[When] ~/.local/bin/composio is a symlink chain to the running executable', () => {
864
+ layer(TestLive())(it => {
865
+ it.scoped('[Then] the PATH line still targets ~/.local/bin', () =>
866
+ Effect.gen(function* () {
867
+ const os = yield* NodeOs;
868
+ const fs = yield* FileSystem.FileSystem;
869
+ vi.stubEnv('SHELL', '/bin/zsh');
870
+
871
+ const execDir = path.join(os.homedir, '.composio-dist');
872
+ const execFile = path.join(execDir, 'composio');
873
+ const intermediateLink = path.join(os.homedir, '.composio-launcher');
874
+ const localBinDir = path.join(os.homedir, '.local', 'bin');
875
+ yield* fs.makeDirectory(execDir, { recursive: true });
876
+ yield* fs.makeDirectory(localBinDir, { recursive: true });
877
+ yield* fs.writeFileString(execFile, '#!/bin/sh\n');
878
+ yield* fs.symlink(execFile, intermediateLink);
879
+ yield* fs.symlink(intermediateLink, path.join(localBinDir, 'composio'));
880
+
881
+ yield* install({ execPath: execFile });
882
+
883
+ const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
884
+ expect(contents).toContain('export PATH="$HOME/.local/bin:$PATH"');
885
+ })
886
+ );
887
+ });
888
+ });
889
+
890
+ describe('[When] ~/.local/bin/composio is a foreign program (e.g. a leftover pip install)', () => {
891
+ layer(TestLive())(it => {
892
+ it.scoped('[Then] the PATH line targets the running executable directory instead', () =>
893
+ Effect.gen(function* () {
894
+ const os = yield* NodeOs;
895
+ const fs = yield* FileSystem.FileSystem;
896
+ vi.stubEnv('SHELL', '/bin/zsh');
897
+ const expectedBinDir = expectedRuntimeBinDir();
898
+
899
+ const localBinDir = path.join(os.homedir, '.local', 'bin');
900
+ yield* fs.makeDirectory(localBinDir, { recursive: true });
901
+ yield* fs.writeFileString(path.join(localBinDir, 'composio'), '#!/usr/bin/env python\n');
902
+
903
+ yield* install();
904
+
905
+ const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
906
+ expect(contents).toContain(`export PATH="${expectedBinDir}:$PATH"`);
907
+ expect(contents).not.toContain('.local/bin');
908
+ })
909
+ );
910
+ });
911
+ });
912
+
913
+ describe('[When] COMPOSIO_BIN_DIR is set and ~/.local/bin/composio is also the running executable', () => {
914
layer(TestLive())(it => {
915
it.scoped('[Then] the env var wins over the ~/.local/bin fallback', () =>
916
Effect.gen(function* () {
@@ -869,10 +920,11 @@ describe('CLI: composio install', () => {
920
vi.stubEnv('COMPOSIO_BIN_DIR', '/custom/bin');
921
922
const localBinDir = path.join(os.homedir, '.local', 'bin');
923
+ const localBinComposio = path.join(localBinDir, 'composio');
924
yield* fs.makeDirectory(localBinDir, { recursive: true });
873
- yield* fs.writeFileString(path.join(localBinDir, 'composio'), '');
925
+ yield* fs.writeFileString(localBinComposio, '#!/bin/sh\n');
926
875
- yield* install();
927
+ yield* install({ execPath: localBinComposio });
928
929
const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
930
expect(contents).toContain('export PATH="/custom/bin:$PATH"');