wolverine-ai 2.3.2 → 2.4.1
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/README.md +23 -0
- package/package.json +1 -1
- package/server/config/settings.json +5 -0
- package/src/brain/brain.js +4 -0
- package/src/core/runner.js +21 -0
- package/src/index.js +4 -0
- package/src/platform/auto-update.js +220 -0
package/README.md
CHANGED
|
@@ -448,6 +448,29 @@ server/config/settings.json ← Everything else (models, port, clustering, te
|
|
|
448
448
|
|
|
449
449
|
---
|
|
450
450
|
|
|
451
|
+
## Auto-Update
|
|
452
|
+
|
|
453
|
+
Wolverine checks npm for new versions hourly and upgrades itself automatically. Config files are protected — backed up before update, restored after.
|
|
454
|
+
|
|
455
|
+
```json
|
|
456
|
+
// server/config/settings.json
|
|
457
|
+
{
|
|
458
|
+
"autoUpdate": {
|
|
459
|
+
"enabled": true, // set false to disable
|
|
460
|
+
"intervalMs": 3600000 // check interval (default: 1 hour)
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
**How it works:**
|
|
466
|
+
- Checks `npm view wolverine-ai version` against installed version
|
|
467
|
+
- If newer: backs up `settings.json`, `.env.local`, `.env` → runs `npm install wolverine-ai@latest` → restores configs → restarts
|
|
468
|
+
- Protected files never overwritten during update
|
|
469
|
+
- First check 30s after startup, then every hour
|
|
470
|
+
- **Disable:** `"autoUpdate": { "enabled": false }` or `WOLVERINE_AUTO_UPDATE=false`
|
|
471
|
+
|
|
472
|
+
---
|
|
473
|
+
|
|
451
474
|
## Platform Telemetry
|
|
452
475
|
|
|
453
476
|
Every wolverine instance automatically broadcasts health data to the analytics platform. **Zero config** — telemetry is on by default.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wolverine-ai",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "Self-healing Node.js server framework powered by AI. Catches crashes, diagnoses errors, generates fixes, verifies, and restarts — automatically.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
package/src/brain/brain.js
CHANGED
|
@@ -235,6 +235,10 @@ const SEED_DOCS = [
|
|
|
235
235
|
text: "Dependency manager skill (src/skills/deps.js): structured npm dependency analysis + repair. diagnose(errorMessage, cwd) returns {diagnosed, category, summary, fixes} — categories: missing_install, missing_package, version_conflict, outdated_api, corrupted_modules. healthReport(cwd) returns full health check: npm audit (vulnerabilities), outdated packages, peer dep conflicts, unused packages, lock file status, health score 0-100. getMigration(packageName) returns known upgrade paths: express→fastify (5.6x faster), moment→dayjs (2KB vs 70KB), request→node-fetch (deprecated), body-parser→built-in, callbacks→async/await. Agent tools: audit_deps (full health check), check_migration (upgrade paths). Heal pipeline uses diagnose() in tryOperationalFix before AI — zero tokens for dependency issues.",
|
|
236
236
|
metadata: { topic: "skill-deps" },
|
|
237
237
|
},
|
|
238
|
+
{
|
|
239
|
+
text: "Auto-update: wolverine checks npm registry hourly for new versions. When found, runs npm install wolverine-ai@latest, backs up settings.json/.env.local before update and restores after. Config: autoUpdate.enabled (default true) in settings.json. Disable with WOLVERINE_AUTO_UPDATE=false env var. On successful update, signals runner to restart. Protected files never overwritten: settings.json, .env.local, .env, db.js. Update check runs 30s after startup then every hour (configurable via autoUpdate.intervalMs).",
|
|
240
|
+
metadata: { topic: "auto-update" },
|
|
241
|
+
},
|
|
238
242
|
{
|
|
239
243
|
text: "Cost optimization: 7 techniques reduce heal cost from $0.31 to $0.02 for simple errors. (1) Verifier skips route probe for simple errors (TypeError/ReferenceError/SyntaxError) — trusts syntax+boot, ErrorMonitor is safety net. Prevents false-rejection cascades. (2) Sub-agents use Haiku (classifier model) for explore/plan/verify/research — only fixer uses Sonnet/Opus. 6 Haiku calls=$0.006 vs 6 Sonnet calls=$0.12. (3) Agent context compacted every 3 turns using compacting model — prevents 15K→95K token blowup. (4) Brain checked for cached fix patterns before AI — repeat errors cost $0. (5) Token budgets capped by error complexity: simple=20K agent budget, moderate=50K, complex=100K. Simple errors get 4 agent turns max. (6) Prior attempt summaries (not full context) passed between iterations — concise 'do NOT repeat' directives. (7) Fast path includes last known good backup code so AI can revert broken additions instead of patching around them.",
|
|
240
244
|
metadata: { topic: "cost-optimization" },
|
package/src/core/runner.js
CHANGED
|
@@ -21,6 +21,7 @@ const { RouteProber } = require("../monitor/route-prober");
|
|
|
21
21
|
const { startHeartbeat, stopHeartbeat } = require("../platform/heartbeat");
|
|
22
22
|
const { Notifier } = require("../notifications/notifier");
|
|
23
23
|
const { ErrorMonitor } = require("../monitor/error-monitor");
|
|
24
|
+
const { startAutoUpdate, stopAutoUpdate } = require("../platform/auto-update");
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* The Wolverine process runner — v3.
|
|
@@ -213,6 +214,25 @@ class WolverineRunner {
|
|
|
213
214
|
redactor: this.redactor,
|
|
214
215
|
});
|
|
215
216
|
|
|
217
|
+
// Auto-update: check for new wolverine-ai versions
|
|
218
|
+
const { getConfig: _gc } = require("./config");
|
|
219
|
+
const autoUpdateEnabled = _gc("autoUpdate.enabled") !== false;
|
|
220
|
+
if (autoUpdateEnabled) {
|
|
221
|
+
startAutoUpdate({
|
|
222
|
+
cwd: this.cwd,
|
|
223
|
+
logger: this.logger,
|
|
224
|
+
intervalMs: parseInt(process.env.WOLVERINE_UPDATE_INTERVAL_MS, 10) || 3600000,
|
|
225
|
+
onUpdate: (result) => {
|
|
226
|
+
console.log(chalk.blue(` 🔄 Wolverine updated ${result.from} → ${result.to}, restarting...`));
|
|
227
|
+
this.logger.info("update.restart", `Restarting after update ${result.from} → ${result.to}`);
|
|
228
|
+
this.restart();
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
console.log(chalk.gray(" 🔄 Auto-update: enabled (checks hourly)"));
|
|
232
|
+
} else {
|
|
233
|
+
console.log(chalk.gray(" 🔄 Auto-update: disabled"));
|
|
234
|
+
}
|
|
235
|
+
|
|
216
236
|
this._spawn();
|
|
217
237
|
}
|
|
218
238
|
|
|
@@ -272,6 +292,7 @@ class WolverineRunner {
|
|
|
272
292
|
this.processMonitor.stop();
|
|
273
293
|
this.routeProber.stop();
|
|
274
294
|
stopHeartbeat();
|
|
295
|
+
stopAutoUpdate();
|
|
275
296
|
this.mcp.shutdown();
|
|
276
297
|
this.tokenTracker.save();
|
|
277
298
|
this.dashboard.stop();
|
package/src/index.js
CHANGED
|
@@ -35,6 +35,7 @@ const { ClusterManager } = require("./core/cluster-manager");
|
|
|
35
35
|
const { loadConfig, getConfig } = require("./core/config");
|
|
36
36
|
const { sqlGuard, SafeDB, scanForInjection, idempotencyGuard, idempotencyAfterHook } = require("./skills/sql");
|
|
37
37
|
const { diagnose: diagnoseDeps, healthReport: depsHealthReport, getMigration } = require("./skills/deps");
|
|
38
|
+
const { checkForUpdate, upgrade: upgradeWolverine, getCurrentVersion } = require("./platform/auto-update");
|
|
38
39
|
|
|
39
40
|
module.exports = {
|
|
40
41
|
// Core
|
|
@@ -99,4 +100,7 @@ module.exports = {
|
|
|
99
100
|
diagnoseDeps,
|
|
100
101
|
depsHealthReport,
|
|
101
102
|
getMigration,
|
|
103
|
+
checkForUpdate,
|
|
104
|
+
upgradeWolverine,
|
|
105
|
+
getCurrentVersion,
|
|
102
106
|
};
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
const { execSync } = require("child_process");
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Auto-Updater — self-updating wolverine framework.
|
|
8
|
+
*
|
|
9
|
+
* Checks npm registry for newer wolverine-ai versions on a schedule.
|
|
10
|
+
* When a new version is found, upgrades via npm and restarts.
|
|
11
|
+
*
|
|
12
|
+
* Config/settings are protected: backed up before update, restored after.
|
|
13
|
+
* Disable in settings.json: "autoUpdate": { "enabled": false }
|
|
14
|
+
*
|
|
15
|
+
* Wolverine can't edit files outside server/ directly, but it CAN
|
|
16
|
+
* run bash commands — so npm update is the upgrade path.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const PACKAGE_NAME = "wolverine-ai";
|
|
20
|
+
const CHECK_INTERVAL_MS = 3600000; // 1 hour
|
|
21
|
+
|
|
22
|
+
let _timer = null;
|
|
23
|
+
let _currentVersion = null;
|
|
24
|
+
let _checking = false;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Get the currently installed version.
|
|
28
|
+
*/
|
|
29
|
+
function getCurrentVersion() {
|
|
30
|
+
if (_currentVersion) return _currentVersion;
|
|
31
|
+
try {
|
|
32
|
+
const pkg = require("../../package.json");
|
|
33
|
+
_currentVersion = pkg.version;
|
|
34
|
+
} catch {
|
|
35
|
+
_currentVersion = "0.0.0";
|
|
36
|
+
}
|
|
37
|
+
return _currentVersion;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Check npm registry for the latest published version.
|
|
42
|
+
* Uses `npm view` — no network dependency beyond npm.
|
|
43
|
+
*/
|
|
44
|
+
function getLatestVersion() {
|
|
45
|
+
try {
|
|
46
|
+
const result = execSync(`npm view ${PACKAGE_NAME} version 2>/dev/null`, {
|
|
47
|
+
encoding: "utf-8",
|
|
48
|
+
timeout: 15000,
|
|
49
|
+
}).trim();
|
|
50
|
+
return result || null;
|
|
51
|
+
} catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Compare semver versions. Returns true if latest > current.
|
|
58
|
+
*/
|
|
59
|
+
function isNewer(latest, current) {
|
|
60
|
+
if (!latest || !current) return false;
|
|
61
|
+
const a = latest.split(".").map(Number);
|
|
62
|
+
const b = current.split(".").map(Number);
|
|
63
|
+
for (let i = 0; i < 3; i++) {
|
|
64
|
+
if ((a[i] || 0) > (b[i] || 0)) return true;
|
|
65
|
+
if ((a[i] || 0) < (b[i] || 0)) return false;
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Protect config files before update and restore after.
|
|
72
|
+
*/
|
|
73
|
+
function backupConfigs(cwd) {
|
|
74
|
+
const configs = [
|
|
75
|
+
"server/config/settings.json",
|
|
76
|
+
".env.local",
|
|
77
|
+
".env",
|
|
78
|
+
];
|
|
79
|
+
const backups = {};
|
|
80
|
+
for (const file of configs) {
|
|
81
|
+
const fullPath = path.join(cwd, file);
|
|
82
|
+
if (fs.existsSync(fullPath)) {
|
|
83
|
+
backups[file] = fs.readFileSync(fullPath, "utf-8");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return backups;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function restoreConfigs(cwd, backups) {
|
|
90
|
+
for (const [file, content] of Object.entries(backups)) {
|
|
91
|
+
const fullPath = path.join(cwd, file);
|
|
92
|
+
try {
|
|
93
|
+
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
|
|
94
|
+
fs.writeFileSync(fullPath, content, "utf-8");
|
|
95
|
+
} catch {}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Perform the upgrade. Returns { success, from, to, error? }
|
|
101
|
+
*/
|
|
102
|
+
function upgrade(cwd, logger) {
|
|
103
|
+
const current = getCurrentVersion();
|
|
104
|
+
const latest = getLatestVersion();
|
|
105
|
+
|
|
106
|
+
if (!latest || !isNewer(latest, current)) {
|
|
107
|
+
return { success: false, from: current, to: latest, error: "Already up to date" };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
console.log(chalk.blue(`\n 🔄 Wolverine update available: ${current} → ${latest}`));
|
|
111
|
+
if (logger) logger.info("update.start", `Upgrading ${current} → ${latest}`, { from: current, to: latest });
|
|
112
|
+
|
|
113
|
+
// Back up configs
|
|
114
|
+
const configBackups = backupConfigs(cwd);
|
|
115
|
+
console.log(chalk.gray(` 🔒 Backed up ${Object.keys(configBackups).length} config files`));
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
// Determine install method: global or local
|
|
119
|
+
const isGlobal = __dirname.includes("node_modules") && !cwd.includes("node_modules");
|
|
120
|
+
const cmd = isGlobal
|
|
121
|
+
? `npm install -g ${PACKAGE_NAME}@${latest}`
|
|
122
|
+
: `npm install ${PACKAGE_NAME}@${latest}`;
|
|
123
|
+
|
|
124
|
+
console.log(chalk.blue(` 📦 Running: ${cmd}`));
|
|
125
|
+
execSync(cmd, { cwd, stdio: "pipe", timeout: 120000 });
|
|
126
|
+
|
|
127
|
+
// Restore configs (npm might have overwritten them)
|
|
128
|
+
restoreConfigs(cwd, configBackups);
|
|
129
|
+
console.log(chalk.gray(` 🔒 Restored config files`));
|
|
130
|
+
|
|
131
|
+
// Clear version cache
|
|
132
|
+
_currentVersion = null;
|
|
133
|
+
|
|
134
|
+
console.log(chalk.green(` ✅ Updated to ${latest}`));
|
|
135
|
+
if (logger) logger.info("update.success", `Upgraded to ${latest}`, { from: current, to: latest });
|
|
136
|
+
|
|
137
|
+
return { success: true, from: current, to: latest };
|
|
138
|
+
} catch (err) {
|
|
139
|
+
// Restore configs on failure
|
|
140
|
+
restoreConfigs(cwd, configBackups);
|
|
141
|
+
const errMsg = (err.message || "").slice(0, 100);
|
|
142
|
+
console.log(chalk.yellow(` ⚠️ Update failed: ${errMsg}`));
|
|
143
|
+
if (logger) logger.warn("update.failed", `Upgrade failed: ${errMsg}`, { from: current, to: latest });
|
|
144
|
+
return { success: false, from: current, to: latest, error: errMsg };
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Check for updates (non-blocking). Logs if update available.
|
|
150
|
+
* Call upgrade() separately to actually apply.
|
|
151
|
+
*/
|
|
152
|
+
function checkForUpdate() {
|
|
153
|
+
if (_checking) return null;
|
|
154
|
+
_checking = true;
|
|
155
|
+
try {
|
|
156
|
+
const current = getCurrentVersion();
|
|
157
|
+
const latest = getLatestVersion();
|
|
158
|
+
_checking = false;
|
|
159
|
+
if (latest && isNewer(latest, current)) {
|
|
160
|
+
console.log(chalk.blue(` 🔄 Update available: ${PACKAGE_NAME} ${current} → ${latest}`));
|
|
161
|
+
return { available: true, current, latest };
|
|
162
|
+
}
|
|
163
|
+
return { available: false, current, latest };
|
|
164
|
+
} catch {
|
|
165
|
+
_checking = false;
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Start auto-update schedule. Checks every hour (configurable).
|
|
172
|
+
* If autoUpdate is enabled and a new version is found, upgrades and signals restart.
|
|
173
|
+
*
|
|
174
|
+
* @param {object} options
|
|
175
|
+
* @param {string} options.cwd — project root
|
|
176
|
+
* @param {object} options.logger — EventLogger
|
|
177
|
+
* @param {function} options.onUpdate — called after successful update (trigger restart)
|
|
178
|
+
* @param {number} options.intervalMs — check interval (default: 1h)
|
|
179
|
+
*/
|
|
180
|
+
function startAutoUpdate({ cwd, logger, onUpdate, intervalMs }) {
|
|
181
|
+
const interval = intervalMs || CHECK_INTERVAL_MS;
|
|
182
|
+
|
|
183
|
+
// Check on startup (delayed 30s to not block boot)
|
|
184
|
+
setTimeout(() => {
|
|
185
|
+
const result = checkForUpdate();
|
|
186
|
+
if (result?.available) {
|
|
187
|
+
const upgraded = upgrade(cwd, logger);
|
|
188
|
+
if (upgraded.success && onUpdate) {
|
|
189
|
+
console.log(chalk.blue(" 🔄 Restarting with new version..."));
|
|
190
|
+
onUpdate(upgraded);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}, 30000);
|
|
194
|
+
|
|
195
|
+
// Periodic check
|
|
196
|
+
_timer = setInterval(() => {
|
|
197
|
+
const result = checkForUpdate();
|
|
198
|
+
if (result?.available) {
|
|
199
|
+
const upgraded = upgrade(cwd, logger);
|
|
200
|
+
if (upgraded.success && onUpdate) {
|
|
201
|
+
console.log(chalk.blue(" 🔄 Restarting with new version..."));
|
|
202
|
+
onUpdate(upgraded);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}, interval);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function stopAutoUpdate() {
|
|
209
|
+
if (_timer) { clearInterval(_timer); _timer = null; }
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
module.exports = {
|
|
213
|
+
getCurrentVersion,
|
|
214
|
+
getLatestVersion,
|
|
215
|
+
isNewer,
|
|
216
|
+
checkForUpdate,
|
|
217
|
+
upgrade,
|
|
218
|
+
startAutoUpdate,
|
|
219
|
+
stopAutoUpdate,
|
|
220
|
+
};
|