@covro/covro 0.1.1-dev.8 → 0.2.0-beta.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 +9 -21
- package/README.zh-CN.md +9 -21
- package/dist/cli/daemon.js +1 -6
- package/dist/cli/daemon.js.map +2 -2
- package/dist/cli/main.js +35 -7
- package/dist/cli/main.js.map +2 -2
- package/dist/cli/service.js +49 -23
- package/dist/cli/service.js.map +2 -2
- package/dist/codex/adapter.js +1 -68
- package/dist/codex/adapter.js.map +2 -2
- package/dist/server/auth.js +1 -1
- package/dist/server/auth.js.map +2 -2
- package/dist/server/http.js +0 -21
- package/dist/server/http.js.map +2 -2
- package/dist/server/service.js +2 -17
- package/dist/server/service.js.map +2 -2
- package/dist/update-worker.cjs +168 -419
- package/dist/updates/worker.js +61 -7
- package/dist/updates/worker.js.map +2 -2
- package/dist/web/assets/index-Dr0Qkixk.css +1 -0
- package/dist/web/assets/index-z5RGzL8u.js +138 -0
- package/dist/web/index.html +2 -2
- package/package.json +4 -6
- package/dist/cli/background.js +0 -103
- package/dist/cli/background.js.map +0 -7
- package/dist/cli/doctor.js +0 -92
- package/dist/cli/doctor.js.map +0 -7
- package/dist/cli/launch-environment.js +0 -85
- package/dist/cli/launch-environment.js.map +0 -7
- package/dist/cli/launchd.js +0 -172
- package/dist/cli/launchd.js.map +0 -7
- package/dist/web/assets/index-BmbPtei8.css +0 -1
- package/dist/web/assets/index-CAtxws9I.js +0 -140
package/dist/update-worker.cjs
CHANGED
|
@@ -101,10 +101,10 @@ var require_polyfills = __commonJS({
|
|
|
101
101
|
if (platform === "win32") {
|
|
102
102
|
fs.rename = typeof fs.rename !== "function" ? fs.rename : (function(fs$rename) {
|
|
103
103
|
function rename4(from, to, cb) {
|
|
104
|
-
var
|
|
104
|
+
var start = Date.now();
|
|
105
105
|
var backoff = 0;
|
|
106
106
|
fs$rename(from, to, function CB(er) {
|
|
107
|
-
if (er && (er.code === "EACCES" || er.code === "EPERM" || er.code === "EBUSY") && Date.now() -
|
|
107
|
+
if (er && (er.code === "EACCES" || er.code === "EPERM" || er.code === "EBUSY") && Date.now() - start < 6e4) {
|
|
108
108
|
setTimeout(function() {
|
|
109
109
|
fs.stat(to, function(stater, st) {
|
|
110
110
|
if (stater && stater.code === "ENOENT")
|
|
@@ -542,8 +542,8 @@ var require_graceful_fs = __commonJS({
|
|
|
542
542
|
}
|
|
543
543
|
}
|
|
544
544
|
var fs$writeFile = fs2.writeFile;
|
|
545
|
-
fs2.writeFile =
|
|
546
|
-
function
|
|
545
|
+
fs2.writeFile = writeFile;
|
|
546
|
+
function writeFile(path, data, options, cb) {
|
|
547
547
|
if (typeof options === "function")
|
|
548
548
|
cb = options, options = null;
|
|
549
549
|
return go$writeFile(path, data, options, cb);
|
|
@@ -1108,7 +1108,7 @@ var require_signal_exit = __commonJS({
|
|
|
1108
1108
|
};
|
|
1109
1109
|
}
|
|
1110
1110
|
assert2.equal(typeof cb, "function", "a callback must be provided for exit handler");
|
|
1111
|
-
if (
|
|
1111
|
+
if (loaded === false) {
|
|
1112
1112
|
load();
|
|
1113
1113
|
}
|
|
1114
1114
|
var ev = "exit";
|
|
@@ -1125,10 +1125,10 @@ var require_signal_exit = __commonJS({
|
|
|
1125
1125
|
return remove;
|
|
1126
1126
|
};
|
|
1127
1127
|
unload = function unload2() {
|
|
1128
|
-
if (!
|
|
1128
|
+
if (!loaded || !processOk(global.process)) {
|
|
1129
1129
|
return;
|
|
1130
1130
|
}
|
|
1131
|
-
|
|
1131
|
+
loaded = false;
|
|
1132
1132
|
signals.forEach(function(sig) {
|
|
1133
1133
|
try {
|
|
1134
1134
|
process2.removeListener(sig, sigListeners[sig]);
|
|
@@ -1168,12 +1168,12 @@ var require_signal_exit = __commonJS({
|
|
|
1168
1168
|
module2.exports.signals = function() {
|
|
1169
1169
|
return signals;
|
|
1170
1170
|
};
|
|
1171
|
-
|
|
1171
|
+
loaded = false;
|
|
1172
1172
|
load = function load2() {
|
|
1173
|
-
if (
|
|
1173
|
+
if (loaded || !processOk(global.process)) {
|
|
1174
1174
|
return;
|
|
1175
1175
|
}
|
|
1176
|
-
|
|
1176
|
+
loaded = true;
|
|
1177
1177
|
emitter.count += 1;
|
|
1178
1178
|
signals = signals.filter(function(sig) {
|
|
1179
1179
|
try {
|
|
@@ -1221,7 +1221,7 @@ var require_signal_exit = __commonJS({
|
|
|
1221
1221
|
var unload;
|
|
1222
1222
|
var emit;
|
|
1223
1223
|
var sigListeners;
|
|
1224
|
-
var
|
|
1224
|
+
var loaded;
|
|
1225
1225
|
var load;
|
|
1226
1226
|
var originalProcessReallyExit;
|
|
1227
1227
|
var processReallyExit;
|
|
@@ -1578,27 +1578,27 @@ var require_adapter = __commonJS({
|
|
|
1578
1578
|
var require_proper_lockfile = __commonJS({
|
|
1579
1579
|
"node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/index.js"(exports2, module2) {
|
|
1580
1580
|
"use strict";
|
|
1581
|
-
var
|
|
1581
|
+
var lockfile3 = require_lockfile();
|
|
1582
1582
|
var { toPromise, toSync, toSyncOptions } = require_adapter();
|
|
1583
1583
|
async function lock(file2, options) {
|
|
1584
|
-
const release = await toPromise(
|
|
1584
|
+
const release = await toPromise(lockfile3.lock)(file2, options);
|
|
1585
1585
|
return toPromise(release);
|
|
1586
1586
|
}
|
|
1587
1587
|
function lockSync(file2, options) {
|
|
1588
|
-
const release = toSync(
|
|
1588
|
+
const release = toSync(lockfile3.lock)(file2, toSyncOptions(options));
|
|
1589
1589
|
return toSync(release);
|
|
1590
1590
|
}
|
|
1591
1591
|
function unlock(file2, options) {
|
|
1592
|
-
return toPromise(
|
|
1592
|
+
return toPromise(lockfile3.unlock)(file2, options);
|
|
1593
1593
|
}
|
|
1594
1594
|
function unlockSync(file2, options) {
|
|
1595
|
-
return toSync(
|
|
1595
|
+
return toSync(lockfile3.unlock)(file2, toSyncOptions(options));
|
|
1596
1596
|
}
|
|
1597
1597
|
function check2(file2, options) {
|
|
1598
|
-
return toPromise(
|
|
1598
|
+
return toPromise(lockfile3.check)(file2, options);
|
|
1599
1599
|
}
|
|
1600
1600
|
function checkSync(file2, options) {
|
|
1601
|
-
return toSync(
|
|
1601
|
+
return toSync(lockfile3.check)(file2, toSyncOptions(options));
|
|
1602
1602
|
}
|
|
1603
1603
|
module2.exports = lock;
|
|
1604
1604
|
module2.exports.lock = lock;
|
|
@@ -2323,9 +2323,9 @@ function nullish(input2) {
|
|
|
2323
2323
|
return input2 === null || input2 === void 0;
|
|
2324
2324
|
}
|
|
2325
2325
|
function cleanRegex(source) {
|
|
2326
|
-
const
|
|
2326
|
+
const start = source.startsWith("^") ? 1 : 0;
|
|
2327
2327
|
const end = source.endsWith("$") ? source.length - 1 : source.length;
|
|
2328
|
-
return source.slice(
|
|
2328
|
+
return source.slice(start, end);
|
|
2329
2329
|
}
|
|
2330
2330
|
function floatSafeRemainder(val, step) {
|
|
2331
2331
|
const ratio = val / step;
|
|
@@ -2796,9 +2796,9 @@ function sizeCaps(defChecks) {
|
|
|
2796
2796
|
}
|
|
2797
2797
|
return caps;
|
|
2798
2798
|
}
|
|
2799
|
-
function attachSchema(issues,
|
|
2799
|
+
function attachSchema(issues, start, inst) {
|
|
2800
2800
|
var _a3;
|
|
2801
|
-
for (let i =
|
|
2801
|
+
for (let i = start; i < issues.length; i++) {
|
|
2802
2802
|
(_a3 = issues[i]).schema ?? (_a3.schema = inst);
|
|
2803
2803
|
}
|
|
2804
2804
|
}
|
|
@@ -4983,10 +4983,10 @@ function capSize(inst, size) {
|
|
|
4983
4983
|
if (n > cap && !ctx?.skipChecks && ctx?.direction !== "backward") {
|
|
4984
4984
|
for (const [max, ch] of sizeCaps(inst._zod.def.checks)) {
|
|
4985
4985
|
if (n > max && ch._zod.def.when(payload)) {
|
|
4986
|
-
const
|
|
4986
|
+
const start = payload.issues.length;
|
|
4987
4987
|
ch._zod.check(payload);
|
|
4988
|
-
payload.issues[
|
|
4989
|
-
attachSchema(payload.issues,
|
|
4988
|
+
payload.issues[start].continue = false;
|
|
4989
|
+
attachSchema(payload.issues, start, inst);
|
|
4990
4990
|
return payload;
|
|
4991
4991
|
}
|
|
4992
4992
|
}
|
|
@@ -21390,15 +21390,17 @@ function requireCodexCompatibility(metadata, running, confirmed = false) {
|
|
|
21390
21390
|
}
|
|
21391
21391
|
|
|
21392
21392
|
// src/updates/worker.ts
|
|
21393
|
-
var
|
|
21394
|
-
var
|
|
21393
|
+
var import_node_child_process2 = require("node:child_process");
|
|
21394
|
+
var import_node_util2 = require("node:util");
|
|
21395
21395
|
var import_node_module = require("node:module");
|
|
21396
|
-
var
|
|
21397
|
-
var
|
|
21396
|
+
var import_node_crypto2 = require("node:crypto");
|
|
21397
|
+
var import_promises5 = require("node:fs/promises");
|
|
21398
21398
|
var import_node_fs2 = require("node:fs");
|
|
21399
|
-
var
|
|
21400
|
-
var
|
|
21401
|
-
var
|
|
21399
|
+
var import_node_path4 = require("node:path");
|
|
21400
|
+
var import_promises6 = require("node:timers/promises");
|
|
21401
|
+
var import_node_child_process3 = require("node:child_process");
|
|
21402
|
+
var import_node_os = require("node:os");
|
|
21403
|
+
var import_proper_lockfile2 = __toESM(require_proper_lockfile(), 1);
|
|
21402
21404
|
|
|
21403
21405
|
// src/cli/control.ts
|
|
21404
21406
|
var import_node_http = require("node:http");
|
|
@@ -21462,121 +21464,23 @@ async function stopAndWait(location) {
|
|
|
21462
21464
|
throw new Error("Covro \u5C1A\u672A\u5B8C\u6210\u5173\u95ED\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");
|
|
21463
21465
|
}
|
|
21464
21466
|
|
|
21465
|
-
// src/
|
|
21466
|
-
var import_node_child_process2 = require("node:child_process");
|
|
21467
|
-
var import_promises5 = require("node:fs/promises");
|
|
21468
|
-
var import_node_path4 = require("node:path");
|
|
21469
|
-
var import_node_util2 = require("node:util");
|
|
21470
|
-
var import_promises6 = require("node:timers/promises");
|
|
21471
|
-
var import_proper_lockfile2 = __toESM(require_proper_lockfile(), 1);
|
|
21472
|
-
|
|
21473
|
-
// src/cli/launchd.ts
|
|
21474
|
-
var import_node_child_process = require("node:child_process");
|
|
21475
|
-
var import_node_util = require("node:util");
|
|
21476
|
-
var import_node_crypto3 = require("node:crypto");
|
|
21477
|
-
var import_node_os = require("node:os");
|
|
21478
|
-
var import_node_path3 = require("node:path");
|
|
21479
|
-
var import_promises4 = require("node:fs/promises");
|
|
21480
|
-
|
|
21481
|
-
// src/cli/launch-environment.ts
|
|
21482
|
-
var import_node_net = require("node:net");
|
|
21483
|
-
var import_promises2 = require("node:fs/promises");
|
|
21467
|
+
// src/updates/files.ts
|
|
21484
21468
|
var import_node_crypto = require("node:crypto");
|
|
21485
21469
|
var import_node_path = require("node:path");
|
|
21486
|
-
|
|
21487
|
-
const path = (0, import_node_path.join)(home, `e-${(0, import_node_crypto.randomBytes)(6).toString("hex")}.sock`);
|
|
21488
|
-
const clients = /* @__PURE__ */ new Set();
|
|
21489
|
-
let accept;
|
|
21490
|
-
const consumed = new Promise((resolve) => {
|
|
21491
|
-
accept = resolve;
|
|
21492
|
-
});
|
|
21493
|
-
const payload = JSON.stringify({ env: { ...process.env, COVRO_HOME: home }, cwd: process.cwd() });
|
|
21494
|
-
const server = (0, import_node_net.createServer)((socket) => {
|
|
21495
|
-
clients.add(socket);
|
|
21496
|
-
socket.setTimeout(5e3, () => socket.destroy());
|
|
21497
|
-
socket.on("error", () => {
|
|
21498
|
-
});
|
|
21499
|
-
socket.on("close", () => clients.delete(socket));
|
|
21500
|
-
socket.end(payload, () => accept?.());
|
|
21501
|
-
});
|
|
21502
|
-
try {
|
|
21503
|
-
await new Promise((resolve, reject) => {
|
|
21504
|
-
server.once("error", reject);
|
|
21505
|
-
server.listen(path, resolve);
|
|
21506
|
-
});
|
|
21507
|
-
await (0, import_promises2.chmod)(path, 384);
|
|
21508
|
-
return {
|
|
21509
|
-
path,
|
|
21510
|
-
async wait() {
|
|
21511
|
-
let timer;
|
|
21512
|
-
try {
|
|
21513
|
-
await Promise.race([
|
|
21514
|
-
consumed,
|
|
21515
|
-
new Promise((_, reject) => {
|
|
21516
|
-
timer = setTimeout(
|
|
21517
|
-
() => reject(new Error("launchd \u542F\u52A8\u73AF\u5883\u4F20\u9012\u8D85\u65F6\uFF0C\u8BF7\u67E5\u770B Covro \u65E5\u5FD7")),
|
|
21518
|
-
1e4
|
|
21519
|
-
);
|
|
21520
|
-
})
|
|
21521
|
-
]);
|
|
21522
|
-
} finally {
|
|
21523
|
-
clearTimeout(timer);
|
|
21524
|
-
}
|
|
21525
|
-
},
|
|
21526
|
-
async close() {
|
|
21527
|
-
for (const socket of clients) socket.destroy();
|
|
21528
|
-
await new Promise(
|
|
21529
|
-
(resolve, reject) => server.close((error62) => error62 ? reject(error62) : resolve())
|
|
21530
|
-
);
|
|
21531
|
-
await (0, import_promises2.rm)(path, { force: true });
|
|
21532
|
-
}
|
|
21533
|
-
};
|
|
21534
|
-
} catch (error62) {
|
|
21535
|
-
server.close();
|
|
21536
|
-
await (0, import_promises2.rm)(path, { force: true });
|
|
21537
|
-
throw error62;
|
|
21538
|
-
}
|
|
21539
|
-
}
|
|
21540
|
-
var launchRunner = `import { connect } from 'node:net';
|
|
21541
|
-
const [socketPath, entry, config] = process.argv.slice(2);
|
|
21542
|
-
try {
|
|
21543
|
-
const input = await new Promise((resolve, reject) => {
|
|
21544
|
-
const socket = connect(socketPath);
|
|
21545
|
-
let body = '';
|
|
21546
|
-
socket.setTimeout(10000, () => socket.destroy(new Error('launch environment timed out')));
|
|
21547
|
-
socket.setEncoding('utf8');
|
|
21548
|
-
socket.on('data', chunk => {
|
|
21549
|
-
body += chunk;
|
|
21550
|
-
if (Buffer.byteLength(body) > 2 * 1024 * 1024) socket.destroy(new Error('launch environment too large'));
|
|
21551
|
-
});
|
|
21552
|
-
socket.on('error', reject);
|
|
21553
|
-
socket.on('end', () => { try { resolve(JSON.parse(body)); } catch { reject(new Error('invalid launch environment')); } });
|
|
21554
|
-
});
|
|
21555
|
-
process.chdir(input.cwd);
|
|
21556
|
-
process.execve(process.execPath, [process.execPath, entry, 'run', '--config', config], input.env);
|
|
21557
|
-
} catch {
|
|
21558
|
-
console.error('Covro launch environment unavailable; restart with covro start.');
|
|
21559
|
-
process.exitCode = 1;
|
|
21560
|
-
}
|
|
21561
|
-
`;
|
|
21562
|
-
|
|
21563
|
-
// src/updates/files.ts
|
|
21564
|
-
var import_node_crypto2 = require("node:crypto");
|
|
21565
|
-
var import_node_path2 = require("node:path");
|
|
21566
|
-
var import_promises3 = require("node:fs/promises");
|
|
21470
|
+
var import_promises2 = require("node:fs/promises");
|
|
21567
21471
|
async function readJson(filename) {
|
|
21568
21472
|
try {
|
|
21569
|
-
return JSON.parse(await (0,
|
|
21473
|
+
return JSON.parse(await (0, import_promises2.readFile)(filename, "utf8"));
|
|
21570
21474
|
} catch (error62) {
|
|
21571
21475
|
if (error62.code === "ENOENT") return void 0;
|
|
21572
21476
|
throw error62;
|
|
21573
21477
|
}
|
|
21574
21478
|
}
|
|
21575
21479
|
async function saveJson(filename, value) {
|
|
21576
|
-
await (0,
|
|
21577
|
-
const temporary = `${filename}.${(0,
|
|
21480
|
+
await (0, import_promises2.mkdir)((0, import_node_path.dirname)(filename), { recursive: true, mode: 448 });
|
|
21481
|
+
const temporary = `${filename}.${(0, import_node_crypto.randomUUID)()}.tmp`;
|
|
21578
21482
|
try {
|
|
21579
|
-
const file2 = await (0,
|
|
21483
|
+
const file2 = await (0, import_promises2.open)(temporary, "wx", 384);
|
|
21580
21484
|
try {
|
|
21581
21485
|
await file2.writeFile(`${JSON.stringify(value, null, 2)}
|
|
21582
21486
|
`);
|
|
@@ -21584,15 +21488,15 @@ async function saveJson(filename, value) {
|
|
|
21584
21488
|
} finally {
|
|
21585
21489
|
await file2.close();
|
|
21586
21490
|
}
|
|
21587
|
-
await (0,
|
|
21588
|
-
await syncDirectory((0,
|
|
21491
|
+
await (0, import_promises2.rename)(temporary, filename);
|
|
21492
|
+
await syncDirectory((0, import_node_path.dirname)(filename));
|
|
21589
21493
|
} finally {
|
|
21590
|
-
await (0,
|
|
21494
|
+
await (0, import_promises2.rm)(temporary, { force: true });
|
|
21591
21495
|
}
|
|
21592
21496
|
}
|
|
21593
21497
|
async function syncDirectory(directory) {
|
|
21594
21498
|
if (process.platform === "win32") return;
|
|
21595
|
-
const handle = await (0,
|
|
21499
|
+
const handle = await (0, import_promises2.open)(directory, "r");
|
|
21596
21500
|
try {
|
|
21597
21501
|
await handle.sync();
|
|
21598
21502
|
} finally {
|
|
@@ -21600,228 +21504,20 @@ async function syncDirectory(directory) {
|
|
|
21600
21504
|
}
|
|
21601
21505
|
}
|
|
21602
21506
|
async function copyDurable(source, target) {
|
|
21603
|
-
await (0,
|
|
21604
|
-
const file2 = await (0,
|
|
21507
|
+
await (0, import_promises2.cp)(source, target);
|
|
21508
|
+
const file2 = await (0, import_promises2.open)(target, "r");
|
|
21605
21509
|
try {
|
|
21606
21510
|
await file2.sync();
|
|
21607
21511
|
} finally {
|
|
21608
21512
|
await file2.close();
|
|
21609
21513
|
}
|
|
21610
|
-
await syncDirectory((0,
|
|
21514
|
+
await syncDirectory((0, import_node_path.dirname)(target));
|
|
21611
21515
|
}
|
|
21612
21516
|
|
|
21613
|
-
// src/cli/launchd.ts
|
|
21614
|
-
var exec = (0, import_node_util.promisify)(import_node_child_process.execFile);
|
|
21615
|
-
var launchctl = (args) => exec("/bin/launchctl", args, { timeout: 5e3, maxBuffer: 2 * 1024 * 1024 });
|
|
21616
|
-
var xml = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """);
|
|
21617
|
-
function failureDetail(error62) {
|
|
21618
|
-
const failure2 = error62;
|
|
21619
|
-
if (failure2.killed) return "launchctl \u8BF7\u6C42\u8D85\u65F6";
|
|
21620
|
-
return (failure2.stderr?.trim() || (error62 instanceof Error ? error62.message : "\u672A\u77E5\u9519\u8BEF")).slice(
|
|
21621
|
-
0,
|
|
21622
|
-
1024
|
|
21623
|
-
);
|
|
21624
|
-
}
|
|
21625
|
-
function launchdPaths(location, label = `dev.covro.${location.key}.${(0, import_node_crypto3.createHash)("sha256").update(location.home).digest("hex").slice(0, 12)}`) {
|
|
21626
|
-
const domain2 = `gui/${process.getuid()}`;
|
|
21627
|
-
return {
|
|
21628
|
-
label,
|
|
21629
|
-
domain: domain2,
|
|
21630
|
-
target: `${domain2}/${label}`,
|
|
21631
|
-
temporary: (0, import_node_path3.join)(location.state, "launchd.plist"),
|
|
21632
|
-
login: (0, import_node_path3.join)((0, import_node_os.homedir)(), "Library/LaunchAgents", `${label}.plist`)
|
|
21633
|
-
};
|
|
21634
|
-
}
|
|
21635
|
-
async function loaded(target) {
|
|
21636
|
-
try {
|
|
21637
|
-
await launchctl(["print", target]);
|
|
21638
|
-
return true;
|
|
21639
|
-
} catch (error62) {
|
|
21640
|
-
const stderr = error62.stderr ?? "";
|
|
21641
|
-
if (/Could not find (?:domain|service|specified service)/i.test(stderr)) return false;
|
|
21642
|
-
throw new Error(
|
|
21643
|
-
`\u65E0\u6CD5\u67E5\u8BE2 launchd ${target}\uFF1A${failureDetail(error62)}\uFF1B\u8BF7\u68C0\u67E5\u5F53\u524D\u7528\u6237\u7684 launchd \u6743\u9650`,
|
|
21644
|
-
{ cause: error62 }
|
|
21645
|
-
);
|
|
21646
|
-
}
|
|
21647
|
-
}
|
|
21648
|
-
async function guiSessionAvailable(location) {
|
|
21649
|
-
return loaded(launchdPaths(location).domain);
|
|
21650
|
-
}
|
|
21651
|
-
async function loginRegistration(location) {
|
|
21652
|
-
const installed = await readJson(
|
|
21653
|
-
(0, import_node_path3.join)(location.state, "service.json")
|
|
21654
|
-
);
|
|
21655
|
-
if (installed?.platform !== "darwin") return void 0;
|
|
21656
|
-
if (installed.label !== launchdPaths(location).label && installed.label !== `dev.covro.${location.key}`)
|
|
21657
|
-
throw new Error("\u767B\u5F55\u670D\u52A1\u8EAB\u4EFD\u4E0E\u5F53\u524D\u914D\u7F6E\u4E0D\u5339\u914D");
|
|
21658
|
-
return installed;
|
|
21659
|
-
}
|
|
21660
|
-
function launchdPlist(location, args, login) {
|
|
21661
|
-
const { label } = launchdPaths(location, login ? `dev.covro.${location.key}` : void 0);
|
|
21662
|
-
const environment = {
|
|
21663
|
-
PATH: process.env.PATH ?? "/usr/bin:/bin",
|
|
21664
|
-
COVRO_HOME: location.home,
|
|
21665
|
-
...process.env.CODEX_HOME ? { CODEX_HOME: process.env.CODEX_HOME } : {}
|
|
21666
|
-
};
|
|
21667
|
-
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
21668
|
-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
21669
|
-
<plist version="1.0"><dict>
|
|
21670
|
-
<key>Label</key><string>${label}</string>
|
|
21671
|
-
<key>ProgramArguments</key><array>${args.map((arg) => `<string>${xml(arg)}</string>`).join("")}</array>
|
|
21672
|
-
<key>LimitLoadToSessionType</key><string>Aqua</string>
|
|
21673
|
-
<key>RunAtLoad</key><true/>
|
|
21674
|
-
${login ? "<key>KeepAlive</key><dict><key>SuccessfulExit</key><false/></dict><key>ThrottleInterval</key><integer>30</integer>" : ""}
|
|
21675
|
-
<key>EnvironmentVariables</key><dict>${Object.entries(environment).map(([key, value]) => `<key>${key}</key><string>${xml(value)}</string>`).join("")}</dict>
|
|
21676
|
-
<key>StandardOutPath</key><string>${xml(location.log)}</string>
|
|
21677
|
-
<key>StandardErrorPath</key><string>${xml(location.log)}</string>
|
|
21678
|
-
</dict></plist>
|
|
21679
|
-
`;
|
|
21680
|
-
}
|
|
21681
|
-
async function unloadLaunchd(location) {
|
|
21682
|
-
const { target, temporary } = launchdPaths(location);
|
|
21683
|
-
const installed = await loginRegistration(location);
|
|
21684
|
-
const targets = /* @__PURE__ */ new Set([
|
|
21685
|
-
target,
|
|
21686
|
-
...installed ? [launchdPaths(location, installed.label).target] : []
|
|
21687
|
-
]);
|
|
21688
|
-
for (const serviceTarget of targets) {
|
|
21689
|
-
if (await loaded(serviceTarget)) {
|
|
21690
|
-
try {
|
|
21691
|
-
await launchctl(["bootout", serviceTarget]);
|
|
21692
|
-
} catch (error62) {
|
|
21693
|
-
if (await loaded(serviceTarget)) throw error62;
|
|
21694
|
-
}
|
|
21695
|
-
}
|
|
21696
|
-
}
|
|
21697
|
-
await (0, import_promises4.rm)(temporary, { force: true });
|
|
21698
|
-
}
|
|
21699
|
-
async function startLaunchd(location, entry) {
|
|
21700
|
-
const installed = await loginRegistration(location);
|
|
21701
|
-
const { domain: domain2, target, temporary, login } = launchdPaths(location, installed?.label);
|
|
21702
|
-
if (!await guiSessionAvailable(location)) {
|
|
21703
|
-
if (installed) throw new Error("\u5F53\u524D\u6CA1\u6709 macOS \u684C\u9762\u767B\u5F55\u4F1A\u8BDD\uFF0C\u65E0\u6CD5\u542F\u52A8 GUI \u767B\u5F55\u670D\u52A1");
|
|
21704
|
-
return false;
|
|
21705
|
-
}
|
|
21706
|
-
await unloadLaunchd(location);
|
|
21707
|
-
if (installed) {
|
|
21708
|
-
await launchctl(["enable", target]);
|
|
21709
|
-
await launchctl(["bootstrap", domain2, login]);
|
|
21710
|
-
return true;
|
|
21711
|
-
}
|
|
21712
|
-
const bridge = await environmentBridge(location.home);
|
|
21713
|
-
try {
|
|
21714
|
-
const runner = (0, import_node_path3.join)(location.state, "launch-runner.mjs");
|
|
21715
|
-
await (0, import_promises4.writeFile)(runner, launchRunner, { mode: 384 });
|
|
21716
|
-
await (0, import_promises4.writeFile)(
|
|
21717
|
-
temporary,
|
|
21718
|
-
launchdPlist(
|
|
21719
|
-
location,
|
|
21720
|
-
[process.execPath, runner, bridge.path, entry, location.config],
|
|
21721
|
-
false
|
|
21722
|
-
),
|
|
21723
|
-
{ mode: 384 }
|
|
21724
|
-
);
|
|
21725
|
-
await launchctl(["enable", target]);
|
|
21726
|
-
await launchctl(["bootstrap", domain2, temporary]);
|
|
21727
|
-
await bridge.wait();
|
|
21728
|
-
return true;
|
|
21729
|
-
} catch (error62) {
|
|
21730
|
-
let cleanup = "";
|
|
21731
|
-
try {
|
|
21732
|
-
await unloadLaunchd(location);
|
|
21733
|
-
} catch (cleanupError) {
|
|
21734
|
-
cleanup = `\uFF1B\u6E05\u7406\u4EFB\u52A1\u5931\u8D25\uFF1A${failureDetail(cleanupError)}`;
|
|
21735
|
-
}
|
|
21736
|
-
throw new Error(
|
|
21737
|
-
`Covro GUI \u540E\u53F0\u542F\u52A8\u5931\u8D25\uFF1A${failureDetail(error62)}${cleanup}\uFF1B\u8FDB\u7A0B\u65E5\u5FD7\u4F4D\u4E8E ${location.log}`,
|
|
21738
|
-
{ cause: error62 }
|
|
21739
|
-
);
|
|
21740
|
-
} finally {
|
|
21741
|
-
await bridge.close();
|
|
21742
|
-
}
|
|
21743
|
-
}
|
|
21744
|
-
|
|
21745
|
-
// src/cli/background.ts
|
|
21746
|
-
var exec2 = (0, import_node_util2.promisify)(import_node_child_process2.execFile);
|
|
21747
|
-
async function lifecycle(location, action) {
|
|
21748
|
-
await (0, import_promises5.mkdir)(location.state, { recursive: true, mode: 448 });
|
|
21749
|
-
const release = await import_proper_lockfile2.default.lock(location.state, {
|
|
21750
|
-
lockfilePath: (0, import_node_path4.join)(location.state, "lifecycle.lock"),
|
|
21751
|
-
stale: 1e4,
|
|
21752
|
-
update: 2e3,
|
|
21753
|
-
retries: { retries: 280, minTimeout: 250, maxTimeout: 250 }
|
|
21754
|
-
});
|
|
21755
|
-
try {
|
|
21756
|
-
return await action();
|
|
21757
|
-
} finally {
|
|
21758
|
-
await release();
|
|
21759
|
-
}
|
|
21760
|
-
}
|
|
21761
|
-
async function start(location, entry) {
|
|
21762
|
-
try {
|
|
21763
|
-
return await control(location, "status");
|
|
21764
|
-
} catch (error62) {
|
|
21765
|
-
if (!isNotRunning(error62)) throw error62;
|
|
21766
|
-
}
|
|
21767
|
-
let child;
|
|
21768
|
-
const installed = await readJson(
|
|
21769
|
-
(0, import_node_path4.join)(location.state, "service.json")
|
|
21770
|
-
);
|
|
21771
|
-
if (process.platform === "darwin" && await startLaunchd(location, entry)) {
|
|
21772
|
-
} else if (installed?.platform === "linux") {
|
|
21773
|
-
await exec2("systemctl", ["--user", "start", `${installed.label}.service`]);
|
|
21774
|
-
} else {
|
|
21775
|
-
if (process.platform === "darwin")
|
|
21776
|
-
console.warn(
|
|
21777
|
-
"\u5F53\u524D\u6CA1\u6709 macOS \u684C\u9762\u767B\u5F55\u4F1A\u8BDD\uFF0C\u4F7F\u7528 headless \u540E\u53F0\u542F\u52A8\uFF1B\u7CFB\u7EDF\u94A5\u5319\u4E32\u51ED\u8BC1\u53EF\u80FD\u4E0D\u53EF\u7528\u3002"
|
|
21778
|
-
);
|
|
21779
|
-
const log = await (0, import_promises5.open)(location.log, "a", 384);
|
|
21780
|
-
try {
|
|
21781
|
-
child = (0, import_node_child_process2.spawn)(process.execPath, [entry, "run", "--config", location.config], {
|
|
21782
|
-
detached: true,
|
|
21783
|
-
stdio: ["ignore", log.fd, log.fd],
|
|
21784
|
-
windowsHide: true,
|
|
21785
|
-
env: { ...process.env, COVRO_HOME: location.home }
|
|
21786
|
-
});
|
|
21787
|
-
await new Promise((resolve, reject) => {
|
|
21788
|
-
child.once("spawn", resolve);
|
|
21789
|
-
child.once("error", reject);
|
|
21790
|
-
});
|
|
21791
|
-
child.unref();
|
|
21792
|
-
} finally {
|
|
21793
|
-
await log.close();
|
|
21794
|
-
}
|
|
21795
|
-
}
|
|
21796
|
-
for (let attempt = 0; attempt < 240; attempt++) {
|
|
21797
|
-
try {
|
|
21798
|
-
return await control(location, "status");
|
|
21799
|
-
} catch (error62) {
|
|
21800
|
-
if (!isNotRunning(error62)) throw error62;
|
|
21801
|
-
}
|
|
21802
|
-
if (child && child.exitCode !== null) throw new Error(`Covro \u542F\u52A8\u5931\u8D25\uFF0C\u8BF7\u67E5\u770B ${location.log}`);
|
|
21803
|
-
await (0, import_promises6.setTimeout)(250);
|
|
21804
|
-
}
|
|
21805
|
-
throw new Error(`Covro \u5C1A\u672A\u786E\u8BA4\u542F\u52A8\uFF0C\u8BF7\u8FD0\u884C covro status \u5E76\u67E5\u770B ${location.log}`);
|
|
21806
|
-
}
|
|
21807
|
-
async function stop(location) {
|
|
21808
|
-
await stopAndWait(location);
|
|
21809
|
-
if (process.platform === "darwin") await unloadLaunchd(location);
|
|
21810
|
-
else {
|
|
21811
|
-
const installed = await readJson(
|
|
21812
|
-
(0, import_node_path4.join)(location.state, "service.json")
|
|
21813
|
-
);
|
|
21814
|
-
if (installed?.platform === "linux")
|
|
21815
|
-
await exec2("systemctl", ["--user", "stop", `${installed.label}.service`]);
|
|
21816
|
-
}
|
|
21817
|
-
}
|
|
21818
|
-
var startBackground = (location, entry) => lifecycle(location, () => start(location, entry));
|
|
21819
|
-
var stopBackground = (location) => lifecycle(location, () => stop(location));
|
|
21820
|
-
|
|
21821
21517
|
// src/updates/transaction.ts
|
|
21822
|
-
var
|
|
21823
|
-
var
|
|
21824
|
-
var exists = async (path) => (0,
|
|
21518
|
+
var import_promises3 = require("node:fs/promises");
|
|
21519
|
+
var import_node_path2 = require("node:path");
|
|
21520
|
+
var exists = async (path) => (0, import_promises3.stat)(path).then(
|
|
21825
21521
|
() => true,
|
|
21826
21522
|
(error62) => {
|
|
21827
21523
|
if (error62.code === "ENOENT") return false;
|
|
@@ -21839,17 +21535,17 @@ async function activateUpdate(paths, effects) {
|
|
|
21839
21535
|
await effects.phase("stopping", "\u5DF2\u5173\u95ED\u65B0\u4EFB\u52A1\u5165\u53E3\uFF0C\u6B63\u5728\u505C\u6B62\u65E7\u670D\u52A1\u5E76\u5907\u4EFD\u6570\u636E");
|
|
21840
21536
|
stopped = true;
|
|
21841
21537
|
await effects.stop();
|
|
21842
|
-
await (0,
|
|
21538
|
+
await (0, import_promises3.mkdir)(paths.backup, { recursive: true, mode: 448 });
|
|
21843
21539
|
for (const name of ["app.sqlite", "app.sqlite-wal", "app.sqlite-shm"]) {
|
|
21844
|
-
if (await exists((0,
|
|
21845
|
-
await copyDurable((0,
|
|
21540
|
+
if (await exists((0, import_node_path2.join)(paths.dataDir, name)))
|
|
21541
|
+
await copyDurable((0, import_node_path2.join)(paths.dataDir, name), (0, import_node_path2.join)(paths.backup, name));
|
|
21846
21542
|
}
|
|
21847
|
-
await copyDurable(paths.config, (0,
|
|
21848
|
-
await saveJson((0,
|
|
21543
|
+
await copyDurable(paths.config, (0, import_node_path2.join)(paths.backup, "config.json"));
|
|
21544
|
+
await saveJson((0, import_node_path2.join)(paths.backup, "snapshot.json"), { complete: true });
|
|
21849
21545
|
backedUp = true;
|
|
21850
|
-
await (0,
|
|
21546
|
+
await (0, import_promises3.rename)(paths.root, paths.previous);
|
|
21851
21547
|
moved = true;
|
|
21852
|
-
await (0,
|
|
21548
|
+
await (0, import_promises3.rename)(paths.candidate, paths.root);
|
|
21853
21549
|
await effects.phase("verifying", "\u6B63\u5728\u542F\u52A8\u65B0\u7248\u3001\u8FC1\u79FB\u6570\u636E\u5E93\u5E76\u9A8C\u8BC1\uFF1B\u4E1A\u52A1\u5199\u5165\u4FDD\u6301\u6682\u505C");
|
|
21854
21550
|
await effects.start(true);
|
|
21855
21551
|
await effects.verify();
|
|
@@ -21866,16 +21562,16 @@ async function activateUpdate(paths, effects) {
|
|
|
21866
21562
|
try {
|
|
21867
21563
|
await effects.stop();
|
|
21868
21564
|
if (moved) {
|
|
21869
|
-
await (0,
|
|
21870
|
-
await (0,
|
|
21565
|
+
await (0, import_promises3.rm)(paths.root, { recursive: true, force: true });
|
|
21566
|
+
await (0, import_promises3.rename)(paths.previous, paths.root);
|
|
21871
21567
|
}
|
|
21872
21568
|
if (backedUp) {
|
|
21873
21569
|
for (const name of ["app.sqlite", "app.sqlite-wal", "app.sqlite-shm"]) {
|
|
21874
|
-
await (0,
|
|
21875
|
-
if (await exists((0,
|
|
21876
|
-
await copyDurable((0,
|
|
21570
|
+
await (0, import_promises3.rm)((0, import_node_path2.join)(paths.dataDir, name), { force: true });
|
|
21571
|
+
if (await exists((0, import_node_path2.join)(paths.backup, name)))
|
|
21572
|
+
await copyDurable((0, import_node_path2.join)(paths.backup, name), (0, import_node_path2.join)(paths.dataDir, name));
|
|
21877
21573
|
}
|
|
21878
|
-
await copyDurable((0,
|
|
21574
|
+
await copyDurable((0, import_node_path2.join)(paths.backup, "config.json"), paths.config);
|
|
21879
21575
|
}
|
|
21880
21576
|
await effects.phase(
|
|
21881
21577
|
"rolledBack",
|
|
@@ -21893,16 +21589,16 @@ async function activateUpdate(paths, effects) {
|
|
|
21893
21589
|
}
|
|
21894
21590
|
}
|
|
21895
21591
|
function transactionPaths(root, id, dataDir, config2, backup) {
|
|
21896
|
-
const prefix = (0,
|
|
21592
|
+
const prefix = (0, import_node_path2.join)((0, import_node_path2.dirname)(root), `.covro-stage-${id}`);
|
|
21897
21593
|
return {
|
|
21898
21594
|
root,
|
|
21899
21595
|
prefix,
|
|
21900
|
-
candidate: (0,
|
|
21596
|
+
candidate: (0, import_node_path2.join)(
|
|
21901
21597
|
prefix,
|
|
21902
21598
|
process.platform === "win32" ? "node_modules" : "lib/node_modules",
|
|
21903
21599
|
npmPackageName
|
|
21904
21600
|
),
|
|
21905
|
-
previous: (0,
|
|
21601
|
+
previous: (0, import_node_path2.join)((0, import_node_path2.dirname)(root), `.covro-previous-${id}`),
|
|
21906
21602
|
backup,
|
|
21907
21603
|
dataDir,
|
|
21908
21604
|
config: config2
|
|
@@ -21910,12 +21606,12 @@ function transactionPaths(root, id, dataDir, config2, backup) {
|
|
|
21910
21606
|
}
|
|
21911
21607
|
|
|
21912
21608
|
// src/updates/registry.ts
|
|
21913
|
-
var
|
|
21914
|
-
var
|
|
21915
|
-
var
|
|
21609
|
+
var import_node_child_process = require("node:child_process");
|
|
21610
|
+
var import_node_util = require("node:util");
|
|
21611
|
+
var import_promises4 = require("node:fs/promises");
|
|
21916
21612
|
var import_node_fs = require("node:fs");
|
|
21917
|
-
var
|
|
21918
|
-
var run = (0,
|
|
21613
|
+
var import_node_path3 = require("node:path");
|
|
21614
|
+
var run = (0, import_node_util.promisify)(import_node_child_process.execFile);
|
|
21919
21615
|
var registry2 = "https://registry.npmjs.org";
|
|
21920
21616
|
var releaseSchema = external_exports.object({
|
|
21921
21617
|
name: external_exports.literal(npmPackageName),
|
|
@@ -21932,27 +21628,80 @@ async function inspectInstallation(root) {
|
|
|
21932
21628
|
}
|
|
21933
21629
|
}
|
|
21934
21630
|
async function inspectPackageDirectory(root, globalRoot) {
|
|
21935
|
-
const expected = (0,
|
|
21936
|
-
if ((await (0,
|
|
21631
|
+
const expected = (0, import_node_path3.join)(await (0, import_promises4.realpath)(globalRoot), npmPackageName);
|
|
21632
|
+
if ((await (0, import_promises4.lstat)(expected)).isSymbolicLink() || await (0, import_promises4.realpath)(root) !== expected)
|
|
21937
21633
|
return "\u5F53\u524D\u4E3A\u6E90\u7801\u3001\u94FE\u63A5\u6216\u975E npm \u5168\u5C40\u5B89\u88C5\uFF1B\u8BF7\u4F7F\u7528\u539F\u90E8\u7F72\u65B9\u5F0F\u66F4\u65B0\u3002";
|
|
21938
21634
|
try {
|
|
21939
|
-
await (0,
|
|
21635
|
+
await (0, import_promises4.lstat)((0, import_node_path3.join)(expected, ".git"));
|
|
21940
21636
|
return "\u5F53\u524D\u5B89\u88C5\u5305\u542B Git \u5DE5\u4F5C\u533A\uFF1B\u8BF7\u4F7F\u7528\u539F\u90E8\u7F72\u65B9\u5F0F\u66F4\u65B0\u3002";
|
|
21941
21637
|
} catch (error62) {
|
|
21942
21638
|
if (error62.code !== "ENOENT") throw error62;
|
|
21943
21639
|
}
|
|
21944
|
-
await (0,
|
|
21640
|
+
await (0, import_promises4.access)(root, import_node_fs.constants.W_OK);
|
|
21945
21641
|
return void 0;
|
|
21946
21642
|
}
|
|
21947
21643
|
|
|
21948
21644
|
// src/updates/worker.ts
|
|
21949
|
-
var
|
|
21645
|
+
var exec = (0, import_node_util2.promisify)(import_node_child_process2.execFile);
|
|
21950
21646
|
var message = (error62) => error62 instanceof Error ? error62.message : String(error62);
|
|
21951
|
-
async function startService(context) {
|
|
21952
|
-
|
|
21647
|
+
async function startService(context, activation) {
|
|
21648
|
+
const installed = await readJson(
|
|
21649
|
+
(0, import_node_path4.join)(context.location.state, "service.json")
|
|
21650
|
+
);
|
|
21651
|
+
if (installed) {
|
|
21652
|
+
if (installed.platform === "darwin")
|
|
21653
|
+
await exec("launchctl", [
|
|
21654
|
+
"bootstrap",
|
|
21655
|
+
`gui/${process.getuid()}`,
|
|
21656
|
+
(0, import_node_path4.join)((0, import_node_os.homedir)(), "Library/LaunchAgents", `${installed.label}.plist`)
|
|
21657
|
+
]);
|
|
21658
|
+
else await exec("systemctl", ["--user", "start", `${installed.label}.service`]);
|
|
21659
|
+
} else {
|
|
21660
|
+
const log = await (0, import_promises5.open)(context.location.log, "a", 384);
|
|
21661
|
+
try {
|
|
21662
|
+
const child = (0, import_node_child_process3.spawn)(
|
|
21663
|
+
process.execPath,
|
|
21664
|
+
[(0, import_node_path4.join)(context.root, "bin/covro.mjs"), "run", "--config", context.location.config],
|
|
21665
|
+
{
|
|
21666
|
+
detached: true,
|
|
21667
|
+
stdio: ["ignore", log.fd, log.fd],
|
|
21668
|
+
windowsHide: true,
|
|
21669
|
+
env: {
|
|
21670
|
+
...process.env,
|
|
21671
|
+
COVRO_HOME: context.location.home,
|
|
21672
|
+
...activation ? { COVRO_ACTIVATING: activation } : {}
|
|
21673
|
+
}
|
|
21674
|
+
}
|
|
21675
|
+
);
|
|
21676
|
+
await new Promise((done, reject) => {
|
|
21677
|
+
child.once("spawn", done);
|
|
21678
|
+
child.once("error", reject);
|
|
21679
|
+
});
|
|
21680
|
+
child.unref();
|
|
21681
|
+
} finally {
|
|
21682
|
+
await log.close();
|
|
21683
|
+
}
|
|
21684
|
+
}
|
|
21953
21685
|
}
|
|
21954
21686
|
async function stopService(context) {
|
|
21955
|
-
await
|
|
21687
|
+
await stopAndWait(context.location);
|
|
21688
|
+
const installed = await readJson(
|
|
21689
|
+
(0, import_node_path4.join)(context.location.state, "service.json")
|
|
21690
|
+
);
|
|
21691
|
+
if (installed?.platform === "linux")
|
|
21692
|
+
await exec("systemctl", ["--user", "stop", `${installed.label}.service`]);
|
|
21693
|
+
else if (installed?.platform === "darwin") {
|
|
21694
|
+
const target = `gui/${process.getuid()}/${installed.label}`;
|
|
21695
|
+
try {
|
|
21696
|
+
await exec("launchctl", ["bootout", target]);
|
|
21697
|
+
} catch (error62) {
|
|
21698
|
+
const stillLoaded = await exec("launchctl", ["print", target]).then(
|
|
21699
|
+
() => true,
|
|
21700
|
+
() => false
|
|
21701
|
+
);
|
|
21702
|
+
if (stillLoaded) throw error62;
|
|
21703
|
+
}
|
|
21704
|
+
}
|
|
21956
21705
|
}
|
|
21957
21706
|
async function verifyRestoredService(context, version3) {
|
|
21958
21707
|
for (let attempt = 0; attempt < 240; attempt++) {
|
|
@@ -21964,15 +21713,15 @@ async function verifyRestoredService(context, version3) {
|
|
|
21964
21713
|
} catch (error62) {
|
|
21965
21714
|
if (attempt === 239) throw error62;
|
|
21966
21715
|
}
|
|
21967
|
-
await (0,
|
|
21716
|
+
await (0, import_promises6.setTimeout)(250);
|
|
21968
21717
|
}
|
|
21969
21718
|
}
|
|
21970
21719
|
async function verifyMigrations(context, candidate) {
|
|
21971
|
-
const require2 = (0, import_node_module.createRequire)((0,
|
|
21720
|
+
const require2 = (0, import_node_module.createRequire)((0, import_node_path4.join)(context.root, "package.json"));
|
|
21972
21721
|
const Sqlite = require2("better-sqlite3");
|
|
21973
|
-
const filename = (0,
|
|
21722
|
+
const filename = (0, import_node_path4.join)(context.dataDir, "app.sqlite");
|
|
21974
21723
|
try {
|
|
21975
|
-
await (0,
|
|
21724
|
+
await (0, import_promises5.access)(filename);
|
|
21976
21725
|
} catch (error62) {
|
|
21977
21726
|
if (error62.code === "ENOENT") return;
|
|
21978
21727
|
throw error62;
|
|
@@ -21983,12 +21732,12 @@ async function verifyMigrations(context, candidate) {
|
|
|
21983
21732
|
if (!table) return;
|
|
21984
21733
|
const applied = db.prepare("SELECT hash FROM __drizzle_migrations ORDER BY created_at").all();
|
|
21985
21734
|
const journal = JSON.parse(
|
|
21986
|
-
await (0,
|
|
21735
|
+
await (0, import_promises5.readFile)((0, import_node_path4.join)(candidate, "dist/drizzle/meta/_journal.json"), "utf8")
|
|
21987
21736
|
);
|
|
21988
21737
|
const hashes = await Promise.all(
|
|
21989
21738
|
journal.entries.map(async (entry) => {
|
|
21990
21739
|
if (!/^[a-zA-Z0-9_-]+$/.test(entry.tag)) throw new Error("\u5019\u9009\u5305\u5305\u542B\u65E0\u6548\u8FC1\u79FB\u8DEF\u5F84");
|
|
21991
|
-
return (0,
|
|
21740
|
+
return (0, import_node_crypto2.createHash)("sha256").update(await (0, import_promises5.readFile)((0, import_node_path4.join)(candidate, "dist/drizzle", `${entry.tag}.sql`))).digest("hex");
|
|
21992
21741
|
})
|
|
21993
21742
|
);
|
|
21994
21743
|
if (applied.some((entry, i) => entry.hash !== hashes[i]))
|
|
@@ -21998,28 +21747,28 @@ async function verifyMigrations(context, candidate) {
|
|
|
21998
21747
|
}
|
|
21999
21748
|
}
|
|
22000
21749
|
async function worker(directory) {
|
|
22001
|
-
await (0,
|
|
22002
|
-
const release = await
|
|
21750
|
+
await (0, import_promises5.mkdir)(directory, { recursive: true, mode: 448 });
|
|
21751
|
+
const release = await import_proper_lockfile2.default.lock(directory, {
|
|
22003
21752
|
stale: 1e4,
|
|
22004
21753
|
update: 2e3,
|
|
22005
21754
|
retries: { retries: 30, minTimeout: 100, maxTimeout: 500 }
|
|
22006
21755
|
});
|
|
22007
|
-
let record2 = await readJson((0,
|
|
22008
|
-
const context = await readJson((0,
|
|
21756
|
+
let record2 = await readJson((0, import_node_path4.join)(directory, "run.json"));
|
|
21757
|
+
const context = await readJson((0, import_node_path4.join)(directory, "context.json"));
|
|
22009
21758
|
if (!record2 || !context) {
|
|
22010
21759
|
await release();
|
|
22011
21760
|
throw new Error("\u7F3A\u5C11\u5347\u7EA7\u8BB0\u5F55");
|
|
22012
21761
|
}
|
|
22013
21762
|
const update = async (phase, detail) => {
|
|
22014
21763
|
record2 = { ...record2, phase, message: detail, updatedAt: Date.now() };
|
|
22015
|
-
await saveJson((0,
|
|
21764
|
+
await saveJson((0, import_node_path4.join)(directory, "run.json"), record2);
|
|
22016
21765
|
};
|
|
22017
21766
|
const paths = transactionPaths(
|
|
22018
21767
|
context.root,
|
|
22019
21768
|
record2.id,
|
|
22020
21769
|
context.dataDir,
|
|
22021
21770
|
context.location.config,
|
|
22022
|
-
(0,
|
|
21771
|
+
(0, import_node_path4.join)(directory, `backup-${record2.id}`)
|
|
22023
21772
|
);
|
|
22024
21773
|
try {
|
|
22025
21774
|
if (process.argv[3] === "--repair") {
|
|
@@ -22033,18 +21782,18 @@ async function worker(directory) {
|
|
|
22033
21782
|
if (active && !active.maintenance && active.version !== record2.from)
|
|
22034
21783
|
throw new Error("\u5F53\u524D\u670D\u52A1\u53EF\u80FD\u5DF2\u63A5\u53D7\u65B0\u7248\u4E1A\u52A1\u6570\u636E\uFF1B\u62D2\u7EDD\u6062\u590D\u65E7\u5FEB\u7167\uFF0C\u8BF7\u4F7F\u7528\u517C\u5BB9\u7248\u672C\u68C0\u67E5\u3002");
|
|
22035
21784
|
const previous = await readJson(
|
|
22036
|
-
(0,
|
|
21785
|
+
(0, import_node_path4.join)(paths.previous, "package.json")
|
|
22037
21786
|
);
|
|
22038
21787
|
if (previous) {
|
|
22039
21788
|
if (active && !active.maintenance)
|
|
22040
21789
|
throw new Error("\u65E7\u670D\u52A1\u5DF2\u6062\u590D\u4E1A\u52A1\u5199\u5165\uFF1B\u62D2\u7EDD\u7528\u5347\u7EA7\u524D\u5FEB\u7167\u8986\u76D6\u73B0\u6709\u6570\u636E\uFF0C\u8BF7\u4FDD\u7559\u73B0\u573A\u68C0\u67E5\u3002");
|
|
22041
21790
|
if (previous.name !== npmPackageName || previous.version !== record2.from)
|
|
22042
21791
|
throw new Error("\u65E7\u7248\u5907\u4EFD\u8EAB\u4EFD\u4E0D\u5339\u914D");
|
|
22043
|
-
const snapshot = await readJson((0,
|
|
21792
|
+
const snapshot = await readJson((0, import_node_path4.join)(paths.backup, "snapshot.json"));
|
|
22044
21793
|
if (!snapshot?.complete) throw new Error("\u6570\u636E\u5E93\u5907\u4EFD\u4E0D\u5B8C\u6574\uFF0C\u4FDD\u7559\u5168\u90E8\u73B0\u573A\u4F9B\u68C0\u67E5");
|
|
22045
21794
|
} else {
|
|
22046
21795
|
const original = await readJson(
|
|
22047
|
-
(0,
|
|
21796
|
+
(0, import_node_path4.join)(paths.root, "package.json")
|
|
22048
21797
|
);
|
|
22049
21798
|
if (original?.name !== npmPackageName || original.version !== record2.from)
|
|
22050
21799
|
throw new Error("\u672A\u627E\u5230\u5B8C\u6574\u7684\u4E0A\u4E00\u7248\u672C\u5B89\u88C5");
|
|
@@ -22055,20 +21804,20 @@ async function worker(directory) {
|
|
|
22055
21804
|
}
|
|
22056
21805
|
await stopService(context);
|
|
22057
21806
|
if (previous) {
|
|
22058
|
-
await (0,
|
|
22059
|
-
await (0,
|
|
21807
|
+
await (0, import_promises5.rm)(paths.root, { recursive: true, force: true });
|
|
21808
|
+
await (0, import_promises5.rename)(paths.previous, paths.root);
|
|
22060
21809
|
for (const name of ["app.sqlite", "app.sqlite-wal", "app.sqlite-shm"]) {
|
|
22061
|
-
await (0,
|
|
21810
|
+
await (0, import_promises5.rm)((0, import_node_path4.join)(paths.dataDir, name), { force: true });
|
|
22062
21811
|
try {
|
|
22063
|
-
await copyDurable((0,
|
|
21812
|
+
await copyDurable((0, import_node_path4.join)(paths.backup, name), (0, import_node_path4.join)(paths.dataDir, name));
|
|
22064
21813
|
} catch (error62) {
|
|
22065
21814
|
if (error62.code !== "ENOENT") throw error62;
|
|
22066
21815
|
}
|
|
22067
21816
|
}
|
|
22068
|
-
await copyDurable((0,
|
|
21817
|
+
await copyDurable((0, import_node_path4.join)(paths.backup, "config.json"), paths.config);
|
|
22069
21818
|
}
|
|
22070
21819
|
const restored = await readJson(
|
|
22071
|
-
(0,
|
|
21820
|
+
(0, import_node_path4.join)(paths.root, "package.json")
|
|
22072
21821
|
);
|
|
22073
21822
|
if (restored?.name !== npmPackageName || restored.version !== record2.from)
|
|
22074
21823
|
throw new Error("\u672A\u627E\u5230\u5B8C\u6574\u7684\u4E0A\u4E00\u7248\u672C\u5B89\u88C5");
|
|
@@ -22085,10 +21834,10 @@ async function worker(directory) {
|
|
|
22085
21834
|
}
|
|
22086
21835
|
const reason = await inspectInstallation(context.root);
|
|
22087
21836
|
if (reason) throw new Error(reason);
|
|
22088
|
-
for (const key of await (0,
|
|
21837
|
+
for (const key of await (0, import_promises5.readdir)((0, import_node_path4.join)(context.location.home, "instances"))) {
|
|
22089
21838
|
if (key === context.location.key) continue;
|
|
22090
21839
|
const instance = await readJson(
|
|
22091
|
-
(0,
|
|
21840
|
+
(0, import_node_path4.join)(context.location.home, "instances", key, "instance.json")
|
|
22092
21841
|
);
|
|
22093
21842
|
if (instance?.root !== context.root) continue;
|
|
22094
21843
|
try {
|
|
@@ -22098,8 +21847,8 @@ async function worker(directory) {
|
|
|
22098
21847
|
if (!isNotRunning(error62)) throw error62;
|
|
22099
21848
|
}
|
|
22100
21849
|
}
|
|
22101
|
-
await (0,
|
|
22102
|
-
await
|
|
21850
|
+
await (0, import_promises5.access)((0, import_node_path4.dirname)(context.root), import_node_fs2.constants.W_OK);
|
|
21851
|
+
await exec(
|
|
22103
21852
|
"npm",
|
|
22104
21853
|
[
|
|
22105
21854
|
"install",
|
|
@@ -22116,7 +21865,7 @@ async function worker(directory) {
|
|
|
22116
21865
|
{ timeout: 10 * 6e4, maxBuffer: 2 * 1024 * 1024 }
|
|
22117
21866
|
);
|
|
22118
21867
|
const candidate = await readJson(
|
|
22119
|
-
(0,
|
|
21868
|
+
(0, import_node_path4.join)(paths.candidate, "package.json")
|
|
22120
21869
|
);
|
|
22121
21870
|
if (candidate?.name !== npmPackageName || candidate.version !== record2.target)
|
|
22122
21871
|
throw new Error("\u5019\u9009\u5305\u8EAB\u4EFD\u6216\u7248\u672C\u4E0D\u5339\u914D");
|
|
@@ -22135,13 +21884,13 @@ async function worker(directory) {
|
|
|
22135
21884
|
);
|
|
22136
21885
|
};
|
|
22137
21886
|
await checkCodex();
|
|
22138
|
-
await
|
|
21887
|
+
await exec(process.execPath, [(0, import_node_path4.join)(paths.candidate, "bin/covro.mjs"), "--version"], {
|
|
22139
21888
|
timeout: 3e4
|
|
22140
21889
|
});
|
|
22141
21890
|
const nativeProbe = 'const {createRequire}=await import("node:module"); const r=createRequire(process.argv[1]); const DB=r("better-sqlite3"); const db=new DB(":memory:"); db.close();';
|
|
22142
|
-
await
|
|
21891
|
+
await exec(
|
|
22143
21892
|
process.execPath,
|
|
22144
|
-
["--input-type=module", "-e", nativeProbe, (0,
|
|
21893
|
+
["--input-type=module", "-e", nativeProbe, (0, import_node_path4.join)(paths.candidate, "package.json")],
|
|
22145
21894
|
{ timeout: 3e4 }
|
|
22146
21895
|
);
|
|
22147
21896
|
await verifyMigrations(context, paths.candidate);
|
|
@@ -22159,12 +21908,12 @@ async function worker(directory) {
|
|
|
22159
21908
|
return;
|
|
22160
21909
|
}
|
|
22161
21910
|
await update("waiting", result.reason ?? "\u7B49\u5F85\u6240\u6709\u4EFB\u52A1\u7ED3\u675F");
|
|
22162
|
-
await (0,
|
|
21911
|
+
await (0, import_promises6.setTimeout)(2e3);
|
|
22163
21912
|
}
|
|
22164
21913
|
},
|
|
22165
21914
|
stop: () => stopService(context),
|
|
22166
21915
|
start: async (candidate2) => {
|
|
22167
|
-
await startService(context);
|
|
21916
|
+
await startService(context, candidate2 ? record2.id : void 0);
|
|
22168
21917
|
if (!candidate2) await verifyRestoredService(context, record2.from);
|
|
22169
21918
|
},
|
|
22170
21919
|
verify: async () => {
|
|
@@ -22178,7 +21927,7 @@ async function worker(directory) {
|
|
|
22178
21927
|
await checkCodex(current);
|
|
22179
21928
|
if (current.codexReady) return;
|
|
22180
21929
|
}
|
|
22181
|
-
await (0,
|
|
21930
|
+
await (0, import_promises6.setTimeout)(250);
|
|
22182
21931
|
}
|
|
22183
21932
|
throw new Error("\u65B0\u7248\u670D\u52A1\u6216 Codex \u8FDE\u63A5\u672A\u5C31\u7EEA\uFF0C\u62D2\u7EDD\u6FC0\u6D3B");
|
|
22184
21933
|
},
|
|
@@ -22187,18 +21936,18 @@ async function worker(directory) {
|
|
|
22187
21936
|
id: record2.id,
|
|
22188
21937
|
channel: record2.channel
|
|
22189
21938
|
});
|
|
22190
|
-
const final = await readJson((0,
|
|
21939
|
+
const final = await readJson((0, import_node_path4.join)(directory, "run.json"));
|
|
22191
21940
|
if (!final?.committed) throw new Error("\u65B0\u7248\u5C1A\u672A\u786E\u8BA4\u5347\u7EA7\u63D0\u4EA4");
|
|
22192
21941
|
record2 = final;
|
|
22193
21942
|
},
|
|
22194
|
-
hasCommitted: async () => Boolean((await readJson((0,
|
|
21943
|
+
hasCommitted: async () => Boolean((await readJson((0, import_node_path4.join)(directory, "run.json")))?.committed),
|
|
22195
21944
|
resume: async () => {
|
|
22196
21945
|
await control(context.location, "cancel-update").catch(() => {
|
|
22197
21946
|
});
|
|
22198
21947
|
}
|
|
22199
21948
|
});
|
|
22200
21949
|
} catch (error62) {
|
|
22201
|
-
const latest = await readJson((0,
|
|
21950
|
+
const latest = await readJson((0, import_node_path4.join)(directory, "run.json"));
|
|
22202
21951
|
if (latest?.committed) {
|
|
22203
21952
|
record2 = latest;
|
|
22204
21953
|
} else if (!["rolledBack", "failed"].includes(record2.phase))
|
|
@@ -22208,7 +21957,7 @@ async function worker(directory) {
|
|
|
22208
21957
|
} finally {
|
|
22209
21958
|
await release();
|
|
22210
21959
|
if (record2.phase === "succeeded" || record2.phase === "rolledBack") {
|
|
22211
|
-
await (0,
|
|
21960
|
+
await (0, import_promises5.rm)(paths.prefix, { recursive: true, force: true });
|
|
22212
21961
|
}
|
|
22213
21962
|
}
|
|
22214
21963
|
}
|