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
5 changes: 3 additions & 2 deletions lib/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ export function createChatMessageTransformHandler(
logger: Logger,
config: PluginConfig
) {
return async(
return async (
input: {},
output: { messages: WithParts[] }
) => {
checkSession(client, state, logger, output.messages);
await checkSession(client, state, logger, output.messages)

if (state.isSubAgent) {
return
}
Expand Down
15 changes: 6 additions & 9 deletions lib/state/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { loadSessionState } from "./persistence"
import { getLastUserMessage } from "../messages/utils"
import { isSubAgentSession } from "../utils"

export const checkSession = (
export const checkSession = async (
client: any,
state: SessionState,
logger: Logger,
messages: WithParts[]
) => {
): Promise<void> => {

const lastUserMessage = getLastUserMessage(messages)
if (!lastUserMessage) {
Expand All @@ -20,14 +20,11 @@ export const checkSession = (

if (state.sessionId === null || state.sessionId !== lastSessionId) {
logger.info(`Session changed: ${state.sessionId} -> ${lastSessionId}`)
ensureSessionInitialized(
client,
state,
lastSessionId,
logger
).catch((err) => {
try {
await ensureSessionInitialized(client, state, lastSessionId, logger)
} catch (err: any) {
logger.error("Failed to initialize session state", { error: err.message })
} )
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/state/tool-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ const MAX_TOOL_CACHE_SIZE = 500

/**
* Sync tool parameters from OpenCode's session.messages() API.
* This is the single source of truth for tool parameters, replacing
* format-specific parsing from LLM API requests.
*/
export async function syncToolCache(
state: SessionState,
Expand All @@ -24,6 +22,8 @@ export async function syncToolCache(
continue
}

const alreadyPruned = state.prune.toolIds.includes(part.callID)

state.toolParameters.set(
part.callID,
{
Expand All @@ -35,7 +35,7 @@ export async function syncToolCache(
}
)

if (!config.strategies.pruneTool.protectedTools.includes(part.tool)) {
if (!alreadyPruned && !config.strategies.pruneTool.protectedTools.includes(part.tool)) {
state.nudgeCounter++
}

Expand Down