opencode-immune 1.0.25 → 1.0.27

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.
Files changed (2) hide show
  1. package/dist/plugin.js +60 -0
  2. package/package.json +1 -1
package/dist/plugin.js CHANGED
@@ -8,6 +8,64 @@ const path_1 = require("path");
8
8
  const crypto_1 = require("crypto");
9
9
  const os_1 = require("os");
10
10
  const child_process_1 = require("child_process");
11
+ // ═══════════════════════════════════════════════════════════════════════════════
12
+ // PLUGIN VERSION CHECK
13
+ // ═══════════════════════════════════════════════════════════════════════════════
14
+ const PLUGIN_VERSION = "1.0.26";
15
+ const PLUGIN_PACKAGE_NAME = "opencode-immune";
16
+ /**
17
+ * Read plugin version from package.json at runtime.
18
+ * Falls back to PLUGIN_VERSION constant if read fails.
19
+ */
20
+ async function getPluginVersion() {
21
+ try {
22
+ // Try to find package.json relative to the compiled plugin location.
23
+ // dist/plugin.js → ../package.json
24
+ // Also try direct path for when loaded from npm cache.
25
+ const candidates = [
26
+ (0, path_1.join)(__dirname, "..", "package.json"),
27
+ (0, path_1.join)(__dirname, "package.json"),
28
+ ];
29
+ for (const pkgPath of candidates) {
30
+ try {
31
+ const content = await (0, promises_1.readFile)(pkgPath, "utf-8");
32
+ const pkg = JSON.parse(content);
33
+ if (pkg.version)
34
+ return pkg.version;
35
+ }
36
+ catch { /* try next */ }
37
+ }
38
+ }
39
+ catch { /* fallback */ }
40
+ return PLUGIN_VERSION;
41
+ }
42
+ /**
43
+ * Check npm registry for latest version. Warn if current is outdated.
44
+ * Non-blocking, fire-and-forget — never delays plugin startup.
45
+ */
46
+ async function checkPluginUpdate() {
47
+ try {
48
+ const currentVersion = await getPluginVersion();
49
+ const controller = new AbortController();
50
+ const timeout = setTimeout(() => controller.abort(), 5_000);
51
+ const res = await fetch(`https://registry.npmjs.org/${PLUGIN_PACKAGE_NAME}/latest`, { signal: controller.signal });
52
+ clearTimeout(timeout);
53
+ if (!res.ok)
54
+ return;
55
+ const data = (await res.json());
56
+ const latest = data.version;
57
+ if (latest && latest !== currentVersion) {
58
+ console.warn(`[opencode-immune] Plugin update available: ${currentVersion} → ${latest}. ` +
59
+ `Restart opencode to pick up the new version.`);
60
+ }
61
+ else if (latest) {
62
+ console.log(`[opencode-immune] Plugin version ${currentVersion} is up to date.`);
63
+ }
64
+ }
65
+ catch {
66
+ // Network error, timeout, etc. — silently ignore
67
+ }
68
+ }
11
69
  function createState(input) {
12
70
  return {
13
71
  input,
@@ -1390,6 +1448,8 @@ function createMultiCycleHandler(state) {
1390
1448
  // ═══════════════════════════════════════════════════════════════════════════════
1391
1449
  async function server(input) {
1392
1450
  const state = createState(input);
1451
+ // ── Plugin version check (non-blocking, fire-and-forget) ──
1452
+ checkPluginUpdate().catch(() => { });
1393
1453
  // ── Harness auto-sync (non-blocking, fire-and-forget) ──
1394
1454
  // Runs in background so it doesn't delay plugin initialization.
1395
1455
  // If sync fails, plugin continues normally with existing config.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-immune",
3
- "version": "1.0.25",
3
+ "version": "1.0.27",
4
4
  "description": "OpenCode plugin: session recovery, auto-retry, multi-cycle automation, context monitoring",
5
5
  "exports": {
6
6
  "./server": "./dist/plugin.js"