Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 77 lines 3.65 KB
Raw
1 import { Config } from 'effect';
2 import { hasEnvironmentRoot, optionalFlag, optionalString } from './env';
3
4 const agentPrefixSignals = Config.all({
5 codex: hasEnvironmentRoot('CODEX'),
6 claude: hasEnvironmentRoot('CLAUDE'),
7 openclaw: hasEnvironmentRoot('OPENCLAW'),
8 });
9
10 /**
11 * Facts about the process that launched the CLI: the shell, CI, the package manager, and the
12 * agent host (Claude Code, Codex, ...). Most of these variables are owned by other programs;
13 * the string-to-domain normalization lives here so consumers never inspect raw values.
14 */
15 export const HOST_CONFIG = {
16 // POSIX shell variables `composio install` edits rc files for
17 SHELL: optionalString('SHELL'),
18 PATH: optionalString('PATH'),
19
20 // The package manager that invoked the CLI, as reported by npm-compatible clients
21 NPM_CONFIG_USER_AGENT: optionalString('npm_config_user_agent'),
22
23 // https://no-color.org/
24 NO_COLOR: optionalString('NO_COLOR').pipe(Config.map(value => value !== undefined)),
25
26 // Output redaction is for recorded CI sessions and keys off the exact `CI=true` convention.
27 // `INTERACTIVE_PERMISSION_UI_DISABLED` below reads the same variable tolerantly because
28 // failing closed there is the safe reading of any non-falsy `CI` value.
29 CI_REDACTION_ENABLED: optionalString('CI').pipe(
30 Config.map(value => value?.toLowerCase() === 'true')
31 ),
32
33 // The browser approval page must never open from automated environments. The explicit
34 // COMPOSIO_DISABLE_PERMISSION_UI knob wins in both directions; without it, CI and Vitest
35 // runs disable the UI.
36 INTERACTIVE_PERMISSION_UI_DISABLED: Config.all({
37 explicit: optionalFlag('COMPOSIO_DISABLE_PERMISSION_UI'),
38 ci: optionalFlag('CI'),
39 vitest: optionalFlag('VITEST'),
40 }).pipe(Config.map(({ explicit, ci, vitest }) => explicit ?? (ci === true || vitest === true))),
41
42 // Markers and directories the agent hosts export to the processes they spawn
43 AGENT_HOST: Config.all({
44 claudeCode: optionalString('CLAUDECODE'),
45 codexThreadId: optionalString('CODEX_THREAD_ID'),
46 codexSandbox: optionalString('CODEX_SANDBOX'),
47 claudeConfigDir: optionalString('CLAUDE_CONFIG_DIR'),
48 codexHome: optionalString('CODEX_HOME'),
49 }),
50
51 // The agent chat this process runs in. The Composio plugin hook exports the first two as a
52 // pair; the other three are the hosts' own session variables, read when the hook exported
53 // nothing. `CODEX_THREAD_ID` is the same variable `AGENT_HOST` reads as a host marker.
54 AGENT_SESSION: Config.all({
55 hookHost: optionalString('COMPOSIO_AGENT_HOST'),
56 hookSessionId: optionalString('COMPOSIO_AGENT_SESSION_ID'),
57 claudeCodeSessionId: optionalString('CLAUDE_CODE_SESSION_ID'),
58 codexSessionId: optionalString('CODEX_SESSION_ID'),
59 codexThreadId: optionalString('CODEX_THREAD_ID'),
60 }),
61
62 // Which agent, if any, drives this process: any `CODEX*` / `CLAUDE*` variable counts
63 MASTER_SIGNALS: agentPrefixSignals.pipe(Config.map(({ codex, claude }) => ({ codex, claude }))),
64
65 // The agent asking for a tool permission: an explicit name beats the prefix signals
66 CALLER_AGENT_SIGNALS: Config.all({
67 explicit: Config.all({
68 callerAgent: optionalString('COMPOSIO_CALLER_AGENT'),
69 legacyAgent: optionalString('COMPOSIO_AGENT'),
70 }).pipe(Config.map(({ callerAgent, legacyAgent }) => callerAgent ?? legacyAgent)),
71 prefixes: agentPrefixSignals,
72 }).pipe(Config.map(({ explicit, prefixes }) => ({ explicit, ...prefixes }))),
73 };
74
75 export type AgentHostEnvironment = Config.Success<typeof HOST_CONFIG.AGENT_HOST>;
76 export type AgentSessionEnvironment = Config.Success<typeof HOST_CONFIG.AGENT_SESSION>;
77 export type CallerAgentSignals = Config.Success<typeof HOST_CONFIG.CALLER_AGENT_SIGNALS>;