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 22, 04:30 UTC
feat(cli): improve install.sh + shell integration
jkomyno committed
Mar 6, 2026 at 02:43 UTC
a181c00abce91ca531e8e362ed8303fbcae37514
5 files changed
+547
-77
install.sh
+104
-77
@@ -23,9 +23,9 @@ fi
23
24
error() { echo -e "${Red}error${Color_Off}:" "$@" >&2; exit 1; }
25
warn() { echo -e "${Red}warning${Color_Off}:" "$@" >&2; }
26
-info() { echo -e "${Dim}$@${Color_Off}"; }
27
-info_bold() { echo -e "${Bold_White}$@${Color_Off}"; }
28
-success() { echo -e "${Green}$@${Color_Off}"; }
26
+info() { echo -e "${Dim}$*${Color_Off}"; }
27
+info_bold() { echo -e "${Bold_White}$*${Color_Off}"; }
28
+success() { echo -e "${Green}$*${Color_Off}"; }
29
30
tildify() {
31
if [[ $1 = $HOME/* ]]; then
@@ -161,87 +161,114 @@ chmod +x "$exe" ||
161
162
success "Composio CLI was installed successfully to $Bold_Green$(tildify "$exe")"
163
164
-# --- Shell configuration ---
164
+# --- Shell integration (PATH + completions) ---
165
+
166
+# Delegate to the CLI's own install command, which handles:
167
+# - Idempotent PATH setup in the correct rc file
168
+# - Shell completions installation
169
+# If the binary can't run (e.g. missing runtime), fall back to inline setup.
170
171
echo
172
168
-refresh_command=''
169
-quoted_install_dir=\"${COMPOSIO_INSTALL_DIR//\"/\\\"}\"
173
+if COMPOSIO_INSTALL_DIR="$COMPOSIO_INSTALL_DIR" "$exe" install 2>/dev/null; then
174
+ : # CLI handled everything
175
+else
176
+ info "Setting up shell integration..."
177
171
-if [[ $quoted_install_dir = \"$HOME/* ]]; then
172
- quoted_install_dir=${COMPOSIO_INSTALL_DIR/$HOME\//\$HOME/}
173
-fi
178
+ refresh_command=''
179
+ quoted_install_dir=\"${COMPOSIO_INSTALL_DIR//\"/\\\"}\"
180
175
-case $(basename "$SHELL") in
176
-fish)
177
- commands=(
178
- "set --export COMPOSIO_INSTALL_DIR $COMPOSIO_INSTALL_DIR"
179
- "set --export PATH $COMPOSIO_INSTALL_DIR \$PATH"
180
- )
181
- fish_config=$HOME/.config/fish/config.fish
182
- if [[ -w $fish_config ]]; then
183
- { echo -e '\n# Composio CLI'; for cmd in "${commands[@]}"; do echo "$cmd"; done; } >>"$fish_config"
184
- info "Added \"$(tildify "$COMPOSIO_INSTALL_DIR")\" to \$PATH in \"$(tildify "$fish_config")\""
185
- refresh_command="source $(tildify "$fish_config")"
186
- else
187
- echo "Manually add the directory to $(tildify "$fish_config") (or similar):"
188
- for cmd in "${commands[@]}"; do info_bold " $cmd"; done
181
+ if [[ $quoted_install_dir = \"$HOME/* ]]; then
182
+ quoted_install_dir=${COMPOSIO_INSTALL_DIR/$HOME\//\$HOME/}
183
fi
190
- ;;
191
-zsh)
192
- commands=(
193
- "export COMPOSIO_INSTALL_DIR=$COMPOSIO_INSTALL_DIR"
194
- "export PATH=\"$COMPOSIO_INSTALL_DIR:\$PATH\""
195
- )
196
- zsh_config=$HOME/.zshrc
197
- if [[ ! -f $zsh_config && -w $(dirname "$zsh_config") ]]; then touch "$zsh_config"; fi
198
- if [[ -w $zsh_config ]]; then
199
- { echo -e '\n# Composio CLI'; for cmd in "${commands[@]}"; do echo "$cmd"; done; } >>"$zsh_config"
200
- info "Added \"$(tildify "$COMPOSIO_INSTALL_DIR")\" to \$PATH in \"$(tildify "$zsh_config")\""
201
- refresh_command="exec $SHELL"
202
- else
203
- echo "Manually add the directory to $(tildify "$zsh_config") (or similar):"
204
- for cmd in "${commands[@]}"; do info_bold " $cmd"; done
205
- fi
206
- ;;
207
-bash)
208
- commands=(
209
- "export COMPOSIO_INSTALL_DIR=$quoted_install_dir"
210
- "export PATH=\"\$COMPOSIO_INSTALL_DIR:\$PATH\""
211
- )
212
- bash_configs=("$HOME/.bashrc" "$HOME/.bash_profile")
213
- if [[ ${XDG_CONFIG_HOME:-} ]]; then
214
- bash_configs+=("$XDG_CONFIG_HOME/.bash_profile" "$XDG_CONFIG_HOME/.bashrc" "$XDG_CONFIG_HOME/bash_profile" "$XDG_CONFIG_HOME/bashrc")
215
- fi
216
- set_manually=true
217
- for bash_config in "${bash_configs[@]}"; do
218
- if [[ -w $bash_config ]]; then
219
- { echo -e '\n# Composio CLI'; for cmd in "${commands[@]}"; do echo "$cmd"; done; } >>"$bash_config"
220
- info "Added \"$(tildify "$COMPOSIO_INSTALL_DIR")\" to \$PATH in \"$(tildify "$bash_config")\""
221
- refresh_command="source $bash_config"
222
- set_manually=false
223
- break
184
+
185
+ shell_name=$(basename "${SHELL:-}")
186
+ marker='# Composio CLI'
187
+
188
+ case $shell_name in
189
+ fish)
190
+ commands=(
191
+ "set --export COMPOSIO_INSTALL_DIR $COMPOSIO_INSTALL_DIR"
192
+ "set --export PATH $COMPOSIO_INSTALL_DIR \$PATH"
193
+ )
194
+ fish_config=$HOME/.config/fish/config.fish
195
+ if [[ -w $fish_config ]] || [[ -w $(dirname "$fish_config") ]]; then
196
+ mkdir -p "$(dirname "$fish_config")"
197
+ if ! grep -qF "$marker" "$fish_config" 2>/dev/null; then
198
+ { echo -e "\n$marker"; for cmd in "${commands[@]}"; do echo "$cmd"; done; } >>"$fish_config"
199
+ info "Added \"$(tildify "$COMPOSIO_INSTALL_DIR")\" to \$PATH in \"$(tildify "$fish_config")\""
200
+ else
201
+ info "PATH already configured in \"$(tildify "$fish_config")\""
202
+ fi
203
+ refresh_command="source $(tildify "$fish_config")"
204
+ else
205
+ echo "Manually add the directory to $(tildify "$fish_config") (or similar):"
206
+ for cmd in "${commands[@]}"; do info_bold " $cmd"; done
207
fi
225
- done
226
- if [[ $set_manually = true ]]; then
227
- echo "Manually add the directory to ~/.bashrc (or similar):"
228
- for cmd in "${commands[@]}"; do info_bold " $cmd"; done
208
+ ;;
209
+ zsh)
210
+ commands=(
211
+ "export COMPOSIO_INSTALL_DIR=$COMPOSIO_INSTALL_DIR"
212
+ "export PATH=\"$COMPOSIO_INSTALL_DIR:\$PATH\""
213
+ )
214
+ zsh_config=$HOME/.zshrc
215
+ if [[ ! -f $zsh_config && -w $(dirname "$zsh_config") ]]; then touch "$zsh_config"; fi
216
+ if [[ -w $zsh_config ]]; then
217
+ if ! grep -qF "$marker" "$zsh_config" 2>/dev/null; then
218
+ { echo -e "\n$marker"; for cmd in "${commands[@]}"; do echo "$cmd"; done; } >>"$zsh_config"
219
+ info "Added \"$(tildify "$COMPOSIO_INSTALL_DIR")\" to \$PATH in \"$(tildify "$zsh_config")\""
220
+ else
221
+ info "PATH already configured in \"$(tildify "$zsh_config")\""
222
+ fi
223
+ refresh_command="exec $SHELL"
224
+ else
225
+ echo "Manually add the directory to $(tildify "$zsh_config") (or similar):"
226
+ for cmd in "${commands[@]}"; do info_bold " $cmd"; done
227
+ fi
228
+ ;;
229
+ bash)
230
+ commands=(
231
+ "export COMPOSIO_INSTALL_DIR=$quoted_install_dir"
232
+ "export PATH=\"\$COMPOSIO_INSTALL_DIR:\$PATH\""
233
+ )
234
+ bash_configs=("$HOME/.bashrc" "$HOME/.bash_profile")
235
+ if [[ ${XDG_CONFIG_HOME:-} ]]; then
236
+ bash_configs+=("$XDG_CONFIG_HOME/.bash_profile" "$XDG_CONFIG_HOME/.bashrc" "$XDG_CONFIG_HOME/bash_profile" "$XDG_CONFIG_HOME/bashrc")
237
+ fi
238
+ set_manually=true
239
+ for bash_config in "${bash_configs[@]}"; do
240
+ if [[ -w $bash_config ]]; then
241
+ if ! grep -qF "$marker" "$bash_config" 2>/dev/null; then
242
+ { echo -e "\n$marker"; for cmd in "${commands[@]}"; do echo "$cmd"; done; } >>"$bash_config"
243
+ info "Added \"$(tildify "$COMPOSIO_INSTALL_DIR")\" to \$PATH in \"$(tildify "$bash_config")\""
244
+ else
245
+ info "PATH already configured in \"$(tildify "$bash_config")\""
246
+ fi
247
+ refresh_command="source $bash_config"
248
+ set_manually=false
249
+ break
250
+ fi
251
+ done
252
+ if [[ $set_manually = true ]]; then
253
+ echo "Manually add the directory to ~/.bashrc (or similar):"
254
+ for cmd in "${commands[@]}"; do info_bold " $cmd"; done
255
+ fi
256
+ ;;
257
+ *)
258
+ echo 'Manually add the directory to ~/.bashrc (or similar):'
259
+ info_bold " export COMPOSIO_INSTALL_DIR=$quoted_install_dir"
260
+ info_bold " export PATH=\"\$COMPOSIO_INSTALL_DIR:\$PATH\""
261
+ ;;
262
+ esac
263
+
264
+ echo
265
+ info "To get started, run:"
266
+ echo
267
+
268
+ if [[ $refresh_command ]]; then
269
+ info_bold " $refresh_command"
270
fi
230
- ;;
231
-*)
232
- echo 'Manually add the directory to ~/.bashrc (or similar):'
233
- info_bold " export COMPOSIO_INSTALL_DIR=$quoted_install_dir"
234
- info_bold " export PATH=\"\$COMPOSIO_INSTALL_DIR:\$PATH\""
235
- ;;
236
-esac
271
238
-echo
239
-info "To get started, run:"
240
-echo
241
-
242
-if [[ $refresh_command ]]; then
243
- info_bold " $refresh_command"
272
+ info_bold " composio --help"
273
+ info_bold " composio login"
274
fi
245
-
246
-info_bold " composio --help"
247
-info_bold " composio login"
ts/packages/cli/src/commands/index.ts
+2
@@ -8,6 +8,7 @@ import { upgradeCmd } from './upgrade.cmd';
8
import { whoamiCmd } from './whoami.cmd';
9
import { loginCmd } from './login.cmd';
10
import { logoutCmd } from './logout.cmd';
11
+import { installCmd } from './install.cmd';
12
import { initCmd } from './init.cmd';
13
import { pyCmd } from './py/py.cmd';
14
import { tsCmd } from './ts/ts.cmd';
@@ -30,6 +31,7 @@ const $cmd = $defaultCmd.pipe(
31
whoamiCmd,
32
loginCmd,
33
logoutCmd,
34
+ installCmd,
35
initCmd,
36
generateCmd,
37
pyCmd,
ts/packages/cli/src/commands/install.cmd.ts
new
+206
@@ -0,0 +1,206 @@
1
+import path from 'node:path';
2
+import process from 'node:process';
3
+import { Command, Options } from '@effect/cli';
4
+import { FileSystem } from '@effect/platform';
5
+import type { PlatformError } from '@effect/platform/Error';
6
+import { Array as Arr, Effect } from 'effect';
7
+import { NodeOs } from 'src/services/node-os';
8
+import { TerminalUI } from 'src/services/terminal-ui';
9
+import { getCompletionScript } from 'src/effects/shell-completions';
10
+
11
+// ---------------------------------------------------------------------------
12
+// Options
13
+// ---------------------------------------------------------------------------
14
+
15
+const noCompletionsOpt = Options.boolean('no-completions').pipe(
16
+ Options.withDescription('Skip shell completions setup.'),
17
+ Options.withDefault(false)
18
+);
19
+
20
+// ---------------------------------------------------------------------------
21
+// Types
22
+// ---------------------------------------------------------------------------
23
+
24
+type Shell = 'bash' | 'zsh' | 'fish';
25
+
26
+interface ShellConfig {
27
+ readonly shell: Shell;
28
+ readonly rcFile: string;
29
+ readonly pathBlock: string;
30
+ readonly completionBlock: string | undefined;
31
+}
32
+
33
+// ---------------------------------------------------------------------------
34
+// Helpers
35
+// ---------------------------------------------------------------------------
36
+
37
+const MARKER = '# Composio CLI';
38
+const COMPLETIONS_MARKER = '# Composio CLI completions';
39
+
40
+const detectShell = (): Shell | undefined => {
41
+ const shellEnv = process.env.SHELL ?? '';
42
+ const base = path.basename(shellEnv);
43
+ if (base === 'zsh') return 'zsh';
44
+ if (base === 'bash') return 'bash';
45
+ if (base === 'fish') return 'fish';
46
+ return undefined;
47
+};
48
+
49
+const rcFileForShell = (shell: Shell, homedir: string): string => {
50
+ switch (shell) {
51
+ case 'zsh':
52
+ return path.join(homedir, '.zshrc');
53
+ case 'bash':
54
+ return path.join(homedir, '.bashrc');
55
+ case 'fish':
56
+ return path.join(homedir, '.config', 'fish', 'config.fish');
57
+ }
58
+};
59
+
60
+const pathBlockForShell = (shell: Shell, installDir: string): string => {
61
+ switch (shell) {
62
+ case 'fish':
63
+ return [
64
+ MARKER,
65
+ `set --export COMPOSIO_INSTALL_DIR ${installDir}`,
66
+ `set --export PATH $COMPOSIO_INSTALL_DIR $PATH`,
67
+ ].join('\n');
68
+ default:
69
+ return [
70
+ MARKER,
71
+ `export COMPOSIO_INSTALL_DIR=${installDir}`,
72
+ `export PATH="$COMPOSIO_INSTALL_DIR:$PATH"`,
73
+ ].join('\n');
74
+ }
75
+};
76
+
77
+const buildShellConfig = (
78
+ shell: Shell,
79
+ homedir: string,
80
+ installDir: string,
81
+ completionScript: string | undefined
82
+): ShellConfig => ({
83
+ shell,
84
+ rcFile: rcFileForShell(shell, homedir),
85
+ pathBlock: pathBlockForShell(shell, installDir),
86
+ completionBlock: completionScript ? `${COMPLETIONS_MARKER}\n${completionScript}` : undefined,
87
+});
88
+
89
+/** Check whether a file already contains a given marker line. */
90
+const fileContains = (contents: string, marker: string): boolean =>
91
+ contents.split('\n').some(line => line.trim() === marker.trim());
92
+
93
+const tildify = (p: string, homedir: string): string =>
94
+ p.startsWith(homedir + '/') ? `~/${p.slice(homedir.length + 1)}` : p;
95
+
96
+// ---------------------------------------------------------------------------
97
+// Exported logic (reusable from install.sh post-install delegation)
98
+// ---------------------------------------------------------------------------
99
+
100
+export const installShellIntegration = (params: {
101
+ readonly noCompletions: boolean;
102
+}): Effect.Effect<void, PlatformError, TerminalUI | NodeOs | FileSystem.FileSystem> =>
103
+ Effect.gen(function* () {
104
+ const ui = yield* TerminalUI;
105
+ const os = yield* NodeOs;
106
+ const fs = yield* FileSystem.FileSystem;
107
+
108
+ yield* ui.intro('composio install');
109
+
110
+ // Detect install directory — either from env or default ~/.composio
111
+ const installDir = process.env.COMPOSIO_INSTALL_DIR ?? path.join(os.homedir, '.composio');
112
+
113
+ // Detect user shell
114
+ const shell = detectShell();
115
+ if (!shell) {
116
+ yield* ui.log.warn(
117
+ 'Could not detect your shell. Manually add the following to your shell config:'
118
+ );
119
+ yield* ui.note(
120
+ `export COMPOSIO_INSTALL_DIR=${installDir}\nexport PATH="$COMPOSIO_INSTALL_DIR:$PATH"`,
121
+ 'PATH setup'
122
+ );
123
+ yield* ui.outro('Manual setup required.');
124
+ return;
125
+ }
126
+
127
+ yield* ui.log.step(`Detected shell: ${shell}`);
128
+
129
+ // Generate completions script if requested.
130
+ // Lazy-import the root command to avoid a circular dependency
131
+ // (index.ts → install.cmd.ts → index.ts).
132
+ let completionScript: string | undefined;
133
+ if (!params.noCompletions) {
134
+ const mod = yield* Effect.promise(() => import('src/commands'));
135
+ const lines = yield* getCompletionScript(mod.rootCommand, shell);
136
+ completionScript = lines.length > 0 ? Arr.join(lines, '\n') : undefined;
137
+ }
138
+
139
+ const config = buildShellConfig(shell, os.homedir, installDir, completionScript);
140
+
141
+ // Read existing rc file (or empty if it doesn't exist yet)
142
+ const rcPath = config.rcFile;
143
+ const existing = yield* fs
144
+ .readFileString(rcPath)
145
+ .pipe(Effect.catchAll(() => Effect.succeed('')));
146
+
147
+ // Build blocks to append (idempotently)
148
+ const blocks: string[] = [];
149
+
150
+ if (!fileContains(existing, MARKER)) {
151
+ blocks.push(config.pathBlock);
152
+ yield* ui.log.step(`PATH: will add ${tildify(installDir, os.homedir)} to $PATH`);
153
+ } else {
154
+ yield* ui.log.step('PATH: already configured');
155
+ }
156
+
157
+ if (config.completionBlock && !fileContains(existing, COMPLETIONS_MARKER)) {
158
+ blocks.push(config.completionBlock);
159
+ yield* ui.log.step('Completions: will install shell completions');
160
+ } else if (params.noCompletions) {
161
+ yield* ui.log.step('Completions: skipped (--no-completions)');
162
+ } else if (!config.completionBlock) {
163
+ yield* ui.log.step('Completions: not available for this shell');
164
+ } else {
165
+ yield* ui.log.step('Completions: already configured');
166
+ }
167
+
168
+ if (blocks.length > 0) {
169
+ // Ensure parent directory exists (for fish config)
170
+ yield* fs
171
+ .makeDirectory(path.dirname(rcPath), { recursive: true })
172
+ .pipe(Effect.catchAll(() => Effect.void));
173
+
174
+ const appendContent = '\n' + blocks.join('\n\n') + '\n';
175
+ yield* fs.writeFileString(rcPath, existing + appendContent);
176
+
177
+ yield* ui.log.success(`Updated ${tildify(rcPath, os.homedir)}`);
178
+ yield* ui.note(
179
+ shell === 'fish' ? `source ${tildify(rcPath, os.homedir)}` : 'exec $SHELL',
180
+ 'Restart your shell to apply changes'
181
+ );
182
+ } else {
183
+ yield* ui.log.success('Shell integration already configured — nothing to do.');
184
+ }
185
+
186
+ yield* ui.outro('Done');
187
+ });
188
+
189
+// ---------------------------------------------------------------------------
190
+// Command
191
+// ---------------------------------------------------------------------------
192
+
193
+/**
194
+ * CLI command to set up shell integration (PATH and completions).
195
+ *
196
+ * @example
197
+ * ```bash
198
+ * composio install
199
+ * composio install --no-completions
200
+ * ```
201
+ */
202
+export const installCmd = Command.make(
203
+ 'install',
204
+ { noCompletions: noCompletionsOpt },
205
+ ({ noCompletions }) => installShellIntegration({ noCompletions })
206
+).pipe(Command.withDescription('Set up shell integration (PATH and completions).'));
ts/packages/cli/src/effects/shell-completions.ts
new
+22
@@ -0,0 +1,22 @@
1
+import { Command } from '@effect/cli';
2
+import { Effect } from 'effect';
3
+
4
+type Shell = 'bash' | 'zsh' | 'fish';
5
+
6
+/**
7
+ * Generate a shell completion script for the given command tree and shell type.
8
+ * Uses @effect/cli's built-in completion generators.
9
+ */
10
+export const getCompletionScript = <Name extends string, R, E, A>(
11
+ command: Command.Command<Name, R, E, A>,
12
+ shell: Shell
13
+): Effect.Effect<Array<string>> => {
14
+ switch (shell) {
15
+ case 'bash':
16
+ return Command.getBashCompletions(command, 'composio');
17
+ case 'zsh':
18
+ return Command.getZshCompletions(command, 'composio');
19
+ case 'fish':
20
+ return Command.getFishCompletions(command, 'composio');
21
+ }
22
+};
ts/packages/cli/test/src/commands/install.cmd.test.ts
new
+213
@@ -0,0 +1,213 @@
1
+import path from 'node:path';
2
+import process from 'node:process';
3
+import { beforeEach, afterEach } from 'vitest';
4
+import { describe, expect, layer } from '@effect/vitest';
5
+import { Effect } from 'effect';
6
+import { FileSystem } from '@effect/platform';
7
+import { NodeOs } from 'src/services/node-os';
8
+import { cli, TestLive, MockConsole } from 'test/__utils__';
9
+
10
+describe('CLI: composio install', () => {
11
+ let savedShell: string | undefined;
12
+ let savedInstallDir: string | undefined;
13
+
14
+ beforeEach(() => {
15
+ savedShell = process.env.SHELL;
16
+ savedInstallDir = process.env.COMPOSIO_INSTALL_DIR;
17
+ });
18
+
19
+ afterEach(() => {
20
+ if (savedShell !== undefined) {
21
+ process.env.SHELL = savedShell;
22
+ } else {
23
+ delete process.env.SHELL;
24
+ }
25
+ if (savedInstallDir !== undefined) {
26
+ process.env.COMPOSIO_INSTALL_DIR = savedInstallDir;
27
+ } else {
28
+ delete process.env.COMPOSIO_INSTALL_DIR;
29
+ }
30
+ });
31
+
32
+ describe('[When] shell is zsh', () => {
33
+ layer(TestLive())(it => {
34
+ it.scoped('[Then] creates .zshrc with PATH and completions', () =>
35
+ Effect.gen(function* () {
36
+ const os = yield* NodeOs;
37
+ process.env.SHELL = '/bin/zsh';
38
+ process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
39
+
40
+ yield* cli(['install']);
41
+
42
+ const fs = yield* FileSystem.FileSystem;
43
+ const rcPath = path.join(os.homedir, '.zshrc');
44
+ const contents = yield* fs.readFileString(rcPath);
45
+
46
+ expect(contents).toContain('# Composio CLI');
47
+ expect(contents).toContain('export COMPOSIO_INSTALL_DIR=');
48
+ expect(contents).toContain('export PATH="$COMPOSIO_INSTALL_DIR:$PATH"');
49
+ expect(contents).toContain('# Composio CLI completions');
50
+
51
+ const lines = yield* MockConsole.getLines();
52
+ const output = lines.join('\n');
53
+ expect(output).toContain('Detected shell: zsh');
54
+ expect(output).toContain('PATH: will add');
55
+ expect(output).toContain('Completions: will install shell completions');
56
+ expect(output).toContain('Updated');
57
+ })
58
+ );
59
+ });
60
+ });
61
+
62
+ describe('[When] shell is bash', () => {
63
+ layer(TestLive())(it => {
64
+ it.scoped('[Then] creates .bashrc with PATH and completions', () =>
65
+ Effect.gen(function* () {
66
+ const os = yield* NodeOs;
67
+ process.env.SHELL = '/bin/bash';
68
+ process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
69
+
70
+ yield* cli(['install']);
71
+
72
+ const fs = yield* FileSystem.FileSystem;
73
+ const rcPath = path.join(os.homedir, '.bashrc');
74
+ const contents = yield* fs.readFileString(rcPath);
75
+
76
+ expect(contents).toContain('# Composio CLI');
77
+ expect(contents).toContain('export COMPOSIO_INSTALL_DIR=');
78
+ expect(contents).toContain('export PATH="$COMPOSIO_INSTALL_DIR:$PATH"');
79
+ expect(contents).toContain('# Composio CLI completions');
80
+ })
81
+ );
82
+ });
83
+ });
84
+
85
+ describe('[When] shell is fish', () => {
86
+ layer(TestLive())(it => {
87
+ it.scoped('[Then] creates config.fish with PATH and completions', () =>
88
+ Effect.gen(function* () {
89
+ const os = yield* NodeOs;
90
+ process.env.SHELL = '/usr/bin/fish';
91
+ process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
92
+
93
+ yield* cli(['install']);
94
+
95
+ const fs = yield* FileSystem.FileSystem;
96
+ const rcPath = path.join(os.homedir, '.config', 'fish', 'config.fish');
97
+ const contents = yield* fs.readFileString(rcPath);
98
+
99
+ expect(contents).toContain('# Composio CLI');
100
+ expect(contents).toContain('set --export COMPOSIO_INSTALL_DIR');
101
+ expect(contents).toContain('set --export PATH $COMPOSIO_INSTALL_DIR $PATH');
102
+ expect(contents).toContain('# Composio CLI completions');
103
+ })
104
+ );
105
+ });
106
+ });
107
+
108
+ describe('[When] --no-completions is passed', () => {
109
+ layer(TestLive())(it => {
110
+ it.scoped('[Then] writes PATH block but skips completions', () =>
111
+ Effect.gen(function* () {
112
+ const os = yield* NodeOs;
113
+ process.env.SHELL = '/bin/zsh';
114
+ process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
115
+
116
+ yield* cli(['install', '--no-completions']);
117
+
118
+ const fs = yield* FileSystem.FileSystem;
119
+ const rcPath = path.join(os.homedir, '.zshrc');
120
+ const contents = yield* fs.readFileString(rcPath);
121
+
122
+ expect(contents).toContain('# Composio CLI');
123
+ expect(contents).toContain('export COMPOSIO_INSTALL_DIR=');
124
+ expect(contents).not.toContain('# Composio CLI completions');
125
+
126
+ const lines = yield* MockConsole.getLines();
127
+ const output = lines.join('\n');
128
+ expect(output).toContain('Completions: skipped (--no-completions)');
129
+ })
130
+ );
131
+ });
132
+ });
133
+
134
+ describe('[When] install is run twice (idempotency)', () => {
135
+ layer(TestLive())(it => {
136
+ it.scoped('[Then] does not duplicate entries', () =>
137
+ Effect.gen(function* () {
138
+ const os = yield* NodeOs;
139
+ process.env.SHELL = '/bin/zsh';
140
+ process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
141
+
142
+ // Run install twice
143
+ yield* cli(['install']);
144
+ yield* cli(['install']);
145
+
146
+ const fs = yield* FileSystem.FileSystem;
147
+ const rcPath = path.join(os.homedir, '.zshrc');
148
+ const contents = yield* fs.readFileString(rcPath);
149
+
150
+ // Count occurrences of each marker — should be exactly 1
151
+ // Use regex with word boundary to avoid "# Composio CLI completions" matching "# Composio CLI"
152
+ const pathMarkerCount = contents.match(/^# Composio CLI$/gm)?.length ?? 0;
153
+ expect(pathMarkerCount).toBe(1);
154
+
155
+ const completionsCount = contents.match(/^# Composio CLI completions$/gm)?.length ?? 0;
156
+ expect(completionsCount).toBe(1);
157
+ })
158
+ );
159
+ });
160
+ });
161
+
162
+ describe('[When] .zshrc already has the marker', () => {
163
+ layer(TestLive())(it => {
164
+ it.scoped('[Then] reports already configured', () =>
165
+ Effect.gen(function* () {
166
+ const os = yield* NodeOs;
167
+ const fs = yield* FileSystem.FileSystem;
168
+ process.env.SHELL = '/bin/zsh';
169
+ process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
170
+
171
+ // Pre-populate .zshrc with existing config
172
+ const rcPath = path.join(os.homedir, '.zshrc');
173
+ yield* fs.writeFileString(
174
+ rcPath,
175
+ '# existing config\n# Composio CLI\nexport COMPOSIO_INSTALL_DIR=/old\n# Composio CLI completions\n_composio() {}\n'
176
+ );
177
+
178
+ yield* cli(['install']);
179
+
180
+ const lines = yield* MockConsole.getLines();
181
+ const output = lines.join('\n');
182
+ expect(output).toContain('PATH: already configured');
183
+ expect(output).toContain('Completions: already configured');
184
+ expect(output).toContain('Shell integration already configured');
185
+
186
+ // File should not have grown
187
+ const contents = yield* fs.readFileString(rcPath);
188
+ const markerCount = contents.split('# Composio CLI').length - 1;
189
+ // "# Composio CLI" appears in both the PATH block marker and the completions marker
190
+ expect(markerCount).toBe(2);
191
+ })
192
+ );
193
+ });
194
+ });
195
+
196
+ describe('[When] shell cannot be detected', () => {
197
+ layer(TestLive())(it => {
198
+ it.scoped('[Then] shows manual setup instructions', () =>
199
+ Effect.gen(function* () {
200
+ process.env.SHELL = '';
201
+
202
+ yield* cli(['install']);
203
+
204
+ const lines = yield* MockConsole.getLines();
205
+ const output = lines.join('\n');
206
+ expect(output).toContain('Could not detect your shell');
207
+ expect(output).toContain('export COMPOSIO_INSTALL_DIR=');
208
+ expect(output).toContain('Manual setup required.');
209
+ })
210
+ );
211
+ });
212
+ });
213
+});