- Provides an OpenCode hook that reacts to
session.created, ensures the hook only runs once per startup, and surfaces update information to the user via TUI toasts and logs. - Detects local development builds, cached installs, and running plugins pinned to specific versions so the hook can decide whether to notify, auto-update, or skip work.
index.tsorchestrates the hook lifecycle: it filters session events, defers the heavy work viasetTimeout, and delegates version discovery and updates to helper functions while respecting the user’sautoUpdateandshowStartupToastpreferences.checker.tsencapsulates environment-aware utilities (config path discovery, local dev detection, NPM registry fetching, and pinned-version mutation) plus memoized cache lookups so the hook can derive current, cached, and latest versions without duplicating logic.cache.tsis responsible for invalidating cached installs (node_modules,package.json,bun.lock) before a freshbun install, keeping the cached package state consistent with the server-provided latest version.- Shared
constants.tsstandardizes paths (cache directory, config locations, package name, registry URL) and fetch timeouts so the rest of the hook is configuration-free.
- On the first
session.createdevent without a parent session,createAutoUpdateCheckerHookschedulesrunBackgroundUpdateCheckwhile immediately showing an initial toast (unless disabled) and short-circuiting for local dev builds. runBackgroundUpdateCheckresolves the current plugin entry and cached version, determines the update channel viaextractChannel, retrieves the latest dist-tag fromgetLatestVersion, and compares versions.- When an update is available, the hook either notifies the user or, if
autoUpdateis on, updates the pinned entry in the OpenCode config (updatePinnedVersion), invalidates the cached package, and runsbun installsafely (runBunInstallSafe) with a 60-second timeout before showing success/error toasts. checker.tssupports the above flow with helpers (getLocalDevVersion,findPluginEntry,getCachedVersion,extractChannel, etc.) that read configs (.opencode/*.jsonc, global config paths) viastripJsonCommentsandfsoperations.cache.tsruns before reinstall to remove lingering plugin directories, dependency entries, and JSON-formattedbun.lockreferences, ensuringrunBunInstallSafeoperates on a clean slate.
- Hooks into the OpenCode plugin lifecycle via
ctx.client.tui.showToastand thesession.createdevent, leveragingPluginInputto know the working directory and show UI feedback. - Reads OpenCode configuration files exposed by
../../cli/config-managerto locate plugin entries, pinned versions, and localfile://installs, so it stays aligned with the same config sources that enable plugin loading. - Uses shared
../../utils/loggerfor tracing background operations and errors while talking to platform APIs (fetch,Bun.spawn,fs) to inspect, mutate, and reinstall theoh-my-opencode-slimpackage stored underCACHE_DIR. - Exposes
AutoUpdateCheckerOptionsfor consumers (viaindex.ts) to opt out of toasts or automatic installs while still reusing the same checker/cache helpers.