Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Merge branch 'feat/cli-install-shell-flag' into feat/mise-style-installer-rollout

jkomyno32b84ab19256
diff --cc ts/packages/cli/src/commands/install.cmd.ts
index 6c59a3a6e,1406c0741..7147c4f15
--- a/ts/packages/cli/src/commands/install.cmd.ts
+++ b/ts/packages/cli/src/commands/install.cmd.ts
@@@ -249,9 -305,16 +304,16 @@@ export const installShellIntegration =
yield* ui.intro('composio install');
+ // Resolve the entry-point bin dir: explicit env, then a ~/.local/bin/composio
+ // that is this executable, then the runtime executable's own directory.
const envBinDir = yield* readOptionalEnv('COMPOSIO_BIN_DIR');
const localBinDir = path.join(os.homedir, '.local', 'bin');
- const localBinComposioExists = yield* fs.exists(path.join(localBinDir, 'composio'));
- const execPath = params.execPath ?? nodeProcess.execPath;
++ const execPath = nodeProcess.execPath;
+ const localBinComposioIsCurrentExecutable = yield* resolvesToCurrentExecutable(
+ path.join(localBinDir, 'composio'),
+ execPath,
+ fs
+ );
const binDir = path.normalize(
resolveBinDir({
envBinDir,
@@@ -411,10 -475,7 +474,9 @@@
// can alias the same physical file through symlinks, and this write must
// not discard a previous iteration's append.
const existingContents = yield* readMaybeMissingFile(filePath, fs);
- const writeTarget = yield* resolveWriteTarget(filePath, fs);
+ // PATH files were already resolved above; only the completion file needs a fresh resolve.
+ const writeTarget =
+ pathFileTargets.get(filePath) ?? (yield* resolveWriteTarget(filePath, fs));
- const existingTargetInfo = yield* fs.stat(writeTarget).pipe(Effect.option);
yield* fs
.makeDirectory(path.dirname(writeTarget), { recursive: true })
diff --cc ts/packages/cli/test/__utils__/services/test-layer.ts
index 2dcafa3a1,cbf7f5c4f..5bbbd3546
--- a/ts/packages/cli/test/__utils__/services/test-layer.ts
+++ b/ts/packages/cli/test/__utils__/services/test-layer.ts
@@@ -84,12 -84,6 +84,13 @@@ export interface TestLiveInput
*/
fixture?: string;
+ /**
- * Override for the mocked `NodeProcess.execPath`.
++ * Override for the mocked `NodeProcess.execPath`. A relative value resolves
++ * against the test home directory, which is only known once the layer builds.
+ * Defaults to `<cwd>/composio`.
+ */
+ execPath?: string;
+
/**
* Mock toolkit-related data to use in test.
*/
@@@ -810,7 -804,7 +811,7 @@@ export const TestLayer = (input?: TestL
NodeProcess,
new NodeProcess({
cwd,
- execPath: input?.execPath ?? path.join(cwd, 'composio'),
- execPath: path.join(cwd, 'composio'),
++ execPath: input?.execPath ? path.resolve(cwd, input.execPath) : path.join(cwd, 'composio'),
platform: 'darwin',
arch: 'arm64',
})
diff --cc ts/packages/cli/test/src/commands/install.cmd.test.ts
index a8c825ff2,d0efcc882..480b43151
--- a/ts/packages/cli/test/src/commands/install.cmd.test.ts
+++ b/ts/packages/cli/test/src/commands/install.cmd.test.ts
@@@ -40,12 -42,14 +44,12 @@@ const InstallTestLive = (input: Paramet
const install = (
params: {
readonly completions?: boolean;
- readonly shell?: string;
- readonly execPath?: string;
+ readonly shell?: Shell;
} = {}
) =>
installShellIntegration({
completions: params.completions ?? false,
- shell: params.shell as 'zsh' | 'bash' | 'fish' | undefined,
- execPath: params.execPath ?? TEST_EXEC_PATH,
+ shell: params.shell,
});
// NOTE: `@effect/vitest`'s `layer(...)` builds one shared TestLive instance
@@@ -837,8 -842,8 +842,8 @@@ describe('CLI: composio install', () =
});
});
- describe('[When] COMPOSIO_BIN_DIR is unset and ~/.local/bin already has a composio entry point', () => {
- layer(InstallTestLive())(it => {
+ describe('[When] COMPOSIO_BIN_DIR is unset and ~/.local/bin/composio is the running executable', () => {
- layer(TestLive())(it => {
++ layer(TestLive({ execPath: '.local/bin/composio' }))(it => {
it.scoped('[Then] the PATH line targets ~/.local/bin via a literal $HOME prefix', () =>
Effect.gen(function* () {
const os = yield* NodeOs;
@@@ -846,10 -851,11 +851,11 @@@
vi.stubEnv('SHELL', '/bin/zsh');
const localBinDir = path.join(os.homedir, '.local', 'bin');
+ const localBinComposio = path.join(localBinDir, 'composio');
yield* fs.makeDirectory(localBinDir, { recursive: true });
- yield* fs.writeFileString(path.join(localBinDir, 'composio'), '');
+ yield* fs.writeFileString(localBinComposio, '#!/bin/sh\n');
- yield* install({ execPath: localBinComposio });
+ yield* install();
const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
expect(contents).toContain('export PATH="$HOME/.local/bin:$PATH"');
@@@ -859,8 -865,58 +865,58 @@@
});
});
- describe('[When] COMPOSIO_BIN_DIR is set and ~/.local/bin also already has a composio entry point', () => {
+ describe('[When] ~/.local/bin/composio is a symlink chain to the running executable', () => {
- layer(TestLive())(it => {
++ layer(TestLive({ execPath: '.composio-dist/composio' }))(it => {
+ it.scoped('[Then] the PATH line still targets ~/.local/bin', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ const fs = yield* FileSystem.FileSystem;
+ vi.stubEnv('SHELL', '/bin/zsh');
+
+ const execDir = path.join(os.homedir, '.composio-dist');
+ const execFile = path.join(execDir, 'composio');
+ const intermediateLink = path.join(os.homedir, '.composio-launcher');
+ const localBinDir = path.join(os.homedir, '.local', 'bin');
+ yield* fs.makeDirectory(execDir, { recursive: true });
+ yield* fs.makeDirectory(localBinDir, { recursive: true });
+ yield* fs.writeFileString(execFile, '#!/bin/sh\n');
+ yield* fs.symlink(execFile, intermediateLink);
+ yield* fs.symlink(intermediateLink, path.join(localBinDir, 'composio'));
+
- yield* install({ execPath: execFile });
++ yield* install();
+
+ const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
+ expect(contents).toContain('export PATH="$HOME/.local/bin:$PATH"');
+ })
+ );
+ });
+ });
+
+ describe('[When] ~/.local/bin/composio is a foreign program (e.g. a leftover pip install)', () => {
- layer(TestLive())(it => {
+ layer(InstallTestLive())(it => {
+ it.scoped('[Then] the PATH line targets the running executable directory instead', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ const fs = yield* FileSystem.FileSystem;
+ vi.stubEnv('SHELL', '/bin/zsh');
+ const expectedBinDir = expectedRuntimeBinDir();
+
+ const localBinDir = path.join(os.homedir, '.local', 'bin');
+ yield* fs.makeDirectory(localBinDir, { recursive: true });
+ yield* fs.writeFileString(path.join(localBinDir, 'composio'), '#!/usr/bin/env python\n');
+
+ yield* install();
+
+ const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
+ expect(contents).toContain(`export PATH="${expectedBinDir}:$PATH"`);
+ expect(contents).not.toContain('.local/bin');
+ })
+ );
+ });
+ });
+
+ describe('[When] COMPOSIO_BIN_DIR is set and ~/.local/bin/composio is also the running executable', () => {
- layer(TestLive())(it => {
++ layer(TestLive({ execPath: '.local/bin/composio' }))(it => {
it.scoped('[Then] the env var wins over the ~/.local/bin fallback', () =>
Effect.gen(function* () {
const os = yield* NodeOs;
@@@ -869,10 -925,11 +925,11 @@@
vi.stubEnv('COMPOSIO_BIN_DIR', '/custom/bin');
const localBinDir = path.join(os.homedir, '.local', 'bin');
+ const localBinComposio = path.join(localBinDir, 'composio');
yield* fs.makeDirectory(localBinDir, { recursive: true });
- yield* fs.writeFileString(path.join(localBinDir, 'composio'), '');
+ yield* fs.writeFileString(localBinComposio, '#!/bin/sh\n');
- yield* install({ execPath: localBinComposio });
+ yield* install();
const contents = yield* fs.readFileString(path.join(os.homedir, '.zshrc'));
expect(contents).toContain('export PATH="/custom/bin:$PATH"');
@@@ -960,7 -1020,8 +1020,8 @@@
Effect.gen(function* () {
vi.stubEnv('SHELL', '/bin/zsh');
- yield* install();
- const error = yield* install({ execPath: "/tmp/o'brien/composio" }).pipe(Effect.flip);
++ const error = yield* install().pipe(Effect.flip);
+ expect(error).toBeInstanceOf(ShellSetupAbortError);
const output = (yield* MockConsole.getLines()).join('\n');
expect(output).toContain('Resolved bin directory');