From 5d57d2ef281f396976f111bee0ca3e1be0fb94ff Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 2 Aug 2026 18:10:00 +0000 Subject: [PATCH 1/2] Derive PLUGIN_VERSION from package.json to prevent drift PLUGIN_VERSION was hand-maintained in src/config.ts and had drifted to 2.0.10 while package.json read 2.0.11. This caused a permanent false-positive update notice (v2.0.10 -> v2.0.11) and mislabelled the sm_plugin_version telemetry attached to every write. Generate src/version.ts from package.json's version via scripts/sync-version.mjs, wired into build/typecheck/test and the release script so the two can no longer drift. Co-authored-by: Dhravya Shah --- package.json | 7 +++--- scripts/release.sh | 6 +++++- scripts/sync-version.mjs | 46 ++++++++++++++++++++++++++++++++++++++++ src/config.ts | 2 +- src/version.ts | 3 +++ 5 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 scripts/sync-version.mjs create mode 100644 src/version.ts diff --git a/package.json b/package.json index b455a7c..70f97e7 100644 --- a/package.json +++ b/package.json @@ -9,10 +9,11 @@ "opencode-supermemory": "./dist/cli.js" }, "scripts": { - "build": "bun build ./src/index.ts --outdir ./dist --target node && bun build ./src/cli.ts --outfile ./dist/cli.js --target node && tsc --emitDeclarationOnly", + "generate:version": "node scripts/sync-version.mjs", + "build": "node scripts/sync-version.mjs && bun build ./src/index.ts --outdir ./dist --target node && bun build ./src/cli.ts --outfile ./dist/cli.js --target node && tsc --emitDeclarationOnly", "dev": "tsc --watch", - "typecheck": "tsc --noEmit", - "test": "bun test" + "typecheck": "node scripts/sync-version.mjs && tsc --noEmit", + "test": "node scripts/sync-version.mjs && bun test" }, "keywords": [ "opencode", diff --git a/scripts/release.sh b/scripts/release.sh index 63ea2b4..0862194 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -40,7 +40,11 @@ echo "new version: $NEW_VERSION" jq ".version = \"$NEW_VERSION\"" package.json > package.json.tmp && mv package.json.tmp package.json -git add package.json +# Keep src/version.ts (PLUGIN_VERSION) in sync with the bumped package.json so +# they cannot drift. +node scripts/sync-version.mjs + +git add package.json src/version.ts git commit -m "v$NEW_VERSION" git tag "v$NEW_VERSION" diff --git a/scripts/sync-version.mjs b/scripts/sync-version.mjs new file mode 100644 index 0000000..65bd8b0 --- /dev/null +++ b/scripts/sync-version.mjs @@ -0,0 +1,46 @@ +#!/usr/bin/env node +// +// Generates src/version.ts from the "version" field in package.json. +// +// The plugin version is needed at runtime (update check + telemetry metadata), +// but restating it in source lets it drift behind package.json. Deriving it from +// the single source of truth here makes that class of bug structurally impossible. +// +// Run automatically as part of `build` and the release script; it can also be +// invoked directly with `npm run generate:version`. + +import { readFileSync, writeFileSync } from "node:fs"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; + +const root = join(dirname(fileURLToPath(import.meta.url)), ".."); +const pkgPath = join(root, "package.json"); +const outPath = join(root, "src", "version.ts"); + +const pkg = JSON.parse(readFileSync(pkgPath, "utf-8")); +const version = pkg.version; + +if (typeof version !== "string" || !version.trim()) { + console.error("sync-version: package.json has no valid \"version\" field"); + process.exit(1); +} + +const contents = `// AUTO-GENERATED by scripts/sync-version.mjs — do not edit by hand. +// Sourced from package.json "version" so the two cannot drift. +export const PLUGIN_VERSION = ${JSON.stringify(version)}; +`; + +const existing = (() => { + try { + return readFileSync(outPath, "utf-8"); + } catch { + return null; + } +})(); + +if (existing !== contents) { + writeFileSync(outPath, contents); + console.log(`sync-version: wrote src/version.ts (PLUGIN_VERSION = ${version})`); +} else { + console.log(`sync-version: src/version.ts already up to date (${version})`); +} diff --git a/src/config.ts b/src/config.ts index 9589a25..b100652 100644 --- a/src/config.ts +++ b/src/config.ts @@ -5,7 +5,7 @@ import { stripJsoncComments } from "./services/jsonc.js"; import { loadCredentials } from "./services/auth.js"; const CONFIG_DIR = join(homedir(), ".config", "opencode"); -export const PLUGIN_VERSION = "2.0.10"; +export { PLUGIN_VERSION } from "./version.js"; const CONFIG_FILES = [ join(CONFIG_DIR, "supermemory.jsonc"), join(CONFIG_DIR, "supermemory.json"), diff --git a/src/version.ts b/src/version.ts new file mode 100644 index 0000000..8c3e2a0 --- /dev/null +++ b/src/version.ts @@ -0,0 +1,3 @@ +// AUTO-GENERATED by scripts/sync-version.mjs — do not edit by hand. +// Sourced from package.json "version" so the two cannot drift. +export const PLUGIN_VERSION = "2.0.11"; From cf957bd55044ab25a99fe07194d012296b9f7ebb Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 2 Aug 2026 18:10:05 +0000 Subject: [PATCH 2/2] Make update notice actionable for standalone-binary users The remediation command (bunx opencode-supermemory@latest install) is not runnable for users of the standalone opencode binary, which embeds bun privately and puts no bun/bunx/node/npm on PATH. Add a runtime-agnostic fallback pointing them at pinning the version in their opencode config. Co-authored-by: Dhravya Shah --- src/services/version-check.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/services/version-check.ts b/src/services/version-check.ts index 2688de7..3d3593e 100644 --- a/src/services/version-check.ts +++ b/src/services/version-check.ts @@ -68,6 +68,7 @@ export function formatUpdateNotice(info: UpdateInfo): string { return [ "[SUPERMEMORY UPDATE]", `Supermemory update available: v${info.currentVersion} -> v${info.latestVersion}`, - `Run: ${info.updateCommand}`, + `Run (if you have a JS runtime): ${info.updateCommand}`, + `Otherwise (e.g. standalone opencode binary), pin "opencode-supermemory@${info.latestVersion}" in your opencode config and restart.`, ].join("\n"); }