@codexhost/cli-win32-x64 0.28.2 → 0.29.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 +1 -1
- package/app/codexhost-distribution.json +1 -1
- package/app/console-server.mjs +1894 -575
- package/app/console-web.js +2814 -729
- package/app/desktop-controller.mjs +251 -36
- package/app/host-runtime.mjs +36528 -32793
- package/app/plugins/antigravity/assets/icon.svg +34 -1
- package/app/plugins/antigravity/plugin.mjs +1628 -657
- package/app/plugins/claude-code/assets/icon.svg +1 -1
- package/app/plugins/claude-code/manifest.json +1 -1
- package/app/plugins/claude-code/plugin.mjs +256 -31
- package/app/plugins/codebuddy/assets/icon.svg +1 -1
- package/app/plugins/codebuddy/plugin.mjs +230 -28
- package/app/plugins/codex-usage/plugin.mjs +230 -28
- package/app/plugins/copilot/assets/icon.svg +3 -0
- package/app/plugins/copilot/manifest.json +13 -1
- package/app/plugins/copilot/plugin.mjs +230 -28
- package/app/plugins/cursor-cli/assets/icon.svg +1 -1
- package/app/plugins/cursor-cli/plugin.mjs +304 -44
- package/app/plugins/deepseek-harness/assets/icon.svg +1 -1
- package/app/plugins/deepseek-harness/manifest.json +1 -1
- package/app/plugins/deepseek-harness/plugin.mjs +230 -28
- package/app/plugins/devin/assets/icon.svg +1 -1
- package/app/plugins/devin/manifest.json +20 -0
- package/app/plugins/devin/plugin.mjs +354 -67
- package/app/plugins/grok/assets/icon.svg +4 -0
- package/app/plugins/grok/manifest.json +16 -2
- package/app/plugins/grok/plugin.mjs +230 -28
- package/app/plugins/hermes/assets/icon.png +0 -0
- package/app/plugins/hermes/manifest.json +0 -5
- package/app/plugins/hermes/plugin.mjs +230 -28
- package/app/plugins/kimi-code/assets/icon.svg +1 -1
- package/app/plugins/kimi-code/manifest.json +20 -0
- package/app/plugins/kimi-code/plugin.mjs +230 -28
- package/app/plugins/kiro-cli/assets/kiro-agent.svg +1 -6
- package/app/plugins/kiro-cli/manifest.json +24 -0
- package/app/plugins/kiro-cli/plugin.mjs +230 -28
- package/app/plugins/omp/assets/icon.svg +1 -1
- package/app/plugins/omp/manifest.json +0 -3
- package/app/plugins/omp/plugin.mjs +231 -29
- package/app/plugins/opencode/assets/icon.svg +5 -0
- package/app/plugins/opencode/manifest.json +22 -1
- package/app/plugins/opencode/plugin.mjs +246 -40
- package/app/plugins/pi/assets/icon.svg +3 -3
- package/app/plugins/pi/plugin.mjs +272 -30
- package/app/plugins/qoder/assets/icon.svg +1 -1
- package/app/plugins/qoder/plugin.mjs +230 -28
- package/app/plugins/qoder-cn/assets/icon.svg +1 -1
- package/app/plugins/qoder-cn/plugin.mjs +230 -28
- package/app/plugins/qwen-code/assets/icon.svg +1 -1
- package/app/plugins/qwen-code/plugin.mjs +230 -28
- package/app/plugins/workbuddy/assets/icon.svg +7 -9
- package/app/plugins/workbuddy/plugin.mjs +230 -28
- package/app/plugins/zcode/assets/icon.svg +1 -1
- package/app/plugins/zcode/plugin.mjs +230 -28
- package/app/renderer-extension.js +4230 -783
- package/app/web/apple-touch-icon.png +0 -0
- package/app/web/assets/index-0TnaYwHS.js +205 -0
- package/app/web/assets/index-aSHN2MIG.css +1 -0
- package/app/web/codex-agent.png +0 -0
- package/app/web/codex.png +0 -0
- package/app/web/codexhost-settings.js +1225 -305
- package/app/web/favicon-dark.svg +37 -4
- package/app/web/favicon.svg +37 -3
- package/app/web/icon-192.png +0 -0
- package/app/web/icon-512.png +0 -0
- package/app/web/index.html +2 -2
- package/app/web/plugins/deepseek-ai__dsh-api-remotes/client.js +65 -65
- package/app/web/plugins/deepseek-ai__dsh-api-session-controller/client.js +8 -8
- package/app/web/plugins/deepseek-ai__dsh-api-workspace-controller/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-file-upload/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-attachment/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-chat/client.js +69 -69
- package/app/web/plugins/deepseek-ai__dsh-client-ui-codexhost/client.js +73 -73
- package/app/web/plugins/deepseek-ai__dsh-client-ui-conversation/client.js +102 -98
- package/app/web/plugins/deepseek-ai__dsh-client-ui-input-trigger/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-model-selection/client.js +2 -2
- package/app/web/plugins/deepseek-ai__dsh-client-ui-session/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-shortcuts/client.js +2 -2
- package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar/client.js +2 -2
- package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar-files/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-subagent/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-theme/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-tool/client.js +18 -18
- package/app/web/plugins/deepseek-ai__dsh-client-ui-user-questions/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-workspace/client.js +75 -81
- package/app/web/plugins.json +1 -0
- package/app/web-modules/server.mjs +1718 -573
- package/bin/codexhost.exe +0 -0
- package/libexec/codexhost-node-repl.exe +0 -0
- package/libexec/codexhost-screenshot.exe +0 -0
- package/libexec/codexhost-shell.exe +0 -0
- package/libexec/codexhost-shim.exe +0 -0
- package/libexec/codexhost-updater.exe +0 -0
- package/package.json +1 -1
- package/app/plugins/copilot/assets/icon.png +0 -0
- package/app/plugins/grok/assets/icon.png +0 -0
- package/app/plugins/opencode/assets/icon.png +0 -0
- package/app/web/assets/index-BJq8mT6r.js +0 -204
- package/app/web/assets/index-CMDliP5b.css +0 -1
package/app/console-server.mjs
CHANGED
|
@@ -91,14 +91,14 @@ var require_polyfills = __commonJS({
|
|
|
91
91
|
fs.fstatSync = statFixSync(fs.fstatSync);
|
|
92
92
|
fs.lstatSync = statFixSync(fs.lstatSync);
|
|
93
93
|
if (fs.chmod && !fs.lchmod) {
|
|
94
|
-
fs.lchmod = function(
|
|
94
|
+
fs.lchmod = function(path25, mode, cb) {
|
|
95
95
|
if (cb) process.nextTick(cb);
|
|
96
96
|
};
|
|
97
97
|
fs.lchmodSync = function() {
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
100
|
if (fs.chown && !fs.lchown) {
|
|
101
|
-
fs.lchown = function(
|
|
101
|
+
fs.lchown = function(path25, uid, gid, cb) {
|
|
102
102
|
if (cb) process.nextTick(cb);
|
|
103
103
|
};
|
|
104
104
|
fs.lchownSync = function() {
|
|
@@ -106,7 +106,7 @@ var require_polyfills = __commonJS({
|
|
|
106
106
|
}
|
|
107
107
|
if (platform === "win32") {
|
|
108
108
|
fs.rename = typeof fs.rename !== "function" ? fs.rename : (function(fs$rename) {
|
|
109
|
-
function
|
|
109
|
+
function rename6(from, to, cb) {
|
|
110
110
|
var start = Date.now();
|
|
111
111
|
var backoff = 0;
|
|
112
112
|
fs$rename(from, to, function CB(er) {
|
|
@@ -126,8 +126,8 @@ var require_polyfills = __commonJS({
|
|
|
126
126
|
if (cb) cb(er);
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
|
-
if (Object.setPrototypeOf) Object.setPrototypeOf(
|
|
130
|
-
return
|
|
129
|
+
if (Object.setPrototypeOf) Object.setPrototypeOf(rename6, fs$rename);
|
|
130
|
+
return rename6;
|
|
131
131
|
})(fs.rename);
|
|
132
132
|
}
|
|
133
133
|
fs.read = typeof fs.read !== "function" ? fs.read : (function(fs$read) {
|
|
@@ -165,9 +165,9 @@ var require_polyfills = __commonJS({
|
|
|
165
165
|
};
|
|
166
166
|
})(fs.readSync);
|
|
167
167
|
function patchLchmod(fs2) {
|
|
168
|
-
fs2.lchmod = function(
|
|
168
|
+
fs2.lchmod = function(path25, mode, callback) {
|
|
169
169
|
fs2.open(
|
|
170
|
-
|
|
170
|
+
path25,
|
|
171
171
|
constants2.O_WRONLY | constants2.O_SYMLINK,
|
|
172
172
|
mode,
|
|
173
173
|
function(err, fd) {
|
|
@@ -183,8 +183,8 @@ var require_polyfills = __commonJS({
|
|
|
183
183
|
}
|
|
184
184
|
);
|
|
185
185
|
};
|
|
186
|
-
fs2.lchmodSync = function(
|
|
187
|
-
var fd = fs2.openSync(
|
|
186
|
+
fs2.lchmodSync = function(path25, mode) {
|
|
187
|
+
var fd = fs2.openSync(path25, constants2.O_WRONLY | constants2.O_SYMLINK, mode);
|
|
188
188
|
var threw = true;
|
|
189
189
|
var ret;
|
|
190
190
|
try {
|
|
@@ -205,8 +205,8 @@ var require_polyfills = __commonJS({
|
|
|
205
205
|
}
|
|
206
206
|
function patchLutimes(fs2) {
|
|
207
207
|
if (constants2.hasOwnProperty("O_SYMLINK") && fs2.futimes) {
|
|
208
|
-
fs2.lutimes = function(
|
|
209
|
-
fs2.open(
|
|
208
|
+
fs2.lutimes = function(path25, at, mt, cb) {
|
|
209
|
+
fs2.open(path25, constants2.O_SYMLINK, function(er, fd) {
|
|
210
210
|
if (er) {
|
|
211
211
|
if (cb) cb(er);
|
|
212
212
|
return;
|
|
@@ -218,8 +218,8 @@ var require_polyfills = __commonJS({
|
|
|
218
218
|
});
|
|
219
219
|
});
|
|
220
220
|
};
|
|
221
|
-
fs2.lutimesSync = function(
|
|
222
|
-
var fd = fs2.openSync(
|
|
221
|
+
fs2.lutimesSync = function(path25, at, mt) {
|
|
222
|
+
var fd = fs2.openSync(path25, constants2.O_SYMLINK);
|
|
223
223
|
var ret;
|
|
224
224
|
var threw = true;
|
|
225
225
|
try {
|
|
@@ -337,11 +337,11 @@ var require_legacy_streams = __commonJS({
|
|
|
337
337
|
ReadStream,
|
|
338
338
|
WriteStream
|
|
339
339
|
};
|
|
340
|
-
function ReadStream(
|
|
341
|
-
if (!(this instanceof ReadStream)) return new ReadStream(
|
|
340
|
+
function ReadStream(path25, options) {
|
|
341
|
+
if (!(this instanceof ReadStream)) return new ReadStream(path25, options);
|
|
342
342
|
Stream.call(this);
|
|
343
343
|
var self = this;
|
|
344
|
-
this.path =
|
|
344
|
+
this.path = path25;
|
|
345
345
|
this.fd = null;
|
|
346
346
|
this.readable = true;
|
|
347
347
|
this.paused = false;
|
|
@@ -386,10 +386,10 @@ var require_legacy_streams = __commonJS({
|
|
|
386
386
|
self._read();
|
|
387
387
|
});
|
|
388
388
|
}
|
|
389
|
-
function WriteStream(
|
|
390
|
-
if (!(this instanceof WriteStream)) return new WriteStream(
|
|
389
|
+
function WriteStream(path25, options) {
|
|
390
|
+
if (!(this instanceof WriteStream)) return new WriteStream(path25, options);
|
|
391
391
|
Stream.call(this);
|
|
392
|
-
this.path =
|
|
392
|
+
this.path = path25;
|
|
393
393
|
this.fd = null;
|
|
394
394
|
this.writable = true;
|
|
395
395
|
this.flags = "w";
|
|
@@ -531,15 +531,15 @@ var require_graceful_fs = __commonJS({
|
|
|
531
531
|
fs2.createReadStream = createReadStream2;
|
|
532
532
|
fs2.createWriteStream = createWriteStream;
|
|
533
533
|
var fs$readFile = fs2.readFile;
|
|
534
|
-
fs2.readFile =
|
|
535
|
-
function
|
|
534
|
+
fs2.readFile = readFile13;
|
|
535
|
+
function readFile13(path25, options, cb) {
|
|
536
536
|
if (typeof options === "function")
|
|
537
537
|
cb = options, options = null;
|
|
538
|
-
return go$readFile(
|
|
539
|
-
function go$readFile(
|
|
540
|
-
return fs$readFile(
|
|
538
|
+
return go$readFile(path25, options, cb);
|
|
539
|
+
function go$readFile(path26, options2, cb2, startTime) {
|
|
540
|
+
return fs$readFile(path26, options2, function(err) {
|
|
541
541
|
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
542
|
-
enqueue([go$readFile, [
|
|
542
|
+
enqueue([go$readFile, [path26, options2, cb2], err, startTime || Date.now(), Date.now()]);
|
|
543
543
|
else {
|
|
544
544
|
if (typeof cb2 === "function")
|
|
545
545
|
cb2.apply(this, arguments);
|
|
@@ -548,15 +548,15 @@ var require_graceful_fs = __commonJS({
|
|
|
548
548
|
}
|
|
549
549
|
}
|
|
550
550
|
var fs$writeFile = fs2.writeFile;
|
|
551
|
-
fs2.writeFile =
|
|
552
|
-
function
|
|
551
|
+
fs2.writeFile = writeFile8;
|
|
552
|
+
function writeFile8(path25, data, options, cb) {
|
|
553
553
|
if (typeof options === "function")
|
|
554
554
|
cb = options, options = null;
|
|
555
|
-
return go$writeFile(
|
|
556
|
-
function go$writeFile(
|
|
557
|
-
return fs$writeFile(
|
|
555
|
+
return go$writeFile(path25, data, options, cb);
|
|
556
|
+
function go$writeFile(path26, data2, options2, cb2, startTime) {
|
|
557
|
+
return fs$writeFile(path26, data2, options2, function(err) {
|
|
558
558
|
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
559
|
-
enqueue([go$writeFile, [
|
|
559
|
+
enqueue([go$writeFile, [path26, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
|
|
560
560
|
else {
|
|
561
561
|
if (typeof cb2 === "function")
|
|
562
562
|
cb2.apply(this, arguments);
|
|
@@ -567,14 +567,14 @@ var require_graceful_fs = __commonJS({
|
|
|
567
567
|
var fs$appendFile = fs2.appendFile;
|
|
568
568
|
if (fs$appendFile)
|
|
569
569
|
fs2.appendFile = appendFile;
|
|
570
|
-
function appendFile(
|
|
570
|
+
function appendFile(path25, data, options, cb) {
|
|
571
571
|
if (typeof options === "function")
|
|
572
572
|
cb = options, options = null;
|
|
573
|
-
return go$appendFile(
|
|
574
|
-
function go$appendFile(
|
|
575
|
-
return fs$appendFile(
|
|
573
|
+
return go$appendFile(path25, data, options, cb);
|
|
574
|
+
function go$appendFile(path26, data2, options2, cb2, startTime) {
|
|
575
|
+
return fs$appendFile(path26, data2, options2, function(err) {
|
|
576
576
|
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
577
|
-
enqueue([go$appendFile, [
|
|
577
|
+
enqueue([go$appendFile, [path26, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
|
|
578
578
|
else {
|
|
579
579
|
if (typeof cb2 === "function")
|
|
580
580
|
cb2.apply(this, arguments);
|
|
@@ -603,33 +603,33 @@ var require_graceful_fs = __commonJS({
|
|
|
603
603
|
}
|
|
604
604
|
}
|
|
605
605
|
var fs$readdir = fs2.readdir;
|
|
606
|
-
fs2.readdir =
|
|
606
|
+
fs2.readdir = readdir7;
|
|
607
607
|
var noReaddirOptionVersions = /^v[0-5]\./;
|
|
608
|
-
function
|
|
608
|
+
function readdir7(path25, options, cb) {
|
|
609
609
|
if (typeof options === "function")
|
|
610
610
|
cb = options, options = null;
|
|
611
|
-
var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(
|
|
612
|
-
return fs$readdir(
|
|
613
|
-
|
|
611
|
+
var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(path26, options2, cb2, startTime) {
|
|
612
|
+
return fs$readdir(path26, fs$readdirCallback(
|
|
613
|
+
path26,
|
|
614
614
|
options2,
|
|
615
615
|
cb2,
|
|
616
616
|
startTime
|
|
617
617
|
));
|
|
618
|
-
} : function go$readdir2(
|
|
619
|
-
return fs$readdir(
|
|
620
|
-
|
|
618
|
+
} : function go$readdir2(path26, options2, cb2, startTime) {
|
|
619
|
+
return fs$readdir(path26, options2, fs$readdirCallback(
|
|
620
|
+
path26,
|
|
621
621
|
options2,
|
|
622
622
|
cb2,
|
|
623
623
|
startTime
|
|
624
624
|
));
|
|
625
625
|
};
|
|
626
|
-
return go$readdir(
|
|
627
|
-
function fs$readdirCallback(
|
|
626
|
+
return go$readdir(path25, options, cb);
|
|
627
|
+
function fs$readdirCallback(path26, options2, cb2, startTime) {
|
|
628
628
|
return function(err, files) {
|
|
629
629
|
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
630
630
|
enqueue([
|
|
631
631
|
go$readdir,
|
|
632
|
-
[
|
|
632
|
+
[path26, options2, cb2],
|
|
633
633
|
err,
|
|
634
634
|
startTime || Date.now(),
|
|
635
635
|
Date.now()
|
|
@@ -700,7 +700,7 @@ var require_graceful_fs = __commonJS({
|
|
|
700
700
|
enumerable: true,
|
|
701
701
|
configurable: true
|
|
702
702
|
});
|
|
703
|
-
function ReadStream(
|
|
703
|
+
function ReadStream(path25, options) {
|
|
704
704
|
if (this instanceof ReadStream)
|
|
705
705
|
return fs$ReadStream.apply(this, arguments), this;
|
|
706
706
|
else
|
|
@@ -708,7 +708,7 @@ var require_graceful_fs = __commonJS({
|
|
|
708
708
|
}
|
|
709
709
|
function ReadStream$open() {
|
|
710
710
|
var that = this;
|
|
711
|
-
|
|
711
|
+
open9(that.path, that.flags, that.mode, function(err, fd) {
|
|
712
712
|
if (err) {
|
|
713
713
|
if (that.autoClose)
|
|
714
714
|
that.destroy();
|
|
@@ -720,7 +720,7 @@ var require_graceful_fs = __commonJS({
|
|
|
720
720
|
}
|
|
721
721
|
});
|
|
722
722
|
}
|
|
723
|
-
function WriteStream(
|
|
723
|
+
function WriteStream(path25, options) {
|
|
724
724
|
if (this instanceof WriteStream)
|
|
725
725
|
return fs$WriteStream.apply(this, arguments), this;
|
|
726
726
|
else
|
|
@@ -728,7 +728,7 @@ var require_graceful_fs = __commonJS({
|
|
|
728
728
|
}
|
|
729
729
|
function WriteStream$open() {
|
|
730
730
|
var that = this;
|
|
731
|
-
|
|
731
|
+
open9(that.path, that.flags, that.mode, function(err, fd) {
|
|
732
732
|
if (err) {
|
|
733
733
|
that.destroy();
|
|
734
734
|
that.emit("error", err);
|
|
@@ -738,22 +738,22 @@ var require_graceful_fs = __commonJS({
|
|
|
738
738
|
}
|
|
739
739
|
});
|
|
740
740
|
}
|
|
741
|
-
function createReadStream2(
|
|
742
|
-
return new fs2.ReadStream(
|
|
741
|
+
function createReadStream2(path25, options) {
|
|
742
|
+
return new fs2.ReadStream(path25, options);
|
|
743
743
|
}
|
|
744
|
-
function createWriteStream(
|
|
745
|
-
return new fs2.WriteStream(
|
|
744
|
+
function createWriteStream(path25, options) {
|
|
745
|
+
return new fs2.WriteStream(path25, options);
|
|
746
746
|
}
|
|
747
747
|
var fs$open = fs2.open;
|
|
748
|
-
fs2.open =
|
|
749
|
-
function
|
|
748
|
+
fs2.open = open9;
|
|
749
|
+
function open9(path25, flags, mode, cb) {
|
|
750
750
|
if (typeof mode === "function")
|
|
751
751
|
cb = mode, mode = null;
|
|
752
|
-
return go$open(
|
|
753
|
-
function go$open(
|
|
754
|
-
return fs$open(
|
|
752
|
+
return go$open(path25, flags, mode, cb);
|
|
753
|
+
function go$open(path26, flags2, mode2, cb2, startTime) {
|
|
754
|
+
return fs$open(path26, flags2, mode2, function(err, fd) {
|
|
755
755
|
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
756
|
-
enqueue([go$open, [
|
|
756
|
+
enqueue([go$open, [path26, flags2, mode2, cb2], err, startTime || Date.now(), Date.now()]);
|
|
757
757
|
else {
|
|
758
758
|
if (typeof cb2 === "function")
|
|
759
759
|
cb2.apply(this, arguments);
|
|
@@ -1282,7 +1282,7 @@ var require_mtime_precision = __commonJS({
|
|
|
1282
1282
|
var require_lockfile = __commonJS({
|
|
1283
1283
|
"node_modules/proper-lockfile/lib/lockfile.js"(exports, module) {
|
|
1284
1284
|
"use strict";
|
|
1285
|
-
var
|
|
1285
|
+
var path25 = __require("path");
|
|
1286
1286
|
var fs = require_graceful_fs();
|
|
1287
1287
|
var retry = require_retry2();
|
|
1288
1288
|
var onExit = require_signal_exit();
|
|
@@ -1293,7 +1293,7 @@ var require_lockfile = __commonJS({
|
|
|
1293
1293
|
}
|
|
1294
1294
|
function resolveCanonicalPath(file2, options, callback) {
|
|
1295
1295
|
if (!options.realpath) {
|
|
1296
|
-
return callback(null,
|
|
1296
|
+
return callback(null, path25.resolve(file2));
|
|
1297
1297
|
}
|
|
1298
1298
|
options.fs.realpath(file2, callback);
|
|
1299
1299
|
}
|
|
@@ -1617,14 +1617,15 @@ var require_proper_lockfile = __commonJS({
|
|
|
1617
1617
|
});
|
|
1618
1618
|
|
|
1619
1619
|
// packages/console-server/src/main.ts
|
|
1620
|
-
import
|
|
1620
|
+
import path24 from "node:path";
|
|
1621
1621
|
import { fileURLToPath } from "node:url";
|
|
1622
1622
|
|
|
1623
1623
|
// packages/update-manager/dist/runtime-metadata.js
|
|
1624
|
-
import { readFile } from "node:fs/promises";
|
|
1624
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
1625
1625
|
import path2 from "node:path";
|
|
1626
1626
|
|
|
1627
1627
|
// packages/update-manager/dist/distribution.js
|
|
1628
|
+
import { lstat, readFile, realpath } from "node:fs/promises";
|
|
1628
1629
|
import path from "node:path";
|
|
1629
1630
|
|
|
1630
1631
|
// node_modules/zod/v4/classic/external.js
|
|
@@ -2444,10 +2445,10 @@ function mergeDefs(...defs) {
|
|
|
2444
2445
|
function cloneDef(schema) {
|
|
2445
2446
|
return mergeDefs(schema._zod.def);
|
|
2446
2447
|
}
|
|
2447
|
-
function getElementAtPath(obj,
|
|
2448
|
-
if (!
|
|
2448
|
+
function getElementAtPath(obj, path25) {
|
|
2449
|
+
if (!path25)
|
|
2449
2450
|
return obj;
|
|
2450
|
-
return
|
|
2451
|
+
return path25.reduce((acc, key) => acc?.[key], obj);
|
|
2451
2452
|
}
|
|
2452
2453
|
function promiseAllObject(promisesObj) {
|
|
2453
2454
|
const keys = Object.keys(promisesObj);
|
|
@@ -2787,11 +2788,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
2787
2788
|
}
|
|
2788
2789
|
return false;
|
|
2789
2790
|
}
|
|
2790
|
-
function prefixIssues(
|
|
2791
|
+
function prefixIssues(path25, issues) {
|
|
2791
2792
|
return issues.map((iss) => {
|
|
2792
2793
|
var _a3;
|
|
2793
2794
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
2794
|
-
iss.path.unshift(
|
|
2795
|
+
iss.path.unshift(path25);
|
|
2795
2796
|
return iss;
|
|
2796
2797
|
});
|
|
2797
2798
|
}
|
|
@@ -3253,16 +3254,16 @@ function flattenError(error62, mapper = (issue2) => issue2.message) {
|
|
|
3253
3254
|
}
|
|
3254
3255
|
function formatError(error62, mapper = (issue2) => issue2.message) {
|
|
3255
3256
|
const fieldErrors = { _errors: [] };
|
|
3256
|
-
const processError = (error63,
|
|
3257
|
+
const processError = (error63, path25 = []) => {
|
|
3257
3258
|
for (const issue2 of error63.issues) {
|
|
3258
3259
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
3259
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
3260
|
+
issue2.errors.map((issues) => processError({ issues }, [...path25, ...issue2.path]));
|
|
3260
3261
|
} else if (issue2.code === "invalid_key") {
|
|
3261
|
-
processError({ issues: issue2.issues }, [...
|
|
3262
|
+
processError({ issues: issue2.issues }, [...path25, ...issue2.path]);
|
|
3262
3263
|
} else if (issue2.code === "invalid_element") {
|
|
3263
|
-
processError({ issues: issue2.issues }, [...
|
|
3264
|
+
processError({ issues: issue2.issues }, [...path25, ...issue2.path]);
|
|
3264
3265
|
} else {
|
|
3265
|
-
const fullpath = [...
|
|
3266
|
+
const fullpath = [...path25, ...issue2.path];
|
|
3266
3267
|
if (fullpath.length === 0) {
|
|
3267
3268
|
fieldErrors._errors.push(mapper(issue2));
|
|
3268
3269
|
} else {
|
|
@@ -3301,17 +3302,17 @@ function formatError(error62, mapper = (issue2) => issue2.message) {
|
|
|
3301
3302
|
}
|
|
3302
3303
|
function treeifyError(error62, mapper = (issue2) => issue2.message) {
|
|
3303
3304
|
const result = { errors: [] };
|
|
3304
|
-
const processError = (error63,
|
|
3305
|
+
const processError = (error63, path25 = []) => {
|
|
3305
3306
|
var _a3;
|
|
3306
3307
|
for (const issue2 of error63.issues) {
|
|
3307
3308
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
3308
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
3309
|
+
issue2.errors.map((issues) => processError({ issues }, [...path25, ...issue2.path]));
|
|
3309
3310
|
} else if (issue2.code === "invalid_key") {
|
|
3310
|
-
processError({ issues: issue2.issues }, [...
|
|
3311
|
+
processError({ issues: issue2.issues }, [...path25, ...issue2.path]);
|
|
3311
3312
|
} else if (issue2.code === "invalid_element") {
|
|
3312
|
-
processError({ issues: issue2.issues }, [...
|
|
3313
|
+
processError({ issues: issue2.issues }, [...path25, ...issue2.path]);
|
|
3313
3314
|
} else {
|
|
3314
|
-
const fullpath = [...
|
|
3315
|
+
const fullpath = [...path25, ...issue2.path];
|
|
3315
3316
|
if (fullpath.length === 0) {
|
|
3316
3317
|
result.errors.push(mapper(issue2));
|
|
3317
3318
|
continue;
|
|
@@ -3350,8 +3351,8 @@ function treeifyError(error62, mapper = (issue2) => issue2.message) {
|
|
|
3350
3351
|
}
|
|
3351
3352
|
function toDotPath(_path) {
|
|
3352
3353
|
const segs = [];
|
|
3353
|
-
const
|
|
3354
|
-
for (const seg of
|
|
3354
|
+
const path25 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
3355
|
+
for (const seg of path25) {
|
|
3355
3356
|
if (typeof seg === "number")
|
|
3356
3357
|
segs.push(`[${seg}]`);
|
|
3357
3358
|
else if (typeof seg === "symbol")
|
|
@@ -20489,13 +20490,13 @@ function resolveRef(ref, ctx) {
|
|
|
20489
20490
|
if (!ref.startsWith("#")) {
|
|
20490
20491
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
20491
20492
|
}
|
|
20492
|
-
const
|
|
20493
|
-
if (
|
|
20493
|
+
const path25 = ref.slice(1).split("/").filter(Boolean);
|
|
20494
|
+
if (path25.length === 0) {
|
|
20494
20495
|
return ctx.rootSchema;
|
|
20495
20496
|
}
|
|
20496
20497
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
20497
|
-
if (
|
|
20498
|
-
const key =
|
|
20498
|
+
if (path25[0] === defsKey) {
|
|
20499
|
+
const key = path25[1] === void 0 ? void 0 : decodeJSONPointerSegment(path25[1]);
|
|
20499
20500
|
if (!key || !ctx.defs[key]) {
|
|
20500
20501
|
throw new Error(`Reference not found: ${ref}`);
|
|
20501
20502
|
}
|
|
@@ -22180,7 +22181,7 @@ var desktopExtensionSettingFieldSchema = external_exports.discriminatedUnion("ty
|
|
|
22180
22181
|
default: external_exports.string().optional()
|
|
22181
22182
|
})
|
|
22182
22183
|
]).superRefine((field2, ctx) => {
|
|
22183
|
-
const issue2 = (
|
|
22184
|
+
const issue2 = (path25, message) => ctx.addIssue({ code: "custom", path: [path25], message });
|
|
22184
22185
|
if (field2.type === "number" || field2.type === "range") {
|
|
22185
22186
|
const { min = -Infinity, max = Infinity, default: value } = field2;
|
|
22186
22187
|
if (min > max)
|
|
@@ -22319,16 +22320,16 @@ var hostExtensionIdSchema = desktopExtensionIdSchema.refine((id2) => !reservedNa
|
|
|
22319
22320
|
var hostExtensionTargetSchema = external_exports.enum(["desktop", "web"]);
|
|
22320
22321
|
var hostExtensionDigestSchema = desktopExtensionHashSchema;
|
|
22321
22322
|
var hostExtensionActivationIdSchema = external_exports.uuid();
|
|
22322
|
-
var hostExtensionResourcePathSchema = pluginRelativeResourceSchema.refine((resource) => !/[\x00-\x1f\x7f<>"|*]/u.test(resource) && resource.split("/").every((part) => !/[. ]$/u.test(part) && !reservedName.test(part)), "Expected a portable relative resource path").refine((
|
|
22323
|
+
var hostExtensionResourcePathSchema = pluginRelativeResourceSchema.refine((resource) => !/[\x00-\x1f\x7f<>"|*]/u.test(resource) && resource.split("/").every((part) => !/[. ]$/u.test(part) && !reservedName.test(part)), "Expected a portable relative resource path").refine((path25) => path25.split("/").length <= 32, "Extension resources may be at most 32 segments deep");
|
|
22323
22324
|
var legacy = desktopExtensionManifestSchema.shape;
|
|
22324
22325
|
var localized = (max, min = 0) => external_exports.strictObject({
|
|
22325
22326
|
en: external_exports.string().trim().min(min).max(max),
|
|
22326
22327
|
"zh-CN": external_exports.string().trim().min(min).max(max)
|
|
22327
22328
|
});
|
|
22328
|
-
var resourceWithSuffix = (suffix) => hostExtensionResourcePathSchema.refine((
|
|
22329
|
+
var resourceWithSuffix = (suffix) => hostExtensionResourcePathSchema.refine((path25) => path25.endsWith(suffix), `Expected a ${suffix} file`);
|
|
22329
22330
|
var moduleEntry = resourceWithSuffix(".mjs");
|
|
22330
22331
|
var style = resourceWithSuffix(".css").optional();
|
|
22331
|
-
var hostExtensionCanonicalPath = (
|
|
22332
|
+
var hostExtensionCanonicalPath = (path25) => path25.normalize("NFC").toLowerCase();
|
|
22332
22333
|
var hostExtensionManifestV2Schema = external_exports.strictObject({
|
|
22333
22334
|
manifestVersion: external_exports.literal(2),
|
|
22334
22335
|
id: hostExtensionIdSchema,
|
|
@@ -22338,8 +22339,8 @@ var hostExtensionManifestV2Schema = external_exports.strictObject({
|
|
|
22338
22339
|
details: localized(16384).optional(),
|
|
22339
22340
|
author: legacy.author,
|
|
22340
22341
|
repository: legacy.repository,
|
|
22341
|
-
icon: legacy.icon.refine((
|
|
22342
|
-
screenshots: legacy.screenshots.refine((paths) => paths === void 0 || paths.every((
|
|
22342
|
+
icon: legacy.icon.refine((path25) => path25 === void 0 || hostExtensionResourcePathSchema.safeParse(path25).success),
|
|
22343
|
+
screenshots: legacy.screenshots.refine((paths) => paths === void 0 || paths.every((path25) => hostExtensionResourcePathSchema.safeParse(path25).success)),
|
|
22343
22344
|
categories: legacy.categories,
|
|
22344
22345
|
settingsSchema: legacy.settingsSchema,
|
|
22345
22346
|
slots: legacy.slots.removeDefault().optional(),
|
|
@@ -22400,6 +22401,35 @@ function targetsForCapabilities({ hasPage, hasWidget, hasDesktop, hasWeb, hasBac
|
|
|
22400
22401
|
}
|
|
22401
22402
|
var hostExtensionBackendMethodSchema = desktopExtensionBackendMethodSchema;
|
|
22402
22403
|
|
|
22404
|
+
// packages/shared-contracts/dist/thread-tree-watch.js
|
|
22405
|
+
var THREAD_TREE_MAX_NODES = 5e3;
|
|
22406
|
+
var threadTreeStatusSchema = external_exports.enum(["running", "waiting", "idle", "unknown"]);
|
|
22407
|
+
var threadTreeHandoffSchema = external_exports.strictObject({
|
|
22408
|
+
sourceThreadId: hostThreadIdSchema,
|
|
22409
|
+
createdAtMs: external_exports.number().int().nonnegative()
|
|
22410
|
+
});
|
|
22411
|
+
var threadTreeNodeSchema = external_exports.strictObject({
|
|
22412
|
+
harnessId: harnessIdSchema,
|
|
22413
|
+
title: external_exports.string().optional(),
|
|
22414
|
+
status: threadTreeStatusSchema,
|
|
22415
|
+
archived: external_exports.boolean(),
|
|
22416
|
+
updatedAtMs: external_exports.number().int().nonnegative().optional()
|
|
22417
|
+
});
|
|
22418
|
+
var threadTreeSnapshotSchema = external_exports.strictObject({
|
|
22419
|
+
revision: external_exports.int().nonnegative(),
|
|
22420
|
+
parents: external_exports.record(hostThreadIdSchema, hostThreadIdSchema),
|
|
22421
|
+
handoffs: external_exports.record(hostThreadIdSchema, threadTreeHandoffSchema).optional(),
|
|
22422
|
+
nodes: external_exports.record(hostThreadIdSchema, threadTreeNodeSchema),
|
|
22423
|
+
truncated: external_exports.boolean()
|
|
22424
|
+
}).refine((snapshot) => Object.keys(snapshot.nodes).length <= THREAD_TREE_MAX_NODES, "Too many Thread tree nodes").refine(({ parents, handoffs, nodes }) => Object.entries(parents).every(([child, parent]) => Object.hasOwn(nodes, child) && Object.hasOwn(nodes, parent)) && Object.entries(handoffs ?? {}).every(([target2, { sourceThreadId }]) => Object.hasOwn(nodes, target2) && Object.hasOwn(nodes, sourceThreadId)), "Missing Thread tree node");
|
|
22425
|
+
var subscriptionId = external_exports.string().min(1).max(128);
|
|
22426
|
+
var threadTreeWatchParamsSchema = external_exports.strictObject({});
|
|
22427
|
+
var threadTreeUnwatchParamsSchema = external_exports.strictObject({ subscriptionId });
|
|
22428
|
+
var threadTreeUnwatchResultSchema = external_exports.strictObject({});
|
|
22429
|
+
var threadTreeWatchResultSchema = threadTreeUnwatchParamsSchema.extend({
|
|
22430
|
+
snapshot: threadTreeSnapshotSchema
|
|
22431
|
+
});
|
|
22432
|
+
|
|
22403
22433
|
// packages/shared-contracts/dist/host-extension-management.js
|
|
22404
22434
|
var HOST_EXTENSION_ZIP_MAX_BYTES = DESKTOP_EXTENSION_ZIP_MAX_BYTES;
|
|
22405
22435
|
var HOST_EXTENSION_CATALOG_URL = "https://raw.githubusercontent.com/BytePioneer-AI/codexhost-extensions-registry/main/catalog.v2.json";
|
|
@@ -22409,6 +22439,16 @@ var hostExtensionConfigurationSchema = external_exports.strictObject({
|
|
|
22409
22439
|
revision: hostExtensionRevisionSchema,
|
|
22410
22440
|
enabled: external_exports.array(hostExtensionIdSchema).max(DESKTOP_EXTENSION_LIMIT).refine((ids) => new Set(ids).size === ids.length, "Duplicate extension IDs")
|
|
22411
22441
|
});
|
|
22442
|
+
var hostExtensionDefaultSeedsSchema = external_exports.strictObject({
|
|
22443
|
+
version: external_exports.literal(1),
|
|
22444
|
+
seeded: external_exports.array(hostExtensionIdSchema).max(DESKTOP_EXTENSION_LIMIT).refine((ids) => new Set(ids).size === ids.length, "Duplicate extension IDs")
|
|
22445
|
+
});
|
|
22446
|
+
var hostExtensionChangelogEntrySchema = external_exports.object({
|
|
22447
|
+
version: external_exports.string().trim().min(1).max(128),
|
|
22448
|
+
publishedAt: external_exports.string().trim().min(1).max(64).optional(),
|
|
22449
|
+
notes: external_exports.string().trim().min(1).max(8192),
|
|
22450
|
+
url: desktopExtensionHttpUrlSchema.optional()
|
|
22451
|
+
});
|
|
22412
22452
|
var { downloadUrl, ...catalogMetadata } = desktopExtensionCatalogEntrySchema.shape;
|
|
22413
22453
|
var hostExtensionCatalogEntrySchema = external_exports.object({
|
|
22414
22454
|
...catalogMetadata,
|
|
@@ -22422,7 +22462,10 @@ var hostExtensionCatalogEntrySchema = external_exports.object({
|
|
|
22422
22462
|
web: external_exports.int().positive().optional(),
|
|
22423
22463
|
backend: external_exports.int().positive().optional()
|
|
22424
22464
|
}),
|
|
22425
|
-
downloadUrl: downloadUrl.refine((url2) => url2.startsWith("https://"), "Expected HTTPS")
|
|
22465
|
+
downloadUrl: downloadUrl.refine((url2) => url2.startsWith("https://"), "Expected HTTPS"),
|
|
22466
|
+
featured: external_exports.boolean().optional(),
|
|
22467
|
+
featuredOrder: external_exports.int().nonnegative().optional(),
|
|
22468
|
+
changelog: external_exports.array(hostExtensionChangelogEntrySchema).max(20).optional()
|
|
22426
22469
|
}).refine(({ targets, apis }) => {
|
|
22427
22470
|
const derived2 = targetsForCapabilities({
|
|
22428
22471
|
hasPage: Boolean(apis.page),
|
|
@@ -22441,7 +22484,8 @@ var hostExtensionCatalogSchema = external_exports.object({
|
|
|
22441
22484
|
var hostExtensionsCatalogResultSchema = hostExtensionCatalogSchema.extend({
|
|
22442
22485
|
catalogUrl: desktopExtensionHttpUrlSchema,
|
|
22443
22486
|
fetchedAt: external_exports.iso.datetime(),
|
|
22444
|
-
cached: external_exports.boolean()
|
|
22487
|
+
cached: external_exports.boolean(),
|
|
22488
|
+
stale: external_exports.boolean().optional()
|
|
22445
22489
|
});
|
|
22446
22490
|
var id = { id: hostExtensionIdSchema };
|
|
22447
22491
|
var active = {
|
|
@@ -22450,7 +22494,7 @@ var active = {
|
|
|
22450
22494
|
digest: hostExtensionDigestSchema
|
|
22451
22495
|
};
|
|
22452
22496
|
var optionalActivation = { ...id, activationId: active.activationId.optional() };
|
|
22453
|
-
var filePath = external_exports.string().min(1).max(4096).refine((
|
|
22497
|
+
var filePath = external_exports.string().min(1).max(4096).refine((path25) => /^(?:\/|[a-z]:[/\\])/iu.test(path25) && !path25.includes("\0") && !path25.split(/[/\\]/u).some((part) => part === "." || part === ".."), "Expected an absolute local path without dot segments");
|
|
22454
22498
|
var gitRef = external_exports.string().min(1).max(256).refine((ref) => ref.split("/").every((part) => part && /^[a-z0-9_.-]+$/iu.test(part) && part !== "." && part !== ".."), "Invalid GitHub ref");
|
|
22455
22499
|
function base643(maxBytes) {
|
|
22456
22500
|
return external_exports.string().max(4 * Math.ceil(maxBytes / 3)).refine((value) => {
|
|
@@ -22525,6 +22569,7 @@ var HOST_EXTENSIONS_RPC = {
|
|
|
22525
22569
|
list: "codexhost/extensions/list",
|
|
22526
22570
|
snapshot: "codexhost/extensions/snapshot",
|
|
22527
22571
|
catalog: "codexhost/extensions/catalog",
|
|
22572
|
+
catalogIcon: "codexhost/extensions/catalogIcon",
|
|
22528
22573
|
install: "codexhost/extensions/install",
|
|
22529
22574
|
update: "codexhost/extensions/update",
|
|
22530
22575
|
enable: "codexhost/extensions/enable",
|
|
@@ -22534,7 +22579,8 @@ var HOST_EXTENSIONS_RPC = {
|
|
|
22534
22579
|
asset: "codexhost/extensions/asset",
|
|
22535
22580
|
settingsGet: "codexhost/extensions/settings/get",
|
|
22536
22581
|
settingsSet: "codexhost/extensions/settings/set",
|
|
22537
|
-
backendInvoke: "codexhost/extensions/backend/invoke"
|
|
22582
|
+
backendInvoke: "codexhost/extensions/backend/invoke",
|
|
22583
|
+
threadTree: "codexhost/extensions/threadTree"
|
|
22538
22584
|
};
|
|
22539
22585
|
var HOST_EXTENSION_MANAGEMENT_METHODS = Object.freeze(Object.values(HOST_EXTENSIONS_RPC));
|
|
22540
22586
|
var methods = new Set(HOST_EXTENSION_MANAGEMENT_METHODS);
|
|
@@ -22556,6 +22602,10 @@ var hostExtensionsAssetResultSchema = external_exports.strictObject({
|
|
|
22556
22602
|
base64: base643(DESKTOP_EXTENSION_ASSET_MAX_BYTES),
|
|
22557
22603
|
digest: active.digest
|
|
22558
22604
|
});
|
|
22605
|
+
var hostExtensionsCatalogIconResultSchema = external_exports.strictObject({
|
|
22606
|
+
mimeType: external_exports.enum(["image/png", "image/jpeg", "image/webp"]),
|
|
22607
|
+
base64: base643(DESKTOP_EXTENSION_ICON_MAX_BYTES)
|
|
22608
|
+
});
|
|
22559
22609
|
var hostExtensionSettingsSchema = external_exports.strictObject({
|
|
22560
22610
|
settingsRevision: hostExtensionRevisionSchema,
|
|
22561
22611
|
values: jsonObjectSchema
|
|
@@ -22564,9 +22614,16 @@ var hostExtensionsRpcSchemas = {
|
|
|
22564
22614
|
[HOST_EXTENSIONS_RPC.list]: { params: noParams, result: hostExtensionsListResultSchema },
|
|
22565
22615
|
[HOST_EXTENSIONS_RPC.snapshot]: { params: noParams, result: hostExtensionsSnapshotResultSchema },
|
|
22566
22616
|
[HOST_EXTENSIONS_RPC.catalog]: {
|
|
22567
|
-
params: external_exports.strictObject({
|
|
22617
|
+
params: external_exports.strictObject({
|
|
22618
|
+
forceRefresh: external_exports.boolean().optional(),
|
|
22619
|
+
staleWhileRevalidate: external_exports.boolean().optional()
|
|
22620
|
+
}),
|
|
22568
22621
|
result: hostExtensionsCatalogResultSchema
|
|
22569
22622
|
},
|
|
22623
|
+
[HOST_EXTENSIONS_RPC.catalogIcon]: {
|
|
22624
|
+
params: external_exports.strictObject({ ...id }),
|
|
22625
|
+
result: hostExtensionsCatalogIconResultSchema
|
|
22626
|
+
},
|
|
22570
22627
|
[HOST_EXTENSIONS_RPC.install]: {
|
|
22571
22628
|
params: external_exports.strictObject({ source: hostExtensionInstallSourceSchema }),
|
|
22572
22629
|
result: installationResult
|
|
@@ -22617,6 +22674,10 @@ var hostExtensionsRpcSchemas = {
|
|
|
22617
22674
|
params: jsonValueSchema.optional()
|
|
22618
22675
|
}),
|
|
22619
22676
|
result: external_exports.strictObject({ result: jsonValueSchema })
|
|
22677
|
+
},
|
|
22678
|
+
[HOST_EXTENSIONS_RPC.threadTree]: {
|
|
22679
|
+
params: noParams,
|
|
22680
|
+
result: threadTreeSnapshotSchema
|
|
22620
22681
|
}
|
|
22621
22682
|
};
|
|
22622
22683
|
|
|
@@ -22625,6 +22686,104 @@ var THREAD_ARCHIVE_CONFIRM_METHOD = "codexhost/thread/archive/confirm";
|
|
|
22625
22686
|
var threadArchiveConfirmParamsSchema = external_exports.object({ threadId: hostThreadIdSchema }).strict();
|
|
22626
22687
|
var threadArchiveConfirmResultSchema = external_exports.object({ confirmed: external_exports.boolean() }).strict();
|
|
22627
22688
|
|
|
22689
|
+
// packages/shared-contracts/dist/telemetry.js
|
|
22690
|
+
var PRODUCT_TELEMETRY_GET_METHOD = "codexhost/telemetry/get";
|
|
22691
|
+
var PRODUCT_TELEMETRY_SET_METHOD = "codexhost/telemetry/set";
|
|
22692
|
+
var PRODUCT_TELEMETRY_SIGNAL_METHOD = "codexhost/telemetry/signal";
|
|
22693
|
+
var TELEMETRY_SURFACES = [
|
|
22694
|
+
"codex-desktop",
|
|
22695
|
+
"web",
|
|
22696
|
+
"web-desktop-shell",
|
|
22697
|
+
"web-mobile",
|
|
22698
|
+
"ssh-remote",
|
|
22699
|
+
"cli"
|
|
22700
|
+
];
|
|
22701
|
+
var TELEMETRY_OS_LIST = ["darwin", "win32", "linux"];
|
|
22702
|
+
var TELEMETRY_ARCH_LIST = ["arm64", "x64", "ia32", "arm"];
|
|
22703
|
+
var TELEMETRY_UI_LANGUAGES = [
|
|
22704
|
+
"zh",
|
|
22705
|
+
"en",
|
|
22706
|
+
"ja",
|
|
22707
|
+
"ko",
|
|
22708
|
+
"de",
|
|
22709
|
+
"fr",
|
|
22710
|
+
"es",
|
|
22711
|
+
"pt",
|
|
22712
|
+
"ru",
|
|
22713
|
+
"other"
|
|
22714
|
+
];
|
|
22715
|
+
var TELEMETRY_OFFICIAL_HARNESSES = [
|
|
22716
|
+
"codex",
|
|
22717
|
+
"claude-code",
|
|
22718
|
+
"antigravity",
|
|
22719
|
+
"pi",
|
|
22720
|
+
"opencode",
|
|
22721
|
+
"cursor-cli",
|
|
22722
|
+
"deepseek-harness",
|
|
22723
|
+
"grok",
|
|
22724
|
+
"omp",
|
|
22725
|
+
"qwen-code",
|
|
22726
|
+
"kiro-cli",
|
|
22727
|
+
"codebuddy",
|
|
22728
|
+
"workbuddy",
|
|
22729
|
+
"devin",
|
|
22730
|
+
"hermes",
|
|
22731
|
+
"qoder",
|
|
22732
|
+
"qoder-cn",
|
|
22733
|
+
"kimi-code",
|
|
22734
|
+
"zcode",
|
|
22735
|
+
"copilot",
|
|
22736
|
+
"custom"
|
|
22737
|
+
];
|
|
22738
|
+
var TELEMETRY_REMOTE_ACCESS_CHANNELS = [
|
|
22739
|
+
"official-relay",
|
|
22740
|
+
"self-hosted-relay",
|
|
22741
|
+
"tailscale-serve",
|
|
22742
|
+
"tailscale-funnel",
|
|
22743
|
+
"tailscale-ip",
|
|
22744
|
+
"lan",
|
|
22745
|
+
"custom-proxy",
|
|
22746
|
+
"remote-peer"
|
|
22747
|
+
];
|
|
22748
|
+
var telemetryVersionSchema = external_exports.string().min(1).max(40).regex(/^[0-9A-Za-z._+-]+$/u);
|
|
22749
|
+
var telemetrySurfaceSchema = external_exports.enum(TELEMETRY_SURFACES);
|
|
22750
|
+
var telemetryUiLanguageSchema = external_exports.enum(TELEMETRY_UI_LANGUAGES);
|
|
22751
|
+
var telemetryHarnessSchema = external_exports.enum(TELEMETRY_OFFICIAL_HARNESSES);
|
|
22752
|
+
var telemetryRemoteAccessChannelSchema = external_exports.enum(TELEMETRY_REMOTE_ACCESS_CHANNELS);
|
|
22753
|
+
var officialHarnessSet = new Set(TELEMETRY_OFFICIAL_HARNESSES);
|
|
22754
|
+
var uiLanguageSet = new Set(TELEMETRY_UI_LANGUAGES);
|
|
22755
|
+
var productTelemetrySettingsSchema = external_exports.object({
|
|
22756
|
+
enabled: external_exports.boolean(),
|
|
22757
|
+
forcedOffByEnv: external_exports.boolean()
|
|
22758
|
+
}).strict();
|
|
22759
|
+
var productTelemetrySetParamsSchema = external_exports.object({
|
|
22760
|
+
enabled: external_exports.boolean()
|
|
22761
|
+
}).strict();
|
|
22762
|
+
var productTelemetrySignalParamsSchema = external_exports.object({
|
|
22763
|
+
surfaces: external_exports.array(telemetrySurfaceSchema).max(12).optional(),
|
|
22764
|
+
harnesses: external_exports.array(telemetryHarnessSchema).max(32).optional(),
|
|
22765
|
+
remoteAccess: external_exports.array(telemetryRemoteAccessChannelSchema).max(12).optional()
|
|
22766
|
+
}).strict();
|
|
22767
|
+
var productTelemetryHeartbeatSchema = external_exports.object({
|
|
22768
|
+
dailyActive: external_exports.literal(true).optional(),
|
|
22769
|
+
weeklyActive: external_exports.literal(true).optional(),
|
|
22770
|
+
monthlyActive: external_exports.literal(true).optional(),
|
|
22771
|
+
newInstall: external_exports.literal(true).optional(),
|
|
22772
|
+
retainedD1: external_exports.literal(true).optional(),
|
|
22773
|
+
retainedD7: external_exports.literal(true).optional(),
|
|
22774
|
+
remoteAny: external_exports.literal(true).optional(),
|
|
22775
|
+
appVersion: telemetryVersionSchema.optional(),
|
|
22776
|
+
codexDesktopVersion: telemetryVersionSchema.optional(),
|
|
22777
|
+
os: external_exports.enum(TELEMETRY_OS_LIST).optional(),
|
|
22778
|
+
arch: external_exports.enum(TELEMETRY_ARCH_LIST).optional(),
|
|
22779
|
+
uiLanguage: telemetryUiLanguageSchema.optional(),
|
|
22780
|
+
surfaces: external_exports.array(telemetrySurfaceSchema).min(1).max(12).optional(),
|
|
22781
|
+
harnesses: external_exports.array(telemetryHarnessSchema).min(1).max(32).optional(),
|
|
22782
|
+
remoteAccess: external_exports.array(telemetryRemoteAccessChannelSchema).min(1).max(12).optional()
|
|
22783
|
+
}).strict().refine((value) => Object.keys(value).length > 0, {
|
|
22784
|
+
message: "Telemetry heartbeat must contain at least one countable field"
|
|
22785
|
+
});
|
|
22786
|
+
|
|
22628
22787
|
// packages/shared-contracts/dist/client-channel.js
|
|
22629
22788
|
var CLIENT_CHANNEL_VERSION = 1;
|
|
22630
22789
|
var CLIENT_REQUEST_LIMIT_BYTES = 128 * 1024 * 1024;
|
|
@@ -22652,6 +22811,7 @@ var CLIENT_CHANNEL_METHODS = [
|
|
|
22652
22811
|
"thread/archive",
|
|
22653
22812
|
THREAD_ARCHIVE_CONFIRM_METHOD,
|
|
22654
22813
|
"thread/unarchive",
|
|
22814
|
+
"thread/delete",
|
|
22655
22815
|
"turn/start",
|
|
22656
22816
|
"turn/interrupt",
|
|
22657
22817
|
"turn/steer",
|
|
@@ -22710,8 +22870,14 @@ var CLIENT_CHANNEL_METHODS = [
|
|
|
22710
22870
|
"codexhost/update/check",
|
|
22711
22871
|
"codexhost/update/start",
|
|
22712
22872
|
"codexhost/update/status",
|
|
22873
|
+
"codexhost/update/macos-signing/status",
|
|
22874
|
+
"codexhost/update/macos-signing/setup",
|
|
22875
|
+
"codexhost/update/macos-signing/remove",
|
|
22713
22876
|
"codexhost/announcement/get",
|
|
22714
22877
|
"codexhost/announcement/acknowledge",
|
|
22878
|
+
PRODUCT_TELEMETRY_GET_METHOD,
|
|
22879
|
+
PRODUCT_TELEMETRY_SET_METHOD,
|
|
22880
|
+
PRODUCT_TELEMETRY_SIGNAL_METHOD,
|
|
22715
22881
|
"codexhost/sessions/loaded/list"
|
|
22716
22882
|
];
|
|
22717
22883
|
var clientThreadSectionsSchema = external_exports.object({
|
|
@@ -22748,7 +22914,10 @@ var clientWorkspaceSnapshotSchema = external_exports.object({
|
|
|
22748
22914
|
pinned: external_exports.array(external_exports.string()),
|
|
22749
22915
|
/** Projects Desktop placed in each custom section, keyed by the official section ID, in
|
|
22750
22916
|
* Desktop's section order. Omitted when no section holds a project. */
|
|
22751
|
-
sectionProjects: external_exports.record(external_exports.string(), external_exports.array(external_exports.string())).optional()
|
|
22917
|
+
sectionProjects: external_exports.record(external_exports.string(), external_exports.array(external_exports.string())).optional(),
|
|
22918
|
+
/** Projects pinned in Codex Desktop (`pinned-project-ids`), in Desktop order.
|
|
22919
|
+
* Omitted when Desktop global state has no `pinned-project-ids` array. */
|
|
22920
|
+
pinnedProjects: external_exports.array(external_exports.string()).optional()
|
|
22752
22921
|
});
|
|
22753
22922
|
var record2 = external_exports.record(external_exports.string(), external_exports.unknown());
|
|
22754
22923
|
var clientChannelCursorSchema = external_exports.object({
|
|
@@ -22896,6 +23065,8 @@ var clientThreadSnapshotSchema = external_exports.object({
|
|
|
22896
23065
|
modelProvider: external_exports.string().min(1),
|
|
22897
23066
|
createdAt: external_exports.number(),
|
|
22898
23067
|
updatedAt: external_exports.number(),
|
|
23068
|
+
/** Last conversation activity in Unix seconds, distinct from metadata writes. */
|
|
23069
|
+
recencyAt: external_exports.number().nullable().optional(),
|
|
22899
23070
|
status: external_exports.object({ type: external_exports.string() }).passthrough(),
|
|
22900
23071
|
name: external_exports.string().nullable().optional(),
|
|
22901
23072
|
preview: external_exports.string().optional(),
|
|
@@ -22974,27 +23145,33 @@ var threadCatalogReadResultSchema = external_exports.object({
|
|
|
22974
23145
|
officialCursor: external_exports.object({ live: external_exports.string().nullable(), archived: external_exports.string().nullable().optional() }).strict().optional()
|
|
22975
23146
|
}).strict();
|
|
22976
23147
|
|
|
22977
|
-
// packages/shared-contracts/dist/
|
|
22978
|
-
var
|
|
22979
|
-
|
|
22980
|
-
|
|
22981
|
-
|
|
22982
|
-
|
|
22983
|
-
|
|
22984
|
-
|
|
22985
|
-
|
|
22986
|
-
|
|
23148
|
+
// packages/shared-contracts/dist/extension-services.js
|
|
23149
|
+
var extensionHarnessPresentationSchema = harnessPluginDescriptorSchema.pick({
|
|
23150
|
+
id: true,
|
|
23151
|
+
name: true,
|
|
23152
|
+
icon: true,
|
|
23153
|
+
iconStyle: true
|
|
23154
|
+
});
|
|
23155
|
+
var extensionActivitySessionSchema = external_exports.strictObject({
|
|
23156
|
+
threadId: external_exports.string().max(1024),
|
|
23157
|
+
title: external_exports.string().max(240),
|
|
23158
|
+
project: external_exports.string().max(240),
|
|
23159
|
+
harness: external_exports.strictObject({ id: external_exports.string().min(1).max(128), name: external_exports.string().min(1).max(128) }).optional(),
|
|
23160
|
+
state: external_exports.enum(["idle", "running", "waiting", "completed", "failed"]),
|
|
23161
|
+
updatedAt: external_exports.number().nonnegative()
|
|
23162
|
+
});
|
|
23163
|
+
var extensionActivitySchema = external_exports.strictObject({
|
|
23164
|
+
epoch: external_exports.string().max(128),
|
|
22987
23165
|
revision: external_exports.int().nonnegative(),
|
|
22988
|
-
|
|
22989
|
-
|
|
22990
|
-
|
|
22991
|
-
|
|
22992
|
-
|
|
22993
|
-
|
|
22994
|
-
|
|
22995
|
-
|
|
22996
|
-
|
|
22997
|
-
snapshot: threadTreeSnapshotSchema
|
|
23166
|
+
running: external_exports.int().nonnegative(),
|
|
23167
|
+
waiting: external_exports.int().nonnegative(),
|
|
23168
|
+
sessions: external_exports.array(extensionActivitySessionSchema).max(32).default([]),
|
|
23169
|
+
notifications: external_exports.array(external_exports.strictObject({
|
|
23170
|
+
threadId: external_exports.string().max(1024),
|
|
23171
|
+
key: external_exports.string().max(4096),
|
|
23172
|
+
kind: external_exports.enum(["completed", "failed", "approval", "question"]),
|
|
23173
|
+
revision: external_exports.int().nonnegative()
|
|
23174
|
+
})).max(256)
|
|
22998
23175
|
});
|
|
22999
23176
|
|
|
23000
23177
|
// packages/shared-contracts/dist/voice.js
|
|
@@ -23201,6 +23378,7 @@ var remotePeerSummarySchema = external_exports.object({
|
|
|
23201
23378
|
updatedAt: external_exports.string()
|
|
23202
23379
|
});
|
|
23203
23380
|
var remotePeerListResultSchema = external_exports.object({
|
|
23381
|
+
localPlatform: external_exports.string().max(64).optional(),
|
|
23204
23382
|
peers: external_exports.array(remotePeerSummarySchema)
|
|
23205
23383
|
});
|
|
23206
23384
|
var remotePeerAddParamsSchema = external_exports.object({
|
|
@@ -23954,7 +24132,10 @@ var CONSOLE_HOST_METHODS = Object.freeze([
|
|
|
23954
24132
|
"codexhost/usage/statistics/get",
|
|
23955
24133
|
"codexhost/update/check",
|
|
23956
24134
|
"codexhost/update/start",
|
|
23957
|
-
"codexhost/update/status"
|
|
24135
|
+
"codexhost/update/status",
|
|
24136
|
+
"codexhost/update/macos-signing/status",
|
|
24137
|
+
"codexhost/update/macos-signing/setup",
|
|
24138
|
+
"codexhost/update/macos-signing/remove"
|
|
23958
24139
|
]);
|
|
23959
24140
|
function isConsoleHostMethod(method) {
|
|
23960
24141
|
return CONSOLE_HOST_METHODS.includes(method);
|
|
@@ -24400,7 +24581,15 @@ var updateStatusSchema = external_exports.strictObject({
|
|
|
24400
24581
|
});
|
|
24401
24582
|
var updateEmptyParamsSchema = external_exports.strictObject({});
|
|
24402
24583
|
var githubReleaseNotesUrlSchema = external_exports.string().max(300).regex(/^https:\/\/github\.com\/BytePioneer-AI\/codex-host\/releases\/tag\/v[0-9A-Za-z.+-]+$/u, "release notes URL must identify a codexhost GitHub Release");
|
|
24403
|
-
var
|
|
24584
|
+
var updateBackgroundPhaseSchema = external_exports.enum(["idle", "downloading", "ready", "failed"]);
|
|
24585
|
+
var updateBackgroundDownloadSchema = external_exports.strictObject({
|
|
24586
|
+
downloadedBytes: external_exports.number().int().nonnegative(),
|
|
24587
|
+
totalBytes: external_exports.number().int().positive()
|
|
24588
|
+
}).refine((progress) => progress.downloadedBytes <= progress.totalBytes, {
|
|
24589
|
+
path: ["downloadedBytes"],
|
|
24590
|
+
message: "downloadedBytes must not exceed totalBytes"
|
|
24591
|
+
});
|
|
24592
|
+
var updateCheckResultSchema = external_exports.object({
|
|
24404
24593
|
currentVersion: updateSemanticVersionSchema,
|
|
24405
24594
|
installation: updateInstallationSchema.nullable(),
|
|
24406
24595
|
latestVersion: updateSemanticVersionSchema.nullable(),
|
|
@@ -24409,7 +24598,12 @@ var updateCheckResultSchema = external_exports.strictObject({
|
|
|
24409
24598
|
releaseNotes: external_exports.string().min(1).max(2e4).nullable(),
|
|
24410
24599
|
releaseNotesUrl: githubReleaseNotesUrlSchema.nullable(),
|
|
24411
24600
|
status: updateStatusSchema.nullable(),
|
|
24412
|
-
error: external_exports.string().min(1).max(UPDATE_ERROR_MAX_LENGTH).nullable()
|
|
24601
|
+
error: external_exports.string().min(1).max(UPDATE_ERROR_MAX_LENGTH).nullable(),
|
|
24602
|
+
stagedVersion: updateSemanticVersionSchema.nullable().optional(),
|
|
24603
|
+
backgroundPhase: updateBackgroundPhaseSchema.optional(),
|
|
24604
|
+
backgroundDownload: updateBackgroundDownloadSchema.nullable().optional(),
|
|
24605
|
+
backgroundError: external_exports.string().min(1).max(UPDATE_ERROR_MAX_LENGTH).nullable().optional(),
|
|
24606
|
+
runningTaskCount: external_exports.number().int().nonnegative().optional()
|
|
24413
24607
|
});
|
|
24414
24608
|
var updateStartResultSchema = external_exports.strictObject({
|
|
24415
24609
|
status: updateStatusSchema
|
|
@@ -24417,6 +24611,15 @@ var updateStartResultSchema = external_exports.strictObject({
|
|
|
24417
24611
|
var updateStatusResultSchema = external_exports.strictObject({
|
|
24418
24612
|
status: updateStatusSchema.nullable()
|
|
24419
24613
|
});
|
|
24614
|
+
var macosLocalSigningStatusSchema = external_exports.strictObject({
|
|
24615
|
+
supported: external_exports.boolean(),
|
|
24616
|
+
enabled: external_exports.boolean(),
|
|
24617
|
+
certificatePresent: external_exports.boolean(),
|
|
24618
|
+
appSignedWithLocalCert: external_exports.boolean(),
|
|
24619
|
+
appPath: external_exports.string().min(1).nullable(),
|
|
24620
|
+
certificateName: external_exports.string().min(1),
|
|
24621
|
+
certificateSha1: external_exports.string().regex(/^[0-9A-Fa-f]{40}$/u).nullable()
|
|
24622
|
+
});
|
|
24420
24623
|
|
|
24421
24624
|
// packages/shared-contracts/dist/release-announcement.js
|
|
24422
24625
|
var RELEASE_ANNOUNCEMENT_MAX_THEMES = 12;
|
|
@@ -24767,6 +24970,7 @@ function parseUpdateStatus(value) {
|
|
|
24767
24970
|
}
|
|
24768
24971
|
|
|
24769
24972
|
// packages/update-manager/dist/distribution.js
|
|
24973
|
+
var PLATFORM_PACKAGE_PATTERN = /^cli-[a-z0-9-]+$/u;
|
|
24770
24974
|
var UPDATE_RUNTIME_ENV = Object.freeze({
|
|
24771
24975
|
launcherPid: "CODEXHOST_LAUNCHER_PID",
|
|
24772
24976
|
launcherExecutable: "CODEXHOST_LAUNCHER_EXECUTABLE",
|
|
@@ -24808,6 +25012,173 @@ function parseDistributionMetadata(value) {
|
|
|
24808
25012
|
target: metadata.target
|
|
24809
25013
|
};
|
|
24810
25014
|
}
|
|
25015
|
+
function explicitAbsoluteEnvironmentPath(environment, name) {
|
|
25016
|
+
const value = environment[name];
|
|
25017
|
+
if (value === void 0)
|
|
25018
|
+
return void 0;
|
|
25019
|
+
if (!value || !path.isAbsolute(value))
|
|
25020
|
+
throw new Error(`${name} must be an absolute path`);
|
|
25021
|
+
return path.normalize(value);
|
|
25022
|
+
}
|
|
25023
|
+
function npmPackageLayout(packageRoot) {
|
|
25024
|
+
const scopeDirectory = path.dirname(packageRoot);
|
|
25025
|
+
if (path.basename(scopeDirectory) !== "@codexhost" || !PLATFORM_PACKAGE_PATTERN.test(path.basename(packageRoot))) {
|
|
25026
|
+
return null;
|
|
25027
|
+
}
|
|
25028
|
+
const parentModules = path.dirname(scopeDirectory);
|
|
25029
|
+
const cliPackage = path.dirname(parentModules);
|
|
25030
|
+
const outerScope = path.dirname(cliPackage);
|
|
25031
|
+
if (path.basename(parentModules) === "node_modules" && path.basename(cliPackage) === "cli" && path.basename(outerScope) === "@codexhost") {
|
|
25032
|
+
return {
|
|
25033
|
+
launcherCandidate: path.join(cliPackage, "bin", "codexhost.js"),
|
|
25034
|
+
globalModulesRoot: path.dirname(outerScope)
|
|
25035
|
+
};
|
|
25036
|
+
}
|
|
25037
|
+
return {
|
|
25038
|
+
launcherCandidate: path.resolve(packageRoot, "../cli/bin/codexhost.js"),
|
|
25039
|
+
globalModulesRoot: parentModules
|
|
25040
|
+
};
|
|
25041
|
+
}
|
|
25042
|
+
async function resolveRegularFile(candidate) {
|
|
25043
|
+
if (!candidate || !path.isAbsolute(candidate))
|
|
25044
|
+
return null;
|
|
25045
|
+
try {
|
|
25046
|
+
const resolved = await realpath(candidate);
|
|
25047
|
+
const metadata = await lstat(resolved);
|
|
25048
|
+
return metadata.isFile() && !metadata.isSymbolicLink() ? resolved : null;
|
|
25049
|
+
} catch {
|
|
25050
|
+
return null;
|
|
25051
|
+
}
|
|
25052
|
+
}
|
|
25053
|
+
async function firstRegularFile(candidates, predicate) {
|
|
25054
|
+
for (const candidate of candidates) {
|
|
25055
|
+
const resolved = await resolveRegularFile(candidate);
|
|
25056
|
+
if (resolved && (!predicate || predicate(resolved)))
|
|
25057
|
+
return resolved;
|
|
25058
|
+
}
|
|
25059
|
+
return null;
|
|
25060
|
+
}
|
|
25061
|
+
function discoverNpmNodePath(globalModulesRoot, platform, nodeExecutable) {
|
|
25062
|
+
const candidates = [];
|
|
25063
|
+
if (path.basename(globalModulesRoot) === "node_modules") {
|
|
25064
|
+
const modulesParent = path.dirname(globalModulesRoot);
|
|
25065
|
+
if (platform === "win32") {
|
|
25066
|
+
candidates.push(path.join(modulesParent, "node.exe"));
|
|
25067
|
+
} else if (path.basename(modulesParent) === "lib") {
|
|
25068
|
+
candidates.push(path.join(path.dirname(modulesParent), "bin", "node"));
|
|
25069
|
+
}
|
|
25070
|
+
}
|
|
25071
|
+
candidates.push(nodeExecutable);
|
|
25072
|
+
return firstRegularFile(candidates);
|
|
25073
|
+
}
|
|
25074
|
+
function homebrewNpmCliCandidates(nodePath, environment) {
|
|
25075
|
+
const candidates = [];
|
|
25076
|
+
const segments = nodePath.split(path.sep);
|
|
25077
|
+
const cellarIndex = segments.lastIndexOf("Cellar");
|
|
25078
|
+
if (cellarIndex >= 1 && segments[cellarIndex + 1]?.startsWith("node") && segments.at(-2) === "bin" && segments.at(-1) === "node") {
|
|
25079
|
+
const brewPrefix = segments.slice(0, cellarIndex).join(path.sep);
|
|
25080
|
+
candidates.push(path.join(brewPrefix, "lib", "node_modules", "npm", "bin", "npm-cli.js"), path.join(path.dirname(path.dirname(nodePath)), "libexec", "lib", "node_modules", "npm", "bin", "npm-cli.js"));
|
|
25081
|
+
}
|
|
25082
|
+
if (environment.HOMEBREW_PREFIX && path.isAbsolute(environment.HOMEBREW_PREFIX)) {
|
|
25083
|
+
candidates.push(path.join(environment.HOMEBREW_PREFIX, "lib", "node_modules", "npm", "bin", "npm-cli.js"));
|
|
25084
|
+
}
|
|
25085
|
+
return candidates;
|
|
25086
|
+
}
|
|
25087
|
+
async function discoverNpmCliPath(globalModulesRoot, nodePath, environment, platform) {
|
|
25088
|
+
const candidates = [];
|
|
25089
|
+
if (path.basename(globalModulesRoot) === "node_modules") {
|
|
25090
|
+
candidates.push(path.join(globalModulesRoot, "npm", "bin", "npm-cli.js"));
|
|
25091
|
+
}
|
|
25092
|
+
candidates.push(platform === "win32" ? path.join(path.dirname(nodePath), "node_modules", "npm", "bin", "npm-cli.js") : path.join(path.dirname(path.dirname(nodePath)), "lib", "node_modules", "npm", "bin", "npm-cli.js"));
|
|
25093
|
+
if (platform !== "win32") {
|
|
25094
|
+
candidates.push(...homebrewNpmCliCandidates(nodePath, environment));
|
|
25095
|
+
}
|
|
25096
|
+
if (environment.npm_execpath) {
|
|
25097
|
+
candidates.push(environment.npm_execpath);
|
|
25098
|
+
}
|
|
25099
|
+
for (const directory of (environment.PATH ?? environment.Path ?? "").split(path.delimiter)) {
|
|
25100
|
+
if (!directory || !path.isAbsolute(directory))
|
|
25101
|
+
continue;
|
|
25102
|
+
if (platform === "win32") {
|
|
25103
|
+
candidates.push(path.join(directory, "node_modules", "npm", "bin", "npm-cli.js"));
|
|
25104
|
+
const shim = await resolveRegularFile(path.join(directory, "npm.cmd"));
|
|
25105
|
+
if (shim && path.dirname(shim) !== directory) {
|
|
25106
|
+
candidates.push(path.join(path.dirname(shim), "node_modules", "npm", "bin", "npm-cli.js"));
|
|
25107
|
+
}
|
|
25108
|
+
} else {
|
|
25109
|
+
candidates.push(path.join(directory, "npm"));
|
|
25110
|
+
}
|
|
25111
|
+
}
|
|
25112
|
+
return firstRegularFile(candidates, (resolved) => {
|
|
25113
|
+
const name = path.basename(resolved);
|
|
25114
|
+
return (platform === "win32" ? name.toLowerCase() : name) === "npm-cli.js";
|
|
25115
|
+
});
|
|
25116
|
+
}
|
|
25117
|
+
function ordinaryWindowsPath(value) {
|
|
25118
|
+
return value.replace(/^\\\\\?\\UNC\\/iu, "\\\\").replace(/^\\\\\?\\(?=[a-z]:[\\/])/iu, "");
|
|
25119
|
+
}
|
|
25120
|
+
async function canonicalWindowsNpmPackageRoot(root) {
|
|
25121
|
+
const ordinaryPath = ordinaryWindowsPath(root);
|
|
25122
|
+
const metadata = await lstat(ordinaryPath);
|
|
25123
|
+
if (metadata.isSymbolicLink()) {
|
|
25124
|
+
throw new Error("The npm platform package is a link or junction; update it manually with npm");
|
|
25125
|
+
}
|
|
25126
|
+
return realpath(ordinaryPath);
|
|
25127
|
+
}
|
|
25128
|
+
async function resolveNpmRuntimePaths(options) {
|
|
25129
|
+
const environment = options.environment ?? process.env;
|
|
25130
|
+
const platform = options.platform ?? process.platform;
|
|
25131
|
+
if (!path.isAbsolute(options.packageRoot)) {
|
|
25132
|
+
throw new Error("npm platform package root must be an absolute path");
|
|
25133
|
+
}
|
|
25134
|
+
const resourcesRoot = path.normalize(options.packageRoot);
|
|
25135
|
+
const explicitNodePath = explicitAbsoluteEnvironmentPath(environment, UPDATE_RUNTIME_ENV.npmNodePath);
|
|
25136
|
+
const explicitNpmCliPath = explicitAbsoluteEnvironmentPath(environment, UPDATE_RUNTIME_ENV.npmCliPath);
|
|
25137
|
+
const explicitLauncherPath = explicitAbsoluteEnvironmentPath(environment, UPDATE_RUNTIME_ENV.npmLauncherPath);
|
|
25138
|
+
const explicitPackageRoot = explicitAbsoluteEnvironmentPath(environment, UPDATE_RUNTIME_ENV.npmPackageRoot);
|
|
25139
|
+
const windows = platform === "win32" && process.platform === "win32";
|
|
25140
|
+
const ordinaryPackageRoot = windows ? ordinaryWindowsPath(resourcesRoot) : resourcesRoot;
|
|
25141
|
+
const canonicalPackageRoot = windows ? await canonicalWindowsNpmPackageRoot(resourcesRoot) : resourcesRoot;
|
|
25142
|
+
const canonicalConfiguredRoot = windows && explicitPackageRoot !== void 0 ? await canonicalWindowsNpmPackageRoot(explicitPackageRoot) : explicitPackageRoot;
|
|
25143
|
+
if (canonicalConfiguredRoot !== void 0 && canonicalConfiguredRoot !== canonicalPackageRoot) {
|
|
25144
|
+
throw new Error("npm platform package root does not own the Host Runtime");
|
|
25145
|
+
}
|
|
25146
|
+
if (explicitNodePath !== void 0 && explicitNpmCliPath !== void 0 && explicitLauncherPath !== void 0 && explicitPackageRoot !== void 0) {
|
|
25147
|
+
return {
|
|
25148
|
+
nodePath: explicitNodePath,
|
|
25149
|
+
npmCliPath: explicitNpmCliPath,
|
|
25150
|
+
npmLauncherPath: explicitLauncherPath,
|
|
25151
|
+
packageRoot: ordinaryPackageRoot
|
|
25152
|
+
};
|
|
25153
|
+
}
|
|
25154
|
+
const packageRoot = canonicalPackageRoot;
|
|
25155
|
+
const layout = npmPackageLayout(packageRoot);
|
|
25156
|
+
if (!layout) {
|
|
25157
|
+
if (explicitNodePath === void 0) {
|
|
25158
|
+
throw new Error(`${UPDATE_RUNTIME_ENV.npmNodePath} must be an absolute path`);
|
|
25159
|
+
}
|
|
25160
|
+
if (explicitNpmCliPath === void 0) {
|
|
25161
|
+
throw new Error(`${UPDATE_RUNTIME_ENV.npmCliPath} must be an absolute path`);
|
|
25162
|
+
}
|
|
25163
|
+
if (explicitLauncherPath === void 0) {
|
|
25164
|
+
throw new Error(`${UPDATE_RUNTIME_ENV.npmLauncherPath} must be an absolute path`);
|
|
25165
|
+
}
|
|
25166
|
+
throw new Error(`${UPDATE_RUNTIME_ENV.npmPackageRoot} must be an absolute path`);
|
|
25167
|
+
}
|
|
25168
|
+
const nodePath = explicitNodePath ?? await discoverNpmNodePath(layout.globalModulesRoot, platform, options.nodeExecutable ?? process.execPath);
|
|
25169
|
+
if (!nodePath) {
|
|
25170
|
+
throw new Error(`${UPDATE_RUNTIME_ENV.npmNodePath} must be an absolute path`);
|
|
25171
|
+
}
|
|
25172
|
+
const npmCliPath = explicitNpmCliPath ?? await discoverNpmCliPath(layout.globalModulesRoot, nodePath, environment, platform);
|
|
25173
|
+
if (!npmCliPath) {
|
|
25174
|
+
throw new Error(platform === "win32" ? "Cannot find npm-cli.js beside Node.js or npm.cmd; reinstall npm or set CODEXHOST_NPM_CLI_PATH to npm-cli.js" : `${UPDATE_RUNTIME_ENV.npmCliPath} must be an absolute path`);
|
|
25175
|
+
}
|
|
25176
|
+
const npmLauncherPath = explicitLauncherPath ?? await resolveRegularFile(layout.launcherCandidate);
|
|
25177
|
+
if (!npmLauncherPath) {
|
|
25178
|
+
throw new Error(`${UPDATE_RUNTIME_ENV.npmLauncherPath} must be an absolute path`);
|
|
25179
|
+
}
|
|
25180
|
+
return { nodePath, npmCliPath, npmLauncherPath, packageRoot };
|
|
25181
|
+
}
|
|
24811
25182
|
function defaultUpdateStateDirectory(platform = process.platform, environment = process.env) {
|
|
24812
25183
|
if (platform === "win32") {
|
|
24813
25184
|
const root = environment.LOCALAPPDATA;
|
|
@@ -24825,11 +25196,11 @@ function defaultUpdateStateDirectory(platform = process.platform, environment =
|
|
|
24825
25196
|
async function readRuntimeMetadata(entryPath2, environment = process.env) {
|
|
24826
25197
|
const directory = path2.dirname(entryPath2);
|
|
24827
25198
|
try {
|
|
24828
|
-
return parseDistributionMetadata(JSON.parse(await
|
|
25199
|
+
return parseDistributionMetadata(JSON.parse(await readFile2(path2.join(directory, "codexhost-distribution.json"), "utf8")));
|
|
24829
25200
|
} catch (error62) {
|
|
24830
25201
|
if (path2.basename(directory) !== "dist" || path2.basename(path2.resolve(directory, "../..")) !== "packages")
|
|
24831
25202
|
throw error62;
|
|
24832
|
-
const workspace = JSON.parse(await
|
|
25203
|
+
const workspace = JSON.parse(await readFile2(path2.resolve(directory, "../../../package.json"), "utf8"));
|
|
24833
25204
|
if (workspace.name !== "codexhost" || typeof workspace.version !== "string")
|
|
24834
25205
|
throw error62;
|
|
24835
25206
|
const workspaceVersion = requireSemanticVersion(workspace.version);
|
|
@@ -24886,20 +25257,40 @@ function parseLatestGitHubRelease(value) {
|
|
|
24886
25257
|
assets: Object.freeze(release.assets.map(releaseAsset))
|
|
24887
25258
|
});
|
|
24888
25259
|
}
|
|
24889
|
-
async function
|
|
25260
|
+
async function fetchLatestGitHubReleaseConditional(options = {}) {
|
|
24890
25261
|
const response = await requestGitHubRelease(CODEXHOST_LATEST_RELEASE_URL, options);
|
|
25262
|
+
const etag = response.headers.get("etag") ?? options.etag ?? null;
|
|
25263
|
+
if (response.status === 304) {
|
|
25264
|
+
options.onEtag?.(etag);
|
|
25265
|
+
return { status: "not-modified", etag };
|
|
25266
|
+
}
|
|
24891
25267
|
if (!response.ok)
|
|
24892
25268
|
throw new Error(`GitHub latest Release request failed with HTTP ${response.status}`);
|
|
24893
|
-
|
|
25269
|
+
const release = parseLatestGitHubRelease(await response.json());
|
|
25270
|
+
options.onEtag?.(response.headers.get("etag"));
|
|
25271
|
+
return { status: "modified", release, etag: response.headers.get("etag") };
|
|
25272
|
+
}
|
|
25273
|
+
async function fetchLatestGitHubRelease(options = {}) {
|
|
25274
|
+
const result = await fetchLatestGitHubReleaseConditional(options);
|
|
25275
|
+
if (result.status === "not-modified") {
|
|
25276
|
+
if (options.cachedRelease)
|
|
25277
|
+
return options.cachedRelease;
|
|
25278
|
+
throw new Error("GitHub latest Release returned HTTP 304 without a cached release");
|
|
25279
|
+
}
|
|
25280
|
+
return result.release;
|
|
24894
25281
|
}
|
|
24895
25282
|
function requestGitHubRelease(url2, options) {
|
|
24896
25283
|
const fetchImpl = options.fetch ?? fetch;
|
|
25284
|
+
const headers = {
|
|
25285
|
+
accept: "application/vnd.github+json",
|
|
25286
|
+
"user-agent": "codexhost-updater",
|
|
25287
|
+
"x-github-api-version": "2022-11-28"
|
|
25288
|
+
};
|
|
25289
|
+
if (options.etag) {
|
|
25290
|
+
headers["if-none-match"] = options.etag;
|
|
25291
|
+
}
|
|
24897
25292
|
return fetchImpl(url2, {
|
|
24898
|
-
headers
|
|
24899
|
-
accept: "application/vnd.github+json",
|
|
24900
|
-
"user-agent": "codexhost-updater",
|
|
24901
|
-
"x-github-api-version": "2022-11-28"
|
|
24902
|
-
},
|
|
25293
|
+
headers,
|
|
24903
25294
|
redirect: "error",
|
|
24904
25295
|
...options.signal ? { signal: options.signal } : {}
|
|
24905
25296
|
});
|
|
@@ -24975,8 +25366,107 @@ function selectInstallerReleaseArtifact(release, target2) {
|
|
|
24975
25366
|
});
|
|
24976
25367
|
}
|
|
24977
25368
|
|
|
25369
|
+
// packages/update-manager/dist/staging.js
|
|
25370
|
+
import { randomUUID } from "node:crypto";
|
|
25371
|
+
import { link, lstat as lstat3, mkdir, open as open3, readdir, readFile as readFile3, realpath as realpath2, rename, rm, rmdir, writeFile } from "node:fs/promises";
|
|
25372
|
+
import path4 from "node:path";
|
|
25373
|
+
|
|
25374
|
+
// packages/update-manager/dist/artifact.js
|
|
25375
|
+
import { createHash } from "node:crypto";
|
|
25376
|
+
import { createReadStream } from "node:fs";
|
|
25377
|
+
import { lstat as lstat2, open as open2 } from "node:fs/promises";
|
|
25378
|
+
var MAX_ARTIFACT_BYTES = 2 * 1024 * 1024 * 1024;
|
|
25379
|
+
var SHA256_PATTERN = /^[0-9a-f]{64}$/u;
|
|
25380
|
+
function validateArtifact(source) {
|
|
25381
|
+
const url2 = new URL(source.url);
|
|
25382
|
+
if (url2.protocol !== "https:" || url2.username || url2.password) {
|
|
25383
|
+
throw new Error("update artifact URL must use HTTPS without credentials");
|
|
25384
|
+
}
|
|
25385
|
+
if (!SHA256_PATTERN.test(source.sha256)) {
|
|
25386
|
+
throw new Error("update artifact SHA-256 must be lowercase hexadecimal");
|
|
25387
|
+
}
|
|
25388
|
+
if (source.size !== void 0 && (!Number.isSafeInteger(source.size) || source.size <= 0 || source.size > MAX_ARTIFACT_BYTES)) {
|
|
25389
|
+
throw new Error(`update artifact size must be between 1 and ${MAX_ARTIFACT_BYTES} bytes`);
|
|
25390
|
+
}
|
|
25391
|
+
return source;
|
|
25392
|
+
}
|
|
25393
|
+
async function writeChunk(file2, chunk) {
|
|
25394
|
+
let offset = 0;
|
|
25395
|
+
while (offset < chunk.byteLength) {
|
|
25396
|
+
const result = await file2.write(chunk, offset, chunk.byteLength - offset, null);
|
|
25397
|
+
if (result.bytesWritten === 0)
|
|
25398
|
+
throw new Error("update artifact write made no progress");
|
|
25399
|
+
offset += result.bytesWritten;
|
|
25400
|
+
}
|
|
25401
|
+
}
|
|
25402
|
+
async function downloadArtifact(source, destination, onProgress) {
|
|
25403
|
+
const response = await fetch(source.url, {
|
|
25404
|
+
redirect: "follow",
|
|
25405
|
+
headers: { "accept-encoding": "identity" }
|
|
25406
|
+
});
|
|
25407
|
+
if (!response.ok || response.body === null) {
|
|
25408
|
+
throw new Error(`update artifact download failed with HTTP ${response.status}`);
|
|
25409
|
+
}
|
|
25410
|
+
const finalUrl = new URL(response.url);
|
|
25411
|
+
if (finalUrl.protocol !== "https:" || finalUrl.username || finalUrl.password) {
|
|
25412
|
+
throw new Error("update artifact redirected to a non-HTTPS URL");
|
|
25413
|
+
}
|
|
25414
|
+
const file2 = await open2(destination, "wx", 384);
|
|
25415
|
+
let bytes = 0;
|
|
25416
|
+
try {
|
|
25417
|
+
const reader = response.body.getReader();
|
|
25418
|
+
while (true) {
|
|
25419
|
+
const item = await reader.read();
|
|
25420
|
+
if (item.done)
|
|
25421
|
+
break;
|
|
25422
|
+
bytes += item.value.byteLength;
|
|
25423
|
+
if (bytes > MAX_ARTIFACT_BYTES) {
|
|
25424
|
+
await reader.cancel();
|
|
25425
|
+
throw new Error(`update artifact exceeds ${MAX_ARTIFACT_BYTES} bytes`);
|
|
25426
|
+
}
|
|
25427
|
+
await writeChunk(file2, item.value);
|
|
25428
|
+
await onProgress?.({ downloadedBytes: bytes, totalBytes: source.size });
|
|
25429
|
+
}
|
|
25430
|
+
await file2.sync();
|
|
25431
|
+
} finally {
|
|
25432
|
+
await file2.close();
|
|
25433
|
+
}
|
|
25434
|
+
return { bytes, finalUrl: finalUrl.toString() };
|
|
25435
|
+
}
|
|
25436
|
+
async function sha256File(filePath2) {
|
|
25437
|
+
const hash2 = createHash("sha256");
|
|
25438
|
+
await new Promise((resolve, reject) => {
|
|
25439
|
+
const stream = createReadStream(filePath2);
|
|
25440
|
+
stream.on("data", (chunk) => hash2.update(chunk));
|
|
25441
|
+
stream.once("error", reject);
|
|
25442
|
+
stream.once("end", resolve);
|
|
25443
|
+
});
|
|
25444
|
+
return hash2.digest("hex");
|
|
25445
|
+
}
|
|
25446
|
+
async function verifyArtifactFile(source, filePath2) {
|
|
25447
|
+
const metadata = await lstat2(filePath2);
|
|
25448
|
+
if (!metadata.isFile() || metadata.isSymbolicLink() || metadata.size === 0) {
|
|
25449
|
+
throw new Error("downloaded update artifact is not a non-empty regular file");
|
|
25450
|
+
}
|
|
25451
|
+
if (source.size !== void 0 && metadata.size !== source.size) {
|
|
25452
|
+
throw new Error(`update artifact size mismatch: expected ${source.size}, got ${metadata.size}`);
|
|
25453
|
+
}
|
|
25454
|
+
const actual = await sha256File(filePath2);
|
|
25455
|
+
if (actual !== source.sha256) {
|
|
25456
|
+
throw new Error(`update artifact SHA-256 mismatch: expected ${source.sha256}, got ${actual}`);
|
|
25457
|
+
}
|
|
25458
|
+
return metadata.size;
|
|
25459
|
+
}
|
|
25460
|
+
async function verifyDownloadedArtifact(source, filePath2, result) {
|
|
25461
|
+
const actualSize = await verifyArtifactFile(source, filePath2);
|
|
25462
|
+
if (actualSize !== result.bytes) {
|
|
25463
|
+
throw new Error("downloaded update artifact size changed after download");
|
|
25464
|
+
}
|
|
25465
|
+
}
|
|
25466
|
+
|
|
24978
25467
|
// packages/update-manager/dist/npm-registry.js
|
|
24979
25468
|
import { execFile } from "node:child_process";
|
|
25469
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
24980
25470
|
import path3 from "node:path";
|
|
24981
25471
|
var CLI_PACKAGE = "@codexhost/cli";
|
|
24982
25472
|
var VIEW_TIMEOUT_MS = 3e4;
|
|
@@ -24989,16 +25479,68 @@ function npmReleasePackages(packageRoot, version2) {
|
|
|
24989
25479
|
return [`${CLI_PACKAGE}@${version2}`, `@codexhost/${name}@${version2}`];
|
|
24990
25480
|
}
|
|
24991
25481
|
var runNpmCommand = (target2, arguments_, timeoutMs) => new Promise((resolve) => {
|
|
24992
|
-
|
|
25482
|
+
const overrides = {
|
|
25483
|
+
...target2.configuration,
|
|
25484
|
+
npm_config_update_notifier: "false",
|
|
25485
|
+
npm_config_fund: "false"
|
|
25486
|
+
};
|
|
25487
|
+
const inherited = Object.fromEntries(Object.entries(process.env).filter(([key]) => !Object.hasOwn(overrides, key.toLowerCase())));
|
|
25488
|
+
execFile(target2.nodePath, [target2.npmCliPath, "--global", ...arguments_], {
|
|
25489
|
+
cwd: path3.dirname(target2.npmCliPath),
|
|
24993
25490
|
timeout: timeoutMs,
|
|
24994
25491
|
maxBuffer: 4 * 1024 * 1024,
|
|
24995
25492
|
windowsHide: true,
|
|
24996
|
-
env: { ...
|
|
25493
|
+
env: { ...inherited, ...overrides }
|
|
24997
25494
|
}, (error62, stdout, stderr) => {
|
|
24998
25495
|
const code = error62 ? typeof error62.code === "number" ? error62.code : null : 0;
|
|
24999
25496
|
resolve({ code, stdout: String(stdout), stderr: String(stderr) });
|
|
25000
25497
|
});
|
|
25001
25498
|
});
|
|
25499
|
+
var npmConfigurationKeys = ["registry", "cache", "prefix", "@codexhost:registry"];
|
|
25500
|
+
async function resolveNpmConfiguration(target2, run2 = runNpmCommand) {
|
|
25501
|
+
const result = await run2(target2, ["config", "get", ...npmConfigurationKeys], VIEW_TIMEOUT_MS);
|
|
25502
|
+
const configuration = result.stdout.trim().replaceAll("\r\n", "\n");
|
|
25503
|
+
const lines = configuration.split("\n");
|
|
25504
|
+
const values = npmConfigurationKeys.map((key) => {
|
|
25505
|
+
const line = lines.find((item) => item.startsWith(key + "="));
|
|
25506
|
+
return line?.slice(key.length + 1);
|
|
25507
|
+
});
|
|
25508
|
+
const [registry2, cache2, prefix, scopedRegistry] = values;
|
|
25509
|
+
if (result.code !== 0 || !registry2 || !cache2 || !prefix || !scopedRegistry) {
|
|
25510
|
+
throw new Error("Could not resolve the global npm registry, cache and prefix");
|
|
25511
|
+
}
|
|
25512
|
+
return {
|
|
25513
|
+
digest: createHash2("sha256").update(configuration).digest("hex"),
|
|
25514
|
+
cacheDirectory: cache2,
|
|
25515
|
+
environment: {
|
|
25516
|
+
npm_config_registry: registry2,
|
|
25517
|
+
npm_config_cache: cache2,
|
|
25518
|
+
npm_config_prefix: prefix,
|
|
25519
|
+
"npm_config_@codexhost:registry": scopedRegistry === "undefined" ? registry2 : scopedRegistry
|
|
25520
|
+
}
|
|
25521
|
+
};
|
|
25522
|
+
}
|
|
25523
|
+
async function resolveNpmPackageCacheFiles(target2, run2 = runNpmCommand) {
|
|
25524
|
+
const specs = npmReleasePackages(target2.packageRoot, target2.version);
|
|
25525
|
+
const files = [];
|
|
25526
|
+
for (const spec of specs) {
|
|
25527
|
+
const result = await run2(target2, ["view", spec, "dist.integrity"], VIEW_TIMEOUT_MS);
|
|
25528
|
+
if (result.code !== 0)
|
|
25529
|
+
return [];
|
|
25530
|
+
const integrity = result.stdout.trim();
|
|
25531
|
+
const match = /^(sha512|sha256|sha1)-([A-Za-z0-9+/=]+)$/u.exec(integrity);
|
|
25532
|
+
if (!match)
|
|
25533
|
+
return [];
|
|
25534
|
+
const [, algorithm, encoded] = match;
|
|
25535
|
+
if (!algorithm || !encoded)
|
|
25536
|
+
return [];
|
|
25537
|
+
const hex3 = Buffer.from(encoded, "base64").toString("hex");
|
|
25538
|
+
if (hex3.length < 8)
|
|
25539
|
+
return [];
|
|
25540
|
+
files.push(`content-v2/${algorithm}/${hex3.slice(0, 2)}/${hex3.slice(2, 4)}/${hex3.slice(4)}`);
|
|
25541
|
+
}
|
|
25542
|
+
return files;
|
|
25543
|
+
}
|
|
25002
25544
|
function firstErrorLine(result) {
|
|
25003
25545
|
const line = result.stderr.split(/\r?\n/u).map((value) => value.trim()).find((value) => /^npm (error|ERR!)/u.test(value) && !/A complete log/u.test(value));
|
|
25004
25546
|
return (line ?? result.stderr.trim().split(/\r?\n/u).at(-1) ?? "").slice(0, 200);
|
|
@@ -25045,7 +25587,7 @@ async function fetchLatestNpmRelease(nodePath, npmCliPath, run2 = runNpmCommand)
|
|
|
25045
25587
|
return Object.freeze({
|
|
25046
25588
|
version: version2,
|
|
25047
25589
|
releaseNotes: null,
|
|
25048
|
-
releaseNotesUrl:
|
|
25590
|
+
releaseNotesUrl: null,
|
|
25049
25591
|
assets: Object.freeze([])
|
|
25050
25592
|
});
|
|
25051
25593
|
} catch {
|
|
@@ -25076,30 +25618,596 @@ function createNpmReleaseAvailability(run2 = runNpmCommand, now = Date.now) {
|
|
|
25076
25618
|
});
|
|
25077
25619
|
}
|
|
25078
25620
|
|
|
25079
|
-
// packages/update-manager/dist/
|
|
25080
|
-
|
|
25081
|
-
|
|
25082
|
-
var
|
|
25083
|
-
var
|
|
25084
|
-
var
|
|
25085
|
-
|
|
25086
|
-
|
|
25087
|
-
|
|
25088
|
-
|
|
25089
|
-
|
|
25090
|
-
|
|
25091
|
-
|
|
25092
|
-
|
|
25093
|
-
|
|
25094
|
-
|
|
25095
|
-
|
|
25096
|
-
|
|
25097
|
-
|
|
25098
|
-
|
|
25099
|
-
|
|
25100
|
-
|
|
25101
|
-
|
|
25102
|
-
|
|
25621
|
+
// packages/update-manager/dist/staging.js
|
|
25622
|
+
var STAGING_SCHEMA_VERSION = 1;
|
|
25623
|
+
var STAGING_LOCK_FILE = "staging-v1.lock";
|
|
25624
|
+
var STAGING_LOCK_TTL_SECONDS = 30 * 60;
|
|
25625
|
+
var STAGING_LOCK_WRITE_GRACE_MS = 5e3;
|
|
25626
|
+
var STAGED_DIRECTORY_NAME = "staged";
|
|
25627
|
+
var STAGED_METADATA_FILE = "staged-v1.json";
|
|
25628
|
+
var SHA256_PATTERN2 = /^[0-9a-f]{64}$/u;
|
|
25629
|
+
var NPM_CACHE_FILE_PATTERN = /^content-v2\/(?:sha512|sha256|sha1)\/[0-9a-f]{2}\/[0-9a-f]{2}\/[0-9a-f]+$/u;
|
|
25630
|
+
var RELEASE_TARGETS = /* @__PURE__ */ new Set([
|
|
25631
|
+
"macos-arm64",
|
|
25632
|
+
"macos-x64",
|
|
25633
|
+
"windows-x64",
|
|
25634
|
+
"windows-arm64",
|
|
25635
|
+
"linux-x64",
|
|
25636
|
+
"linux-arm64"
|
|
25637
|
+
]);
|
|
25638
|
+
var WINDOWS_RENAME_RETRY_DELAYS_MS = [20, 50, 100, 200, 350, 500, 800];
|
|
25639
|
+
function systemErrorCode(error62) {
|
|
25640
|
+
return typeof error62 === "object" && error62 !== null && "code" in error62 ? String(error62.code) : null;
|
|
25641
|
+
}
|
|
25642
|
+
function delay(milliseconds) {
|
|
25643
|
+
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
25644
|
+
}
|
|
25645
|
+
async function replaceFile(temporaryPath, destinationPath) {
|
|
25646
|
+
let retryIndex = 0;
|
|
25647
|
+
for (; ; ) {
|
|
25648
|
+
try {
|
|
25649
|
+
await rename(temporaryPath, destinationPath);
|
|
25650
|
+
return;
|
|
25651
|
+
} catch (error62) {
|
|
25652
|
+
const retryDelay = WINDOWS_RENAME_RETRY_DELAYS_MS[retryIndex];
|
|
25653
|
+
const code = systemErrorCode(error62);
|
|
25654
|
+
if (process.platform !== "win32" || retryDelay === void 0 || code !== "EACCES" && code !== "EBUSY" && code !== "EPERM") {
|
|
25655
|
+
throw error62;
|
|
25656
|
+
}
|
|
25657
|
+
retryIndex += 1;
|
|
25658
|
+
await delay(retryDelay);
|
|
25659
|
+
}
|
|
25660
|
+
}
|
|
25661
|
+
}
|
|
25662
|
+
function requireAbsoluteDirectory(value) {
|
|
25663
|
+
if (!path4.isAbsolute(value))
|
|
25664
|
+
throw new Error("update state directory must be absolute");
|
|
25665
|
+
return path4.normalize(value);
|
|
25666
|
+
}
|
|
25667
|
+
function requireSafeAssetName(value) {
|
|
25668
|
+
if (value.length === 0 || value.length > 160 || value === "." || value === ".." || value.includes("/") || value.includes("\\") || value.includes("\0")) {
|
|
25669
|
+
throw new Error("staged asset name is invalid");
|
|
25670
|
+
}
|
|
25671
|
+
return value;
|
|
25672
|
+
}
|
|
25673
|
+
function stagedDirectoryPath(stateDirectory) {
|
|
25674
|
+
return path4.join(requireAbsoluteDirectory(stateDirectory), STAGED_DIRECTORY_NAME);
|
|
25675
|
+
}
|
|
25676
|
+
function stagedMetadataPath(stateDirectory) {
|
|
25677
|
+
return path4.join(stagedDirectoryPath(stateDirectory), STAGED_METADATA_FILE);
|
|
25678
|
+
}
|
|
25679
|
+
function stagingLockPath(stateDirectory) {
|
|
25680
|
+
return path4.join(requireAbsoluteDirectory(stateDirectory), STAGING_LOCK_FILE);
|
|
25681
|
+
}
|
|
25682
|
+
function normalizePathForContainment(filePath2, platform = process.platform) {
|
|
25683
|
+
if (platform === "win32") {
|
|
25684
|
+
let stripped = filePath2;
|
|
25685
|
+
if (/^\\\\\?\\UNC\\/iu.test(stripped)) {
|
|
25686
|
+
stripped = `\\\\${stripped.slice(8)}`;
|
|
25687
|
+
} else if (stripped.startsWith("\\\\?\\")) {
|
|
25688
|
+
stripped = stripped.slice(4);
|
|
25689
|
+
}
|
|
25690
|
+
return path4.win32.normalize(stripped).toLowerCase();
|
|
25691
|
+
}
|
|
25692
|
+
return path4.posix.normalize(filePath2);
|
|
25693
|
+
}
|
|
25694
|
+
function isPathInsideRoot(rootPath, candidatePath, platform = process.platform) {
|
|
25695
|
+
const normalizedRoot = normalizePathForContainment(rootPath, platform);
|
|
25696
|
+
const normalizedCandidate = normalizePathForContainment(candidatePath, platform);
|
|
25697
|
+
const pathImpl = platform === "win32" ? path4.win32 : path4.posix;
|
|
25698
|
+
const relative = pathImpl.relative(normalizedRoot, normalizedCandidate);
|
|
25699
|
+
return relative.length > 0 && !relative.startsWith("..") && !pathImpl.isAbsolute(relative);
|
|
25700
|
+
}
|
|
25701
|
+
function processIsAlive(processId) {
|
|
25702
|
+
if (!Number.isSafeInteger(processId) || processId <= 0)
|
|
25703
|
+
return false;
|
|
25704
|
+
try {
|
|
25705
|
+
process.kill(processId, 0);
|
|
25706
|
+
return true;
|
|
25707
|
+
} catch (error62) {
|
|
25708
|
+
return error62.code === "EPERM";
|
|
25709
|
+
}
|
|
25710
|
+
}
|
|
25711
|
+
async function regularFile(filePath2) {
|
|
25712
|
+
try {
|
|
25713
|
+
const metadata = await lstat3(filePath2);
|
|
25714
|
+
return metadata.isFile() && !metadata.isSymbolicLink();
|
|
25715
|
+
} catch (error62) {
|
|
25716
|
+
if (error62.code === "ENOENT")
|
|
25717
|
+
return false;
|
|
25718
|
+
throw error62;
|
|
25719
|
+
}
|
|
25720
|
+
}
|
|
25721
|
+
async function recoverStagingLock(stateDirectory, now = Date.now) {
|
|
25722
|
+
const lockPath = stagingLockPath(stateDirectory);
|
|
25723
|
+
let metadata;
|
|
25724
|
+
try {
|
|
25725
|
+
metadata = await lstat3(lockPath);
|
|
25726
|
+
} catch (error62) {
|
|
25727
|
+
if (systemErrorCode(error62) === "ENOENT")
|
|
25728
|
+
return;
|
|
25729
|
+
throw error62;
|
|
25730
|
+
}
|
|
25731
|
+
if (!metadata.isFile() || metadata.isSymbolicLink())
|
|
25732
|
+
return;
|
|
25733
|
+
let raw;
|
|
25734
|
+
try {
|
|
25735
|
+
raw = await readFile3(lockPath, "utf8");
|
|
25736
|
+
} catch (error62) {
|
|
25737
|
+
const code = systemErrorCode(error62);
|
|
25738
|
+
if (code === "ENOENT" || code === "EACCES" || code === "EBUSY" || code === "EPERM")
|
|
25739
|
+
return;
|
|
25740
|
+
throw error62;
|
|
25741
|
+
}
|
|
25742
|
+
const nowMs = now();
|
|
25743
|
+
const nowSeconds = Math.floor(nowMs / 1e3);
|
|
25744
|
+
try {
|
|
25745
|
+
const parsed = JSON.parse(raw);
|
|
25746
|
+
const ownerPid = parsed.ownerPid;
|
|
25747
|
+
const startedAt = parsed.startedAt;
|
|
25748
|
+
const pidAlive = typeof ownerPid === "number" && processIsAlive(ownerPid);
|
|
25749
|
+
const expired = typeof startedAt !== "number" || !Number.isSafeInteger(startedAt) || startedAt < 0 || nowSeconds - startedAt >= STAGING_LOCK_TTL_SECONDS;
|
|
25750
|
+
if (!pidAlive || expired) {
|
|
25751
|
+
await rm(lockPath, { force: true });
|
|
25752
|
+
}
|
|
25753
|
+
} catch {
|
|
25754
|
+
if (nowMs - metadata.mtimeMs < STAGING_LOCK_WRITE_GRACE_MS)
|
|
25755
|
+
return;
|
|
25756
|
+
await rm(lockPath, { force: true });
|
|
25757
|
+
}
|
|
25758
|
+
}
|
|
25759
|
+
async function acquireStagingLock(stateDirectory, now) {
|
|
25760
|
+
const root = requireAbsoluteDirectory(stateDirectory);
|
|
25761
|
+
await mkdir(root, { recursive: true, mode: 448 });
|
|
25762
|
+
await recoverStagingLock(root, now);
|
|
25763
|
+
const lockPath = stagingLockPath(root);
|
|
25764
|
+
const token = randomUUID();
|
|
25765
|
+
const payload = `${JSON.stringify({
|
|
25766
|
+
ownerPid: process.pid,
|
|
25767
|
+
startedAt: Math.floor(now() / 1e3),
|
|
25768
|
+
token
|
|
25769
|
+
})}
|
|
25770
|
+
`;
|
|
25771
|
+
const temporaryLockPath = path4.join(root, `.staging-v1-${token}.tmp`);
|
|
25772
|
+
try {
|
|
25773
|
+
const handle = await open3(temporaryLockPath, "wx", 384);
|
|
25774
|
+
try {
|
|
25775
|
+
await handle.writeFile(payload, "utf8");
|
|
25776
|
+
await handle.sync();
|
|
25777
|
+
} finally {
|
|
25778
|
+
await handle.close();
|
|
25779
|
+
}
|
|
25780
|
+
try {
|
|
25781
|
+
await link(temporaryLockPath, lockPath);
|
|
25782
|
+
} catch (error62) {
|
|
25783
|
+
const code = systemErrorCode(error62);
|
|
25784
|
+
if (code === "EEXIST")
|
|
25785
|
+
return null;
|
|
25786
|
+
if (code === "EXDEV" || code === "ENOTSUP" || code === "ENOSYS") {
|
|
25787
|
+
let fallbackHandle;
|
|
25788
|
+
try {
|
|
25789
|
+
fallbackHandle = await open3(lockPath, "wx", 384);
|
|
25790
|
+
} catch (fallbackError) {
|
|
25791
|
+
if (systemErrorCode(fallbackError) === "EEXIST")
|
|
25792
|
+
return null;
|
|
25793
|
+
throw fallbackError;
|
|
25794
|
+
}
|
|
25795
|
+
try {
|
|
25796
|
+
await fallbackHandle.writeFile(payload, "utf8");
|
|
25797
|
+
await fallbackHandle.sync();
|
|
25798
|
+
} catch (writeError) {
|
|
25799
|
+
await fallbackHandle.close().catch(() => void 0);
|
|
25800
|
+
await rm(lockPath, { force: true }).catch(() => void 0);
|
|
25801
|
+
throw writeError;
|
|
25802
|
+
}
|
|
25803
|
+
await fallbackHandle.close();
|
|
25804
|
+
} else {
|
|
25805
|
+
throw error62;
|
|
25806
|
+
}
|
|
25807
|
+
}
|
|
25808
|
+
} finally {
|
|
25809
|
+
await rm(temporaryLockPath, { force: true });
|
|
25810
|
+
}
|
|
25811
|
+
let released = false;
|
|
25812
|
+
return {
|
|
25813
|
+
async release() {
|
|
25814
|
+
if (released)
|
|
25815
|
+
return;
|
|
25816
|
+
released = true;
|
|
25817
|
+
try {
|
|
25818
|
+
const current = JSON.parse(await readFile3(lockPath, "utf8"));
|
|
25819
|
+
if (current.token !== token)
|
|
25820
|
+
return;
|
|
25821
|
+
} catch {
|
|
25822
|
+
return;
|
|
25823
|
+
}
|
|
25824
|
+
await rm(lockPath, { force: true });
|
|
25825
|
+
}
|
|
25826
|
+
};
|
|
25827
|
+
}
|
|
25828
|
+
function parseStagedUpdateRecord(value) {
|
|
25829
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
25830
|
+
throw new Error("staged update metadata must be an object");
|
|
25831
|
+
}
|
|
25832
|
+
const record4 = value;
|
|
25833
|
+
const allowed = /* @__PURE__ */ new Set([
|
|
25834
|
+
"schemaVersion",
|
|
25835
|
+
"version",
|
|
25836
|
+
"distribution",
|
|
25837
|
+
"target",
|
|
25838
|
+
"stagedAt",
|
|
25839
|
+
"npmConfigSha256",
|
|
25840
|
+
"npmCacheFiles",
|
|
25841
|
+
"assetName",
|
|
25842
|
+
"artifactPath",
|
|
25843
|
+
"sha256",
|
|
25844
|
+
"size"
|
|
25845
|
+
]);
|
|
25846
|
+
if (Object.keys(record4).some((key) => !allowed.has(key))) {
|
|
25847
|
+
throw new Error("staged update metadata contains unknown fields");
|
|
25848
|
+
}
|
|
25849
|
+
if (record4.schemaVersion !== STAGING_SCHEMA_VERSION || typeof record4.version !== "string" || record4.distribution !== "npm" && record4.distribution !== "installer" || typeof record4.target !== "string" || !RELEASE_TARGETS.has(record4.target) || typeof record4.stagedAt !== "number" || !Number.isSafeInteger(record4.stagedAt) || record4.stagedAt < 0) {
|
|
25850
|
+
throw new Error("staged update metadata is invalid");
|
|
25851
|
+
}
|
|
25852
|
+
const version2 = requireSemanticVersion(record4.version);
|
|
25853
|
+
if (record4.distribution === "npm") {
|
|
25854
|
+
if (record4.assetName !== void 0 || record4.artifactPath !== void 0 || record4.sha256 !== void 0 || record4.size !== void 0) {
|
|
25855
|
+
throw new Error("staged npm metadata must not include installer fields");
|
|
25856
|
+
}
|
|
25857
|
+
if (record4.npmConfigSha256 !== void 0 && (typeof record4.npmConfigSha256 !== "string" || !SHA256_PATTERN2.test(record4.npmConfigSha256))) {
|
|
25858
|
+
throw new Error("staged npm metadata has an invalid npmConfigSha256");
|
|
25859
|
+
}
|
|
25860
|
+
let npmCacheFiles;
|
|
25861
|
+
if (record4.npmCacheFiles !== void 0) {
|
|
25862
|
+
if (!Array.isArray(record4.npmCacheFiles) || record4.npmCacheFiles.length > 8 || record4.npmCacheFiles.some((entry) => typeof entry !== "string" || !NPM_CACHE_FILE_PATTERN.test(entry))) {
|
|
25863
|
+
throw new Error("staged npm metadata has invalid npmCacheFiles");
|
|
25864
|
+
}
|
|
25865
|
+
npmCacheFiles = record4.npmCacheFiles;
|
|
25866
|
+
}
|
|
25867
|
+
return {
|
|
25868
|
+
schemaVersion: 1,
|
|
25869
|
+
version: version2,
|
|
25870
|
+
distribution: "npm",
|
|
25871
|
+
target: record4.target,
|
|
25872
|
+
stagedAt: record4.stagedAt,
|
|
25873
|
+
...record4.npmConfigSha256 !== void 0 ? { npmConfigSha256: record4.npmConfigSha256 } : {},
|
|
25874
|
+
...npmCacheFiles !== void 0 ? { npmCacheFiles } : {}
|
|
25875
|
+
};
|
|
25876
|
+
}
|
|
25877
|
+
if (record4.npmConfigSha256 !== void 0 || record4.npmCacheFiles !== void 0) {
|
|
25878
|
+
throw new Error("staged installer metadata must not include npm staging fields");
|
|
25879
|
+
}
|
|
25880
|
+
if (typeof record4.assetName !== "string" || typeof record4.artifactPath !== "string" || !path4.isAbsolute(record4.artifactPath) || typeof record4.sha256 !== "string" || !SHA256_PATTERN2.test(record4.sha256) || typeof record4.size !== "number" || !Number.isSafeInteger(record4.size) || record4.size <= 0) {
|
|
25881
|
+
throw new Error("staged installer metadata is invalid");
|
|
25882
|
+
}
|
|
25883
|
+
return {
|
|
25884
|
+
schemaVersion: 1,
|
|
25885
|
+
version: version2,
|
|
25886
|
+
distribution: "installer",
|
|
25887
|
+
target: record4.target,
|
|
25888
|
+
stagedAt: record4.stagedAt,
|
|
25889
|
+
assetName: requireSafeAssetName(record4.assetName),
|
|
25890
|
+
artifactPath: path4.normalize(record4.artifactPath),
|
|
25891
|
+
sha256: record4.sha256,
|
|
25892
|
+
size: record4.size
|
|
25893
|
+
};
|
|
25894
|
+
}
|
|
25895
|
+
async function writeStagedMetadata(stateDirectory, record4) {
|
|
25896
|
+
const stagedRoot = stagedDirectoryPath(stateDirectory);
|
|
25897
|
+
await mkdir(stagedRoot, { recursive: true, mode: 448 });
|
|
25898
|
+
const destination = stagedMetadataPath(stateDirectory);
|
|
25899
|
+
const temporary = path4.join(stagedRoot, `.staged-v1-${randomUUID()}.tmp`);
|
|
25900
|
+
try {
|
|
25901
|
+
await writeFile(temporary, `${JSON.stringify(record4)}
|
|
25902
|
+
`, {
|
|
25903
|
+
encoding: "utf8",
|
|
25904
|
+
mode: 384,
|
|
25905
|
+
flag: "wx"
|
|
25906
|
+
});
|
|
25907
|
+
await replaceFile(temporary, destination);
|
|
25908
|
+
} catch (error62) {
|
|
25909
|
+
await rm(temporary, { force: true });
|
|
25910
|
+
throw error62;
|
|
25911
|
+
}
|
|
25912
|
+
}
|
|
25913
|
+
async function removeOtherStagedVersionDirectories(stateDirectory, keepVersion) {
|
|
25914
|
+
const stagedRoot = stagedDirectoryPath(stateDirectory);
|
|
25915
|
+
let entries;
|
|
25916
|
+
try {
|
|
25917
|
+
entries = await readdir(stagedRoot, { withFileTypes: true });
|
|
25918
|
+
} catch (error62) {
|
|
25919
|
+
if (error62.code === "ENOENT")
|
|
25920
|
+
return;
|
|
25921
|
+
throw error62;
|
|
25922
|
+
}
|
|
25923
|
+
const keepName = keepVersion ? `update-${keepVersion}` : null;
|
|
25924
|
+
for (const entry of entries) {
|
|
25925
|
+
if (!entry.name.startsWith("update-"))
|
|
25926
|
+
continue;
|
|
25927
|
+
if (keepName !== null && entry.name === keepName)
|
|
25928
|
+
continue;
|
|
25929
|
+
await rm(path4.join(stagedRoot, entry.name), { recursive: true, force: true });
|
|
25930
|
+
}
|
|
25931
|
+
}
|
|
25932
|
+
async function readStagedUpdate(stateDirectory) {
|
|
25933
|
+
const metadataPath = stagedMetadataPath(stateDirectory);
|
|
25934
|
+
if (!await regularFile(metadataPath))
|
|
25935
|
+
return null;
|
|
25936
|
+
try {
|
|
25937
|
+
return parseStagedUpdateRecord(JSON.parse(await readFile3(metadataPath, "utf8")));
|
|
25938
|
+
} catch {
|
|
25939
|
+
return null;
|
|
25940
|
+
}
|
|
25941
|
+
}
|
|
25942
|
+
async function verifyStagedArtifact(stateDirectory, staged, expectedSource) {
|
|
25943
|
+
if (staged.distribution !== "installer" || !staged.artifactPath || !staged.sha256) {
|
|
25944
|
+
return null;
|
|
25945
|
+
}
|
|
25946
|
+
if (staged.sha256 !== expectedSource.sha256)
|
|
25947
|
+
return null;
|
|
25948
|
+
if (expectedSource.size !== void 0 && staged.size !== expectedSource.size)
|
|
25949
|
+
return null;
|
|
25950
|
+
const stagedRoot = stagedDirectoryPath(stateDirectory);
|
|
25951
|
+
try {
|
|
25952
|
+
const entryMeta = await lstat3(staged.artifactPath);
|
|
25953
|
+
if (!entryMeta.isFile() || entryMeta.isSymbolicLink())
|
|
25954
|
+
return null;
|
|
25955
|
+
const [realStagedRoot, realArtifactPath] = await Promise.all([
|
|
25956
|
+
realpath2(stagedRoot),
|
|
25957
|
+
realpath2(staged.artifactPath)
|
|
25958
|
+
]);
|
|
25959
|
+
if (!isPathInsideRoot(realStagedRoot, realArtifactPath))
|
|
25960
|
+
return null;
|
|
25961
|
+
const size = await verifyArtifactFile(expectedSource, realArtifactPath);
|
|
25962
|
+
if (staged.size !== void 0 && size !== staged.size)
|
|
25963
|
+
return null;
|
|
25964
|
+
return { artifactPath: realArtifactPath, size };
|
|
25965
|
+
} catch {
|
|
25966
|
+
return null;
|
|
25967
|
+
}
|
|
25968
|
+
}
|
|
25969
|
+
async function cleanupStagedUpdates(stateDirectory, options = {}) {
|
|
25970
|
+
const root = requireAbsoluteDirectory(stateDirectory);
|
|
25971
|
+
const now = options.now ?? Date.now;
|
|
25972
|
+
await recoverStagingLock(root, now);
|
|
25973
|
+
const stagedRoot = stagedDirectoryPath(root);
|
|
25974
|
+
try {
|
|
25975
|
+
await lstat3(stagedRoot);
|
|
25976
|
+
} catch (error62) {
|
|
25977
|
+
if (error62.code === "ENOENT")
|
|
25978
|
+
return;
|
|
25979
|
+
throw error62;
|
|
25980
|
+
}
|
|
25981
|
+
const lock = await acquireStagingLock(root, now);
|
|
25982
|
+
if (!lock)
|
|
25983
|
+
return;
|
|
25984
|
+
try {
|
|
25985
|
+
if (options.currentVersion !== void 0) {
|
|
25986
|
+
const currentVersion = requireSemanticVersion(options.currentVersion);
|
|
25987
|
+
const staged = await readStagedUpdate(root);
|
|
25988
|
+
if (staged) {
|
|
25989
|
+
if (compareSemanticVersions(currentVersion, staged.version) >= 0) {
|
|
25990
|
+
await rm(stagedRoot, { recursive: true, force: true });
|
|
25991
|
+
}
|
|
25992
|
+
return;
|
|
25993
|
+
}
|
|
25994
|
+
let entries;
|
|
25995
|
+
try {
|
|
25996
|
+
entries = await readdir(stagedRoot, { withFileTypes: true });
|
|
25997
|
+
} catch (error62) {
|
|
25998
|
+
if (error62.code === "ENOENT")
|
|
25999
|
+
return;
|
|
26000
|
+
throw error62;
|
|
26001
|
+
}
|
|
26002
|
+
for (const entry of entries) {
|
|
26003
|
+
if (!entry.isDirectory() || entry.isSymbolicLink() || !entry.name.startsWith("update-")) {
|
|
26004
|
+
continue;
|
|
26005
|
+
}
|
|
26006
|
+
const candidateVersion = entry.name.slice("update-".length);
|
|
26007
|
+
if (!SEMVER_PATTERN.test(candidateVersion))
|
|
26008
|
+
continue;
|
|
26009
|
+
if (compareSemanticVersions(currentVersion, candidateVersion) >= 0) {
|
|
26010
|
+
await rm(path4.join(stagedRoot, entry.name), { recursive: true, force: true });
|
|
26011
|
+
}
|
|
26012
|
+
}
|
|
26013
|
+
const remaining = await readdir(stagedRoot).catch(() => null);
|
|
26014
|
+
if (remaining !== null && remaining.length === 0) {
|
|
26015
|
+
await rmdir(stagedRoot).catch(() => void 0);
|
|
26016
|
+
}
|
|
26017
|
+
return;
|
|
26018
|
+
}
|
|
26019
|
+
if (options.keepVersion !== void 0) {
|
|
26020
|
+
const keepVersion = requireSemanticVersion(options.keepVersion);
|
|
26021
|
+
await removeOtherStagedVersionDirectories(root, keepVersion);
|
|
26022
|
+
return;
|
|
26023
|
+
}
|
|
26024
|
+
await rm(stagedRoot, { recursive: true, force: true });
|
|
26025
|
+
} finally {
|
|
26026
|
+
await lock.release();
|
|
26027
|
+
}
|
|
26028
|
+
}
|
|
26029
|
+
async function stageArtifact(options) {
|
|
26030
|
+
const root = requireAbsoluteDirectory(options.stateDirectory);
|
|
26031
|
+
const version2 = requireSemanticVersion(options.version);
|
|
26032
|
+
const assetName = requireSafeAssetName(options.assetName);
|
|
26033
|
+
const source = validateArtifact(options.source);
|
|
26034
|
+
const now = options.now ?? Date.now;
|
|
26035
|
+
const download2 = options.download ?? downloadArtifact;
|
|
26036
|
+
const lock = await acquireStagingLock(root, now);
|
|
26037
|
+
if (!lock) {
|
|
26038
|
+
throw new Error("Another background update staging operation is already active");
|
|
26039
|
+
}
|
|
26040
|
+
const versionDirectory = path4.join(stagedDirectoryPath(root), `update-${version2}`);
|
|
26041
|
+
const artifactPath = path4.join(versionDirectory, assetName);
|
|
26042
|
+
const temporaryPath = path4.join(versionDirectory, `.${assetName}.${randomUUID()}.download`);
|
|
26043
|
+
try {
|
|
26044
|
+
const existing = await readStagedUpdate(root);
|
|
26045
|
+
if (existing && existing.distribution === "installer" && existing.version === version2 && existing.target === options.target && existing.assetName === assetName) {
|
|
26046
|
+
const verified = await verifyStagedArtifact(root, existing, source);
|
|
26047
|
+
if (verified) {
|
|
26048
|
+
await removeOtherStagedVersionDirectories(root, version2);
|
|
26049
|
+
return existing;
|
|
26050
|
+
}
|
|
26051
|
+
}
|
|
26052
|
+
await removeOtherStagedVersionDirectories(root, version2);
|
|
26053
|
+
await mkdir(versionDirectory, { recursive: true, mode: 448 });
|
|
26054
|
+
const result = await download2(source, temporaryPath, options.onProgress);
|
|
26055
|
+
const finalUrl = new URL(result.finalUrl);
|
|
26056
|
+
if (finalUrl.protocol !== "https:" || finalUrl.username || finalUrl.password) {
|
|
26057
|
+
throw new Error("update artifact downloader returned a non-HTTPS URL");
|
|
26058
|
+
}
|
|
26059
|
+
await verifyDownloadedArtifact(source, temporaryPath, result);
|
|
26060
|
+
await replaceFile(temporaryPath, artifactPath);
|
|
26061
|
+
const record4 = {
|
|
26062
|
+
schemaVersion: 1,
|
|
26063
|
+
version: version2,
|
|
26064
|
+
distribution: "installer",
|
|
26065
|
+
target: options.target,
|
|
26066
|
+
stagedAt: Math.floor(now() / 1e3),
|
|
26067
|
+
assetName,
|
|
26068
|
+
artifactPath,
|
|
26069
|
+
sha256: source.sha256,
|
|
26070
|
+
size: result.bytes
|
|
26071
|
+
};
|
|
26072
|
+
await writeStagedMetadata(root, record4);
|
|
26073
|
+
await removeOtherStagedVersionDirectories(root, version2);
|
|
26074
|
+
return record4;
|
|
26075
|
+
} catch (error62) {
|
|
26076
|
+
await rm(temporaryPath, { force: true });
|
|
26077
|
+
await rmdir(versionDirectory).catch(() => void 0);
|
|
26078
|
+
await rmdir(stagedDirectoryPath(root)).catch(() => void 0);
|
|
26079
|
+
throw error62;
|
|
26080
|
+
} finally {
|
|
26081
|
+
await lock.release();
|
|
26082
|
+
}
|
|
26083
|
+
}
|
|
26084
|
+
async function nonEmptyDirectory(directoryPath) {
|
|
26085
|
+
try {
|
|
26086
|
+
const entries = await readdir(directoryPath);
|
|
26087
|
+
return entries.length > 0;
|
|
26088
|
+
} catch {
|
|
26089
|
+
return false;
|
|
26090
|
+
}
|
|
26091
|
+
}
|
|
26092
|
+
async function verifyNpmCacheContentFiles(cacacheRoot, relativeFiles) {
|
|
26093
|
+
let realCacacheRoot;
|
|
26094
|
+
try {
|
|
26095
|
+
realCacacheRoot = await realpath2(cacacheRoot);
|
|
26096
|
+
} catch {
|
|
26097
|
+
return false;
|
|
26098
|
+
}
|
|
26099
|
+
for (const relativeFile of relativeFiles) {
|
|
26100
|
+
if (!NPM_CACHE_FILE_PATTERN.test(relativeFile))
|
|
26101
|
+
return false;
|
|
26102
|
+
const candidate = path4.join(realCacacheRoot, ...relativeFile.split("/"));
|
|
26103
|
+
try {
|
|
26104
|
+
const metadata = await lstat3(candidate);
|
|
26105
|
+
if (!metadata.isFile() || metadata.isSymbolicLink() || metadata.size <= 0)
|
|
26106
|
+
return false;
|
|
26107
|
+
const realCandidate = await realpath2(candidate);
|
|
26108
|
+
if (!isPathInsideRoot(realCacacheRoot, realCandidate))
|
|
26109
|
+
return false;
|
|
26110
|
+
} catch {
|
|
26111
|
+
return false;
|
|
26112
|
+
}
|
|
26113
|
+
}
|
|
26114
|
+
return true;
|
|
26115
|
+
}
|
|
26116
|
+
async function verifyStagedNpm(staged, options) {
|
|
26117
|
+
if (staged.distribution !== "npm")
|
|
26118
|
+
return false;
|
|
26119
|
+
if (staged.version !== options.version)
|
|
26120
|
+
return false;
|
|
26121
|
+
if (options.target && staged.target !== options.target)
|
|
26122
|
+
return false;
|
|
26123
|
+
if (options.npmConfigSha256 && staged.npmConfigSha256 !== options.npmConfigSha256)
|
|
26124
|
+
return false;
|
|
26125
|
+
if (options.npmCacheDirectory) {
|
|
26126
|
+
const cacacheRoot = path4.join(options.npmCacheDirectory, "_cacache");
|
|
26127
|
+
const [hasIndex, hasContent] = await Promise.all([
|
|
26128
|
+
nonEmptyDirectory(path4.join(cacacheRoot, "index-v5")),
|
|
26129
|
+
nonEmptyDirectory(path4.join(cacacheRoot, "content-v2"))
|
|
26130
|
+
]);
|
|
26131
|
+
if (!hasIndex || !hasContent)
|
|
26132
|
+
return false;
|
|
26133
|
+
if (staged.npmCacheFiles && staged.npmCacheFiles.length > 0) {
|
|
26134
|
+
if (!await verifyNpmCacheContentFiles(cacacheRoot, staged.npmCacheFiles))
|
|
26135
|
+
return false;
|
|
26136
|
+
}
|
|
26137
|
+
}
|
|
26138
|
+
return true;
|
|
26139
|
+
}
|
|
26140
|
+
async function stageNpm(options) {
|
|
26141
|
+
const root = requireAbsoluteDirectory(options.stateDirectory);
|
|
26142
|
+
const version2 = requireSemanticVersion(options.version);
|
|
26143
|
+
if (options.npmConfigSha256 !== void 0 && !SHA256_PATTERN2.test(options.npmConfigSha256)) {
|
|
26144
|
+
throw new Error("npmConfigSha256 must be lowercase hexadecimal");
|
|
26145
|
+
}
|
|
26146
|
+
const now = options.now ?? Date.now;
|
|
26147
|
+
const prefetch = options.prefetchNpm ?? ((target2, onProgress) => prefetchNpmRelease(target2, void 0, onProgress));
|
|
26148
|
+
const lock = await acquireStagingLock(root, now);
|
|
26149
|
+
if (!lock) {
|
|
26150
|
+
throw new Error("Another background update staging operation is already active");
|
|
26151
|
+
}
|
|
26152
|
+
try {
|
|
26153
|
+
const existing = await readStagedUpdate(root);
|
|
26154
|
+
if (existing && await verifyStagedNpm(existing, {
|
|
26155
|
+
version: version2,
|
|
26156
|
+
target: options.target,
|
|
26157
|
+
...options.npmConfigSha256 ? { npmConfigSha256: options.npmConfigSha256 } : {},
|
|
26158
|
+
...options.npmCacheDirectory ? { npmCacheDirectory: options.npmCacheDirectory } : {}
|
|
26159
|
+
})) {
|
|
26160
|
+
return existing;
|
|
26161
|
+
}
|
|
26162
|
+
await removeOtherStagedVersionDirectories(root);
|
|
26163
|
+
await prefetch(options.npmTarget, options.onProgress);
|
|
26164
|
+
let verifiedCacheFiles;
|
|
26165
|
+
if (options.npmCacheDirectory && options.resolveCacheFiles) {
|
|
26166
|
+
const candidateFiles = await options.resolveCacheFiles(options.npmTarget).catch(() => []);
|
|
26167
|
+
if (candidateFiles.length > 0 && await verifyNpmCacheContentFiles(path4.join(options.npmCacheDirectory, "_cacache"), candidateFiles)) {
|
|
26168
|
+
verifiedCacheFiles = candidateFiles;
|
|
26169
|
+
}
|
|
26170
|
+
}
|
|
26171
|
+
const record4 = {
|
|
26172
|
+
schemaVersion: 1,
|
|
26173
|
+
version: version2,
|
|
26174
|
+
distribution: "npm",
|
|
26175
|
+
target: options.target,
|
|
26176
|
+
stagedAt: Math.floor(now() / 1e3),
|
|
26177
|
+
...options.npmConfigSha256 ? { npmConfigSha256: options.npmConfigSha256 } : {},
|
|
26178
|
+
...verifiedCacheFiles ? { npmCacheFiles: verifiedCacheFiles } : {}
|
|
26179
|
+
};
|
|
26180
|
+
await writeStagedMetadata(root, record4);
|
|
26181
|
+
return record4;
|
|
26182
|
+
} finally {
|
|
26183
|
+
await lock.release();
|
|
26184
|
+
}
|
|
26185
|
+
}
|
|
26186
|
+
|
|
26187
|
+
// packages/update-manager/dist/github-cli-release.js
|
|
26188
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
26189
|
+
import path5 from "node:path";
|
|
26190
|
+
var GITHUB_LATEST_RELEASE_ENDPOINT = "repos/BytePioneer-AI/codex-host/releases/latest";
|
|
26191
|
+
var MAX_RELEASE_RESPONSE_BYTES = 1024 * 1024;
|
|
26192
|
+
var GITHUB_CLI_TIMEOUT_MS = 5e3;
|
|
26193
|
+
function defaultExecutableCandidates(environment, platform) {
|
|
26194
|
+
if (environment.CODEXHOST_GH_COMMAND)
|
|
26195
|
+
return [environment.CODEXHOST_GH_COMMAND];
|
|
26196
|
+
const candidates = ["gh"];
|
|
26197
|
+
if (platform === "darwin") {
|
|
26198
|
+
candidates.push("/opt/homebrew/bin/gh", "/usr/local/bin/gh");
|
|
26199
|
+
} else if (platform === "win32") {
|
|
26200
|
+
const programFiles = environment.ProgramFiles ?? environment.PROGRAMFILES;
|
|
26201
|
+
const localAppData = environment.LOCALAPPDATA;
|
|
26202
|
+
if (programFiles)
|
|
26203
|
+
candidates.push(path5.win32.join(programFiles, "GitHub CLI", "gh.exe"));
|
|
26204
|
+
if (localAppData) {
|
|
26205
|
+
candidates.push(path5.win32.join(localAppData, "Programs", "GitHub CLI", "gh.exe"));
|
|
26206
|
+
}
|
|
26207
|
+
} else {
|
|
26208
|
+
candidates.push("/usr/local/bin/gh", "/usr/bin/gh", "/snap/bin/gh");
|
|
26209
|
+
}
|
|
26210
|
+
return [...new Set(candidates.filter((candidate) => Boolean(candidate)))];
|
|
25103
26211
|
}
|
|
25104
26212
|
function runGitHubCli(executable, arguments_, options) {
|
|
25105
26213
|
return new Promise((resolve, reject) => {
|
|
@@ -25153,15 +26261,15 @@ async function fetchLatestGitHubReleaseWithGitHubCli(options = {}) {
|
|
|
25153
26261
|
}
|
|
25154
26262
|
|
|
25155
26263
|
// packages/update-manager/dist/operation-state.js
|
|
25156
|
-
import { lstat, mkdir, open as
|
|
25157
|
-
import { randomUUID } from "node:crypto";
|
|
25158
|
-
import
|
|
26264
|
+
import { lstat as lstat4, mkdir as mkdir2, open as open4, readFile as readFile4, readdir as readdir2, rename as rename2, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
26265
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
26266
|
+
import path6 from "node:path";
|
|
25159
26267
|
var LOCK_FILE = "active-update-v1.lock";
|
|
25160
26268
|
var STATUS_FILE = "status-v1.json";
|
|
25161
26269
|
var TERMINAL_PHASES = /* @__PURE__ */ new Set(["succeeded", "failed"]);
|
|
25162
|
-
async function
|
|
26270
|
+
async function regularFile2(filePath2) {
|
|
25163
26271
|
try {
|
|
25164
|
-
const metadata = await
|
|
26272
|
+
const metadata = await lstat4(filePath2);
|
|
25165
26273
|
return metadata.isFile() && !metadata.isSymbolicLink();
|
|
25166
26274
|
} catch (error62) {
|
|
25167
26275
|
if (error62.code === "ENOENT")
|
|
@@ -25170,18 +26278,18 @@ async function regularFile(filePath2) {
|
|
|
25170
26278
|
}
|
|
25171
26279
|
}
|
|
25172
26280
|
async function discoverActiveUpdateStatus(stateDirectory) {
|
|
25173
|
-
if (!
|
|
26281
|
+
if (!path6.isAbsolute(stateDirectory))
|
|
25174
26282
|
throw new Error("update state directory must be absolute");
|
|
25175
|
-
const lockPath =
|
|
25176
|
-
if (!await
|
|
26283
|
+
const lockPath = path6.join(stateDirectory, LOCK_FILE);
|
|
26284
|
+
if (!await regularFile2(lockPath))
|
|
25177
26285
|
return null;
|
|
25178
26286
|
try {
|
|
25179
|
-
const lock = JSON.parse(await
|
|
25180
|
-
if (typeof lock.statusPath !== "string" || !
|
|
26287
|
+
const lock = JSON.parse(await readFile4(lockPath, "utf8"));
|
|
26288
|
+
if (typeof lock.statusPath !== "string" || !path6.isAbsolute(lock.statusPath))
|
|
25181
26289
|
return null;
|
|
25182
|
-
if (!await
|
|
26290
|
+
if (!await regularFile2(lock.statusPath))
|
|
25183
26291
|
return null;
|
|
25184
|
-
const status = parseUpdateStatus(JSON.parse(await
|
|
26292
|
+
const status = parseUpdateStatus(JSON.parse(await readFile4(lock.statusPath, "utf8")));
|
|
25185
26293
|
if (TERMINAL_PHASES.has(status.phase))
|
|
25186
26294
|
return null;
|
|
25187
26295
|
return { statusPath: lock.statusPath, status };
|
|
@@ -25190,11 +26298,11 @@ async function discoverActiveUpdateStatus(stateDirectory) {
|
|
|
25190
26298
|
}
|
|
25191
26299
|
}
|
|
25192
26300
|
async function discoverLatestUpdateStatus(stateDirectory) {
|
|
25193
|
-
if (!
|
|
26301
|
+
if (!path6.isAbsolute(stateDirectory))
|
|
25194
26302
|
throw new Error("update state directory must be absolute");
|
|
25195
26303
|
let entries;
|
|
25196
26304
|
try {
|
|
25197
|
-
entries = await
|
|
26305
|
+
entries = await readdir2(stateDirectory, { withFileTypes: true });
|
|
25198
26306
|
} catch (error62) {
|
|
25199
26307
|
if (error62.code === "ENOENT")
|
|
25200
26308
|
return null;
|
|
@@ -25204,13 +26312,13 @@ async function discoverLatestUpdateStatus(stateDirectory) {
|
|
|
25204
26312
|
for (const entry of entries) {
|
|
25205
26313
|
if (!entry.isDirectory() || entry.isSymbolicLink() || !entry.name.startsWith("update-"))
|
|
25206
26314
|
continue;
|
|
25207
|
-
const statusPath =
|
|
25208
|
-
if (!await
|
|
26315
|
+
const statusPath = path6.join(stateDirectory, entry.name, STATUS_FILE);
|
|
26316
|
+
if (!await regularFile2(statusPath))
|
|
25209
26317
|
continue;
|
|
25210
26318
|
try {
|
|
25211
26319
|
candidates.push({
|
|
25212
26320
|
statusPath,
|
|
25213
|
-
status: parseUpdateStatus(JSON.parse(await
|
|
26321
|
+
status: parseUpdateStatus(JSON.parse(await readFile4(statusPath, "utf8")))
|
|
25214
26322
|
});
|
|
25215
26323
|
} catch {
|
|
25216
26324
|
}
|
|
@@ -25229,7 +26337,7 @@ async function cleanupTerminalUpdateState(stateDirectory, options = {}) {
|
|
|
25229
26337
|
const retentionSeconds = options.retentionSeconds ?? 7 * 24 * 60 * 60;
|
|
25230
26338
|
let entries;
|
|
25231
26339
|
try {
|
|
25232
|
-
entries = await
|
|
26340
|
+
entries = await readdir2(stateDirectory, { withFileTypes: true });
|
|
25233
26341
|
} catch (error62) {
|
|
25234
26342
|
if (error62.code === "ENOENT")
|
|
25235
26343
|
return;
|
|
@@ -25238,25 +26346,25 @@ async function cleanupTerminalUpdateState(stateDirectory, options = {}) {
|
|
|
25238
26346
|
for (const entry of entries) {
|
|
25239
26347
|
if (!entry.isDirectory() || entry.isSymbolicLink() || !entry.name.startsWith("update-"))
|
|
25240
26348
|
continue;
|
|
25241
|
-
const directory =
|
|
25242
|
-
const statusPath =
|
|
26349
|
+
const directory = path6.join(stateDirectory, entry.name);
|
|
26350
|
+
const statusPath = path6.join(directory, STATUS_FILE);
|
|
25243
26351
|
try {
|
|
25244
|
-
const status = parseUpdateStatus(JSON.parse(await
|
|
26352
|
+
const status = parseUpdateStatus(JSON.parse(await readFile4(statusPath, "utf8")));
|
|
25245
26353
|
if (TERMINAL_PHASES.has(status.phase) && now - status.updatedAt > retentionSeconds) {
|
|
25246
|
-
await
|
|
26354
|
+
await rm2(directory, { recursive: true, force: true });
|
|
25247
26355
|
}
|
|
25248
26356
|
} catch {
|
|
25249
26357
|
}
|
|
25250
26358
|
}
|
|
25251
26359
|
}
|
|
25252
26360
|
async function acquireUpdateOperationLock(stateDirectory) {
|
|
25253
|
-
if (!
|
|
26361
|
+
if (!path6.isAbsolute(stateDirectory))
|
|
25254
26362
|
throw new Error("update state directory must be absolute");
|
|
25255
|
-
await
|
|
25256
|
-
const lockPath =
|
|
26363
|
+
await mkdir2(stateDirectory, { recursive: true, mode: 448 });
|
|
26364
|
+
const lockPath = path6.join(stateDirectory, LOCK_FILE);
|
|
25257
26365
|
let handle;
|
|
25258
26366
|
try {
|
|
25259
|
-
handle = await
|
|
26367
|
+
handle = await open4(lockPath, "wx", 384);
|
|
25260
26368
|
} catch (error62) {
|
|
25261
26369
|
if (error62.code === "EEXIST")
|
|
25262
26370
|
return null;
|
|
@@ -25273,175 +26381,86 @@ async function acquireUpdateOperationLock(stateDirectory) {
|
|
|
25273
26381
|
async setStatusPath(statusPath) {
|
|
25274
26382
|
if (released)
|
|
25275
26383
|
throw new Error("update operation lock is released");
|
|
25276
|
-
if (!
|
|
26384
|
+
if (!path6.isAbsolute(statusPath))
|
|
25277
26385
|
throw new Error("update status path must be absolute");
|
|
25278
|
-
await
|
|
26386
|
+
await writeFile2(lockPath, `${JSON.stringify({ ownerPid: process.pid, statusPath: path6.normalize(statusPath) })}
|
|
25279
26387
|
`, { encoding: "utf8", mode: 384 });
|
|
25280
|
-
operationStatusPath =
|
|
26388
|
+
operationStatusPath = path6.normalize(statusPath);
|
|
25281
26389
|
},
|
|
25282
26390
|
async transferTo(ownerPid) {
|
|
25283
26391
|
if (released || !operationStatusPath)
|
|
25284
26392
|
throw new Error("Update operation is not prepared");
|
|
25285
26393
|
if (!Number.isSafeInteger(ownerPid) || ownerPid <= 0)
|
|
25286
26394
|
throw new Error("Invalid update owner PID");
|
|
25287
|
-
const temporary = `${lockPath}.${
|
|
25288
|
-
try {
|
|
25289
|
-
await
|
|
25290
|
-
`, {
|
|
25291
|
-
encoding: "utf8",
|
|
25292
|
-
mode: 384,
|
|
25293
|
-
flag: "wx"
|
|
25294
|
-
});
|
|
25295
|
-
await
|
|
25296
|
-
} finally {
|
|
25297
|
-
await
|
|
25298
|
-
}
|
|
25299
|
-
},
|
|
25300
|
-
async release() {
|
|
25301
|
-
if (released)
|
|
25302
|
-
return;
|
|
25303
|
-
released = true;
|
|
25304
|
-
await rm(lockPath, { force: true });
|
|
25305
|
-
}
|
|
25306
|
-
};
|
|
25307
|
-
}
|
|
25308
|
-
function processIsAlive(processId) {
|
|
25309
|
-
if (!Number.isSafeInteger(processId) || processId <= 0)
|
|
25310
|
-
return false;
|
|
25311
|
-
try {
|
|
25312
|
-
process.kill(processId, 0);
|
|
25313
|
-
return true;
|
|
25314
|
-
} catch (error62) {
|
|
25315
|
-
return error62.code === "EPERM";
|
|
25316
|
-
}
|
|
25317
|
-
}
|
|
25318
|
-
async function recoverUpdateOperationLock(stateDirectory) {
|
|
25319
|
-
const lockPath = path5.join(stateDirectory, LOCK_FILE);
|
|
25320
|
-
if (!await regularFile(lockPath))
|
|
25321
|
-
return;
|
|
25322
|
-
let ownerPid;
|
|
25323
|
-
let statusPath;
|
|
25324
|
-
let remoteUpdate = false;
|
|
25325
|
-
try {
|
|
25326
|
-
const value = JSON.parse(await readFile2(lockPath, "utf8"));
|
|
25327
|
-
ownerPid = value.ownerPid;
|
|
25328
|
-
statusPath = value.statusPath;
|
|
25329
|
-
remoteUpdate = value.remoteUpdate === true;
|
|
25330
|
-
} catch {
|
|
25331
|
-
return;
|
|
25332
|
-
}
|
|
25333
|
-
if (remoteUpdate && typeof ownerPid === "number" && Number.isSafeInteger(ownerPid) && ownerPid > 0 && !processIsAlive(ownerPid)) {
|
|
25334
|
-
await rm(lockPath, { force: true });
|
|
25335
|
-
return;
|
|
25336
|
-
}
|
|
25337
|
-
if (typeof statusPath !== "string" || !path5.isAbsolute(statusPath))
|
|
25338
|
-
return;
|
|
25339
|
-
try {
|
|
25340
|
-
const status = parseUpdateStatus(JSON.parse(await readFile2(statusPath, "utf8")));
|
|
25341
|
-
if (TERMINAL_PHASES.has(status.phase) || typeof ownerPid !== "number" || !processIsAlive(ownerPid)) {
|
|
25342
|
-
await rm(lockPath, { force: true });
|
|
25343
|
-
}
|
|
25344
|
-
} catch {
|
|
25345
|
-
}
|
|
25346
|
-
}
|
|
25347
|
-
|
|
25348
|
-
// packages/update-manager/dist/update-manager.js
|
|
25349
|
-
import { spawn } from "node:child_process";
|
|
25350
|
-
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
25351
|
-
import { chmod, copyFile, lstat as lstat3, mkdir as mkdir2, readFile as readFile3, rename as rename2, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
25352
|
-
import path6 from "node:path";
|
|
25353
|
-
|
|
25354
|
-
// packages/update-manager/dist/artifact.js
|
|
25355
|
-
import { createHash } from "node:crypto";
|
|
25356
|
-
import { createReadStream } from "node:fs";
|
|
25357
|
-
import { lstat as lstat2, open as open3 } from "node:fs/promises";
|
|
25358
|
-
var MAX_ARTIFACT_BYTES = 2 * 1024 * 1024 * 1024;
|
|
25359
|
-
var SHA256_PATTERN = /^[0-9a-f]{64}$/u;
|
|
25360
|
-
function validateArtifact(source) {
|
|
25361
|
-
const url2 = new URL(source.url);
|
|
25362
|
-
if (url2.protocol !== "https:" || url2.username || url2.password) {
|
|
25363
|
-
throw new Error("update artifact URL must use HTTPS without credentials");
|
|
25364
|
-
}
|
|
25365
|
-
if (!SHA256_PATTERN.test(source.sha256)) {
|
|
25366
|
-
throw new Error("update artifact SHA-256 must be lowercase hexadecimal");
|
|
25367
|
-
}
|
|
25368
|
-
if (source.size !== void 0 && (!Number.isSafeInteger(source.size) || source.size <= 0 || source.size > MAX_ARTIFACT_BYTES)) {
|
|
25369
|
-
throw new Error(`update artifact size must be between 1 and ${MAX_ARTIFACT_BYTES} bytes`);
|
|
25370
|
-
}
|
|
25371
|
-
return source;
|
|
25372
|
-
}
|
|
25373
|
-
async function writeChunk(file2, chunk) {
|
|
25374
|
-
let offset = 0;
|
|
25375
|
-
while (offset < chunk.byteLength) {
|
|
25376
|
-
const result = await file2.write(chunk, offset, chunk.byteLength - offset, null);
|
|
25377
|
-
if (result.bytesWritten === 0)
|
|
25378
|
-
throw new Error("update artifact write made no progress");
|
|
25379
|
-
offset += result.bytesWritten;
|
|
25380
|
-
}
|
|
25381
|
-
}
|
|
25382
|
-
async function downloadArtifact(source, destination, onProgress) {
|
|
25383
|
-
const response = await fetch(source.url, {
|
|
25384
|
-
redirect: "follow",
|
|
25385
|
-
headers: { "accept-encoding": "identity" }
|
|
25386
|
-
});
|
|
25387
|
-
if (!response.ok || response.body === null) {
|
|
25388
|
-
throw new Error(`update artifact download failed with HTTP ${response.status}`);
|
|
25389
|
-
}
|
|
25390
|
-
const finalUrl = new URL(response.url);
|
|
25391
|
-
if (finalUrl.protocol !== "https:" || finalUrl.username || finalUrl.password) {
|
|
25392
|
-
throw new Error("update artifact redirected to a non-HTTPS URL");
|
|
25393
|
-
}
|
|
25394
|
-
const file2 = await open3(destination, "wx", 384);
|
|
25395
|
-
let bytes = 0;
|
|
25396
|
-
try {
|
|
25397
|
-
const reader = response.body.getReader();
|
|
25398
|
-
while (true) {
|
|
25399
|
-
const item = await reader.read();
|
|
25400
|
-
if (item.done)
|
|
25401
|
-
break;
|
|
25402
|
-
bytes += item.value.byteLength;
|
|
25403
|
-
if (bytes > MAX_ARTIFACT_BYTES) {
|
|
25404
|
-
await reader.cancel();
|
|
25405
|
-
throw new Error(`update artifact exceeds ${MAX_ARTIFACT_BYTES} bytes`);
|
|
26395
|
+
const temporary = `${lockPath}.${randomUUID2()}.tmp`;
|
|
26396
|
+
try {
|
|
26397
|
+
await writeFile2(temporary, `${JSON.stringify({ ownerPid, statusPath: operationStatusPath })}
|
|
26398
|
+
`, {
|
|
26399
|
+
encoding: "utf8",
|
|
26400
|
+
mode: 384,
|
|
26401
|
+
flag: "wx"
|
|
26402
|
+
});
|
|
26403
|
+
await rename2(temporary, lockPath);
|
|
26404
|
+
} finally {
|
|
26405
|
+
await rm2(temporary, { force: true });
|
|
25406
26406
|
}
|
|
25407
|
-
|
|
25408
|
-
|
|
26407
|
+
},
|
|
26408
|
+
async release() {
|
|
26409
|
+
if (released)
|
|
26410
|
+
return;
|
|
26411
|
+
released = true;
|
|
26412
|
+
await rm2(lockPath, { force: true });
|
|
25409
26413
|
}
|
|
25410
|
-
|
|
25411
|
-
} finally {
|
|
25412
|
-
await file2.close();
|
|
25413
|
-
}
|
|
25414
|
-
return { bytes, finalUrl: finalUrl.toString() };
|
|
25415
|
-
}
|
|
25416
|
-
async function sha256File(filePath2) {
|
|
25417
|
-
const hash2 = createHash("sha256");
|
|
25418
|
-
await new Promise((resolve, reject) => {
|
|
25419
|
-
const stream = createReadStream(filePath2);
|
|
25420
|
-
stream.on("data", (chunk) => hash2.update(chunk));
|
|
25421
|
-
stream.once("error", reject);
|
|
25422
|
-
stream.once("end", resolve);
|
|
25423
|
-
});
|
|
25424
|
-
return hash2.digest("hex");
|
|
26414
|
+
};
|
|
25425
26415
|
}
|
|
25426
|
-
|
|
25427
|
-
|
|
25428
|
-
|
|
25429
|
-
|
|
26416
|
+
function processIsAlive2(processId) {
|
|
26417
|
+
if (!Number.isSafeInteger(processId) || processId <= 0)
|
|
26418
|
+
return false;
|
|
26419
|
+
try {
|
|
26420
|
+
process.kill(processId, 0);
|
|
26421
|
+
return true;
|
|
26422
|
+
} catch (error62) {
|
|
26423
|
+
return error62.code === "EPERM";
|
|
25430
26424
|
}
|
|
25431
|
-
|
|
25432
|
-
|
|
26425
|
+
}
|
|
26426
|
+
async function recoverUpdateOperationLock(stateDirectory) {
|
|
26427
|
+
const lockPath = path6.join(stateDirectory, LOCK_FILE);
|
|
26428
|
+
if (!await regularFile2(lockPath))
|
|
26429
|
+
return;
|
|
26430
|
+
let ownerPid;
|
|
26431
|
+
let statusPath;
|
|
26432
|
+
let remoteUpdate = false;
|
|
26433
|
+
try {
|
|
26434
|
+
const value = JSON.parse(await readFile4(lockPath, "utf8"));
|
|
26435
|
+
ownerPid = value.ownerPid;
|
|
26436
|
+
statusPath = value.statusPath;
|
|
26437
|
+
remoteUpdate = value.remoteUpdate === true;
|
|
26438
|
+
} catch {
|
|
26439
|
+
return;
|
|
25433
26440
|
}
|
|
25434
|
-
if (
|
|
25435
|
-
|
|
26441
|
+
if (remoteUpdate && typeof ownerPid === "number" && Number.isSafeInteger(ownerPid) && ownerPid > 0 && !processIsAlive2(ownerPid)) {
|
|
26442
|
+
await rm2(lockPath, { force: true });
|
|
26443
|
+
return;
|
|
25436
26444
|
}
|
|
25437
|
-
|
|
25438
|
-
|
|
25439
|
-
|
|
26445
|
+
if (typeof statusPath !== "string" || !path6.isAbsolute(statusPath))
|
|
26446
|
+
return;
|
|
26447
|
+
try {
|
|
26448
|
+
const status = parseUpdateStatus(JSON.parse(await readFile4(statusPath, "utf8")));
|
|
26449
|
+
if (TERMINAL_PHASES.has(status.phase) || typeof ownerPid !== "number" || !processIsAlive2(ownerPid)) {
|
|
26450
|
+
await rm2(lockPath, { force: true });
|
|
26451
|
+
}
|
|
26452
|
+
} catch {
|
|
25440
26453
|
}
|
|
25441
26454
|
}
|
|
25442
26455
|
|
|
26456
|
+
// packages/update-manager/dist/update-manager.js
|
|
26457
|
+
import { spawn } from "node:child_process";
|
|
26458
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
26459
|
+
import { chmod, copyFile, lstat as lstat5, mkdir as mkdir3, readFile as readFile5, rename as rename3, rm as rm3, writeFile as writeFile3 } from "node:fs/promises";
|
|
26460
|
+
import path7 from "node:path";
|
|
26461
|
+
|
|
25443
26462
|
// packages/update-manager/dist/updater-ready.js
|
|
25444
|
-
import { setTimeout as
|
|
26463
|
+
import { setTimeout as delay2 } from "node:timers/promises";
|
|
25445
26464
|
async function waitForUpdaterReady(child, readStatus, timeoutMs = 1e4, beforeWait) {
|
|
25446
26465
|
let failure2;
|
|
25447
26466
|
const onError = (error62) => {
|
|
@@ -25472,7 +26491,7 @@ async function waitForUpdaterReady(child, readStatus, timeoutMs = 1e4, beforeWai
|
|
|
25472
26491
|
if (performance.now() >= deadline) {
|
|
25473
26492
|
throw new Error("Background Updater did not confirm handoff before the startup timeout");
|
|
25474
26493
|
}
|
|
25475
|
-
await
|
|
26494
|
+
await delay2(20);
|
|
25476
26495
|
}
|
|
25477
26496
|
} catch (error62) {
|
|
25478
26497
|
child.kill();
|
|
@@ -25485,41 +26504,41 @@ async function waitForUpdaterReady(child, readStatus, timeoutMs = 1e4, beforeWai
|
|
|
25485
26504
|
|
|
25486
26505
|
// packages/update-manager/dist/update-manager.js
|
|
25487
26506
|
var REQUEST_SCHEMA_VERSION = 1;
|
|
25488
|
-
var
|
|
26507
|
+
var WINDOWS_RENAME_RETRY_DELAYS_MS2 = [10, 30, 70, 150, 300];
|
|
25489
26508
|
function errorMessage(error62) {
|
|
25490
26509
|
return error62 instanceof Error ? error62.message : String(error62);
|
|
25491
26510
|
}
|
|
25492
|
-
function
|
|
26511
|
+
function systemErrorCode2(error62) {
|
|
25493
26512
|
return typeof error62 === "object" && error62 !== null && "code" in error62 ? String(error62.code) : null;
|
|
25494
26513
|
}
|
|
25495
|
-
function
|
|
26514
|
+
function delay3(milliseconds) {
|
|
25496
26515
|
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
25497
26516
|
}
|
|
25498
26517
|
async function replaceStatusFile(temporaryPath, statusPath) {
|
|
25499
26518
|
let retryIndex = 0;
|
|
25500
26519
|
for (; ; ) {
|
|
25501
26520
|
try {
|
|
25502
|
-
await
|
|
26521
|
+
await rename3(temporaryPath, statusPath);
|
|
25503
26522
|
return;
|
|
25504
26523
|
} catch (error62) {
|
|
25505
|
-
const retryDelay =
|
|
25506
|
-
const code =
|
|
26524
|
+
const retryDelay = WINDOWS_RENAME_RETRY_DELAYS_MS2[retryIndex];
|
|
26525
|
+
const code = systemErrorCode2(error62);
|
|
25507
26526
|
if (process.platform !== "win32" || retryDelay === void 0 || code !== "EACCES" && code !== "EBUSY" && code !== "EPERM") {
|
|
25508
26527
|
throw error62;
|
|
25509
26528
|
}
|
|
25510
26529
|
retryIndex += 1;
|
|
25511
|
-
await
|
|
26530
|
+
await delay3(retryDelay);
|
|
25512
26531
|
}
|
|
25513
26532
|
}
|
|
25514
26533
|
}
|
|
25515
26534
|
function requireAbsolutePath(value, label) {
|
|
25516
|
-
if (!
|
|
26535
|
+
if (!path7.isAbsolute(value))
|
|
25517
26536
|
throw new Error(`${label} must be an absolute path`);
|
|
25518
|
-
return
|
|
26537
|
+
return path7.normalize(value);
|
|
25519
26538
|
}
|
|
25520
26539
|
async function requireRegularFile(value, label) {
|
|
25521
26540
|
const filePath2 = requireAbsolutePath(value, label);
|
|
25522
|
-
const metadata = await
|
|
26541
|
+
const metadata = await lstat5(filePath2).catch((error62) => {
|
|
25523
26542
|
throw new Error(`${label} is unavailable: ${errorMessage(error62)}`);
|
|
25524
26543
|
});
|
|
25525
26544
|
if (!metadata.isFile() || metadata.isSymbolicLink()) {
|
|
@@ -25534,7 +26553,7 @@ function requireLauncherPid(value) {
|
|
|
25534
26553
|
return value;
|
|
25535
26554
|
}
|
|
25536
26555
|
async function writePrivateJson(filePath2, value) {
|
|
25537
|
-
await
|
|
26556
|
+
await writeFile3(filePath2, `${JSON.stringify(value)}
|
|
25538
26557
|
`, {
|
|
25539
26558
|
encoding: "utf8",
|
|
25540
26559
|
mode: 384,
|
|
@@ -25552,16 +26571,18 @@ function defaultSpawnUpdater(executable, requestPath) {
|
|
|
25552
26571
|
}
|
|
25553
26572
|
function createBackgroundUpdateManager(dependencies = {}) {
|
|
25554
26573
|
const platform = dependencies.platform ?? process.platform;
|
|
25555
|
-
const randomId = dependencies.randomId ??
|
|
26574
|
+
const randomId = dependencies.randomId ?? randomUUID3;
|
|
25556
26575
|
const download2 = dependencies.download ?? downloadArtifact;
|
|
25557
26576
|
const spawnUpdater = dependencies.spawnUpdater ?? defaultSpawnUpdater;
|
|
25558
26577
|
const prefetchNpm = dependencies.prefetchNpm ?? ((target2, onProgress) => prefetchNpmRelease(target2, void 0, onProgress));
|
|
26578
|
+
const resolveNpmConfig = dependencies.resolveNpmConfiguration ?? (dependencies.prefetchNpm ? void 0 : resolveNpmConfiguration);
|
|
26579
|
+
const resolveNpmCacheFiles = dependencies.resolveNpmPackageCacheFiles ?? (dependencies.prefetchNpm ? void 0 : resolveNpmPackageCacheFiles);
|
|
25559
26580
|
const now = dependencies.now ?? Date.now;
|
|
25560
26581
|
const preparedRequests = /* @__PURE__ */ new Set();
|
|
25561
26582
|
async function writeStatusSnapshot(statusPath, status) {
|
|
25562
|
-
const temporaryPath =
|
|
26583
|
+
const temporaryPath = path7.join(path7.dirname(statusPath), `.update-status-${randomId()}.tmp`);
|
|
25563
26584
|
try {
|
|
25564
|
-
await
|
|
26585
|
+
await writeFile3(temporaryPath, `${JSON.stringify(status)}
|
|
25565
26586
|
`, {
|
|
25566
26587
|
encoding: "utf8",
|
|
25567
26588
|
mode: 384,
|
|
@@ -25569,7 +26590,7 @@ function createBackgroundUpdateManager(dependencies = {}) {
|
|
|
25569
26590
|
});
|
|
25570
26591
|
await replaceStatusFile(temporaryPath, statusPath);
|
|
25571
26592
|
} catch (error62) {
|
|
25572
|
-
await
|
|
26593
|
+
await rm3(temporaryPath, { force: true });
|
|
25573
26594
|
throw error62;
|
|
25574
26595
|
}
|
|
25575
26596
|
}
|
|
@@ -25623,16 +26644,16 @@ function createBackgroundUpdateManager(dependencies = {}) {
|
|
|
25623
26644
|
throw new Error("Invalid update restart target");
|
|
25624
26645
|
if ((options.serviceManaged || options.restartTarget === "web") && !dataDirectory2)
|
|
25625
26646
|
throw new Error("Service updates require a data directory");
|
|
25626
|
-
await
|
|
25627
|
-
const workDirectory =
|
|
25628
|
-
await
|
|
26647
|
+
await mkdir3(stateDirectory, { recursive: true, mode: 448 });
|
|
26648
|
+
const workDirectory = path7.join(stateDirectory, `update-${version2}-${randomId()}`);
|
|
26649
|
+
await mkdir3(workDirectory, { recursive: false, mode: 448 });
|
|
25629
26650
|
const executableSuffix = platform === "win32" ? ".exe" : "";
|
|
25630
|
-
const helperPath =
|
|
26651
|
+
const helperPath = path7.join(workDirectory, `codexhost-updater${executableSuffix}`);
|
|
25631
26652
|
await copyFile(updaterExecutable, helperPath);
|
|
25632
26653
|
if (platform !== "win32")
|
|
25633
26654
|
await chmod(helperPath, 448);
|
|
25634
|
-
const requestPath =
|
|
25635
|
-
const statusPath =
|
|
26655
|
+
const requestPath = path7.join(workDirectory, "request-v1.json");
|
|
26656
|
+
const statusPath = path7.join(workDirectory, "status-v1.json");
|
|
25636
26657
|
await writePrivateJson(statusPath, statusSnapshot(version2, installation, "downloading"));
|
|
25637
26658
|
await options.onPrepared?.({ version: version2, installation, statusPath });
|
|
25638
26659
|
return {
|
|
@@ -25640,6 +26661,7 @@ function createBackgroundUpdateManager(dependencies = {}) {
|
|
|
25640
26661
|
launcherPid,
|
|
25641
26662
|
launcherExecutable,
|
|
25642
26663
|
runtimeDescriptorPath,
|
|
26664
|
+
stateDirectory,
|
|
25643
26665
|
workDirectory,
|
|
25644
26666
|
helperPath,
|
|
25645
26667
|
requestPath,
|
|
@@ -25649,12 +26671,39 @@ function createBackgroundUpdateManager(dependencies = {}) {
|
|
|
25649
26671
|
...dataDirectory2 ? { dataDirectory: dataDirectory2 } : {}
|
|
25650
26672
|
};
|
|
25651
26673
|
}
|
|
25652
|
-
async function
|
|
25653
|
-
const
|
|
25654
|
-
|
|
26674
|
+
async function tryReuseStagedArtifact(common, source, temporaryPath) {
|
|
26675
|
+
const staged = await readStagedUpdate(common.stateDirectory);
|
|
26676
|
+
if (!staged || staged.version !== common.version)
|
|
26677
|
+
return null;
|
|
26678
|
+
const verified = await verifyStagedArtifact(common.stateDirectory, staged, source);
|
|
26679
|
+
if (!verified)
|
|
26680
|
+
return null;
|
|
26681
|
+
try {
|
|
26682
|
+
await copyFile(verified.artifactPath, temporaryPath);
|
|
26683
|
+
if (platform !== "win32")
|
|
26684
|
+
await chmod(temporaryPath, 384);
|
|
26685
|
+
return await verifyArtifactFile(source, temporaryPath);
|
|
26686
|
+
} catch {
|
|
26687
|
+
await rm3(temporaryPath, { force: true });
|
|
26688
|
+
return null;
|
|
26689
|
+
}
|
|
26690
|
+
}
|
|
26691
|
+
async function prepareArtifact(common, installation, sourceValue, fileName, waitForStaged) {
|
|
26692
|
+
const temporaryPath = path7.join(common.workDirectory, `.${fileName}.download`);
|
|
26693
|
+
const artifactPath = path7.join(common.workDirectory, fileName);
|
|
25655
26694
|
let progress;
|
|
25656
26695
|
try {
|
|
25657
26696
|
const source = validateArtifact(sourceValue);
|
|
26697
|
+
await waitForStaged?.();
|
|
26698
|
+
const reusedSize = await tryReuseStagedArtifact(common, source, temporaryPath);
|
|
26699
|
+
if (reusedSize !== null) {
|
|
26700
|
+
await writeStatusSnapshot(common.statusPath, statusSnapshot(common.version, installation, "downloading", {
|
|
26701
|
+
downloadedBytes: reusedSize,
|
|
26702
|
+
totalBytes: source.size ?? reusedSize
|
|
26703
|
+
}));
|
|
26704
|
+
await rename3(temporaryPath, artifactPath);
|
|
26705
|
+
return { source, artifactPath };
|
|
26706
|
+
}
|
|
25658
26707
|
progress = progressReporter(common.statusPath, common.version, installation, source.size);
|
|
25659
26708
|
const result = await download2(source, temporaryPath, progress.update);
|
|
25660
26709
|
progress.update({ downloadedBytes: result.bytes, totalBytes: source.size });
|
|
@@ -25664,10 +26713,10 @@ function createBackgroundUpdateManager(dependencies = {}) {
|
|
|
25664
26713
|
throw new Error("update artifact downloader returned a non-HTTPS URL");
|
|
25665
26714
|
}
|
|
25666
26715
|
await verifyDownloadedArtifact(source, temporaryPath, result);
|
|
25667
|
-
await
|
|
26716
|
+
await rename3(temporaryPath, artifactPath);
|
|
25668
26717
|
return { source, artifactPath };
|
|
25669
26718
|
} catch (error62) {
|
|
25670
|
-
await
|
|
26719
|
+
await rm3(temporaryPath, { force: true });
|
|
25671
26720
|
await progress?.flush();
|
|
25672
26721
|
await writeFailedStatus(common.statusPath, common.version, installation, error62);
|
|
25673
26722
|
throw error62;
|
|
@@ -25710,16 +26759,30 @@ function createBackgroundUpdateManager(dependencies = {}) {
|
|
|
25710
26759
|
const nodePath = await requireRegularFile(options.nodePath, "npm Node.js executable");
|
|
25711
26760
|
const npmCliPath = await requireRegularFile(options.npmCliPath, "npm CLI");
|
|
25712
26761
|
const packageRoot = requireAbsolutePath(options.packageRoot, "npm platform package root");
|
|
25713
|
-
await
|
|
25714
|
-
|
|
25715
|
-
|
|
25716
|
-
|
|
26762
|
+
await options.waitForStaged?.();
|
|
26763
|
+
const target2 = { nodePath, npmCliPath, packageRoot, version: common.version };
|
|
26764
|
+
const configuration = resolveNpmConfig ? await resolveNpmConfig(target2) : void 0;
|
|
26765
|
+
const expectedConfigSha256 = options.npmConfigSha256 ?? configuration?.digest;
|
|
26766
|
+
const staged = await readStagedUpdate(common.stateDirectory);
|
|
26767
|
+
const alreadyStaged = staged !== null && await verifyStagedNpm(staged, {
|
|
26768
|
+
version: common.version,
|
|
26769
|
+
...options.target ? { target: options.target } : {},
|
|
26770
|
+
...expectedConfigSha256 ? { npmConfigSha256: expectedConfigSha256 } : {},
|
|
26771
|
+
...configuration ? { npmCacheDirectory: configuration.cacheDirectory } : {}
|
|
26772
|
+
});
|
|
26773
|
+
if (!alreadyStaged) {
|
|
26774
|
+
await prefetchNpm({ ...target2, ...configuration ? { configuration: configuration.environment } : {} }, (npmDownload) => writeStatusSnapshot(common.statusPath, {
|
|
26775
|
+
...statusSnapshot(common.version, "npm", "downloading"),
|
|
26776
|
+
npmDownload
|
|
26777
|
+
}).catch(() => void 0));
|
|
26778
|
+
}
|
|
25717
26779
|
return await finalize2(common, {
|
|
25718
26780
|
kind: "npm",
|
|
25719
26781
|
node_path: nodePath,
|
|
25720
26782
|
npm_cli_path: npmCliPath,
|
|
25721
26783
|
npm_launcher_path: await requireRegularFile(options.npmLauncherPath, "npm codexhost launcher"),
|
|
25722
|
-
npm_package_root: packageRoot
|
|
26784
|
+
npm_package_root: packageRoot,
|
|
26785
|
+
...configuration ? { npm_config_sha256: configuration.digest } : {}
|
|
25723
26786
|
});
|
|
25724
26787
|
} catch (error62) {
|
|
25725
26788
|
await writeFailedStatus(common.statusPath, common.version, "npm", error62);
|
|
@@ -25731,7 +26794,7 @@ function createBackgroundUpdateManager(dependencies = {}) {
|
|
|
25731
26794
|
throw new Error("Windows installer updates require Windows");
|
|
25732
26795
|
const installRoot = requireAbsolutePath(options.installRoot, "Windows install root");
|
|
25733
26796
|
const common = await prepareCommon(options, "windows-installer");
|
|
25734
|
-
const artifact = await prepareArtifact(common, "windows-installer", options.artifact, "update.exe");
|
|
26797
|
+
const artifact = await prepareArtifact(common, "windows-installer", options.artifact, "update.exe", options.waitForStaged);
|
|
25735
26798
|
return finalize2(common, {
|
|
25736
26799
|
kind: "windows-installer",
|
|
25737
26800
|
installer_path: artifact.artifactPath,
|
|
@@ -25743,11 +26806,11 @@ function createBackgroundUpdateManager(dependencies = {}) {
|
|
|
25743
26806
|
if (platform !== "darwin")
|
|
25744
26807
|
throw new Error("macOS DMG updates require macOS");
|
|
25745
26808
|
const appPath = requireAbsolutePath(options.appPath, "macOS application path");
|
|
25746
|
-
if (
|
|
26809
|
+
if (path7.extname(appPath) !== ".app") {
|
|
25747
26810
|
throw new Error("macOS application path must end in .app");
|
|
25748
26811
|
}
|
|
25749
26812
|
const common = await prepareCommon(options, "macos-dmg");
|
|
25750
|
-
const artifact = await prepareArtifact(common, "macos-dmg", options.artifact, "update.dmg");
|
|
26813
|
+
const artifact = await prepareArtifact(common, "macos-dmg", options.artifact, "update.dmg", options.waitForStaged);
|
|
25751
26814
|
return finalize2(common, {
|
|
25752
26815
|
kind: "macos-dmg",
|
|
25753
26816
|
dmg_path: artifact.artifactPath,
|
|
@@ -25760,7 +26823,7 @@ function createBackgroundUpdateManager(dependencies = {}) {
|
|
|
25760
26823
|
throw new Error("Linux archive updates require Linux");
|
|
25761
26824
|
const installRoot = requireAbsolutePath(options.installRoot, "Linux install root");
|
|
25762
26825
|
const common = await prepareCommon(options, "linux-archive");
|
|
25763
|
-
const artifact = await prepareArtifact(common, "linux-archive", options.artifact, "update.tar.gz");
|
|
26826
|
+
const artifact = await prepareArtifact(common, "linux-archive", options.artifact, "update.tar.gz", options.waitForStaged);
|
|
25764
26827
|
return finalize2(common, {
|
|
25765
26828
|
kind: "linux-archive",
|
|
25766
26829
|
archive_path: artifact.artifactPath,
|
|
@@ -25768,6 +26831,48 @@ function createBackgroundUpdateManager(dependencies = {}) {
|
|
|
25768
26831
|
install_root: installRoot
|
|
25769
26832
|
}, artifact.artifactPath);
|
|
25770
26833
|
},
|
|
26834
|
+
stageArtifact(options) {
|
|
26835
|
+
return stageArtifact({
|
|
26836
|
+
...options,
|
|
26837
|
+
download: download2,
|
|
26838
|
+
now
|
|
26839
|
+
});
|
|
26840
|
+
},
|
|
26841
|
+
async stageNpm(options) {
|
|
26842
|
+
const configuration = resolveNpmConfig ? await resolveNpmConfig(options.npmTarget) : void 0;
|
|
26843
|
+
const npmTarget = {
|
|
26844
|
+
...options.npmTarget,
|
|
26845
|
+
...configuration ? { configuration: configuration.environment } : {}
|
|
26846
|
+
};
|
|
26847
|
+
const npmConfigSha256 = options.npmConfigSha256 ?? configuration?.digest;
|
|
26848
|
+
const npmCacheDirectory = options.npmCacheDirectory ?? configuration?.cacheDirectory;
|
|
26849
|
+
const resolveCacheFiles = options.resolveCacheFiles ?? resolveNpmCacheFiles;
|
|
26850
|
+
return stageNpm({
|
|
26851
|
+
...options,
|
|
26852
|
+
npmTarget,
|
|
26853
|
+
...npmConfigSha256 ? { npmConfigSha256 } : {},
|
|
26854
|
+
...npmCacheDirectory ? { npmCacheDirectory } : {},
|
|
26855
|
+
...resolveCacheFiles ? { resolveCacheFiles } : {},
|
|
26856
|
+
prefetchNpm: (target2, onProgress) => prefetchNpm(target2, async (progress) => {
|
|
26857
|
+
await onProgress?.(progress);
|
|
26858
|
+
}),
|
|
26859
|
+
now
|
|
26860
|
+
});
|
|
26861
|
+
},
|
|
26862
|
+
async verifyStagedNpm(options) {
|
|
26863
|
+
const staged = await readStagedUpdate(options.stateDirectory);
|
|
26864
|
+
if (!staged)
|
|
26865
|
+
return false;
|
|
26866
|
+
const configuration = resolveNpmConfig ? await resolveNpmConfig(options.npmTarget).catch(() => null) : void 0;
|
|
26867
|
+
if (configuration === null)
|
|
26868
|
+
return false;
|
|
26869
|
+
return verifyStagedNpm(staged, {
|
|
26870
|
+
version: options.npmTarget.version,
|
|
26871
|
+
...options.target ? { target: options.target } : {},
|
|
26872
|
+
...configuration ? { npmConfigSha256: configuration.digest } : {},
|
|
26873
|
+
...configuration ? { npmCacheDirectory: configuration.cacheDirectory } : {}
|
|
26874
|
+
});
|
|
26875
|
+
},
|
|
25771
26876
|
async start(prepared, transferOwnership) {
|
|
25772
26877
|
if (!preparedRequests.delete(prepared.requestPath)) {
|
|
25773
26878
|
throw new Error("background update was not prepared by this manager or was already started");
|
|
@@ -25788,7 +26893,7 @@ function createBackgroundUpdateManager(dependencies = {}) {
|
|
|
25788
26893
|
async readStatus(statusPathValue) {
|
|
25789
26894
|
const statusPath = requireAbsolutePath(statusPathValue, "update status path");
|
|
25790
26895
|
try {
|
|
25791
|
-
return parseUpdateStatus(JSON.parse(await
|
|
26896
|
+
return parseUpdateStatus(JSON.parse(await readFile5(statusPath, "utf8")));
|
|
25792
26897
|
} catch (error62) {
|
|
25793
26898
|
if (error62.code === "ENOENT")
|
|
25794
26899
|
return null;
|
|
@@ -25799,24 +26904,24 @@ function createBackgroundUpdateManager(dependencies = {}) {
|
|
|
25799
26904
|
}
|
|
25800
26905
|
|
|
25801
26906
|
// packages/console-server/src/harnesses.ts
|
|
25802
|
-
import
|
|
26907
|
+
import path15 from "node:path";
|
|
25803
26908
|
|
|
25804
26909
|
// packages/harness-plugin-files/dist/discovery.js
|
|
25805
|
-
import { readdir as
|
|
25806
|
-
import
|
|
26910
|
+
import { readdir as readdir3, realpath as realpath4 } from "node:fs/promises";
|
|
26911
|
+
import path9 from "node:path";
|
|
25807
26912
|
|
|
25808
26913
|
// packages/harness-plugin-files/dist/plugin-files.js
|
|
25809
|
-
import { open as
|
|
25810
|
-
import
|
|
26914
|
+
import { open as open5, realpath as realpath3, stat } from "node:fs/promises";
|
|
26915
|
+
import path8 from "node:path";
|
|
25811
26916
|
function inside(root, candidate) {
|
|
25812
|
-
const relative =
|
|
25813
|
-
return relative !== "" && !
|
|
26917
|
+
const relative = path8.relative(root, candidate);
|
|
26918
|
+
return relative !== "" && !path8.isAbsolute(relative) && relative !== ".." && !relative.startsWith(`..${path8.sep}`);
|
|
25814
26919
|
}
|
|
25815
26920
|
async function pluginResourcePath(root, relative) {
|
|
25816
|
-
if (
|
|
26921
|
+
if (path8.isAbsolute(relative) || !inside(root, path8.resolve(root, relative))) {
|
|
25817
26922
|
throw new Error("Plugin resource escapes its root");
|
|
25818
26923
|
}
|
|
25819
|
-
const resolved = await
|
|
26924
|
+
const resolved = await realpath3(path8.resolve(root, relative));
|
|
25820
26925
|
if (!inside(root, resolved) || !(await stat(resolved)).isFile()) {
|
|
25821
26926
|
throw new Error("Plugin resource must be a regular file inside its root");
|
|
25822
26927
|
}
|
|
@@ -25825,7 +26930,7 @@ async function pluginResourcePath(root, relative) {
|
|
|
25825
26930
|
async function readPluginFile(file2, maximum) {
|
|
25826
26931
|
if (!(await stat(file2)).isFile())
|
|
25827
26932
|
throw new Error("Plugin resource is not a regular file");
|
|
25828
|
-
const handle = await
|
|
26933
|
+
const handle = await open5(file2, "r");
|
|
25829
26934
|
try {
|
|
25830
26935
|
const info = await handle.stat();
|
|
25831
26936
|
if (!info.isFile() || info.size > maximum)
|
|
@@ -25880,13 +26985,13 @@ async function discoverHarnessPlugins(configuredRoots, diagnose = () => void 0,
|
|
|
25880
26985
|
const enabledIds = /* @__PURE__ */ new Set();
|
|
25881
26986
|
const roots = /* @__PURE__ */ new Set();
|
|
25882
26987
|
for (const configuredRoot of configuredRoots) {
|
|
25883
|
-
if (!
|
|
26988
|
+
if (!path9.isAbsolute(configuredRoot)) {
|
|
25884
26989
|
diagnose("invalidRoot");
|
|
25885
26990
|
continue;
|
|
25886
26991
|
}
|
|
25887
26992
|
let root;
|
|
25888
26993
|
try {
|
|
25889
|
-
root = await
|
|
26994
|
+
root = await realpath4(configuredRoot);
|
|
25890
26995
|
if (roots.has(root))
|
|
25891
26996
|
continue;
|
|
25892
26997
|
roots.add(root);
|
|
@@ -25906,7 +27011,7 @@ async function discoverHarnessPlugins(configuredRoots, diagnose = () => void 0,
|
|
|
25906
27011
|
for (const id2 of enabled)
|
|
25907
27012
|
enabledIds.add(id2);
|
|
25908
27013
|
try {
|
|
25909
|
-
const directories = (await
|
|
27014
|
+
const directories = (await readdir3(root, { withFileTypes: true })).filter((entry) => entry.isDirectory() || entry.isSymbolicLink()).sort((a, b) => a.name.localeCompare(b.name));
|
|
25910
27015
|
if (directories.length > HARNESS_PLUGIN_LIMIT) {
|
|
25911
27016
|
diagnose("invalidRoot");
|
|
25912
27017
|
continue;
|
|
@@ -25914,7 +27019,7 @@ async function discoverHarnessPlugins(configuredRoots, diagnose = () => void 0,
|
|
|
25914
27019
|
for (const directory of directories) {
|
|
25915
27020
|
try {
|
|
25916
27021
|
const file2 = await pluginResourcePath(root, `${directory.name}/manifest.json`);
|
|
25917
|
-
const pluginRoot = await
|
|
27022
|
+
const pluginRoot = await realpath4(path9.join(root, directory.name));
|
|
25918
27023
|
await pluginResourcePath(pluginRoot, "manifest.json");
|
|
25919
27024
|
const manifest = harnessPluginManifestSchema.parse(JSON.parse((await readPluginFile(file2, HARNESS_PLUGIN_MANIFEST_MAX_BYTES)).toString("utf8")));
|
|
25920
27025
|
plugins.push({ root: pluginRoot, manifest, enabled: enabled.has(manifest.id) });
|
|
@@ -25930,24 +27035,24 @@ async function discoverHarnessPlugins(configuredRoots, diagnose = () => void 0,
|
|
|
25930
27035
|
}
|
|
25931
27036
|
|
|
25932
27037
|
// packages/harness-plugin-files/dist/launch-settings.js
|
|
25933
|
-
import { randomUUID as
|
|
25934
|
-
import { mkdir as
|
|
27038
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
27039
|
+
import { mkdir as mkdir4, readFile as readFile6, rename as rename4, rm as rm4, stat as stat2, writeFile as writeFile4 } from "node:fs/promises";
|
|
25935
27040
|
import os from "node:os";
|
|
25936
|
-
import
|
|
27041
|
+
import path10 from "node:path";
|
|
25937
27042
|
var HarnessLaunchSettingsStore = class {
|
|
25938
27043
|
#directory;
|
|
25939
27044
|
#initial = /* @__PURE__ */ new Map();
|
|
25940
27045
|
constructor(environment) {
|
|
25941
|
-
this.#directory =
|
|
27046
|
+
this.#directory = path10.join(environment.CODEXHOST_DATA_DIR ? path10.resolve(environment.CODEXHOST_DATA_DIR) : path10.join(os.homedir(), ".codexhost"), "harness-launch-settings");
|
|
25942
27047
|
}
|
|
25943
27048
|
#file(id2) {
|
|
25944
|
-
return
|
|
27049
|
+
return path10.join(this.#directory, `${harnessPluginIdSchema.parse(id2)}.json`);
|
|
25945
27050
|
}
|
|
25946
27051
|
async #read(id2) {
|
|
25947
27052
|
const file2 = this.#file(id2);
|
|
25948
27053
|
let text2;
|
|
25949
27054
|
try {
|
|
25950
|
-
text2 = await
|
|
27055
|
+
text2 = await readFile6(file2, "utf8");
|
|
25951
27056
|
} catch (error62) {
|
|
25952
27057
|
if (error62 && typeof error62 === "object" && "code" in error62 && error62.code === "ENOENT")
|
|
25953
27058
|
return null;
|
|
@@ -25958,7 +27063,7 @@ var HarnessLaunchSettingsStore = class {
|
|
|
25958
27063
|
parsed = harnessLaunchPathSchema.parse(JSON.parse(text2));
|
|
25959
27064
|
} catch {
|
|
25960
27065
|
}
|
|
25961
|
-
if (parsed === void 0 || !
|
|
27066
|
+
if (parsed === void 0 || !path10.isAbsolute(parsed)) {
|
|
25962
27067
|
throw new Error(`Could not read Harness launch settings at ${file2}: expected an absolute installation path; save a new path or reset it`);
|
|
25963
27068
|
}
|
|
25964
27069
|
return parsed;
|
|
@@ -25998,22 +27103,22 @@ var HarnessLaunchSettingsStore = class {
|
|
|
25998
27103
|
const snapshot = await this.#snapshot(id2);
|
|
25999
27104
|
const file2 = this.#file(id2);
|
|
26000
27105
|
if (value === null) {
|
|
26001
|
-
await
|
|
27106
|
+
await rm4(file2, { force: true });
|
|
26002
27107
|
} else {
|
|
26003
27108
|
value = harnessLaunchPathSchema.parse(value);
|
|
26004
|
-
if (!
|
|
27109
|
+
if (!path10.isAbsolute(value))
|
|
26005
27110
|
throw new Error("Use an absolute entrypoint path without arguments");
|
|
26006
27111
|
const metadata = await stat2(value).catch(() => void 0);
|
|
26007
27112
|
if (!metadata?.isDirectory() && !metadata?.isFile())
|
|
26008
27113
|
throw new Error("The installation path must be an existing directory on this Host");
|
|
26009
|
-
await
|
|
26010
|
-
const temporary = `${file2}.${
|
|
27114
|
+
await mkdir4(this.#directory, { recursive: true, mode: 448 });
|
|
27115
|
+
const temporary = `${file2}.${randomUUID4()}.tmp`;
|
|
26011
27116
|
try {
|
|
26012
|
-
await
|
|
27117
|
+
await writeFile4(temporary, `${JSON.stringify(value)}
|
|
26013
27118
|
`, { mode: 384, flag: "wx" });
|
|
26014
|
-
await
|
|
27119
|
+
await rename4(temporary, file2);
|
|
26015
27120
|
} finally {
|
|
26016
|
-
await
|
|
27121
|
+
await rm4(temporary, { force: true });
|
|
26017
27122
|
}
|
|
26018
27123
|
}
|
|
26019
27124
|
return { path: value, restartRequired: this.#restartRequired(snapshot, value) };
|
|
@@ -26023,22 +27128,43 @@ var HarnessLaunchSettingsStore = class {
|
|
|
26023
27128
|
// packages/harness-plugin-files/dist/host-extension-io.js
|
|
26024
27129
|
var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
|
|
26025
27130
|
import { constants } from "node:fs";
|
|
26026
|
-
import { lstat as
|
|
26027
|
-
import
|
|
27131
|
+
import { lstat as lstat6, mkdir as mkdir5, open as open6, realpath as realpath5, rm as rm5, writeFile as writeFile5 } from "node:fs/promises";
|
|
27132
|
+
import path11 from "node:path";
|
|
27133
|
+
|
|
27134
|
+
// packages/harness-plugin-files/dist/rename-with-windows-retry.js
|
|
27135
|
+
import { rename as rename5 } from "node:fs/promises";
|
|
27136
|
+
import { setTimeout as delay4 } from "node:timers/promises";
|
|
27137
|
+
var WINDOWS_RENAME_DELAYS_MS = [10, 30, 70, 150, 300];
|
|
27138
|
+
async function renameWithWindowsRetry(temporary, destination) {
|
|
27139
|
+
for (let attempt = 0; ; attempt++) {
|
|
27140
|
+
try {
|
|
27141
|
+
await rename5(temporary, destination);
|
|
27142
|
+
return;
|
|
27143
|
+
} catch (error62) {
|
|
27144
|
+
const wait = WINDOWS_RENAME_DELAYS_MS[attempt];
|
|
27145
|
+
const code = error62.code;
|
|
27146
|
+
if (process.platform !== "win32" || wait === void 0 || !["EPERM", "EACCES", "EBUSY"].includes(code ?? ""))
|
|
27147
|
+
throw error62;
|
|
27148
|
+
await delay4(wait);
|
|
27149
|
+
}
|
|
27150
|
+
}
|
|
27151
|
+
}
|
|
27152
|
+
|
|
27153
|
+
// packages/harness-plugin-files/dist/host-extension-io.js
|
|
26028
27154
|
function extensionFileMissing(error62) {
|
|
26029
27155
|
return error62 instanceof Error && "code" in error62 && error62.code === "ENOENT";
|
|
26030
27156
|
}
|
|
26031
27157
|
function assertPrivateExtensionEntry(file2, info, directory) {
|
|
26032
27158
|
if (directory ? !info.isDirectory() : !info.isFile())
|
|
26033
|
-
throw new Error(`${
|
|
27159
|
+
throw new Error(`${path11.basename(file2)} must be a regular ${directory ? "directory" : "file"}`);
|
|
26034
27160
|
if (!privateMode(info))
|
|
26035
|
-
throw new Error(`${
|
|
27161
|
+
throw new Error(`${path11.basename(file2)} must belong to the current user and not permit group/other writes`);
|
|
26036
27162
|
}
|
|
26037
27163
|
async function privateExtensionDirectory(directory) {
|
|
26038
|
-
assertPrivateExtensionEntry(directory, await
|
|
26039
|
-
return
|
|
27164
|
+
assertPrivateExtensionEntry(directory, await lstat6(directory), true);
|
|
27165
|
+
return realpath5(directory);
|
|
26040
27166
|
}
|
|
26041
|
-
var hostExtensionsRoot = (dataDir) =>
|
|
27167
|
+
var hostExtensionsRoot = (dataDir) => path11.join(dataDir, "host-extensions");
|
|
26042
27168
|
var utf8 = new TextDecoder("utf-8", { fatal: true });
|
|
26043
27169
|
var errorMessage2 = (error62) => error62 instanceof Error ? error62.message : String(error62);
|
|
26044
27170
|
async function ifMissing(operation) {
|
|
@@ -26052,13 +27178,13 @@ async function ifMissing(operation) {
|
|
|
26052
27178
|
}
|
|
26053
27179
|
async function storeRoot(root, create) {
|
|
26054
27180
|
if (create)
|
|
26055
|
-
await
|
|
27181
|
+
await mkdir5(root, { recursive: true, mode: 448 });
|
|
26056
27182
|
return privateExtensionDirectory(root);
|
|
26057
27183
|
}
|
|
26058
27184
|
async function storeChild(root, name, create = false) {
|
|
26059
|
-
const directory =
|
|
27185
|
+
const directory = path11.join(root, name);
|
|
26060
27186
|
if (create)
|
|
26061
|
-
await
|
|
27187
|
+
await mkdir5(directory, { mode: 448 }).catch((error62) => {
|
|
26062
27188
|
if (error62.code !== "EEXIST")
|
|
26063
27189
|
throw error62;
|
|
26064
27190
|
});
|
|
@@ -26071,16 +27197,16 @@ async function readHostFile(root, relative, max, owned = true) {
|
|
|
26071
27197
|
throw new Error(`No file name for ${relative}`);
|
|
26072
27198
|
let directory = root;
|
|
26073
27199
|
for (const part of parts) {
|
|
26074
|
-
directory =
|
|
26075
|
-
const info2 = await
|
|
27200
|
+
directory = path11.join(directory, part);
|
|
27201
|
+
const info2 = await lstat6(directory);
|
|
26076
27202
|
if (!info2.isDirectory() || owned && !privateMode(info2))
|
|
26077
27203
|
throw new Error(`Unsafe directory for ${relative}`);
|
|
26078
27204
|
}
|
|
26079
|
-
const target2 =
|
|
26080
|
-
const info = await
|
|
27205
|
+
const target2 = path11.join(directory, leaf);
|
|
27206
|
+
const info = await lstat6(target2);
|
|
26081
27207
|
if (!info.isFile() || info.nlink !== 1 || owned && !privateMode(info))
|
|
26082
27208
|
throw new Error(`Unsafe file: ${relative}`);
|
|
26083
|
-
const handle = await
|
|
27209
|
+
const handle = await open6(target2, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
|
|
26084
27210
|
try {
|
|
26085
27211
|
const opened = await handle.stat();
|
|
26086
27212
|
if (!opened.isFile() || opened.dev !== info.dev || opened.ino !== info.ino || opened.nlink !== 1 || owned && !privateMode(opened))
|
|
@@ -26113,7 +27239,7 @@ var riffSignature = Buffer.from("RIFF");
|
|
|
26113
27239
|
var webpSignature = Buffer.from("WEBP");
|
|
26114
27240
|
|
|
26115
27241
|
// packages/harness-plugin-files/dist/desktop-extension-download.js
|
|
26116
|
-
import { setTimeout as
|
|
27242
|
+
import { setTimeout as delay5 } from "node:timers/promises";
|
|
26117
27243
|
var githubHeaders = {
|
|
26118
27244
|
accept: "application/vnd.github+json",
|
|
26119
27245
|
"user-agent": "codexhost-desktop-extensions"
|
|
@@ -26227,7 +27353,7 @@ async function downloadExtensionBytes(url2, limit, headers, { signal: callerSign
|
|
|
26227
27353
|
const waitMs = retryBaseDelayMs * 2 ** attempt;
|
|
26228
27354
|
try {
|
|
26229
27355
|
if (waitMs > 0)
|
|
26230
|
-
await
|
|
27356
|
+
await delay5(waitMs, void 0, { signal: overallSignal });
|
|
26231
27357
|
} catch (delayError) {
|
|
26232
27358
|
if (callerSignal?.aborted)
|
|
26233
27359
|
throw new ExtensionDownloadError("Download aborted", { cause: callerSignal.reason });
|
|
@@ -26245,16 +27371,16 @@ async function downloadExtensionBytes(url2, limit, headers, { signal: callerSign
|
|
|
26245
27371
|
}
|
|
26246
27372
|
|
|
26247
27373
|
// packages/harness-plugin-files/dist/host-extension-package.js
|
|
26248
|
-
import { createHash as
|
|
26249
|
-
import
|
|
27374
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
27375
|
+
import path12 from "node:path";
|
|
26250
27376
|
var PACKAGE_INDEX = ".host-extension-generation.json";
|
|
26251
27377
|
var MAX_INDEX_BYTES = 8 * 1024 * 1024;
|
|
26252
27378
|
var MAX_PACKAGE_BYTES = 256 * 1024 * 1024;
|
|
26253
27379
|
var MAX_ENTRIES = 1e4;
|
|
26254
|
-
var sha256 = (bytes) =>
|
|
27380
|
+
var sha256 = (bytes) => createHash3("sha256").update(bytes).digest("hex");
|
|
26255
27381
|
var allowedSuffix = /\.(?:js|mjs|cjs|css|json|png|jpe?g|webp|gif|woff2|md|txt|svg|ts|tsx|ya?ml)$/iu;
|
|
26256
27382
|
function packageLimit(resource) {
|
|
26257
|
-
if (hostExtensionCanonicalPath(resource) === PACKAGE_INDEX || !(allowedSuffix.test(resource) || /^(?:licen[cs]e|notice|\.gitignore|\.gitattributes)$/iu.test(
|
|
27383
|
+
if (hostExtensionCanonicalPath(resource) === PACKAGE_INDEX || !(allowedSuffix.test(resource) || /^(?:licen[cs]e|notice|\.gitignore|\.gitattributes)$/iu.test(path12.posix.basename(resource))))
|
|
26258
27384
|
throw new Error(`Unsupported extension package file: ${resource}`);
|
|
26259
27385
|
if (resource === "manifest.json")
|
|
26260
27386
|
return DESKTOP_EXTENSION_MANIFEST_MAX_BYTES;
|
|
@@ -26336,7 +27462,7 @@ async function validateHostPackageEntries(manifest, read) {
|
|
|
26336
27462
|
}
|
|
26337
27463
|
|
|
26338
27464
|
// packages/harness-plugin-files/dist/host-extension-files.js
|
|
26339
|
-
import { mkdir as
|
|
27465
|
+
import { mkdir as mkdir6, mkdtemp, readdir as readdir4, rm as rm6, writeFile as writeFile6 } from "node:fs/promises";
|
|
26340
27466
|
var ACTIVE = "active.json";
|
|
26341
27467
|
var ENABLED = "enabled.json";
|
|
26342
27468
|
var activeFields = hostExtensionInstallationSchema.omit({ manifest: true, id: true });
|
|
@@ -26371,7 +27497,8 @@ async function readHostExtensionConfiguration(dataDir) {
|
|
|
26371
27497
|
const root = await ifMissing(() => storeRoot(hostExtensionsRoot(dataDir), false));
|
|
26372
27498
|
return root ? readConfiguration(root) : emptyConfiguration();
|
|
26373
27499
|
}
|
|
26374
|
-
async function discoverHostExtensions(dataDir) {
|
|
27500
|
+
async function discoverHostExtensions(dataDir, options = {}) {
|
|
27501
|
+
const includeScreenshots = options.includeScreenshots ?? true;
|
|
26375
27502
|
const diagnostics = [];
|
|
26376
27503
|
const configuration = await readHostExtensionConfiguration(dataDir).catch((error62) => {
|
|
26377
27504
|
diagnostics.push(`Invalid extension configuration: ${errorMessage2(error62)}`);
|
|
@@ -26382,7 +27509,7 @@ async function discoverHostExtensions(dataDir) {
|
|
|
26382
27509
|
const root = await ifMissing(() => storeRoot(hostExtensionsRoot(dataDir), false));
|
|
26383
27510
|
if (!root)
|
|
26384
27511
|
return { configuration, installations, extensions, diagnostics };
|
|
26385
|
-
const ids = (await
|
|
27512
|
+
const ids = (await readdir4(root, { withFileTypes: true })).filter((entry) => !entry.name.startsWith(".") && (entry.isDirectory() || entry.isSymbolicLink())).map(({ name }) => name).sort();
|
|
26386
27513
|
let screenshotBudget = DESKTOP_EXTENSION_LIST_SCREENSHOTS_MAX_BYTES;
|
|
26387
27514
|
let omitted = false;
|
|
26388
27515
|
for (const id2 of ids) {
|
|
@@ -26396,18 +27523,22 @@ async function discoverHostExtensions(dataDir) {
|
|
|
26396
27523
|
const metadata = hostExtensionInstallationMetadata(installation);
|
|
26397
27524
|
const { icon, screenshots } = await validateHostPackageEntries(metadata.manifest, read);
|
|
26398
27525
|
const toDataUrl = ({ mime, bytes }) => `data:${mime};base64,${bytes.toString("base64")}`;
|
|
26399
|
-
|
|
26400
|
-
|
|
26401
|
-
|
|
26402
|
-
screenshotBudget
|
|
26403
|
-
|
|
26404
|
-
|
|
27526
|
+
let screenshotDataUrls;
|
|
27527
|
+
if (includeScreenshots && screenshots.length > 0) {
|
|
27528
|
+
const size = screenshots.reduce((sum, { bytes }) => sum + bytes.length, 0);
|
|
27529
|
+
if (size <= screenshotBudget) {
|
|
27530
|
+
screenshotBudget -= size;
|
|
27531
|
+
screenshotDataUrls = screenshots.map(toDataUrl);
|
|
27532
|
+
} else {
|
|
27533
|
+
omitted = true;
|
|
27534
|
+
}
|
|
27535
|
+
}
|
|
26405
27536
|
extensions.push({
|
|
26406
27537
|
state: "valid",
|
|
26407
27538
|
...metadata,
|
|
26408
27539
|
enabled,
|
|
26409
27540
|
...icon ? { iconDataUrl: toDataUrl(icon) } : {},
|
|
26410
|
-
...
|
|
27541
|
+
...screenshotDataUrls ? { screenshotDataUrls } : {}
|
|
26411
27542
|
});
|
|
26412
27543
|
installations.push(installation);
|
|
26413
27544
|
} catch (error62) {
|
|
@@ -26430,6 +27561,13 @@ async function discoverHostExtensions(dataDir) {
|
|
|
26430
27561
|
return { configuration, installations, extensions, diagnostics };
|
|
26431
27562
|
}
|
|
26432
27563
|
|
|
27564
|
+
// packages/harness-plugin-files/dist/host-extension-default-seeds.js
|
|
27565
|
+
var MAX_DEFAULT_SEEDS_BYTES = 32 * 1024;
|
|
27566
|
+
|
|
27567
|
+
// packages/harness-plugin-files/dist/host-extension-sources.js
|
|
27568
|
+
import { lstat as lstat7, mkdir as mkdir7, readFile as readFile7, realpath as realpath6, unlink, writeFile as writeFile7 } from "node:fs/promises";
|
|
27569
|
+
import path13 from "node:path";
|
|
27570
|
+
|
|
26433
27571
|
// packages/harness-plugin-files/dist/extension-zip.js
|
|
26434
27572
|
import { promisify } from "node:util";
|
|
26435
27573
|
import { crc32, inflateRaw, inflateRawSync } from "node:zlib";
|
|
@@ -26441,17 +27579,56 @@ var inflate = promisify(inflateRaw);
|
|
|
26441
27579
|
// packages/harness-plugin-files/dist/host-extension-sources.js
|
|
26442
27580
|
var TTL = 5 * 60 * 1e3;
|
|
26443
27581
|
var STALE_FALLBACK_MAX_AGE_MS = 30 * 60 * 1e3;
|
|
27582
|
+
var DISK_CATALOG_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
26444
27583
|
var CATALOG_TIMEOUT_MS = 12e3;
|
|
26445
27584
|
var CATALOG_RETRIES = 1;
|
|
27585
|
+
var STATS_MAX_BYTES = 256 * 1024;
|
|
27586
|
+
var STATS_TIMEOUT_MS = 2e3;
|
|
27587
|
+
var STATS_INLINE_GRACE_MS = 600;
|
|
26446
27588
|
var httpsDownload = (url2) => url2.protocol === "https:" && !url2.username && !url2.password;
|
|
26447
27589
|
var cache;
|
|
26448
27590
|
var pending;
|
|
26449
27591
|
var catalogGeneration = 0;
|
|
26450
27592
|
var cacheWrittenGeneration = 0;
|
|
26451
|
-
var
|
|
26452
|
-
var
|
|
26453
|
-
var
|
|
26454
|
-
var
|
|
27593
|
+
var lastKnownDownloadStats;
|
|
27594
|
+
var PNG_SIG = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
|
|
27595
|
+
var JPEG_SIG = Buffer.from([255, 216, 255]);
|
|
27596
|
+
var RIFF_SIG = Buffer.from("RIFF");
|
|
27597
|
+
var WEBP_SIG = Buffer.from("WEBP");
|
|
27598
|
+
async function atomicWriteFile(filePath2, data) {
|
|
27599
|
+
const dir = path13.dirname(filePath2);
|
|
27600
|
+
const tempPath = `${filePath2}.tmp-${process.pid}-${Math.random().toString(36).slice(2, 10)}`;
|
|
27601
|
+
try {
|
|
27602
|
+
await mkdir7(dir, { recursive: true });
|
|
27603
|
+
await writeFile7(tempPath, data);
|
|
27604
|
+
await renameWithWindowsRetry(tempPath, filePath2);
|
|
27605
|
+
} catch {
|
|
27606
|
+
await unlink(tempPath).catch(() => void 0);
|
|
27607
|
+
}
|
|
27608
|
+
}
|
|
27609
|
+
function catalogDiskCachePath(dataDir) {
|
|
27610
|
+
return path13.join(dataDir, "cache", "host-extension-catalog.v2.json");
|
|
27611
|
+
}
|
|
27612
|
+
async function readDiskCatalogCache(dataDir) {
|
|
27613
|
+
try {
|
|
27614
|
+
const raw = await readFile7(catalogDiskCachePath(dataDir), "utf8");
|
|
27615
|
+
const parsed = hostExtensionsCatalogResultSchema.safeParse(JSON.parse(raw));
|
|
27616
|
+
if (!parsed.success)
|
|
27617
|
+
return void 0;
|
|
27618
|
+
const fetchedAtMs = Date.parse(parsed.data.fetchedAt);
|
|
27619
|
+
if (Number.isFinite(fetchedAtMs) && Date.now() - fetchedAtMs > DISK_CATALOG_MAX_AGE_MS) {
|
|
27620
|
+
return void 0;
|
|
27621
|
+
}
|
|
27622
|
+
return parsed.data;
|
|
27623
|
+
} catch {
|
|
27624
|
+
return void 0;
|
|
27625
|
+
}
|
|
27626
|
+
}
|
|
27627
|
+
async function writeDiskCatalogCache(dataDir, result) {
|
|
27628
|
+
if (!dataDir)
|
|
27629
|
+
return;
|
|
27630
|
+
await atomicWriteFile(catalogDiskCachePath(dataDir), JSON.stringify(result));
|
|
27631
|
+
}
|
|
26455
27632
|
function raceWithSignal(promise2, signal) {
|
|
26456
27633
|
if (!signal)
|
|
26457
27634
|
return promise2;
|
|
@@ -26473,9 +27650,6 @@ function catalogGeneratedAtMs(result) {
|
|
|
26473
27650
|
const parsed = Date.parse(result.generatedAt);
|
|
26474
27651
|
return Number.isFinite(parsed) ? parsed : 0;
|
|
26475
27652
|
}
|
|
26476
|
-
function pickFresherCatalog(primary, mirror) {
|
|
26477
|
-
return catalogGeneratedAtMs(mirror) > catalogGeneratedAtMs(primary) ? mirror : primary;
|
|
26478
|
-
}
|
|
26479
27653
|
async function fetchCatalogFrom(catalogUrl, signal, forceRefresh) {
|
|
26480
27654
|
const bytes = await downloadExtensionBytes(catalogUrl, 2 * 1024 * 1024, {
|
|
26481
27655
|
accept: "application/json",
|
|
@@ -26493,7 +27667,7 @@ async function fetchCatalogFrom(catalogUrl, signal, forceRefresh) {
|
|
|
26493
27667
|
cached: false
|
|
26494
27668
|
};
|
|
26495
27669
|
}
|
|
26496
|
-
async function raceCatalog(forceRefresh) {
|
|
27670
|
+
async function raceCatalog(forceRefresh, onPrimaryFresher) {
|
|
26497
27671
|
const primaryController = new AbortController();
|
|
26498
27672
|
const mirrorController = new AbortController();
|
|
26499
27673
|
const primaryPromise = fetchCatalogFrom(HOST_EXTENSION_CATALOG_URL, primaryController.signal, forceRefresh);
|
|
@@ -26509,27 +27683,20 @@ async function raceCatalog(forceRefresh) {
|
|
|
26509
27683
|
mirrorController.abort();
|
|
26510
27684
|
return first.result;
|
|
26511
27685
|
}
|
|
26512
|
-
|
|
26513
|
-
|
|
26514
|
-
|
|
26515
|
-
|
|
26516
|
-
|
|
26517
|
-
|
|
26518
|
-
|
|
26519
|
-
|
|
26520
|
-
if (timer !== void 0)
|
|
26521
|
-
clearTimeout(timer);
|
|
26522
|
-
});
|
|
26523
|
-
if (primaryWithinGrace) {
|
|
26524
|
-
return pickFresherCatalog(primaryWithinGrace, first.result);
|
|
27686
|
+
if (onPrimaryFresher) {
|
|
27687
|
+
void primaryPromise.then((primaryResult) => {
|
|
27688
|
+
if (catalogGeneratedAtMs(primaryResult) > catalogGeneratedAtMs(first.result)) {
|
|
27689
|
+
onPrimaryFresher(primaryResult);
|
|
27690
|
+
}
|
|
27691
|
+
}, () => void 0);
|
|
27692
|
+
} else {
|
|
27693
|
+
primaryController.abort();
|
|
26525
27694
|
}
|
|
26526
|
-
primaryController.abort();
|
|
26527
27695
|
return first.result;
|
|
26528
27696
|
} catch (cause) {
|
|
26529
|
-
throw new Error("Host extension catalog unavailable", { cause });
|
|
26530
|
-
} finally {
|
|
26531
27697
|
primaryController.abort();
|
|
26532
27698
|
mirrorController.abort();
|
|
27699
|
+
throw new Error("Host extension catalog unavailable", { cause });
|
|
26533
27700
|
}
|
|
26534
27701
|
}
|
|
26535
27702
|
async function fetchLiveDownloadStats(statsUrl, forceRefresh) {
|
|
@@ -26576,45 +27743,114 @@ function mergeLiveDownloadStats(catalog, liveDownloads) {
|
|
|
26576
27743
|
})
|
|
26577
27744
|
};
|
|
26578
27745
|
}
|
|
26579
|
-
|
|
27746
|
+
function startCatalogFetch(forceRefresh, dataDir) {
|
|
27747
|
+
if (pending && (!forceRefresh || pending.forceRefresh)) {
|
|
27748
|
+
return pending.promise;
|
|
27749
|
+
}
|
|
27750
|
+
const generation = ++catalogGeneration;
|
|
27751
|
+
const statsUrl = resolveHostExtensionStatsUrl();
|
|
27752
|
+
const statsPromise = fetchLiveDownloadStats(statsUrl, forceRefresh);
|
|
27753
|
+
const commitCache = (merged) => {
|
|
27754
|
+
if (generation >= cacheWrittenGeneration) {
|
|
27755
|
+
cacheWrittenGeneration = generation;
|
|
27756
|
+
const now = Date.now();
|
|
27757
|
+
cache = {
|
|
27758
|
+
result: merged,
|
|
27759
|
+
expires: now + TTL,
|
|
27760
|
+
staleUntil: now + STALE_FALLBACK_MAX_AGE_MS
|
|
27761
|
+
};
|
|
27762
|
+
void writeDiskCatalogCache(dataDir, merged);
|
|
27763
|
+
}
|
|
27764
|
+
};
|
|
27765
|
+
const created = raceCatalog(forceRefresh, (fresherPrimary) => {
|
|
27766
|
+
const knownStats = statsUrl && lastKnownDownloadStats?.url === statsUrl ? lastKnownDownloadStats.downloads : void 0;
|
|
27767
|
+
commitCache(mergeLiveDownloadStats(fresherPrimary, knownStats));
|
|
27768
|
+
}).then(async (catalog) => {
|
|
27769
|
+
let timer;
|
|
27770
|
+
const statsOutcome = await Promise.race([
|
|
27771
|
+
statsPromise.then((downloads) => ({ settled: true, downloads })),
|
|
27772
|
+
new Promise((resolve) => {
|
|
27773
|
+
timer = setTimeout(() => resolve({ settled: false }), STATS_INLINE_GRACE_MS);
|
|
27774
|
+
})
|
|
27775
|
+
]).finally(() => {
|
|
27776
|
+
if (timer !== void 0)
|
|
27777
|
+
clearTimeout(timer);
|
|
27778
|
+
});
|
|
27779
|
+
let initialDownloads;
|
|
27780
|
+
if (statsOutcome.settled) {
|
|
27781
|
+
if (statsOutcome.downloads && statsUrl) {
|
|
27782
|
+
lastKnownDownloadStats = {
|
|
27783
|
+
url: statsUrl,
|
|
27784
|
+
downloads: statsOutcome.downloads,
|
|
27785
|
+
expires: Date.now() + TTL
|
|
27786
|
+
};
|
|
27787
|
+
}
|
|
27788
|
+
initialDownloads = statsOutcome.downloads;
|
|
27789
|
+
} else {
|
|
27790
|
+
if (!forceRefresh && statsUrl && lastKnownDownloadStats?.url === statsUrl && Date.now() < lastKnownDownloadStats.expires) {
|
|
27791
|
+
initialDownloads = lastKnownDownloadStats.downloads;
|
|
27792
|
+
}
|
|
27793
|
+
void statsPromise.then((lateDownloads) => {
|
|
27794
|
+
if (!lateDownloads || !statsUrl)
|
|
27795
|
+
return;
|
|
27796
|
+
lastKnownDownloadStats = {
|
|
27797
|
+
url: statsUrl,
|
|
27798
|
+
downloads: lateDownloads,
|
|
27799
|
+
expires: Date.now() + TTL
|
|
27800
|
+
};
|
|
27801
|
+
if (cache && generation >= cacheWrittenGeneration) {
|
|
27802
|
+
const updated = mergeLiveDownloadStats(cache.result, lateDownloads);
|
|
27803
|
+
cache = { ...cache, result: updated };
|
|
27804
|
+
void writeDiskCatalogCache(dataDir, updated);
|
|
27805
|
+
}
|
|
27806
|
+
});
|
|
27807
|
+
}
|
|
27808
|
+
const merged = mergeLiveDownloadStats(catalog, initialDownloads);
|
|
27809
|
+
commitCache(merged);
|
|
27810
|
+
return merged;
|
|
27811
|
+
}).finally(() => {
|
|
27812
|
+
if (pending?.promise === created)
|
|
27813
|
+
pending = void 0;
|
|
27814
|
+
});
|
|
27815
|
+
created.catch(() => void 0);
|
|
27816
|
+
pending = { forceRefresh, promise: created };
|
|
27817
|
+
return created;
|
|
27818
|
+
}
|
|
27819
|
+
async function fetchHostExtensionCatalog({ dataDir, forceRefresh = false, fallbackToCache = false, staleWhileRevalidate = false, signal } = {}) {
|
|
26580
27820
|
if (!forceRefresh && cache && Date.now() < cache.expires)
|
|
26581
27821
|
return { ...structuredClone(cache.result), cached: true };
|
|
26582
27822
|
if (signal?.aborted)
|
|
26583
27823
|
throw new ExtensionDownloadError("Download aborted", { cause: signal.reason });
|
|
26584
|
-
|
|
26585
|
-
|
|
26586
|
-
|
|
26587
|
-
|
|
26588
|
-
|
|
26589
|
-
const created = Promise.all([
|
|
26590
|
-
raceCatalog(forceRefresh),
|
|
26591
|
-
fetchLiveDownloadStats(resolveHostExtensionStatsUrl(), forceRefresh)
|
|
26592
|
-
]).then(([catalog, liveDownloads]) => {
|
|
26593
|
-
const merged = mergeLiveDownloadStats(catalog, liveDownloads);
|
|
26594
|
-
if (generation >= cacheWrittenGeneration) {
|
|
26595
|
-
cacheWrittenGeneration = generation;
|
|
26596
|
-
const now = Date.now();
|
|
27824
|
+
if (!forceRefresh && staleWhileRevalidate) {
|
|
27825
|
+
const staleEntry = cache && Date.now() <= cache.staleUntil ? cache.result : dataDir ? await readDiskCatalogCache(dataDir) : void 0;
|
|
27826
|
+
if (staleEntry) {
|
|
27827
|
+
const now = Date.now();
|
|
27828
|
+
if (!cache) {
|
|
26597
27829
|
cache = {
|
|
26598
|
-
result:
|
|
26599
|
-
expires: now
|
|
27830
|
+
result: staleEntry,
|
|
27831
|
+
expires: now,
|
|
26600
27832
|
staleUntil: now + STALE_FALLBACK_MAX_AGE_MS
|
|
26601
27833
|
};
|
|
26602
27834
|
}
|
|
26603
|
-
|
|
26604
|
-
|
|
26605
|
-
|
|
26606
|
-
pending = void 0;
|
|
26607
|
-
});
|
|
26608
|
-
created.catch(() => void 0);
|
|
26609
|
-
pending = { forceRefresh, promise: created };
|
|
26610
|
-
request = created;
|
|
27835
|
+
void startCatalogFetch(false, dataDir);
|
|
27836
|
+
return { ...structuredClone(staleEntry), cached: true, stale: true };
|
|
27837
|
+
}
|
|
26611
27838
|
}
|
|
27839
|
+
const request = startCatalogFetch(forceRefresh, dataDir);
|
|
26612
27840
|
try {
|
|
26613
27841
|
const result = await raceWithSignal(request, signal);
|
|
26614
27842
|
return structuredClone(result);
|
|
26615
27843
|
} catch (error62) {
|
|
26616
|
-
if (fallbackToCache && !signal?.aborted
|
|
26617
|
-
|
|
27844
|
+
if (fallbackToCache && !signal?.aborted) {
|
|
27845
|
+
if (cache && Date.now() <= cache.staleUntil) {
|
|
27846
|
+
return { ...structuredClone(cache.result), cached: true };
|
|
27847
|
+
}
|
|
27848
|
+
if (dataDir) {
|
|
27849
|
+
const diskFallback = await readDiskCatalogCache(dataDir);
|
|
27850
|
+
if (diskFallback)
|
|
27851
|
+
return { ...structuredClone(diskFallback), cached: true };
|
|
27852
|
+
}
|
|
27853
|
+
}
|
|
26618
27854
|
throw error62;
|
|
26619
27855
|
}
|
|
26620
27856
|
}
|
|
@@ -26634,21 +27870,21 @@ function resolveHostExtensionStatsUrl(environment = process.env) {
|
|
|
26634
27870
|
|
|
26635
27871
|
// packages/console-server/src/paths.ts
|
|
26636
27872
|
import os2 from "node:os";
|
|
26637
|
-
import
|
|
27873
|
+
import path14 from "node:path";
|
|
26638
27874
|
var DEFAULT_CONSOLE_PORT = 4399;
|
|
26639
27875
|
var CONSOLE_PORT_ENV = "CODEXHOST_CONSOLE_PORT";
|
|
26640
27876
|
var LAUNCHER_EXECUTABLE_ENV = "CODEXHOST_LAUNCHER_EXECUTABLE";
|
|
26641
27877
|
function dataDirectory(environment = process.env) {
|
|
26642
|
-
return environment.CODEXHOST_DATA_DIR ?
|
|
27878
|
+
return environment.CODEXHOST_DATA_DIR ? path14.resolve(environment.CODEXHOST_DATA_DIR) : path14.join(os2.homedir(), ".codexhost");
|
|
26643
27879
|
}
|
|
26644
27880
|
function consolePaths(environment = process.env) {
|
|
26645
27881
|
const root = dataDirectory(environment);
|
|
26646
27882
|
return {
|
|
26647
27883
|
dataDirectory: root,
|
|
26648
|
-
startupRecordFile:
|
|
26649
|
-
controllerStatusFile:
|
|
26650
|
-
logsDirectory:
|
|
26651
|
-
hostDescriptorDirectory:
|
|
27884
|
+
startupRecordFile: path14.join(root, "diagnostics", "launcher-startup-v1.json"),
|
|
27885
|
+
controllerStatusFile: path14.join(root, "diagnostics", "desktop-controller-v1.json"),
|
|
27886
|
+
logsDirectory: path14.join(root, "logs"),
|
|
27887
|
+
hostDescriptorDirectory: path14.join(root, "console", "hosts")
|
|
26652
27888
|
};
|
|
26653
27889
|
}
|
|
26654
27890
|
function consolePort(environment = process.env) {
|
|
@@ -26664,10 +27900,10 @@ function consolePort(environment = process.env) {
|
|
|
26664
27900
|
// packages/console-server/src/harnesses.ts
|
|
26665
27901
|
var HARNESS_PLUGIN_DIRECTORY_ENV = "CODEXHOST_PLUGIN_DIRECTORY";
|
|
26666
27902
|
function harnessPluginRoots(appDirectory2, sourceCheckout, environment = process.env) {
|
|
26667
|
-
const bundled = sourceCheckout ?
|
|
27903
|
+
const bundled = sourceCheckout ? path15.resolve(appDirectory2, "..", "..", "host-runtime", "dist", "plugins") : path15.join(appDirectory2, "plugins");
|
|
26668
27904
|
return [
|
|
26669
27905
|
bundled,
|
|
26670
|
-
environment[HARNESS_PLUGIN_DIRECTORY_ENV] ??
|
|
27906
|
+
environment[HARNESS_PLUGIN_DIRECTORY_ENV] ?? path15.join(dataDirectory(environment), "plugins")
|
|
26671
27907
|
];
|
|
26672
27908
|
}
|
|
26673
27909
|
var ConsoleHarnessError = class extends Error {
|
|
@@ -26733,12 +27969,12 @@ function createConsoleHarnesses(roots, environment = process.env) {
|
|
|
26733
27969
|
}
|
|
26734
27970
|
|
|
26735
27971
|
// packages/console-server/src/host-client.ts
|
|
26736
|
-
import { readdir as
|
|
26737
|
-
import
|
|
27972
|
+
import { readdir as readdir6, readFile as readFile9, realpath as realpath7, rm as rm7 } from "node:fs/promises";
|
|
27973
|
+
import path17 from "node:path";
|
|
26738
27974
|
|
|
26739
27975
|
// packages/console-server/src/diagnostics.ts
|
|
26740
|
-
import { open as
|
|
26741
|
-
import
|
|
27976
|
+
import { open as open7, readdir as readdir5, readFile as readFile8, stat as stat3 } from "node:fs/promises";
|
|
27977
|
+
import path16 from "node:path";
|
|
26742
27978
|
var MAX_DIAGNOSTIC_FILE_BYTES = 256 * 1024;
|
|
26743
27979
|
var MAX_LOG_TAIL_BYTES = 256 * 1024;
|
|
26744
27980
|
var LOG_FILE_PATTERN = /^host-runtime-\d{1,10}\.log(?:\.1)?$/u;
|
|
@@ -26746,7 +27982,7 @@ async function readBoundedJson(filePath2) {
|
|
|
26746
27982
|
try {
|
|
26747
27983
|
const metadata = await stat3(filePath2);
|
|
26748
27984
|
if (!metadata.isFile() || metadata.size > MAX_DIAGNOSTIC_FILE_BYTES) return null;
|
|
26749
|
-
return JSON.parse(await
|
|
27985
|
+
return JSON.parse(await readFile8(filePath2, "utf8"));
|
|
26750
27986
|
} catch {
|
|
26751
27987
|
return null;
|
|
26752
27988
|
}
|
|
@@ -26810,14 +28046,14 @@ function isLogFileName(name) {
|
|
|
26810
28046
|
async function listLogFiles(logsDirectory) {
|
|
26811
28047
|
let names;
|
|
26812
28048
|
try {
|
|
26813
|
-
names = await
|
|
28049
|
+
names = await readdir5(logsDirectory);
|
|
26814
28050
|
} catch {
|
|
26815
28051
|
return [];
|
|
26816
28052
|
}
|
|
26817
28053
|
const entries = await Promise.all(
|
|
26818
28054
|
names.filter(isLogFileName).map(async (name) => {
|
|
26819
28055
|
try {
|
|
26820
|
-
const metadata = await stat3(
|
|
28056
|
+
const metadata = await stat3(path16.join(logsDirectory, name));
|
|
26821
28057
|
return metadata.isFile() ? { name, size: metadata.size, modifiedAt: metadata.mtimeMs } : null;
|
|
26822
28058
|
} catch {
|
|
26823
28059
|
return null;
|
|
@@ -26831,7 +28067,7 @@ async function readLogTail(logsDirectory, name, maxBytes = MAX_LOG_TAIL_BYTES) {
|
|
|
26831
28067
|
const limit = Math.max(1, Math.min(maxBytes, MAX_LOG_TAIL_BYTES));
|
|
26832
28068
|
let handle;
|
|
26833
28069
|
try {
|
|
26834
|
-
handle = await
|
|
28070
|
+
handle = await open7(path16.join(logsDirectory, name), "r");
|
|
26835
28071
|
} catch {
|
|
26836
28072
|
return null;
|
|
26837
28073
|
}
|
|
@@ -26876,7 +28112,7 @@ function summarize(input3) {
|
|
|
26876
28112
|
}
|
|
26877
28113
|
return { state: "stopped", detail: null };
|
|
26878
28114
|
}
|
|
26879
|
-
function
|
|
28115
|
+
function processIsAlive3(pid) {
|
|
26880
28116
|
if (!Number.isInteger(pid) || pid <= 0) return false;
|
|
26881
28117
|
try {
|
|
26882
28118
|
process.kill(pid, 0);
|
|
@@ -26906,26 +28142,26 @@ function parseDescriptor(value) {
|
|
|
26906
28142
|
port: record4.port,
|
|
26907
28143
|
token: record4.token,
|
|
26908
28144
|
startedAt: record4.startedAt,
|
|
26909
|
-
...typeof record4.runtimePath === "string" &&
|
|
28145
|
+
...typeof record4.runtimePath === "string" && path17.isAbsolute(record4.runtimePath) ? { runtimePath: record4.runtimePath } : {}
|
|
26910
28146
|
};
|
|
26911
28147
|
}
|
|
26912
|
-
async function findHost(descriptorDirectory, isAlive =
|
|
28148
|
+
async function findHost(descriptorDirectory, isAlive = processIsAlive3) {
|
|
26913
28149
|
let names;
|
|
26914
28150
|
try {
|
|
26915
|
-
names = await
|
|
28151
|
+
names = await readdir6(descriptorDirectory);
|
|
26916
28152
|
} catch {
|
|
26917
28153
|
return null;
|
|
26918
28154
|
}
|
|
26919
28155
|
const hosts = [];
|
|
26920
28156
|
for (const name of names.filter((candidate) => DESCRIPTOR_PATTERN.test(candidate))) {
|
|
26921
|
-
const filePath2 =
|
|
28157
|
+
const filePath2 = path17.join(descriptorDirectory, name);
|
|
26922
28158
|
try {
|
|
26923
|
-
const text2 = await
|
|
28159
|
+
const text2 = await readFile9(filePath2, "utf8");
|
|
26924
28160
|
if (text2.length > DESCRIPTOR_MAX_BYTES) continue;
|
|
26925
28161
|
const endpoint = parseDescriptor(JSON.parse(text2));
|
|
26926
28162
|
if (!endpoint) continue;
|
|
26927
28163
|
if (isAlive(endpoint.pid)) hosts.push(endpoint);
|
|
26928
|
-
else await
|
|
28164
|
+
else await rm7(filePath2, { force: true });
|
|
26929
28165
|
} catch {
|
|
26930
28166
|
continue;
|
|
26931
28167
|
}
|
|
@@ -26955,8 +28191,8 @@ function createConsoleHostClient(descriptorDirectory, options = {}) {
|
|
|
26955
28191
|
"The running Host does not identify its installation; restart it before updating"
|
|
26956
28192
|
);
|
|
26957
28193
|
const [hostDirectory, requestedDirectory] = await Promise.all([
|
|
26958
|
-
|
|
26959
|
-
|
|
28194
|
+
realpath7(path17.dirname(host.runtimePath)),
|
|
28195
|
+
realpath7(options.updateAppDirectory)
|
|
26960
28196
|
]).catch(() => {
|
|
26961
28197
|
throw new Error("The running Host installation could not be verified");
|
|
26962
28198
|
});
|
|
@@ -27004,12 +28240,12 @@ function createHostUpdates(host) {
|
|
|
27004
28240
|
// packages/console-server/src/installation.ts
|
|
27005
28241
|
import { execFile as execFile3 } from "node:child_process";
|
|
27006
28242
|
import { existsSync } from "node:fs";
|
|
27007
|
-
import { readFile as
|
|
27008
|
-
import
|
|
28243
|
+
import { readFile as readFile10 } from "node:fs/promises";
|
|
28244
|
+
import path18 from "node:path";
|
|
27009
28245
|
async function readDistribution(appDirectory2) {
|
|
27010
28246
|
try {
|
|
27011
28247
|
return parseDistributionMetadata(
|
|
27012
|
-
JSON.parse(await
|
|
28248
|
+
JSON.parse(await readFile10(path18.join(appDirectory2, "codexhost-distribution.json"), "utf8"))
|
|
27013
28249
|
);
|
|
27014
28250
|
} catch (error62) {
|
|
27015
28251
|
if (error62.code === "ENOENT") return null;
|
|
@@ -27017,17 +28253,17 @@ async function readDistribution(appDirectory2) {
|
|
|
27017
28253
|
}
|
|
27018
28254
|
}
|
|
27019
28255
|
function installedLauncherCandidates(appDirectory2, platform = process.platform) {
|
|
27020
|
-
const resourcesRoot =
|
|
28256
|
+
const resourcesRoot = path18.dirname(appDirectory2);
|
|
27021
28257
|
const suffix = platform === "win32" ? ".exe" : "";
|
|
27022
|
-
const candidates = [
|
|
27023
|
-
if (platform === "darwin" &&
|
|
27024
|
-
candidates.unshift(
|
|
28258
|
+
const candidates = [path18.join(resourcesRoot, "bin", `codexhost${suffix}`)];
|
|
28259
|
+
if (platform === "darwin" && path18.basename(resourcesRoot) === "Resources") {
|
|
28260
|
+
candidates.unshift(path18.join(path18.dirname(resourcesRoot), "MacOS", "codexhost"));
|
|
27025
28261
|
}
|
|
27026
28262
|
return candidates;
|
|
27027
28263
|
}
|
|
27028
28264
|
function resolveLauncherExecutable(appDirectory2, environment = process.env, platform = process.platform, exists = existsSync) {
|
|
27029
28265
|
const configured = environment[LAUNCHER_EXECUTABLE_ENV];
|
|
27030
|
-
if (configured &&
|
|
28266
|
+
if (configured && path18.isAbsolute(configured) && exists(configured)) return configured;
|
|
27031
28267
|
return installedLauncherCandidates(appDirectory2, platform).find(exists) ?? null;
|
|
27032
28268
|
}
|
|
27033
28269
|
async function resolveInstallation(appDirectory2, environment = process.env) {
|
|
@@ -27069,7 +28305,7 @@ function launchCommand(installation, environment = process.env) {
|
|
|
27069
28305
|
if (installation.distribution?.distribution === "npm") {
|
|
27070
28306
|
const node2 = environment.CODEXHOST_NPM_NODE_PATH;
|
|
27071
28307
|
const wrapper = environment.CODEXHOST_NPM_LAUNCHER_PATH;
|
|
27072
|
-
if (node2 && wrapper &&
|
|
28308
|
+
if (node2 && wrapper && path18.isAbsolute(node2) && path18.isAbsolute(wrapper)) {
|
|
27073
28309
|
return { command: node2, args: [wrapper] };
|
|
27074
28310
|
}
|
|
27075
28311
|
return null;
|
|
@@ -27080,11 +28316,11 @@ function launchCommand(installation, environment = process.env) {
|
|
|
27080
28316
|
// packages/console-server/src/open.ts
|
|
27081
28317
|
import { spawn as spawn4 } from "node:child_process";
|
|
27082
28318
|
import { stat as stat4 } from "node:fs/promises";
|
|
27083
|
-
import
|
|
28319
|
+
import path23 from "node:path";
|
|
27084
28320
|
|
|
27085
28321
|
// packages/console-server/src/page.ts
|
|
27086
|
-
import { readFile as
|
|
27087
|
-
import
|
|
28322
|
+
import { readFile as readFile11 } from "node:fs/promises";
|
|
28323
|
+
import path19 from "node:path";
|
|
27088
28324
|
var CONSOLE_PAGE_HTML = `<!doctype html>
|
|
27089
28325
|
<html lang="en">
|
|
27090
28326
|
<head>
|
|
@@ -27105,14 +28341,14 @@ var MISSING_BUNDLE_SCRIPT = `document.body.textContent = "codexhost console asse
|
|
|
27105
28341
|
`;
|
|
27106
28342
|
function consoleBundleCandidates(appDirectory2) {
|
|
27107
28343
|
return [
|
|
27108
|
-
|
|
27109
|
-
|
|
28344
|
+
path19.join(appDirectory2, "console-web.js"),
|
|
28345
|
+
path19.resolve(appDirectory2, "..", "..", "renderer-extension", "dist", "console.js")
|
|
27110
28346
|
];
|
|
27111
28347
|
}
|
|
27112
28348
|
async function loadConsoleBundle(appDirectory2) {
|
|
27113
28349
|
for (const candidate of consoleBundleCandidates(appDirectory2)) {
|
|
27114
28350
|
try {
|
|
27115
|
-
return await
|
|
28351
|
+
return await readFile11(candidate, "utf8");
|
|
27116
28352
|
} catch {
|
|
27117
28353
|
continue;
|
|
27118
28354
|
}
|
|
@@ -27131,8 +28367,9 @@ function allowedChange(origin, consoleHeader, port) {
|
|
|
27131
28367
|
}
|
|
27132
28368
|
|
|
27133
28369
|
// packages/console-server/src/server.ts
|
|
27134
|
-
import { spawn as spawn3 } from "node:child_process";
|
|
28370
|
+
import { execFile as execFile4, spawn as spawn3 } from "node:child_process";
|
|
27135
28371
|
import { createServer } from "node:http";
|
|
28372
|
+
import { promisify as promisify2 } from "node:util";
|
|
27136
28373
|
|
|
27137
28374
|
// packages/console-server/src/announcement.ts
|
|
27138
28375
|
var ANNOUNCEMENT_URL = "https://raw.githubusercontent.com/BytePioneer-AI/codex-host/main/docs/NOTICE.md";
|
|
@@ -27375,7 +28612,7 @@ async function extensionsRoute(route, body, dataDirectory2, query, host) {
|
|
|
27375
28612
|
}
|
|
27376
28613
|
|
|
27377
28614
|
// packages/console-server/src/updates.ts
|
|
27378
|
-
import
|
|
28615
|
+
import path20 from "node:path";
|
|
27379
28616
|
var ERROR_MAX_LENGTH = 500;
|
|
27380
28617
|
var ConsoleUpdateError = class extends Error {
|
|
27381
28618
|
constructor(code, message) {
|
|
@@ -27408,16 +28645,6 @@ function installationKind(metadata) {
|
|
|
27408
28645
|
if (metadata.target.startsWith("macos-")) return "macos-dmg";
|
|
27409
28646
|
return "linux-archive";
|
|
27410
28647
|
}
|
|
27411
|
-
function absoluteEnvironmentPath(environment, name) {
|
|
27412
|
-
const value = environment[name];
|
|
27413
|
-
if (!value || !path18.isAbsolute(value)) {
|
|
27414
|
-
throw new ConsoleUpdateError(
|
|
27415
|
-
"unsupported",
|
|
27416
|
-
`${name} is unavailable; run 'codexhost console' from the npm command to update`
|
|
27417
|
-
);
|
|
27418
|
-
}
|
|
27419
|
-
return path18.normalize(value);
|
|
27420
|
-
}
|
|
27421
28648
|
function createConsoleUpdates(options) {
|
|
27422
28649
|
const environment = options.environment ?? process.env;
|
|
27423
28650
|
const platform = options.platform ?? process.platform;
|
|
@@ -27436,12 +28663,21 @@ function createConsoleUpdates(options) {
|
|
|
27436
28663
|
});
|
|
27437
28664
|
let candidate = null;
|
|
27438
28665
|
let handedOff = false;
|
|
27439
|
-
const
|
|
28666
|
+
const resolveConsoleNpmPaths = async (target2) => {
|
|
28667
|
+
try {
|
|
28668
|
+
return await resolveNpmRuntimePaths({
|
|
28669
|
+
packageRoot: path20.dirname(target2.appDirectory),
|
|
28670
|
+
environment,
|
|
28671
|
+
platform
|
|
28672
|
+
});
|
|
28673
|
+
} catch (error62) {
|
|
28674
|
+
throw new ConsoleUpdateError("unsupported", boundedError(error62));
|
|
28675
|
+
}
|
|
28676
|
+
};
|
|
28677
|
+
const npmFallbackRelease = async (metadata, target2, error62) => {
|
|
27440
28678
|
if (!metadata || installationKind(metadata) !== "npm") throw error62;
|
|
27441
|
-
const
|
|
27442
|
-
|
|
27443
|
-
absoluteEnvironmentPath(environment, "CODEXHOST_NPM_CLI_PATH")
|
|
27444
|
-
);
|
|
28679
|
+
const npm = await resolveConsoleNpmPaths(target2);
|
|
28680
|
+
const fallback = await fetchLatestNpmRelease(npm.nodePath, npm.npmCliPath);
|
|
27445
28681
|
if (!fallback) throw error62;
|
|
27446
28682
|
return fallback;
|
|
27447
28683
|
};
|
|
@@ -27461,10 +28697,11 @@ function createConsoleUpdates(options) {
|
|
|
27461
28697
|
async function installable(metadata, target2, release) {
|
|
27462
28698
|
if (installationKind(metadata) === "npm") {
|
|
27463
28699
|
try {
|
|
28700
|
+
const npm = await resolveConsoleNpmPaths(target2);
|
|
27464
28701
|
const available = await npmRelease.installable({
|
|
27465
|
-
nodePath:
|
|
27466
|
-
npmCliPath:
|
|
27467
|
-
packageRoot:
|
|
28702
|
+
nodePath: npm.nodePath,
|
|
28703
|
+
npmCliPath: npm.npmCliPath,
|
|
28704
|
+
packageRoot: npm.packageRoot,
|
|
27468
28705
|
version: release.version
|
|
27469
28706
|
});
|
|
27470
28707
|
return { available, error: null };
|
|
@@ -27483,13 +28720,13 @@ function createConsoleUpdates(options) {
|
|
|
27483
28720
|
}
|
|
27484
28721
|
}
|
|
27485
28722
|
async function prepare(metadata, target2, release, onPrepared) {
|
|
27486
|
-
const resourcesRoot =
|
|
28723
|
+
const resourcesRoot = path20.dirname(target2.appDirectory);
|
|
27487
28724
|
const common = {
|
|
27488
28725
|
version: release.version,
|
|
27489
28726
|
launcherPid: options.processId ?? process.pid,
|
|
27490
28727
|
launcherExecutable: options.processExecutable ?? process.execPath,
|
|
27491
28728
|
runtimeDescriptorPath: target2.runtimeDescriptorPath,
|
|
27492
|
-
updaterExecutable:
|
|
28729
|
+
updaterExecutable: path20.join(
|
|
27493
28730
|
resourcesRoot,
|
|
27494
28731
|
"libexec",
|
|
27495
28732
|
platform === "win32" ? "codexhost-updater.exe" : "codexhost-updater"
|
|
@@ -27501,19 +28738,14 @@ function createConsoleUpdates(options) {
|
|
|
27501
28738
|
};
|
|
27502
28739
|
const kind = installationKind(metadata);
|
|
27503
28740
|
if (kind === "npm") {
|
|
27504
|
-
const
|
|
27505
|
-
if (packageRoot !== resourcesRoot) {
|
|
27506
|
-
throw new ConsoleUpdateError(
|
|
27507
|
-
"unsupported",
|
|
27508
|
-
"npm platform package root does not own this console"
|
|
27509
|
-
);
|
|
27510
|
-
}
|
|
28741
|
+
const npm = await resolveConsoleNpmPaths(target2);
|
|
27511
28742
|
return manager.prepareNpm({
|
|
27512
28743
|
...common,
|
|
27513
|
-
packageRoot,
|
|
27514
|
-
|
|
27515
|
-
|
|
27516
|
-
|
|
28744
|
+
packageRoot: npm.packageRoot,
|
|
28745
|
+
target: metadata.target,
|
|
28746
|
+
nodePath: npm.nodePath,
|
|
28747
|
+
npmCliPath: npm.npmCliPath,
|
|
28748
|
+
npmLauncherPath: npm.npmLauncherPath
|
|
27517
28749
|
});
|
|
27518
28750
|
}
|
|
27519
28751
|
const artifact = selectInstallerReleaseArtifact(release, metadata.target).source;
|
|
@@ -27523,13 +28755,13 @@ function createConsoleUpdates(options) {
|
|
|
27523
28755
|
if (kind === "linux-archive") {
|
|
27524
28756
|
return manager.prepareLinuxArchive({ ...common, artifact, installRoot: resourcesRoot });
|
|
27525
28757
|
}
|
|
27526
|
-
const appPath =
|
|
28758
|
+
const appPath = path20.dirname(path20.dirname(resourcesRoot));
|
|
27527
28759
|
return manager.prepareMacOsDmg({ ...common, artifact, appPath });
|
|
27528
28760
|
}
|
|
27529
28761
|
return Object.freeze({
|
|
27530
28762
|
async check(target2, signal) {
|
|
27531
28763
|
const metadata = target2.distribution;
|
|
27532
|
-
const runtime = metadata ? null : await readRuntimeMetadata(
|
|
28764
|
+
const runtime = metadata ? null : await readRuntimeMetadata(path20.join(target2.appDirectory, "main.js"), environment).catch(
|
|
27533
28765
|
() => null
|
|
27534
28766
|
);
|
|
27535
28767
|
const empty = {
|
|
@@ -27550,13 +28782,48 @@ function createConsoleUpdates(options) {
|
|
|
27550
28782
|
try {
|
|
27551
28783
|
await recoverUpdateOperationLock(stateDirectory());
|
|
27552
28784
|
await cleanupTerminalUpdateState(stateDirectory());
|
|
28785
|
+
await cleanupStagedUpdates(stateDirectory(), { currentVersion: metadata.version });
|
|
27553
28786
|
status = await latestStatus();
|
|
27554
28787
|
const release = await fetchLatest(signal).catch(
|
|
27555
|
-
(error63) => npmFallbackRelease(metadata, error63)
|
|
28788
|
+
(error63) => npmFallbackRelease(metadata, target2, error63)
|
|
27556
28789
|
);
|
|
27557
28790
|
candidate = release;
|
|
27558
28791
|
const updateAvailable = compareSemanticVersions(metadata.version, release.version) < 0;
|
|
27559
28792
|
const { available: installationAvailable, error: error62 } = updateAvailable ? await installable(metadata, target2, release) : { available: false, error: null };
|
|
28793
|
+
let stagedVersion = null;
|
|
28794
|
+
if (updateAvailable && installationAvailable) {
|
|
28795
|
+
if (installationKind(metadata) === "npm") {
|
|
28796
|
+
try {
|
|
28797
|
+
const npm = await resolveConsoleNpmPaths(target2);
|
|
28798
|
+
const verified = await manager.verifyStagedNpm({
|
|
28799
|
+
stateDirectory: stateDirectory(),
|
|
28800
|
+
target: metadata.target,
|
|
28801
|
+
npmTarget: {
|
|
28802
|
+
nodePath: npm.nodePath,
|
|
28803
|
+
npmCliPath: npm.npmCliPath,
|
|
28804
|
+
packageRoot: npm.packageRoot,
|
|
28805
|
+
version: release.version
|
|
28806
|
+
}
|
|
28807
|
+
});
|
|
28808
|
+
if (verified) stagedVersion = release.version;
|
|
28809
|
+
} catch {
|
|
28810
|
+
}
|
|
28811
|
+
} else {
|
|
28812
|
+
const staged = await readStagedUpdate(stateDirectory());
|
|
28813
|
+
if (staged && staged.distribution === "installer" && staged.version === release.version && staged.target === metadata.target) {
|
|
28814
|
+
try {
|
|
28815
|
+
const selected = selectInstallerReleaseArtifact(release, metadata.target);
|
|
28816
|
+
const verified = await verifyStagedArtifact(
|
|
28817
|
+
stateDirectory(),
|
|
28818
|
+
staged,
|
|
28819
|
+
selected.source
|
|
28820
|
+
);
|
|
28821
|
+
if (verified) stagedVersion = staged.version;
|
|
28822
|
+
} catch {
|
|
28823
|
+
}
|
|
28824
|
+
}
|
|
28825
|
+
}
|
|
28826
|
+
}
|
|
27560
28827
|
return {
|
|
27561
28828
|
...empty,
|
|
27562
28829
|
latestVersion: release.version,
|
|
@@ -27565,7 +28832,8 @@ function createConsoleUpdates(options) {
|
|
|
27565
28832
|
releaseNotes: release.releaseNotes,
|
|
27566
28833
|
releaseNotesUrl: release.releaseNotesUrl,
|
|
27567
28834
|
status,
|
|
27568
|
-
error: error62
|
|
28835
|
+
error: error62,
|
|
28836
|
+
...stagedVersion ? { stagedVersion, backgroundPhase: "ready" } : {}
|
|
27569
28837
|
};
|
|
27570
28838
|
} catch (error62) {
|
|
27571
28839
|
return { ...empty, status, error: boundedError(error62) };
|
|
@@ -27582,7 +28850,7 @@ function createConsoleUpdates(options) {
|
|
|
27582
28850
|
if (!metadata) {
|
|
27583
28851
|
throw new ConsoleUpdateError("unsupported", "A source checkout cannot update itself");
|
|
27584
28852
|
}
|
|
27585
|
-
if (!target2.runtimeDescriptorPath || !
|
|
28853
|
+
if (!target2.runtimeDescriptorPath || !path20.isAbsolute(target2.runtimeDescriptorPath)) {
|
|
27586
28854
|
throw new ConsoleUpdateError("unsupported", "The Launcher runtime path is unavailable");
|
|
27587
28855
|
}
|
|
27588
28856
|
if (handedOff) {
|
|
@@ -27599,7 +28867,9 @@ function createConsoleUpdates(options) {
|
|
|
27599
28867
|
}
|
|
27600
28868
|
currentStatusPath = null;
|
|
27601
28869
|
try {
|
|
27602
|
-
const release = await fetchLatest().catch(
|
|
28870
|
+
const release = await fetchLatest().catch(
|
|
28871
|
+
(error62) => npmFallbackRelease(metadata, target2, error62)
|
|
28872
|
+
);
|
|
27603
28873
|
if (compareSemanticVersions(metadata.version, release.version) >= 0 || candidate && candidate.version !== release.version) {
|
|
27604
28874
|
throw new ConsoleUpdateError(
|
|
27605
28875
|
"stale",
|
|
@@ -27653,12 +28923,12 @@ function createConsoleUpdates(options) {
|
|
|
27653
28923
|
// packages/console-server/src/services.ts
|
|
27654
28924
|
import { spawn as spawn2 } from "node:child_process";
|
|
27655
28925
|
import { existsSync as existsSync2 } from "node:fs";
|
|
27656
|
-
import
|
|
28926
|
+
import path21 from "node:path";
|
|
27657
28927
|
function serviceCommand(installation, action, options = {}) {
|
|
27658
28928
|
if (!installation.launcherExecutable) throw new Error("codexhost Launcher was not found");
|
|
27659
28929
|
const resource = (packaged, source) => {
|
|
27660
|
-
const bundled =
|
|
27661
|
-
return existsSync2(bundled) ? bundled :
|
|
28930
|
+
const bundled = path21.join(installation.appDirectory, packaged);
|
|
28931
|
+
return existsSync2(bundled) ? bundled : path21.resolve(installation.appDirectory, "..", "..", source, "dist", "main.js");
|
|
27662
28932
|
};
|
|
27663
28933
|
return {
|
|
27664
28934
|
command: installation.launcherExecutable,
|
|
@@ -27695,8 +28965,8 @@ function runServiceCommand(command2, args, environment) {
|
|
|
27695
28965
|
}
|
|
27696
28966
|
|
|
27697
28967
|
// packages/console-server/src/web-client.ts
|
|
27698
|
-
import { readFile as
|
|
27699
|
-
import
|
|
28968
|
+
import { readFile as readFile12 } from "node:fs/promises";
|
|
28969
|
+
import path22 from "node:path";
|
|
27700
28970
|
var WEB_CONNECTION_METHODS = [
|
|
27701
28971
|
"codexhost/accessTokenGet",
|
|
27702
28972
|
"codexhost/accessTokenRegenerate",
|
|
@@ -27712,9 +28982,9 @@ async function webConnectionRequest(dataDirectory2, method, args) {
|
|
|
27712
28982
|
let token;
|
|
27713
28983
|
try {
|
|
27714
28984
|
const ready = JSON.parse(
|
|
27715
|
-
await
|
|
28985
|
+
await readFile12(path22.join(dataDirectory2, "web-service-ready.json"), "utf8")
|
|
27716
28986
|
);
|
|
27717
|
-
if (!
|
|
28987
|
+
if (!processIsAlive3(ready.pid) || !processIsAlive3(ready.web_pid)) throw new Error();
|
|
27718
28988
|
const login = new URL(ready.loginUrl);
|
|
27719
28989
|
token = login.searchParams.get("token") ?? "";
|
|
27720
28990
|
if (login.protocol !== "http:" || login.hostname !== "127.0.0.1" || login.username || login.password || login.pathname !== "/" || !token)
|
|
@@ -27742,6 +29012,7 @@ async function webConnectionRequest(dataDirectory2, method, args) {
|
|
|
27742
29012
|
}
|
|
27743
29013
|
|
|
27744
29014
|
// packages/console-server/src/server.ts
|
|
29015
|
+
var execFileAsync = promisify2(execFile4);
|
|
27745
29016
|
var CONSOLE_SERVICE = "codexhost-console";
|
|
27746
29017
|
var MAX_BODY_BYTES = 16 * 1024;
|
|
27747
29018
|
var MAX_EXTENSION_INSTALL_BODY_BYTES = 4 * Math.ceil(HOST_EXTENSION_ZIP_MAX_BYTES / 3) + MAX_BODY_BYTES;
|
|
@@ -27860,12 +29131,12 @@ function startConsoleServer(options) {
|
|
|
27860
29131
|
readControllerStatus(options.paths.controllerStatusFile)
|
|
27861
29132
|
]);
|
|
27862
29133
|
const inspectDocument = inspectResult.value;
|
|
27863
|
-
const controllerAlive = controller !== null &&
|
|
29134
|
+
const controllerAlive = controller !== null && processIsAlive3(controller.pid);
|
|
27864
29135
|
const summary = summarize({
|
|
27865
29136
|
running: inspectDocument?.runtime.running ?? false,
|
|
27866
29137
|
desktopError: inspectDocument?.desktopError ?? null,
|
|
27867
29138
|
latestStartup: startup[0] ?? null,
|
|
27868
|
-
launcherAlive: startup[0]?.outcome === "starting" &&
|
|
29139
|
+
launcherAlive: startup[0]?.outcome === "starting" && processIsAlive3(startup[0].pid),
|
|
27869
29140
|
controller,
|
|
27870
29141
|
controllerAlive
|
|
27871
29142
|
});
|
|
@@ -28086,6 +29357,54 @@ function startConsoleServer(options) {
|
|
|
28086
29357
|
return;
|
|
28087
29358
|
}
|
|
28088
29359
|
}
|
|
29360
|
+
if (route === "GET /api/update/macos-signing/status" || route === "POST /api/update/macos-signing/setup" || route === "POST /api/update/macos-signing/remove") {
|
|
29361
|
+
const action = route.endsWith("/setup") ? "setup" : route.endsWith("/remove") ? "remove" : "status";
|
|
29362
|
+
if (await options.host.available()) {
|
|
29363
|
+
const reply = await options.host.request(`codexhost/update/macos-signing/${action}`, {}).catch((error62) => ({
|
|
29364
|
+
error: {
|
|
29365
|
+
code: -32603,
|
|
29366
|
+
message: error62 instanceof Error ? error62.message : String(error62)
|
|
29367
|
+
}
|
|
29368
|
+
}));
|
|
29369
|
+
if ("error" in reply) sendJson(response, 500, { error: reply.error.message });
|
|
29370
|
+
else sendJson(response, 200, reply.result);
|
|
29371
|
+
return;
|
|
29372
|
+
}
|
|
29373
|
+
if (process.platform !== "darwin" || !options.installation.launcherExecutable) {
|
|
29374
|
+
if (action === "status") {
|
|
29375
|
+
sendJson(response, 200, {
|
|
29376
|
+
supported: false,
|
|
29377
|
+
enabled: false,
|
|
29378
|
+
certificatePresent: false,
|
|
29379
|
+
appSignedWithLocalCert: false,
|
|
29380
|
+
appPath: null,
|
|
29381
|
+
certificateName: "CodexHost Local Signer",
|
|
29382
|
+
certificateSha1: null
|
|
29383
|
+
});
|
|
29384
|
+
} else {
|
|
29385
|
+
sendJson(response, 400, { error: "macOS local signing is unavailable" });
|
|
29386
|
+
}
|
|
29387
|
+
return;
|
|
29388
|
+
}
|
|
29389
|
+
try {
|
|
29390
|
+
const { stdout } = await execFileAsync(
|
|
29391
|
+
options.installation.launcherExecutable,
|
|
29392
|
+
["macos-signing", action, "--json"],
|
|
29393
|
+
{
|
|
29394
|
+
env: serviceEnvironment(),
|
|
29395
|
+
timeout: action === "setup" ? 12e4 : 3e4,
|
|
29396
|
+
maxBuffer: 256 * 1024
|
|
29397
|
+
}
|
|
29398
|
+
);
|
|
29399
|
+
sendJson(response, 200, macosLocalSigningStatusSchema.parse(JSON.parse(stdout.trim())));
|
|
29400
|
+
} catch (error62) {
|
|
29401
|
+
const stderr = typeof error62 === "object" && error62 !== null && "stderr" in error62 && typeof error62.stderr === "string" ? error62.stderr.trim() : "";
|
|
29402
|
+
sendJson(response, 500, {
|
|
29403
|
+
error: stderr || (error62 instanceof Error ? error62.message : String(error62))
|
|
29404
|
+
});
|
|
29405
|
+
}
|
|
29406
|
+
return;
|
|
29407
|
+
}
|
|
28089
29408
|
if (route === "POST /api/update/check") {
|
|
28090
29409
|
sendJson(response, 200, await options.updates.check(await updateTarget()));
|
|
28091
29410
|
return;
|
|
@@ -28251,7 +29570,7 @@ async function stopConsole(environment = process.env) {
|
|
|
28251
29570
|
return true;
|
|
28252
29571
|
}
|
|
28253
29572
|
async function consoleBuildId(entryPath2, environment = process.env) {
|
|
28254
|
-
const files = [entryPath2, ...consoleBundleCandidates(
|
|
29573
|
+
const files = [entryPath2, ...consoleBundleCandidates(path23.dirname(entryPath2))];
|
|
28255
29574
|
const parts = [];
|
|
28256
29575
|
for (const file2 of files) {
|
|
28257
29576
|
const metadata = await stat4(file2).catch(() => null);
|
|
@@ -28317,7 +29636,7 @@ async function openConsole(options) {
|
|
|
28317
29636
|
}
|
|
28318
29637
|
|
|
28319
29638
|
// packages/console-server/src/update-cli.ts
|
|
28320
|
-
import { setTimeout as
|
|
29639
|
+
import { setTimeout as delay6 } from "node:timers/promises";
|
|
28321
29640
|
var POLL_INTERVAL_MS = 500;
|
|
28322
29641
|
var DOWNLOAD_IDLE_TIMEOUT_MS = 15 * 6e4;
|
|
28323
29642
|
function downloadMessage(status) {
|
|
@@ -28355,7 +29674,7 @@ async function runUpdateCommand(target2, updates, write = (message) => console.l
|
|
|
28355
29674
|
write(message, true);
|
|
28356
29675
|
};
|
|
28357
29676
|
const starting = updates.start(target2).then(({ status: status2 }) => status2);
|
|
28358
|
-
const startOrPoll = () => Promise.race([starting,
|
|
29677
|
+
const startOrPoll = () => Promise.race([starting, delay6(POLL_INTERVAL_MS, null, { ref: false })]);
|
|
28359
29678
|
let status = await startOrPoll();
|
|
28360
29679
|
while (status === null) {
|
|
28361
29680
|
report((await updates.status()).status);
|
|
@@ -28366,7 +29685,7 @@ async function runUpdateCommand(target2, updates, write = (message) => console.l
|
|
|
28366
29685
|
report(status);
|
|
28367
29686
|
if (Date.now() - Math.max(waitingSince, status.updatedAt * 1e3) >= DOWNLOAD_IDLE_TIMEOUT_MS)
|
|
28368
29687
|
throw new Error("Timed out waiting for download progress");
|
|
28369
|
-
await
|
|
29688
|
+
await delay6(POLL_INTERVAL_MS);
|
|
28370
29689
|
const current = (await updates.status()).status;
|
|
28371
29690
|
if (current?.version === status.version && current.installation === status.installation)
|
|
28372
29691
|
status = current;
|
|
@@ -28431,7 +29750,7 @@ async function updateFromCommand(appDirectory2, arguments_) {
|
|
|
28431
29750
|
var IDLE_TIMEOUT_MS = 30 * 60 * 1e3;
|
|
28432
29751
|
var HANDOFF_EXIT_DELAY_MS = 500;
|
|
28433
29752
|
var entryPath = fileURLToPath(import.meta.url);
|
|
28434
|
-
var appDirectory =
|
|
29753
|
+
var appDirectory = path24.dirname(entryPath);
|
|
28435
29754
|
function usage() {
|
|
28436
29755
|
console.error(
|
|
28437
29756
|
"usage: console-server open [--no-browser] | console-server ensure | console-server serve | console-server stop | console-server update"
|
|
@@ -28479,7 +29798,7 @@ function parseOpenArguments(arguments_) {
|
|
|
28479
29798
|
}
|
|
28480
29799
|
return parsed;
|
|
28481
29800
|
}
|
|
28482
|
-
async function
|
|
29801
|
+
async function open8(arguments_) {
|
|
28483
29802
|
const parsed = parseOpenArguments(arguments_);
|
|
28484
29803
|
const installation = await resolveInstallation(appDirectory);
|
|
28485
29804
|
const url2 = await openConsole({
|
|
@@ -28500,7 +29819,7 @@ async function stop(arguments_) {
|
|
|
28500
29819
|
process.exitCode = await stopConsole() ? 0 : 3;
|
|
28501
29820
|
}
|
|
28502
29821
|
var [command, ...rest] = process.argv.slice(2);
|
|
28503
|
-
var run = command === "serve" ? serve() : command === "open" ?
|
|
29822
|
+
var run = command === "serve" ? serve() : command === "open" ? open8(rest) : command === "ensure" ? ensure(rest) : command === "stop" ? stop(rest) : command === "update" ? updateFromCommand(appDirectory, rest) : usage();
|
|
28504
29823
|
run.catch((error62) => {
|
|
28505
29824
|
console.error(`codexhost console: ${error62 instanceof Error ? error62.message : String(error62)}`);
|
|
28506
29825
|
process.exit(1);
|