Skip to content

Commit befa392

Browse files
committed
small refactor and prepare strategies
1 parent 90496a3 commit befa392

File tree

8 files changed

+25
-203
lines changed

8 files changed

+25
-203
lines changed

lib/core/strategies/deduplication.ts

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

lib/core/strategies/index.ts

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

lib/hooks.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { SessionState, WithParts } from "./state"
22
import type { Logger } from "./logger"
33
import type { PluginConfig } from "./config"
44
import { syncToolCache } from "./state/tool-cache"
5+
import { deduplicate } from "./strategies"
56

67

78
export function createChatMessageTransformHandler(
@@ -15,6 +16,9 @@ export function createChatMessageTransformHandler(
1516
output: { messages: WithParts[] }
1617
) => {
1718
syncToolCache(state, logger, output.messages);
19+
20+
deduplicate(state, logger, config, output.messages)
21+
pruneTool(state, logger, config, output.messages)
1822
}
1923
}
2024

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { readFileSync } from "fs"
22
import { join } from "path"
33

44
export function loadPrompt(name: string, vars?: Record<string, string>): string {
5-
const filePath = join(__dirname, "..", "prompts", `${name}.txt`)
5+
const filePath = join(__dirname, "prompts", `${name}.txt`)
66
let content = readFileSync(filePath, "utf8").trim()
77
if (vars) {
88
for (const [key, value] of Object.entries(vars)) {

lib/pruning-tool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ensureSessionInitialized } from "./state"
88
import { saveSessionState } from "./state/persistence"
99
import type { Logger } from "./logger"
1010
import { estimateTokensBatch } from "./tokenizer"
11-
import { loadPrompt } from "./core/prompt"
11+
import { loadPrompt } from "./prompt"
1212

1313
/** Tool description loaded from prompts/tool.txt */
1414
const TOOL_DESCRIPTION = loadPrompt("tool")

lib/state/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ export interface SessionStats {
2626
totalGCTools: number
2727
}
2828

29+
export interface Prune {
30+
toolIds: string[]
31+
}
32+
2933
export interface SessionState {
3034
sessionId: string | null
31-
prunedIds: string[]
35+
prune: Prune
3236
stats: SessionStats
3337
gcPending: GCStats
3438
toolParameters: Map<string, ToolParameterEntry>

lib/strategies/deduplication.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { PluginConfig } from "../config"
2+
import { Logger } from "../logger"
3+
import type { SessionState, WithParts } from "../state"
4+
5+
export const deduplicate = (
6+
state: SessionState,
7+
logger: Logger,
8+
config: PluginConfig,
9+
messages: WithParts[]
10+
) => {
11+
12+
}

lib/strategies/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { deduplicate } from "./deduplication"
2+

0 commit comments

Comments
 (0)