Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/core/strategies/deduplication.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
45 changes: 43 additions & 2 deletions lib/core/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, StrategyDetail>
}

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<string, ToolMetadata>,
unprunedIds: string[],
protectedTools: string[]
): StrategyResult
}

/** All available strategies */
const ALL_STRATEGIES: PruningStrategy[] = [
Expand Down
43 changes: 0 additions & 43 deletions lib/core/strategies/types.ts

This file was deleted.

4 changes: 2 additions & 2 deletions lib/pruning-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)) {
Expand Down