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
feat(cli): track plugin setup lifecycle
Kshitij Jhunjhunwala4e68e652809d
diff --git a/install.sh b/install.shindex 4ac559085..6a2488de5 100755--- a/install.sh+++ b/install.sh@@ -407,7 +407,7 @@ rm -f "$install_err"if [[ $install_plugins = true ]]; thenechoinfo "Checking for supported agent hosts..."- if ! "$exe" setup --target auto --yes --if-present; then+ if ! COMPOSIO_CLI_INVOCATION_ORIGIN=installer "$exe" setup --target auto --yes --if-present; thenerror 'Composio CLI was installed, but agent plugin setup failed. Retry with `composio setup --target auto --yes`.'fifidiff --git a/test/install-sh-release-resolution.test.sh b/test/install-sh-release-resolution.test.shindex f492e4a5c..1fcc5fe2d 100755--- a/test/install-sh-release-resolution.test.sh+++ b/test/install-sh-release-resolution.test.sh@@ -154,6 +154,10 @@ install)exit 0;;setup)+ if [[ "${COMPOSIO_CLI_INVOCATION_ORIGIN:-}" != 'installer' ]]; then+ echo 'Expected automatic plugin setup telemetry origin to be installer.' >&2+ exit 97+ fiexit "${TEST_SETUP_EXIT:-0}";;--version|version)diff --git a/ts/packages/cli/src/analytics/events.ts b/ts/packages/cli/src/analytics/events.tsindex 213c2b1f1..8b22e876b 100644--- a/ts/packages/cli/src/analytics/events.ts+++ b/ts/packages/cli/src/analytics/events.ts@@ -27,6 +27,14 @@ export const CLI_ANALYTICS_EVENTS = {CLI_RUN_INVOKED: 'CLI_RUN_INVOKED',CLI_RUN_SUCCEEDED: 'CLI_RUN_SUCCEEDED',CLI_RUN_FAILED: 'CLI_RUN_FAILED',+ CLI_INSTALL_INVOKED: 'CLI_INSTALL_INVOKED',+ CLI_INSTALL_SUCCEEDED: 'CLI_INSTALL_SUCCEEDED',+ CLI_INSTALL_FAILED: 'CLI_INSTALL_FAILED',+ CLI_SETUP_INVOKED: 'CLI_SETUP_INVOKED',+ CLI_SETUP_SUCCEEDED: 'CLI_SETUP_SUCCEEDED',+ CLI_SETUP_FAILED: 'CLI_SETUP_FAILED',+ CLI_PLUGIN_SETUP_SUCCEEDED: 'CLI_PLUGIN_SETUP_SUCCEEDED',+ CLI_PLUGIN_UNINSTALL_SUCCEEDED: 'CLI_PLUGIN_UNINSTALL_SUCCEEDED',CLI_TOOL_INVOCATION_VALIDATION_FAILED: 'CLI_TOOL_INVOCATION_VALIDATION_FAILED',CLI_TOOL_INVOCATION_TOOL_NOT_FOUND: 'CLI_TOOL_INVOCATION_TOOL_NOT_FOUND',CLI_TOOL_INVOCATION_FAILED: 'CLI_TOOL_INVOCATION_FAILED',@@ -40,6 +48,7 @@ const KNOWN_COMMAND_TOKENS = new Set(['logout','run','install',+ 'setup','dev','generate','tools',@@ -281,6 +290,28 @@ const getRunCommandProperties = (context: CliCommandTelemetryContext) => ({arg_count: Math.max(0, context.argv.length - 3),});+const getInstallCommandProperties = (context: CliCommandTelemetryContext) => ({+ source: 'cli',+ invocation_origin: getInvocationOrigin(),+ cli_version: context.cliVersion,+ command_path: context.commandPath,+ duration_ms: Date.now() - context.startedAt,+ completions: isFlagPresent(context.argv, '--completions'),+ no_completions: isFlagPresent(context.argv, '--no-completions'),+});++const getSetupCommandProperties = (context: CliCommandTelemetryContext) => ({+ source: 'cli',+ invocation_origin: getInvocationOrigin(),+ cli_version: context.cliVersion,+ command_path: context.commandPath,+ duration_ms: Date.now() - context.startedAt,+ operation: isFlagPresent(context.argv, '--uninstall') ? 'uninstall' : 'setup',+ target: getFlagValue(context.argv, '--target') ?? 'auto',+ yes: isFlagPresent(context.argv, '--yes', '-y'),+ if_present: isFlagPresent(context.argv, '--if-present'),+});+const getLoginCommandProperties = (context: CliCommandTelemetryContext) => ({source: 'cli',invocation_origin: getInvocationOrigin(),@@ -333,6 +364,10 @@ const isProxyCommand = (commandPath: string): boolean => commandPath === 'proxy'const isRunCommand = (commandPath: string): boolean => commandPath === 'run';+const isInstallCommand = (commandPath: string): boolean => commandPath === 'install';++const isSetupCommand = (commandPath: string): boolean => commandPath === 'setup';+const isGenericOnlyCommand = (commandPath: string): boolean =>commandPath === 'composio' || commandPath.startsWith('dev');@@ -452,6 +487,20 @@ const SPECIAL_LIFECYCLE_FAMILIES: ReadonlyArray<SpecialLifecycleFamily> = [failedEventName: CLI_ANALYTICS_EVENTS.CLI_RUN_FAILED,getProperties: getRunCommandProperties,},+ {+ match: isInstallCommand,+ invokedEventName: CLI_ANALYTICS_EVENTS.CLI_INSTALL_INVOKED,+ succeededEventName: CLI_ANALYTICS_EVENTS.CLI_INSTALL_SUCCEEDED,+ failedEventName: CLI_ANALYTICS_EVENTS.CLI_INSTALL_FAILED,+ getProperties: getInstallCommandProperties,+ },+ {+ match: isSetupCommand,+ invokedEventName: CLI_ANALYTICS_EVENTS.CLI_SETUP_INVOKED,+ succeededEventName: CLI_ANALYTICS_EVENTS.CLI_SETUP_SUCCEEDED,+ failedEventName: CLI_ANALYTICS_EVENTS.CLI_SETUP_FAILED,+ getProperties: getSetupCommandProperties,+ },];const getSpecialLifecycleFamily = (commandPath: string): SpecialLifecycleFamily | undefined =>@@ -501,6 +550,27 @@ export const getPrimaryLifecycleFailedEvent = (};};+export const getPluginLifecycleSucceededEvent = (params: {+ readonly operation: 'setup' | 'uninstall';+ readonly target: 'claude' | 'codex';+ readonly action: 'installed' | 'enabled' | 'configured' | 'uninstalled';+ readonly cliVersion: string;+}): TrackEvent => ({+ name:+ params.operation === 'uninstall'+ ? CLI_ANALYTICS_EVENTS.CLI_PLUGIN_UNINSTALL_SUCCEEDED+ : CLI_ANALYTICS_EVENTS.CLI_PLUGIN_SETUP_SUCCEEDED,+ properties: {+ source: 'cli',+ invocation_origin: getInvocationOrigin(),+ cli_version: params.cliVersion,+ command_path: 'setup',+ operation: params.operation,+ agent_host: params.target,+ action: params.action,+ },+});+export const getToolExecuteValidationFailedEvent = (params: {readonly toolSlug: string;readonly args: Record<string, unknown>;diff --git a/ts/packages/cli/src/services/setup.ts b/ts/packages/cli/src/services/setup.tsindex 156b2ecd7..ba3432e02 100644--- a/ts/packages/cli/src/services/setup.ts+++ b/ts/packages/cli/src/services/setup.ts@@ -1,6 +1,9 @@import { Command } from '@effect/platform';import { Data, Effect } from 'effect';import semver from 'semver';+import { trackCliEventEffect } from 'src/analytics/dispatch';+import { getPluginLifecycleSucceededEvent } from 'src/analytics/events';+import { APP_VERSION } from 'src/constants';import { CommandRunner, type CommandResult } from './command-runner';import { SetupSkillInstaller } from './setup-skill-installer';@@ -746,6 +749,21 @@ export const installSetupTargets = (inspected: ReadonlyArray<InspectedSetupTarge);}));+ if (result.plugin_changed) {+ const action = !status.plugin_installed+ ? 'installed'+ : !status.plugin_enabled+ ? 'enabled'+ : 'configured';+ yield* trackCliEventEffect(+ getPluginLifecycleSucceededEvent({+ operation: 'setup',+ target: result.target,+ action,+ cliVersion: APP_VERSION,+ })+ );+ }completed.push(result);}return completed;@@ -764,6 +782,16 @@ export const uninstallSetupTargets = (inspected: ReadonlyArray<InspectedSetupTar);}));+ if (result.plugin_changed) {+ yield* trackCliEventEffect(+ getPluginLifecycleSucceededEvent({+ operation: 'uninstall',+ target: result.target,+ action: 'uninstalled',+ cliVersion: APP_VERSION,+ })+ );+ }completed.push(result);}return completed;diff --git a/ts/packages/cli/test/src/analytics.events.test.ts b/ts/packages/cli/test/src/analytics.events.test.tsindex 5194ef7ad..fc4bc6df1 100644--- a/ts/packages/cli/test/src/analytics.events.test.ts+++ b/ts/packages/cli/test/src/analytics.events.test.ts@@ -1,12 +1,19 @@import { describe, expect, it } from 'vitest';import { createCliCodactFailureBody } from 'src/analytics/dispatch';import {+ CLI_ANALYTICS_EVENTS,+ createCliCommandTelemetryContext,+ getPluginLifecycleSucceededEvent,+ getPrimaryLifecycleFailedEvent,+ getPrimaryLifecycleInvokedEvent,+ getPrimaryLifecycleSucceededEvent,getToolExecuteFailedEvent,getToolExecuteToolNotFoundEvent,getToolExecuteValidationFailedEvent,isMaybeToolNotFoundError,isMaybeToolValidationError,} from 'src/analytics/events';+import { APP_VERSION } from 'src/constants';import { ToolInputValidationError } from 'src/services/tool-input-validation';describe('CLI analytics execute failure events', () => {@@ -127,3 +134,62 @@ describe('CLI analytics execute failure events', () => {});});});++describe('CLI analytics setup and install lifecycle events', () => {+ it('tracks setup as a dedicated lifecycle with safe option properties', () => {+ const context = createCliCommandTelemetryContext(+ ['bun', 'composio', 'setup', '--target', 'codex', '--uninstall', '--yes'],+ APP_VERSION+ );++ const invoked = getPrimaryLifecycleInvokedEvent(context);+ const succeeded = getPrimaryLifecycleSucceededEvent(context);+ const failed = getPrimaryLifecycleFailedEvent(context, new Error('native failure'));++ expect(invoked?.name).toBe(CLI_ANALYTICS_EVENTS.CLI_SETUP_INVOKED);+ expect(succeeded?.name).toBe(CLI_ANALYTICS_EVENTS.CLI_SETUP_SUCCEEDED);+ expect(failed?.name).toBe(CLI_ANALYTICS_EVENTS.CLI_SETUP_FAILED);+ expect(invoked?.properties).toMatchObject({+ command_path: 'setup',+ operation: 'uninstall',+ target: 'codex',+ yes: true,+ if_present: false,+ });+ });++ it('tracks shell installation separately from plugin setup', () => {+ const context = createCliCommandTelemetryContext(+ ['bun', 'composio', 'install', '--completions'],+ APP_VERSION+ );++ expect(getPrimaryLifecycleInvokedEvent(context)).toMatchObject({+ name: CLI_ANALYTICS_EVENTS.CLI_INSTALL_INVOKED,+ properties: {+ command_path: 'install',+ completions: true,+ no_completions: false,+ },+ });+ });++ it('tracks a verified per-host plugin change', () => {+ expect(+ getPluginLifecycleSucceededEvent({+ operation: 'setup',+ target: 'claude',+ action: 'installed',+ cliVersion: APP_VERSION,+ })+ ).toMatchObject({+ name: CLI_ANALYTICS_EVENTS.CLI_PLUGIN_SETUP_SUCCEEDED,+ properties: {+ command_path: 'setup',+ operation: 'setup',+ agent_host: 'claude',+ action: 'installed',+ },+ });+ });+});