Skip to content

Commit 86c564d

Browse files
committed
chore: remove redundant comments
1 parent 035285f commit 86c564d

File tree

8 files changed

+3
-32
lines changed

8 files changed

+3
-32
lines changed

lib/fetch-wrapper/formats/gemini.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ export const geminiFormat: FormatDescriptor = {
5050
extractToolOutputs(data: any[], state: PluginState): ToolOutput[] {
5151
const outputs: ToolOutput[] = []
5252

53-
// We need the position mapping to correlate functionResponses to tool call IDs
54-
// Find the mapping from any active session
5553
let positionMapping: Map<string, string> | undefined
5654
for (const [_sessionId, mapping] of state.googleToolCallMapping) {
5755
if (mapping && mapping.size > 0) {
@@ -64,7 +62,6 @@ export const geminiFormat: FormatDescriptor = {
6462
return outputs
6563
}
6664

67-
// Track position counters per tool name
6865
const toolPositionCounters = new Map<string, number>()
6966

7067
for (const content of data) {
@@ -95,7 +92,6 @@ export const geminiFormat: FormatDescriptor = {
9592
},
9693

9794
replaceToolOutput(data: any[], toolId: string, prunedMessage: string, state: PluginState): boolean {
98-
// Find the position mapping
9995
let positionMapping: Map<string, string> | undefined
10096
for (const [_sessionId, mapping] of state.googleToolCallMapping) {
10197
if (mapping && mapping.size > 0) {

lib/fetch-wrapper/formats/openai-chat.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export const openaiChatFormat: FormatDescriptor = {
4949
const outputs: ToolOutput[] = []
5050

5151
for (const m of data) {
52-
// OpenAI Chat format: role='tool' with tool_call_id
5352
if (m.role === 'tool' && m.tool_call_id) {
5453
const metadata = state.toolParameters.get(m.tool_call_id.toLowerCase())
5554
outputs.push({
@@ -58,7 +57,6 @@ export const openaiChatFormat: FormatDescriptor = {
5857
})
5958
}
6059

61-
// Anthropic format: role='user' with content[].type='tool_result'
6260
if (m.role === 'user' && Array.isArray(m.content)) {
6361
for (const part of m.content) {
6462
if (part.type === 'tool_result' && part.tool_use_id) {
@@ -82,13 +80,11 @@ export const openaiChatFormat: FormatDescriptor = {
8280
for (let i = 0; i < data.length; i++) {
8381
const m = data[i]
8482

85-
// OpenAI Chat format
8683
if (m.role === 'tool' && m.tool_call_id?.toLowerCase() === toolIdLower) {
8784
data[i] = { ...m, content: prunedMessage }
8885
replaced = true
8986
}
9087

91-
// Anthropic format
9288
if (m.role === 'user' && Array.isArray(m.content)) {
9389
let messageModified = false
9490
const newContent = m.content.map((part: any) => {

lib/fetch-wrapper/handler.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ export async function handleFormat(
2929

3030
let modified = false
3131

32-
// Cache tool parameters for this format
3332
format.cacheToolParameters(data, ctx.state, ctx.logger)
3433

35-
// Inject synthetic instructions if strategies are enabled
3634
if (ctx.config.strategies.onTool.length > 0) {
3735
if (format.injectSynth(data, ctx.prompts.synthInstruction, ctx.prompts.nudgeInstruction)) {
3836
modified = true
@@ -70,25 +68,21 @@ export async function handleFormat(
7068
}
7169
}
7270

73-
// Check if there are any tool outputs to potentially prune
7471
if (!format.hasToolOutputs(data)) {
7572
return { modified, body }
7673
}
7774

78-
// Get all pruned IDs across sessions
7975
const { allSessions, allPrunedIds } = await getAllPrunedIds(ctx.client, ctx.state, ctx.logger)
8076

8177
if (allPrunedIds.size === 0) {
8278
return { modified, body }
8379
}
8480

85-
// Extract tool outputs and replace pruned ones
8681
const toolOutputs = format.extractToolOutputs(data, ctx.state)
8782
const protectedToolsLower = new Set(ctx.config.protectedTools.map(t => t.toLowerCase()))
8883
let replacedCount = 0
8984

9085
for (const output of toolOutputs) {
91-
// Skip protected tools
9286
if (output.toolName && protectedToolsLower.has(output.toolName.toLowerCase())) {
9387
continue
9488
}
@@ -106,7 +100,6 @@ export async function handleFormat(
106100
total: toolOutputs.length
107101
})
108102

109-
// Save context for debugging if logging is enabled
110103
if (ctx.logger.enabled) {
111104
const activeSessions = allSessions.data?.filter((s: any) => !s.parentID) || []
112105
let sessionMessages: any[] | undefined

lib/fetch-wrapper/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function installFetchWrapper(
5656

5757
const toolIdsBefore = new Set(state.toolParameters.keys())
5858

59-
// Mutually exclusive format handlers to avoid double-processing
59+
// Mutually exclusive format handlers
6060
if (openaiResponsesFormat.detect(body)) {
6161
const result = await handleFormat(body, ctx, inputUrl, openaiResponsesFormat)
6262
if (result.modified) {

lib/fetch-wrapper/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ export async function getAllPrunedIds(
9999
if (currentSession) {
100100
await ensureSessionRestored(state, currentSession.id, logger)
101101
const prunedIds = state.prunedIds.get(currentSession.id) ?? []
102-
// Normalize to lowercase for case-insensitive matching
103102
prunedIds.forEach((id: string) => allPrunedIds.add(id.toLowerCase()))
104103

105104
if (logger && prunedIds.length > 0) {

lib/hooks.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export function createEventHandler(
3232
if (await isSubagentSession(client, event.properties.sessionID)) return
3333
if (config.strategies.onIdle.length === 0) return
3434

35-
// Skip idle pruning if the last tool used was prune and idle strategies cover tool strategies
3635
if (toolTracker?.skipNextIdle) {
3736
toolTracker.skipNextIdle = false
3837
if (toolStrategiesCoveredByIdle(config.strategies.onIdle, config.strategies.onTool)) {
@@ -43,7 +42,6 @@ export function createEventHandler(
4342
try {
4443
const result = await runOnIdle(janitorCtx, event.properties.sessionID, config.strategies.onIdle)
4544

46-
// Reset nudge counter if idle pruning succeeded and covers tool strategies
4745
if (result && result.prunedCount > 0 && toolTracker && config.nudge_freq > 0) {
4846
if (toolStrategiesCoveredByIdle(config.strategies.onIdle, config.strategies.onTool)) {
4947
resetToolTrackerCount(toolTracker)
@@ -91,8 +89,7 @@ export function createChatParamsHandler(
9189
}
9290
}
9391

94-
// Build Google/Gemini tool call mapping for position-based correlation
95-
// This is needed because Google's native format loses tool call IDs
92+
// Build position-based mapping for Gemini (which loses tool call IDs in native format)
9693
if (providerID === 'google' || providerID === 'google-vertex') {
9794
try {
9895
const messagesResponse = await client.session.messages({
@@ -116,8 +113,6 @@ export function createChatParamsHandler(
116113
}
117114
toolCallsByName.get(toolName)!.push(callId)
118115

119-
// Also populate toolParameters for Gemini
120-
// This is needed for buildPrunableToolsList to work
121116
if (!state.toolParameters.has(callId)) {
122117
state.toolParameters.set(callId, {
123118
tool: part.tool,

lib/pruning-tool.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export function createPruningTool(
8686

8787
const toolMetadata = new Map<string, { tool: string, parameters?: any }>()
8888
for (const id of prunedIds) {
89-
// Look up with lowercase since all IDs are stored lowercase
9089
const meta = state.toolParameters.get(id.toLowerCase())
9190
if (meta) {
9291
toolMetadata.set(id.toLowerCase(), meta)
@@ -144,7 +143,6 @@ async function calculateTokensSaved(
144143
})
145144
const messages = messagesResponse.data || messagesResponse
146145

147-
// Build map of tool call ID -> output content
148146
const toolOutputs = new Map<string, string>()
149147
for (const msg of messages) {
150148
if (msg.role === 'tool' && msg.tool_call_id) {
@@ -153,7 +151,6 @@ async function calculateTokensSaved(
153151
: JSON.stringify(msg.content)
154152
toolOutputs.set(msg.tool_call_id.toLowerCase(), content)
155153
}
156-
// Handle Anthropic format
157154
if (msg.role === 'user' && Array.isArray(msg.content)) {
158155
for (const part of msg.content) {
159156
if (part.type === 'tool_result' && part.tool_use_id) {
@@ -166,7 +163,6 @@ async function calculateTokensSaved(
166163
}
167164
}
168165

169-
// Collect content for pruned outputs
170166
const contents: string[] = []
171167
for (const id of prunedIds) {
172168
const content = toolOutputs.get(id.toLowerCase())
@@ -176,14 +172,12 @@ async function calculateTokensSaved(
176172
}
177173

178174
if (contents.length === 0) {
179-
return prunedIds.length * 500 // fallback estimate
175+
return prunedIds.length * 500
180176
}
181177

182-
// Estimate tokens
183178
const tokenCounts = await estimateTokensBatch(contents)
184179
return tokenCounts.reduce((sum, count) => sum + count, 0)
185180
} catch (error: any) {
186-
// If we can't calculate, estimate based on average
187181
return prunedIds.length * 500
188182
}
189183
}

lib/state/tool-cache.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export function cacheToolParametersFromMessages(
3838
})
3939
openaiCached++
4040
} catch (error) {
41-
// Silently ignore parse errors
4241
}
4342
}
4443
}
@@ -93,7 +92,6 @@ export function cacheToolParametersFromInput(
9392
})
9493
cached++
9594
} catch (error) {
96-
// Silently ignore parse errors
9795
}
9896
}
9997

0 commit comments

Comments
 (0)