1
import * as FileSystem from 'effect/FileSystem';
2
import * as Path from 'effect/Path';
3
-import * as BunFileSystem from '@effect/platform-bun/BunFileSystem';
4
-import { Config, ConfigProvider, Effect, Layer, Option, Schema } from 'effect';
3
+import { Effect, Option, Schema } from 'effect';
4
+import { trackCliEventEffect } from 'src/analytics/dispatch';
5
+import { getPluginHintShownEvent } from 'src/analytics/events';
6
import { APP_CONFIG } from 'src/effects/app-config';
7
import { setupCacheDir } from 'src/effects/setup-cache-dir';
8
+import { getVersion } from 'src/effects/version';
9
import { AGENT_HOST_LABELS, COMPOSIO_AGENT_PLUGIN_ID, type AgentHost } from './agent-host';
10
+import { detectPluginHost, hostConfigDirectory, rawHostEnvironment } from './agent-host-env';
11
import { NodeOs } from './node-os';
12
+import { cliInvocationContext } from './runtime-cli-context';
13
import { TerminalUI } from './terminal-ui';
14
15
/**
21
22
const HINT_INTERVAL_MS = 24 * 60 * 60 * 1000;
23
20
-export interface HostEnvMarkers {
21
- readonly claudeCode: string | undefined;
22
- readonly codexThreadId: string | undefined;
23
- readonly codexSandbox: string | undefined;
24
-}
25
-
26
-const isPresent = (value: string | undefined): boolean =>
27
- value !== undefined && value.trim().length > 0;
28
-
29
-const nonBlankOrUndefined = (value: string | undefined): string | undefined =>
30
- value === undefined || value.trim().length === 0 ? undefined : value;
31
-
32
-export function detectPluginHost(markers: HostEnvMarkers): AgentHost | undefined {
33
- if (isPresent(markers.claudeCode)) return 'claude';
34
- if (isPresent(markers.codexThreadId) || isPresent(markers.codexSandbox)) return 'codex';
35
- return undefined;
36
-}
37
-
24
const InstalledPluginsSchema = Schema.fromJsonString(
25
Schema.Struct({
26
plugins: Schema.Record(Schema.String, Schema.Array(Schema.Unknown)),
97
codex: codexPluginAbsent,
98
};
99
100
+ /** Resolves to `true` only when the hint line was actually printed. */
101
function showPluginHint(terminal: Pick<TerminalUI, 'error'>) {
102
return Effect.gen(function* () {
103
const host = config.host;
106
config.invocationOrigin === 'run' ||
107
config.commandName === 'setup'
108
) {
122
- return;
109
+ return false;
110
}
124
- if (!(yield* pluginAbsentByHost[host])) return;
125
- if (!(yield* claimHint(host))) return;
111
+ if (!(yield* pluginAbsentByHost[host])) return false;
112
+ if (!(yield* claimHint(host))) return false;
113
yield* terminal.error(
127
- `Tip: running under ${AGENT_HOST_LABELS[host]} without the Composio plugin — 'composio setup' installs it.`
114
+ `Tip: running under ${AGENT_HOST_LABELS[host]} without the Composio plugin — 'composio setup --yes' installs it.`
115
);
129
- }).pipe(Effect.ignore);
116
+ return true;
117
+ }).pipe(Effect.orElseSucceed(() => false));
118
}
119
120
return { showPluginHint };
121
}
122
135
-const DefaultConfigLayers = Layer.mergeAll(Path.layer, NodeOs.Default, BunFileSystem.layer);
136
-
137
-const readOptionalEnv = (name: string) =>
138
- Effect.orDie(Config.option(Config.string(name)).pipe(Config.map(Option.getOrUndefined)));
139
-
123
export function findRootCommandName(argv: ReadonlyArray<string>): string | undefined {
124
const args = argv.slice(2);
125
for (let index = 0; index < args.length; index += 1) {
136
return undefined;
137
}
138
156
-// Host-owned variables must bypass the CLI ConfigProvider, which prefixes
157
-// application keys with COMPOSIO_.
158
-const rawHostEnvironment = Effect.gen(function* () {
159
- const claudeCode = yield* readOptionalEnv('CLAUDECODE');
160
- const codexThreadId = yield* readOptionalEnv('CODEX_THREAD_ID');
161
- const codexSandbox = yield* readOptionalEnv('CODEX_SANDBOX');
162
- const claudeConfigDir = nonBlankOrUndefined(yield* readOptionalEnv('CLAUDE_CONFIG_DIR'));
163
- const codexHome = nonBlankOrUndefined(yield* readOptionalEnv('CODEX_HOME'));
164
- return {
165
- claudeCode,
166
- codexThreadId,
167
- codexSandbox,
168
- claudeConfigDir,
169
- codexHome,
170
- };
171
-}).pipe(
172
- // v4's fromEnv() snapshots the environment when the provider is built, so
173
- // build it per invocation to keep reading the live host environment.
174
- Effect.provideServiceEffect(
175
- ConfigProvider.ConfigProvider,
176
- Effect.sync(() => ConfigProvider.fromEnv())
177
- )
178
-);
179
-
139
export const resolvePluginHintConfig = (argv: ReadonlyArray<string>) =>
140
Effect.gen(function* () {
141
const path = yield* Path.Path;
143
const cacheDir = yield* setupCacheDir;
144
const invocationOrigin = yield* APP_CONFIG.CLI_INVOCATION_ORIGIN;
145
const env = yield* rawHostEnvironment;
146
+ const configDir = (host: AgentHost) =>
147
+ hostConfigDirectory({ host, env, homedir: os.homedir, join: path.join });
148
return {
149
stateDirectory: path.join(cacheDir, 'plugin-hints'),
150
host: detectPluginHost(env),
151
invocationOrigin,
152
commandName: findRootCommandName(argv),
153
claudeInstalledPluginsFile: path.join(
193
- env.claudeConfigDir ?? path.join(os.homedir, '.claude'),
154
+ configDir('claude'),
155
'plugins',
156
'installed_plugins.json'
157
),
197
- codexConfigFile: path.join(env.codexHome ?? path.join(os.homedir, '.codex'), 'config.toml'),
158
+ codexConfigFile: path.join(configDir('codex'), 'config.toml'),
159
hintIntervalMs: HINT_INTERVAL_MS,
160
} satisfies PluginHintConfig;
161
});
162
163
+const trackHintShown = (config: PluginHintConfig) =>
164
+ Effect.gen(function* () {
165
+ if (config.host === undefined) return;
166
+ const { invocationOrigin } = yield* cliInvocationContext;
167
+ yield* trackCliEventEffect(
168
+ getPluginHintShownEvent({
169
+ invocationOrigin,
170
+ cliVersion: yield* getVersion,
171
+ commandPath: config.commandName ?? 'composio',
172
+ agentHost: config.host,
173
+ })
174
+ );
175
+ }).pipe(Effect.ignore);
176
+
177
/** Print the plugin acquisition hint when eligible. Never fails, never blocks on network. */
178
export const showPluginAcquisitionHint = (argv: ReadonlyArray<string>) =>
179
Effect.gen(function* () {
180
const terminal = yield* TerminalUI;
181
const config = yield* resolvePluginHintConfig(argv);
207
- yield* createPluginHint(config).showPluginHint(terminal);
208
- }).pipe(Effect.provide(DefaultConfigLayers));
182
+ const shown = yield* createPluginHint(config).showPluginHint(terminal);
183
+ if (!shown) return;
184
+ yield* trackHintShown(config);
185
+ });