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): handle incompatible Codex plugin commands
Kshitij Jhunjhunwalad004b2a309ab
diff --git a/ts/e2e-tests/cli/setup-plugins/e2e.test.ts b/ts/e2e-tests/cli/setup-plugins/e2e.test.tsindex b033de8a1..4bde9dd87 100644--- a/ts/e2e-tests/cli/setup-plugins/e2e.test.ts+++ b/ts/e2e-tests/cli/setup-plugins/e2e.test.ts@@ -42,6 +42,17 @@ test ! -e /tmp/.agents/skills/composio-cli`cp /tmp/host-state/commands.log second-run.log`;+const legacyCodexFixture = `+set -eu+mkdir -p /tmp/bin /tmp/host-state+cp fixtures/fake-agent-host.sh /tmp/bin/codex+chmod +x /tmp/bin/codex+touch /tmp/host-state/codex-without-json+export HOST_STATE_DIR=/tmp/host-state+export PATH=/tmp/bin:$PATH+composio setup --target codex --yes+`;+e2e(import.meta.url, {versions: {cli: ['current'],@@ -52,6 +63,7 @@ e2e(import.meta.url, {let unavailable: E2ETestResult;let skippedUnavailable: E2ETestResult;let skippedUnavailableUninstall: E2ETestResult;+ let legacyCodex: E2ETestResult;beforeAll(async () => {// The shared E2E runner derives container names from Date.now(), so keep@@ -69,6 +81,7 @@ e2e(import.meta.url, {skippedUnavailableUninstall = await runCmd('composio setup --uninstall --target auto --yes --if-present');+ legacyCodex = await runCmd(legacyCodexFixture);}, TIMEOUTS.FIXTURE);describe.each([@@ -146,5 +159,15 @@ e2e(import.meta.url, {expect(skippedUnavailableUninstall.stderr).toBe('');});});++ describe('Codex compatibility', () => {+ it('explains how to upgrade when JSON plugin inspection is unavailable', () => {+ expect(legacyCodex.exitCode).not.toBe(0);+ expect(legacyCodex.stdout).toBe('');+ expect(legacyCodex.stderr).toContain('requires Codex 0.139.0 or newer');+ expect(legacyCodex.stderr).toContain('codex update');+ expect(legacyCodex.stderr).not.toContain("unexpected argument '--json'");+ });+ });},});diff --git a/ts/e2e-tests/cli/setup-plugins/fixtures/fake-agent-host.sh b/ts/e2e-tests/cli/setup-plugins/fixtures/fake-agent-host.shindex af7b75fe4..44f51e47c 100644--- a/ts/e2e-tests/cli/setup-plugins/fixtures/fake-agent-host.sh+++ b/ts/e2e-tests/cli/setup-plugins/fixtures/fake-agent-host.sh@@ -39,7 +39,17 @@ case "$host:$command" inrm -f "$state_dir/claude-plugin";;"codex:--version")- printf '%s\n' 'codex-cli 0.144.1'+ if [ -f "$state_dir/codex-without-json" ]; then+ printf '%s\n' 'codex-cli 0.137.0'+ else+ printf '%s\n' 'codex-cli 0.144.1'+ fi+ ;;+ "codex:plugin marketplace list --help")+ printf '%s\n' 'Usage: codex plugin marketplace list [OPTIONS]'+ if [ ! -f "$state_dir/codex-without-json" ]; then+ printf '%s\n' ' --json'+ fi;;"codex:plugin marketplace list --json")if [ -f "$state_dir/codex-marketplace" ]; thendiff --git a/ts/packages/cli/src/services/setup.ts b/ts/packages/cli/src/services/setup.tsindex fd9083256..b6a902535 100644--- a/ts/packages/cli/src/services/setup.ts+++ b/ts/packages/cli/src/services/setup.ts@@ -1,5 +1,6 @@import { Command } from '@effect/platform';import { Effect } from 'effect';+import semver from 'semver';import { CommandRunner, type CommandResult } from './command-runner';import { SetupSkillInstaller } from './setup-skill-installer';@@ -105,6 +106,7 @@ const ADAPTERS: Readonly<Record<AgentHost, SetupTargetAdapter>> = {const ADAPTER_LIST = Object.values(ADAPTERS);const SETUP_COMMAND_TIMEOUT = '2 minutes';+const MINIMUM_CODEX_SETUP_VERSION = '0.139.0';const asRecord = (value: unknown): Record<string, unknown> | undefined => {if (value === null || typeof value !== 'object' || Array.isArray(value)) return undefined;@@ -238,11 +240,35 @@ const capture = (executable: string, args: ReadonlyArray<string>) =>);});-const isAdapterAvailable = (adapter: SetupTargetAdapter) =>- capture(adapter.executable, ['--version']).pipe(- Effect.map(result => result !== undefined && result.exitCode === 0)+const detectAdapter = (adapter: SetupTargetAdapter) =>+ Effect.gen(function* () {+ const result = yield* capture(adapter.executable, ['--version']);+ const available = result !== undefined && result.exitCode === 0;+ const version = available ? result.stdout.trim() || result.stderr.trim() : '';+ return version ? { available, version } : { available };+ });++const unsupportedCodexInspectionError = () =>+ new Error(+ `This Codex installation does not support safe automatic plugin inspection. Composio setup requires Codex ${MINIMUM_CODEX_SETUP_VERSION} or newer with JSON plugin inspection. Run \`codex update\`, then rerun this command.`);+const requireInspectionSupport = (adapter: SetupTargetAdapter, versionOutput?: string) =>+ Effect.gen(function* () {+ if (adapter.target !== 'codex') return;++ const version = versionOutput?.match(/\b\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?\b/)?.[0];+ if (!version || !semver.valid(version) || semver.lt(version, MINIMUM_CODEX_SETUP_VERSION)) {+ return yield* Effect.fail(unsupportedCodexInspectionError());+ }++ const result = yield* capture(adapter.executable, ['plugin', 'marketplace', 'list', '--help']);+ const help = result ? `${result.stdout}\n${result.stderr}` : '';+ if (result?.exitCode === 0 && /^\s*--json\b/m.test(help)) return;++ return yield* Effect.fail(unsupportedCodexInspectionError());+ });+const commandFailureSuffix = (result: CommandResult): string => {const detail = result.stderr.trim() || result.stdout.trim();if (detail) return `: ${detail}`;@@ -275,11 +301,14 @@ const requireInspection = <T>(return Effect.succeed(inspected);};-const inspectAdapter = (adapter: SetupTargetAdapter, knownAvailable?: boolean) =>+const inspectAdapter = (+ adapter: SetupTargetAdapter,+ knownDetection?: { readonly available: boolean; readonly version?: string }+) =>Effect.gen(function* () {const skillInstaller = yield* SetupSkillInstaller;- const available = knownAvailable ?? (yield* isAdapterAvailable(adapter));- if (!available) {+ const detection = knownDetection ?? (yield* detectAdapter(adapter));+ if (!detection.available) {return {target: adapter.target,available: false,@@ -291,6 +320,8 @@ const inspectAdapter = (adapter: SetupTargetAdapter, knownAvailable?: boolean) =} satisfies InspectedSetupTarget;}+ yield* requireInspectionSupport(adapter, detection.version);+const [marketplaces, plugins] = yield* Effect.all([capture(adapter.executable, adapter.marketplaceListArgs),capture(adapter.executable, adapter.pluginListArgs),@@ -475,6 +506,7 @@ const FIXED_TARGETS: Readonly<Partial<Record<SetupTarget, ReadonlyArray<AgentHosexport interface SetupTargetDetection {readonly target: AgentHost;readonly available: boolean;+ readonly version?: string;}export const detectSetupTargets = (target: SetupTarget) =>@@ -482,8 +514,8 @@ export const detectSetupTargets = (target: SetupTarget) =>const targets = FIXED_TARGETS[target] ?? ADAPTER_LIST.map(adapter => adapter.target);return yield* Effect.all(targets.map(target =>- isAdapterAvailable(ADAPTERS[target]).pipe(- Effect.map(available => ({ target, available }) satisfies SetupTargetDetection)+ detectAdapter(ADAPTERS[target]).pipe(+ Effect.map(detection => ({ target, ...detection }) satisfies SetupTargetDetection))));@@ -496,7 +528,7 @@ export const inspectSetupTargets = (Effect.gen(function* () {const inspected = yield* Effect.forEach(detections.filter(detection => detection.available),- detection => inspectAdapter(ADAPTERS[detection.target], true)+ detection => inspectAdapter(ADAPTERS[detection.target], detection));if (!options.allowMarketplaceConflict) {yield* Effect.forEach(inspected, status =>diff --git a/ts/packages/cli/test/src/commands/setup.cmd.test.ts b/ts/packages/cli/test/src/commands/setup.cmd.test.tsindex 047c66de8..31b8a628d 100644--- a/ts/packages/cli/test/src/commands/setup.cmd.test.ts+++ b/ts/packages/cli/test/src/commands/setup.cmd.test.ts@@ -122,6 +122,8 @@ const makeFakeHosts = (readonly noOp?: boolean;readonly failOn?: string;readonly malformedOn?: string;+ readonly codexJsonInspection?: boolean;+ readonly codexVersion?: string;readonly marketplaceSource?: Partial<Record<AgentHost, string>>;} = {}) => {@@ -155,7 +157,20 @@ const makeFakeHosts = (const command = parts.join(' ');if (parts[1] === '--version') {if (!state[host].available) return { exitCode: 127, stderr: 'not found' };- return { stdout: HOST_OUTPUT_FORMATTERS[host].version };+ return {+ stdout:+ host === 'codex' && options.codexVersion+ ? options.codexVersion+ : HOST_OUTPUT_FORMATTERS[host].version,+ };+ }+ if (command === 'codex plugin marketplace list --help') {+ return {+ stdout:+ options.codexJsonInspection === false+ ? 'Usage: codex plugin marketplace list [OPTIONS]'+ : 'Usage: codex plugin marketplace list [OPTIONS]\n\n --json',+ };}if (options.failOn && command.includes(options.failOn)) {return { exitCode: 2, stderr: 'native operation failed' };@@ -806,6 +821,35 @@ describe('CLI: composio setup', () => {{ codex: { available: true } },{ malformedOn: 'plugin marketplace list --json' });++ const legacyCodex = makeFakeHosts(+ { codex: { available: true } },+ { codexJsonInspection: false, codexVersion: 'codex-cli 0.137.0' }+ );+ layer(TestLive({ commandRunner: legacyCodex.runner }))(+ 'Codex without JSON marketplace inspection',+ it => {+ it.scoped('fails with an actionable upgrade message before running setup mutations', () =>+ Effect.gen(function* () {+ const exit = yield* Effect.exit(cli(['setup', '--target', 'codex', '--yes']));++ expect(Exit.isFailure(exit)).toBe(true);+ if (Exit.isFailure(exit)) {+ const renderedCause = Cause.pretty(exit.cause);+ expect(renderedCause).toContain('requires Codex 0.139.0 or newer');+ expect(renderedCause).toContain('codex update');+ expect(renderedCause).not.toContain("unexpected argument '--json'");+ }+ expect(legacyCodex.commands.some(parts => parts.includes('--json'))).toBe(false);+ expect(+ legacyCodex.commands.some(parts =>+ ['add', 'install', 'enable', 'remove'].some(operation => parts.includes(operation))+ )+ ).toBe(false);+ })+ );+ }+ );layer(TestLive({ commandRunner: malformedInspection.runner }))('malformed native inspection',it => {