opencode-immune 1.0.26 → 1.0.28
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.
- package/dist/plugin.js +42 -6
- package/package.json +1 -1
package/dist/plugin.js
CHANGED
|
@@ -13,12 +13,40 @@ const child_process_1 = require("child_process");
|
|
|
13
13
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
14
14
|
const PLUGIN_VERSION = "1.0.26";
|
|
15
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
|
+
}
|
|
16
42
|
/**
|
|
17
43
|
* Check npm registry for latest version. Warn if current is outdated.
|
|
44
|
+
* Stores update message in state for injection into system prompt.
|
|
18
45
|
* Non-blocking, fire-and-forget — never delays plugin startup.
|
|
19
46
|
*/
|
|
20
|
-
async function checkPluginUpdate() {
|
|
47
|
+
async function checkPluginUpdate(state) {
|
|
21
48
|
try {
|
|
49
|
+
const currentVersion = await getPluginVersion();
|
|
22
50
|
const controller = new AbortController();
|
|
23
51
|
const timeout = setTimeout(() => controller.abort(), 5_000);
|
|
24
52
|
const res = await fetch(`https://registry.npmjs.org/${PLUGIN_PACKAGE_NAME}/latest`, { signal: controller.signal });
|
|
@@ -27,12 +55,14 @@ async function checkPluginUpdate() {
|
|
|
27
55
|
return;
|
|
28
56
|
const data = (await res.json());
|
|
29
57
|
const latest = data.version;
|
|
30
|
-
if (latest && latest !==
|
|
31
|
-
|
|
32
|
-
`
|
|
58
|
+
if (latest && latest !== currentVersion) {
|
|
59
|
+
state.pluginUpdateMessage =
|
|
60
|
+
`[PLUGIN UPDATE] opencode-immune ${currentVersion} → ${latest} is available. ` +
|
|
61
|
+
`Please inform the user: a plugin update is available. They should restart opencode to get the latest version.`;
|
|
62
|
+
console.warn(`[opencode-immune] Plugin update available: ${currentVersion} → ${latest}.`);
|
|
33
63
|
}
|
|
34
64
|
else if (latest) {
|
|
35
|
-
console.log(`[opencode-immune] Plugin version ${
|
|
65
|
+
console.log(`[opencode-immune] Plugin version ${currentVersion} is up to date.`);
|
|
36
66
|
}
|
|
37
67
|
}
|
|
38
68
|
catch {
|
|
@@ -56,6 +86,7 @@ function createState(input) {
|
|
|
56
86
|
autoResumeAttempted: false,
|
|
57
87
|
cycleCount: 0,
|
|
58
88
|
commitPending: false,
|
|
89
|
+
pluginUpdateMessage: null,
|
|
59
90
|
};
|
|
60
91
|
}
|
|
61
92
|
const ULTRAWORK_AGENT = "0-ultrawork";
|
|
@@ -928,6 +959,11 @@ function createSystemTransform(state) {
|
|
|
928
959
|
// Clear after injection to avoid repeated hints
|
|
929
960
|
state.lastEditAttempt = null;
|
|
930
961
|
}
|
|
962
|
+
// Plugin update notification — inject once into first system prompt
|
|
963
|
+
if (state.pluginUpdateMessage) {
|
|
964
|
+
output.system.push(state.pluginUpdateMessage);
|
|
965
|
+
// Keep showing until opencode restarts (don't clear)
|
|
966
|
+
}
|
|
931
967
|
};
|
|
932
968
|
}
|
|
933
969
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
@@ -1422,7 +1458,7 @@ function createMultiCycleHandler(state) {
|
|
|
1422
1458
|
async function server(input) {
|
|
1423
1459
|
const state = createState(input);
|
|
1424
1460
|
// ── Plugin version check (non-blocking, fire-and-forget) ──
|
|
1425
|
-
checkPluginUpdate().catch(() => { });
|
|
1461
|
+
checkPluginUpdate(state).catch(() => { });
|
|
1426
1462
|
// ── Harness auto-sync (non-blocking, fire-and-forget) ──
|
|
1427
1463
|
// Runs in background so it doesn't delay plugin initialization.
|
|
1428
1464
|
// If sync fails, plugin continues normally with existing config.
|