Skip to content

Commit 7e89cc7

Browse files
committed
Add showUpdateToasts and autoUpdate config options
Previously, update notifications were always shown and auto-update was always attempted. This change gives users control over both behaviors: - showUpdateToasts (default: true) - Control whether update toasts appear - autoUpdate (default: false) - Opt-in to automatic config version updates With autoUpdate disabled (the new default), users are simply notified of available updates without any config modifications. This is less intrusive and gives users explicit control over when their config changes.
1 parent 1e0e738 commit 7e89cc7

File tree

3 files changed

+49
-18
lines changed

3 files changed

+49
-18
lines changed

index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ const plugin: Plugin = (async (ctx) => {
5353

5454
// Check for updates after a delay
5555
setTimeout(() => {
56-
checkForUpdates(ctx.client, logger).catch(() => { })
56+
checkForUpdates(ctx.client, logger, {
57+
showToast: config.showUpdateToasts ?? true,
58+
autoUpdate: config.autoUpdate ?? false
59+
}).catch(() => { })
5760
}, 5000)
5861

5962
// Show migration toast if there were config migrations

lib/config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export interface PluginConfig {
1313
protectedTools: string[]
1414
model?: string
1515
showModelErrorToasts?: boolean
16+
showUpdateToasts?: boolean
17+
autoUpdate?: boolean
1618
strictModelSelection?: boolean
1719
pruning_summary: "off" | "minimal" | "detailed"
1820
nudge_freq: number
@@ -32,6 +34,8 @@ const defaultConfig: PluginConfig = {
3234
debug: false,
3335
protectedTools: ['task', 'todowrite', 'todoread', 'prune', 'batch', 'edit', 'write'],
3436
showModelErrorToasts: true,
37+
showUpdateToasts: true,
38+
autoUpdate: false,
3539
strictModelSelection: false,
3640
pruning_summary: 'detailed',
3741
nudge_freq: 10,
@@ -47,6 +51,8 @@ const VALID_CONFIG_KEYS = new Set([
4751
'protectedTools',
4852
'model',
4953
'showModelErrorToasts',
54+
'showUpdateToasts',
55+
'autoUpdate',
5056
'strictModelSelection',
5157
'pruning_summary',
5258
'nudge_freq',
@@ -110,6 +116,10 @@ function createDefaultConfig(): void {
110116
// "model": "anthropic/claude-haiku-4-5",
111117
// Show toast notifications when model selection fails
112118
"showModelErrorToasts": true,
119+
// Show toast notifications when a new version is available
120+
"showUpdateToasts": true,
121+
// Automatically update to new versions (restart required to apply)
122+
"autoUpdate": false,
113123
// Only run AI analysis with session model or configured model (disables fallback models)
114124
"strictModelSelection": false,
115125
// AI analysis strategies (deduplication runs automatically on every request)
@@ -199,6 +209,8 @@ export function getConfig(ctx?: PluginInput): ConfigResult {
199209
protectedTools: [...new Set([...config.protectedTools, ...(globalConfig.protectedTools ?? [])])],
200210
model: globalConfig.model ?? config.model,
201211
showModelErrorToasts: globalConfig.showModelErrorToasts ?? config.showModelErrorToasts,
212+
showUpdateToasts: globalConfig.showUpdateToasts ?? config.showUpdateToasts,
213+
autoUpdate: globalConfig.autoUpdate ?? config.autoUpdate,
202214
strictModelSelection: globalConfig.strictModelSelection ?? config.strictModelSelection,
203215
strategies: mergeStrategies(config.strategies, globalConfig.strategies as any),
204216
pruning_summary: globalConfig.pruning_summary ?? config.pruning_summary,
@@ -230,6 +242,8 @@ export function getConfig(ctx?: PluginInput): ConfigResult {
230242
protectedTools: [...new Set([...config.protectedTools, ...(projectConfig.protectedTools ?? [])])],
231243
model: projectConfig.model ?? config.model,
232244
showModelErrorToasts: projectConfig.showModelErrorToasts ?? config.showModelErrorToasts,
245+
showUpdateToasts: projectConfig.showUpdateToasts ?? config.showUpdateToasts,
246+
autoUpdate: projectConfig.autoUpdate ?? config.autoUpdate,
233247
strictModelSelection: projectConfig.strictModelSelection ?? config.strictModelSelection,
234248
strategies: mergeStrategies(config.strategies, projectConfig.strategies as any),
235249
pruning_summary: projectConfig.pruning_summary ?? config.pruning_summary,

lib/version-checker.ts

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,11 @@ export function updateConfigVersion(newVersion: string, logger?: { info: (compon
109109

110110
export async function checkForUpdates(
111111
client: any,
112-
logger?: { info: (component: string, message: string, data?: any) => void }
112+
logger?: { info: (component: string, message: string, data?: any) => void },
113+
options: { showToast?: boolean; autoUpdate?: boolean } = {}
113114
): Promise<void> {
115+
const { showToast = true, autoUpdate = false } = options
116+
114117
try {
115118
const local = getLocalVersion()
116119
const npm = await getNpmVersion()
@@ -125,22 +128,33 @@ export async function checkForUpdates(
125128
return
126129
}
127130

128-
logger?.info("version", "Update available", { local, npm })
129-
130-
// Update any configs found
131-
const updated = updateConfigVersion(npm, logger)
132-
133-
if (updated) {
134-
await client.tui.showToast({
135-
body: {
136-
title: "DCP: Update available",
137-
message: `v${local} → v${npm}\nRestart OpenCode to apply`,
138-
variant: "info",
139-
duration: 6000
140-
}
141-
})
142-
} else {
143-
// Config update failed or plugin not found in config, show manual instructions
131+
logger?.info("version", "Update available", { local, npm, autoUpdate })
132+
133+
if (autoUpdate) {
134+
// Attempt config update
135+
const updated = updateConfigVersion(npm, logger)
136+
137+
if (updated && showToast) {
138+
await client.tui.showToast({
139+
body: {
140+
title: "DCP: Updated!",
141+
message: `v${local} → v${npm}\nRestart OpenCode to apply`,
142+
variant: "success",
143+
duration: 6000
144+
}
145+
})
146+
} else if (!updated && showToast) {
147+
// Config update failed or plugin not found in config, show manual instructions
148+
await client.tui.showToast({
149+
body: {
150+
title: "DCP: Update available",
151+
message: `v${local} → v${npm}\nUpdate opencode.jsonc:\n"${PACKAGE_NAME}@${npm}"`,
152+
variant: "info",
153+
duration: 8000
154+
}
155+
})
156+
}
157+
} else if (showToast) {
144158
await client.tui.showToast({
145159
body: {
146160
title: "DCP: Update available",

0 commit comments

Comments
 (0)