From 1114d5bffac79e8ab9baf76f61eb634dcafb1aa8 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Sat, 6 Dec 2025 20:21:30 -0500 Subject: [PATCH] Consolidate strategy types and remove unused imports --- lib/core/strategies/deduplication.ts | 2 +- lib/core/strategies/index.ts | 45 ++++++++++++++++++++++++++-- lib/core/strategies/types.ts | 43 -------------------------- lib/pruning-tool.ts | 4 +-- 4 files changed, 46 insertions(+), 48 deletions(-) delete mode 100644 lib/core/strategies/types.ts diff --git a/lib/core/strategies/deduplication.ts b/lib/core/strategies/deduplication.ts index bcc3c59..ace7b3f 100644 --- a/lib/core/strategies/deduplication.ts +++ b/lib/core/strategies/deduplication.ts @@ -1,5 +1,5 @@ import { extractParameterKey } from "../../ui/display-utils" -import type { PruningStrategy, StrategyResult, ToolMetadata } from "./types" +import type { PruningStrategy, StrategyResult, ToolMetadata } from "./index" /** * Deduplication strategy - prunes older tool calls that have identical diff --git a/lib/core/strategies/index.ts b/lib/core/strategies/index.ts index c6c9128..c2742e6 100644 --- a/lib/core/strategies/index.ts +++ b/lib/core/strategies/index.ts @@ -2,10 +2,51 @@ * Strategy runner - executes all enabled pruning strategies and collects results. */ -import type { PruningStrategy, StrategyResult, ToolMetadata } from "./types" import { deduplicationStrategy } from "./deduplication" -export type { PruningStrategy, StrategyResult, ToolMetadata, StrategyDetail } from "./types" +/** + * Common interface for rule-based pruning strategies. + * Each strategy analyzes tool metadata and returns IDs that should be pruned. + */ + +export interface ToolMetadata { + tool: string + parameters?: any +} + +export interface StrategyResult { + /** Tool call IDs that should be pruned */ + prunedIds: string[] + /** Optional details about what was pruned and why */ + details?: Map +} + +export interface StrategyDetail { + toolName: string + parameterKey: string + reason: string + /** Additional info specific to the strategy */ + [key: string]: any +} + +export interface PruningStrategy { + /** Unique identifier for this strategy */ + name: string + + /** + * Analyze tool metadata and determine which tool calls should be pruned. + * + * @param toolMetadata - Map of tool call ID to metadata (tool name + parameters) + * @param unprunedIds - Tool call IDs that haven't been pruned yet (chronological order) + * @param protectedTools - Tool names that should never be pruned + * @returns IDs to prune and optional details + */ + detect( + toolMetadata: Map, + unprunedIds: string[], + protectedTools: string[] + ): StrategyResult +} /** All available strategies */ const ALL_STRATEGIES: PruningStrategy[] = [ diff --git a/lib/core/strategies/types.ts b/lib/core/strategies/types.ts deleted file mode 100644 index a013a0d..0000000 --- a/lib/core/strategies/types.ts +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Common interface for rule-based pruning strategies. - * Each strategy analyzes tool metadata and returns IDs that should be pruned. - */ - -export interface ToolMetadata { - tool: string - parameters?: any -} - -export interface StrategyResult { - /** Tool call IDs that should be pruned */ - prunedIds: string[] - /** Optional details about what was pruned and why */ - details?: Map -} - -export interface StrategyDetail { - toolName: string - parameterKey: string - reason: string - /** Additional info specific to the strategy */ - [key: string]: any -} - -export interface PruningStrategy { - /** Unique identifier for this strategy */ - name: string - - /** - * Analyze tool metadata and determine which tool calls should be pruned. - * - * @param toolMetadata - Map of tool call ID to metadata (tool name + parameters) - * @param unprunedIds - Tool call IDs that haven't been pruned yet (chronological order) - * @param protectedTools - Tool names that should never be pruned - * @returns IDs to prune and optional details - */ - detect( - toolMetadata: Map, - unprunedIds: string[], - protectedTools: string[] - ): StrategyResult -} diff --git a/lib/pruning-tool.ts b/lib/pruning-tool.ts index b4e7354..dfa7fdc 100644 --- a/lib/pruning-tool.ts +++ b/lib/pruning-tool.ts @@ -5,7 +5,7 @@ import type { ToolTracker } from "./fetch-wrapper/tool-tracker" import { resetToolTrackerCount } from "./fetch-wrapper/tool-tracker" import { isSubagentSession } from "./hooks" import { getActualId } from "./state/id-mapping" -import { formatPruningResultForTool, sendUnifiedNotification, type NotificationContext } from "./ui/notification" +import { sendUnifiedNotification, type NotificationContext } from "./ui/notification" import { ensureSessionRestored } from "./state" import { saveSessionState } from "./state/persistence" import type { Logger } from "./logger" @@ -41,7 +41,7 @@ export function createPruningTool( ), }, async execute(args, toolCtx) { - const { client, state, logger, config, notificationCtx, workingDirectory } = ctx + const { client, state, logger, config, notificationCtx } = ctx const sessionId = toolCtx.sessionID if (await isSubagentSession(client, sessionId)) {