@devries-cameron20 / composio Mirror · read-only / commits / 96516e3dd
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, 18:30 UTC

chore(cli): trim telemetry comments; bake PostHog key at build (not source)

Hygiene pass on the direct-to-PostHog telemetry: condense verbose block comments in dispatch.ts/constants.ts. Source the public write-only PostHog project key from a build-time COMPOSIO_POSTHOG_KEY env var, baked into the binary via `bun build --define` (scripts/_shared.ts posthogBakeArgs), instead of a committed source literal. This mirrors the dashboard's env-driven NEXT_PUBLIC_POSTHOG_TOKEN pattern and, for this OSS repo, keeps the key out of public git history and out of fork/local builds (they compile a no-op binary). `--define` is used rather than a second `--env` because Bun honors only one `--env` and it would clobber the existing DEBUG_OVERRIDE_* inline. CI passes the key as an Actions variable on the cross-compile step; empty -> telemetry no-ops. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Kshitij Jhunjhunwala committed Jul 22, 2026 at 18:48 UTC 96516e3dd5edbac1abe1284535402f292ddeeaf3
7 files changed +73 -79
.github/workflows/build-cli-binaries.yml
+5
@@ -132,6 +132,11 @@ jobs:
132
133 - name: Cross-compile CLI binary
134 working-directory: ts/packages/cli
135 + env:
136 + # Public, write-only PostHog project key (project 196278), baked into
137 + # the released binary via `--define`. Not a secret — an Actions
138 + # *variable* so only official builds carry it and forks stay no-op.
139 + COMPOSIO_POSTHOG_KEY: ${{ vars.COMPOSIO_POSTHOG_KEY }}
140 run: pnpm build:binary:cross --target ${{ matrix.target }}
141
142 - name: Verify binary
ts/packages/cli/scripts/_shared.ts
+9
@@ -51,6 +51,15 @@ const copyBundledAcpAdapters = async (outputDir: string): Promise<void> => {
51
52 export const LOCAL_TOOLS_BINARY_ASSET_DIRNAME = 'local-tools-binaries';
53
54 +// Bakes the public PostHog write key from the build-time COMPOSIO_POSTHOG_KEY
55 +// env var into the compiled binary (mirrors the dashboard's NEXT_PUBLIC baking).
56 +// Empty when unset -> telemetry is a no-op. Kept out of --env so it doesn't
57 +// clobber the DEBUG_OVERRIDE_* inline (Bun honors only the last --env).
58 +export const posthogBakeArgs = (): ReadonlyArray<string> => {
59 + const key = process.env.COMPOSIO_POSTHOG_KEY?.trim();
60 + return key ? ['--define', `COMPOSIO_POSTHOG_KEY_BAKED=${JSON.stringify(key)}`] : [];
61 +};
62 +
63 const localToolsBinaryAssetsSourceDir = (): string =>
64 path.resolve(process.cwd(), '../cli-local-tools', LOCAL_TOOLS_BINARY_ASSET_DIRNAME);
65
ts/packages/cli/scripts/build-all-binaries.ts
+10 -5
@@ -15,7 +15,12 @@
15 import { Config, ConfigProvider, Console, Effect, Stream, Logger, Layer, LogLevel } from 'effect';
16 import { Command } from '@effect/platform';
17 import { BunContext, BunRuntime } from '@effect/platform-bun';
18 -import { buildCompanionModules, copyLocalToolBinaryAssets, teardown } from './_shared';
18 +import {
19 + buildCompanionModules,
20 + copyLocalToolBinaryAssets,
21 + posthogBakeArgs,
22 + teardown,
23 +} from './_shared';
24 import { BinaryBuildError } from './build-error';
25
26 /**
@@ -30,21 +35,21 @@ const TARGETS = [
35
36 function runBunBuild(target: string, outfile: string) {
37 return Effect.gen(function* () {
33 - const args = [
34 - 'bun',
38 + const args: ReadonlyArray<string> = [
39 'build',
40 './src/bin.ts',
41 '--env',
42 'DEBUG_OVERRIDE_*',
43 + ...posthogBakeArgs(),
44 '--compile',
45 '--production',
46 '--target',
47 target,
48 '--outfile',
49 outfile,
45 - ] as const satisfies ReadonlyArray<string>;
50 + ];
51
47 - const cmd = Command.make(...args);
52 + const cmd = Command.make('bun', ...args);
53
54 const { exitCode } = yield* cmd.pipe(
55 Command.start,
ts/packages/cli/scripts/build-binary-cross.ts
+10 -5
@@ -18,7 +18,12 @@ import process from 'node:process';
18 import { Config, ConfigProvider, Console, Effect, Stream, Logger, Layer, LogLevel } from 'effect';
19 import { Command } from '@effect/platform';
20 import { BunContext, BunRuntime } from '@effect/platform-bun';
21 -import { buildCompanionModules, copyLocalToolBinaryAssets, teardown } from './_shared';
21 +import {
22 + buildCompanionModules,
23 + copyLocalToolBinaryAssets,
24 + posthogBakeArgs,
25 + teardown,
26 +} from './_shared';
27 import { BinaryBuildError } from './build-error';
28
29 /**
@@ -61,21 +66,21 @@ export function buildBinaryCross() {
66
67 const outfile = `./dist/binaries/${artifact}`;
68
64 - const args = [
65 - 'bun',
69 + const args: ReadonlyArray<string> = [
70 'build',
71 './src/bin.ts',
72 '--env',
73 'DEBUG_OVERRIDE_*',
74 + ...posthogBakeArgs(),
75 '--compile',
76 '--production',
77 '--target',
78 target,
79 '--outfile',
80 outfile,
76 - ] as const satisfies ReadonlyArray<string>;
81 + ];
82
78 - const cmd = Command.make(...args);
83 + const cmd = Command.make('bun', ...args);
84
85 yield* Effect.logDebug('Running build command with', args.join(' '), '');
86
ts/packages/cli/scripts/build-binary.ts
+12 -20
@@ -2,7 +2,12 @@ import process from 'node:process';
2 import { Config, ConfigProvider, Console, Effect, Stream, Logger, Layer, LogLevel } from 'effect';
3 import { Command } from '@effect/platform';
4 import { BunContext, BunRuntime } from '@effect/platform-bun';
5 -import { buildCompanionModules, copyLocalToolBinaryAssets, teardown } from './_shared';
5 +import {
6 + buildCompanionModules,
7 + copyLocalToolBinaryAssets,
8 + posthogBakeArgs,
9 + teardown,
10 +} from './_shared';
11 import { BinaryBuildError } from './build-error';
12
13 /**
@@ -13,34 +18,21 @@ export function buildBinary() {
18 const cwd = process.cwd();
19 yield* Effect.logDebug(`Building binary in ${cwd}`);
20
16 - const args = [
17 - 'bun',
18 - /**
19 - * Transpile and bundle the CLI app.
20 - */
21 + // `--env DEBUG_OVERRIDE_*` inlines matching env vars; the PostHog key is
22 + // baked via `--define` instead (Bun honors only the last `--env`).
23 + const args: ReadonlyArray<string> = [
24 'build',
25 './src/bin.ts',
23 -
24 - /**
25 - * Statically inline any environment variable that matches `DEBUG_OVERRIDE_*`.
26 - */
26 '--env',
27 'DEBUG_OVERRIDE_*',
29 -
30 - /**
31 - * Generate a standalone Bun executable containing your bundled code.
32 - */
28 + ...posthogBakeArgs(),
29 '--compile',
30 '--production',
35 -
36 - /**
37 - * Output file destination.
38 - */
31 '--outfile',
32 './dist/composio',
41 - ] as const satisfies ReadonlyArray<string>;
33 + ];
34
43 - const cmd = Command.make(...args);
35 + const cmd = Command.make('bun', ...args);
36
37 yield* Effect.logDebug('Running build command with', args.join(' '), '');
38
ts/packages/cli/src/analytics/dispatch.ts
+14 -32
@@ -25,8 +25,6 @@ const ANALYTICS_STATE_FILE_NAME = 'analytics.json';
25 const CONSUMER_SHORT_TERM_CACHE_FILE_NAME = 'consumer-short-term-cache.json';
26 const CLI_CODACT_FAILURES_PATH = '/api/v3/cli/codact_failures';
27
28 -// PostHog's single-event capture endpoint expects `$create_alias` to merge an
29 -// anonymous person into an identified one (`properties.alias` -> `distinct_id`).
28 const POSTHOG_ALIAS_EVENT = '$create_alias';
29 const POSTHOG_LIB = 'composio-cli';
30
@@ -102,10 +100,8 @@ const analyticsDisabled = environmentProvider.load(
100 )
101 );
102
105 -// Resolves the direct-to-PostHog transport target. Both fields fall back to the
106 -// embedded constants; env overrides exist for tests and staging. Crucially this
107 -// does NOT depend on the Composio API base URL (which is only written at login),
108 -// so pre-login install/setup events can be delivered.
103 +// Direct-to-PostHog target; env overrides fall back to the embedded constants.
104 +// No dependency on the API base URL, so pre-login events can send.
105 const getPostHogConfig = environmentProvider
106 .load(
107 Config.all({
@@ -175,9 +171,8 @@ const readOptionalJson = <A>(filePath: string) =>
171 return (yield* decodeJson(raw)) as A;
172 }).pipe(Effect.catchAll(() => Effect.succeed(undefined)));
173
178 -// Persisted `~/.composio/analytics.json`. `install_id` is the anonymous device
179 -// UUID; `apollo_user_id` (the Apollo `org_member.id`, persisted at login) becomes
180 -// the PostHog identity so CLI events join the same person as web onboarding.
174 +// `install_id` = anonymous device UUID; `apollo_user_id` = Apollo `org_member.id`
175 +// persisted at login, used as the PostHog identity post-login.
176 type AnalyticsState = {
177 readonly install_id?: string;
178 readonly apollo_user_id?: string;
@@ -221,9 +216,7 @@ const readApolloUserId = Effect.map(readAnalyticsState, state =>
216 : null
217 );
218
224 -// Persists the Apollo `org_member.id` into the analytics state, preserving the
225 -// existing `install_id`/`created_at` so the anonymous device identity is kept
226 -// for the login-time alias. Best-effort: never surfaces or throws.
219 +// Persists the Apollo `org_member.id`, preserving `install_id`/`created_at`.
220 const persistApolloUserId = (installId: string, apolloUserId: string) =>
221 Effect.gen(function* () {
222 const fs = yield* FileSystem.FileSystem;
@@ -263,10 +256,8 @@ const getUserApiKey = Effect.gen(function* () {
256 : null;
257 });
258
266 -// Post-login events key on the Apollo `org_member.id` (persisted at login) so
267 -// they resolve to the same PostHog person as web onboarding. Pre-login, the raw
268 -// `install_id` is the distinct id (NOT wrapped as `anon_<id>` — the login-time
269 -// `$create_alias` merges this exact value into the Apollo person).
259 +// Post-login: the Apollo `org_member.id`. Pre-login: the raw `install_id` (the
260 +// login-time `$create_alias` merges this exact value into the Apollo person).
261 const getDistinctId = (installId: string) =>
262 Effect.map(readApolloUserId, apolloUserId => apolloUserId ?? installId);
263
@@ -360,11 +351,8 @@ const spawnWorker = (command: string, args: ReadonlyArray<string>) =>
351 );
352 });
353
363 -// Shapes an analytics envelope into a PostHog single-event capture body. The
364 -// public project write key authenticates the ingest in-band (no user API key),
365 -// which is what lets pre-login events send. Only allowlisted, already-shaped
366 -// properties from the event builders flow through here — no secrets or tool-arg
367 -// values (see events.ts).
354 +// Shapes an envelope into a PostHog capture body. The public project key
355 +// authenticates the ingest in-band — no user API key, so pre-login events send.
356 const buildPostHogBody = (envelope: AnalyticsEnvelope, projectKey: string) => ({
357 api_key: projectKey,
358 event: envelope.event,
@@ -504,8 +492,7 @@ const captureToComposioCodactFailures = (failure: CliCodactFailure) =>
492 });
493 });
494
507 -// Encodes an envelope and hands it to the detached best-effort worker, which
508 -// delivers it directly to PostHog. Shared by event tracking and login aliasing.
495 +// Hands an envelope to the detached best-effort worker for PostHog delivery.
496 const enqueuePostHogEnvelope = (envelope: AnalyticsEnvelope) =>
497 Effect.gen(function* () {
498 yield* telemetryDebugLog('enqueue', { envelope });
@@ -524,9 +511,6 @@ export const trackCliEventEffect = (event: TrackEvent) =>
511 return;
512 }
513
527 - // The direct PostHog transport carries a fixed endpoint + embedded public
528 - // key, so — unlike the old Apollo path — there is no base-URL gate here and
529 - // pre-login install/setup events are delivered.
514 const disabled = yield* analyticsDisabled;
515 if (disabled) {
516 yield* telemetryDebugLog('skip', { reason: 'disabled', eventName: event.name });
@@ -553,8 +537,7 @@ export const trackCliEventEffect = (event: TrackEvent) =>
537 yield* enqueuePostHogEnvelope(envelope);
538 }).pipe(Effect.catchAllCause(() => Effect.void));
539
556 -// Fires a single PostHog `$create_alias` merging the anonymous `install_id`
557 -// device person into the identified Apollo `org_member.id` person. Best-effort.
540 +// Fires one `$create_alias` merging the `install_id` device into the Apollo person.
541 export const emitPostHogAlias = (installId: string, apolloUserId: string) =>
542 Effect.gen(function* () {
543 const disabled = yield* analyticsDisabled;
@@ -567,7 +550,7 @@ export const emitPostHogAlias = (installId: string, apolloUserId: string) =>
550 const envelope: AnalyticsEnvelope = {
551 event: POSTHOG_ALIAS_EVENT,
552 properties: {
570 - // PostHog merges `properties.alias` into the event's `distinct_id`.
553 + // PostHog merges `alias` into `distinct_id`.
554 distinct_id: apolloUserId,
555 alias: installId,
556 cli_version: constants.APP_VERSION,
@@ -580,9 +563,8 @@ export const emitPostHogAlias = (installId: string, apolloUserId: string) =>
563 yield* enqueuePostHogEnvelope(envelope);
564 }).pipe(Effect.catchAllCause(() => Effect.void));
565
583 -// Called at login: persists the Apollo `org_member.id` as the analytics identity
584 -// and stitches the pre-login anonymous device into that person via one alias.
585 -// Fully non-fatal so login never fails on telemetry.
566 +// Called at login: persist the Apollo identity and alias the device into it.
567 +// Non-fatal so login never fails on telemetry.
568 export const linkApolloIdentityForAnalytics = (apolloUserId: string) =>
569 Effect.gen(function* () {
570 if (typeof apolloUserId !== 'string' || apolloUserId.trim().length === 0) {
ts/packages/cli/src/constants.ts
+13 -17
@@ -78,28 +78,24 @@ export const PROJECT_ENV_FILE_NAME = '.env';
78 export const PROJECT_COMPOSIO_DIR = '.composio';
79
80 /**
81 - * PostHog ingest endpoint the CLI sends telemetry directly to.
82 - *
83 - * This is the public single-event capture API. It does not depend on the
84 - * Composio API base URL, so pre-login install/setup events can be delivered
85 - * before the user has ever authenticated. Overridable via the
86 - * `COMPOSIO_POSTHOG_INGEST_URL` environment variable (used by tests / staging).
81 + * PostHog single-event capture endpoint for direct CLI telemetry. Overridable
82 + * via `COMPOSIO_POSTHOG_INGEST_URL` (tests / staging).
83 */
84 export const COMPOSIO_POSTHOG_INGEST_URL = 'https://us.i.posthog.com/i/v0/e/';
85
86 +// Injected at build time from the COMPOSIO_POSTHOG_KEY env var via `--define`
87 +// (see scripts/_shared.ts `posthogBakeArgs`); undefined in dev/test.
88 +declare const COMPOSIO_POSTHOG_KEY_BAKED: string | undefined;
89 +
90 /**
91 - * Public, write-only PostHog project write key for project 196278
92 - * ("Composio Platform"). This is client-embeddable by design (same trust model
93 - * as the dashboard JS bundle): it can only ingest events, never read them.
94 - *
95 - * Overridable via the `COMPOSIO_POSTHOG_KEY` environment variable.
96 - *
97 - * TODO(kj): fill in the real public `phc_*` project-196278 write key from the
98 - * PostHog project settings. While this is empty, direct PostHog delivery is a
99 - * safe no-op (the transport skips when no key is configured). Do NOT commit a
100 - * real token into tests or fixtures.
91 + * Public, write-only PostHog project write key (project 196278). Client-
92 + * embeddable by design — it can only ingest events, never read them — same as
93 + * the dashboard's `NEXT_PUBLIC_POSTHOG_TOKEN`. Sourced from the build-time
94 + * bake, overridable at runtime via `COMPOSIO_POSTHOG_KEY`. Empty -> telemetry
95 + * is a no-op.
96 */
102 -export const COMPOSIO_POSTHOG_PROJECT_KEY = '';
97 +export const COMPOSIO_POSTHOG_PROJECT_KEY =
98 + typeof COMPOSIO_POSTHOG_KEY_BAKED === 'string' ? COMPOSIO_POSTHOG_KEY_BAKED : '';
99
100 /**
101 * GitHub repository information for release fetching