Skip to content

Commit 8023464

Browse files
authored
Merge pull request #79 from Tarquinen/refactor/consolidate-strategy-types
Consolidate strategy types and remove unused imports
2 parents 3a7088e + 1114d5b commit 8023464

File tree

4 files changed

+46
-48
lines changed

4 files changed

+46
-48
lines changed

lib/core/strategies/deduplication.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { extractParameterKey } from "../../ui/display-utils"
2-
import type { PruningStrategy, StrategyResult, ToolMetadata } from "./types"
2+
import type { PruningStrategy, StrategyResult, ToolMetadata } from "./index"
33

44
/**
55
* Deduplication strategy - prunes older tool calls that have identical

lib/core/strategies/index.ts

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,51 @@
22
* Strategy runner - executes all enabled pruning strategies and collects results.
33
*/
44

5-
import type { PruningStrategy, StrategyResult, ToolMetadata } from "./types"
65
import { deduplicationStrategy } from "./deduplication"
76

8-
export type { PruningStrategy, StrategyResult, ToolMetadata, StrategyDetail } from "./types"
7+
/**
8+
* Common interface for rule-based pruning strategies.
9+
* Each strategy analyzes tool metadata and returns IDs that should be pruned.
10+
*/
11+
12+
export interface ToolMetadata {
13+
tool: string
14+
parameters?: any
15+
}
16+
17+
export interface StrategyResult {
18+
/** Tool call IDs that should be pruned */
19+
prunedIds: string[]
20+
/** Optional details about what was pruned and why */
21+
details?: Map<string, StrategyDetail>
22+
}
23+
24+
export interface StrategyDetail {
25+
toolName: string
26+
parameterKey: string
27+
reason: string
28+
/** Additional info specific to the strategy */
29+
[key: string]: any
30+
}
31+
32+
export interface PruningStrategy {
33+
/** Unique identifier for this strategy */
34+
name: string
35+
36+
/**
37+
* Analyze tool metadata and determine which tool calls should be pruned.
38+
*
39+
* @param toolMetadata - Map of tool call ID to metadata (tool name + parameters)
40+
* @param unprunedIds - Tool call IDs that haven't been pruned yet (chronological order)
41+
* @param protectedTools - Tool names that should never be pruned
42+
* @returns IDs to prune and optional details
43+
*/
44+
detect(
45+
toolMetadata: Map<string, ToolMetadata>,
46+
unprunedIds: string[],
47+
protectedTools: string[]
48+
): StrategyResult
49+
}
950

1051
/** All available strategies */
1152
const ALL_STRATEGIES: PruningStrategy[] = [

lib/core/strategies/types.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.

lib/pruning-tool.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { ToolTracker } from "./fetch-wrapper/tool-tracker"
55
import { resetToolTrackerCount } from "./fetch-wrapper/tool-tracker"
66
import { isSubagentSession } from "./hooks"
77
import { getActualId } from "./state/id-mapping"
8-
import { formatPruningResultForTool, sendUnifiedNotification, type NotificationContext } from "./ui/notification"
8+
import { sendUnifiedNotification, type NotificationContext } from "./ui/notification"
99
import { ensureSessionRestored } from "./state"
1010
import { saveSessionState } from "./state/persistence"
1111
import type { Logger } from "./logger"
@@ -41,7 +41,7 @@ export function createPruningTool(
4141
),
4242
},
4343
async execute(args, toolCtx) {
44-
const { client, state, logger, config, notificationCtx, workingDirectory } = ctx
44+
const { client, state, logger, config, notificationCtx } = ctx
4545
const sessionId = toolCtx.sessionID
4646

4747
if (await isSubagentSession(client, sessionId)) {

0 commit comments

Comments
 (0)