From e16bbbcc056b990b9d1a7fcc1faa8bcbca2ca403 Mon Sep 17 00:00:00 2001 From: justsisyphus Date: Fri, 23 Jan 2026 14:20:38 +0900 Subject: [PATCH] feat: show warning toast when model cache is not available - Added isModelCacheAvailable() to check if cache file exists - Shows warning toast on session start if cache is missing - Suggests running 'opencode models --refresh' or restarting --- src/hooks/auto-update-checker/index.ts | 19 +++++++++++++++++++ src/shared/model-availability.ts | 5 +++++ 2 files changed, 24 insertions(+) diff --git a/src/hooks/auto-update-checker/index.ts b/src/hooks/auto-update-checker/index.ts index 08cbd64c..72cd5630 100644 --- a/src/hooks/auto-update-checker/index.ts +++ b/src/hooks/auto-update-checker/index.ts @@ -5,6 +5,7 @@ import { PACKAGE_NAME } from "./constants" import { log } from "../../shared/logger" import { getConfigLoadErrors, clearConfigLoadErrors } from "../../shared/config-errors" import { runBunInstall } from "../../cli/config-manager" +import { isModelCacheAvailable } from "../../shared/model-availability" import type { AutoUpdateCheckerOptions } from "./types" const SISYPHUS_SPINNER = ["·", "•", "●", "○", "◌", "◦", " "] @@ -75,6 +76,7 @@ export function createAutoUpdateCheckerHook(ctx: PluginInput, options: AutoUpdat const displayVersion = localDevVersion ?? cachedVersion await showConfigErrorsIfAny(ctx) + await showModelCacheWarningIfNeeded(ctx) if (localDevVersion) { if (showStartupToast) { @@ -167,6 +169,23 @@ async function runBunInstallSafe(): Promise { } } +async function showModelCacheWarningIfNeeded(ctx: PluginInput): Promise { + if (isModelCacheAvailable()) return + + await ctx.client.tui + .showToast({ + body: { + title: "Model Cache Not Found", + message: "Run 'opencode models --refresh' or restart OpenCode to populate the models cache for optimal agent model selection.", + variant: "warning" as const, + duration: 10000, + }, + }) + .catch(() => {}) + + log("[auto-update-checker] Model cache warning shown") +} + async function showConfigErrorsIfAny(ctx: PluginInput): Promise { const errors = getConfigLoadErrors() if (errors.length === 0) return diff --git a/src/shared/model-availability.ts b/src/shared/model-availability.ts index 3873591d..7abc1d3c 100644 --- a/src/shared/model-availability.ts +++ b/src/shared/model-availability.ts @@ -147,3 +147,8 @@ export async function fetchAvailableModels(_client?: any): Promise> export function __resetModelCache(): void { cachedModels = null } + +export function isModelCacheAvailable(): boolean { + const cacheFile = join(getOpenCodeCacheDir(), "models.json") + return existsSync(cacheFile) +}