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): read user and CLI config from the cache dir in analytics
jkomynoa59b6480dd58
diff --git a/ts/packages/cli/src/analytics/dispatch.ts b/ts/packages/cli/src/analytics/dispatch.tsindex 812cacf33..63e3d213b 100644--- a/ts/packages/cli/src/analytics/dispatch.ts+++ b/ts/packages/cli/src/analytics/dispatch.ts@@ -157,8 +157,10 @@ const getAnalyticsPaths = Effect.gen(function* () {return {analyticsDir,analyticsStatePath: path.join(analyticsDir, ANALYTICS_STATE_FILE_NAME),- userConfigPath: path.join(analyticsDir, constants.USER_CONFIG_FILE_NAME),- cliConfigPath: path.join(analyticsDir, constants.CLI_CONFIG_FILE_NAME),+ // user_data.json and config.json live in the cache dir (setup-cache-dir.ts,+ // cli-user-config.ts), which COMPOSIO_CACHE_DIR relocates away from ~/.composio.+ userConfigPath: path.join(cacheDir, constants.USER_CONFIG_FILE_NAME),+ cliConfigPath: path.join(cacheDir, constants.CLI_CONFIG_FILE_NAME),consumerShortTermCachePath: path.join(cacheDir, CONSUMER_SHORT_TERM_CACHE_FILE_NAME),};});diff --git a/ts/packages/cli/test/src/analytics.dispatch.test.ts b/ts/packages/cli/test/src/analytics.dispatch.test.tsindex 1b346f73e..ec25149d7 100644--- a/ts/packages/cli/test/src/analytics.dispatch.test.ts+++ b/ts/packages/cli/test/src/analytics.dispatch.test.ts@@ -110,10 +110,8 @@ describe('CLI analytics dispatch', () => {return Effect.gen(function* () {const fs = yield* FileSystem.FileSystem;const path = yield* Path.Path;- const composioDir = path.join(home, '.composio');- yield* fs.makeDirectory(composioDir, { recursive: true });yield* fs.writeFileString(- path.join(composioDir, USER_CONFIG_FILE_NAME),+ path.join(cacheDir, USER_CONFIG_FILE_NAME),JSON.stringify({ base_url: 'https://backend.example.test///' }));yield* fs.writeFileString(@@ -739,6 +737,7 @@ describe('CLI analytics dispatch', () => {const home = tempy.temporaryDirectory();const scriptPath = `${home}/composio.ts`;enableTelemetry();+ vi.stubEnv('COMPOSIO_CACHE_DIR', `${home}/.composio`);process.argv[1] = scriptPath;return Effect.gen(function* () {@@ -760,6 +759,33 @@ describe('CLI analytics dispatch', () => {}).pipe(Effect.provide(makePlatformLayer(home)));});+ it.effect('reads the user config from COMPOSIO_CACHE_DIR rather than the homedir', () => {+ const home = tempy.temporaryDirectory();+ const cacheDir = tempy.temporaryDirectory();+ const scriptPath = `${home}/composio.ts`;+ enableTelemetry();+ vi.stubEnv('COMPOSIO_CACHE_DIR', cacheDir);+ process.argv[1] = scriptPath;++ return Effect.gen(function* () {+ const fs = yield* FileSystem.FileSystem;+ const path = yield* Path.Path;+ yield* fs.writeFileString(scriptPath, '');+ // The user config exists only in the relocated cache dir; ~/.composio+ // never receives a copy.+ yield* fs.writeFileString(+ path.join(cacheDir, USER_CONFIG_FILE_NAME),+ JSON.stringify({ api_key: 'uak_test', org_id: 'org_cache_dir' })+ );++ yield* trackCliEventEffect({ name: 'producer_event' });++ const args = childProcessMocks.spawn.mock.calls[0]![1] as string[];+ const payload = decodeWorkerPayload<{ properties?: { org_id?: string } }>(args[2]!);+ expect(payload.properties?.org_id).toBe('org_cache_dir');+ }).pipe(Effect.provide(makePlatformLayer(home)));+ });+it.effect('does not create the identity file when logging out with telemetry disabled', () => {const home = tempy.temporaryDirectory();enableTelemetry();@@ -823,6 +849,7 @@ describe('CLI analytics dispatch', () => {const scriptPath = `${home}/composio.ts`;// No env key and no plaintext api_key on disk -> no fingerprint.enableTelemetry('');+ vi.stubEnv('COMPOSIO_CACHE_DIR', `${home}/.composio`);process.argv[1] = scriptPath;return Effect.gen(function* () {@@ -861,6 +888,7 @@ describe('CLI analytics dispatch', () => {const home = tempy.temporaryDirectory();const scriptPath = `${home}/composio.ts`;enableTelemetry('');+ vi.stubEnv('COMPOSIO_CACHE_DIR', `${home}/.composio`);process.argv[1] = scriptPath;return Effect.gen(function* () {