@slock-ai/computer 0.0.16 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +514 -229
- package/dist/lib/index.d.ts +172 -72
- package/dist/lib/index.js +357 -125
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5729,9 +5729,9 @@ var require_dispatcher_base = __commonJS({
|
|
|
5729
5729
|
}
|
|
5730
5730
|
close(callback) {
|
|
5731
5731
|
if (callback === void 0) {
|
|
5732
|
-
return new Promise((
|
|
5732
|
+
return new Promise((resolve2, reject) => {
|
|
5733
5733
|
this.close((err, data) => {
|
|
5734
|
-
return err ? reject(err) :
|
|
5734
|
+
return err ? reject(err) : resolve2(data);
|
|
5735
5735
|
});
|
|
5736
5736
|
});
|
|
5737
5737
|
}
|
|
@@ -5769,9 +5769,9 @@ var require_dispatcher_base = __commonJS({
|
|
|
5769
5769
|
err = null;
|
|
5770
5770
|
}
|
|
5771
5771
|
if (callback === void 0) {
|
|
5772
|
-
return new Promise((
|
|
5772
|
+
return new Promise((resolve2, reject) => {
|
|
5773
5773
|
this.destroy(err, (err2, data) => {
|
|
5774
|
-
return err2 ? reject(err2) :
|
|
5774
|
+
return err2 ? reject(err2) : resolve2(data);
|
|
5775
5775
|
});
|
|
5776
5776
|
});
|
|
5777
5777
|
}
|
|
@@ -9264,8 +9264,8 @@ var require_promise = __commonJS({
|
|
|
9264
9264
|
function createDeferredPromise() {
|
|
9265
9265
|
let res;
|
|
9266
9266
|
let rej;
|
|
9267
|
-
const promise = new Promise((
|
|
9268
|
-
res =
|
|
9267
|
+
const promise = new Promise((resolve2, reject) => {
|
|
9268
|
+
res = resolve2;
|
|
9269
9269
|
rej = reject;
|
|
9270
9270
|
});
|
|
9271
9271
|
return { promise, resolve: res, reject: rej };
|
|
@@ -10568,12 +10568,12 @@ upgrade: ${upgrade}\r
|
|
|
10568
10568
|
cb();
|
|
10569
10569
|
}
|
|
10570
10570
|
}
|
|
10571
|
-
const waitForDrain = () => new Promise((
|
|
10571
|
+
const waitForDrain = () => new Promise((resolve2, reject) => {
|
|
10572
10572
|
assert(callback === null);
|
|
10573
10573
|
if (socket[kError]) {
|
|
10574
10574
|
reject(socket[kError]);
|
|
10575
10575
|
} else {
|
|
10576
|
-
callback =
|
|
10576
|
+
callback = resolve2;
|
|
10577
10577
|
}
|
|
10578
10578
|
});
|
|
10579
10579
|
socket.on("close", onDrain).on("drain", onDrain);
|
|
@@ -11419,12 +11419,12 @@ var require_client_h2 = __commonJS({
|
|
|
11419
11419
|
cb();
|
|
11420
11420
|
}
|
|
11421
11421
|
}
|
|
11422
|
-
const waitForDrain = () => new Promise((
|
|
11422
|
+
const waitForDrain = () => new Promise((resolve2, reject) => {
|
|
11423
11423
|
assert(callback === null);
|
|
11424
11424
|
if (socket[kError]) {
|
|
11425
11425
|
reject(socket[kError]);
|
|
11426
11426
|
} else {
|
|
11427
|
-
callback =
|
|
11427
|
+
callback = resolve2;
|
|
11428
11428
|
}
|
|
11429
11429
|
});
|
|
11430
11430
|
h2stream.on("close", onDrain).on("drain", onDrain);
|
|
@@ -11736,16 +11736,16 @@ var require_client = __commonJS({
|
|
|
11736
11736
|
return this[kNeedDrain] < 2;
|
|
11737
11737
|
}
|
|
11738
11738
|
[kClose]() {
|
|
11739
|
-
return new Promise((
|
|
11739
|
+
return new Promise((resolve2) => {
|
|
11740
11740
|
if (this[kSize]) {
|
|
11741
|
-
this[kClosedResolve] =
|
|
11741
|
+
this[kClosedResolve] = resolve2;
|
|
11742
11742
|
} else {
|
|
11743
|
-
|
|
11743
|
+
resolve2(null);
|
|
11744
11744
|
}
|
|
11745
11745
|
});
|
|
11746
11746
|
}
|
|
11747
11747
|
[kDestroy](err) {
|
|
11748
|
-
return new Promise((
|
|
11748
|
+
return new Promise((resolve2) => {
|
|
11749
11749
|
const requests = this[kQueue].splice(this[kPendingIdx]);
|
|
11750
11750
|
for (let i = 0; i < requests.length; i++) {
|
|
11751
11751
|
const request = requests[i];
|
|
@@ -11756,7 +11756,7 @@ var require_client = __commonJS({
|
|
|
11756
11756
|
this[kClosedResolve]();
|
|
11757
11757
|
this[kClosedResolve] = null;
|
|
11758
11758
|
}
|
|
11759
|
-
|
|
11759
|
+
resolve2(null);
|
|
11760
11760
|
};
|
|
11761
11761
|
if (this[kHTTPContext]) {
|
|
11762
11762
|
this[kHTTPContext].destroy(err, callback);
|
|
@@ -12163,8 +12163,8 @@ var require_pool_base = __commonJS({
|
|
|
12163
12163
|
}
|
|
12164
12164
|
return Promise.all(closeAll);
|
|
12165
12165
|
} else {
|
|
12166
|
-
return new Promise((
|
|
12167
|
-
this[kClosedResolve] =
|
|
12166
|
+
return new Promise((resolve2) => {
|
|
12167
|
+
this[kClosedResolve] = resolve2;
|
|
12168
12168
|
});
|
|
12169
12169
|
}
|
|
12170
12170
|
}
|
|
@@ -13263,10 +13263,10 @@ var require_socks5_proxy_agent = __commonJS({
|
|
|
13263
13263
|
const proxyHost = this[kProxyUrl].hostname;
|
|
13264
13264
|
const proxyPort = parseInt(this[kProxyUrl].port) || 1080;
|
|
13265
13265
|
debug("creating SOCKS5 connection to", proxyHost, proxyPort);
|
|
13266
|
-
const socket = await new Promise((
|
|
13266
|
+
const socket = await new Promise((resolve2, reject) => {
|
|
13267
13267
|
const onConnect = () => {
|
|
13268
13268
|
socket2.removeListener("error", onError);
|
|
13269
|
-
|
|
13269
|
+
resolve2(socket2);
|
|
13270
13270
|
};
|
|
13271
13271
|
const onError = (err) => {
|
|
13272
13272
|
socket2.removeListener("connect", onConnect);
|
|
@@ -13285,14 +13285,14 @@ var require_socks5_proxy_agent = __commonJS({
|
|
|
13285
13285
|
socket.destroy();
|
|
13286
13286
|
});
|
|
13287
13287
|
await socks5Client.handshake();
|
|
13288
|
-
await new Promise((
|
|
13288
|
+
await new Promise((resolve2, reject) => {
|
|
13289
13289
|
const timeout = setTimeout(() => {
|
|
13290
13290
|
reject(new Error("SOCKS5 authentication timeout"));
|
|
13291
13291
|
}, 5e3);
|
|
13292
13292
|
const onAuthenticated = () => {
|
|
13293
13293
|
clearTimeout(timeout);
|
|
13294
13294
|
socks5Client.removeListener("error", onError);
|
|
13295
|
-
|
|
13295
|
+
resolve2();
|
|
13296
13296
|
};
|
|
13297
13297
|
const onError = (err) => {
|
|
13298
13298
|
clearTimeout(timeout);
|
|
@@ -13301,14 +13301,14 @@ var require_socks5_proxy_agent = __commonJS({
|
|
|
13301
13301
|
};
|
|
13302
13302
|
if (socks5Client.state === "authenticated") {
|
|
13303
13303
|
clearTimeout(timeout);
|
|
13304
|
-
|
|
13304
|
+
resolve2();
|
|
13305
13305
|
} else {
|
|
13306
13306
|
socks5Client.once("authenticated", onAuthenticated);
|
|
13307
13307
|
socks5Client.once("error", onError);
|
|
13308
13308
|
}
|
|
13309
13309
|
});
|
|
13310
13310
|
await socks5Client.connect(targetHost, targetPort);
|
|
13311
|
-
await new Promise((
|
|
13311
|
+
await new Promise((resolve2, reject) => {
|
|
13312
13312
|
const timeout = setTimeout(() => {
|
|
13313
13313
|
reject(new Error("SOCKS5 connection timeout"));
|
|
13314
13314
|
}, 5e3);
|
|
@@ -13316,7 +13316,7 @@ var require_socks5_proxy_agent = __commonJS({
|
|
|
13316
13316
|
debug("SOCKS5 tunnel established to", targetHost, targetPort, "via", info2);
|
|
13317
13317
|
clearTimeout(timeout);
|
|
13318
13318
|
socks5Client.removeListener("error", onError);
|
|
13319
|
-
|
|
13319
|
+
resolve2();
|
|
13320
13320
|
};
|
|
13321
13321
|
const onError = (err) => {
|
|
13322
13322
|
clearTimeout(timeout);
|
|
@@ -13357,8 +13357,8 @@ var require_socks5_proxy_agent = __commonJS({
|
|
|
13357
13357
|
servername: targetHost,
|
|
13358
13358
|
...connectOpts.tls || {}
|
|
13359
13359
|
});
|
|
13360
|
-
await new Promise((
|
|
13361
|
-
finalSocket.once("secureConnect",
|
|
13360
|
+
await new Promise((resolve2, reject) => {
|
|
13361
|
+
finalSocket.once("secureConnect", resolve2);
|
|
13362
13362
|
finalSocket.once("error", reject);
|
|
13363
13363
|
});
|
|
13364
13364
|
}
|
|
@@ -14389,7 +14389,7 @@ var require_readable = __commonJS({
|
|
|
14389
14389
|
if (this._readableState.closeEmitted) {
|
|
14390
14390
|
return Promise.resolve(null);
|
|
14391
14391
|
}
|
|
14392
|
-
return new Promise((
|
|
14392
|
+
return new Promise((resolve2, reject) => {
|
|
14393
14393
|
if (this[kContentLength] && this[kContentLength] > limit || this[kBytesRead] > limit) {
|
|
14394
14394
|
this.destroy(new AbortError());
|
|
14395
14395
|
}
|
|
@@ -14403,11 +14403,11 @@ var require_readable = __commonJS({
|
|
|
14403
14403
|
if (signal.aborted) {
|
|
14404
14404
|
reject(signal.reason ?? new AbortError());
|
|
14405
14405
|
} else {
|
|
14406
|
-
|
|
14406
|
+
resolve2(null);
|
|
14407
14407
|
}
|
|
14408
14408
|
});
|
|
14409
14409
|
} else {
|
|
14410
|
-
this.on("close",
|
|
14410
|
+
this.on("close", resolve2);
|
|
14411
14411
|
}
|
|
14412
14412
|
this.on("error", noop).on("data", () => {
|
|
14413
14413
|
if (this[kBytesRead] > limit) {
|
|
@@ -14435,7 +14435,7 @@ var require_readable = __commonJS({
|
|
|
14435
14435
|
}
|
|
14436
14436
|
function consume(stream, type) {
|
|
14437
14437
|
assert(!stream[kConsume]);
|
|
14438
|
-
return new Promise((
|
|
14438
|
+
return new Promise((resolve2, reject) => {
|
|
14439
14439
|
if (isUnusable(stream)) {
|
|
14440
14440
|
const rState = stream._readableState;
|
|
14441
14441
|
if (rState.destroyed && rState.closeEmitted === false) {
|
|
@@ -14450,7 +14450,7 @@ var require_readable = __commonJS({
|
|
|
14450
14450
|
stream[kConsume] = {
|
|
14451
14451
|
type,
|
|
14452
14452
|
stream,
|
|
14453
|
-
resolve,
|
|
14453
|
+
resolve: resolve2,
|
|
14454
14454
|
reject,
|
|
14455
14455
|
length: 0,
|
|
14456
14456
|
body: []
|
|
@@ -14524,18 +14524,18 @@ var require_readable = __commonJS({
|
|
|
14524
14524
|
return buffer;
|
|
14525
14525
|
}
|
|
14526
14526
|
function consumeEnd(consume2, encoding) {
|
|
14527
|
-
const { type, body, resolve, stream, length } = consume2;
|
|
14527
|
+
const { type, body, resolve: resolve2, stream, length } = consume2;
|
|
14528
14528
|
try {
|
|
14529
14529
|
if (type === "text") {
|
|
14530
|
-
|
|
14530
|
+
resolve2(chunksDecode(body, length, encoding));
|
|
14531
14531
|
} else if (type === "json") {
|
|
14532
|
-
|
|
14532
|
+
resolve2(JSON.parse(chunksDecode(body, length, encoding)));
|
|
14533
14533
|
} else if (type === "arrayBuffer") {
|
|
14534
|
-
|
|
14534
|
+
resolve2(chunksConcat(body, length).buffer);
|
|
14535
14535
|
} else if (type === "blob") {
|
|
14536
|
-
|
|
14536
|
+
resolve2(new Blob(body, { type: stream[kContentType] }));
|
|
14537
14537
|
} else if (type === "bytes") {
|
|
14538
|
-
|
|
14538
|
+
resolve2(chunksConcat(body, length));
|
|
14539
14539
|
}
|
|
14540
14540
|
consumeFinish(consume2);
|
|
14541
14541
|
} catch (err) {
|
|
@@ -14726,9 +14726,9 @@ var require_api_request = __commonJS({
|
|
|
14726
14726
|
};
|
|
14727
14727
|
function request(opts, callback) {
|
|
14728
14728
|
if (callback === void 0) {
|
|
14729
|
-
return new Promise((
|
|
14729
|
+
return new Promise((resolve2, reject) => {
|
|
14730
14730
|
request.call(this, opts, (err, data) => {
|
|
14731
|
-
return err ? reject(err) :
|
|
14731
|
+
return err ? reject(err) : resolve2(data);
|
|
14732
14732
|
});
|
|
14733
14733
|
});
|
|
14734
14734
|
}
|
|
@@ -14942,9 +14942,9 @@ var require_api_stream = __commonJS({
|
|
|
14942
14942
|
};
|
|
14943
14943
|
function stream(opts, factory, callback) {
|
|
14944
14944
|
if (callback === void 0) {
|
|
14945
|
-
return new Promise((
|
|
14945
|
+
return new Promise((resolve2, reject) => {
|
|
14946
14946
|
stream.call(this, opts, factory, (err, data) => {
|
|
14947
|
-
return err ? reject(err) :
|
|
14947
|
+
return err ? reject(err) : resolve2(data);
|
|
14948
14948
|
});
|
|
14949
14949
|
});
|
|
14950
14950
|
}
|
|
@@ -15234,9 +15234,9 @@ var require_api_upgrade = __commonJS({
|
|
|
15234
15234
|
};
|
|
15235
15235
|
function upgrade(opts, callback) {
|
|
15236
15236
|
if (callback === void 0) {
|
|
15237
|
-
return new Promise((
|
|
15237
|
+
return new Promise((resolve2, reject) => {
|
|
15238
15238
|
upgrade.call(this, opts, (err, data) => {
|
|
15239
|
-
return err ? reject(err) :
|
|
15239
|
+
return err ? reject(err) : resolve2(data);
|
|
15240
15240
|
});
|
|
15241
15241
|
});
|
|
15242
15242
|
}
|
|
@@ -15330,9 +15330,9 @@ var require_api_connect = __commonJS({
|
|
|
15330
15330
|
};
|
|
15331
15331
|
function connect(opts, callback) {
|
|
15332
15332
|
if (callback === void 0) {
|
|
15333
|
-
return new Promise((
|
|
15333
|
+
return new Promise((resolve2, reject) => {
|
|
15334
15334
|
connect.call(this, opts, (err, data) => {
|
|
15335
|
-
return err ? reject(err) :
|
|
15335
|
+
return err ? reject(err) : resolve2(data);
|
|
15336
15336
|
});
|
|
15337
15337
|
});
|
|
15338
15338
|
}
|
|
@@ -16618,7 +16618,7 @@ var require_snapshot_recorder = __commonJS({
|
|
|
16618
16618
|
"use strict";
|
|
16619
16619
|
init_esm_shims();
|
|
16620
16620
|
var { writeFile: writeFile13, readFile: readFile17, mkdir: mkdir17 } = __require("fs/promises");
|
|
16621
|
-
var { dirname: dirname14, resolve } = __require("path");
|
|
16621
|
+
var { dirname: dirname14, resolve: resolve2 } = __require("path");
|
|
16622
16622
|
var { setTimeout: setTimeout2, clearTimeout: clearTimeout2 } = __require("timers");
|
|
16623
16623
|
var { InvalidArgumentError: InvalidArgumentError2, UndiciError } = require_errors();
|
|
16624
16624
|
var { hashId, isUrlExcludedFactory, normalizeHeaders, createHeaderFilters } = require_snapshot_utils();
|
|
@@ -16819,7 +16819,7 @@ var require_snapshot_recorder = __commonJS({
|
|
|
16819
16819
|
throw new InvalidArgumentError2("Snapshot path is required");
|
|
16820
16820
|
}
|
|
16821
16821
|
try {
|
|
16822
|
-
const data = await readFile17(
|
|
16822
|
+
const data = await readFile17(resolve2(path3), "utf8");
|
|
16823
16823
|
const parsed = JSON.parse(data);
|
|
16824
16824
|
if (Array.isArray(parsed)) {
|
|
16825
16825
|
this.#snapshots.clear();
|
|
@@ -16848,7 +16848,7 @@ var require_snapshot_recorder = __commonJS({
|
|
|
16848
16848
|
if (!path3) {
|
|
16849
16849
|
throw new InvalidArgumentError2("Snapshot path is required");
|
|
16850
16850
|
}
|
|
16851
|
-
const resolvedPath =
|
|
16851
|
+
const resolvedPath = resolve2(path3);
|
|
16852
16852
|
await mkdir17(dirname14(resolvedPath), { recursive: true });
|
|
16853
16853
|
const data = Array.from(this.#snapshots.entries()).map(([hash, snapshot]) => ({
|
|
16854
16854
|
hash,
|
|
@@ -23714,7 +23714,7 @@ var require_fetch = __commonJS({
|
|
|
23714
23714
|
const agent = fetchParams.controller.dispatcher;
|
|
23715
23715
|
const path3 = url.pathname + url.search;
|
|
23716
23716
|
const hasTrailingQuestionMark = url.search.length === 0 && url.href[url.href.length - url.hash.length - 1] === "?";
|
|
23717
|
-
return new Promise((
|
|
23717
|
+
return new Promise((resolve2, reject) => agent.dispatch(
|
|
23718
23718
|
{
|
|
23719
23719
|
path: hasTrailingQuestionMark ? `${path3}?` : path3,
|
|
23720
23720
|
origin: url.origin,
|
|
@@ -23802,7 +23802,7 @@ var require_fetch = __commonJS({
|
|
|
23802
23802
|
}
|
|
23803
23803
|
}
|
|
23804
23804
|
const onError = this.onError.bind(this);
|
|
23805
|
-
|
|
23805
|
+
resolve2({
|
|
23806
23806
|
status,
|
|
23807
23807
|
statusText,
|
|
23808
23808
|
headersList,
|
|
@@ -23855,7 +23855,7 @@ var require_fetch = __commonJS({
|
|
|
23855
23855
|
headersList.append(headerName, String(value), true);
|
|
23856
23856
|
}
|
|
23857
23857
|
}
|
|
23858
|
-
|
|
23858
|
+
resolve2({
|
|
23859
23859
|
status,
|
|
23860
23860
|
statusText: STATUS_CODES[status],
|
|
23861
23861
|
headersList,
|
|
@@ -23879,7 +23879,7 @@ var require_fetch = __commonJS({
|
|
|
23879
23879
|
headersList.append(nameStr, value.toString("latin1"), true);
|
|
23880
23880
|
}
|
|
23881
23881
|
}
|
|
23882
|
-
|
|
23882
|
+
resolve2({
|
|
23883
23883
|
status,
|
|
23884
23884
|
statusText: STATUS_CODES[status],
|
|
23885
23885
|
headersList,
|
|
@@ -29193,11 +29193,11 @@ var require_mtime_precision = __commonJS({
|
|
|
29193
29193
|
function probe(file, fs, callback) {
|
|
29194
29194
|
const cachedPrecision = fs[cacheSymbol];
|
|
29195
29195
|
if (cachedPrecision) {
|
|
29196
|
-
return fs.stat(file, (err,
|
|
29196
|
+
return fs.stat(file, (err, stat5) => {
|
|
29197
29197
|
if (err) {
|
|
29198
29198
|
return callback(err);
|
|
29199
29199
|
}
|
|
29200
|
-
callback(null,
|
|
29200
|
+
callback(null, stat5.mtime, cachedPrecision);
|
|
29201
29201
|
});
|
|
29202
29202
|
}
|
|
29203
29203
|
const mtime = new Date(Math.ceil(Date.now() / 1e3) * 1e3 + 5);
|
|
@@ -29205,13 +29205,13 @@ var require_mtime_precision = __commonJS({
|
|
|
29205
29205
|
if (err) {
|
|
29206
29206
|
return callback(err);
|
|
29207
29207
|
}
|
|
29208
|
-
fs.stat(file, (err2,
|
|
29208
|
+
fs.stat(file, (err2, stat5) => {
|
|
29209
29209
|
if (err2) {
|
|
29210
29210
|
return callback(err2);
|
|
29211
29211
|
}
|
|
29212
|
-
const precision =
|
|
29212
|
+
const precision = stat5.mtime.getTime() % 1e3 === 0 ? "s" : "ms";
|
|
29213
29213
|
Object.defineProperty(fs, cacheSymbol, { value: precision });
|
|
29214
|
-
callback(null,
|
|
29214
|
+
callback(null, stat5.mtime, precision);
|
|
29215
29215
|
});
|
|
29216
29216
|
});
|
|
29217
29217
|
}
|
|
@@ -29266,14 +29266,14 @@ var require_lockfile = __commonJS({
|
|
|
29266
29266
|
if (options.stale <= 0) {
|
|
29267
29267
|
return callback(Object.assign(new Error("Lock file is already being held"), { code: "ELOCKED", file }));
|
|
29268
29268
|
}
|
|
29269
|
-
options.fs.stat(lockfilePath, (err2,
|
|
29269
|
+
options.fs.stat(lockfilePath, (err2, stat5) => {
|
|
29270
29270
|
if (err2) {
|
|
29271
29271
|
if (err2.code === "ENOENT") {
|
|
29272
29272
|
return acquireLock(file, { ...options, stale: 0 }, callback);
|
|
29273
29273
|
}
|
|
29274
29274
|
return callback(err2);
|
|
29275
29275
|
}
|
|
29276
|
-
if (!isLockStale(
|
|
29276
|
+
if (!isLockStale(stat5, options)) {
|
|
29277
29277
|
return callback(Object.assign(new Error("Lock file is already being held"), { code: "ELOCKED", file }));
|
|
29278
29278
|
}
|
|
29279
29279
|
removeLock(file, options, (err3) => {
|
|
@@ -29285,8 +29285,8 @@ var require_lockfile = __commonJS({
|
|
|
29285
29285
|
});
|
|
29286
29286
|
});
|
|
29287
29287
|
}
|
|
29288
|
-
function isLockStale(
|
|
29289
|
-
return
|
|
29288
|
+
function isLockStale(stat5, options) {
|
|
29289
|
+
return stat5.mtime.getTime() < Date.now() - options.stale;
|
|
29290
29290
|
}
|
|
29291
29291
|
function removeLock(file, options, callback) {
|
|
29292
29292
|
options.fs.rmdir(getLockFile(file, options), (err) => {
|
|
@@ -29304,7 +29304,7 @@ var require_lockfile = __commonJS({
|
|
|
29304
29304
|
lock2.updateDelay = lock2.updateDelay || options.update;
|
|
29305
29305
|
lock2.updateTimeout = setTimeout(() => {
|
|
29306
29306
|
lock2.updateTimeout = null;
|
|
29307
|
-
options.fs.stat(lock2.lockfilePath, (err,
|
|
29307
|
+
options.fs.stat(lock2.lockfilePath, (err, stat5) => {
|
|
29308
29308
|
const isOverThreshold = lock2.lastUpdate + options.stale < Date.now();
|
|
29309
29309
|
if (err) {
|
|
29310
29310
|
if (err.code === "ENOENT" || isOverThreshold) {
|
|
@@ -29313,7 +29313,7 @@ var require_lockfile = __commonJS({
|
|
|
29313
29313
|
lock2.updateDelay = 1e3;
|
|
29314
29314
|
return updateLock(file, options);
|
|
29315
29315
|
}
|
|
29316
|
-
const isMtimeOurs = lock2.mtime.getTime() ===
|
|
29316
|
+
const isMtimeOurs = lock2.mtime.getTime() === stat5.mtime.getTime();
|
|
29317
29317
|
if (!isMtimeOurs) {
|
|
29318
29318
|
return setLockAsCompromised(
|
|
29319
29319
|
file,
|
|
@@ -29438,11 +29438,11 @@ var require_lockfile = __commonJS({
|
|
|
29438
29438
|
if (err) {
|
|
29439
29439
|
return callback(err);
|
|
29440
29440
|
}
|
|
29441
|
-
options.fs.stat(getLockFile(file2, options), (err2,
|
|
29441
|
+
options.fs.stat(getLockFile(file2, options), (err2, stat5) => {
|
|
29442
29442
|
if (err2) {
|
|
29443
29443
|
return err2.code === "ENOENT" ? callback(null, false) : callback(err2);
|
|
29444
29444
|
}
|
|
29445
|
-
return callback(null, !isLockStale(
|
|
29445
|
+
return callback(null, !isLockStale(stat5, options));
|
|
29446
29446
|
});
|
|
29447
29447
|
});
|
|
29448
29448
|
}
|
|
@@ -29489,12 +29489,12 @@ var require_adapter = __commonJS({
|
|
|
29489
29489
|
return newFs;
|
|
29490
29490
|
}
|
|
29491
29491
|
function toPromise(method) {
|
|
29492
|
-
return (...args) => new Promise((
|
|
29492
|
+
return (...args) => new Promise((resolve2, reject) => {
|
|
29493
29493
|
args.push((err, result) => {
|
|
29494
29494
|
if (err) {
|
|
29495
29495
|
reject(err);
|
|
29496
29496
|
} else {
|
|
29497
|
-
|
|
29497
|
+
resolve2(result);
|
|
29498
29498
|
}
|
|
29499
29499
|
});
|
|
29500
29500
|
method(...args);
|
|
@@ -29799,6 +29799,52 @@ var ComputerAttachClient = class {
|
|
|
29799
29799
|
return { ok: false, code };
|
|
29800
29800
|
}
|
|
29801
29801
|
};
|
|
29802
|
+
var LegacyMachinesClient = class {
|
|
29803
|
+
constructor(baseUrl, accessToken) {
|
|
29804
|
+
this.baseUrl = baseUrl;
|
|
29805
|
+
this.accessToken = accessToken;
|
|
29806
|
+
}
|
|
29807
|
+
url(p) {
|
|
29808
|
+
return new URL(p, this.baseUrl).toString();
|
|
29809
|
+
}
|
|
29810
|
+
async list(serverSlug) {
|
|
29811
|
+
let res;
|
|
29812
|
+
try {
|
|
29813
|
+
res = await (0, import_undici.fetch)(
|
|
29814
|
+
this.url(`/api/computer/legacy-machines?serverSlug=${encodeURIComponent(serverSlug)}`),
|
|
29815
|
+
{
|
|
29816
|
+
method: "GET",
|
|
29817
|
+
headers: { Authorization: `Bearer ${this.accessToken}` }
|
|
29818
|
+
}
|
|
29819
|
+
);
|
|
29820
|
+
} catch {
|
|
29821
|
+
return { status: "error", code: "request_failed" };
|
|
29822
|
+
}
|
|
29823
|
+
const body = await res.json().catch(() => null);
|
|
29824
|
+
if (res.status === 200 && body && Array.isArray(body.entries)) {
|
|
29825
|
+
const entries = body.entries.map((raw) => {
|
|
29826
|
+
if (!raw || typeof raw !== "object") return null;
|
|
29827
|
+
const e = raw;
|
|
29828
|
+
if (typeof e.daemonId !== "string" || typeof e.apiKeyFingerprint !== "string" || typeof e.machineName !== "string") {
|
|
29829
|
+
return null;
|
|
29830
|
+
}
|
|
29831
|
+
return {
|
|
29832
|
+
daemonId: e.daemonId,
|
|
29833
|
+
apiKeyFingerprint: e.apiKeyFingerprint,
|
|
29834
|
+
machineName: e.machineName,
|
|
29835
|
+
hostname: typeof e.hostname === "string" ? e.hostname : null,
|
|
29836
|
+
lastSeenAt: typeof e.lastSeenAt === "string" ? e.lastSeenAt : null
|
|
29837
|
+
};
|
|
29838
|
+
}).filter((entry) => entry !== null);
|
|
29839
|
+
return { status: "success", entries };
|
|
29840
|
+
}
|
|
29841
|
+
if (res.status === 401) return { status: "auth_required" };
|
|
29842
|
+
if (res.status === 403) return { status: "not_authorized" };
|
|
29843
|
+
if (res.status === 404) return { status: "disabled" };
|
|
29844
|
+
const code = body && typeof body.code === "string" ? body.code : `http_${res.status}`;
|
|
29845
|
+
return { status: "error", code };
|
|
29846
|
+
}
|
|
29847
|
+
};
|
|
29802
29848
|
var RunnersClient = class {
|
|
29803
29849
|
constructor(baseUrl, computerApiKey) {
|
|
29804
29850
|
this.baseUrl = baseUrl;
|
|
@@ -29879,6 +29925,9 @@ function serverDir(slockHome, serverId) {
|
|
|
29879
29925
|
function serverAttachmentPath(slockHome, serverId) {
|
|
29880
29926
|
return path2.join(serverDir(slockHome, serverId), "runner.state.json");
|
|
29881
29927
|
}
|
|
29928
|
+
function legacyServerAttachmentPath(slockHome, serverId) {
|
|
29929
|
+
return path2.join(serverDir(slockHome, serverId), "attachment.json");
|
|
29930
|
+
}
|
|
29882
29931
|
function serverRunnerPidPath(slockHome, serverId) {
|
|
29883
29932
|
return path2.join(serverDir(slockHome, serverId), "server-runner.pid");
|
|
29884
29933
|
}
|
|
@@ -29975,14 +30024,14 @@ function resolveServerUrl(...candidates) {
|
|
|
29975
30024
|
|
|
29976
30025
|
// src/services/login.ts
|
|
29977
30026
|
function sleep(ms, signal) {
|
|
29978
|
-
return new Promise((
|
|
30027
|
+
return new Promise((resolve2, reject) => {
|
|
29979
30028
|
if (signal?.aborted) {
|
|
29980
30029
|
reject(abortError(signal));
|
|
29981
30030
|
return;
|
|
29982
30031
|
}
|
|
29983
30032
|
const t = setTimeout(() => {
|
|
29984
30033
|
signal?.removeEventListener("abort", onAbort);
|
|
29985
|
-
|
|
30034
|
+
resolve2();
|
|
29986
30035
|
}, ms);
|
|
29987
30036
|
const onAbort = () => {
|
|
29988
30037
|
clearTimeout(t);
|
|
@@ -30130,21 +30179,33 @@ function parseAttachment(raw) {
|
|
|
30130
30179
|
serverMachineId: a.serverMachineId,
|
|
30131
30180
|
apiKey: a.apiKey,
|
|
30132
30181
|
serverUrl: a.serverUrl,
|
|
30133
|
-
attachedAt: typeof a.attachedAt === "string" ? a.attachedAt : void 0
|
|
30182
|
+
attachedAt: typeof a.attachedAt === "string" ? a.attachedAt : void 0,
|
|
30183
|
+
adoptedFromLegacy: a.adoptedFromLegacy === true ? true : void 0,
|
|
30184
|
+
legacyMachineId: typeof a.legacyMachineId === "string" ? a.legacyMachineId : void 0
|
|
30134
30185
|
};
|
|
30135
30186
|
}
|
|
30136
30187
|
} catch {
|
|
30137
30188
|
}
|
|
30138
30189
|
return null;
|
|
30139
30190
|
}
|
|
30140
|
-
async function
|
|
30141
|
-
if (!isValidServerId(serverId)) return null;
|
|
30191
|
+
async function readAttachmentAt(path3) {
|
|
30142
30192
|
try {
|
|
30143
|
-
return parseAttachment(await readFile(
|
|
30193
|
+
return parseAttachment(await readFile(path3, "utf8"));
|
|
30144
30194
|
} catch {
|
|
30145
30195
|
return null;
|
|
30146
30196
|
}
|
|
30147
30197
|
}
|
|
30198
|
+
async function readServerAttachment(slockHome, serverId) {
|
|
30199
|
+
if (!isValidServerId(serverId)) return null;
|
|
30200
|
+
const current = await readAttachmentAt(serverAttachmentPath(slockHome, serverId));
|
|
30201
|
+
const legacy = await readAttachmentAt(legacyServerAttachmentPath(slockHome, serverId));
|
|
30202
|
+
if (!current) return legacy;
|
|
30203
|
+
if (!legacy) return current;
|
|
30204
|
+
if (legacy.adoptedFromLegacy === true && current.adoptedFromLegacy !== true && legacy.serverMachineId !== current.serverMachineId) {
|
|
30205
|
+
return legacy;
|
|
30206
|
+
}
|
|
30207
|
+
return current;
|
|
30208
|
+
}
|
|
30148
30209
|
async function writeServerAttachment(slockHome, attachment) {
|
|
30149
30210
|
if (!isValidServerId(attachment.serverId)) return;
|
|
30150
30211
|
const path3 = serverAttachmentPath(slockHome, attachment.serverId);
|
|
@@ -30403,68 +30464,153 @@ import { dirname as dirname9 } from "path";
|
|
|
30403
30464
|
|
|
30404
30465
|
// src/lib/migration.ts
|
|
30405
30466
|
init_esm_shims();
|
|
30406
|
-
import { readdir as readdir2, readFile as readFile3 } from "fs/promises";
|
|
30407
|
-
import { join } from "path";
|
|
30467
|
+
import { readdir as readdir2, readFile as readFile3, stat } from "fs/promises";
|
|
30468
|
+
import { join, resolve } from "path";
|
|
30408
30469
|
var MACHINE_DIR_PREFIX = "machine-";
|
|
30409
|
-
|
|
30410
|
-
|
|
30411
|
-
|
|
30412
|
-
|
|
30413
|
-
|
|
30414
|
-
|
|
30415
|
-
|
|
30416
|
-
|
|
30470
|
+
var FINGERPRINT_HEX_RE = /^[0-9a-f]{16}$/;
|
|
30471
|
+
async function readLocalOwners(installRoot) {
|
|
30472
|
+
const machinesDir = join(installRoot, "machines");
|
|
30473
|
+
let entries;
|
|
30474
|
+
try {
|
|
30475
|
+
entries = await readdir2(machinesDir);
|
|
30476
|
+
} catch {
|
|
30477
|
+
return [];
|
|
30478
|
+
}
|
|
30479
|
+
const owners = [];
|
|
30480
|
+
for (const name of entries) {
|
|
30481
|
+
if (!name.startsWith(MACHINE_DIR_PREFIX)) continue;
|
|
30482
|
+
const ownerPath = join(machinesDir, name, "daemon.lock", "owner.json");
|
|
30483
|
+
let raw;
|
|
30484
|
+
try {
|
|
30485
|
+
raw = await readFile3(ownerPath, "utf8");
|
|
30486
|
+
} catch {
|
|
30487
|
+
continue;
|
|
30488
|
+
}
|
|
30489
|
+
let parsed;
|
|
30490
|
+
try {
|
|
30491
|
+
parsed = JSON.parse(raw);
|
|
30492
|
+
} catch {
|
|
30493
|
+
continue;
|
|
30494
|
+
}
|
|
30495
|
+
const fp = parsed.apiKeyFingerprint;
|
|
30496
|
+
if (typeof fp !== "string" || !FINGERPRINT_HEX_RE.test(fp)) continue;
|
|
30497
|
+
owners.push({ apiKeyFingerprint: fp, localPath: ownerPath });
|
|
30498
|
+
}
|
|
30499
|
+
return owners;
|
|
30500
|
+
}
|
|
30501
|
+
function indexLocalByFingerprint(owners) {
|
|
30502
|
+
const map = /* @__PURE__ */ new Map();
|
|
30503
|
+
for (const owner of owners) {
|
|
30504
|
+
if (!map.has(owner.apiKeyFingerprint)) {
|
|
30505
|
+
map.set(owner.apiKeyFingerprint, owner);
|
|
30506
|
+
}
|
|
30507
|
+
}
|
|
30508
|
+
return map;
|
|
30509
|
+
}
|
|
30510
|
+
function intersect(localByFp, roster) {
|
|
30511
|
+
const out = [];
|
|
30512
|
+
for (const entry of roster) {
|
|
30513
|
+
const local = localByFp.get(entry.apiKeyFingerprint);
|
|
30514
|
+
if (!local) continue;
|
|
30515
|
+
out.push({
|
|
30516
|
+
apiKeyFingerprint: entry.apiKeyFingerprint,
|
|
30517
|
+
daemonId: entry.daemonId,
|
|
30518
|
+
localPath: local.localPath,
|
|
30519
|
+
machineName: entry.machineName,
|
|
30520
|
+
...entry.hostname ? { hostname: entry.hostname } : {},
|
|
30521
|
+
...entry.lastSeenAt ? { lastSeenAt: entry.lastSeenAt } : {}
|
|
30522
|
+
});
|
|
30523
|
+
}
|
|
30524
|
+
out.sort((a, b) => {
|
|
30525
|
+
const aSeen = a.lastSeenAt ?? "";
|
|
30526
|
+
const bSeen = b.lastSeenAt ?? "";
|
|
30527
|
+
if (aSeen !== bSeen) {
|
|
30528
|
+
if (aSeen === "") return 1;
|
|
30529
|
+
if (bSeen === "") return -1;
|
|
30530
|
+
return aSeen < bSeen ? 1 : -1;
|
|
30531
|
+
}
|
|
30532
|
+
return a.apiKeyFingerprint < b.apiKeyFingerprint ? -1 : a.apiKeyFingerprint > b.apiKeyFingerprint ? 1 : 0;
|
|
30533
|
+
});
|
|
30534
|
+
return out;
|
|
30535
|
+
}
|
|
30536
|
+
async function detectLegacyMigration(installRoot, serverSlug, client) {
|
|
30537
|
+
const localOwners = await readLocalOwners(installRoot);
|
|
30538
|
+
if (localOwners.length === 0) {
|
|
30539
|
+
return { kind: "candidates", candidates: [] };
|
|
30540
|
+
}
|
|
30541
|
+
const result = await client.list(serverSlug);
|
|
30542
|
+
if (result.status !== "success") {
|
|
30543
|
+
return { kind: "server-unavailable" };
|
|
30544
|
+
}
|
|
30545
|
+
const localByFp = indexLocalByFingerprint(localOwners);
|
|
30546
|
+
return { kind: "candidates", candidates: intersect(localByFp, result.entries) };
|
|
30547
|
+
}
|
|
30548
|
+
async function validateManualMigratePath(inputPath, roster) {
|
|
30549
|
+
const absInput = resolve(inputPath);
|
|
30550
|
+
let stats;
|
|
30551
|
+
try {
|
|
30552
|
+
stats = await stat(absInput);
|
|
30553
|
+
} catch {
|
|
30554
|
+
return { ok: false, code: "MIGRATE_FROM_NOT_FOUND" };
|
|
30555
|
+
}
|
|
30556
|
+
const ownerPath = stats.isDirectory() ? join(absInput, "daemon.lock", "owner.json") : absInput;
|
|
30557
|
+
const candidateOwnerPath = await firstReadableOwner([
|
|
30558
|
+
ownerPath,
|
|
30559
|
+
join(absInput, "owner.json"),
|
|
30560
|
+
absInput
|
|
30561
|
+
]);
|
|
30562
|
+
if (!candidateOwnerPath) {
|
|
30563
|
+
return { ok: false, code: "MIGRATE_FROM_INVALID" };
|
|
30564
|
+
}
|
|
30417
30565
|
let raw;
|
|
30418
30566
|
try {
|
|
30419
|
-
raw = await readFile3(
|
|
30567
|
+
raw = await readFile3(candidateOwnerPath, "utf8");
|
|
30420
30568
|
} catch {
|
|
30421
|
-
return {};
|
|
30569
|
+
return { ok: false, code: "MIGRATE_FROM_INVALID" };
|
|
30422
30570
|
}
|
|
30423
30571
|
let parsed;
|
|
30424
30572
|
try {
|
|
30425
30573
|
parsed = JSON.parse(raw);
|
|
30426
30574
|
} catch {
|
|
30427
|
-
return {};
|
|
30575
|
+
return { ok: false, code: "MIGRATE_FROM_INVALID" };
|
|
30428
30576
|
}
|
|
30429
|
-
const
|
|
30430
|
-
|
|
30431
|
-
|
|
30432
|
-
}
|
|
30433
|
-
async function detectLegacyMigration(installRoot, loggedInUserId) {
|
|
30434
|
-
void loggedInUserId;
|
|
30435
|
-
const machinesDir = join(installRoot, "machines");
|
|
30436
|
-
let entries;
|
|
30437
|
-
try {
|
|
30438
|
-
entries = await readdir2(machinesDir);
|
|
30439
|
-
} catch {
|
|
30440
|
-
return { kind: "no-match" };
|
|
30577
|
+
const fp = parsed.apiKeyFingerprint;
|
|
30578
|
+
if (typeof fp !== "string" || !FINGERPRINT_HEX_RE.test(fp)) {
|
|
30579
|
+
return { ok: false, code: "MIGRATE_FROM_INVALID" };
|
|
30441
30580
|
}
|
|
30442
|
-
const
|
|
30443
|
-
|
|
30444
|
-
|
|
30445
|
-
const evidence = await readOwnerEvidence(installRoot, name);
|
|
30446
|
-
candidates.push({
|
|
30447
|
-
machineId: name,
|
|
30448
|
-
machineName: evidence.machineName,
|
|
30449
|
-
serverUrl: evidence.serverUrl
|
|
30450
|
-
});
|
|
30581
|
+
const match = roster.find((r) => r.apiKeyFingerprint === fp);
|
|
30582
|
+
if (!match) {
|
|
30583
|
+
return { ok: false, code: "MIGRATE_FROM_NOT_OWNED" };
|
|
30451
30584
|
}
|
|
30452
|
-
|
|
30453
|
-
|
|
30454
|
-
|
|
30455
|
-
|
|
30456
|
-
|
|
30457
|
-
|
|
30458
|
-
machineName:
|
|
30459
|
-
|
|
30460
|
-
|
|
30585
|
+
return {
|
|
30586
|
+
ok: true,
|
|
30587
|
+
candidate: {
|
|
30588
|
+
apiKeyFingerprint: match.apiKeyFingerprint,
|
|
30589
|
+
daemonId: match.daemonId,
|
|
30590
|
+
localPath: candidateOwnerPath,
|
|
30591
|
+
machineName: match.machineName,
|
|
30592
|
+
...match.hostname ? { hostname: match.hostname } : {},
|
|
30593
|
+
...match.lastSeenAt ? { lastSeenAt: match.lastSeenAt } : {}
|
|
30594
|
+
}
|
|
30595
|
+
};
|
|
30596
|
+
}
|
|
30597
|
+
async function firstReadableOwner(paths) {
|
|
30598
|
+
const seen = /* @__PURE__ */ new Set();
|
|
30599
|
+
for (const p of paths) {
|
|
30600
|
+
if (seen.has(p)) continue;
|
|
30601
|
+
seen.add(p);
|
|
30602
|
+
try {
|
|
30603
|
+
const st = await stat(p);
|
|
30604
|
+
if (st.isFile()) return p;
|
|
30605
|
+
} catch {
|
|
30606
|
+
}
|
|
30461
30607
|
}
|
|
30462
|
-
return
|
|
30608
|
+
return null;
|
|
30463
30609
|
}
|
|
30464
30610
|
|
|
30465
30611
|
// src/services/adoptLegacy.ts
|
|
30466
30612
|
init_esm_shims();
|
|
30467
|
-
import { chmod as chmod3, mkdir as mkdir4, readFile as readFile4, writeFile as writeFile4, appendFile, stat } from "fs/promises";
|
|
30613
|
+
import { chmod as chmod3, mkdir as mkdir4, readFile as readFile4, writeFile as writeFile4, appendFile, stat as stat2 } from "fs/promises";
|
|
30468
30614
|
import { createHash as createHash2 } from "crypto";
|
|
30469
30615
|
import { dirname as dirname4, join as join2 } from "path";
|
|
30470
30616
|
import { setTimeout as delay } from "timers/promises";
|
|
@@ -30807,7 +30953,7 @@ async function appendAdoptionLog(slockHome, line) {
|
|
|
30807
30953
|
const path3 = adoptionLogPath(slockHome);
|
|
30808
30954
|
await appendFile(path3, fields.join(" ") + "\n", { mode: 384 });
|
|
30809
30955
|
try {
|
|
30810
|
-
const st = await
|
|
30956
|
+
const st = await stat2(path3);
|
|
30811
30957
|
if ((st.mode & 63) !== 0) await chmod3(path3, 384);
|
|
30812
30958
|
} catch {
|
|
30813
30959
|
}
|
|
@@ -30824,7 +30970,7 @@ import { fileURLToPath as fileURLToPath2 } from "url";
|
|
|
30824
30970
|
|
|
30825
30971
|
// src/cleanup.ts
|
|
30826
30972
|
init_esm_shims();
|
|
30827
|
-
import { readdir as readdir3, stat as
|
|
30973
|
+
import { readdir as readdir3, stat as stat3, unlink as unlink3, rm, rmdir, rename, mkdir as mkdir6 } from "fs/promises";
|
|
30828
30974
|
import { spawn } from "child_process";
|
|
30829
30975
|
import { join as join3 } from "path";
|
|
30830
30976
|
|
|
@@ -30918,7 +31064,7 @@ async function readPsTable(psSpawn = defaultPsSpawn) {
|
|
|
30918
31064
|
}
|
|
30919
31065
|
}
|
|
30920
31066
|
function defaultPsSpawn() {
|
|
30921
|
-
return new Promise((
|
|
31067
|
+
return new Promise((resolve2) => {
|
|
30922
31068
|
const child = spawn("ps", ["-o", "pid,ppid,comm", "-A"], {
|
|
30923
31069
|
stdio: ["ignore", "pipe", "ignore"]
|
|
30924
31070
|
});
|
|
@@ -30926,8 +31072,8 @@ function defaultPsSpawn() {
|
|
|
30926
31072
|
child.stdout.on("data", (chunk) => {
|
|
30927
31073
|
out += String(chunk);
|
|
30928
31074
|
});
|
|
30929
|
-
child.on("error", () =>
|
|
30930
|
-
child.on("close", (code) =>
|
|
31075
|
+
child.on("error", () => resolve2({ stdout: "", exitCode: 1 }));
|
|
31076
|
+
child.on("close", (code) => resolve2({ stdout: out, exitCode: code ?? 1 }));
|
|
30931
31077
|
});
|
|
30932
31078
|
}
|
|
30933
31079
|
async function cleanupOrphanProcesses(slockHome, psSpawn) {
|
|
@@ -31006,7 +31152,7 @@ async function cleanupTmpFiles(slockHome) {
|
|
|
31006
31152
|
for (const v of versions) {
|
|
31007
31153
|
const vdir = join3(stagingDir, v);
|
|
31008
31154
|
try {
|
|
31009
|
-
const s = await
|
|
31155
|
+
const s = await stat3(vdir);
|
|
31010
31156
|
if (Date.now() - s.mtimeMs > TMP_MAX_AGE_MS) {
|
|
31011
31157
|
await rm(vdir, { recursive: true, force: true });
|
|
31012
31158
|
removed.push(vdir);
|
|
@@ -31023,7 +31169,7 @@ async function cleanupTmpFiles(slockHome) {
|
|
|
31023
31169
|
}
|
|
31024
31170
|
const snap = join3(cdir, "upgrade-snapshot.json");
|
|
31025
31171
|
try {
|
|
31026
|
-
const s = await
|
|
31172
|
+
const s = await stat3(snap);
|
|
31027
31173
|
if (Date.now() - s.mtimeMs > TMP_MAX_AGE_MS) {
|
|
31028
31174
|
await unlink3(snap);
|
|
31029
31175
|
removed.push(snap);
|
|
@@ -31035,7 +31181,7 @@ async function cleanupTmpFiles(slockHome) {
|
|
|
31035
31181
|
async function cleanupStaleLock(slockHome) {
|
|
31036
31182
|
const lockDir = join3(computerDir(slockHome), ".lock");
|
|
31037
31183
|
try {
|
|
31038
|
-
const s = await
|
|
31184
|
+
const s = await stat3(lockDir);
|
|
31039
31185
|
if (Date.now() - s.mtimeMs > 60 * 1e3) {
|
|
31040
31186
|
await rm(lockDir, { recursive: true, force: true });
|
|
31041
31187
|
return [lockDir];
|
|
@@ -31047,7 +31193,7 @@ async function cleanupStaleLock(slockHome) {
|
|
|
31047
31193
|
async function forceReleaseLock(slockHome) {
|
|
31048
31194
|
const lockDir = join3(computerDir(slockHome), ".lock");
|
|
31049
31195
|
try {
|
|
31050
|
-
await
|
|
31196
|
+
await stat3(lockDir);
|
|
31051
31197
|
await rm(lockDir, { recursive: true, force: true });
|
|
31052
31198
|
return [lockDir];
|
|
31053
31199
|
} catch {
|
|
@@ -31238,7 +31384,7 @@ function emit4(opts, event) {
|
|
|
31238
31384
|
async function waitForManagedDaemonPids(slockHome, serverIds, opts) {
|
|
31239
31385
|
const readPidfile = opts.readPidfile ?? readPidfileAt;
|
|
31240
31386
|
const isAlive = opts.isProcessAlive ?? isProcessAlive2;
|
|
31241
|
-
const sleep2 = opts.sleep ?? ((ms) => new Promise((
|
|
31387
|
+
const sleep2 = opts.sleep ?? ((ms) => new Promise((resolve2) => setTimeout(resolve2, ms)));
|
|
31242
31388
|
const timeoutMs = opts.ensureTimeoutMs ?? START_ENSURE_TIMEOUT_MS;
|
|
31243
31389
|
const pollIntervalMs = opts.ensurePollIntervalMs ?? START_ENSURE_POLL_INTERVAL_MS;
|
|
31244
31390
|
const deadline = Date.now() + timeoutMs;
|
|
@@ -31414,7 +31560,7 @@ async function stop(input = {}, options = {}) {
|
|
|
31414
31560
|
const killer = options.killService ?? ((pid2) => {
|
|
31415
31561
|
process.kill(pid2, "SIGTERM");
|
|
31416
31562
|
});
|
|
31417
|
-
const sleep2 = options.sleep ?? ((ms) => new Promise((
|
|
31563
|
+
const sleep2 = options.sleep ?? ((ms) => new Promise((resolve2) => setTimeout(resolve2, ms)));
|
|
31418
31564
|
const pollIntervalMs = options.pollIntervalMs ?? STOP_POLL_INTERVAL_MS;
|
|
31419
31565
|
const timeoutMs = options.timeoutMs ?? STOP_TIMEOUT_MS;
|
|
31420
31566
|
const { pid, pidfilePath, firstStalePidfile, firstStalePid } = await findLiveServicePid(slockHome, {
|
|
@@ -31967,12 +32113,15 @@ async function runDetach(serverId, serverLabel = serverId) {
|
|
|
31967
32113
|
|
|
31968
32114
|
// src/setup.ts
|
|
31969
32115
|
var USER_SESSION_EXPIRY_LEEWAY_MS = 3e4;
|
|
31970
|
-
async function
|
|
32116
|
+
async function readUserSessionAuth(slockHome) {
|
|
31971
32117
|
try {
|
|
31972
32118
|
const parsed = JSON.parse(await readFile8(userSessionPath(slockHome), "utf8"));
|
|
31973
|
-
return
|
|
32119
|
+
return {
|
|
32120
|
+
accessToken: typeof parsed.accessToken === "string" ? parsed.accessToken : "",
|
|
32121
|
+
...typeof parsed.serverUrl === "string" ? { serverUrl: parsed.serverUrl } : {}
|
|
32122
|
+
};
|
|
31974
32123
|
} catch {
|
|
31975
|
-
return "";
|
|
32124
|
+
return { accessToken: "" };
|
|
31976
32125
|
}
|
|
31977
32126
|
}
|
|
31978
32127
|
async function hasValidUserSession(slockHome) {
|
|
@@ -32042,15 +32191,60 @@ async function refreshUserSession(slockHome, serverUrl) {
|
|
|
32042
32191
|
return false;
|
|
32043
32192
|
}
|
|
32044
32193
|
}
|
|
32045
|
-
async function
|
|
32046
|
-
|
|
32047
|
-
|
|
32048
|
-
|
|
32049
|
-
|
|
32194
|
+
async function pickMigrationCandidateFromInput(candidates, read, write) {
|
|
32195
|
+
write(
|
|
32196
|
+
"Migration: detected legacy daemon(s) on this Computer that match the target server.\n"
|
|
32197
|
+
);
|
|
32198
|
+
candidates.forEach((c, i) => {
|
|
32199
|
+
const host = c.hostname ? ` (${c.hostname})` : "";
|
|
32200
|
+
const seen = c.lastSeenAt ? ` last seen ${c.lastSeenAt}` : "";
|
|
32201
|
+
write(` ${i + 1}. ${c.machineName}${host}${seen}
|
|
32202
|
+
`);
|
|
32203
|
+
write(` local: ${c.localPath}
|
|
32204
|
+
`);
|
|
32205
|
+
});
|
|
32206
|
+
write(" 0. Fresh attach (skip migration)\n");
|
|
32207
|
+
write(" m. Migrate from a different on-disk path\n");
|
|
32208
|
+
while (true) {
|
|
32209
|
+
write("Choose [1]: ");
|
|
32210
|
+
const { line, eof } = await read();
|
|
32211
|
+
if (eof) return { kind: "fresh" };
|
|
32212
|
+
const trimmed = line.trim();
|
|
32213
|
+
const norm = trimmed.toLowerCase();
|
|
32214
|
+
if (norm === "m") {
|
|
32215
|
+
write("Path to legacy machine dir or owner.json: ");
|
|
32216
|
+
const { line: pathLine } = await read();
|
|
32217
|
+
return { kind: "manual", path: pathLine.trim() };
|
|
32218
|
+
}
|
|
32219
|
+
if (norm.length === 0) return { kind: "candidate", index: 0 };
|
|
32220
|
+
if (norm === "0") return { kind: "fresh" };
|
|
32221
|
+
const n = Number.parseInt(norm, 10);
|
|
32222
|
+
if (Number.isFinite(n) && String(n) === norm && n >= 1 && n <= candidates.length) {
|
|
32223
|
+
return { kind: "candidate", index: n - 1 };
|
|
32224
|
+
}
|
|
32225
|
+
write(
|
|
32226
|
+
`Invalid selection "${trimmed}". Enter 1..${candidates.length}, 0, or m.
|
|
32227
|
+
`
|
|
32228
|
+
);
|
|
32229
|
+
}
|
|
32050
32230
|
}
|
|
32051
|
-
async function
|
|
32052
|
-
|
|
32053
|
-
|
|
32231
|
+
async function defaultPickMigrationCandidate(candidates) {
|
|
32232
|
+
return pickMigrationCandidateFromInput(
|
|
32233
|
+
candidates,
|
|
32234
|
+
() => readLine(false),
|
|
32235
|
+
(s) => {
|
|
32236
|
+
process.stdout.write(s);
|
|
32237
|
+
}
|
|
32238
|
+
);
|
|
32239
|
+
}
|
|
32240
|
+
async function readLegacyApiKey(isTty) {
|
|
32241
|
+
const fromEnv = process.env.SLOCK_LEGACY_API_KEY;
|
|
32242
|
+
if (typeof fromEnv === "string" && fromEnv.length > 0) return fromEnv.trim();
|
|
32243
|
+
if (!isTty) return "";
|
|
32244
|
+
process.stdout.write(
|
|
32245
|
+
"Paste legacy api key (sk_machine_* or sk_daemon_*); input is hidden: "
|
|
32246
|
+
);
|
|
32247
|
+
const { line } = await readLine(true);
|
|
32054
32248
|
process.stdout.write("\n");
|
|
32055
32249
|
return line.trim();
|
|
32056
32250
|
}
|
|
@@ -32060,7 +32254,7 @@ async function readLine(masked) {
|
|
|
32060
32254
|
const enterRaw = masked && stdin.isTTY === true && typeof stdin.setRawMode === "function";
|
|
32061
32255
|
if (enterRaw) stdin.setRawMode(true);
|
|
32062
32256
|
stdin.resume();
|
|
32063
|
-
return await new Promise((
|
|
32257
|
+
return await new Promise((resolve2) => {
|
|
32064
32258
|
let buf = "";
|
|
32065
32259
|
const cleanup = () => {
|
|
32066
32260
|
stdin.off("data", onData);
|
|
@@ -32073,12 +32267,17 @@ async function readLine(masked) {
|
|
|
32073
32267
|
for (const ch of text) {
|
|
32074
32268
|
if (ch === "\n" || ch === "\r") {
|
|
32075
32269
|
cleanup();
|
|
32076
|
-
|
|
32270
|
+
resolve2({ line: buf, eof: false });
|
|
32271
|
+
return;
|
|
32272
|
+
}
|
|
32273
|
+
if (ch === "") {
|
|
32274
|
+
cleanup();
|
|
32275
|
+
resolve2({ line: buf, eof: true });
|
|
32077
32276
|
return;
|
|
32078
32277
|
}
|
|
32079
32278
|
if (ch === "") {
|
|
32080
32279
|
cleanup();
|
|
32081
|
-
|
|
32280
|
+
resolve2({ line: "", eof: false });
|
|
32082
32281
|
return;
|
|
32083
32282
|
}
|
|
32084
32283
|
if (ch === "\x7F" || ch === "\b") {
|
|
@@ -32090,12 +32289,88 @@ async function readLine(masked) {
|
|
|
32090
32289
|
};
|
|
32091
32290
|
const onEnd = () => {
|
|
32092
32291
|
cleanup();
|
|
32093
|
-
|
|
32292
|
+
resolve2({ line: buf, eof: true });
|
|
32094
32293
|
};
|
|
32095
32294
|
stdin.on("data", onData);
|
|
32096
32295
|
stdin.on("end", onEnd);
|
|
32097
32296
|
});
|
|
32098
32297
|
}
|
|
32298
|
+
async function runMigrateAdoption(opts, candidate, isTty, adoptLegacyImpl, readLegacyApiKeyImpl) {
|
|
32299
|
+
const where = candidate.hostname ? ` (${candidate.hostname})` : "";
|
|
32300
|
+
const seen = candidate.lastSeenAt ? ` last seen ${candidate.lastSeenAt}` : "";
|
|
32301
|
+
info(`Migration: adopting legacy daemon "${candidate.machineName}"${where}${seen}.`);
|
|
32302
|
+
info(` local owner.json: ${candidate.localPath}`);
|
|
32303
|
+
const rawKey = await readLegacyApiKeyImpl(isTty);
|
|
32304
|
+
if (rawKey.length === 0) {
|
|
32305
|
+
fail(
|
|
32306
|
+
"LEGACY_KEY_REQUIRED",
|
|
32307
|
+
"No legacy api key provided. Set `SLOCK_LEGACY_API_KEY` or paste the legacy `sk_machine_*` / `sk_daemon_*` key when prompted."
|
|
32308
|
+
);
|
|
32309
|
+
}
|
|
32310
|
+
if (!rawKey.startsWith("sk_machine_") && !rawKey.startsWith("sk_daemon_")) {
|
|
32311
|
+
fail(
|
|
32312
|
+
"LEGACY_KEY_INVALID",
|
|
32313
|
+
"Provided key does not look like a legacy machine key (expected `sk_machine_*` or `sk_daemon_*`)."
|
|
32314
|
+
);
|
|
32315
|
+
}
|
|
32316
|
+
try {
|
|
32317
|
+
await adoptLegacyImpl(
|
|
32318
|
+
{
|
|
32319
|
+
serverSlug: opts.serverSlug,
|
|
32320
|
+
...opts.serverUrl ? { serverUrl: opts.serverUrl } : {},
|
|
32321
|
+
...opts.name ? { name: opts.name } : {},
|
|
32322
|
+
rawKey,
|
|
32323
|
+
mode: "legacy_key_stdin",
|
|
32324
|
+
redactedPrefix: rawKey.slice(0, 8)
|
|
32325
|
+
},
|
|
32326
|
+
{
|
|
32327
|
+
onEvent: (event) => {
|
|
32328
|
+
if (event.type === "adopting") {
|
|
32329
|
+
info(
|
|
32330
|
+
`Adopting legacy daemon for ${formatServerSlugDisplay(event.serverSlug)} via ${event.mode}\u2026`
|
|
32331
|
+
);
|
|
32332
|
+
} else if (event.type === "preflight") {
|
|
32333
|
+
info(
|
|
32334
|
+
event.resumed ? "Adopted (resumed prior attachment); running preflight\u2026" : "Adopted; running preflight\u2026"
|
|
32335
|
+
);
|
|
32336
|
+
} else if (event.type === "adopted") {
|
|
32337
|
+
info(`Adopted. Computer state written to ${event.attachmentPath}`);
|
|
32338
|
+
info(` server: ${formatServerSlugDisplay(event.serverSlug)}`);
|
|
32339
|
+
info(` serverMachine: ${event.serverMachineId}`);
|
|
32340
|
+
info(` legacyMachine: ${event.legacyMachineId}`);
|
|
32341
|
+
switch (event.legacyStop.outcome) {
|
|
32342
|
+
case "absent":
|
|
32343
|
+
info(" legacy daemon: not detected on this Computer (no local lock file)");
|
|
32344
|
+
break;
|
|
32345
|
+
case "already_dead":
|
|
32346
|
+
info(` legacy daemon: already stopped (pid ${event.legacyStop.pid} not running)`);
|
|
32347
|
+
break;
|
|
32348
|
+
case "stopped":
|
|
32349
|
+
info(` legacy daemon: stopped (pid ${event.legacyStop.pid}, SIGTERM)`);
|
|
32350
|
+
break;
|
|
32351
|
+
}
|
|
32352
|
+
}
|
|
32353
|
+
}
|
|
32354
|
+
}
|
|
32355
|
+
);
|
|
32356
|
+
} catch (err) {
|
|
32357
|
+
if (err instanceof CliExit) throw err;
|
|
32358
|
+
if (err instanceof ComputerServiceError) {
|
|
32359
|
+
fail(err.code, err.message);
|
|
32360
|
+
}
|
|
32361
|
+
throw err;
|
|
32362
|
+
}
|
|
32363
|
+
}
|
|
32364
|
+
function manualPathErrorMessage(code, inputPath) {
|
|
32365
|
+
switch (code) {
|
|
32366
|
+
case "MIGRATE_FROM_NOT_FOUND":
|
|
32367
|
+
return `--migrate-from path not found: ${inputPath}. Pass the legacy machine directory, its daemon.lock/, or its owner.json file.`;
|
|
32368
|
+
case "MIGRATE_FROM_INVALID":
|
|
32369
|
+
return `--migrate-from path is not a valid legacy daemon install: ${inputPath}. Expected an owner.json with a 16-hex-char apiKeyFingerprint field.`;
|
|
32370
|
+
case "MIGRATE_FROM_NOT_OWNED":
|
|
32371
|
+
return `--migrate-from path's apiKeyFingerprint is not in this server's legacy machine roster for the logged-in user: ${inputPath}. Either the daemon is already migrated, the row is unowned by this user, or the fingerprint is from a different server.`;
|
|
32372
|
+
}
|
|
32373
|
+
}
|
|
32099
32374
|
async function runSetup(opts, deps = {}) {
|
|
32100
32375
|
const slockHome = resolveSlockHome();
|
|
32101
32376
|
const isTty = deps.isTty ?? Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
@@ -32104,8 +32379,11 @@ async function runSetup(opts, deps = {}) {
|
|
|
32104
32379
|
const start2 = deps.runStart ?? runStart;
|
|
32105
32380
|
const refreshSession = deps.refreshUserSession ?? refreshUserSession;
|
|
32106
32381
|
const detectMigration = deps.detectLegacyMigration ?? detectLegacyMigration;
|
|
32107
|
-
const
|
|
32108
|
-
const
|
|
32382
|
+
const validateManualPath = deps.validateManualMigratePath ?? validateManualMigratePath;
|
|
32383
|
+
const buildRoster = deps.buildRosterClient ?? ((baseUrl, accessToken) => new LegacyMachinesClient(baseUrl, accessToken));
|
|
32384
|
+
const pickCandidate = deps.pickMigrationCandidate ?? defaultPickMigrationCandidate;
|
|
32385
|
+
const adoptLegacy2 = deps.adoptLegacy ?? adoptLegacy;
|
|
32386
|
+
const readLegacyKey = deps.readLegacyApiKey ?? readLegacyApiKey;
|
|
32109
32387
|
if (!isTty && !opts.yes) {
|
|
32110
32388
|
fail(
|
|
32111
32389
|
"NON_INTERACTIVE_SETUP_REQUIRES_FLAGS",
|
|
@@ -32134,78 +32412,85 @@ async function runSetup(opts, deps = {}) {
|
|
|
32134
32412
|
if (attachment) {
|
|
32135
32413
|
info(`Attachment: already attached to ${label}.`);
|
|
32136
32414
|
} else {
|
|
32415
|
+
const session = await readUserSessionAuth(slockHome);
|
|
32416
|
+
const baseUrl = resolveServerUrl(
|
|
32417
|
+
opts.serverUrl,
|
|
32418
|
+
session.serverUrl,
|
|
32419
|
+
process.env.SLOCK_SERVER_URL
|
|
32420
|
+
);
|
|
32421
|
+
const rosterClient = buildRoster(baseUrl, session.accessToken);
|
|
32137
32422
|
let migrated = false;
|
|
32138
|
-
if (
|
|
32139
|
-
const
|
|
32140
|
-
if (
|
|
32141
|
-
|
|
32142
|
-
|
|
32143
|
-
|
|
32144
|
-
`Migration: detected legacy daemon machine${who}${where}. Migrate it under Computer instead of creating a fresh attachment? [y/N] `
|
|
32423
|
+
if (typeof opts.migrateFrom === "string" && opts.migrateFrom.length > 0) {
|
|
32424
|
+
const rosterResult = await rosterClient.list(opts.serverSlug);
|
|
32425
|
+
if (rosterResult.status !== "success") {
|
|
32426
|
+
fail(
|
|
32427
|
+
"MIGRATE_FROM_ROSTER_UNAVAILABLE",
|
|
32428
|
+
`Cannot validate --migrate-from path: legacy machine roster unavailable (${rosterResult.status}). Retry when the server is reachable, or remove --migrate-from to fall through to fresh attach.`
|
|
32145
32429
|
);
|
|
32146
|
-
|
|
32147
|
-
|
|
32148
|
-
|
|
32149
|
-
|
|
32150
|
-
|
|
32151
|
-
|
|
32152
|
-
|
|
32153
|
-
|
|
32154
|
-
|
|
32155
|
-
|
|
32156
|
-
|
|
32157
|
-
|
|
32158
|
-
|
|
32159
|
-
|
|
32160
|
-
|
|
32161
|
-
|
|
32162
|
-
|
|
32163
|
-
|
|
32164
|
-
|
|
32165
|
-
|
|
32166
|
-
|
|
32167
|
-
|
|
32168
|
-
|
|
32169
|
-
|
|
32170
|
-
|
|
32171
|
-
|
|
32172
|
-
|
|
32173
|
-
);
|
|
32174
|
-
} else if (event.type === "preflight") {
|
|
32175
|
-
info(
|
|
32176
|
-
event.resumed ? "Adopted (resumed prior attachment); running preflight\u2026" : "Adopted; running preflight\u2026"
|
|
32177
|
-
);
|
|
32178
|
-
} else if (event.type === "adopted") {
|
|
32179
|
-
info(`Adopted. Computer state written to ${event.attachmentPath}`);
|
|
32180
|
-
info(` server: ${formatServerSlugDisplay(event.serverSlug)}`);
|
|
32181
|
-
info(` serverMachine: ${event.serverMachineId}`);
|
|
32182
|
-
info(` legacyMachine: ${event.legacyMachineId}`);
|
|
32183
|
-
switch (event.legacyStop.outcome) {
|
|
32184
|
-
case "absent":
|
|
32185
|
-
info(" legacy daemon: not detected on this Computer (no local lock file)");
|
|
32186
|
-
break;
|
|
32187
|
-
case "already_dead":
|
|
32188
|
-
info(` legacy daemon: already stopped (pid ${event.legacyStop.pid} not running)`);
|
|
32189
|
-
break;
|
|
32190
|
-
case "stopped":
|
|
32191
|
-
info(` legacy daemon: stopped (pid ${event.legacyStop.pid}, SIGTERM)`);
|
|
32192
|
-
break;
|
|
32193
|
-
}
|
|
32194
|
-
}
|
|
32195
|
-
}
|
|
32196
|
-
}
|
|
32430
|
+
}
|
|
32431
|
+
const validation = await validateManualPath(opts.migrateFrom, rosterResult.entries);
|
|
32432
|
+
if (!validation.ok) {
|
|
32433
|
+
fail(validation.code, manualPathErrorMessage(validation.code, opts.migrateFrom));
|
|
32434
|
+
}
|
|
32435
|
+
await runMigrateAdoption(opts, validation.candidate, isTty, adoptLegacy2, readLegacyKey);
|
|
32436
|
+
migrated = true;
|
|
32437
|
+
} else {
|
|
32438
|
+
const detection = await detectMigration(slockHome, opts.serverSlug, rosterClient);
|
|
32439
|
+
if (detection.kind === "server-unavailable") {
|
|
32440
|
+
info(
|
|
32441
|
+
"Migration: legacy machine roster unavailable (fresh trigger: server-unavailable); falling back to fresh attach."
|
|
32442
|
+
);
|
|
32443
|
+
} else if (detection.candidates.length === 0) {
|
|
32444
|
+
} else if (!isTty) {
|
|
32445
|
+
info(
|
|
32446
|
+
`Migration: ${detection.candidates.length} legacy daemon(s) match this server but setup is non-interactive (fresh trigger: non-tty); falling back to fresh attach. Re-run on a TTY or pass --migrate-from <path> to adopt a specific install.`
|
|
32447
|
+
);
|
|
32448
|
+
} else {
|
|
32449
|
+
pickerLoop: while (true) {
|
|
32450
|
+
const selection = await pickCandidate(detection.candidates);
|
|
32451
|
+
if (selection.kind === "candidate") {
|
|
32452
|
+
const candidate = detection.candidates[selection.index];
|
|
32453
|
+
if (!candidate) {
|
|
32454
|
+
fail(
|
|
32455
|
+
"MIGRATE_PICKER_OUT_OF_RANGE",
|
|
32456
|
+
`Picker returned candidate index ${selection.index} but only ${detection.candidates.length} candidate(s) were detected.`
|
|
32197
32457
|
);
|
|
32198
|
-
migrated = true;
|
|
32199
|
-
} catch (err) {
|
|
32200
|
-
if (err instanceof CliExit) throw err;
|
|
32201
|
-
if (err instanceof ComputerServiceError) {
|
|
32202
|
-
fail(err.code, err.message);
|
|
32203
|
-
}
|
|
32204
|
-
throw err;
|
|
32205
32458
|
}
|
|
32459
|
+
await runMigrateAdoption(opts, candidate, isTty, adoptLegacy2, readLegacyKey);
|
|
32460
|
+
migrated = true;
|
|
32461
|
+
break pickerLoop;
|
|
32462
|
+
} else if (selection.kind === "manual") {
|
|
32463
|
+
if (selection.path.length === 0) {
|
|
32464
|
+
info("Migration: no path provided; returning to picker.");
|
|
32465
|
+
continue pickerLoop;
|
|
32466
|
+
}
|
|
32467
|
+
const rosterResult = await rosterClient.list(opts.serverSlug);
|
|
32468
|
+
if (rosterResult.status !== "success") {
|
|
32469
|
+
info(
|
|
32470
|
+
`Migration: MIGRATE_FROM_ROSTER_UNAVAILABLE \u2014 legacy machine roster unavailable (${rosterResult.status}); returning to picker. Pick "0" to fall through to fresh attach if the server stays unreachable.`
|
|
32471
|
+
);
|
|
32472
|
+
continue pickerLoop;
|
|
32473
|
+
}
|
|
32474
|
+
const validation = await validateManualPath(selection.path, rosterResult.entries);
|
|
32475
|
+
if (!validation.ok) {
|
|
32476
|
+
info(
|
|
32477
|
+
`Migration: ${validation.code} \u2014 ${manualPathErrorMessage(validation.code, selection.path)} Returning to picker.`
|
|
32478
|
+
);
|
|
32479
|
+
continue pickerLoop;
|
|
32480
|
+
}
|
|
32481
|
+
await runMigrateAdoption(
|
|
32482
|
+
opts,
|
|
32483
|
+
validation.candidate,
|
|
32484
|
+
isTty,
|
|
32485
|
+
adoptLegacy2,
|
|
32486
|
+
readLegacyKey
|
|
32487
|
+
);
|
|
32488
|
+
migrated = true;
|
|
32489
|
+
break pickerLoop;
|
|
32490
|
+
} else {
|
|
32491
|
+
info("Migration: fresh attach selected.");
|
|
32492
|
+
break pickerLoop;
|
|
32206
32493
|
}
|
|
32207
|
-
} else {
|
|
32208
|
-
info("Migration: declined; falling back to fresh attach.");
|
|
32209
32494
|
}
|
|
32210
32495
|
}
|
|
32211
32496
|
}
|
|
@@ -33096,7 +33381,7 @@ function errMsg(e) {
|
|
|
33096
33381
|
return e instanceof Error ? e.message : String(e);
|
|
33097
33382
|
}
|
|
33098
33383
|
async function defaultReadTarballPackageJson(tarballPath) {
|
|
33099
|
-
const raw = await new Promise((
|
|
33384
|
+
const raw = await new Promise((resolve2, reject) => {
|
|
33100
33385
|
const child = spawn3("tar", ["-xzOf", tarballPath, "package/package.json"], {
|
|
33101
33386
|
stdio: ["ignore", "pipe", "pipe"]
|
|
33102
33387
|
});
|
|
@@ -33114,7 +33399,7 @@ async function defaultReadTarballPackageJson(tarballPath) {
|
|
|
33114
33399
|
reject(new Error(`tar -xzOf exited ${code}: ${stderrBuf.slice(0, 300)}`));
|
|
33115
33400
|
return;
|
|
33116
33401
|
}
|
|
33117
|
-
|
|
33402
|
+
resolve2(stdoutBuf);
|
|
33118
33403
|
});
|
|
33119
33404
|
});
|
|
33120
33405
|
return JSON.parse(raw);
|
|
@@ -33242,7 +33527,7 @@ async function stagePhase(slockHome, version, deps = {}) {
|
|
|
33242
33527
|
return { stagedPath, version, tarballSha1 };
|
|
33243
33528
|
}
|
|
33244
33529
|
function defaultNpmPack(cwd, packageRef) {
|
|
33245
|
-
return new Promise((
|
|
33530
|
+
return new Promise((resolve2) => {
|
|
33246
33531
|
const child = spawn4("npm", ["pack", packageRef, "--json"], {
|
|
33247
33532
|
cwd,
|
|
33248
33533
|
stdio: ["ignore", "pipe", "pipe"]
|
|
@@ -33256,23 +33541,23 @@ function defaultNpmPack(cwd, packageRef) {
|
|
|
33256
33541
|
stderrBuf += String(chunk);
|
|
33257
33542
|
});
|
|
33258
33543
|
child.on("error", (err) => {
|
|
33259
|
-
|
|
33544
|
+
resolve2({ tarballPath: "", exitCode: 1, stderr: String(err) });
|
|
33260
33545
|
});
|
|
33261
33546
|
child.on("close", (code) => {
|
|
33262
33547
|
if (code !== 0) {
|
|
33263
|
-
|
|
33548
|
+
resolve2({ tarballPath: "", exitCode: code ?? 1, stderr: stderrBuf });
|
|
33264
33549
|
return;
|
|
33265
33550
|
}
|
|
33266
33551
|
try {
|
|
33267
33552
|
const parsed = JSON.parse(stdoutBuf);
|
|
33268
33553
|
const filename = parsed[0]?.filename;
|
|
33269
33554
|
if (!filename) {
|
|
33270
|
-
|
|
33555
|
+
resolve2({ tarballPath: "", exitCode: 1, stderr: "npm pack returned no filename" });
|
|
33271
33556
|
return;
|
|
33272
33557
|
}
|
|
33273
|
-
|
|
33558
|
+
resolve2({ tarballPath: join6(cwd, filename), exitCode: 0, stderr: stderrBuf });
|
|
33274
33559
|
} catch (e) {
|
|
33275
|
-
|
|
33560
|
+
resolve2({ tarballPath: "", exitCode: 1, stderr: `parse npm pack output: ${e}` });
|
|
33276
33561
|
}
|
|
33277
33562
|
});
|
|
33278
33563
|
});
|
|
@@ -33352,7 +33637,7 @@ async function extractTarball(tarballPath, destDir, deps = {}) {
|
|
|
33352
33637
|
return { extractedPackageDir: join6(destDir, "package") };
|
|
33353
33638
|
}
|
|
33354
33639
|
function defaultTarSpawn(tarballPath, destDir) {
|
|
33355
|
-
return new Promise((
|
|
33640
|
+
return new Promise((resolve2) => {
|
|
33356
33641
|
const child = spawn4("tar", ["-xzf", tarballPath, "-C", destDir], {
|
|
33357
33642
|
stdio: ["ignore", "ignore", "pipe"]
|
|
33358
33643
|
});
|
|
@@ -33361,10 +33646,10 @@ function defaultTarSpawn(tarballPath, destDir) {
|
|
|
33361
33646
|
stderrBuf += String(chunk);
|
|
33362
33647
|
});
|
|
33363
33648
|
child.on("error", (err) => {
|
|
33364
|
-
|
|
33649
|
+
resolve2({ exitCode: 1, stderr: String(err) });
|
|
33365
33650
|
});
|
|
33366
33651
|
child.on("close", (code) => {
|
|
33367
|
-
|
|
33652
|
+
resolve2({ exitCode: code ?? 1, stderr: stderrBuf });
|
|
33368
33653
|
});
|
|
33369
33654
|
});
|
|
33370
33655
|
}
|
|
@@ -33380,7 +33665,7 @@ async function hydrateStagedDependencies(extractedPackageDir, deps = {}) {
|
|
|
33380
33665
|
}
|
|
33381
33666
|
}
|
|
33382
33667
|
function defaultNpmInstallProductionDeps(cwd) {
|
|
33383
|
-
return new Promise((
|
|
33668
|
+
return new Promise((resolve2) => {
|
|
33384
33669
|
const child = spawn4(
|
|
33385
33670
|
"npm",
|
|
33386
33671
|
[
|
|
@@ -33401,10 +33686,10 @@ function defaultNpmInstallProductionDeps(cwd) {
|
|
|
33401
33686
|
stderrBuf += String(chunk);
|
|
33402
33687
|
});
|
|
33403
33688
|
child.on("error", (err) => {
|
|
33404
|
-
|
|
33689
|
+
resolve2({ exitCode: 1, stderr: String(err) });
|
|
33405
33690
|
});
|
|
33406
33691
|
child.on("close", (code) => {
|
|
33407
|
-
|
|
33692
|
+
resolve2({ exitCode: code ?? 1, stderr: stderrBuf });
|
|
33408
33693
|
});
|
|
33409
33694
|
});
|
|
33410
33695
|
}
|
|
@@ -34264,7 +34549,7 @@ async function defaultCurrentVersion() {
|
|
|
34264
34549
|
|
|
34265
34550
|
// src/upgradeTestHarness.ts
|
|
34266
34551
|
init_esm_shims();
|
|
34267
|
-
import { mkdir as mkdir15, readdir as readdir4, stat as
|
|
34552
|
+
import { mkdir as mkdir15, readdir as readdir4, stat as stat4, writeFile as writeFile12 } from "fs/promises";
|
|
34268
34553
|
import { join as join8 } from "path";
|
|
34269
34554
|
import { createHash as createHash4 } from "crypto";
|
|
34270
34555
|
var PHASES = /* @__PURE__ */ new Set([
|
|
@@ -34401,7 +34686,7 @@ async function arrangeSnapshotFailure(slockHome) {
|
|
|
34401
34686
|
}
|
|
34402
34687
|
async function pathInfo(path3) {
|
|
34403
34688
|
try {
|
|
34404
|
-
const s = await
|
|
34689
|
+
const s = await stat4(path3);
|
|
34405
34690
|
if (s.isDirectory()) return { kind: "dir", size: 0 };
|
|
34406
34691
|
if (s.isFile()) return { kind: "file", size: s.size };
|
|
34407
34692
|
return null;
|