@devries-cameron20 / composio Mirror · read-only / commits / 648e95727
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, 17:15 UTC

fix(cli): exit non-zero when shell setup aborts

Both abort branches (unsafe or relative resolved bin dir) printed an error and returned, so the effect succeeded and the process exited 0. install.sh gates its inline PATH fallback on a non-zero exit from 'composio install', so an aborted setup looked green and left the user with no PATH setup at all. Raise a typed ShellSetupAbortError after printing the abort reason; cli-main.ts maps it to exit code 1 without printing anything further, so install.sh now takes its fallback branch.

jkomyno committed Aug 3, 2026 at 20:29 UTC 648e95727abc954f52cfec82b0a567413e338660
3 files changed +44 -13
ts/packages/cli/src/cli-main.ts
+11
@@ -44,6 +44,7 @@ import { getVersion } from 'src/effects/version';
44 import { mapOnlyComposioOverrideError } from 'src/services/composio-error-overrides';
45 import { SetupSkillInstaller } from 'src/services/setup-skill-installer';
46 import { SetupCommandError } from 'src/services/setup';
47 +import { ShellSetupAbortError } from 'src/commands/install.cmd';
48
49 // Layer is contravariant in ROut and covariant in E, so `never`/`unknown` accept any
50 // produced context and error type while still pinning the requirements (RIn) to `never`.
@@ -225,6 +226,16 @@ showUpdateNotice.pipe(
226 process.exitCode = 1;
227 })
228 ),
229 + Effect.catchIf(
230 + (error): error is ShellSetupAbortError => error instanceof ShellSetupAbortError,
231 + // `composio install` already printed the abort reason; the typed failure
232 + // only exists so the process exits non-zero and install.sh runs its
233 + // guarded inline PATH fallback instead of reporting a green install.
234 + () =>
235 + Effect.sync(() => {
236 + process.exitCode = 1;
237 + })
238 + ),
239 Effect.withSpan('composio-cli', {
240 attributes: {
241 name: constants.APP_NAME,
ts/packages/cli/src/commands/install.cmd.ts
+20 -8
@@ -1,7 +1,7 @@
1 import { Command, Options } from '@effect/cli';
2 import { FileSystem, Path } from '@effect/platform';
3 import type { PlatformError } from '@effect/platform/Error';
4 -import { Array as Arr, Config, ConfigProvider, Effect, Option } from 'effect';
4 +import { Array as Arr, Config, ConfigProvider, Data, Effect, Option } from 'effect';
5 import { ComposioCliUserConfig } from 'src/services/cli-user-config';
6 import { NodeOs } from 'src/services/node-os';
7 import { NodeProcess } from 'src/services/node-process';
@@ -35,6 +35,17 @@ const shellOpt = Options.choice('shell', SHELLS).pipe(
35
36 export type Shell = (typeof SHELLS)[number];
37
38 +/**
39 + * Aborted shell setup must fail the process: install.sh only runs its guarded
40 + * inline PATH fallback when `composio install` exits non-zero, so a successful
41 + * exit here would leave the user with no PATH setup and a green install. The
42 + * abort reason is already printed before this error is raised; cli-main.ts
43 + * maps it to exit code 1 without printing anything further.
44 + */
45 +export class ShellSetupAbortError extends Data.TaggedError('commands/ShellSetupAbortError')<{
46 + readonly message: string;
47 +}> {}
48 +
49 interface ShellConfig {
50 readonly shell: Shell;
51 readonly pathFiles: readonly string[];
@@ -268,7 +279,7 @@ export const installShellIntegration = (params: {
279 readonly shell?: Shell;
280 }): Effect.Effect<
281 void,
271 - PlatformError,
282 + PlatformError | ShellSetupAbortError,
283 TerminalUI | NodeOs | NodeProcess | FileSystem.FileSystem | Path.Path | ComposioCliUserConfig
284 > =>
285 Effect.gen(function* () {
@@ -315,17 +326,18 @@ export const installShellIntegration = (params: {
326 );
327
328 if (!path.isAbsolute(binDir)) {
318 - yield* failure('Resolved bin directory must be an absolute path.');
329 + const message = 'Resolved bin directory must be an absolute path.';
330 + yield* failure(message);
331 yield* ui.outro('Aborted.');
320 - return;
332 + return yield* new ShellSetupAbortError({ message });
333 }
334
335 if (isUnsafePath(binDir)) {
324 - yield* failure(
325 - 'Resolved bin directory contains unsafe characters and cannot be written to shell config.'
326 - );
336 + const message =
337 + 'Resolved bin directory contains unsafe characters and cannot be written to shell config.';
338 + yield* failure(message);
339 yield* ui.outro('Aborted.');
328 - return;
340 + return yield* new ShellSetupAbortError({ message });
341 }
342
343 const isExplicitShell = params.shell !== undefined;
ts/packages/cli/test/src/commands/install.cmd.test.ts
+13 -5
@@ -5,7 +5,11 @@ import { describe, expect, layer } from '@effect/vitest';
5 import { Effect, Exit } from 'effect';
6 import { FileSystem } from '@effect/platform';
7 import { NodeOs } from 'src/services/node-os';
8 -import { installShellIntegration, type Shell } from 'src/commands/install.cmd';
8 +import {
9 + installShellIntegration,
10 + ShellSetupAbortError,
11 + type Shell,
12 +} from 'src/commands/install.cmd';
13 import { makeTerminalUI } from 'src/services/terminal-ui';
14 import { cli, TestLive, MockConsole } from 'test/__utils__';
15
@@ -960,7 +964,8 @@ describe('CLI: composio install', () => {
964 vi.stubEnv('SHELL', '/bin/zsh');
965 vi.stubEnv('COMPOSIO_BIN_DIR', '/tmp/x; curl evil.com');
966
963 - yield* install();
967 + const error = yield* install().pipe(Effect.flip);
968 + expect(error).toBeInstanceOf(ShellSetupAbortError);
969
970 const lines = yield* MockConsole.getLines();
971 const output = lines.join('\n');
@@ -979,7 +984,8 @@ describe('CLI: composio install', () => {
984 vi.stubEnv('SHELL', '/bin/zsh');
985 vi.stubEnv('COMPOSIO_BIN_DIR', './bin');
986
982 - yield* install();
987 + const error = yield* install().pipe(Effect.flip);
988 + expect(error).toBeInstanceOf(ShellSetupAbortError);
989
990 const output = (yield* MockConsole.getLines()).join('\n');
991 expect(output).toContain('must be an absolute path');
@@ -996,7 +1002,8 @@ describe('CLI: composio install', () => {
1002 vi.stubEnv('SHELL', '/bin/zsh');
1003 vi.stubEnv('COMPOSIO_BIN_DIR', '/custom/bin:/tmp/extra');
1004
999 - yield* install();
1005 + const error = yield* install().pipe(Effect.flip);
1006 + expect(error).toBeInstanceOf(ShellSetupAbortError);
1007
1008 const output = (yield* MockConsole.getLines()).join('\n');
1009 expect(output).toContain('Resolved bin directory');
@@ -1013,7 +1020,8 @@ describe('CLI: composio install', () => {
1020 Effect.gen(function* () {
1021 vi.stubEnv('SHELL', '/bin/zsh');
1022
1016 - yield* install({ execPath: "/tmp/o'brien/composio" });
1023 + const error = yield* install({ execPath: "/tmp/o'brien/composio" }).pipe(Effect.flip);
1024 + expect(error).toBeInstanceOf(ShellSetupAbortError);
1025
1026 const output = (yield* MockConsole.getLines()).join('\n');
1027 expect(output).toContain('Resolved bin directory');