Skip to content

Commit 0643888

Browse files
committed
refactor: update all consumers to use new config paths
1 parent f51109e commit 0643888

File tree

5 files changed

+20
-39
lines changed

5 files changed

+20
-39
lines changed

index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ const plugin: Plugin = (async (ctx) => {
2727

2828
return {
2929
"experimental.chat.system.transform": async (_input: unknown, output: { system: string[] }) => {
30-
const discardEnabled = config.strategies.discardTool.enabled
31-
const extractEnabled = config.strategies.extractTool.enabled
30+
const discardEnabled = config.tools.discard.enabled
31+
const extractEnabled = config.tools.extract.enabled
3232

3333
let promptName: string
3434
if (discardEnabled && extractEnabled) {
@@ -51,7 +51,7 @@ const plugin: Plugin = (async (ctx) => {
5151
config
5252
),
5353
tool: {
54-
...(config.strategies.discardTool.enabled && {
54+
...(config.tools.discard.enabled && {
5555
discard: createDiscardTool({
5656
client: ctx.client,
5757
state,
@@ -60,7 +60,7 @@ const plugin: Plugin = (async (ctx) => {
6060
workingDirectory: ctx.directory
6161
}),
6262
}),
63-
...(config.strategies.extractTool.enabled && {
63+
...(config.tools.extract.enabled && {
6464
extract: createExtractTool({
6565
client: ctx.client,
6666
state,
@@ -74,8 +74,8 @@ const plugin: Plugin = (async (ctx) => {
7474
// Add enabled tools to primary_tools by mutating the opencode config
7575
// This works because config is cached and passed by reference
7676
const toolsToAdd: string[] = []
77-
if (config.strategies.discardTool.enabled) toolsToAdd.push("discard")
78-
if (config.strategies.extractTool.enabled) toolsToAdd.push("extract")
77+
if (config.tools.discard.enabled) toolsToAdd.push("discard")
78+
if (config.tools.extract.enabled) toolsToAdd.push("extract")
7979

8080
if (toolsToAdd.length > 0) {
8181
const existingPrimaryTools = opencodeConfig.experimental?.primary_tools ?? []

lib/messages/prune.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { UserMessage } from "@opencode-ai/sdk"
99
const PRUNED_TOOL_INPUT_REPLACEMENT = '[Input removed to save context]'
1010
const PRUNED_TOOL_OUTPUT_REPLACEMENT = '[Output removed to save context - information superseded or no longer needed]'
1111
const getNudgeString = (config: PluginConfig): string => {
12-
const discardEnabled = config.strategies.discardTool.enabled
13-
const extractEnabled = config.strategies.extractTool.enabled
12+
const discardEnabled = config.tools.discard.enabled
13+
const extractEnabled = config.tools.extract.enabled
1414

1515
if (discardEnabled && extractEnabled) {
1616
return loadPrompt("nudge/nudge-both")
@@ -28,8 +28,8 @@ ${content}
2828
</prunable-tools>`
2929

3030
const getCooldownMessage = (config: PluginConfig): string => {
31-
const discardEnabled = config.strategies.discardTool.enabled
32-
const extractEnabled = config.strategies.extractTool.enabled
31+
const discardEnabled = config.tools.discard.enabled
32+
const extractEnabled = config.tools.extract.enabled
3333

3434
let toolName: string
3535
if (discardEnabled && extractEnabled) {
@@ -61,10 +61,7 @@ const buildPrunableToolsList = (
6161
if (state.prune.toolIds.includes(toolCallId)) {
6262
return
6363
}
64-
const allProtectedTools = [
65-
...config.strategies.discardTool.protectedTools,
66-
...config.strategies.extractTool.protectedTools
67-
]
64+
const allProtectedTools = config.tools.settings.protectedTools
6865
if (allProtectedTools.includes(toolParameterEntry.tool)) {
6966
return
7067
}
@@ -92,7 +89,7 @@ export const insertPruneToolContext = (
9289
logger: Logger,
9390
messages: WithParts[]
9491
): void => {
95-
if (!config.strategies.discardTool.enabled && !config.strategies.extractTool.enabled) {
92+
if (!config.tools.discard.enabled && !config.tools.extract.enabled) {
9693
return
9794
}
9895

@@ -115,13 +112,7 @@ export const insertPruneToolContext = (
115112
logger.debug("prunable-tools: \n" + prunableToolsList)
116113

117114
let nudgeString = ""
118-
// TODO: Using Math.min() means the lower frequency dominates when both tools are enabled.
119-
// Consider using separate counters for each tool's nudge, or documenting this behavior.
120-
const nudgeFrequency = Math.min(
121-
config.strategies.discardTool.nudge.frequency,
122-
config.strategies.extractTool.nudge.frequency
123-
)
124-
if (state.nudgeCounter >= nudgeFrequency) {
115+
if (config.tools.settings.nudgeEnabled && state.nudgeCounter >= config.tools.settings.nudgeFrequency) {
125116
logger.info("Inserting prune nudge message")
126117
nudgeString = "\n" + getNudgeString(config)
127118
}

lib/state/tool-cache.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,15 @@ export async function syncToolCache(
3535
continue
3636
}
3737

38-
const turnProtectionEnabled = config.strategies.discardTool.turnProtection.enabled ||
39-
config.strategies.extractTool.turnProtection.enabled
40-
const turnProtectionTurns = Math.max(
41-
config.strategies.discardTool.turnProtection.turns,
42-
config.strategies.extractTool.turnProtection.turns
43-
)
38+
const turnProtectionEnabled = config.turnProtection.enabled
39+
const turnProtectionTurns = config.turnProtection.turns
4440
const isProtectedByTurn = turnProtectionEnabled &&
4541
turnProtectionTurns > 0 &&
4642
(state.currentTurn - turnCounter) < turnProtectionTurns
4743

4844
state.lastToolPrune = part.tool === "discard" || part.tool === "extract"
4945

50-
const allProtectedTools = [
51-
...config.strategies.discardTool.protectedTools,
52-
...config.strategies.extractTool.protectedTools
53-
]
46+
const allProtectedTools = config.tools.settings.protectedTools
5447

5548
if (part.tool === "discard" || part.tool === "extract") {
5649
state.nudgeCounter = 0

lib/strategies/tools.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ async function executePruneOperation(
7676
logger.debug("Rejecting prune request - ID not in cache (turn-protected or hallucinated)", { index, id })
7777
return "Invalid IDs provided. Only use numeric IDs from the <prunable-tools> list."
7878
}
79-
const allProtectedTools = [
80-
...config.strategies.discardTool.protectedTools,
81-
...config.strategies.extractTool.protectedTools
82-
]
79+
const allProtectedTools = config.tools.settings.protectedTools
8380
if (allProtectedTools.includes(metadata.tool)) {
8481
logger.debug("Rejecting prune request - protected tool", { index, id, tool: metadata.tool })
8582
return "Invalid IDs provided. Only use numeric IDs from the <prunable-tools> list."
@@ -114,7 +111,7 @@ async function executePruneOperation(
114111
workingDirectory
115112
)
116113

117-
if (distillation && config.strategies.extractTool.showDistillation) {
114+
if (distillation && config.tools.extract.showDistillation) {
118115
await sendDistillationNotification(
119116
client,
120117
logger,

lib/ui/notification.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ export async function sendUnifiedNotification(
7070
return false
7171
}
7272

73-
if (config.pruningSummary === 'off') {
73+
if (config.pruneNotification === 'off') {
7474
return false
7575
}
7676

77-
const message = config.pruningSummary === 'minimal'
77+
const message = config.pruneNotification === 'minimal'
7878
? buildMinimalMessage(state, reason)
7979
: buildDetailedMessage(state, reason, pruneToolIds, toolMetadata, workingDirectory)
8080

0 commit comments

Comments
 (0)