@devries-cameron20 / composio Mirror · read-only
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, 04:45 UTC

next
ts 151 lines 5.04 KB
Raw
1 import { commandInputError } from 'src/commands/errors';
2 import { Effect, Option } from 'effect';
3 import { Argument, Command } from 'effect/cli';
4 import { ComposioCliUserConfig } from 'src/services/cli-user-config';
5 import { TerminalUI } from 'src/services/terminal-ui';
6 import { NodeOs } from 'src/services/node-os';
7 import { CLI_EXPERIMENTAL_FEATURES } from 'src/constants';
8 import { discoverSkillRoots } from 'src/effects/discover-skill-roots';
9 import { buildComposioCliSkill } from '../../../skills-src/composio-cli/index';
10 import type { SkillFeatureFlag } from '../../../skills-src/composio-cli/reference-schema';
11
12 const knownFeatures: ReadonlyArray<SkillFeatureFlag> = Object.values(CLI_EXPERIMENTAL_FEATURES);
13
14 const invalidState = commandInputError('config experimental');
15
16 const featureArg = Argument.String('feature').pipe(
17 Argument.withDescription(
18 `Experimental feature name. Known features: ${knownFeatures.join(', ')}`
19 ),
20 Argument.optional
21 );
22
23 const stateArg = Argument.String('state').pipe(
24 Argument.withDescription('Set to "on" or "off"'),
25 Argument.optional
26 );
27
28 const rebuildSkill = Effect.gen(function* () {
29 const ui = yield* TerminalUI;
30 const os = yield* NodeOs;
31 const cliConfig = yield* ComposioCliUserConfig;
32 const home = os.homedir;
33
34 // Build the feature overrides from the current config
35 const featureOverrides: Partial<Record<SkillFeatureFlag, boolean>> = {};
36 for (const name of knownFeatures) {
37 featureOverrides[name] = cliConfig.isExperimentalFeatureEnabled(name);
38 }
39
40 const roots = yield* discoverSkillRoots(home);
41 for (const root of roots) {
42 yield* Effect.try(() =>
43 buildComposioCliSkill({
44 channel: cliConfig.channel,
45 outputRoot: root,
46 featureOverrides,
47 })
48 );
49 }
50
51 yield* ui.log.step(
52 roots.length === 1
53 ? `Rebuilt skill in ${roots[0]}`
54 : `Rebuilt skill in ${roots.length} locations`
55 );
56 });
57
58 export const configExperimentalCmd = Command.make(
59 'experimental',
60 { feature: featureArg, state: stateArg },
61 ({ feature, state }) =>
62 Effect.gen(function* () {
63 const ui = yield* TerminalUI;
64 const cliConfig = yield* ComposioCliUserConfig;
65
66 // No args: list all experimental features and their state
67 if (Option.isNone(feature)) {
68 const features = cliConfig.data.experimentalFeatures;
69 const lines: string[] = [];
70 for (const name of knownFeatures) {
71 const enabled = cliConfig.isExperimentalFeatureEnabled(name);
72 const configured = name in features;
73 const suffix = configured ? '' : ` (default, channel: ${cliConfig.channel})`;
74 lines.push(` ${name}: ${enabled ? 'on' : 'off'}${suffix}`);
75 }
76
77 // Show any custom features not in the known list
78 for (const [name, value] of Object.entries(features)) {
79 if (!knownFeatures.some(feature => feature === name)) {
80 lines.push(` ${name}: ${value ? 'on' : 'off'}`);
81 }
82 }
83
84 if (lines.length === 0) {
85 yield* ui.log.info('No experimental features available.');
86 } else {
87 yield* ui.note(lines.join('\n'), 'Experimental Features');
88 yield* ui.output(JSON.stringify(features));
89 }
90 return;
91 }
92
93 const featureName = feature.value;
94
95 // Feature name only: show current state
96 if (Option.isNone(state)) {
97 const enabled = cliConfig.isExperimentalFeatureEnabled(featureName);
98 yield* ui.log.info(`${featureName}: ${enabled ? 'on' : 'off'}`);
99 yield* ui.output(enabled ? 'on' : 'off');
100 return;
101 }
102
103 const stateValue = state.value.toLowerCase();
104 if (stateValue !== 'on' && stateValue !== 'off') {
105 return yield* Effect.fail(
106 invalidState(`Invalid state "${state.value}". Use "on" or "off".`, '<state>')
107 );
108 }
109
110 const enabled = stateValue === 'on';
111 yield* cliConfig.update({
112 experimentalFeatures: {
113 ...cliConfig.data.experimentalFeatures,
114 [featureName]: enabled,
115 },
116 });
117
118 yield* ui.log.success(`${featureName}: ${stateValue}`);
119
120 // Rebuild the skill so Claude Code picks up the new feature flags
121 yield* rebuildSkill.pipe(
122 Effect.tapError(error =>
123 Effect.all([
124 Effect.logDebug('Skill rebuild failed:', error),
125 ui.log.warn('Could not rebuild skill (non-fatal)'),
126 ])
127 ),
128 Effect.ignore
129 );
130
131 yield* ui.output(stateValue);
132 })
133 ).pipe(
134 Command.withDescription(
135 [
136 'View or toggle experimental feature flags.',
137 '',
138 'Usage:',
139 ' composio config experimental List all features',
140 ' composio config experimental <feature> Show current state',
141 ' composio config experimental <feature> on|off Enable or disable',
142 '',
143 `Known features: ${knownFeatures.join(', ')}`,
144 ].join('\n')
145 ),
146 Command.withExamples([
147 { command: 'composio config experimental' },
148 { command: 'composio config experimental listen on' },
149 { command: 'composio config experimental listen off' },
150 ])
151 );