@codemem/opencode-plugin 0.22.1 → 0.22.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,7 +15,11 @@ import {
15
15
 
16
16
  const TRUTHY_VALUES = ["1", "true", "yes"];
17
17
  const DISABLED_VALUES = ["0", "false", "off"];
18
- const PINNED_BACKEND_VERSION = "0.22.1";
18
+ const PINNED_BACKEND_VERSION = "0.22.2";
19
+ const COMPAT_CHECK_DELAY_MS = 1500;
20
+ const COMPAT_CHECK_CACHE_TTL_MS = 5 * 60 * 1000;
21
+
22
+ let compatCheckCache = null;
19
23
 
20
24
  const normalizeEnvValue = (value) => (value || "").toLowerCase();
21
25
  const envHasValue = (value, truthyValues) =>
@@ -40,6 +44,35 @@ const resolveLogPath = (logPathEnvRaw, cwd, homeDir) => {
40
44
  /** Path for error/warning logging — always available regardless of debug flag. */
41
45
  const resolveErrorLogPath = (cwd, homeDir) => DEFAULT_LOG_PATH(homeDir, cwd);
42
46
 
47
+ const resolveCompatCheckCacheKey = ({ backendUpdatePolicy, minVersion, runner, runnerFrom }) =>
48
+ [backendUpdatePolicy, minVersion, runner, runnerFrom || ""].join("|");
49
+
50
+ const readCompatCheckCache = (cacheKey) => {
51
+ if (!compatCheckCache) {
52
+ return null;
53
+ }
54
+ if (compatCheckCache.cacheKey !== cacheKey) {
55
+ return null;
56
+ }
57
+ if (Date.now() >= compatCheckCache.expiresAtMs) {
58
+ compatCheckCache = null;
59
+ return null;
60
+ }
61
+ return compatCheckCache.value;
62
+ };
63
+
64
+ const writeCompatCheckCache = (cacheKey, value) => {
65
+ compatCheckCache = {
66
+ cacheKey,
67
+ expiresAtMs: Date.now() + COMPAT_CHECK_CACHE_TTL_MS,
68
+ value,
69
+ };
70
+ };
71
+
72
+ const clearCompatCheckCache = () => {
73
+ compatCheckCache = null;
74
+ };
75
+
43
76
  const createLogLine = (logPath) => async (line) => {
44
77
  if (!logPath) {
45
78
  return;
@@ -1180,6 +1213,18 @@ export const OpencodeMemPlugin = async ({
1180
1213
 
1181
1214
  const verifyCliCompatibility = async () => {
1182
1215
  const minVersion = process.env.CODEMEM_MIN_VERSION || "0.9.20";
1216
+ const cacheKey = resolveCompatCheckCacheKey({
1217
+ backendUpdatePolicy,
1218
+ minVersion,
1219
+ runner,
1220
+ runnerFrom,
1221
+ });
1222
+ const cachedVersion = readCompatCheckCache(cacheKey);
1223
+ if (cachedVersion && isVersionAtLeast(cachedVersion, minVersion)) {
1224
+ await logLine(`compat.version_check_cached current=${cachedVersion} required=${minVersion}`);
1225
+ return;
1226
+ }
1227
+
1183
1228
  const versionResult = await runCli(["version"]);
1184
1229
  if (!versionResult || versionResult.exitCode !== 0) {
1185
1230
  await logLine(
@@ -1213,9 +1258,12 @@ export const OpencodeMemPlugin = async ({
1213
1258
  }
1214
1259
 
1215
1260
  if (isVersionAtLeast(currentVersion, minVersion)) {
1261
+ writeCompatCheckCache(cacheKey, currentVersion);
1216
1262
  return;
1217
1263
  }
1218
1264
 
1265
+ clearCompatCheckCache();
1266
+
1219
1267
  const guidance = resolveUpgradeGuidance({ runner, runnerFrom });
1220
1268
  const message = `codemem CLI ${currentVersion || "unknown"} is older than required ${minVersion}`;
1221
1269
  await log("warn", message, {
@@ -1249,6 +1297,7 @@ export const OpencodeMemPlugin = async ({
1249
1297
  && refreshedResult?.exitCode === 0
1250
1298
  && isVersionAtLeast(refreshedVersion, minVersion)
1251
1299
  ) {
1300
+ writeCompatCheckCache(cacheKey, refreshedVersion);
1252
1301
  const viewerRestart = await restartViewerAfterAutoUpdate();
1253
1302
  await logLine(
1254
1303
  `compat.auto_update_success before=${currentVersion} after=${refreshedVersion}`
@@ -1485,11 +1534,14 @@ export const OpencodeMemPlugin = async ({
1485
1534
  await log("info", "codemem plugin initialized", { cwd, version });
1486
1535
  await logLine(`plugin initialized cwd=${cwd} version=${version}`);
1487
1536
  startViewer();
1488
- void verifyCliCompatibility().catch(async (err) => {
1489
- await logLine(
1490
- `compat.version_check_error message=${String(err?.message || err || "unknown")}`
1491
- );
1492
- });
1537
+ const compatCheckTimer = setTimeout(() => {
1538
+ void verifyCliCompatibility().catch(async (err) => {
1539
+ await logLine(
1540
+ `compat.version_check_error message=${String(err?.message || err || "unknown")}`
1541
+ );
1542
+ });
1543
+ }, COMPAT_CHECK_DELAY_MS);
1544
+ if (compatCheckTimer.unref) compatCheckTimer.unref();
1493
1545
 
1494
1546
  const truncate = (value) => {
1495
1547
  if (value === undefined || value === null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemem/opencode-plugin",
3
- "version": "0.22.1",
3
+ "version": "0.22.2",
4
4
  "description": "CodeMem plugin for OpenCode",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -18,7 +18,7 @@
18
18
  ".opencode/lib/"
19
19
  ],
20
20
  "dependencies": {
21
- "@opencode-ai/plugin": "1.3.9"
21
+ "@opencode-ai/plugin": "1.3.13"
22
22
  },
23
23
  "repository": {
24
24
  "type": "git",