@devries-cameron20 / composio Mirror · read-only / commits / cf13e1781
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.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 21:00 UTC

Fix fish completion install paths (#3162)

## Summary - Route fish shell completions to `~/.config/fish/completions/composio.fish` instead of writing them into the rc file. - Keep fish PATH setup in `~/.config/fish/config.fish` while writing completion blocks to the dedicated completions file. - Sanitize fish completion lines to strip description text that can break parsing, including multiline descriptions. - Add tests covering fish install behavior and fish completion sanitization. Closes #3147 ## Testing - `pnpm test --filter ts/packages/cli/test/src/commands/install.cmd.test.ts` - `pnpm test --filter ts/packages/cli/test/src/effects/shell-completions.test.ts` - Not run: full repository test suite

Rahul Tarak committed May 26, 2026 at 03:26 UTC cf13e17817b28a8f8628e8f0f04899261fa0eaf8
4 files changed +172 -44
ts/packages/cli/src/commands/install.cmd.ts
+78 -43
@@ -31,7 +31,8 @@ type Shell = 'bash' | 'zsh' | 'fish';
31
32 interface ShellConfig {
33 readonly shell: Shell;
34 - readonly rcFile: string;
34 + readonly pathFile: string;
35 + readonly completionFile: string;
36 readonly pathBlock: string;
37 readonly completionBlock: string | undefined;
38 }
@@ -108,10 +109,15 @@ const buildShellConfig = (
109 shell: Shell,
110 rcFile: string,
111 installDir: string,
111 - completionScript: string | undefined
112 + completionScript: string | undefined,
113 + homedir: string
114 ): ShellConfig => ({
115 shell,
114 - rcFile,
116 + pathFile: rcFile,
117 + completionFile:
118 + shell === 'fish'
119 + ? path.join(homedir, '.config', 'fish', 'completions', 'composio.fish')
120 + : rcFile,
121 pathBlock: pathBlockForShell(shell, installDir),
122 completionBlock: completionScript ? `${COMPLETIONS_MARKER}\n${completionScript}` : undefined,
123 });
@@ -123,6 +129,18 @@ const fileContains = (contents: string, marker: string): boolean =>
129 const tildify = (p: string, homedir: string): string =>
130 p.startsWith(homedir + '/') ? `~/${p.slice(homedir.length + 1)}` : p;
131
132 +const readMaybeMissingFile = (
133 + filePath: string,
134 + fs: FileSystem.FileSystem
135 +): Effect.Effect<string, PlatformError> =>
136 + fs
137 + .readFileString(filePath)
138 + .pipe(
139 + Effect.catchAll(e =>
140 + Effect.logDebug('File does not exist yet, will create:', e).pipe(Effect.as(''))
141 + )
142 + );
143 +
144 // ---------------------------------------------------------------------------
145 // Exported logic (reusable from install.sh post-install delegation)
146 // ---------------------------------------------------------------------------
@@ -187,23 +205,27 @@ export const installShellIntegration = (params: {
205 }
206
207 const rcFile = yield* resolveRcFile(rcFileCandidates(shell, os.homedir), fs);
190 - const config = buildShellConfig(shell, rcFile, installDir, completionScript);
191 -
192 - // Read existing rc file (or empty if it doesn't exist yet)
193 - const rcPath = config.rcFile;
194 - const existing = yield* fs
195 - .readFileString(rcPath)
196 - .pipe(
197 - Effect.catchAll(e =>
198 - Effect.logDebug('RC file does not exist yet, will create:', e).pipe(Effect.as(''))
199 - )
200 - );
208 + const config = buildShellConfig(shell, rcFile, installDir, completionScript, os.homedir);
209
202 - // Build blocks to append (idempotently)
203 - const blocks: string[] = [];
210 + const uniqueTargetFiles = [...new Set([config.pathFile, config.completionFile])];
211 + const existingByFile = new Map<string, string>();
212 + for (const filePath of uniqueTargetFiles) {
213 + existingByFile.set(filePath, yield* readMaybeMissingFile(filePath, fs));
214 + }
215
205 - if (!fileContains(existing, MARKER)) {
206 - blocks.push(config.pathBlock);
216 + const blocksByFile = new Map<string, Array<string>>();
217 + const pushBlock = (filePath: string, block: string) => {
218 + const blocks = blocksByFile.get(filePath);
219 + if (blocks) {
220 + blocks.push(block);
221 + } else {
222 + blocksByFile.set(filePath, [block]);
223 + }
224 + };
225 +
226 + const existingPathFile = existingByFile.get(config.pathFile) ?? '';
227 + if (!fileContains(existingPathFile, MARKER)) {
228 + pushBlock(config.pathFile, config.pathBlock);
229 yield* ui.log.step(`PATH: will add ${tildify(installDir, os.homedir)} to $PATH`);
230 } else {
231 yield* ui.log.step('PATH: already configured');
@@ -213,42 +235,55 @@ export const installShellIntegration = (params: {
235 yield* ui.log.step('Completions: skipped for zsh');
236 } else if (!params.completions) {
237 yield* ui.log.step('Completions: skipped by default (pass --completions to enable)');
216 - } else if (config.completionBlock && !fileContains(existing, COMPLETIONS_MARKER)) {
217 - blocks.push(config.completionBlock);
218 - yield* ui.log.step('Completions: will install shell completions');
238 } else if (!config.completionBlock) {
239 yield* ui.log.step('Completions: not available for this shell');
240 } else {
222 - yield* ui.log.step('Completions: already configured');
241 + const existingCompletionFile = existingByFile.get(config.completionFile) ?? '';
242 + if (!fileContains(existingCompletionFile, COMPLETIONS_MARKER)) {
243 + pushBlock(config.completionFile, config.completionBlock);
244 + yield* ui.log.step(
245 + config.shell === 'fish'
246 + ? `Completions: will install fish completions to ${tildify(config.completionFile, os.homedir)}`
247 + : 'Completions: will install shell completions'
248 + );
249 + } else {
250 + yield* ui.log.step('Completions: already configured');
251 + }
252 }
253
225 - if (blocks.length > 0) {
226 - // Ensure parent directory exists (for fish config)
227 - yield* fs
228 - .makeDirectory(path.dirname(rcPath), { recursive: true })
229 - .pipe(
230 - Effect.catchAll(e =>
231 - Effect.logDebug('Could not create parent directory (may already exist):', e)
232 - )
233 - );
254 + if (blocksByFile.size > 0) {
255 + for (const [filePath, blocks] of blocksByFile.entries()) {
256 + const existingContents = existingByFile.get(filePath) ?? '';
257
235 - const appendContent = '\n' + blocks.join('\n\n') + '\n';
258 + yield* fs
259 + .makeDirectory(path.dirname(filePath), { recursive: true })
260 + .pipe(
261 + Effect.catchAll(e =>
262 + Effect.logDebug('Could not create parent directory (may already exist):', e)
263 + )
264 + );
265
237 - // Atomic write: write to a temp file then rename, so a crash mid-write
238 - // cannot leave the user's rc file truncated/corrupted.
239 - const tmpPath = `${rcPath}.composio-tmp`;
240 - yield* fs.writeFileString(tmpPath, existing + appendContent);
241 - yield* fs.rename(tmpPath, rcPath);
266 + const appendContent = '\n' + blocks.join('\n\n') + '\n';
267 + const tmpPath = `${filePath}.composio-tmp`;
268
243 - yield* ui.log.success(`Updated ${tildify(rcPath, os.homedir)}`);
269 + yield* fs.writeFileString(tmpPath, existingContents + appendContent);
270 + yield* fs.rename(tmpPath, filePath);
271 +
272 + yield* ui.log.success(`Updated ${tildify(filePath, os.homedir)}`);
273 + }
274 + } else {
275 + yield* ui.log.success('Shell integration already configured — nothing to do.');
276 + }
277 +
278 + if (blocksByFile.size > 0) {
279 yield* ui.note(
245 - shell === 'fish' || shell === 'zsh'
246 - ? `source ${tildify(rcPath, os.homedir)}`
247 - : 'exec $SHELL',
280 + shell === 'fish'
281 + ? 'exec fish'
282 + : shell === 'zsh'
283 + ? `source ${tildify(rcFile, os.homedir)}`
284 + : 'exec $SHELL',
285 'Restart your shell to apply changes'
286 );
250 - } else {
251 - yield* ui.log.success('Shell integration already configured — nothing to do.');
287 }
288
289 yield* ui.outro('Done');
ts/packages/cli/src/effects/shell-completions.ts
+25 -1
@@ -3,6 +3,24 @@ import { Effect } from 'effect';
3
4 type Shell = 'bash' | 'zsh' | 'fish';
5
6 +const sanitizeFishCompletionLine = (line: string): string => {
7 + if (!line.startsWith('complete ')) {
8 + return line;
9 + }
10 +
11 + const descriptionIndex = line.indexOf(' -d ');
12 + if (descriptionIndex === -1) {
13 + return line;
14 + }
15 +
16 + // Fish descriptions are optional. Dropping them avoids parse errors from
17 + // multiline or quote-heavy command descriptions emitted by the upstream generator.
18 + return line.slice(0, descriptionIndex).trimEnd();
19 +};
20 +
21 +const sanitizeFishCompletionLines = (lines: Array<string>): Array<string> =>
22 + lines.map(sanitizeFishCompletionLine);
23 +
24 /**
25 * Generate a shell completion script for the given command tree and shell type.
26 * Uses @effect/cli's built-in completion generators.
@@ -17,6 +35,12 @@ export const getCompletionScript = <Name extends string, R, E, A>(
35 case 'zsh':
36 return Command.getZshCompletions(command, 'composio');
37 case 'fish':
20 - return Command.getFishCompletions(command, 'composio');
38 + return Command.getFishCompletions(command, 'composio').pipe(
39 + Effect.map(sanitizeFishCompletionLines)
40 + );
41 }
42 };
43 +
44 +export const _test = {
45 + sanitizeFishCompletionLine,
46 +};
ts/packages/cli/test/src/commands/install.cmd.test.ts
+41
@@ -132,6 +132,47 @@ describe('CLI: composio install', () => {
132 });
133 });
134
135 + describe('[When] fish shell installs completions', () => {
136 + layer(TestLive())(it => {
137 + it.scoped(
138 + '[Then] keeps PATH setup in config.fish and writes completions to composio.fish',
139 + () =>
140 + Effect.gen(function* () {
141 + const os = yield* NodeOs;
142 + process.env.SHELL = '/usr/bin/fish';
143 + process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
144 +
145 + yield* cli(['install', '--completions']);
146 +
147 + const fs = yield* FileSystem.FileSystem;
148 + const configPath = path.join(os.homedir, '.config', 'fish', 'config.fish');
149 + const completionPath = path.join(
150 + os.homedir,
151 + '.config',
152 + 'fish',
153 + 'completions',
154 + 'composio.fish'
155 + );
156 + const configContents = yield* fs.readFileString(configPath);
157 + const completionContents = yield* fs.readFileString(completionPath);
158 +
159 + expect(configContents).toContain('# Composio CLI');
160 + expect(configContents).toContain('set --export COMPOSIO_INSTALL_DIR');
161 + expect(configContents).not.toContain('# Composio CLI completions');
162 +
163 + expect(completionContents).toContain('# Composio CLI completions');
164 +
165 + const lines = yield* MockConsole.getLines();
166 + const output = lines.join('\n');
167 + expect(output).toContain('Completions: will install fish completions to');
168 + expect(output).toContain('Updated ~/.config/fish/config.fish');
169 + expect(output).toContain('Updated ~/.config/fish/completions/composio.fish');
170 + expect(output).toContain('exec fish');
171 + })
172 + );
173 + });
174 + });
175 +
176 describe('[When] --no-completions is passed', () => {
177 layer(TestLive())(it => {
178 it.scoped('[Then] writes PATH block but skips completions', () =>
ts/packages/cli/test/src/effects/shell-completions.test.ts new
+28
@@ -0,0 +1,28 @@
1 +import { describe, expect, it } from 'vitest';
2 +import { _test } from 'src/effects/shell-completions';
3 +
4 +describe('shell-completions', () => {
5 + it('removes fish descriptions from completion commands', () => {
6 + const line =
7 + 'complete -c composio -n "__fish_seen_subcommand_from orgs; and __fish_seen_subcommand_from switch" -l limit -r -f -d \'Max orgs to fetch from API (default: 50)\'';
8 +
9 + expect(_test.sanitizeFishCompletionLine(line)).toBe(
10 + 'complete -c composio -n "__fish_seen_subcommand_from orgs; and __fish_seen_subcommand_from switch" -l limit -r -f'
11 + );
12 + });
13 +
14 + it('preserves non-complete fish lines unchanged', () => {
15 + const line = 'function __fish_composio_no_subcommand';
16 +
17 + expect(_test.sanitizeFishCompletionLine(line)).toBe(line);
18 + });
19 +
20 + it('drops multiline descriptions before they can break fish parsing', () => {
21 + const line = `complete -c composio -n "__fish_seen_subcommand_from dev" -l alias -r -f -d 'Line one
22 +line two with "quotes" and apostrophe'"'"'s'`;
23 +
24 + expect(_test.sanitizeFishCompletionLine(line)).toBe(
25 + 'complete -c composio -n "__fish_seen_subcommand_from dev" -l alias -r -f'
26 + );
27 + });
28 +});