@devries-cameron20 / composio-1 / commits / 03f21d423
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.

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

## Summary `composio install` uses a temporary file and rename so shell config updates are atomic. When the config path is a symlink, that rename replaces the symlink itself. This breaks setups that use tools such as GNU Stow to manage and sync dotfiles across machines. Fixes #3922 ## Changes - Resolve valid symlink chains before choosing the temporary file and rename target. - Keep regular shell config files on the existing write path. - Add a regression test using a relative `.zshrc` symlink. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Refactor/Chore - [ ] Documentation - [ ] Breaking change ## How Has This Been Tested? - `mise exec -- pnpm --filter @composio/cli exec vitest run test/src/commands/install.cmd.test.ts` — 13 passed - `mise exec -- pnpm --filter @composio/cli typecheck` - ESLint and Prettier on the two changed files ## Screenshots (if applicable) Not applicable. ## Checklist - [x] I have read the Code of Conduct and this PR adheres to it - [x] I ran linters/tests locally and they passed - [x] I updated documentation as needed - [x] I added tests or explain why not applicable - [x] I added a changeset if this change affects published packages ## Additional context No changeset is needed because `@composio/cli` is ignored by the repository's Changesets configuration. The current `next` branch is missing the `#ssrf_guard` alias in the CLI Vitest config. I added that alias locally to run the focused test, then removed it before committing this patch. --------- Co-authored-by: Alberto Schiabel <jkomyno@users.noreply.github.com> Co-authored-by: jkomyno <alberto@composio.dev>

pandec committed Jul 23, 2026 at 16:26 UTC 03f21d4236568aeea4fcd6abea9c323265dc2f5f
2 files changed +77 -4
ts/packages/cli/src/commands/install.cmd.ts
+18 -4
@@ -142,6 +142,16 @@ const readMaybeMissingFile = (
142 )
143 );
144
145 +/** Resolve valid symlink chains so atomic writes update the target instead of replacing the link. */
146 +const resolveWriteTarget = (
147 + filePath: string,
148 + fs: FileSystem.FileSystem
149 +): Effect.Effect<string, PlatformError> =>
150 + fs.readLink(filePath).pipe(
151 + Effect.flatMap(() => fs.realPath(filePath)),
152 + Effect.catchAll(() => Effect.succeed(filePath))
153 + );
154 +
155 // ---------------------------------------------------------------------------
156 // Exported logic (reusable from install.sh post-install delegation)
157 // ---------------------------------------------------------------------------
@@ -256,10 +266,14 @@ export const installShellIntegration = (params: {
266
267 if (blocksByFile.size > 0) {
268 for (const [filePath, blocks] of blocksByFile.entries()) {
259 - const existingContents = existingByFile.get(filePath) ?? '';
269 + // Re-read instead of reusing the pre-check snapshot: two configured paths
270 + // can alias the same physical file through symlinks, and this write must
271 + // not discard a previous iteration's append.
272 + const existingContents = yield* readMaybeMissingFile(filePath, fs);
273 + const writeTarget = yield* resolveWriteTarget(filePath, fs);
274
275 yield* fs
262 - .makeDirectory(path.dirname(filePath), { recursive: true })
276 + .makeDirectory(path.dirname(writeTarget), { recursive: true })
277 .pipe(
278 Effect.catchAll(e =>
279 Effect.logDebug('Could not create parent directory (may already exist):', e)
@@ -267,10 +281,10 @@ export const installShellIntegration = (params: {
281 );
282
283 const appendContent = '\n' + blocks.join('\n\n') + '\n';
270 - const tmpPath = `${filePath}.composio-tmp`;
284 + const tmpPath = `${writeTarget}.composio-tmp`;
285
286 yield* fs.writeFileString(tmpPath, existingContents + appendContent);
273 - yield* fs.rename(tmpPath, filePath);
287 + yield* fs.rename(tmpPath, writeTarget);
288
289 yield* ui.log.success(`Updated ${tildify(filePath, os.homedir)}`);
290 }
ts/packages/cli/test/src/commands/install.cmd.test.ts
+59
@@ -57,6 +57,28 @@ describe('CLI: composio install', () => {
57 expect(output).toContain('source ~/.zshrc');
58 })
59 );
60 +
61 + it.scoped('[Then] preserves a symlinked .zshrc', () =>
62 + Effect.gen(function* () {
63 + const os = yield* NodeOs;
64 + const fs = yield* FileSystem.FileSystem;
65 + process.env.SHELL = '/bin/zsh';
66 + process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
67 +
68 + const rcPath = path.join(os.homedir, '.zshrc');
69 + const managedPath = path.join(os.homedir, '.managed-zshrc');
70 + const linkTarget = path.basename(managedPath);
71 + yield* fs.remove(rcPath, { force: true });
72 + yield* fs.writeFileString(managedPath, '# managed shell config\n');
73 + yield* fs.symlink(linkTarget, rcPath);
74 +
75 + yield* cli(['install']);
76 +
77 + expect(yield* fs.readLink(rcPath)).toBe(linkTarget);
78 + expect(yield* fs.readFileString(managedPath)).toContain('# Composio CLI');
79 + expect(yield* fs.exists(`${rcPath}.composio-tmp`)).toBe(false);
80 + })
81 + );
82 });
83 });
84
@@ -173,6 +195,43 @@ describe('CLI: composio install', () => {
195 });
196 });
197
198 + describe('[When] fish config and completions are symlinked to the same file', () => {
199 + layer(TestLive())(it => {
200 + it.scoped('[Then] keeps both PATH and completions blocks', () =>
201 + Effect.gen(function* () {
202 + const os = yield* NodeOs;
203 + const fs = yield* FileSystem.FileSystem;
204 + process.env.SHELL = '/usr/bin/fish';
205 + process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
206 +
207 + const configPath = path.join(os.homedir, '.config', 'fish', 'config.fish');
208 + const completionPath = path.join(
209 + os.homedir,
210 + '.config',
211 + 'fish',
212 + 'completions',
213 + 'composio.fish'
214 + );
215 + const managedPath = path.join(os.homedir, '.managed-fish-config');
216 + yield* fs.makeDirectory(path.dirname(completionPath), { recursive: true });
217 + yield* fs.remove(configPath, { force: true });
218 + yield* fs.writeFileString(managedPath, '# managed fish config\n');
219 + yield* fs.symlink(managedPath, configPath);
220 + yield* fs.symlink(managedPath, completionPath);
221 +
222 + yield* cli(['install', '--completions']);
223 +
224 + const contents = yield* fs.readFileString(managedPath);
225 + const pathMarkerCount = contents.match(/^# Composio CLI$/gm)?.length ?? 0;
226 + const completionsMarkerCount =
227 + contents.match(/^# Composio CLI completions$/gm)?.length ?? 0;
228 + expect(pathMarkerCount).toBe(1);
229 + expect(completionsMarkerCount).toBe(1);
230 + })
231 + );
232 + });
233 + });
234 +
235 describe('[When] fish shell installs completions twice', () => {
236 layer(TestLive())(it => {
237 it.scoped('[Then] keeps config.fish and composio.fish idempotent', () =>