Skip to content

Commit 53dbebd

Browse files
authored
Merge pull request #158 from Opencode-DCP/dev
merge dev into master
2 parents 12cfda2 + 3428541 commit 53dbebd

File tree

8 files changed

+29
-35
lines changed

8 files changed

+29
-35
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ DCP uses its own config file:
5858
"enabled": true,
5959
// Enable debug logging to ~/.config/opencode/logs/dcp/
6060
"debug": false,
61-
// Show toast notifications when a new version is available
62-
"showUpdateToasts": true,
6361
// Summary display: "off", "minimal", or "detailed"
6462
"pruningSummary": "detailed",
6563
// Strategies for pruning tokens from chat history

lib/config.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export interface PruneTool {
3131
export interface PluginConfig {
3232
enabled: boolean
3333
debug: boolean
34-
showUpdateToasts?: boolean
3534
pruningSummary: "off" | "minimal" | "detailed"
3635
strategies: {
3736
deduplication: Deduplication
@@ -47,7 +46,7 @@ export const VALID_CONFIG_KEYS = new Set([
4746
// Top-level keys
4847
'enabled',
4948
'debug',
50-
'showUpdateToasts',
49+
'showUpdateToasts', // Deprecated but kept for backwards compatibility
5150
'pruningSummary',
5251
'strategies',
5352
// strategies.deduplication
@@ -106,9 +105,6 @@ function validateConfigTypes(config: Record<string, any>): ValidationError[] {
106105
if (config.debug !== undefined && typeof config.debug !== 'boolean') {
107106
errors.push({ key: 'debug', expected: 'boolean', actual: typeof config.debug })
108107
}
109-
if (config.showUpdateToasts !== undefined && typeof config.showUpdateToasts !== 'boolean') {
110-
errors.push({ key: 'showUpdateToasts', expected: 'boolean', actual: typeof config.showUpdateToasts })
111-
}
112108
if (config.pruningSummary !== undefined) {
113109
const validValues = ['off', 'minimal', 'detailed']
114110
if (!validValues.includes(config.pruningSummary)) {
@@ -217,7 +213,6 @@ function showConfigValidationWarnings(
217213
const defaultConfig: PluginConfig = {
218214
enabled: true,
219215
debug: false,
220-
showUpdateToasts: true,
221216
pruningSummary: 'detailed',
222217
strategies: {
223218
deduplication: {
@@ -310,8 +305,6 @@ function createDefaultConfig(): void {
310305
"enabled": true,
311306
// Enable debug logging to ~/.config/opencode/logs/dcp/
312307
"debug": false,
313-
// Show toast notifications when a new version is available
314-
"showUpdateToasts": true,
315308
// Summary display: "off", "minimal", or "detailed"
316309
"pruningSummary": "detailed",
317310
// Strategies for pruning tokens from chat history
@@ -468,7 +461,6 @@ export function getConfig(ctx: PluginInput): PluginConfig {
468461
config = {
469462
enabled: result.data.enabled ?? config.enabled,
470463
debug: result.data.debug ?? config.debug,
471-
showUpdateToasts: result.data.showUpdateToasts ?? config.showUpdateToasts,
472464
pruningSummary: result.data.pruningSummary ?? config.pruningSummary,
473465
strategies: mergeStrategies(config.strategies, result.data.strategies as any)
474466
}
@@ -500,7 +492,6 @@ export function getConfig(ctx: PluginInput): PluginConfig {
500492
config = {
501493
enabled: result.data.enabled ?? config.enabled,
502494
debug: result.data.debug ?? config.debug,
503-
showUpdateToasts: result.data.showUpdateToasts ?? config.showUpdateToasts,
504495
pruningSummary: result.data.pruningSummary ?? config.pruningSummary,
505496
strategies: mergeStrategies(config.strategies, result.data.strategies as any)
506497
}
@@ -529,7 +520,6 @@ export function getConfig(ctx: PluginInput): PluginConfig {
529520
config = {
530521
enabled: result.data.enabled ?? config.enabled,
531522
debug: result.data.debug ?? config.debug,
532-
showUpdateToasts: result.data.showUpdateToasts ?? config.showUpdateToasts,
533523
pruningSummary: result.data.pruningSummary ?? config.pruningSummary,
534524
strategies: mergeStrategies(config.strategies, result.data.strategies as any)
535525
}

lib/hooks.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ export function createEventHandler(
4848
return
4949
}
5050

51-
if (event.type === "session.compacted") {
52-
logger.info("Session compaction detected - updating state")
53-
state.lastCompaction = Date.now()
54-
}
55-
5651
if (event.type === "session.status" && event.properties.status.type === "idle") {
5752
if (!config.strategies.onIdle.enabled) {
5853
return

lib/messages/prune.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ const buildPrunableToolsList = (
2727
return
2828
}
2929
const numericId = toolIdList.indexOf(toolCallId)
30+
if (numericId === -1) {
31+
logger.warn(`Tool in cache but not in toolIdList - possible stale entry`, { toolCallId, tool: toolParameterEntry.tool })
32+
return
33+
}
3034
const paramKey = extractParameterKey(toolParameterEntry.tool, toolParameterEntry.parameters)
3135
const description = paramKey ? `${toolParameterEntry.tool}, ${paramKey}` : toolParameterEntry.tool
3236
lines.push(`${numericId}: ${description}`)

lib/shared-utils.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Logger } from "./logger"
21
import { SessionState, WithParts } from "./state"
32

43
export const isMessageCompacted = (
@@ -20,12 +19,4 @@ export const getLastUserMessage = (
2019
return null
2120
}
2221

23-
export const checkForCompaction = (
24-
state: SessionState,
25-
messages: WithParts[],
26-
logger: Logger
27-
): void => {
28-
for (const msg of messages) {
2922

30-
}
31-
}

lib/state/persistence.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export interface PersistedSessionState {
1616
prune: Prune
1717
stats: SessionStats;
1818
lastUpdated: string;
19-
lastCompacted: number
2019
}
2120

2221
const STORAGE_DIR = join(
@@ -55,8 +54,7 @@ export async function saveSessionState(
5554
sessionName: sessionName,
5655
prune: sessionState.prune,
5756
stats: sessionState.stats,
58-
lastUpdated: new Date().toISOString(),
59-
lastCompacted: sessionState.lastCompaction
57+
lastUpdated: new Date().toISOString()
6058
};
6159

6260
const filePath = getSessionFilePath(sessionState.sessionId);

lib/state/state.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,19 @@ export const checkSession = async (
2121
if (state.sessionId === null || state.sessionId !== lastSessionId) {
2222
logger.info(`Session changed: ${state.sessionId} -> ${lastSessionId}`)
2323
try {
24-
await ensureSessionInitialized(client, state, lastSessionId, logger)
24+
await ensureSessionInitialized(client, state, lastSessionId, logger, messages)
2525
} catch (err: any) {
2626
logger.error("Failed to initialize session state", { error: err.message })
2727
}
2828
}
29+
30+
const lastCompactionTimestamp = findLastCompactionTimestamp(messages)
31+
if (lastCompactionTimestamp > state.lastCompaction) {
32+
state.lastCompaction = lastCompactionTimestamp
33+
state.toolParameters.clear()
34+
state.prune.toolIds = []
35+
logger.info("Detected compaction from messages - cleared tool cache", { timestamp: lastCompactionTimestamp })
36+
}
2937
}
3038

3139
export function createSessionState(): SessionState {
@@ -66,7 +74,8 @@ export async function ensureSessionInitialized(
6674
client: any,
6775
state: SessionState,
6876
sessionId: string,
69-
logger: Logger
77+
logger: Logger,
78+
messages: WithParts[]
7079
): Promise<void> {
7180
if (state.sessionId === sessionId) {
7281
return;
@@ -97,5 +106,14 @@ export async function ensureSessionInitialized(
97106
pruneTokenCounter: persisted.stats?.pruneTokenCounter || 0,
98107
totalPruneTokens: persisted.stats?.totalPruneTokens || 0,
99108
}
100-
state.lastCompaction = persisted.lastCompacted || 0
109+
}
110+
111+
function findLastCompactionTimestamp(messages: WithParts[]): number {
112+
for (let i = messages.length - 1; i >= 0; i--) {
113+
const msg = messages[i]
114+
if (msg.info.role === "assistant" && msg.info.summary === true) {
115+
return msg.info.time.created
116+
}
117+
}
118+
return 0
101119
}

lib/strategies/prune-tool.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ export function createPruneTool(
6666
return "No numeric IDs provided. Format: [reason, id1, id2, ...] where reason is 'completion', 'noise', or 'consolidation'."
6767
}
6868

69-
await ensureSessionInitialized(ctx.client, state, sessionId, logger)
70-
7169
// Fetch messages to calculate tokens and find current agent
7270
const messagesResponse = await client.session.messages({
7371
path: { id: sessionId }
7472
})
7573
const messages: WithParts[] = messagesResponse.data || messagesResponse
7674

75+
await ensureSessionInitialized(ctx.client, state, sessionId, logger, messages)
76+
7777
const currentParams = getCurrentParams(messages, logger)
7878
const toolIdList: string[] = buildToolIdList(state, messages, logger)
7979

0 commit comments

Comments
 (0)