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.

fix(cli): preserve symlinked shell configs during install (#3923)

pandec03f21d423656
diff --git a/ts/packages/cli/src/commands/install.cmd.ts b/ts/packages/cli/src/commands/install.cmd.ts
index 10e7c1e80..69b5b60b4 100644
--- a/ts/packages/cli/src/commands/install.cmd.ts
+++ b/ts/packages/cli/src/commands/install.cmd.ts
@@ -142,6 +142,16 @@ const readMaybeMissingFile = (
)
);
+/** Resolve valid symlink chains so atomic writes update the target instead of replacing the link. */
+const resolveWriteTarget = (
+ filePath: string,
+ fs: FileSystem.FileSystem
+): Effect.Effect<string, PlatformError> =>
+ fs.readLink(filePath).pipe(
+ Effect.flatMap(() => fs.realPath(filePath)),
+ Effect.catchAll(() => Effect.succeed(filePath))
+ );
+
// ---------------------------------------------------------------------------
// Exported logic (reusable from install.sh post-install delegation)
// ---------------------------------------------------------------------------
@@ -256,10 +266,14 @@ export const installShellIntegration = (params: {
if (blocksByFile.size > 0) {
for (const [filePath, blocks] of blocksByFile.entries()) {
- const existingContents = existingByFile.get(filePath) ?? '';
+ // Re-read instead of reusing the pre-check snapshot: two configured paths
+ // 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);
yield* fs
- .makeDirectory(path.dirname(filePath), { recursive: true })
+ .makeDirectory(path.dirname(writeTarget), { recursive: true })
.pipe(
Effect.catchAll(e =>
Effect.logDebug('Could not create parent directory (may already exist):', e)
@@ -267,10 +281,10 @@ export const installShellIntegration = (params: {
);
const appendContent = '\n' + blocks.join('\n\n') + '\n';
- const tmpPath = `${filePath}.composio-tmp`;
+ const tmpPath = `${writeTarget}.composio-tmp`;
yield* fs.writeFileString(tmpPath, existingContents + appendContent);
- yield* fs.rename(tmpPath, filePath);
+ yield* fs.rename(tmpPath, writeTarget);
yield* ui.log.success(`Updated ${tildify(filePath, os.homedir)}`);
}
diff --git a/ts/packages/cli/test/src/commands/install.cmd.test.ts b/ts/packages/cli/test/src/commands/install.cmd.test.ts
index f2fad7172..b0afb1990 100644
--- a/ts/packages/cli/test/src/commands/install.cmd.test.ts
+++ b/ts/packages/cli/test/src/commands/install.cmd.test.ts
@@ -57,6 +57,28 @@ describe('CLI: composio install', () => {
expect(output).toContain('source ~/.zshrc');
})
);
+
+ it.scoped('[Then] preserves a symlinked .zshrc', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ const fs = yield* FileSystem.FileSystem;
+ process.env.SHELL = '/bin/zsh';
+ process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
+
+ const rcPath = path.join(os.homedir, '.zshrc');
+ const managedPath = path.join(os.homedir, '.managed-zshrc');
+ const linkTarget = path.basename(managedPath);
+ yield* fs.remove(rcPath, { force: true });
+ yield* fs.writeFileString(managedPath, '# managed shell config\n');
+ yield* fs.symlink(linkTarget, rcPath);
+
+ yield* cli(['install']);
+
+ expect(yield* fs.readLink(rcPath)).toBe(linkTarget);
+ expect(yield* fs.readFileString(managedPath)).toContain('# Composio CLI');
+ expect(yield* fs.exists(`${rcPath}.composio-tmp`)).toBe(false);
+ })
+ );
});
});
@@ -173,6 +195,43 @@ describe('CLI: composio install', () => {
});
});
+ describe('[When] fish config and completions are symlinked to the same file', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] keeps both PATH and completions blocks', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ const fs = yield* FileSystem.FileSystem;
+ process.env.SHELL = '/usr/bin/fish';
+ process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
+
+ const configPath = path.join(os.homedir, '.config', 'fish', 'config.fish');
+ const completionPath = path.join(
+ os.homedir,
+ '.config',
+ 'fish',
+ 'completions',
+ 'composio.fish'
+ );
+ const managedPath = path.join(os.homedir, '.managed-fish-config');
+ yield* fs.makeDirectory(path.dirname(completionPath), { recursive: true });
+ yield* fs.remove(configPath, { force: true });
+ yield* fs.writeFileString(managedPath, '# managed fish config\n');
+ yield* fs.symlink(managedPath, configPath);
+ yield* fs.symlink(managedPath, completionPath);
+
+ yield* cli(['install', '--completions']);
+
+ const contents = yield* fs.readFileString(managedPath);
+ const pathMarkerCount = contents.match(/^# Composio CLI$/gm)?.length ?? 0;
+ const completionsMarkerCount =
+ contents.match(/^# Composio CLI completions$/gm)?.length ?? 0;
+ expect(pathMarkerCount).toBe(1);
+ expect(completionsMarkerCount).toBe(1);
+ })
+ );
+ });
+ });
+
describe('[When] fish shell installs completions twice', () => {
layer(TestLive())(it => {
it.scoped('[Then] keeps config.fish and composio.fish idempotent', () =>