diff --git a/index.ts b/index.ts index b8d8083..b7713e5 100644 --- a/index.ts +++ b/index.ts @@ -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 diff --git a/lib/config.ts b/lib/config.ts index 73e7060..02084d5 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -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 @@ -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, @@ -47,6 +51,8 @@ const VALID_CONFIG_KEYS = new Set([ 'protectedTools', 'model', 'showModelErrorToasts', + 'showUpdateToasts', + 'autoUpdate', 'strictModelSelection', 'pruning_summary', 'nudge_freq', @@ -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) @@ -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, @@ -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, diff --git a/lib/version-checker.ts b/lib/version-checker.ts index 191a85c..7e2bf71 100644 --- a/lib/version-checker.ts +++ b/lib/version-checker.ts @@ -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 { + const { showToast = true, autoUpdate = false } = options + try { const local = getLocalVersion() const npm = await getNpmVersion() @@ -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", diff --git a/package-lock.json b/package-lock.json index 218e35d..bea7dfb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@tarquinen/opencode-dcp", - "version": "0.4.9", + "version": "0.4.10", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@tarquinen/opencode-dcp", - "version": "0.4.9", + "version": "0.4.10", "license": "MIT", "dependencies": { "@ai-sdk/openai-compatible": "^1.0.28", diff --git a/package.json b/package.json index 709930f..02cb8ce 100644 --- a/package.json +++ b/package.json @@ -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",