cfpilot 0.7.3 → 0.8.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 +93 -0
- package/assets/control.js +14 -0
- package/assets/dataplane.js +4 -0
- package/assets/{cfpilot-worker.js → worker.js} +11 -11
- package/dist/cli.js +424 -70
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -87,7 +87,7 @@ var VERSION, NAME;
|
|
|
87
87
|
var init_version = __esm({
|
|
88
88
|
"src/shared/version.ts"() {
|
|
89
89
|
"use strict";
|
|
90
|
-
VERSION = "0.
|
|
90
|
+
VERSION = "0.8.1";
|
|
91
91
|
NAME = "cfpilot";
|
|
92
92
|
}
|
|
93
93
|
});
|
|
@@ -1354,6 +1354,317 @@ var init_token_check = __esm({
|
|
|
1354
1354
|
}
|
|
1355
1355
|
});
|
|
1356
1356
|
|
|
1357
|
+
// src/shared/version-util.ts
|
|
1358
|
+
function parseVersion(input) {
|
|
1359
|
+
const text = input.trim();
|
|
1360
|
+
if (!text) return null;
|
|
1361
|
+
const matched = VERSION_RE.exec(text);
|
|
1362
|
+
if (!matched) return null;
|
|
1363
|
+
const major = Number(matched[1]);
|
|
1364
|
+
const minor = matched[2] === void 0 ? 0 : Number(matched[2]);
|
|
1365
|
+
const patch = matched[3] === void 0 ? 0 : Number(matched[3]);
|
|
1366
|
+
if (!Number.isFinite(major) || !Number.isFinite(minor) || !Number.isFinite(patch)) {
|
|
1367
|
+
return null;
|
|
1368
|
+
}
|
|
1369
|
+
const rest = matched[4] ?? "";
|
|
1370
|
+
let prerelease = [];
|
|
1371
|
+
if (rest === "") {
|
|
1372
|
+
} else if (rest.startsWith("-")) {
|
|
1373
|
+
const pre = rest.slice(1);
|
|
1374
|
+
if (!pre) return null;
|
|
1375
|
+
prerelease = pre.split(".");
|
|
1376
|
+
} else if (rest.startsWith("+")) {
|
|
1377
|
+
} else {
|
|
1378
|
+
return null;
|
|
1379
|
+
}
|
|
1380
|
+
return { major, minor, patch, prerelease };
|
|
1381
|
+
}
|
|
1382
|
+
function compareSemver(a, b) {
|
|
1383
|
+
const va = parseVersion(a);
|
|
1384
|
+
const vb = parseVersion(b);
|
|
1385
|
+
if (!va && !vb) return 0;
|
|
1386
|
+
if (!va) return -1;
|
|
1387
|
+
if (!vb) return 1;
|
|
1388
|
+
if (va.major !== vb.major) return va.major > vb.major ? 1 : -1;
|
|
1389
|
+
if (va.minor !== vb.minor) return va.minor > vb.minor ? 1 : -1;
|
|
1390
|
+
if (va.patch !== vb.patch) return va.patch > vb.patch ? 1 : -1;
|
|
1391
|
+
return comparePrerelease(va.prerelease, vb.prerelease);
|
|
1392
|
+
}
|
|
1393
|
+
function comparePrerelease(a, b) {
|
|
1394
|
+
if (a.length === 0 && b.length === 0) return 0;
|
|
1395
|
+
if (a.length === 0) return 1;
|
|
1396
|
+
if (b.length === 0) return -1;
|
|
1397
|
+
const len = Math.max(a.length, b.length);
|
|
1398
|
+
for (let i = 0; i < len; i++) {
|
|
1399
|
+
const x = a[i];
|
|
1400
|
+
const y = b[i];
|
|
1401
|
+
if (x === void 0) return -1;
|
|
1402
|
+
if (y === void 0) return 1;
|
|
1403
|
+
const c2 = comparePrereleaseIdentifier(x, y);
|
|
1404
|
+
if (c2 !== 0) return c2;
|
|
1405
|
+
}
|
|
1406
|
+
return 0;
|
|
1407
|
+
}
|
|
1408
|
+
function comparePrereleaseIdentifier(a, b) {
|
|
1409
|
+
const aNumeric = /^\d+$/.test(a);
|
|
1410
|
+
const bNumeric = /^\d+$/.test(b);
|
|
1411
|
+
if (aNumeric && bNumeric) {
|
|
1412
|
+
const na = Number(a);
|
|
1413
|
+
const nb = Number(b);
|
|
1414
|
+
if (na !== nb) return na > nb ? 1 : -1;
|
|
1415
|
+
return 0;
|
|
1416
|
+
}
|
|
1417
|
+
if (aNumeric) return -1;
|
|
1418
|
+
if (bNumeric) return 1;
|
|
1419
|
+
if (a === b) return 0;
|
|
1420
|
+
return a < b ? -1 : 1;
|
|
1421
|
+
}
|
|
1422
|
+
var VERSION_RE;
|
|
1423
|
+
var init_version_util = __esm({
|
|
1424
|
+
"src/shared/version-util.ts"() {
|
|
1425
|
+
"use strict";
|
|
1426
|
+
VERSION_RE = /^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(.*)$/;
|
|
1427
|
+
}
|
|
1428
|
+
});
|
|
1429
|
+
|
|
1430
|
+
// src/deploy/kernel-remote.ts
|
|
1431
|
+
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
1432
|
+
import { homedir as homedir2 } from "node:os";
|
|
1433
|
+
import { dirname, join as join2, resolve } from "node:path";
|
|
1434
|
+
import { fileURLToPath } from "node:url";
|
|
1435
|
+
function versionFromTag(tag) {
|
|
1436
|
+
const text = tag.trim();
|
|
1437
|
+
for (const prefix of ["desktop-v", "gui-v", "v"]) {
|
|
1438
|
+
if (text.startsWith(prefix)) {
|
|
1439
|
+
const rest = text.slice(prefix.length);
|
|
1440
|
+
return /^\d+\.\d+\.\d+/.test(rest) ? rest : "";
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
return "";
|
|
1444
|
+
}
|
|
1445
|
+
async function fetchRemoteKernelInfo(options = {}) {
|
|
1446
|
+
if (isRemoteDisabled()) return null;
|
|
1447
|
+
let releases;
|
|
1448
|
+
try {
|
|
1449
|
+
const response = await fetch(`${RELEASES_API}?per_page=20`, {
|
|
1450
|
+
headers: {
|
|
1451
|
+
Accept: "application/vnd.github+json",
|
|
1452
|
+
"User-Agent": "CFPilot-CLI"
|
|
1453
|
+
},
|
|
1454
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS)
|
|
1455
|
+
});
|
|
1456
|
+
if (!response.ok) return null;
|
|
1457
|
+
const payload = await response.json();
|
|
1458
|
+
if (!Array.isArray(payload)) return null;
|
|
1459
|
+
releases = payload.filter(isGitHubRelease);
|
|
1460
|
+
} catch {
|
|
1461
|
+
return null;
|
|
1462
|
+
}
|
|
1463
|
+
const sorted = releases.filter((release) => !release.draft && !release.prerelease).map((release) => ({ release, version: versionFromTag(release.tag_name) })).filter((item) => item.version !== "").sort((a, b) => compareSemver(b.version, a.version));
|
|
1464
|
+
for (const item of sorted) {
|
|
1465
|
+
const controlUrl = findAssetUrl(item.release.assets ?? [], CONTROL_ASSET_NAME);
|
|
1466
|
+
const dataUrl = findAssetUrl(item.release.assets ?? [], DATA_ASSET_NAME);
|
|
1467
|
+
if (!controlUrl || !dataUrl) {
|
|
1468
|
+
continue;
|
|
1469
|
+
}
|
|
1470
|
+
return { version: item.version, controlUrl, dataUrl };
|
|
1471
|
+
}
|
|
1472
|
+
return null;
|
|
1473
|
+
}
|
|
1474
|
+
function findAssetUrl(assets, name) {
|
|
1475
|
+
for (const asset of assets) {
|
|
1476
|
+
if (asset.name.trim().toLowerCase() === name) return asset.browser_download_url;
|
|
1477
|
+
}
|
|
1478
|
+
return "";
|
|
1479
|
+
}
|
|
1480
|
+
function isRemoteDisabled() {
|
|
1481
|
+
const raw = process.env[REMOTE_OFF_ENV]?.trim().toLowerCase();
|
|
1482
|
+
if (!raw) return false;
|
|
1483
|
+
return ["0", "false", "no", "off"].includes(raw);
|
|
1484
|
+
}
|
|
1485
|
+
function isGitHubRelease(value) {
|
|
1486
|
+
if (typeof value !== "object" || value === null) return false;
|
|
1487
|
+
const item = value;
|
|
1488
|
+
if (typeof item.tag_name !== "string") return false;
|
|
1489
|
+
if (item.assets !== void 0 && !Array.isArray(item.assets)) return false;
|
|
1490
|
+
return true;
|
|
1491
|
+
}
|
|
1492
|
+
async function downloadAsset(url, timeoutMs) {
|
|
1493
|
+
if (!url.trim()) throw new Error("\u4E0B\u8F7D\u5730\u5740\u4E3A\u7A7A");
|
|
1494
|
+
const response = await fetch(url, {
|
|
1495
|
+
headers: { "User-Agent": "CFPilot-CLI" },
|
|
1496
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
1497
|
+
});
|
|
1498
|
+
if (!response.ok) {
|
|
1499
|
+
throw new Error(`\u4E0B\u8F7D\u5931\u8D25\uFF1AHTTP ${response.status}`);
|
|
1500
|
+
}
|
|
1501
|
+
const declared = response.headers.get("content-length");
|
|
1502
|
+
if (declared) {
|
|
1503
|
+
const size = Number(declared);
|
|
1504
|
+
if (Number.isFinite(size) && size > MAX_ASSET_BYTES) {
|
|
1505
|
+
throw new Error(`\u5185\u6838\u4EA7\u7269\u8D85\u8FC7 ${MAX_ASSET_BYTES} \u5B57\u8282\u4E0A\u9650\uFF0C\u7591\u4F3C\u5F02\u5E38\u5185\u5BB9`);
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
return await readBodyWithLimit(response);
|
|
1509
|
+
}
|
|
1510
|
+
async function readBodyWithLimit(response) {
|
|
1511
|
+
const body = response.body;
|
|
1512
|
+
if (!body) {
|
|
1513
|
+
const text = await response.text();
|
|
1514
|
+
if (Buffer.byteLength(text) > MAX_ASSET_BYTES) {
|
|
1515
|
+
throw new Error(`\u5185\u6838\u4EA7\u7269\u8D85\u8FC7 ${MAX_ASSET_BYTES} \u5B57\u8282\u4E0A\u9650\uFF0C\u7591\u4F3C\u5F02\u5E38\u5185\u5BB9`);
|
|
1516
|
+
}
|
|
1517
|
+
return text;
|
|
1518
|
+
}
|
|
1519
|
+
const reader = body.getReader();
|
|
1520
|
+
const decoder = new TextDecoder();
|
|
1521
|
+
let total = 0;
|
|
1522
|
+
let out = "";
|
|
1523
|
+
try {
|
|
1524
|
+
for (; ; ) {
|
|
1525
|
+
const { done, value } = await reader.read();
|
|
1526
|
+
if (done) break;
|
|
1527
|
+
if (!value) continue;
|
|
1528
|
+
const chunk = value;
|
|
1529
|
+
total += chunk.byteLength;
|
|
1530
|
+
if (total > MAX_ASSET_BYTES) {
|
|
1531
|
+
await reader.cancel().catch(() => void 0);
|
|
1532
|
+
throw new Error(`\u5185\u6838\u4EA7\u7269\u8D85\u8FC7 ${MAX_ASSET_BYTES} \u5B57\u8282\u4E0A\u9650\uFF0C\u7591\u4F3C\u5F02\u5E38\u5185\u5BB9`);
|
|
1533
|
+
}
|
|
1534
|
+
out += decoder.decode(chunk, { stream: true });
|
|
1535
|
+
}
|
|
1536
|
+
} finally {
|
|
1537
|
+
reader.releaseLock();
|
|
1538
|
+
}
|
|
1539
|
+
out += decoder.decode();
|
|
1540
|
+
return out;
|
|
1541
|
+
}
|
|
1542
|
+
function cacheRoot() {
|
|
1543
|
+
const override = process.env[CACHE_DIR_ENV]?.trim();
|
|
1544
|
+
if (override) return override;
|
|
1545
|
+
return join2(homedir2(), ".cfpilot", "kernel");
|
|
1546
|
+
}
|
|
1547
|
+
function cacheDir(version) {
|
|
1548
|
+
return join2(cacheRoot(), version);
|
|
1549
|
+
}
|
|
1550
|
+
async function readCached(path) {
|
|
1551
|
+
try {
|
|
1552
|
+
const text = await readFile(path, "utf8");
|
|
1553
|
+
return text.length > 0 ? text : null;
|
|
1554
|
+
} catch {
|
|
1555
|
+
return null;
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
async function writeCached(path, content) {
|
|
1559
|
+
await mkdir(dirname(path), { recursive: true });
|
|
1560
|
+
const tmp = `${path}.tmp`;
|
|
1561
|
+
await writeFile(tmp, content, "utf8");
|
|
1562
|
+
try {
|
|
1563
|
+
await rename(tmp, path);
|
|
1564
|
+
} catch {
|
|
1565
|
+
await writeFile(path, content, "utf8").catch(() => void 0);
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
function moduleDir() {
|
|
1569
|
+
try {
|
|
1570
|
+
const meta = import.meta;
|
|
1571
|
+
if (meta && typeof meta.url === "string") return dirname(fileURLToPath(meta.url));
|
|
1572
|
+
} catch {
|
|
1573
|
+
}
|
|
1574
|
+
return typeof __dirname === "string" ? __dirname : process.cwd();
|
|
1575
|
+
}
|
|
1576
|
+
async function loadBuiltinBundle(fileName) {
|
|
1577
|
+
const override = process.env[LOCAL_DIR_ENV]?.trim();
|
|
1578
|
+
const candidates = override ? [resolve(override, fileName)] : [
|
|
1579
|
+
resolve(moduleDir(), `../worker-core/dist/${fileName}`),
|
|
1580
|
+
resolve(moduleDir(), `../../worker-core/dist/${fileName}`),
|
|
1581
|
+
resolve(moduleDir(), `../assets/${fileName}`),
|
|
1582
|
+
resolve(moduleDir(), `../../assets/${fileName}`),
|
|
1583
|
+
resolve(process.cwd(), `packages/worker-core/dist/${fileName}`)
|
|
1584
|
+
];
|
|
1585
|
+
for (const candidate of candidates) {
|
|
1586
|
+
try {
|
|
1587
|
+
const text = await readFile(candidate, "utf8");
|
|
1588
|
+
if (text.length > 0) return text;
|
|
1589
|
+
} catch {
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
throw new Error(
|
|
1593
|
+
`\u672A\u627E\u5230 ${fileName}\uFF0C\u8BF7\u5148\u6267\u884C npm run build -w @cfpilot/worker-core`
|
|
1594
|
+
);
|
|
1595
|
+
}
|
|
1596
|
+
function extractBuildVersion(source) {
|
|
1597
|
+
const matched = BUILD_RE.exec(source);
|
|
1598
|
+
if (matched?.[1]) return matched[1];
|
|
1599
|
+
const numeric = BUILD_NUMERIC_RE.exec(source);
|
|
1600
|
+
if (numeric?.[1]) return numeric[1];
|
|
1601
|
+
return "";
|
|
1602
|
+
}
|
|
1603
|
+
async function loadKernelBundle(currentVersion, options = {}) {
|
|
1604
|
+
const log = options.log ?? (() => {
|
|
1605
|
+
});
|
|
1606
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
1607
|
+
const remote = await fetchRemoteKernelInfo({ timeoutMs });
|
|
1608
|
+
if (remote && compareSemver(remote.version, currentVersion) > 0) {
|
|
1609
|
+
try {
|
|
1610
|
+
const bundle = await fetchRemoteKernel(remote, timeoutMs);
|
|
1611
|
+
return {
|
|
1612
|
+
control: bundle.control,
|
|
1613
|
+
data: bundle.data,
|
|
1614
|
+
version: remote.version,
|
|
1615
|
+
source: `\u8FDC\u7A0B ${remote.version}`
|
|
1616
|
+
};
|
|
1617
|
+
} catch (err) {
|
|
1618
|
+
log(
|
|
1619
|
+
`\xB7 \u8FDC\u7A0B\u5185\u6838 ${remote.version} \u83B7\u53D6\u5931\u8D25\uFF0C\u6539\u7528\u5185\u7F6E\u5185\u6838\uFF1A` + (err instanceof Error ? err.message : String(err))
|
|
1620
|
+
);
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
const control = await loadBuiltinBundle("control.js");
|
|
1624
|
+
const data = await loadBuiltinBundle("dataplane.js");
|
|
1625
|
+
return {
|
|
1626
|
+
control,
|
|
1627
|
+
data,
|
|
1628
|
+
version: currentVersion,
|
|
1629
|
+
source: `\u5185\u7F6E ${currentVersion}`
|
|
1630
|
+
};
|
|
1631
|
+
}
|
|
1632
|
+
async function fetchRemoteKernel(info, timeoutMs) {
|
|
1633
|
+
const dir = cacheDir(info.version);
|
|
1634
|
+
const controlPath = join2(dir, "control.js");
|
|
1635
|
+
const dataPath = join2(dir, "dataplane.js");
|
|
1636
|
+
const cachedControl = await readCached(controlPath);
|
|
1637
|
+
const cachedData = await readCached(dataPath);
|
|
1638
|
+
if (cachedControl && cachedData) {
|
|
1639
|
+
return { control: cachedControl, data: cachedData };
|
|
1640
|
+
}
|
|
1641
|
+
const control = cachedControl ?? await downloadAsset(info.controlUrl, timeoutMs);
|
|
1642
|
+
const data = cachedData ?? await downloadAsset(info.dataUrl, timeoutMs);
|
|
1643
|
+
if (!control.trim()) throw new Error("\u4E0B\u8F7D\u5230\u7684\u63A7\u5236\u9762\u4EA7\u7269\u4E3A\u7A7A");
|
|
1644
|
+
if (!data.trim()) throw new Error("\u4E0B\u8F7D\u5230\u7684\u6570\u636E\u9762\u4EA7\u7269\u4E3A\u7A7A");
|
|
1645
|
+
await writeCached(controlPath, control).catch(() => void 0);
|
|
1646
|
+
await writeCached(dataPath, data).catch(() => void 0);
|
|
1647
|
+
return { control, data };
|
|
1648
|
+
}
|
|
1649
|
+
var CONTROL_ASSET_NAME, DATA_ASSET_NAME, REPO, RELEASES_API, DEFAULT_TIMEOUT_MS, MAX_ASSET_BYTES, CACHE_DIR_ENV, LOCAL_DIR_ENV, REMOTE_OFF_ENV, BUILD_RE, BUILD_NUMERIC_RE;
|
|
1650
|
+
var init_kernel_remote = __esm({
|
|
1651
|
+
"src/deploy/kernel-remote.ts"() {
|
|
1652
|
+
"use strict";
|
|
1653
|
+
init_version_util();
|
|
1654
|
+
CONTROL_ASSET_NAME = "cfpilot-kernel-control.js";
|
|
1655
|
+
DATA_ASSET_NAME = "cfpilot-kernel-dataplane.js";
|
|
1656
|
+
REPO = "xmwengxing/CFPilot";
|
|
1657
|
+
RELEASES_API = process.env.CFPILOT_KERNEL_API_BASE ?? `https://api.github.com/repos/${REPO}/releases`;
|
|
1658
|
+
DEFAULT_TIMEOUT_MS = 2e4;
|
|
1659
|
+
MAX_ASSET_BYTES = 10 * 1024 * 1024;
|
|
1660
|
+
CACHE_DIR_ENV = "CFPILOT_KERNEL_CACHE_DIR";
|
|
1661
|
+
LOCAL_DIR_ENV = "CFPILOT_KERNEL_DIR";
|
|
1662
|
+
REMOTE_OFF_ENV = "CFPILOT_KERNEL_REMOTE";
|
|
1663
|
+
BUILD_RE = /["']([0-9a-f]{7,10}-(?:[0-9a-f]{4,16}|[0-9]{12}))["']/;
|
|
1664
|
+
BUILD_NUMERIC_RE = /["'](\d{10,14})["']/;
|
|
1665
|
+
}
|
|
1666
|
+
});
|
|
1667
|
+
|
|
1357
1668
|
// src/deploy/pages-deploy.ts
|
|
1358
1669
|
var pages_deploy_exports = {};
|
|
1359
1670
|
__export(pages_deploy_exports, {
|
|
@@ -1364,9 +1675,6 @@ __export(pages_deploy_exports, {
|
|
|
1364
1675
|
listCfPilotNamespaces: () => listCfPilotNamespaces,
|
|
1365
1676
|
readManifest: () => readManifest
|
|
1366
1677
|
});
|
|
1367
|
-
import { readFile } from "node:fs/promises";
|
|
1368
|
-
import { dirname, resolve } from "node:path";
|
|
1369
|
-
import { fileURLToPath } from "node:url";
|
|
1370
1678
|
import { randomBytes as randomBytes2, randomUUID } from "node:crypto";
|
|
1371
1679
|
async function readManifest(client, accountId, namespaceId) {
|
|
1372
1680
|
try {
|
|
@@ -1498,31 +1806,55 @@ async function writeEffectiveConfig(client, accountId, namespaceId, effective, o
|
|
|
1498
1806
|
);
|
|
1499
1807
|
}
|
|
1500
1808
|
}
|
|
1501
|
-
function
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
} catch {
|
|
1506
|
-
}
|
|
1507
|
-
return typeof __dirname === "string" ? __dirname : process.cwd();
|
|
1508
|
-
}
|
|
1509
|
-
async function loadBundle(fileName) {
|
|
1510
|
-
const here = moduleDir();
|
|
1511
|
-
const candidates = [
|
|
1512
|
-
resolve(here, `../worker-core/dist/${fileName}`),
|
|
1513
|
-
resolve(here, `../../worker-core/dist/${fileName}`),
|
|
1514
|
-
resolve(here, `../assets/${fileName}`),
|
|
1515
|
-
resolve(process.cwd(), `packages/worker-core/dist/${fileName}`)
|
|
1516
|
-
];
|
|
1517
|
-
for (const candidate of candidates) {
|
|
1809
|
+
async function resolveKernel(options, log, warnings) {
|
|
1810
|
+
const explicitControl = options.bundles?.control ?? "";
|
|
1811
|
+
const explicitData = options.bundles?.data ?? "";
|
|
1812
|
+
if (explicitControl || explicitData) {
|
|
1518
1813
|
try {
|
|
1519
|
-
|
|
1520
|
-
|
|
1814
|
+
const control = explicitControl || await loadBuiltinBundle("control.js");
|
|
1815
|
+
const data = explicitData || await loadBuiltinBundle("dataplane.js");
|
|
1816
|
+
return {
|
|
1817
|
+
control,
|
|
1818
|
+
data,
|
|
1819
|
+
version: options.kernelVersion ?? "",
|
|
1820
|
+
build: extractBuildVersion(control),
|
|
1821
|
+
source: "\u8C03\u7528\u65B9\u6307\u5B9A"
|
|
1822
|
+
};
|
|
1823
|
+
} catch (err) {
|
|
1824
|
+
warnings.push(
|
|
1825
|
+
`\u5185\u6838\u4EA7\u7269\u52A0\u8F7D\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`
|
|
1826
|
+
);
|
|
1827
|
+
return {
|
|
1828
|
+
control: explicitControl,
|
|
1829
|
+
data: explicitData,
|
|
1830
|
+
version: options.kernelVersion ?? "",
|
|
1831
|
+
build: extractBuildVersion(explicitControl),
|
|
1832
|
+
source: "\u4E0D\u53EF\u7528"
|
|
1833
|
+
};
|
|
1521
1834
|
}
|
|
1522
1835
|
}
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1836
|
+
try {
|
|
1837
|
+
const bundle = await loadKernelBundle(VERSION, { log });
|
|
1838
|
+
log(`\xB7 \u5185\u6838\u6765\u6E90\uFF1A${bundle.source}`);
|
|
1839
|
+
return {
|
|
1840
|
+
control: bundle.control,
|
|
1841
|
+
data: bundle.data,
|
|
1842
|
+
version: options.kernelVersion ?? bundle.version,
|
|
1843
|
+
build: extractBuildVersion(bundle.control),
|
|
1844
|
+
source: bundle.source
|
|
1845
|
+
};
|
|
1846
|
+
} catch (err) {
|
|
1847
|
+
warnings.push(
|
|
1848
|
+
`\u5185\u6838\u4EA7\u7269\u52A0\u8F7D\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`
|
|
1849
|
+
);
|
|
1850
|
+
return {
|
|
1851
|
+
control: "",
|
|
1852
|
+
data: "",
|
|
1853
|
+
version: options.kernelVersion ?? "",
|
|
1854
|
+
build: "",
|
|
1855
|
+
source: "\u4E0D\u53EF\u7528"
|
|
1856
|
+
};
|
|
1857
|
+
}
|
|
1526
1858
|
}
|
|
1527
1859
|
function validateOptions(options) {
|
|
1528
1860
|
const problems = [];
|
|
@@ -1596,6 +1928,8 @@ async function deployPagesSplit(options) {
|
|
|
1596
1928
|
warnings
|
|
1597
1929
|
};
|
|
1598
1930
|
const kv = { KV: { namespace_id: options.kvNamespaceId } };
|
|
1931
|
+
const kernel = await resolveKernel(options, log, warnings);
|
|
1932
|
+
const effectiveBuild = kernel.build || (options.localBuild ?? "").trim();
|
|
1599
1933
|
const manifest = await readManifest(client, options.accountId, options.kvNamespaceId);
|
|
1600
1934
|
let effective = {
|
|
1601
1935
|
panelPath: options.panelPath,
|
|
@@ -1628,16 +1962,29 @@ async function deployPagesSplit(options) {
|
|
|
1628
1962
|
log(` \xB7 UUID\uFF1A${effective.uuid}`);
|
|
1629
1963
|
log(` \xB7 WS \u8DEF\u5F84\uFF1A${effective.wsPath}`);
|
|
1630
1964
|
}
|
|
1631
|
-
|
|
1632
|
-
|
|
1965
|
+
const onlineBuild = manifest.build?.trim() ?? "";
|
|
1966
|
+
const onlineVersion = manifest.kernelVersion?.trim() ?? "";
|
|
1967
|
+
const sameBuild = !!effectiveBuild && onlineBuild === effectiveBuild;
|
|
1968
|
+
const wouldDowngrade = !!onlineVersion && !!kernel.version && compareSemver(kernel.version, onlineVersion) < 0;
|
|
1969
|
+
if (skipSameVersion && (sameBuild || wouldDowngrade)) {
|
|
1970
|
+
if (wouldDowngrade && !sameBuild) {
|
|
1971
|
+
log(
|
|
1972
|
+
`\u2705 \u7EBF\u4E0A\u5185\u6838 ${onlineVersion} \u6BD4\u672C\u6B21\u53EF\u7528\u5185\u6838 ${kernel.version} \u66F4\u65B0\uFF0C\u8DF3\u8FC7\u90E8\u7F72\uFF08\u907F\u514D\u964D\u7EA7\uFF09`
|
|
1973
|
+
);
|
|
1974
|
+
} else {
|
|
1975
|
+
log(`\u2705 \u7EBF\u4E0A\u5DF2\u662F\u6700\u65B0\u7248\u672C\uFF08${effectiveBuild}\uFF09\uFF0C\u8DF3\u8FC7\u90E8\u7F72`);
|
|
1976
|
+
}
|
|
1633
1977
|
result.panelPath = effective.panelPath;
|
|
1634
1978
|
result.uuid = effective.uuid;
|
|
1635
1979
|
result.wsPath = effective.wsPath;
|
|
1636
1980
|
result.panelPassword = effective.panelPassword;
|
|
1637
1981
|
return result;
|
|
1638
1982
|
}
|
|
1639
|
-
if (
|
|
1640
|
-
log(`\xB7 \u7248\u672C\u53D8\u5316\uFF1A${
|
|
1983
|
+
if (onlineBuild && effectiveBuild && onlineBuild !== effectiveBuild) {
|
|
1984
|
+
log(`\xB7 \u7248\u672C\u53D8\u5316\uFF1A${onlineBuild} \u2192 ${effectiveBuild}`);
|
|
1985
|
+
}
|
|
1986
|
+
if (onlineVersion && kernel.version && onlineVersion !== kernel.version) {
|
|
1987
|
+
log(`\xB7 \u5185\u6838\u7248\u672C\u53D8\u5316\uFF1A${onlineVersion} \u2192 ${kernel.version}`);
|
|
1641
1988
|
}
|
|
1642
1989
|
} else if (manifest && mode === "fresh") {
|
|
1643
1990
|
log("\xB7 \u6307\u5B9A\u4E86\u9996\u6B21\u90E8\u7F72\u6A21\u5F0F\uFF0C\u5FFD\u7565\u5DF2\u6709\u6E05\u5355");
|
|
@@ -1709,22 +2056,8 @@ async function deployPagesSplit(options) {
|
|
|
1709
2056
|
warnings,
|
|
1710
2057
|
log
|
|
1711
2058
|
);
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
if (!dataCode) {
|
|
1715
|
-
try {
|
|
1716
|
-
dataCode = await loadBundle("dataplane.js");
|
|
1717
|
-
} catch (err) {
|
|
1718
|
-
warnings.push(err instanceof Error ? err.message : String(err));
|
|
1719
|
-
}
|
|
1720
|
-
}
|
|
1721
|
-
if (!controlCode) {
|
|
1722
|
-
try {
|
|
1723
|
-
controlCode = await loadBundle("control.js");
|
|
1724
|
-
} catch (err) {
|
|
1725
|
-
warnings.push(err instanceof Error ? err.message : String(err));
|
|
1726
|
-
}
|
|
1727
|
-
}
|
|
2059
|
+
const dataCode = kernel.data;
|
|
2060
|
+
const controlCode = kernel.control;
|
|
1728
2061
|
let dataCustomDomain = "";
|
|
1729
2062
|
if (previousDataProject) {
|
|
1730
2063
|
const isCustom = (d) => typeof d === "string" && !d.endsWith(".pages.dev");
|
|
@@ -1801,7 +2134,8 @@ async function deployPagesSplit(options) {
|
|
|
1801
2134
|
result.control.subdomain = controlAttempt.subdomain;
|
|
1802
2135
|
}
|
|
1803
2136
|
if (result.control.subdomain && result.data.subdomain) {
|
|
1804
|
-
const build =
|
|
2137
|
+
const build = effectiveBuild;
|
|
2138
|
+
const kernelVersion = kernel.version.trim();
|
|
1805
2139
|
await writeManifest(client, options.accountId, options.kvNamespaceId, {
|
|
1806
2140
|
v: 1,
|
|
1807
2141
|
kvNamespaceId: options.kvNamespaceId,
|
|
@@ -1812,6 +2146,7 @@ async function deployPagesSplit(options) {
|
|
|
1812
2146
|
// 自定义域名:本次迁过来的,或旧项目上原有的(下次更新还要靠它迁移)
|
|
1813
2147
|
dataCustomDomain: dataCustomDomain || manifest?.dataCustomDomain || "",
|
|
1814
2148
|
build,
|
|
2149
|
+
kernelVersion,
|
|
1815
2150
|
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1816
2151
|
credentials: {
|
|
1817
2152
|
panelPath: effective.panelPath,
|
|
@@ -1961,6 +2296,9 @@ var init_pages_deploy = __esm({
|
|
|
1961
2296
|
"use strict";
|
|
1962
2297
|
init_cf_api();
|
|
1963
2298
|
init_utils();
|
|
2299
|
+
init_kernel_remote();
|
|
2300
|
+
init_version_util();
|
|
2301
|
+
init_version();
|
|
1964
2302
|
MANIFEST_KEY = "CFP_DEPLOY_MANIFEST";
|
|
1965
2303
|
}
|
|
1966
2304
|
});
|
|
@@ -2050,14 +2388,17 @@ async function listKvInstances(client, accountId) {
|
|
|
2050
2388
|
`);
|
|
2051
2389
|
const instances = await listCfPilotNamespaces(client, accountId);
|
|
2052
2390
|
const instanceIds = new Set(instances.map((i) => i.id));
|
|
2391
|
+
const remote = await fetchRemoteKernelInfo({ timeoutMs: 8e3 });
|
|
2053
2392
|
for (const ns of namespaces) {
|
|
2054
2393
|
const instance = instances.find((i) => i.id === ns.id);
|
|
2055
2394
|
if (instance) {
|
|
2395
|
+
const online = instance.manifest.kernelVersion?.trim() || "\u672A\u77E5";
|
|
2056
2396
|
process.stdout.write(
|
|
2057
2397
|
` \u25CF ${ns.id} ${ns.title}
|
|
2058
2398
|
\u5B9E\u4F8B\uFF1A\u63A7\u5236\u9762 ${instance.manifest.controlProject} / \u6570\u636E\u9762 ${instance.manifest.dataProject}
|
|
2059
2399
|
\u57DF\u540D\uFF1A${instance.manifest.controlSubdomain} / ${instance.manifest.dataSubdomain}
|
|
2060
2400
|
\u90E8\u7F72\u4E8E ${instance.manifest.at}\uFF0C\u7248\u672C ${instance.manifest.build}
|
|
2401
|
+
\u5185\u6838\u7248\u672C\uFF1A\u7EBF\u4E0A ${online} \uFF5C \u5185\u7F6E ${VERSION} \uFF5C \u8FDC\u7A0B ${remote?.version ?? "\u672A\u77E5"}
|
|
2061
2402
|
`
|
|
2062
2403
|
);
|
|
2063
2404
|
} else {
|
|
@@ -2065,6 +2406,13 @@ async function listKvInstances(client, accountId) {
|
|
|
2065
2406
|
`);
|
|
2066
2407
|
}
|
|
2067
2408
|
}
|
|
2409
|
+
if (remote) {
|
|
2410
|
+
const cmp = compareSemver(remote.version, VERSION);
|
|
2411
|
+
const hint = cmp > 0 ? `\u8FDC\u7A0B\u5185\u6838 ${remote.version} \u6BD4\u5185\u7F6E ${VERSION} \u66F4\u65B0\uFF0C\u90E8\u7F72\u65F6\u4F1A\u81EA\u52A8\u4F7F\u7528\u8FDC\u7A0B\u5185\u6838\u3002` : cmp === 0 ? `\u8FDC\u7A0B\u5185\u6838 ${remote.version} \u4E0E\u5185\u7F6E\u7248\u672C\u4E00\u81F4\u3002` : `\u8FDC\u7A0B\u5185\u6838 ${remote.version} \u6BD4\u5185\u7F6E ${VERSION} \u65E7\uFF0C\u5C06\u4F7F\u7528\u5185\u7F6E\u5185\u6838\u3002`;
|
|
2412
|
+
process.stdout.write(`
|
|
2413
|
+
${hint}
|
|
2414
|
+
`);
|
|
2415
|
+
}
|
|
2068
2416
|
process.stdout.write(
|
|
2069
2417
|
`
|
|
2070
2418
|
\u5171 ${instances.length} \u4E2A CFPilot \u5B9E\u4F8B\u3002
|
|
@@ -2211,23 +2559,8 @@ ${"\u2500".repeat(52)}
|
|
|
2211
2559
|
}
|
|
2212
2560
|
async function readLocalBuild() {
|
|
2213
2561
|
try {
|
|
2214
|
-
const
|
|
2215
|
-
|
|
2216
|
-
const { fileURLToPath: fileURLToPath2 } = await import("node:url");
|
|
2217
|
-
const here = dirname2(fileURLToPath2(import.meta.url));
|
|
2218
|
-
const candidates = [
|
|
2219
|
-
resolve2(here, "../worker-core/dist/control.js"),
|
|
2220
|
-
resolve2(here, "../../worker-core/dist/control.js"),
|
|
2221
|
-
resolve2(process.cwd(), "packages/worker-core/dist/control.js")
|
|
2222
|
-
];
|
|
2223
|
-
for (const candidate of candidates) {
|
|
2224
|
-
try {
|
|
2225
|
-
const code = await readFile2(candidate, "utf8");
|
|
2226
|
-
const m = /["']([0-9a-f]{7,10}-\d{12})["']/.exec(code);
|
|
2227
|
-
if (m) return m[1];
|
|
2228
|
-
} catch {
|
|
2229
|
-
}
|
|
2230
|
-
}
|
|
2562
|
+
const code = await loadBuiltinBundle("control.js");
|
|
2563
|
+
return extractBuildVersion(code) || void 0;
|
|
2231
2564
|
} catch {
|
|
2232
2565
|
}
|
|
2233
2566
|
return void 0;
|
|
@@ -2238,8 +2571,11 @@ var init_command = __esm({
|
|
|
2238
2571
|
init_args();
|
|
2239
2572
|
init_cf_api();
|
|
2240
2573
|
init_pages_deploy();
|
|
2574
|
+
init_kernel_remote();
|
|
2241
2575
|
init_utils();
|
|
2242
2576
|
init_help();
|
|
2577
|
+
init_version_util();
|
|
2578
|
+
init_version();
|
|
2243
2579
|
}
|
|
2244
2580
|
});
|
|
2245
2581
|
|
|
@@ -3219,6 +3555,24 @@ async function pool(items, concurrency, worker, shouldStop) {
|
|
|
3219
3555
|
await Promise.all(runners);
|
|
3220
3556
|
return out;
|
|
3221
3557
|
}
|
|
3558
|
+
async function poolAdaptive(items, concurrency, worker, batchSize = 200) {
|
|
3559
|
+
const out = [];
|
|
3560
|
+
const maxConcurrency = Math.max(1, concurrency);
|
|
3561
|
+
let current = maxConcurrency;
|
|
3562
|
+
for (let start = 0; start < items.length; start += batchSize) {
|
|
3563
|
+
const batch = items.slice(start, start + batchSize);
|
|
3564
|
+
const results = await pool(batch, current, worker);
|
|
3565
|
+
out.push(...results);
|
|
3566
|
+
const okCount = results.reduce((n, r) => n + (r.ok ? 1 : 0), 0);
|
|
3567
|
+
const rate = results.length > 0 ? okCount / results.length : 1;
|
|
3568
|
+
if (rate < 0.4) {
|
|
3569
|
+
current = Math.max(8, Math.floor(current / 2));
|
|
3570
|
+
} else if (rate > 0.85) {
|
|
3571
|
+
current = Math.min(maxConcurrency, current * 2);
|
|
3572
|
+
}
|
|
3573
|
+
}
|
|
3574
|
+
return out;
|
|
3575
|
+
}
|
|
3222
3576
|
function isTimeoutError(error) {
|
|
3223
3577
|
if (!error) return false;
|
|
3224
3578
|
return /超时|timeout|timed out|ETIMEDOUT/i.test(error);
|
|
@@ -3248,7 +3602,7 @@ async function runScan(options) {
|
|
|
3248
3602
|
const speedConcurrency = options.speedConcurrency ?? 4;
|
|
3249
3603
|
const speedTimeoutMs = options.speedTimeoutMs ?? 12e3;
|
|
3250
3604
|
const speedBytes = options.speedBytes ?? 5 * 1024 * 1024;
|
|
3251
|
-
const top = options.top ??
|
|
3605
|
+
const top = options.top ?? 8;
|
|
3252
3606
|
const countryFilter = normalizeCountryFilter(options.countries ?? []);
|
|
3253
3607
|
const hasCountryFilter = countryFilter.length > 0;
|
|
3254
3608
|
const effectiveProbeLimit = hasCountryFilter ? Math.max(probeLimit * 4, 500) : probeLimit;
|
|
@@ -3257,7 +3611,7 @@ async function runScan(options) {
|
|
|
3257
3611
|
});
|
|
3258
3612
|
report({ type: "stage", stage: 1, name: "TCP \u63E1\u624B\u521D\u7B5B", total: candidates.length });
|
|
3259
3613
|
let done = 0;
|
|
3260
|
-
const tcpResults = await
|
|
3614
|
+
const tcpResults = await poolAdaptive(candidates, concurrency, async (ip) => {
|
|
3261
3615
|
const result = await withRetry(retries, () => tcpPing(ip, options.port, tcpTimeoutMs));
|
|
3262
3616
|
done++;
|
|
3263
3617
|
if (done % 500 === 0 || done === candidates.length) {
|
|
@@ -3277,7 +3631,7 @@ async function runScan(options) {
|
|
|
3277
3631
|
const tlsInput = filtered.slice().sort((a, b) => a.latency - b.latency).slice(0, tlsCandidateLimit);
|
|
3278
3632
|
report({ type: "stage", stage: 1, name: "TLS \u63E1\u624B\u7B5B\u9009", total: tlsInput.length });
|
|
3279
3633
|
let tlsDone = 0;
|
|
3280
|
-
const tlsResults = await
|
|
3634
|
+
const tlsResults = await poolAdaptive(tlsInput, tlsConcurrency, async (item) => {
|
|
3281
3635
|
const probe = await withRetry(
|
|
3282
3636
|
retries,
|
|
3283
3637
|
() => probeTlsHandshake(item.ip, options.port, options.host, tlsTimeoutMs),
|
|
@@ -4405,7 +4759,7 @@ async function handleRequest(req, res) {
|
|
|
4405
4759
|
candidates: plan.candidates,
|
|
4406
4760
|
// 国家过滤(可多选):不传 = 全量;无效代码在 normalizeCountryFilter 里被丢弃
|
|
4407
4761
|
countries: Array.isArray(body.countries) ? body.countries : void 0,
|
|
4408
|
-
top: body.top ??
|
|
4762
|
+
top: body.top ?? 8,
|
|
4409
4763
|
// ⚠️ 必须透传这些参数,否则桥接服务永远用默认值:
|
|
4410
4764
|
// wsPath / probePath —— 对接第三方项目(路径不是 /__edge_probe)时,
|
|
4411
4765
|
// 阶段二会硬连默认探针路径 → 全军覆没
|
|
@@ -4546,7 +4900,7 @@ scan \u9009\u9879:
|
|
|
4546
4900
|
\uFF08\u9ED8\u8BA4\u6821\u9A8C\uFF1A\u53D1 PING \u5E76\u9A8C\u8BC1\u6570\u636E\u9762\u56DE {"pong":true}\uFF09
|
|
4547
4901
|
\u76EE\u6807\u6CA1\u6709\u63A2\u9488\u7AEF\u70B9\u65F6\u4F1A\u81EA\u52A8\u964D\u7EA7\u4E3A\u7EAF 101 \u6821\u9A8C
|
|
4548
4902
|
--no-speed \u8DF3\u8FC7\u6D4B\u901F\uFF0C\u53EA\u6309\u5EF6\u8FDF\u6392\u5E8F
|
|
4549
|
-
--top <n> \u8FD4\u56DE\u6761\u6570\uFF0C\u9ED8\u8BA4
|
|
4903
|
+
--top <n> \u8FD4\u56DE\u6761\u6570\uFF0C\u9ED8\u8BA4 8
|
|
4550
4904
|
--concurrency <n> \u9636\u6BB5\u4E00 TCP \u5E76\u53D1\uFF0C\u9ED8\u8BA4 300
|
|
4551
4905
|
--tls-concurrency <n> \u9636\u6BB5\u4E00 TLS \u63E1\u624B\u5E76\u53D1\uFF0C\u9ED8\u8BA4 64
|
|
4552
4906
|
TLS \u63E1\u624B\u662F CPU \u5BC6\u96C6\u578B\u64CD\u4F5C\uFF0C\u8FC7\u9AD8\u4F1A\u8BA9\u672C\u673A\u6210\u4E3A\u74F6\u9888
|
|
@@ -4723,7 +5077,7 @@ async function runScanCommand(args) {
|
|
|
4723
5077
|
process.exit(1);
|
|
4724
5078
|
}
|
|
4725
5079
|
const port = flagNumber(args, "port", 443);
|
|
4726
|
-
const top = flagNumber(args, "top",
|
|
5080
|
+
const top = flagNumber(args, "top", 8);
|
|
4727
5081
|
let token = flagString(args, "token");
|
|
4728
5082
|
const noCallback = flagBool(args, "no-callback");
|
|
4729
5083
|
const askCallback = flagBool(args, "ask-callback");
|