squad-openclaw 2026.2.2011 → 2026.2.2013
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/index.js +183 -21
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1231,6 +1231,9 @@ import { fileURLToPath } from "url";
|
|
|
1231
1231
|
var PACKAGE_NAME = "squad-openclaw";
|
|
1232
1232
|
var CONFIG_PATH = path6.join(getOpenclawStateDir(), "openclaw.json");
|
|
1233
1233
|
var updateInProgress = false;
|
|
1234
|
+
var VERIFY_TIMEOUT_MS = 2e4;
|
|
1235
|
+
var VERIFY_INTERVAL_MS = 500;
|
|
1236
|
+
var RESTART_BUFFER_MS = 5e3;
|
|
1234
1237
|
function getCurrentVersion() {
|
|
1235
1238
|
const thisFile = fileURLToPath(import.meta.url);
|
|
1236
1239
|
const pkgPath = path6.resolve(path6.dirname(thisFile), "..", "package.json");
|
|
@@ -1255,6 +1258,145 @@ async function fetchLatestVersion() {
|
|
|
1255
1258
|
clearTimeout(timeout);
|
|
1256
1259
|
}
|
|
1257
1260
|
}
|
|
1261
|
+
function runDoctorFixSilently() {
|
|
1262
|
+
try {
|
|
1263
|
+
execSync2("openclaw doctor --fix 2>/dev/null || true", {
|
|
1264
|
+
timeout: 3e4,
|
|
1265
|
+
encoding: "utf-8"
|
|
1266
|
+
});
|
|
1267
|
+
} catch {
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
function sleep(ms) {
|
|
1271
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1272
|
+
}
|
|
1273
|
+
function verifyInstalledPluginState() {
|
|
1274
|
+
let configRaw;
|
|
1275
|
+
try {
|
|
1276
|
+
configRaw = fs5.readFileSync(CONFIG_PATH, "utf-8");
|
|
1277
|
+
} catch (err2) {
|
|
1278
|
+
const msg = err2 instanceof Error ? err2.message : String(err2);
|
|
1279
|
+
return {
|
|
1280
|
+
ok: false,
|
|
1281
|
+
reason: `Could not read openclaw.json: ${msg}`,
|
|
1282
|
+
installPath: null,
|
|
1283
|
+
configVersion: null,
|
|
1284
|
+
packageVersion: null,
|
|
1285
|
+
requiredFilesMissing: []
|
|
1286
|
+
};
|
|
1287
|
+
}
|
|
1288
|
+
let config;
|
|
1289
|
+
try {
|
|
1290
|
+
config = JSON.parse(configRaw);
|
|
1291
|
+
} catch (err2) {
|
|
1292
|
+
const msg = err2 instanceof Error ? err2.message : String(err2);
|
|
1293
|
+
return {
|
|
1294
|
+
ok: false,
|
|
1295
|
+
reason: `Could not parse openclaw.json: ${msg}`,
|
|
1296
|
+
installPath: null,
|
|
1297
|
+
configVersion: null,
|
|
1298
|
+
packageVersion: null,
|
|
1299
|
+
requiredFilesMissing: []
|
|
1300
|
+
};
|
|
1301
|
+
}
|
|
1302
|
+
const installMeta = config?.plugins?.installs?.[PACKAGE_NAME];
|
|
1303
|
+
const installPath = typeof installMeta?.installPath === "string" ? installMeta.installPath : null;
|
|
1304
|
+
const configVersion = typeof installMeta?.version === "string" ? installMeta.version : null;
|
|
1305
|
+
if (!installPath) {
|
|
1306
|
+
return {
|
|
1307
|
+
ok: false,
|
|
1308
|
+
reason: "Missing plugins.installs entry or installPath for squad-openclaw",
|
|
1309
|
+
installPath: null,
|
|
1310
|
+
configVersion,
|
|
1311
|
+
packageVersion: null,
|
|
1312
|
+
requiredFilesMissing: []
|
|
1313
|
+
};
|
|
1314
|
+
}
|
|
1315
|
+
const requiredFiles = [
|
|
1316
|
+
path6.join(installPath, "package.json"),
|
|
1317
|
+
path6.join(installPath, "openclaw.plugin.json"),
|
|
1318
|
+
path6.join(installPath, "dist", "index.js")
|
|
1319
|
+
];
|
|
1320
|
+
const requiredFilesMissing = requiredFiles.filter((p) => !fs5.existsSync(p));
|
|
1321
|
+
if (requiredFilesMissing.length > 0) {
|
|
1322
|
+
return {
|
|
1323
|
+
ok: false,
|
|
1324
|
+
reason: "Missing required installed plugin files",
|
|
1325
|
+
installPath,
|
|
1326
|
+
configVersion,
|
|
1327
|
+
packageVersion: null,
|
|
1328
|
+
requiredFilesMissing
|
|
1329
|
+
};
|
|
1330
|
+
}
|
|
1331
|
+
let installedPackage;
|
|
1332
|
+
try {
|
|
1333
|
+
installedPackage = JSON.parse(
|
|
1334
|
+
fs5.readFileSync(path6.join(installPath, "package.json"), "utf-8")
|
|
1335
|
+
);
|
|
1336
|
+
} catch (err2) {
|
|
1337
|
+
const msg = err2 instanceof Error ? err2.message : String(err2);
|
|
1338
|
+
return {
|
|
1339
|
+
ok: false,
|
|
1340
|
+
reason: `Could not parse installed package.json: ${msg}`,
|
|
1341
|
+
installPath,
|
|
1342
|
+
configVersion,
|
|
1343
|
+
packageVersion: null,
|
|
1344
|
+
requiredFilesMissing: []
|
|
1345
|
+
};
|
|
1346
|
+
}
|
|
1347
|
+
try {
|
|
1348
|
+
JSON.parse(
|
|
1349
|
+
fs5.readFileSync(path6.join(installPath, "openclaw.plugin.json"), "utf-8")
|
|
1350
|
+
);
|
|
1351
|
+
} catch (err2) {
|
|
1352
|
+
const msg = err2 instanceof Error ? err2.message : String(err2);
|
|
1353
|
+
return {
|
|
1354
|
+
ok: false,
|
|
1355
|
+
reason: `Could not parse installed openclaw.plugin.json: ${msg}`,
|
|
1356
|
+
installPath,
|
|
1357
|
+
configVersion,
|
|
1358
|
+
packageVersion: null,
|
|
1359
|
+
requiredFilesMissing: []
|
|
1360
|
+
};
|
|
1361
|
+
}
|
|
1362
|
+
const packageVersion = typeof installedPackage?.version === "string" ? installedPackage.version : null;
|
|
1363
|
+
if (!packageVersion) {
|
|
1364
|
+
return {
|
|
1365
|
+
ok: false,
|
|
1366
|
+
reason: "Installed package.json missing version",
|
|
1367
|
+
installPath,
|
|
1368
|
+
configVersion,
|
|
1369
|
+
packageVersion,
|
|
1370
|
+
requiredFilesMissing: []
|
|
1371
|
+
};
|
|
1372
|
+
}
|
|
1373
|
+
if (configVersion && configVersion !== packageVersion) {
|
|
1374
|
+
return {
|
|
1375
|
+
ok: false,
|
|
1376
|
+
reason: `Version mismatch: config=${configVersion}, package=${packageVersion}`,
|
|
1377
|
+
installPath,
|
|
1378
|
+
configVersion,
|
|
1379
|
+
packageVersion,
|
|
1380
|
+
requiredFilesMissing: []
|
|
1381
|
+
};
|
|
1382
|
+
}
|
|
1383
|
+
return {
|
|
1384
|
+
ok: true,
|
|
1385
|
+
installPath,
|
|
1386
|
+
configVersion,
|
|
1387
|
+
packageVersion,
|
|
1388
|
+
requiredFilesMissing: []
|
|
1389
|
+
};
|
|
1390
|
+
}
|
|
1391
|
+
async function waitForVerifiedInstall() {
|
|
1392
|
+
const deadline = Date.now() + VERIFY_TIMEOUT_MS;
|
|
1393
|
+
let last = verifyInstalledPluginState();
|
|
1394
|
+
while (!last.ok && Date.now() < deadline) {
|
|
1395
|
+
await sleep(VERIFY_INTERVAL_MS);
|
|
1396
|
+
last = verifyInstalledPluginState();
|
|
1397
|
+
}
|
|
1398
|
+
return last;
|
|
1399
|
+
}
|
|
1258
1400
|
function registerVersionMethods(api) {
|
|
1259
1401
|
api.registerGatewayMethod(
|
|
1260
1402
|
"squad.version.check",
|
|
@@ -1300,29 +1442,48 @@ function registerVersionMethods(api) {
|
|
|
1300
1442
|
configBackup = fs5.readFileSync(CONFIG_PATH, "utf-8");
|
|
1301
1443
|
} catch {
|
|
1302
1444
|
}
|
|
1303
|
-
|
|
1304
|
-
execSync2("openclaw doctor --fix 2>&1", {
|
|
1305
|
-
timeout: 3e4,
|
|
1306
|
-
encoding: "utf-8"
|
|
1307
|
-
});
|
|
1308
|
-
} catch {
|
|
1309
|
-
}
|
|
1445
|
+
runDoctorFixSilently();
|
|
1310
1446
|
try {
|
|
1311
1447
|
updateOutput = execSync2(
|
|
1312
1448
|
`openclaw plugins update ${PACKAGE_NAME} 2>&1`,
|
|
1313
1449
|
{ timeout: 12e4, encoding: "utf-8" }
|
|
1314
1450
|
);
|
|
1315
|
-
} catch (
|
|
1451
|
+
} catch (firstErr) {
|
|
1452
|
+
runDoctorFixSilently();
|
|
1453
|
+
try {
|
|
1454
|
+
updateOutput = execSync2(
|
|
1455
|
+
`openclaw plugins update ${PACKAGE_NAME} 2>&1`,
|
|
1456
|
+
{ timeout: 12e4, encoding: "utf-8" }
|
|
1457
|
+
);
|
|
1458
|
+
} catch (installErr) {
|
|
1459
|
+
if (configBackup) {
|
|
1460
|
+
try {
|
|
1461
|
+
fs5.writeFileSync(CONFIG_PATH, configBackup, "utf-8");
|
|
1462
|
+
} catch {
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
const firstMsg = firstErr instanceof Error ? firstErr.message : String(firstErr);
|
|
1466
|
+
const retryMsg = installErr instanceof Error ? installErr.message : String(installErr);
|
|
1467
|
+
respond(false, {
|
|
1468
|
+
error: `Update failed after doctor fix retry: ${retryMsg}`,
|
|
1469
|
+
output: updateOutput,
|
|
1470
|
+
firstError: firstMsg
|
|
1471
|
+
});
|
|
1472
|
+
return;
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
const verification = await waitForVerifiedInstall();
|
|
1476
|
+
if (!verification.ok) {
|
|
1316
1477
|
if (configBackup) {
|
|
1317
1478
|
try {
|
|
1318
1479
|
fs5.writeFileSync(CONFIG_PATH, configBackup, "utf-8");
|
|
1319
1480
|
} catch {
|
|
1320
1481
|
}
|
|
1321
1482
|
}
|
|
1322
|
-
const msg = installErr instanceof Error ? installErr.message : String(installErr);
|
|
1323
1483
|
respond(false, {
|
|
1324
|
-
error: `Update failed: ${
|
|
1325
|
-
output: updateOutput
|
|
1484
|
+
error: `Update verification failed: ${verification.reason ?? "unknown error"}`,
|
|
1485
|
+
output: updateOutput.slice(0, 500),
|
|
1486
|
+
verification
|
|
1326
1487
|
});
|
|
1327
1488
|
return;
|
|
1328
1489
|
}
|
|
@@ -1332,20 +1493,21 @@ function registerVersionMethods(api) {
|
|
|
1332
1493
|
currentVersion: after,
|
|
1333
1494
|
updated: true,
|
|
1334
1495
|
restartRequired: true,
|
|
1496
|
+
restartInMs: RESTART_BUFFER_MS,
|
|
1497
|
+
verification,
|
|
1335
1498
|
output: updateOutput.slice(0, 500)
|
|
1336
1499
|
});
|
|
1500
|
+
await sleep(RESTART_BUFFER_MS);
|
|
1337
1501
|
console.log(
|
|
1338
|
-
`[version] Plugin update
|
|
1502
|
+
`[version] Plugin update verified (was ${before}), restarting gateway...`
|
|
1339
1503
|
);
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
}
|
|
1348
|
-
}, 2e3);
|
|
1504
|
+
try {
|
|
1505
|
+
execSync2("openclaw gateway restart 2>&1", {
|
|
1506
|
+
timeout: 3e4,
|
|
1507
|
+
encoding: "utf-8"
|
|
1508
|
+
});
|
|
1509
|
+
} catch {
|
|
1510
|
+
}
|
|
1349
1511
|
} catch (e) {
|
|
1350
1512
|
const msg = e instanceof Error ? e.message : String(e);
|
|
1351
1513
|
respond(false, { error: msg });
|
package/package.json
CHANGED