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.

feat(cli): improve install.sh + shell integration

jkomynoa181c00abce9
diff --git a/install.sh b/install.sh
index fbe46a8da..696e80eae 100755
--- a/install.sh
+++ b/install.sh
@@ -23,9 +23,9 @@ fi
error() { echo -e "${Red}error${Color_Off}:" "$@" >&2; exit 1; }
warn() { echo -e "${Red}warning${Color_Off}:" "$@" >&2; }
-info() { echo -e "${Dim}$@${Color_Off}"; }
-info_bold() { echo -e "${Bold_White}$@${Color_Off}"; }
-success() { echo -e "${Green}$@${Color_Off}"; }
+info() { echo -e "${Dim}$*${Color_Off}"; }
+info_bold() { echo -e "${Bold_White}$*${Color_Off}"; }
+success() { echo -e "${Green}$*${Color_Off}"; }
tildify() {
if [[ $1 = $HOME/* ]]; then
@@ -161,87 +161,114 @@ chmod +x "$exe" ||
success "Composio CLI was installed successfully to $Bold_Green$(tildify "$exe")"
-# --- Shell configuration ---
+# --- Shell integration (PATH + completions) ---
+
+# Delegate to the CLI's own install command, which handles:
+# - Idempotent PATH setup in the correct rc file
+# - Shell completions installation
+# If the binary can't run (e.g. missing runtime), fall back to inline setup.
echo
-refresh_command=''
-quoted_install_dir=\"${COMPOSIO_INSTALL_DIR//\"/\\\"}\"
+if COMPOSIO_INSTALL_DIR="$COMPOSIO_INSTALL_DIR" "$exe" install 2>/dev/null; then
+ : # CLI handled everything
+else
+ info "Setting up shell integration..."
-if [[ $quoted_install_dir = \"$HOME/* ]]; then
- quoted_install_dir=${COMPOSIO_INSTALL_DIR/$HOME\//\$HOME/}
-fi
+ refresh_command=''
+ quoted_install_dir=\"${COMPOSIO_INSTALL_DIR//\"/\\\"}\"
-case $(basename "$SHELL") in
-fish)
- commands=(
- "set --export COMPOSIO_INSTALL_DIR $COMPOSIO_INSTALL_DIR"
- "set --export PATH $COMPOSIO_INSTALL_DIR \$PATH"
- )
- fish_config=$HOME/.config/fish/config.fish
- if [[ -w $fish_config ]]; then
- { echo -e '\n# Composio CLI'; for cmd in "${commands[@]}"; do echo "$cmd"; done; } >>"$fish_config"
- info "Added \"$(tildify "$COMPOSIO_INSTALL_DIR")\" to \$PATH in \"$(tildify "$fish_config")\""
- refresh_command="source $(tildify "$fish_config")"
- else
- echo "Manually add the directory to $(tildify "$fish_config") (or similar):"
- for cmd in "${commands[@]}"; do info_bold " $cmd"; done
+ if [[ $quoted_install_dir = \"$HOME/* ]]; then
+ quoted_install_dir=${COMPOSIO_INSTALL_DIR/$HOME\//\$HOME/}
fi
- ;;
-zsh)
- commands=(
- "export COMPOSIO_INSTALL_DIR=$COMPOSIO_INSTALL_DIR"
- "export PATH=\"$COMPOSIO_INSTALL_DIR:\$PATH\""
- )
- zsh_config=$HOME/.zshrc
- if [[ ! -f $zsh_config && -w $(dirname "$zsh_config") ]]; then touch "$zsh_config"; fi
- if [[ -w $zsh_config ]]; then
- { echo -e '\n# Composio CLI'; for cmd in "${commands[@]}"; do echo "$cmd"; done; } >>"$zsh_config"
- info "Added \"$(tildify "$COMPOSIO_INSTALL_DIR")\" to \$PATH in \"$(tildify "$zsh_config")\""
- refresh_command="exec $SHELL"
- else
- echo "Manually add the directory to $(tildify "$zsh_config") (or similar):"
- for cmd in "${commands[@]}"; do info_bold " $cmd"; done
- fi
- ;;
-bash)
- commands=(
- "export COMPOSIO_INSTALL_DIR=$quoted_install_dir"
- "export PATH=\"\$COMPOSIO_INSTALL_DIR:\$PATH\""
- )
- bash_configs=("$HOME/.bashrc" "$HOME/.bash_profile")
- if [[ ${XDG_CONFIG_HOME:-} ]]; then
- bash_configs+=("$XDG_CONFIG_HOME/.bash_profile" "$XDG_CONFIG_HOME/.bashrc" "$XDG_CONFIG_HOME/bash_profile" "$XDG_CONFIG_HOME/bashrc")
- fi
- set_manually=true
- for bash_config in "${bash_configs[@]}"; do
- if [[ -w $bash_config ]]; then
- { echo -e '\n# Composio CLI'; for cmd in "${commands[@]}"; do echo "$cmd"; done; } >>"$bash_config"
- info "Added \"$(tildify "$COMPOSIO_INSTALL_DIR")\" to \$PATH in \"$(tildify "$bash_config")\""
- refresh_command="source $bash_config"
- set_manually=false
- break
+
+ shell_name=$(basename "${SHELL:-}")
+ marker='# Composio CLI'
+
+ case $shell_name in
+ fish)
+ commands=(
+ "set --export COMPOSIO_INSTALL_DIR $COMPOSIO_INSTALL_DIR"
+ "set --export PATH $COMPOSIO_INSTALL_DIR \$PATH"
+ )
+ fish_config=$HOME/.config/fish/config.fish
+ if [[ -w $fish_config ]] || [[ -w $(dirname "$fish_config") ]]; then
+ mkdir -p "$(dirname "$fish_config")"
+ if ! grep -qF "$marker" "$fish_config" 2>/dev/null; then
+ { echo -e "\n$marker"; for cmd in "${commands[@]}"; do echo "$cmd"; done; } >>"$fish_config"
+ info "Added \"$(tildify "$COMPOSIO_INSTALL_DIR")\" to \$PATH in \"$(tildify "$fish_config")\""
+ else
+ info "PATH already configured in \"$(tildify "$fish_config")\""
+ fi
+ refresh_command="source $(tildify "$fish_config")"
+ else
+ echo "Manually add the directory to $(tildify "$fish_config") (or similar):"
+ for cmd in "${commands[@]}"; do info_bold " $cmd"; done
fi
- done
- if [[ $set_manually = true ]]; then
- echo "Manually add the directory to ~/.bashrc (or similar):"
- for cmd in "${commands[@]}"; do info_bold " $cmd"; done
+ ;;
+ zsh)
+ commands=(
+ "export COMPOSIO_INSTALL_DIR=$COMPOSIO_INSTALL_DIR"
+ "export PATH=\"$COMPOSIO_INSTALL_DIR:\$PATH\""
+ )
+ zsh_config=$HOME/.zshrc
+ if [[ ! -f $zsh_config && -w $(dirname "$zsh_config") ]]; then touch "$zsh_config"; fi
+ if [[ -w $zsh_config ]]; then
+ if ! grep -qF "$marker" "$zsh_config" 2>/dev/null; then
+ { echo -e "\n$marker"; for cmd in "${commands[@]}"; do echo "$cmd"; done; } >>"$zsh_config"
+ info "Added \"$(tildify "$COMPOSIO_INSTALL_DIR")\" to \$PATH in \"$(tildify "$zsh_config")\""
+ else
+ info "PATH already configured in \"$(tildify "$zsh_config")\""
+ fi
+ refresh_command="exec $SHELL"
+ else
+ echo "Manually add the directory to $(tildify "$zsh_config") (or similar):"
+ for cmd in "${commands[@]}"; do info_bold " $cmd"; done
+ fi
+ ;;
+ bash)
+ commands=(
+ "export COMPOSIO_INSTALL_DIR=$quoted_install_dir"
+ "export PATH=\"\$COMPOSIO_INSTALL_DIR:\$PATH\""
+ )
+ bash_configs=("$HOME/.bashrc" "$HOME/.bash_profile")
+ if [[ ${XDG_CONFIG_HOME:-} ]]; then
+ bash_configs+=("$XDG_CONFIG_HOME/.bash_profile" "$XDG_CONFIG_HOME/.bashrc" "$XDG_CONFIG_HOME/bash_profile" "$XDG_CONFIG_HOME/bashrc")
+ fi
+ set_manually=true
+ for bash_config in "${bash_configs[@]}"; do
+ if [[ -w $bash_config ]]; then
+ if ! grep -qF "$marker" "$bash_config" 2>/dev/null; then
+ { echo -e "\n$marker"; for cmd in "${commands[@]}"; do echo "$cmd"; done; } >>"$bash_config"
+ info "Added \"$(tildify "$COMPOSIO_INSTALL_DIR")\" to \$PATH in \"$(tildify "$bash_config")\""
+ else
+ info "PATH already configured in \"$(tildify "$bash_config")\""
+ fi
+ refresh_command="source $bash_config"
+ set_manually=false
+ break
+ fi
+ done
+ if [[ $set_manually = true ]]; then
+ echo "Manually add the directory to ~/.bashrc (or similar):"
+ for cmd in "${commands[@]}"; do info_bold " $cmd"; done
+ fi
+ ;;
+ *)
+ echo 'Manually add the directory to ~/.bashrc (or similar):'
+ info_bold " export COMPOSIO_INSTALL_DIR=$quoted_install_dir"
+ info_bold " export PATH=\"\$COMPOSIO_INSTALL_DIR:\$PATH\""
+ ;;
+ esac
+
+ echo
+ info "To get started, run:"
+ echo
+
+ if [[ $refresh_command ]]; then
+ info_bold " $refresh_command"
fi
- ;;
-*)
- echo 'Manually add the directory to ~/.bashrc (or similar):'
- info_bold " export COMPOSIO_INSTALL_DIR=$quoted_install_dir"
- info_bold " export PATH=\"\$COMPOSIO_INSTALL_DIR:\$PATH\""
- ;;
-esac
-echo
-info "To get started, run:"
-echo
-
-if [[ $refresh_command ]]; then
- info_bold " $refresh_command"
+ info_bold " composio --help"
+ info_bold " composio login"
fi
-
-info_bold " composio --help"
-info_bold " composio login"
diff --git a/ts/packages/cli/src/commands/index.ts b/ts/packages/cli/src/commands/index.ts
index 99b3e6926..a69c0db6f 100644
--- a/ts/packages/cli/src/commands/index.ts
+++ b/ts/packages/cli/src/commands/index.ts
@@ -8,6 +8,7 @@ import { upgradeCmd } from './upgrade.cmd';
import { whoamiCmd } from './whoami.cmd';
import { loginCmd } from './login.cmd';
import { logoutCmd } from './logout.cmd';
+import { installCmd } from './install.cmd';
import { initCmd } from './init.cmd';
import { pyCmd } from './py/py.cmd';
import { tsCmd } from './ts/ts.cmd';
@@ -30,6 +31,7 @@ const $cmd = $defaultCmd.pipe(
whoamiCmd,
loginCmd,
logoutCmd,
+ installCmd,
initCmd,
generateCmd,
pyCmd,
diff --git a/ts/packages/cli/src/commands/install.cmd.ts b/ts/packages/cli/src/commands/install.cmd.ts
new file mode 100644
index 000000000..e7b504e8b
--- /dev/null
+++ b/ts/packages/cli/src/commands/install.cmd.ts
@@ -0,0 +1,206 @@
+import path from 'node:path';
+import process from 'node:process';
+import { Command, Options } from '@effect/cli';
+import { FileSystem } from '@effect/platform';
+import type { PlatformError } from '@effect/platform/Error';
+import { Array as Arr, Effect } from 'effect';
+import { NodeOs } from 'src/services/node-os';
+import { TerminalUI } from 'src/services/terminal-ui';
+import { getCompletionScript } from 'src/effects/shell-completions';
+
+// ---------------------------------------------------------------------------
+// Options
+// ---------------------------------------------------------------------------
+
+const noCompletionsOpt = Options.boolean('no-completions').pipe(
+ Options.withDescription('Skip shell completions setup.'),
+ Options.withDefault(false)
+);
+
+// ---------------------------------------------------------------------------
+// Types
+// ---------------------------------------------------------------------------
+
+type Shell = 'bash' | 'zsh' | 'fish';
+
+interface ShellConfig {
+ readonly shell: Shell;
+ readonly rcFile: string;
+ readonly pathBlock: string;
+ readonly completionBlock: string | undefined;
+}
+
+// ---------------------------------------------------------------------------
+// Helpers
+// ---------------------------------------------------------------------------
+
+const MARKER = '# Composio CLI';
+const COMPLETIONS_MARKER = '# Composio CLI completions';
+
+const detectShell = (): Shell | undefined => {
+ const shellEnv = process.env.SHELL ?? '';
+ const base = path.basename(shellEnv);
+ if (base === 'zsh') return 'zsh';
+ if (base === 'bash') return 'bash';
+ if (base === 'fish') return 'fish';
+ return undefined;
+};
+
+const rcFileForShell = (shell: Shell, homedir: string): string => {
+ switch (shell) {
+ case 'zsh':
+ return path.join(homedir, '.zshrc');
+ case 'bash':
+ return path.join(homedir, '.bashrc');
+ case 'fish':
+ return path.join(homedir, '.config', 'fish', 'config.fish');
+ }
+};
+
+const pathBlockForShell = (shell: Shell, installDir: string): string => {
+ switch (shell) {
+ case 'fish':
+ return [
+ MARKER,
+ `set --export COMPOSIO_INSTALL_DIR ${installDir}`,
+ `set --export PATH $COMPOSIO_INSTALL_DIR $PATH`,
+ ].join('\n');
+ default:
+ return [
+ MARKER,
+ `export COMPOSIO_INSTALL_DIR=${installDir}`,
+ `export PATH="$COMPOSIO_INSTALL_DIR:$PATH"`,
+ ].join('\n');
+ }
+};
+
+const buildShellConfig = (
+ shell: Shell,
+ homedir: string,
+ installDir: string,
+ completionScript: string | undefined
+): ShellConfig => ({
+ shell,
+ rcFile: rcFileForShell(shell, homedir),
+ pathBlock: pathBlockForShell(shell, installDir),
+ completionBlock: completionScript ? `${COMPLETIONS_MARKER}\n${completionScript}` : undefined,
+});
+
+/** Check whether a file already contains a given marker line. */
+const fileContains = (contents: string, marker: string): boolean =>
+ contents.split('\n').some(line => line.trim() === marker.trim());
+
+const tildify = (p: string, homedir: string): string =>
+ p.startsWith(homedir + '/') ? `~/${p.slice(homedir.length + 1)}` : p;
+
+// ---------------------------------------------------------------------------
+// Exported logic (reusable from install.sh post-install delegation)
+// ---------------------------------------------------------------------------
+
+export const installShellIntegration = (params: {
+ readonly noCompletions: boolean;
+}): Effect.Effect<void, PlatformError, TerminalUI | NodeOs | FileSystem.FileSystem> =>
+ Effect.gen(function* () {
+ const ui = yield* TerminalUI;
+ const os = yield* NodeOs;
+ const fs = yield* FileSystem.FileSystem;
+
+ yield* ui.intro('composio install');
+
+ // Detect install directory — either from env or default ~/.composio
+ const installDir = process.env.COMPOSIO_INSTALL_DIR ?? path.join(os.homedir, '.composio');
+
+ // Detect user shell
+ const shell = detectShell();
+ if (!shell) {
+ yield* ui.log.warn(
+ 'Could not detect your shell. Manually add the following to your shell config:'
+ );
+ yield* ui.note(
+ `export COMPOSIO_INSTALL_DIR=${installDir}\nexport PATH="$COMPOSIO_INSTALL_DIR:$PATH"`,
+ 'PATH setup'
+ );
+ yield* ui.outro('Manual setup required.');
+ return;
+ }
+
+ yield* ui.log.step(`Detected shell: ${shell}`);
+
+ // Generate completions script if requested.
+ // Lazy-import the root command to avoid a circular dependency
+ // (index.ts → install.cmd.ts → index.ts).
+ let completionScript: string | undefined;
+ if (!params.noCompletions) {
+ const mod = yield* Effect.promise(() => import('src/commands'));
+ const lines = yield* getCompletionScript(mod.rootCommand, shell);
+ completionScript = lines.length > 0 ? Arr.join(lines, '\n') : undefined;
+ }
+
+ const config = buildShellConfig(shell, os.homedir, installDir, completionScript);
+
+ // Read existing rc file (or empty if it doesn't exist yet)
+ const rcPath = config.rcFile;
+ const existing = yield* fs
+ .readFileString(rcPath)
+ .pipe(Effect.catchAll(() => Effect.succeed('')));
+
+ // Build blocks to append (idempotently)
+ const blocks: string[] = [];
+
+ if (!fileContains(existing, MARKER)) {
+ blocks.push(config.pathBlock);
+ yield* ui.log.step(`PATH: will add ${tildify(installDir, os.homedir)} to $PATH`);
+ } else {
+ yield* ui.log.step('PATH: already configured');
+ }
+
+ if (config.completionBlock && !fileContains(existing, COMPLETIONS_MARKER)) {
+ blocks.push(config.completionBlock);
+ yield* ui.log.step('Completions: will install shell completions');
+ } else if (params.noCompletions) {
+ yield* ui.log.step('Completions: skipped (--no-completions)');
+ } else if (!config.completionBlock) {
+ yield* ui.log.step('Completions: not available for this shell');
+ } else {
+ yield* ui.log.step('Completions: already configured');
+ }
+
+ if (blocks.length > 0) {
+ // Ensure parent directory exists (for fish config)
+ yield* fs
+ .makeDirectory(path.dirname(rcPath), { recursive: true })
+ .pipe(Effect.catchAll(() => Effect.void));
+
+ const appendContent = '\n' + blocks.join('\n\n') + '\n';
+ yield* fs.writeFileString(rcPath, existing + appendContent);
+
+ yield* ui.log.success(`Updated ${tildify(rcPath, os.homedir)}`);
+ yield* ui.note(
+ shell === 'fish' ? `source ${tildify(rcPath, os.homedir)}` : 'exec $SHELL',
+ 'Restart your shell to apply changes'
+ );
+ } else {
+ yield* ui.log.success('Shell integration already configured — nothing to do.');
+ }
+
+ yield* ui.outro('Done');
+ });
+
+// ---------------------------------------------------------------------------
+// Command
+// ---------------------------------------------------------------------------
+
+/**
+ * CLI command to set up shell integration (PATH and completions).
+ *
+ * @example
+ * ```bash
+ * composio install
+ * composio install --no-completions
+ * ```
+ */
+export const installCmd = Command.make(
+ 'install',
+ { noCompletions: noCompletionsOpt },
+ ({ noCompletions }) => installShellIntegration({ noCompletions })
+).pipe(Command.withDescription('Set up shell integration (PATH and completions).'));
diff --git a/ts/packages/cli/src/effects/shell-completions.ts b/ts/packages/cli/src/effects/shell-completions.ts
new file mode 100644
index 000000000..67697fa5c
--- /dev/null
+++ b/ts/packages/cli/src/effects/shell-completions.ts
@@ -0,0 +1,22 @@
+import { Command } from '@effect/cli';
+import { Effect } from 'effect';
+
+type Shell = 'bash' | 'zsh' | 'fish';
+
+/**
+ * Generate a shell completion script for the given command tree and shell type.
+ * Uses @effect/cli's built-in completion generators.
+ */
+export const getCompletionScript = <Name extends string, R, E, A>(
+ command: Command.Command<Name, R, E, A>,
+ shell: Shell
+): Effect.Effect<Array<string>> => {
+ switch (shell) {
+ case 'bash':
+ return Command.getBashCompletions(command, 'composio');
+ case 'zsh':
+ return Command.getZshCompletions(command, 'composio');
+ case 'fish':
+ return Command.getFishCompletions(command, 'composio');
+ }
+};
diff --git a/ts/packages/cli/test/src/commands/install.cmd.test.ts b/ts/packages/cli/test/src/commands/install.cmd.test.ts
new file mode 100644
index 000000000..d67b95cd4
--- /dev/null
+++ b/ts/packages/cli/test/src/commands/install.cmd.test.ts
@@ -0,0 +1,213 @@
+import path from 'node:path';
+import process from 'node:process';
+import { beforeEach, afterEach } from 'vitest';
+import { describe, expect, layer } from '@effect/vitest';
+import { Effect } from 'effect';
+import { FileSystem } from '@effect/platform';
+import { NodeOs } from 'src/services/node-os';
+import { cli, TestLive, MockConsole } from 'test/__utils__';
+
+describe('CLI: composio install', () => {
+ let savedShell: string | undefined;
+ let savedInstallDir: string | undefined;
+
+ beforeEach(() => {
+ savedShell = process.env.SHELL;
+ savedInstallDir = process.env.COMPOSIO_INSTALL_DIR;
+ });
+
+ afterEach(() => {
+ if (savedShell !== undefined) {
+ process.env.SHELL = savedShell;
+ } else {
+ delete process.env.SHELL;
+ }
+ if (savedInstallDir !== undefined) {
+ process.env.COMPOSIO_INSTALL_DIR = savedInstallDir;
+ } else {
+ delete process.env.COMPOSIO_INSTALL_DIR;
+ }
+ });
+
+ describe('[When] shell is zsh', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] creates .zshrc with PATH and completions', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ process.env.SHELL = '/bin/zsh';
+ process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
+
+ yield* cli(['install']);
+
+ const fs = yield* FileSystem.FileSystem;
+ const rcPath = path.join(os.homedir, '.zshrc');
+ const contents = yield* fs.readFileString(rcPath);
+
+ expect(contents).toContain('# Composio CLI');
+ expect(contents).toContain('export COMPOSIO_INSTALL_DIR=');
+ expect(contents).toContain('export PATH="$COMPOSIO_INSTALL_DIR:$PATH"');
+ expect(contents).toContain('# Composio CLI completions');
+
+ const lines = yield* MockConsole.getLines();
+ const output = lines.join('\n');
+ expect(output).toContain('Detected shell: zsh');
+ expect(output).toContain('PATH: will add');
+ expect(output).toContain('Completions: will install shell completions');
+ expect(output).toContain('Updated');
+ })
+ );
+ });
+ });
+
+ describe('[When] shell is bash', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] creates .bashrc with PATH and completions', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ process.env.SHELL = '/bin/bash';
+ process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
+
+ yield* cli(['install']);
+
+ const fs = yield* FileSystem.FileSystem;
+ const rcPath = path.join(os.homedir, '.bashrc');
+ const contents = yield* fs.readFileString(rcPath);
+
+ expect(contents).toContain('# Composio CLI');
+ expect(contents).toContain('export COMPOSIO_INSTALL_DIR=');
+ expect(contents).toContain('export PATH="$COMPOSIO_INSTALL_DIR:$PATH"');
+ expect(contents).toContain('# Composio CLI completions');
+ })
+ );
+ });
+ });
+
+ describe('[When] shell is fish', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] creates config.fish with PATH and completions', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ process.env.SHELL = '/usr/bin/fish';
+ process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
+
+ yield* cli(['install']);
+
+ const fs = yield* FileSystem.FileSystem;
+ const rcPath = path.join(os.homedir, '.config', 'fish', 'config.fish');
+ const contents = yield* fs.readFileString(rcPath);
+
+ expect(contents).toContain('# Composio CLI');
+ expect(contents).toContain('set --export COMPOSIO_INSTALL_DIR');
+ expect(contents).toContain('set --export PATH $COMPOSIO_INSTALL_DIR $PATH');
+ expect(contents).toContain('# Composio CLI completions');
+ })
+ );
+ });
+ });
+
+ describe('[When] --no-completions is passed', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] writes PATH block but skips completions', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ process.env.SHELL = '/bin/zsh';
+ process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
+
+ yield* cli(['install', '--no-completions']);
+
+ const fs = yield* FileSystem.FileSystem;
+ const rcPath = path.join(os.homedir, '.zshrc');
+ const contents = yield* fs.readFileString(rcPath);
+
+ expect(contents).toContain('# Composio CLI');
+ expect(contents).toContain('export COMPOSIO_INSTALL_DIR=');
+ expect(contents).not.toContain('# Composio CLI completions');
+
+ const lines = yield* MockConsole.getLines();
+ const output = lines.join('\n');
+ expect(output).toContain('Completions: skipped (--no-completions)');
+ })
+ );
+ });
+ });
+
+ describe('[When] install is run twice (idempotency)', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] does not duplicate entries', () =>
+ Effect.gen(function* () {
+ const os = yield* NodeOs;
+ process.env.SHELL = '/bin/zsh';
+ process.env.COMPOSIO_INSTALL_DIR = path.join(os.homedir, '.composio');
+
+ // Run install twice
+ yield* cli(['install']);
+ yield* cli(['install']);
+
+ const fs = yield* FileSystem.FileSystem;
+ const rcPath = path.join(os.homedir, '.zshrc');
+ const contents = yield* fs.readFileString(rcPath);
+
+ // Count occurrences of each marker — should be exactly 1
+ // Use regex with word boundary to avoid "# Composio CLI completions" matching "# Composio CLI"
+ const pathMarkerCount = contents.match(/^# Composio CLI$/gm)?.length ?? 0;
+ expect(pathMarkerCount).toBe(1);
+
+ const completionsCount = contents.match(/^# Composio CLI completions$/gm)?.length ?? 0;
+ expect(completionsCount).toBe(1);
+ })
+ );
+ });
+ });
+
+ describe('[When] .zshrc already has the marker', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] reports already configured', () =>
+ 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');
+
+ // Pre-populate .zshrc with existing config
+ const rcPath = path.join(os.homedir, '.zshrc');
+ yield* fs.writeFileString(
+ rcPath,
+ '# existing config\n# Composio CLI\nexport COMPOSIO_INSTALL_DIR=/old\n# Composio CLI completions\n_composio() {}\n'
+ );
+
+ yield* cli(['install']);
+
+ const lines = yield* MockConsole.getLines();
+ const output = lines.join('\n');
+ expect(output).toContain('PATH: already configured');
+ expect(output).toContain('Completions: already configured');
+ expect(output).toContain('Shell integration already configured');
+
+ // File should not have grown
+ const contents = yield* fs.readFileString(rcPath);
+ const markerCount = contents.split('# Composio CLI').length - 1;
+ // "# Composio CLI" appears in both the PATH block marker and the completions marker
+ expect(markerCount).toBe(2);
+ })
+ );
+ });
+ });
+
+ describe('[When] shell cannot be detected', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] shows manual setup instructions', () =>
+ Effect.gen(function* () {
+ process.env.SHELL = '';
+
+ yield* cli(['install']);
+
+ const lines = yield* MockConsole.getLines();
+ const output = lines.join('\n');
+ expect(output).toContain('Could not detect your shell');
+ expect(output).toContain('export COMPOSIO_INSTALL_DIR=');
+ expect(output).toContain('Manual setup required.');
+ })
+ );
+ });
+ });
+});