wolverine-ai 2.4.3 → 2.4.4
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/package.json +1 -1
- package/src/platform/auto-update.js +60 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wolverine-ai",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.4",
|
|
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": {
|
|
@@ -38,19 +38,42 @@ function getCurrentVersion() {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
* Check
|
|
42
|
-
*
|
|
41
|
+
* Check for the latest available version.
|
|
42
|
+
* For git repos: checks remote for newer commits via `git ls-remote`.
|
|
43
|
+
* For npm installs: checks npm registry via `npm view`.
|
|
43
44
|
*/
|
|
44
|
-
function getLatestVersion() {
|
|
45
|
+
function getLatestVersion(cwd) {
|
|
46
|
+
// Try npm registry first (works for both git and npm installs)
|
|
45
47
|
try {
|
|
46
48
|
const result = execSync(`npm view ${PACKAGE_NAME} version 2>/dev/null`, {
|
|
47
49
|
encoding: "utf-8",
|
|
48
50
|
timeout: 15000,
|
|
51
|
+
cwd: cwd || process.cwd(),
|
|
49
52
|
}).trim();
|
|
50
|
-
|
|
51
|
-
} catch {
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
if (result) return result;
|
|
54
|
+
} catch {}
|
|
55
|
+
|
|
56
|
+
// Fallback for git repos: check if remote has newer commits
|
|
57
|
+
try {
|
|
58
|
+
if (isGitRepo(cwd || process.cwd())) {
|
|
59
|
+
execSync("git fetch origin --quiet", { cwd: cwd || process.cwd(), stdio: "pipe", timeout: 15000 });
|
|
60
|
+
const behind = execSync("git rev-list HEAD..origin/master --count", {
|
|
61
|
+
cwd: cwd || process.cwd(), encoding: "utf-8", timeout: 5000,
|
|
62
|
+
}).trim();
|
|
63
|
+
if (parseInt(behind, 10) > 0) {
|
|
64
|
+
// There are newer commits — read version from remote package.json
|
|
65
|
+
try {
|
|
66
|
+
const remoteVersion = execSync("git show origin/master:package.json", {
|
|
67
|
+
cwd: cwd || process.cwd(), encoding: "utf-8", timeout: 5000,
|
|
68
|
+
});
|
|
69
|
+
const pkg = JSON.parse(remoteVersion);
|
|
70
|
+
return pkg.version || null;
|
|
71
|
+
} catch {}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
} catch {}
|
|
75
|
+
|
|
76
|
+
return null;
|
|
54
77
|
}
|
|
55
78
|
|
|
56
79
|
/**
|
|
@@ -96,8 +119,19 @@ function restoreConfigs(cwd, backups) {
|
|
|
96
119
|
}
|
|
97
120
|
}
|
|
98
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Detect if this is a git repo or an npm install.
|
|
124
|
+
*/
|
|
125
|
+
function isGitRepo(cwd) {
|
|
126
|
+
try {
|
|
127
|
+
execSync("git rev-parse --is-inside-work-tree", { cwd, stdio: "pipe", timeout: 3000 });
|
|
128
|
+
return true;
|
|
129
|
+
} catch { return false; }
|
|
130
|
+
}
|
|
131
|
+
|
|
99
132
|
/**
|
|
100
133
|
* Perform the upgrade. Returns { success, from, to, error? }
|
|
134
|
+
* Supports both npm-installed and git-cloned wolverine.
|
|
101
135
|
*/
|
|
102
136
|
function upgrade(cwd, logger) {
|
|
103
137
|
const current = getCurrentVersion();
|
|
@@ -115,11 +149,21 @@ function upgrade(cwd, logger) {
|
|
|
115
149
|
console.log(chalk.gray(` 🔒 Backed up ${Object.keys(configBackups).length} config files`));
|
|
116
150
|
|
|
117
151
|
try {
|
|
118
|
-
//
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
152
|
+
// Detect install method: git clone or npm package
|
|
153
|
+
const useGit = isGitRepo(cwd);
|
|
154
|
+
let cmd;
|
|
155
|
+
|
|
156
|
+
if (useGit) {
|
|
157
|
+
// Git-cloned: pull latest from origin, then npm install for deps
|
|
158
|
+
cmd = "git pull origin master && npm install";
|
|
159
|
+
console.log(chalk.blue(` 📦 Git repo detected — pulling latest`));
|
|
160
|
+
} else {
|
|
161
|
+
// npm-installed: update the package
|
|
162
|
+
const isGlobal = __dirname.includes("node_modules") && !cwd.includes("node_modules");
|
|
163
|
+
cmd = isGlobal
|
|
164
|
+
? `npm install -g ${PACKAGE_NAME}@${latest}`
|
|
165
|
+
: `npm install ${PACKAGE_NAME}@${latest}`;
|
|
166
|
+
}
|
|
123
167
|
|
|
124
168
|
console.log(chalk.blue(` 📦 Running: ${cmd}`));
|
|
125
169
|
execSync(cmd, { cwd, stdio: "pipe", timeout: 120000 });
|
|
@@ -149,12 +193,12 @@ function upgrade(cwd, logger) {
|
|
|
149
193
|
* Check for updates (non-blocking). Logs if update available.
|
|
150
194
|
* Call upgrade() separately to actually apply.
|
|
151
195
|
*/
|
|
152
|
-
function checkForUpdate() {
|
|
196
|
+
function checkForUpdate(cwd) {
|
|
153
197
|
if (_checking) return null;
|
|
154
198
|
_checking = true;
|
|
155
199
|
try {
|
|
156
200
|
const current = getCurrentVersion();
|
|
157
|
-
const latest = getLatestVersion();
|
|
201
|
+
const latest = getLatestVersion(cwd);
|
|
158
202
|
_checking = false;
|
|
159
203
|
if (latest && isNewer(latest, current)) {
|
|
160
204
|
console.log(chalk.blue(` 🔄 Update available: ${PACKAGE_NAME} ${current} → ${latest}`));
|
|
@@ -184,7 +228,7 @@ function startAutoUpdate({ cwd, logger, onUpdate, intervalMs }) {
|
|
|
184
228
|
console.log(chalk.gray(` 🔄 Auto-update scheduled: first check in 30s, then every ${Math.round(interval / 60000)}min`));
|
|
185
229
|
setTimeout(() => {
|
|
186
230
|
console.log(chalk.gray(` 🔄 Checking for updates (v${getCurrentVersion()})...`));
|
|
187
|
-
const result = checkForUpdate();
|
|
231
|
+
const result = checkForUpdate(cwd);
|
|
188
232
|
if (result?.available) {
|
|
189
233
|
const upgraded = upgrade(cwd, logger);
|
|
190
234
|
if (upgraded.success && onUpdate) {
|
|
@@ -200,7 +244,7 @@ function startAutoUpdate({ cwd, logger, onUpdate, intervalMs }) {
|
|
|
200
244
|
|
|
201
245
|
// Periodic check
|
|
202
246
|
_timer = setInterval(() => {
|
|
203
|
-
const result = checkForUpdate();
|
|
247
|
+
const result = checkForUpdate(cwd);
|
|
204
248
|
if (result?.available) {
|
|
205
249
|
const upgraded = upgrade(cwd, logger);
|
|
206
250
|
if (upgraded.success && onUpdate) {
|