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: 4 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ const plugin: Plugin = (async (ctx) => {

// Check for updates after a delay
setTimeout(() => {
checkForUpdates(ctx.client, logger).catch(() => { })
checkForUpdates(ctx.client, logger, {
showToast: config.showUpdateToasts ?? true,
autoUpdate: config.autoUpdate ?? false
}).catch(() => { })
}, 5000)

// Show migration toast if there were config migrations
Expand Down
14 changes: 14 additions & 0 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export interface PluginConfig {
protectedTools: string[]
model?: string
showModelErrorToasts?: boolean
showUpdateToasts?: boolean
autoUpdate?: boolean
strictModelSelection?: boolean
pruning_summary: "off" | "minimal" | "detailed"
nudge_freq: number
Expand All @@ -32,6 +34,8 @@ const defaultConfig: PluginConfig = {
debug: false,
protectedTools: ['task', 'todowrite', 'todoread', 'prune', 'batch', 'edit', 'write'],
showModelErrorToasts: true,
showUpdateToasts: true,
autoUpdate: false,
strictModelSelection: false,
pruning_summary: 'detailed',
nudge_freq: 10,
Expand All @@ -47,6 +51,8 @@ const VALID_CONFIG_KEYS = new Set([
'protectedTools',
'model',
'showModelErrorToasts',
'showUpdateToasts',
'autoUpdate',
'strictModelSelection',
'pruning_summary',
'nudge_freq',
Expand Down Expand Up @@ -110,6 +116,10 @@ function createDefaultConfig(): void {
// "model": "anthropic/claude-haiku-4-5",
// Show toast notifications when model selection fails
"showModelErrorToasts": true,
// Show toast notifications when a new version is available
"showUpdateToasts": true,
// Automatically update to new versions (restart required to apply)
"autoUpdate": false,
// Only run AI analysis with session model or configured model (disables fallback models)
"strictModelSelection": false,
// AI analysis strategies (deduplication runs automatically on every request)
Expand Down Expand Up @@ -199,6 +209,8 @@ export function getConfig(ctx?: PluginInput): ConfigResult {
protectedTools: [...new Set([...config.protectedTools, ...(globalConfig.protectedTools ?? [])])],
model: globalConfig.model ?? config.model,
showModelErrorToasts: globalConfig.showModelErrorToasts ?? config.showModelErrorToasts,
showUpdateToasts: globalConfig.showUpdateToasts ?? config.showUpdateToasts,
autoUpdate: globalConfig.autoUpdate ?? config.autoUpdate,
strictModelSelection: globalConfig.strictModelSelection ?? config.strictModelSelection,
strategies: mergeStrategies(config.strategies, globalConfig.strategies as any),
pruning_summary: globalConfig.pruning_summary ?? config.pruning_summary,
Expand Down Expand Up @@ -230,6 +242,8 @@ export function getConfig(ctx?: PluginInput): ConfigResult {
protectedTools: [...new Set([...config.protectedTools, ...(projectConfig.protectedTools ?? [])])],
model: projectConfig.model ?? config.model,
showModelErrorToasts: projectConfig.showModelErrorToasts ?? config.showModelErrorToasts,
showUpdateToasts: projectConfig.showUpdateToasts ?? config.showUpdateToasts,
autoUpdate: projectConfig.autoUpdate ?? config.autoUpdate,
strictModelSelection: projectConfig.strictModelSelection ?? config.strictModelSelection,
strategies: mergeStrategies(config.strategies, projectConfig.strategies as any),
pruning_summary: projectConfig.pruning_summary ?? config.pruning_summary,
Expand Down
48 changes: 31 additions & 17 deletions lib/version-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,11 @@ export function updateConfigVersion(newVersion: string, logger?: { info: (compon

export async function checkForUpdates(
client: any,
logger?: { info: (component: string, message: string, data?: any) => void }
logger?: { info: (component: string, message: string, data?: any) => void },
options: { showToast?: boolean; autoUpdate?: boolean } = {}
): Promise<void> {
const { showToast = true, autoUpdate = false } = options

try {
const local = getLocalVersion()
const npm = await getNpmVersion()
Expand All @@ -125,22 +128,33 @@ export async function checkForUpdates(
return
}

logger?.info("version", "Update available", { local, npm })

// Update any configs found
const updated = updateConfigVersion(npm, logger)

if (updated) {
await client.tui.showToast({
body: {
title: "DCP: Update available",
message: `v${local} → v${npm}\nRestart OpenCode to apply`,
variant: "info",
duration: 6000
}
})
} else {
// Config update failed or plugin not found in config, show manual instructions
logger?.info("version", "Update available", { local, npm, autoUpdate })

if (autoUpdate) {
// Attempt config update
const updated = updateConfigVersion(npm, logger)

if (updated && showToast) {
await client.tui.showToast({
body: {
title: "DCP: Updated!",
message: `v${local} → v${npm}\nRestart OpenCode to apply`,
variant: "success",
duration: 6000
}
})
} else if (!updated && showToast) {
// Config update failed or plugin not found in config, show manual instructions
await client.tui.showToast({
body: {
title: "DCP: Update available",
message: `v${local} → v${npm}\nUpdate opencode.jsonc:\n"${PACKAGE_NAME}@${npm}"`,
variant: "info",
duration: 8000
}
})
}
} else if (showToast) {
await client.tui.showToast({
body: {
title: "DCP: Update available",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@tarquinen/opencode-dcp",
"version": "0.4.9",
"version": "0.4.10",
"type": "module",
"description": "OpenCode plugin that optimizes token usage by pruning obsolete tool outputs from conversation context",
"main": "./dist/index.js",
Expand Down