Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
fix(cli): throttle plugin hints per host
Kshitij Jhunjhunwala5ab7dbbcc357
diff --git a/ts/packages/cli/src/services/plugin-hint.ts b/ts/packages/cli/src/services/plugin-hint.tsindex 4bbadd52f..99ab8a6f2 100644--- a/ts/packages/cli/src/services/plugin-hint.ts+++ b/ts/packages/cli/src/services/plugin-hint.ts@@ -37,12 +37,53 @@ export function detectPluginHost(markers: HostEnvMarkers): PluginHost | undefine}export interface PluginHintState {- lastHintShown: string; // ISO-8601+ readonly lastHintShown: {+ readonly claude?: string; // ISO-8601+ readonly codex?: string; // ISO-8601+ };}+const CurrentPluginHintStateSchema = Schema.Struct({+ lastHintShown: Schema.Struct({+ claude: Schema.optional(Schema.String),+ codex: Schema.optional(Schema.String),+ }),+});++const LegacyPluginHintStateSchema = Schema.Struct({+ lastHintShown: Schema.String,+});+const PluginHintStateSchema = Schema.parseJson(+ Schema.Union(CurrentPluginHintStateSchema, LegacyPluginHintStateSchema)+);++const normalizePluginHintState = (+ state:+ | Schema.Schema.Type<typeof CurrentPluginHintStateSchema>+ | {+ readonly lastHintShown: string;+ }+): PluginHintState => {+ const lastHintShown = state.lastHintShown;+ if (typeof lastHintShown === 'string') {+ return {+ // Preserve the legacy global throttle during migration.+ lastHintShown: {+ claude: lastHintShown,+ codex: lastHintShown,+ },+ };+ }+ return { lastHintShown };+};++const PluginHintStateOutputSchema = Schema.parseJson(Schema.Struct({- lastHintShown: Schema.String,+ lastHintShown: Schema.Struct({+ claude: Schema.optional(Schema.String),+ codex: Schema.optional(Schema.String),+ }),}));@@ -65,20 +106,32 @@ export function createPluginHint(config: PluginHintConfig) {const readState = Effect.gen(function* () {const fs = yield* FileSystem.FileSystem;const rawState = yield* fs.readFileString(config.stateFile);- return yield* Schema.decodeUnknown(PluginHintStateSchema)(rawState);- });-- const writeState = Effect.gen(function* () {- const fs = yield* FileSystem.FileSystem;- const path = yield* Path.Path;- const state: PluginHintState = { lastHintShown: new Date().toISOString() };- yield* fs.makeDirectory(path.dirname(config.stateFile), { recursive: true });- yield* fs.writeFileString(config.stateFile, JSON.stringify(state, null, 2));+ return normalizePluginHintState(yield* Schema.decodeUnknown(PluginHintStateSchema)(rawState));});- const shownWithinInterval = (state: Option.Option<PluginHintState>): boolean => {+ const writeState = (host: PluginHost, previous: Option.Option<PluginHintState>) =>+ Effect.gen(function* () {+ const fs = yield* FileSystem.FileSystem;+ const path = yield* Path.Path;+ const state: PluginHintState = {+ lastHintShown: {+ ...(Option.isSome(previous) ? previous.value.lastHintShown : {}),+ [host]: new Date().toISOString(),+ },+ };+ const encoded = yield* Schema.encode(PluginHintStateOutputSchema)(state);+ yield* fs.makeDirectory(path.dirname(config.stateFile), { recursive: true });+ yield* fs.writeFileString(config.stateFile, encoded);+ });++ const shownWithinInterval = (+ state: Option.Option<PluginHintState>,+ host: PluginHost+ ): boolean => {if (Option.isNone(state)) return false;- const shownAt = new Date(state.value.lastHintShown).getTime();+ const lastHintShown = state.value.lastHintShown[host];+ if (lastHintShown === undefined) return false;+ const shownAt = new Date(lastHintShown).getTime();if (!Number.isFinite(shownAt)) return false;return Date.now() - shownAt < config.hintIntervalMs;};@@ -118,10 +171,10 @@ export function createPluginHint(config: PluginHintConfig) {if (config.host === undefined) return;if (config.invocationOrigin === 'run') return;const state = yield* Effect.option(readState);- if (shownWithinInterval(state)) return;+ if (shownWithinInterval(state, config.host)) return;const absent = yield* pluginAbsentByHost[config.host];if (!absent) return;- yield* writeState;+ yield* writeState(config.host, state);const label = HOST_LABELS[config.host];yield* terminal.error(`Tip: running under ${label} without the Composio plugin — 'composio setup' installs it.`diff --git a/ts/packages/cli/test/src/services/plugin-hint.test.ts b/ts/packages/cli/test/src/services/plugin-hint.test.tsindex 527fea29c..613e6cc37 100644--- a/ts/packages/cli/test/src/services/plugin-hint.test.ts+++ b/ts/packages/cli/test/src/services/plugin-hint.test.ts@@ -210,7 +210,7 @@ describe('showPluginHint', () => {it.effect('stays silent when the hint was shown within the interval', () =>Effect.gen(function* () {const config = makeConfig();- writeHintState(config, { lastHintShown: new Date().toISOString() });+ writeHintState(config, { lastHintShown: { claude: new Date().toISOString() } });yield* createPluginHint(config).showPluginHint(makeTerminal(output));@@ -221,7 +221,7 @@ describe('showPluginHint', () => {it.effect('shows the hint again after the interval elapses', () =>Effect.gen(function* () {const config = makeConfig();- writeHintState(config, { lastHintShown: '2000-01-01T00:00:00.000Z' });+ writeHintState(config, { lastHintShown: { claude: '2000-01-01T00:00:00.000Z' } });yield* createPluginHint(config).showPluginHint(makeTerminal(output));@@ -229,6 +229,31 @@ describe('showPluginHint', () => {}).pipe(Effect.provide(PlatformLayers)));+ it.effect('throttles Claude and Codex independently', () =>+ Effect.gen(function* () {+ const claudeConfig = makeConfig({ host: 'claude' });+ const codexConfig = makeConfig({ host: 'codex' });++ yield* createPluginHint(claudeConfig).showPluginHint(makeTerminal(output));+ yield* createPluginHint(codexConfig).showPluginHint(makeTerminal(output));++ expect(output).toHaveLength(2);+ expect(output[0]).toContain('Claude Code');+ expect(output[1]).toContain('Codex');+ }).pipe(Effect.provide(PlatformLayers))+ );++ it.effect('honors the legacy global timestamp during state migration', () =>+ Effect.gen(function* () {+ const config = makeConfig({ host: 'codex' });+ writeFileAt(config.stateFile, JSON.stringify({ lastHintShown: new Date().toISOString() }));++ yield* createPluginHint(config).showPluginHint(makeTerminal(output));++ expect(output).toEqual([]);+ }).pipe(Effect.provide(PlatformLayers))+ );+it.effect('shows the hint when the throttle state file is unreadable', () =>Effect.gen(function* () {const config = makeConfig();