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
fix(cli): throttle plugin hints per host
Kshitij Jhunjhunwala committed
Jul 29, 2026 at 15:43 UTC
5ab7dbbcc357ffabfddddcf9b1599566895ca711
2 files changed
+95
-17
ts/packages/cli/src/services/plugin-hint.ts
+68
-15
@@ -37,12 +37,53 @@ export function detectPluginHost(markers: HostEnvMarkers): PluginHost | undefine
37
}
38
39
export interface PluginHintState {
40
- lastHintShown: string; // ISO-8601
40
+ readonly lastHintShown: {
41
+ readonly claude?: string; // ISO-8601
42
+ readonly codex?: string; // ISO-8601
43
+ };
44
}
45
46
+const CurrentPluginHintStateSchema = Schema.Struct({
47
+ lastHintShown: Schema.Struct({
48
+ claude: Schema.optional(Schema.String),
49
+ codex: Schema.optional(Schema.String),
50
+ }),
51
+});
52
+
53
+const LegacyPluginHintStateSchema = Schema.Struct({
54
+ lastHintShown: Schema.String,
55
+});
56
+
57
const PluginHintStateSchema = Schema.parseJson(
58
+ Schema.Union(CurrentPluginHintStateSchema, LegacyPluginHintStateSchema)
59
+);
60
+
61
+const normalizePluginHintState = (
62
+ state:
63
+ | Schema.Schema.Type<typeof CurrentPluginHintStateSchema>
64
+ | {
65
+ readonly lastHintShown: string;
66
+ }
67
+): PluginHintState => {
68
+ const lastHintShown = state.lastHintShown;
69
+ if (typeof lastHintShown === 'string') {
70
+ return {
71
+ // Preserve the legacy global throttle during migration.
72
+ lastHintShown: {
73
+ claude: lastHintShown,
74
+ codex: lastHintShown,
75
+ },
76
+ };
77
+ }
78
+ return { lastHintShown };
79
+};
80
+
81
+const PluginHintStateOutputSchema = Schema.parseJson(
82
Schema.Struct({
45
- lastHintShown: Schema.String,
83
+ lastHintShown: Schema.Struct({
84
+ claude: Schema.optional(Schema.String),
85
+ codex: Schema.optional(Schema.String),
86
+ }),
87
})
88
);
89
@@ -65,20 +106,32 @@ export function createPluginHint(config: PluginHintConfig) {
106
const readState = Effect.gen(function* () {
107
const fs = yield* FileSystem.FileSystem;
108
const rawState = yield* fs.readFileString(config.stateFile);
68
- return yield* Schema.decodeUnknown(PluginHintStateSchema)(rawState);
69
- });
70
-
71
- const writeState = Effect.gen(function* () {
72
- const fs = yield* FileSystem.FileSystem;
73
- const path = yield* Path.Path;
74
- const state: PluginHintState = { lastHintShown: new Date().toISOString() };
75
- yield* fs.makeDirectory(path.dirname(config.stateFile), { recursive: true });
76
- yield* fs.writeFileString(config.stateFile, JSON.stringify(state, null, 2));
109
+ return normalizePluginHintState(yield* Schema.decodeUnknown(PluginHintStateSchema)(rawState));
110
});
111
79
- const shownWithinInterval = (state: Option.Option<PluginHintState>): boolean => {
112
+ const writeState = (host: PluginHost, previous: Option.Option<PluginHintState>) =>
113
+ Effect.gen(function* () {
114
+ const fs = yield* FileSystem.FileSystem;
115
+ const path = yield* Path.Path;
116
+ const state: PluginHintState = {
117
+ lastHintShown: {
118
+ ...(Option.isSome(previous) ? previous.value.lastHintShown : {}),
119
+ [host]: new Date().toISOString(),
120
+ },
121
+ };
122
+ const encoded = yield* Schema.encode(PluginHintStateOutputSchema)(state);
123
+ yield* fs.makeDirectory(path.dirname(config.stateFile), { recursive: true });
124
+ yield* fs.writeFileString(config.stateFile, encoded);
125
+ });
126
+
127
+ const shownWithinInterval = (
128
+ state: Option.Option<PluginHintState>,
129
+ host: PluginHost
130
+ ): boolean => {
131
if (Option.isNone(state)) return false;
81
- const shownAt = new Date(state.value.lastHintShown).getTime();
132
+ const lastHintShown = state.value.lastHintShown[host];
133
+ if (lastHintShown === undefined) return false;
134
+ const shownAt = new Date(lastHintShown).getTime();
135
if (!Number.isFinite(shownAt)) return false;
136
return Date.now() - shownAt < config.hintIntervalMs;
137
};
@@ -118,10 +171,10 @@ export function createPluginHint(config: PluginHintConfig) {
171
if (config.host === undefined) return;
172
if (config.invocationOrigin === 'run') return;
173
const state = yield* Effect.option(readState);
121
- if (shownWithinInterval(state)) return;
174
+ if (shownWithinInterval(state, config.host)) return;
175
const absent = yield* pluginAbsentByHost[config.host];
176
if (!absent) return;
124
- yield* writeState;
177
+ yield* writeState(config.host, state);
178
const label = HOST_LABELS[config.host];
179
yield* terminal.error(
180
`Tip: running under ${label} without the Composio plugin — 'composio setup' installs it.`
ts/packages/cli/test/src/services/plugin-hint.test.ts
+27
-2
@@ -210,7 +210,7 @@ describe('showPluginHint', () => {
210
it.effect('stays silent when the hint was shown within the interval', () =>
211
Effect.gen(function* () {
212
const config = makeConfig();
213
- writeHintState(config, { lastHintShown: new Date().toISOString() });
213
+ writeHintState(config, { lastHintShown: { claude: new Date().toISOString() } });
214
215
yield* createPluginHint(config).showPluginHint(makeTerminal(output));
216
@@ -221,7 +221,7 @@ describe('showPluginHint', () => {
221
it.effect('shows the hint again after the interval elapses', () =>
222
Effect.gen(function* () {
223
const config = makeConfig();
224
- writeHintState(config, { lastHintShown: '2000-01-01T00:00:00.000Z' });
224
+ writeHintState(config, { lastHintShown: { claude: '2000-01-01T00:00:00.000Z' } });
225
226
yield* createPluginHint(config).showPluginHint(makeTerminal(output));
227
@@ -229,6 +229,31 @@ describe('showPluginHint', () => {
229
}).pipe(Effect.provide(PlatformLayers))
230
);
231
232
+ it.effect('throttles Claude and Codex independently', () =>
233
+ Effect.gen(function* () {
234
+ const claudeConfig = makeConfig({ host: 'claude' });
235
+ const codexConfig = makeConfig({ host: 'codex' });
236
+
237
+ yield* createPluginHint(claudeConfig).showPluginHint(makeTerminal(output));
238
+ yield* createPluginHint(codexConfig).showPluginHint(makeTerminal(output));
239
+
240
+ expect(output).toHaveLength(2);
241
+ expect(output[0]).toContain('Claude Code');
242
+ expect(output[1]).toContain('Codex');
243
+ }).pipe(Effect.provide(PlatformLayers))
244
+ );
245
+
246
+ it.effect('honors the legacy global timestamp during state migration', () =>
247
+ Effect.gen(function* () {
248
+ const config = makeConfig({ host: 'codex' });
249
+ writeFileAt(config.stateFile, JSON.stringify({ lastHintShown: new Date().toISOString() }));
250
+
251
+ yield* createPluginHint(config).showPluginHint(makeTerminal(output));
252
+
253
+ expect(output).toEqual([]);
254
+ }).pipe(Effect.provide(PlatformLayers))
255
+ );
256
+
257
it.effect('shows the hint when the throttle state file is unreadable', () =>
258
Effect.gen(function* () {
259
const config = makeConfig();