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

refactor(cli): stamp agent host at dispatch and drop setup error indirection

trackCliEventEffect reads the host environment and adds agent_host_env to every enqueued envelope, so there is no module-level state and no bootstrap hook. SetupCommandError lives in a leaf module so analytics/events.ts can use instanceof without a cycle, setup.cmd.ts keeps its original helper shape with the reason code as a third argument, and plugin-hint.ts keeps its original config resolution. Event names and properties are unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

Kshitij Jhunjhunwala committed Sep 15, 2026 at 13:54 UTC b09b322d1cc7c7323648b8a67fa9320469b7c77e
12 files changed +120 -147
.agents/skills/cli-command/references/implementation.md
+4 -3
@@ -61,11 +61,12 @@ Never add an `eslint-disable`: `pnpm run validate:boundaries` (CI-blocking via `
61 ## Analytics Events
62
63 Event names and builders live in `src/analytics/events.ts`; `buildEvent` stamps every event with
64 -`journey_stage`, `cli_channel`, and `agent_host_env` (`claude`, `codex`, or `none`, from
65 -`src/services/agent-host-env.ts`). Setup-related events and their extra properties:
64 +`journey_stage` and `cli_channel`, and `trackCliEventEffect` (`src/analytics/dispatch.ts`) adds
65 +`agent_host_env` (`claude`, `codex`, or `none`, from `src/services/agent-host-env.ts`) to every
66 +enqueued envelope. Setup-related events and their extra properties:
67
68 - `CLI_SETUP_HOST_DETECTED`: `host_config_dir_present` and `host_binary_in_known_paths` only when
68 - `available` is `false` (probed by `src/services/agent-host-locations.ts`).
69 + `available` is `false` (probed by `src/services/agent-host-env.ts`).
70 - `CLI_SETUP_FAILED`: `failure_reason_code` read from `SetupCommandError.reasonCode`
71 (`src/services/setup-command-error.ts`).
72 - `CLI_PLUGIN_HINT_SHOWN`: emitted by `src/services/plugin-hint.ts` once per printed hint with
ts/packages/cli/src/analytics/dispatch.ts
+3
@@ -22,6 +22,7 @@ import { atomicWriteFileString } from 'src/utils/atomic-write';
22 import { sha256Hex } from 'src/utils/checksums';
23 import { djb2Hash } from 'src/utils/djb2';
24 import { NodeOs } from 'src/services/node-os';
25 +import { detectPluginHost, rawHostEnvironment } from 'src/services/agent-host-env';
26 import { TerminalUI } from 'src/services/terminal-ui';
27 import { isTelemetryDebugEnabled, TELEMETRY_DEBUG_FLAG } from 'src/services/runtime-flags';
28 import { CliRunId } from 'src/services/runtime-cli-context';
@@ -721,10 +722,12 @@ export const trackCliEventEffect = (event: TrackEvent) =>
722 const installId = yield* getOrCreateInstallId;
723 const distinctId = yield* getDistinctId(installId);
724 const orgId = yield* getOrgId;
725 + const hostEnv = yield* rawHostEnvironment;
726 const sentAt = DateTime.formatIso(yield* DateTime.now);
727 const properties = scrubSecrets({
728 ...(enrichedEvent.properties ?? {}),
729 ...(orgId ? { org_id: orgId } : {}),
730 + agent_host_env: detectPluginHost(hostEnv) ?? 'none',
731 }) as Record<string, unknown>;
732 const envelope: AnalyticsEnvelope = {
733 event: enrichedEvent.name,
ts/packages/cli/src/analytics/events.ts
+2 -12
@@ -1,10 +1,9 @@
1 import type { CliCommandTelemetryContext, TrackEvent } from './types';
2 -import { Predicate } from 'effect';
2 import { APP_VERSION } from 'src/constants';
3 import { inferSkillReleaseChannel } from 'src/effects/install-skill';
4 import type { AgentHost } from 'src/services/agent-host';
6 -import type { AgentHostEnv } from 'src/services/agent-host-env';
5 import type { CliInvocationContext } from 'src/services/runtime-cli-context';
6 +import { SetupCommandError } from 'src/services/setup-command-error';
7 import { ToolInputValidationError } from 'src/services/tool-input-validation';
8 import { guessToolkitFromToolSlug } from 'src/utils/toolkit-from-tool-slug';
9
@@ -117,12 +116,6 @@ export const configureCliAnalyticsReleaseVersion = (version: string): void => {
116 cliChannel = inferSkillReleaseChannel(version);
117 };
118
120 -let agentHostEnv: AgentHostEnv = 'none';
121 -
122 -export const configureCliAnalyticsAgentHostEnv = (host: AgentHostEnv): void => {
123 - agentHostEnv = host;
124 -};
125 -
119 const buildEvent = (
120 name: CliAnalyticsEventName,
121 properties: Record<string, unknown>
@@ -132,7 +125,6 @@ const buildEvent = (
125 ...properties,
126 journey_stage: CLI_EVENT_JOURNEY_STAGES[name],
127 cli_channel: cliChannel,
135 - agent_host_env: agentHostEnv,
128 },
129 });
130
@@ -246,9 +238,7 @@ const errorNameOf = (error: unknown): string =>
238 error instanceof Error && error.name ? error.name : 'UnknownError';
239
240 const failureReasonProperties = (error: unknown) => {
249 - if (Predicate.hasProperty(error, 'reasonCode') && Predicate.isString(error.reasonCode)) {
250 - return { failure_reason_code: error.reasonCode };
251 - }
241 + if (error instanceof SetupCommandError) return { failure_reason_code: error.reasonCode };
242 return {};
243 };
244
ts/packages/cli/src/cli-main.ts
+2 -9
@@ -105,10 +105,8 @@ import { ProjectEnvironmentDetector } from 'src/services/project-environment-det
105 import { CommandRunner } from 'src/services/command-runner';
106 import { StdinLive } from 'src/services/stdin';
107 import { showPluginAcquisitionHint } from 'src/services/plugin-hint';
108 -import { agentHostEnvOf, rawHostEnvironment } from 'src/services/agent-host-env';
108 import { showUpdateNotice } from 'src/services/update-check';
109 import {
111 - configureCliAnalyticsAgentHostEnv,
110 configureCliAnalyticsReleaseVersion,
111 createCliCommandTelemetryContext,
112 getExecuteCommandToolSlug,
@@ -121,7 +119,7 @@ import { getVersion } from 'src/effects/version';
119 import { toolkitFromToolSlug } from 'src/effects/toolkit-from-tool-slug';
120 import { mapOnlyComposioOverrideError } from 'src/services/composio-error-overrides';
121 import { SetupSkillInstaller } from 'src/services/setup-skill-installer';
124 -import { SetupCommandError } from 'src/services/setup';
122 +import { SetupCommandError } from 'src/services/setup-command-error';
123 import { ShellSetupAbortError } from 'src/commands/install.cmd';
124 import { MissingRunSourceError } from 'src/commands/run.cmd';
125 import { cliInvocationContext } from 'src/services/runtime-cli-context';
@@ -312,13 +310,8 @@ export type CliBootstrapOptions = {
310 readonly telemetryDebug: boolean;
311 };
312
315 -const stampAgentHostEnv = rawHostEnvironment.pipe(
316 - Effect.map(env => configureCliAnalyticsAgentHostEnv(agentHostEnvOf(env)))
317 -);
318 -
313 const cliProgram = (argv: ReadonlyArray<string>) =>
320 - stampAgentHostEnv.pipe(
321 - Effect.andThen(showUpdateNotice),
314 + showUpdateNotice.pipe(
315 Effect.andThen(showPluginAcquisitionHint(argv)),
316 Effect.andThen(runWithTelemetry(argv)),
317 Effect.catchIf(
ts/packages/cli/src/commands/setup.cmd.ts
+51 -50
@@ -15,11 +15,10 @@ import {
15 isSetupPluginReady,
16 isSetupReady,
17 SETUP_TARGETS,
18 - SetupCommandError,
18 uninstallSetupTargets,
19 type AgentHost,
21 - type SetupFailureReasonCode,
20 } from 'src/services/setup';
21 +import { SetupCommandError, type SetupFailureReasonCode } from 'src/services/setup-command-error';
22 import { TerminalUI } from 'src/services/terminal-ui';
23 import { SetupSkillInstaller } from 'src/services/setup-skill-installer';
24 import { cliInvocationContext } from 'src/services/runtime-cli-context';
@@ -51,31 +50,28 @@ const formatTargets = (targets: ReadonlyArray<AgentHost>): string =>
50 const errorMessage = (error: unknown): string =>
51 Predicate.isError(error) ? error.message : String(error);
52
54 -type SetupOperation = 'setup' | 'uninstall';
55 -
56 -interface SetupCommandErrorParams {
57 - readonly message: string;
58 - readonly reasonCode: SetupFailureReasonCode;
59 - readonly cause?: unknown;
60 -}
61 -
62 -const operationOf = (uninstall: boolean): SetupOperation => {
63 - if (uninstall) return 'uninstall';
64 - return 'setup';
65 -};
53 +const setupCommandError = (
54 + message: string,
55 + operation: 'setup' | 'uninstall',
56 + reasonCode: SetupFailureReasonCode,
57 + cause?: unknown
58 +) =>
59 + new SetupCommandError({
60 + message,
61 + operation,
62 + reasonCode,
63 + ...(cause === undefined ? {} : { cause }),
64 + });
65
66 const setupBaseCmd = Command.make(
67 'setup',
68 { target, yes, ifPresent, uninstall },
70 - ({ target, yes, ifPresent, uninstall }) => {
71 - const operation = operationOf(uninstall);
72 - const setupCommandError = (params: SetupCommandErrorParams) =>
73 - new SetupCommandError({ operation, ...params });
74 -
75 - return Effect.gen(function* () {
69 + ({ target, yes, ifPresent, uninstall }) =>
70 + Effect.gen(function* () {
71 const ui = yield* TerminalUI;
72 const terminal = yield* ui.capabilities;
73 const { invocationOrigin } = yield* cliInvocationContext;
74 + const operation = uninstall ? 'uninstall' : 'setup';
75 yield* ui.intro(uninstall ? 'composio setup --uninstall' : 'composio setup');
76
77 const detections = yield* detectSetupTargets(target);
@@ -113,10 +109,11 @@ const setupBaseCmd = Command.make(
109 yield* ui.log.info(`${formatTargets(notDetected)} not detected.`);
110 }
111 if (target === 'all' && notDetected.length > 0) {
116 - return yield* setupCommandError({
117 - message: `\`--target all\` requires Claude Code and Codex. Missing: ${formatTargets(notDetected)}. Install the missing agent host, or use \`--target auto\` to operate on detected hosts only.`,
118 - reasonCode: 'all_requires_both_hosts',
119 - });
112 + return yield* setupCommandError(
113 + `\`--target all\` requires Claude Code and Codex. Missing: ${formatTargets(notDetected)}. Install the missing agent host, or use \`--target auto\` to operate on detected hosts only.`,
114 + operation,
115 + 'all_requires_both_hosts'
116 + );
117 }
118 if (unsupported.length > 0) {
119 const reason = unsupported
@@ -124,7 +121,7 @@ const setupBaseCmd = Command.make(
121 .filter((message): message is string => Boolean(message))
122 .join(' ');
123 if (target !== 'auto') {
127 - return yield* setupCommandError({ message: reason, reasonCode: 'unsupported_host' });
124 + return yield* setupCommandError(reason, operation, 'unsupported_host');
125 }
126 yield* ui.log.warn(
127 `${formatTargets(unsupported.map(result => result.target))} plugin setup skipped. ${reason}`
@@ -144,21 +141,23 @@ const setupBaseCmd = Command.make(
141 );
142 return;
143 }
147 - return yield* setupCommandError({ message: reason, reasonCode: 'unsupported_host' });
144 + return yield* setupCommandError(reason, operation, 'unsupported_host');
145 }
146 }
147 if (detected.length === 0) {
148 if (target === 'claude' || target === 'codex') {
152 - return yield* setupCommandError({
153 - message: `${target} is not installed or not available on PATH. Install it and rerun \`composio setup${uninstall ? ' --uninstall' : ''} --target ${target}\`.`,
154 - reasonCode: 'target_not_installed',
155 - });
149 + return yield* setupCommandError(
150 + `${target} is not installed or not available on PATH. Install it and rerun \`composio setup${uninstall ? ' --uninstall' : ''} --target ${target}\`.`,
151 + operation,
152 + 'target_not_installed'
153 + );
154 }
155 if (!ifPresent || target !== 'auto') {
158 - return yield* setupCommandError({
159 - message: `No supported agent host was detected. Install Claude Code or Codex, then rerun \`composio setup${uninstall ? ' --uninstall' : ''}\`.`,
160 - reasonCode: 'no_host_detected',
161 - });
156 + return yield* setupCommandError(
157 + `No supported agent host was detected. Install Claude Code or Codex, then rerun \`composio setup${uninstall ? ' --uninstall' : ''}\`.`,
158 + operation,
159 + 'no_host_detected'
160 + );
161 }
162 yield* trackCliEventEffect(
163 getSetupSkippedEvent({
@@ -176,7 +175,7 @@ const setupBaseCmd = Command.make(
175
176 const inspected = yield* inspectSetupTargets(detections, {
177 allowMarketplaceConflict: uninstall,
179 - operation,
178 + operation: uninstall ? 'uninstall' : 'setup',
179 });
180 if (uninstall) {
181 const installed = inspected.filter(status => status.plugin_installed);
@@ -202,10 +201,11 @@ const setupBaseCmd = Command.make(
201
202 if (!yes && removable.length > 0) {
203 if (!terminal.canPrompt) {
205 - return yield* setupCommandError({
206 - message: 'Non-interactive uninstall requires `--yes` to approve local changes.',
207 - reasonCode: 'non_interactive_requires_yes',
208 - });
204 + return yield* setupCommandError(
205 + 'Non-interactive uninstall requires `--yes` to approve local changes.',
206 + operation,
207 + 'non_interactive_requires_yes'
208 + );
209 }
210 const confirmed = yield* ui.confirm(
211 `Remove Composio from ${formatTargets(removable.map(status => status.target))}?`,
@@ -251,10 +251,11 @@ const setupBaseCmd = Command.make(
251 const pendingPlugins = pending.filter(status => !isSetupPluginReady(status));
252 if (!yes) {
253 if (!terminal.canPrompt) {
254 - return yield* setupCommandError({
255 - message: 'Non-interactive setup requires `--yes` to approve local changes.',
256 - reasonCode: 'non_interactive_requires_yes',
257 - });
254 + return yield* setupCommandError(
255 + 'Non-interactive setup requires `--yes` to approve local changes.',
256 + operation,
257 + 'non_interactive_requires_yes'
258 + );
259 }
260
261 const prompt =
@@ -299,14 +300,14 @@ const setupBaseCmd = Command.make(
300 }).pipe(
301 Effect.mapError(error => {
302 if (error instanceof SetupCommandError) return error;
302 - return setupCommandError({
303 - message: errorMessage(error),
304 - reasonCode: 'unknown',
305 - cause: error,
306 - });
303 + return setupCommandError(
304 + errorMessage(error),
305 + uninstall ? 'uninstall' : 'setup',
306 + 'unknown',
307 + error
308 + );
309 })
308 - );
309 - }
310 + )
311 );
312
313 export const setupCmd = setupBaseCmd.pipe(
ts/packages/cli/src/services/agent-host-env.ts
-5
@@ -4,8 +4,6 @@ import { Config, ConfigProvider, Effect, Option } from 'effect';
4 import type { AgentHost } from './agent-host';
5 import { NodeOs } from './node-os';
6
7 -export type AgentHostEnv = AgentHost | 'none';
8 -
7 export interface HostEnvMarkers {
8 readonly claudeCode: string | undefined;
9 readonly codexThreadId: string | undefined;
@@ -31,9 +29,6 @@ export function detectPluginHost(markers: HostEnvMarkers): AgentHost | undefined
29 return undefined;
30 }
31
34 -export const agentHostEnvOf = (markers: HostEnvMarkers): AgentHostEnv =>
35 - detectPluginHost(markers) ?? 'none';
36 -
32 const readOptionalEnv = (name: string) =>
33 Effect.orDie(Config.option(Config.string(name)).pipe(Config.map(Option.getOrUndefined)));
34
ts/packages/cli/src/services/plugin-hint.ts
+14 -7
@@ -1,13 +1,15 @@
1 import * as FileSystem from 'effect/FileSystem';
2 import * as Path from 'effect/Path';
3 -import { Effect, Option, Schema } from 'effect';
3 +import * as BunFileSystem from '@effect/platform-bun/BunFileSystem';
4 +import { Effect, Layer, Option, Schema } from 'effect';
5 import { trackCliEventEffect } from 'src/analytics/dispatch';
6 import { getPluginHintShownEvent } from 'src/analytics/events';
7 import { APP_CONFIG } from 'src/effects/app-config';
8 import { setupCacheDir } from 'src/effects/setup-cache-dir';
9 import { APP_VERSION } from 'src/constants';
10 import { AGENT_HOST_LABELS, COMPOSIO_AGENT_PLUGIN_ID, type AgentHost } from './agent-host';
10 -import { detectPluginHost, hostConfigDirectory, rawHostEnvironment } from './agent-host-env';
11 +import { detectPluginHost, rawHostEnvironment } from './agent-host-env';
12 +import { NodeOs } from './node-os';
13 import { DEFAULT_CLI_INVOCATION_ORIGIN } from './runtime-cli-context';
14 import { TerminalUI } from './terminal-ui';
15
@@ -125,6 +127,8 @@ export function createPluginHint(config: PluginHintConfig) {
127 return { showPluginHint };
128 }
129
130 +const DefaultConfigLayers = Layer.mergeAll(Path.layer, NodeOs.Default, BunFileSystem.layer);
131 +
132 export function findRootCommandName(argv: ReadonlyArray<string>): string | undefined {
133 const args = argv.slice(2);
134 for (let index = 0; index < args.length; index += 1) {
@@ -144,18 +148,21 @@ export function findRootCommandName(argv: ReadonlyArray<string>): string | undef
148 export const resolvePluginHintConfig = (argv: ReadonlyArray<string>) =>
149 Effect.gen(function* () {
150 const path = yield* Path.Path;
151 + const os = yield* NodeOs;
152 const cacheDir = yield* setupCacheDir;
153 const invocationOrigin = yield* APP_CONFIG.CLI_INVOCATION_ORIGIN;
154 const env = yield* rawHostEnvironment;
150 - const claudeConfigDir = yield* hostConfigDirectory('claude');
151 - const codexConfigDir = yield* hostConfigDirectory('codex');
155 return {
156 stateDirectory: path.join(cacheDir, 'plugin-hints'),
157 host: detectPluginHost(env),
158 invocationOrigin,
159 commandName: findRootCommandName(argv),
157 - claudeInstalledPluginsFile: path.join(claudeConfigDir, 'plugins', 'installed_plugins.json'),
158 - codexConfigFile: path.join(codexConfigDir, 'config.toml'),
160 + claudeInstalledPluginsFile: path.join(
161 + env.claudeConfigDir ?? path.join(os.homedir, '.claude'),
162 + 'plugins',
163 + 'installed_plugins.json'
164 + ),
165 + codexConfigFile: path.join(env.codexHome ?? path.join(os.homedir, '.codex'), 'config.toml'),
166 hintIntervalMs: HINT_INTERVAL_MS,
167 } satisfies PluginHintConfig;
168 });
@@ -166,4 +173,4 @@ export const showPluginAcquisitionHint = (argv: ReadonlyArray<string>) =>
173 const terminal = yield* TerminalUI;
174 const config = yield* resolvePluginHintConfig(argv);
175 yield* createPluginHint(config).showPluginHint(terminal);
169 - });
176 + }).pipe(Effect.provide(DefaultConfigLayers));
ts/packages/cli/src/services/setup-command-error.ts new
+17
@@ -0,0 +1,17 @@
1 +import { Data } from 'effect';
2 +
3 +export type SetupFailureReasonCode =
4 + | 'all_requires_both_hosts'
5 + | 'unsupported_host'
6 + | 'target_not_installed'
7 + | 'no_host_detected'
8 + | 'non_interactive_requires_yes'
9 + | 'marketplace_conflict'
10 + | 'unknown';
11 +
12 +export class SetupCommandError extends Data.TaggedError('services/SetupCommandError')<{
13 + readonly message: string;
14 + readonly operation: 'setup' | 'uninstall';
15 + readonly reasonCode: SetupFailureReasonCode;
16 + readonly cause?: unknown;
17 +}> {}
ts/packages/cli/src/services/setup.ts
+1 -16
@@ -16,6 +16,7 @@ import {
16 } from './agent-host';
17 import { probeHostInstallation } from './agent-host-env';
18 import { CommandRunner, type CommandResult } from './command-runner';
19 +import { SetupCommandError } from './setup-command-error';
20 import { SetupSkillInstaller } from './setup-skill-installer';
21 import { cliInvocationContext } from './runtime-cli-context';
22
@@ -132,22 +133,6 @@ const ADAPTER_LIST = Object.values(ADAPTERS);
133 const SETUP_COMMAND_TIMEOUT = '2 minutes';
134 const MINIMUM_CODEX_SETUP_VERSION = '0.139.0';
135
135 -export type SetupFailureReasonCode =
136 - | 'all_requires_both_hosts'
137 - | 'unsupported_host'
138 - | 'target_not_installed'
139 - | 'no_host_detected'
140 - | 'non_interactive_requires_yes'
141 - | 'marketplace_conflict'
142 - | 'unknown';
143 -
144 -export class SetupCommandError extends Data.TaggedError('services/SetupCommandError')<{
145 - readonly message: string;
146 - readonly operation: 'setup' | 'uninstall';
147 - readonly reasonCode: SetupFailureReasonCode;
148 - readonly cause?: unknown;
149 -}> {}
150 -
136 type SetupFailureStage = 'detect' | 'inspect' | 'validate' | 'mutate' | 'verify' | 'skill';
137
138 export class SetupProcessError extends Data.TaggedError('services/SetupProcessError')<{
ts/packages/cli/test/src/analytics.dispatch.test.ts
+23 -1
@@ -295,6 +295,9 @@ describe('CLI analytics dispatch', () => {
295 const home = tempy.temporaryDirectory();
296 const scriptPath = `${home}/composio.ts`;
297 enableTelemetry();
298 + vi.stubEnv('CLAUDECODE', '');
299 + vi.stubEnv('CODEX_THREAD_ID', '');
300 + vi.stubEnv('CODEX_SANDBOX', '');
301 process.argv[1] = scriptPath;
302
303 return Effect.gen(function* () {
@@ -316,7 +319,7 @@ describe('CLI analytics dispatch', () => {
319 expect(args).toHaveLength(3);
320 expect(decodeWorkerPayload(args[2]!)).toMatchObject({
321 event: 'producer_event',
319 - properties: { cli_version: APP_VERSION, sample: 'value' },
322 + properties: { cli_version: APP_VERSION, sample: 'value', agent_host_env: 'none' },
323 source: 'cli',
324 });
325 expect(options).toMatchObject({
@@ -329,6 +332,25 @@ describe('CLI analytics dispatch', () => {
332 }).pipe(Effect.provide(makePlatformLayer(home)));
333 });
334
335 + it.effect('stamps the enqueued envelope with the agent host it runs under', () => {
336 + const home = tempy.temporaryDirectory();
337 + const scriptPath = `${home}/composio.ts`;
338 + enableTelemetry();
339 + vi.stubEnv('CLAUDECODE', '1');
340 + process.argv[1] = scriptPath;
341 +
342 + return Effect.gen(function* () {
343 + const fs = yield* FileSystem.FileSystem;
344 + yield* fs.writeFileString(scriptPath, '');
345 + yield* trackCliEventEffect({ name: 'producer_event' });
346 +
347 + const [, args] = childProcessMocks.spawn.mock.calls[0] as unknown as [string, string[]];
348 + expect(decodeWorkerPayload(args[2]!)).toMatchObject({
349 + properties: { agent_host_env: 'claude' },
350 + });
351 + }).pipe(Effect.provide(makePlatformLayer(home)));
352 + });
353 +
354 it.effect('propagates telemetry debug to the detached worker without an env write', () => {
355 const home = tempy.temporaryDirectory();
356 const scriptPath = `${home}/composio.ts`;
ts/packages/cli/test/src/analytics.events.test.ts
+1 -43
@@ -11,7 +11,6 @@ import {
11 CLI_ANALYTICS_EVENTS,
12 CLI_EVENT_JOURNEY_STAGES,
13 CLI_JOURNEY_STAGES,
14 - configureCliAnalyticsAgentHostEnv,
14 configureCliAnalyticsReleaseVersion,
15 createCliCommandTelemetryContext,
16 getPluginHintShownEvent,
@@ -36,7 +35,7 @@ import {
35 DEFAULT_CLI_INVOCATION_ORIGIN,
36 type CliInvocationContext,
37 } from 'src/services/runtime-cli-context';
39 -import { SetupCommandError } from 'src/services/setup';
38 +import { SetupCommandError } from 'src/services/setup-command-error';
39 import { ToolInputValidationError } from 'src/services/tool-input-validation';
40 import { resolveInstalledCliVersion } from 'src/services/run-companion-modules';
41
@@ -358,7 +357,6 @@ describe('CLI analytics setup runtime-context events', () => {
357 agent_host: 'claude',
358 journey_stage: 'setup',
359 cli_channel: inferSkillReleaseChannel(APP_VERSION),
361 - agent_host_env: 'none',
360 },
361 });
362 });
@@ -479,46 +477,6 @@ describe('CLI analytics setup runtime-context events', () => {
477 });
478 });
479
482 -describe('CLI analytics agent host environment', () => {
483 - afterEach(() => {
484 - configureCliAnalyticsAgentHostEnv('none');
485 - });
486 -
487 - const contextFor = (argv: ReadonlyArray<string>) =>
488 - createCliCommandTelemetryContext(
489 - ['bun', 'composio', ...argv],
490 - APP_VERSION,
491 - { stdoutIsTTY: false, stderrIsTTY: false },
492 - CLI_INVOCATION
493 - );
494 -
495 - it('stamps every event with none until a host is configured', () => {
496 - expect(
497 - getPrimaryLifecycleInvokedEvent(contextFor(['whoami']))?.properties?.agent_host_env
498 - ).toBe('none');
499 - });
500 -
501 - it('stamps lifecycle and standalone events with the configured host', () => {
502 - configureCliAnalyticsAgentHostEnv('codex');
503 -
504 - expect(
505 - getPrimaryLifecycleInvokedEvent(contextFor(['whoami']))?.properties?.agent_host_env
506 - ).toBe('codex');
507 - expect(
508 - getPrimaryLifecycleFailedEvent(contextFor(['setup']), new Error('boom'))?.properties
509 - ?.agent_host_env
510 - ).toBe('codex');
511 - expect(
512 - getSetupSkippedEvent({
513 - operation: 'setup',
514 - requestedTarget: 'auto',
515 - invocationOrigin: DEFAULT_CLI_INVOCATION_ORIGIN,
516 - cliVersion: APP_VERSION,
517 - })?.properties?.agent_host_env
518 - ).toBe('codex');
519 - });
520 -});
521 -
480 describe('CLI analytics journey taxonomy', () => {
481 afterEach(() => {
482 configureCliAnalyticsReleaseVersion(APP_VERSION);
ts/packages/cli/test/src/commands/setup.cmd.test.ts
+2 -1
@@ -5,7 +5,8 @@ import { ChildProcess, ChildProcessSpawner } from 'effect/unstable/process';
5 import { afterEach, vi } from 'vitest';
6 import { SkillInstallError } from 'src/effects/install-skill';
7 import { CommandRunner } from 'src/services/command-runner';
8 -import { SetupCommandError, SetupProcessError } from 'src/services/setup';
8 +import { SetupProcessError } from 'src/services/setup';
9 +import { SetupCommandError } from 'src/services/setup-command-error';
10 import { SetupSkillInstaller } from 'src/services/setup-skill-installer';
11 import { cli, MockConsole, TestLive } from 'test/__utils__';
12