@moxt-ai/cli 0.10.0-beta.3 → 0.10.0-beta.5
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.cjs +434 -184
- package/dist/index.cjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -6685,6 +6685,62 @@ var init_version = __esm({
|
|
|
6685
6685
|
}
|
|
6686
6686
|
});
|
|
6687
6687
|
|
|
6688
|
+
// ../machine-connector/dist/runtime/local-codex-runtime/contracts.js
|
|
6689
|
+
var localCodexRuntimeProtocolVersion, localCodexRuntimeEventSchemaVersion, localCodexRuntimeEventRedactionVersion, LocalCodexComponentStatusWire, LocalCodexTurnStatusWire, LocalCodexControlKindWire, LocalCodexControlOutcomeWire, LocalCodexDiscoveryKindWire, LocalCodexDiscoveryStatusWire, LocalCodexAttemptPhase, LocalCodexControlApplyPhase;
|
|
6690
|
+
var init_contracts2 = __esm({
|
|
6691
|
+
"../machine-connector/dist/runtime/local-codex-runtime/contracts.js"() {
|
|
6692
|
+
"use strict";
|
|
6693
|
+
init_cjs_shims();
|
|
6694
|
+
localCodexRuntimeProtocolVersion = "1.0";
|
|
6695
|
+
localCodexRuntimeEventSchemaVersion = 1;
|
|
6696
|
+
localCodexRuntimeEventRedactionVersion = 1;
|
|
6697
|
+
(function(LocalCodexComponentStatusWire2) {
|
|
6698
|
+
LocalCodexComponentStatusWire2["AuthenticationRequired"] = "authentication_required";
|
|
6699
|
+
LocalCodexComponentStatusWire2["Error"] = "error";
|
|
6700
|
+
LocalCodexComponentStatusWire2["Incompatible"] = "incompatible";
|
|
6701
|
+
LocalCodexComponentStatusWire2["Missing"] = "missing";
|
|
6702
|
+
LocalCodexComponentStatusWire2["Ready"] = "ready";
|
|
6703
|
+
LocalCodexComponentStatusWire2["Unknown"] = "unknown";
|
|
6704
|
+
})(LocalCodexComponentStatusWire || (LocalCodexComponentStatusWire = {}));
|
|
6705
|
+
(function(LocalCodexTurnStatusWire2) {
|
|
6706
|
+
LocalCodexTurnStatusWire2["Cancelled"] = "cancelled";
|
|
6707
|
+
LocalCodexTurnStatusWire2["Failed"] = "failed";
|
|
6708
|
+
LocalCodexTurnStatusWire2["Interrupted"] = "interrupted";
|
|
6709
|
+
LocalCodexTurnStatusWire2["Running"] = "running";
|
|
6710
|
+
LocalCodexTurnStatusWire2["RuntimeLost"] = "runtime_lost";
|
|
6711
|
+
LocalCodexTurnStatusWire2["Succeeded"] = "succeeded";
|
|
6712
|
+
})(LocalCodexTurnStatusWire || (LocalCodexTurnStatusWire = {}));
|
|
6713
|
+
(function(LocalCodexControlKindWire2) {
|
|
6714
|
+
LocalCodexControlKindWire2["Abort"] = "abort";
|
|
6715
|
+
LocalCodexControlKindWire2["InteractionResponse"] = "interaction_response";
|
|
6716
|
+
LocalCodexControlKindWire2["Steer"] = "steer";
|
|
6717
|
+
})(LocalCodexControlKindWire || (LocalCodexControlKindWire = {}));
|
|
6718
|
+
(function(LocalCodexControlOutcomeWire2) {
|
|
6719
|
+
LocalCodexControlOutcomeWire2["Applied"] = "applied";
|
|
6720
|
+
LocalCodexControlOutcomeWire2["Rejected"] = "rejected";
|
|
6721
|
+
LocalCodexControlOutcomeWire2["Stale"] = "stale";
|
|
6722
|
+
})(LocalCodexControlOutcomeWire || (LocalCodexControlOutcomeWire = {}));
|
|
6723
|
+
(function(LocalCodexDiscoveryKindWire2) {
|
|
6724
|
+
LocalCodexDiscoveryKindWire2["DirectoryList"] = "directory_list";
|
|
6725
|
+
LocalCodexDiscoveryKindWire2["ModelList"] = "model_list";
|
|
6726
|
+
})(LocalCodexDiscoveryKindWire || (LocalCodexDiscoveryKindWire = {}));
|
|
6727
|
+
(function(LocalCodexDiscoveryStatusWire2) {
|
|
6728
|
+
LocalCodexDiscoveryStatusWire2["Failed"] = "failed";
|
|
6729
|
+
LocalCodexDiscoveryStatusWire2["Succeeded"] = "succeeded";
|
|
6730
|
+
})(LocalCodexDiscoveryStatusWire || (LocalCodexDiscoveryStatusWire = {}));
|
|
6731
|
+
(function(LocalCodexAttemptPhase2) {
|
|
6732
|
+
LocalCodexAttemptPhase2["Claimed"] = "claimed";
|
|
6733
|
+
LocalCodexAttemptPhase2["Running"] = "running";
|
|
6734
|
+
LocalCodexAttemptPhase2["TerminalPendingUpload"] = "terminal_pending_upload";
|
|
6735
|
+
LocalCodexAttemptPhase2["Uploaded"] = "uploaded";
|
|
6736
|
+
})(LocalCodexAttemptPhase || (LocalCodexAttemptPhase = {}));
|
|
6737
|
+
(function(LocalCodexControlApplyPhase2) {
|
|
6738
|
+
LocalCodexControlApplyPhase2["Applied"] = "applied";
|
|
6739
|
+
LocalCodexControlApplyPhase2["Recorded"] = "recorded";
|
|
6740
|
+
})(LocalCodexControlApplyPhase || (LocalCodexControlApplyPhase = {}));
|
|
6741
|
+
}
|
|
6742
|
+
});
|
|
6743
|
+
|
|
6688
6744
|
// ../machine-connector/dist/runtime/relay-client.js
|
|
6689
6745
|
function localCodexRuntimeEventsRequestBody(fence, firstSequence, events) {
|
|
6690
6746
|
return { ...fence, events, firstSequence };
|
|
@@ -6769,6 +6825,7 @@ var init_relay_client = __esm({
|
|
|
6769
6825
|
"use strict";
|
|
6770
6826
|
init_cjs_shims();
|
|
6771
6827
|
init_version();
|
|
6828
|
+
init_contracts2();
|
|
6772
6829
|
requestTimeoutMilliseconds = 65e3;
|
|
6773
6830
|
RelayHttpError = class extends Error {
|
|
6774
6831
|
responseBody;
|
|
@@ -6851,6 +6908,16 @@ var init_relay_client = __esm({
|
|
|
6851
6908
|
async claimCodexRuntime(request2, signal) {
|
|
6852
6909
|
return await this.authenticatedPost("codex-runtime/turns/claim", request2, signal);
|
|
6853
6910
|
}
|
|
6911
|
+
async claimCodexRuntimeDiscovery(request2, signal) {
|
|
6912
|
+
return await this.authenticatedPost("codex-runtime/discovery/claim", request2, signal);
|
|
6913
|
+
}
|
|
6914
|
+
async completeCodexRuntimeDiscovery(requestId, connectorInstanceId, result) {
|
|
6915
|
+
return await this.authenticatedPost(`codex-runtime/discovery/requests/${encodeURIComponent(requestId)}/result`, {
|
|
6916
|
+
...result,
|
|
6917
|
+
connectorInstanceId,
|
|
6918
|
+
protocolVersion: localCodexRuntimeProtocolVersion
|
|
6919
|
+
});
|
|
6920
|
+
}
|
|
6854
6921
|
async renewCodexRuntimeLease(attemptId, fence, signal) {
|
|
6855
6922
|
return await this.authenticatedPost(`codex-runtime/attempts/${encodeURIComponent(attemptId)}/lease`, fence, signal);
|
|
6856
6923
|
}
|
|
@@ -7282,54 +7349,6 @@ var init_store = __esm({
|
|
|
7282
7349
|
}
|
|
7283
7350
|
});
|
|
7284
7351
|
|
|
7285
|
-
// ../machine-connector/dist/runtime/local-codex-runtime/contracts.js
|
|
7286
|
-
var localCodexRuntimeProtocolVersion, localCodexRuntimeEventSchemaVersion, localCodexRuntimeEventRedactionVersion, LocalCodexComponentStatusWire, LocalCodexTurnStatusWire, LocalCodexControlKindWire, LocalCodexControlOutcomeWire, LocalCodexAttemptPhase, LocalCodexControlApplyPhase;
|
|
7287
|
-
var init_contracts2 = __esm({
|
|
7288
|
-
"../machine-connector/dist/runtime/local-codex-runtime/contracts.js"() {
|
|
7289
|
-
"use strict";
|
|
7290
|
-
init_cjs_shims();
|
|
7291
|
-
localCodexRuntimeProtocolVersion = "1.0";
|
|
7292
|
-
localCodexRuntimeEventSchemaVersion = 1;
|
|
7293
|
-
localCodexRuntimeEventRedactionVersion = 1;
|
|
7294
|
-
(function(LocalCodexComponentStatusWire2) {
|
|
7295
|
-
LocalCodexComponentStatusWire2["AuthenticationRequired"] = "authentication_required";
|
|
7296
|
-
LocalCodexComponentStatusWire2["Error"] = "error";
|
|
7297
|
-
LocalCodexComponentStatusWire2["Incompatible"] = "incompatible";
|
|
7298
|
-
LocalCodexComponentStatusWire2["Missing"] = "missing";
|
|
7299
|
-
LocalCodexComponentStatusWire2["Ready"] = "ready";
|
|
7300
|
-
LocalCodexComponentStatusWire2["Unknown"] = "unknown";
|
|
7301
|
-
})(LocalCodexComponentStatusWire || (LocalCodexComponentStatusWire = {}));
|
|
7302
|
-
(function(LocalCodexTurnStatusWire2) {
|
|
7303
|
-
LocalCodexTurnStatusWire2["Cancelled"] = "cancelled";
|
|
7304
|
-
LocalCodexTurnStatusWire2["Failed"] = "failed";
|
|
7305
|
-
LocalCodexTurnStatusWire2["Interrupted"] = "interrupted";
|
|
7306
|
-
LocalCodexTurnStatusWire2["Running"] = "running";
|
|
7307
|
-
LocalCodexTurnStatusWire2["RuntimeLost"] = "runtime_lost";
|
|
7308
|
-
LocalCodexTurnStatusWire2["Succeeded"] = "succeeded";
|
|
7309
|
-
})(LocalCodexTurnStatusWire || (LocalCodexTurnStatusWire = {}));
|
|
7310
|
-
(function(LocalCodexControlKindWire2) {
|
|
7311
|
-
LocalCodexControlKindWire2["Abort"] = "abort";
|
|
7312
|
-
LocalCodexControlKindWire2["InteractionResponse"] = "interaction_response";
|
|
7313
|
-
LocalCodexControlKindWire2["Steer"] = "steer";
|
|
7314
|
-
})(LocalCodexControlKindWire || (LocalCodexControlKindWire = {}));
|
|
7315
|
-
(function(LocalCodexControlOutcomeWire2) {
|
|
7316
|
-
LocalCodexControlOutcomeWire2["Applied"] = "applied";
|
|
7317
|
-
LocalCodexControlOutcomeWire2["Rejected"] = "rejected";
|
|
7318
|
-
LocalCodexControlOutcomeWire2["Stale"] = "stale";
|
|
7319
|
-
})(LocalCodexControlOutcomeWire || (LocalCodexControlOutcomeWire = {}));
|
|
7320
|
-
(function(LocalCodexAttemptPhase2) {
|
|
7321
|
-
LocalCodexAttemptPhase2["Claimed"] = "claimed";
|
|
7322
|
-
LocalCodexAttemptPhase2["Running"] = "running";
|
|
7323
|
-
LocalCodexAttemptPhase2["TerminalPendingUpload"] = "terminal_pending_upload";
|
|
7324
|
-
LocalCodexAttemptPhase2["Uploaded"] = "uploaded";
|
|
7325
|
-
})(LocalCodexAttemptPhase || (LocalCodexAttemptPhase = {}));
|
|
7326
|
-
(function(LocalCodexControlApplyPhase2) {
|
|
7327
|
-
LocalCodexControlApplyPhase2["Applied"] = "applied";
|
|
7328
|
-
LocalCodexControlApplyPhase2["Recorded"] = "recorded";
|
|
7329
|
-
})(LocalCodexControlApplyPhase || (LocalCodexControlApplyPhase = {}));
|
|
7330
|
-
}
|
|
7331
|
-
});
|
|
7332
|
-
|
|
7333
7352
|
// ../machine-connector/dist/runtime/local-codex-runtime/app-server-client.js
|
|
7334
7353
|
function appServerResponseMessage(response) {
|
|
7335
7354
|
if (typeof response === "object" && response !== null && "message" in response && typeof response.message === "string") {
|
|
@@ -8513,6 +8532,36 @@ function terminalErrorMessage(payload) {
|
|
|
8513
8532
|
const message = safeRecord(payload.error).message;
|
|
8514
8533
|
return typeof message === "string" ? { value: message } : {};
|
|
8515
8534
|
}
|
|
8535
|
+
function parseModelListResponse(value) {
|
|
8536
|
+
const response = safeRecord(value);
|
|
8537
|
+
if (!Array.isArray(response.data)) {
|
|
8538
|
+
throw new AppServerProtocolError("Codex App Server model/list returned no data array");
|
|
8539
|
+
}
|
|
8540
|
+
const models = [];
|
|
8541
|
+
for (const candidate of response.data) {
|
|
8542
|
+
const model = safeRecord(candidate);
|
|
8543
|
+
if (typeof model.model !== "string" || model.model.length === 0 || model.model.length > 128 || typeof model.displayName !== "string" || model.displayName.length === 0 || model.displayName.length > 255 || typeof model.description !== "string" || model.description.length > 2e3 || typeof model.isDefault !== "boolean") {
|
|
8544
|
+
throw new AppServerProtocolError("Codex App Server model/list returned an invalid model");
|
|
8545
|
+
}
|
|
8546
|
+
models.push({
|
|
8547
|
+
description: model.description,
|
|
8548
|
+
displayName: model.displayName,
|
|
8549
|
+
isDefault: model.isDefault,
|
|
8550
|
+
model: model.model
|
|
8551
|
+
});
|
|
8552
|
+
}
|
|
8553
|
+
const nextCursor = response.nextCursor;
|
|
8554
|
+
if (nextCursor === null || nextCursor === void 0) {
|
|
8555
|
+
return { models };
|
|
8556
|
+
}
|
|
8557
|
+
if (typeof nextCursor !== "string" || nextCursor.length === 0) {
|
|
8558
|
+
throw new AppServerProtocolError("Codex App Server model/list returned an invalid cursor");
|
|
8559
|
+
}
|
|
8560
|
+
return { models, nextCursor };
|
|
8561
|
+
}
|
|
8562
|
+
function portableRelativeDirectory(value) {
|
|
8563
|
+
return value === "" ? "." : value.replaceAll("\\", "/");
|
|
8564
|
+
}
|
|
8516
8565
|
function safeRecord(value) {
|
|
8517
8566
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
|
|
8518
8567
|
}
|
|
@@ -8592,12 +8641,14 @@ function parseLeaseDeadline(value) {
|
|
|
8592
8641
|
}
|
|
8593
8642
|
return parsed;
|
|
8594
8643
|
}
|
|
8595
|
-
var import_node_child_process4, heartbeatIntervalMilliseconds, claimRetryMilliseconds, claimWaitSeconds, eventUploadCoalesceMilliseconds, eventUploadRetryMilliseconds, maximumEventUploadCount, preferredEventUploadRequestBytes, leaseRenewIntervalMilliseconds, leaseRenewRetryMilliseconds, interactionTimeoutMilliseconds, executableProbeTimeoutMilliseconds, recoveryRetryMilliseconds, initialThreadNameRetryMilliseconds, maximumThreadNameRetryMilliseconds, maximumInitialThreadNameAttempts, ThreadUnavailableError, LeaseLostError, SpoolPersistenceError, UnknownTurnStartResultError, LocalCodexRuntimeConnectionWorker;
|
|
8644
|
+
var import_node_child_process4, import_promises12, import_node_path10, heartbeatIntervalMilliseconds, claimRetryMilliseconds, claimWaitSeconds, discoveryWaitSeconds, discoveryRetryMilliseconds, maximumDiscoveryDirectories, maximumDiscoveryModels, maximumModelListPages, eventUploadCoalesceMilliseconds, eventUploadRetryMilliseconds, maximumEventUploadCount, preferredEventUploadRequestBytes, leaseRenewIntervalMilliseconds, leaseRenewRetryMilliseconds, interactionTimeoutMilliseconds, executableProbeTimeoutMilliseconds, recoveryRetryMilliseconds, initialThreadNameRetryMilliseconds, maximumThreadNameRetryMilliseconds, maximumInitialThreadNameAttempts, ThreadUnavailableError, LeaseLostError, SpoolPersistenceError, UnknownTurnStartResultError, LocalCodexRuntimeConnectionWorker;
|
|
8596
8645
|
var init_runtime_worker = __esm({
|
|
8597
8646
|
"../machine-connector/dist/runtime/local-codex-runtime/runtime-worker.js"() {
|
|
8598
8647
|
"use strict";
|
|
8599
8648
|
init_cjs_shims();
|
|
8600
8649
|
import_node_child_process4 = require("child_process");
|
|
8650
|
+
import_promises12 = require("fs/promises");
|
|
8651
|
+
import_node_path10 = require("path");
|
|
8601
8652
|
init_process_executor();
|
|
8602
8653
|
init_relay_client();
|
|
8603
8654
|
init_app_server_client();
|
|
@@ -8607,6 +8658,11 @@ var init_runtime_worker = __esm({
|
|
|
8607
8658
|
heartbeatIntervalMilliseconds = 2e4;
|
|
8608
8659
|
claimRetryMilliseconds = 250;
|
|
8609
8660
|
claimWaitSeconds = 25;
|
|
8661
|
+
discoveryWaitSeconds = 25;
|
|
8662
|
+
discoveryRetryMilliseconds = 1e3;
|
|
8663
|
+
maximumDiscoveryDirectories = 1e3;
|
|
8664
|
+
maximumDiscoveryModels = 100;
|
|
8665
|
+
maximumModelListPages = 10;
|
|
8610
8666
|
eventUploadCoalesceMilliseconds = 500;
|
|
8611
8667
|
eventUploadRetryMilliseconds = 1e3;
|
|
8612
8668
|
maximumEventUploadCount = 500;
|
|
@@ -8805,6 +8861,7 @@ var init_runtime_worker = __esm({
|
|
|
8805
8861
|
await Promise.all([
|
|
8806
8862
|
this.runHeartbeatLoop(),
|
|
8807
8863
|
this.runClaimLoop(),
|
|
8864
|
+
this.runDiscoveryLoop(),
|
|
8808
8865
|
this.runRecoveryLoop()
|
|
8809
8866
|
]);
|
|
8810
8867
|
} finally {
|
|
@@ -8861,6 +8918,105 @@ var init_runtime_worker = __esm({
|
|
|
8861
8918
|
}
|
|
8862
8919
|
}
|
|
8863
8920
|
}
|
|
8921
|
+
async runDiscoveryLoop() {
|
|
8922
|
+
while (!this.lifetimeAbort.signal.aborted && !this.relay.isRevoked()) {
|
|
8923
|
+
try {
|
|
8924
|
+
const response = await this.relay.claimCodexRuntimeDiscovery({
|
|
8925
|
+
connectorInstanceId: this.connectorInstanceId,
|
|
8926
|
+
protocolVersion: localCodexRuntimeProtocolVersion,
|
|
8927
|
+
waitSeconds: discoveryWaitSeconds
|
|
8928
|
+
}, this.lifetimeAbort.signal);
|
|
8929
|
+
if (response.request === void 0) {
|
|
8930
|
+
continue;
|
|
8931
|
+
}
|
|
8932
|
+
await this.completeDiscovery(response.request);
|
|
8933
|
+
} catch (error) {
|
|
8934
|
+
if (!this.lifetimeAbort.signal.aborted) {
|
|
8935
|
+
await this.logger.error(`Local Codex discovery loop failed for connection ${this.connection.connectionId}`, error);
|
|
8936
|
+
await waitForAbort(this.lifetimeAbort.signal, discoveryRetryMilliseconds);
|
|
8937
|
+
}
|
|
8938
|
+
}
|
|
8939
|
+
}
|
|
8940
|
+
}
|
|
8941
|
+
async completeDiscovery(request2) {
|
|
8942
|
+
let result;
|
|
8943
|
+
try {
|
|
8944
|
+
result = await this.executeDiscovery(request2);
|
|
8945
|
+
} catch (error) {
|
|
8946
|
+
await this.logger.error(`Local Codex ${request2.kind} discovery failed for connection ${this.connection.connectionId}`, error);
|
|
8947
|
+
result = {
|
|
8948
|
+
errorCode: request2.kind === LocalCodexDiscoveryKindWire.ModelList ? "model_discovery_failed" : "directory_unavailable",
|
|
8949
|
+
requestId: request2.requestId,
|
|
8950
|
+
status: LocalCodexDiscoveryStatusWire.Failed
|
|
8951
|
+
};
|
|
8952
|
+
}
|
|
8953
|
+
const completion = await this.relay.completeCodexRuntimeDiscovery(request2.requestId, this.connectorInstanceId, result);
|
|
8954
|
+
if (!completion.accepted) {
|
|
8955
|
+
await this.logger.info(`Local Codex discovery request ${request2.requestId} expired before completion`);
|
|
8956
|
+
}
|
|
8957
|
+
}
|
|
8958
|
+
async executeDiscovery(request2) {
|
|
8959
|
+
if (request2.kind === LocalCodexDiscoveryKindWire.ModelList) {
|
|
8960
|
+
return {
|
|
8961
|
+
models: await this.discoverModels(),
|
|
8962
|
+
requestId: request2.requestId,
|
|
8963
|
+
status: LocalCodexDiscoveryStatusWire.Succeeded
|
|
8964
|
+
};
|
|
8965
|
+
}
|
|
8966
|
+
if (request2.kind === LocalCodexDiscoveryKindWire.DirectoryList) {
|
|
8967
|
+
const listing = await this.discoverDirectories(request2.relativeDirectory ?? ".");
|
|
8968
|
+
return {
|
|
8969
|
+
...listing,
|
|
8970
|
+
requestId: request2.requestId,
|
|
8971
|
+
status: LocalCodexDiscoveryStatusWire.Succeeded
|
|
8972
|
+
};
|
|
8973
|
+
}
|
|
8974
|
+
throw new Error("Unsupported Local Codex discovery kind");
|
|
8975
|
+
}
|
|
8976
|
+
async discoverModels() {
|
|
8977
|
+
const client = await this.processPool.ensureStarted();
|
|
8978
|
+
const models = /* @__PURE__ */ new Map();
|
|
8979
|
+
const cursor = {};
|
|
8980
|
+
for (let page = 0; page < maximumModelListPages; page += 1) {
|
|
8981
|
+
const response = await client.request("model/list", {
|
|
8982
|
+
cursor: cursor.value ?? null,
|
|
8983
|
+
includeHidden: false,
|
|
8984
|
+
limit: maximumDiscoveryModels
|
|
8985
|
+
});
|
|
8986
|
+
const parsed = parseModelListResponse(response);
|
|
8987
|
+
for (const model of parsed.models) {
|
|
8988
|
+
models.set(model.model, model);
|
|
8989
|
+
if (models.size >= maximumDiscoveryModels) {
|
|
8990
|
+
return [...models.values()];
|
|
8991
|
+
}
|
|
8992
|
+
}
|
|
8993
|
+
if (parsed.nextCursor === void 0) {
|
|
8994
|
+
return [...models.values()];
|
|
8995
|
+
}
|
|
8996
|
+
cursor.value = parsed.nextCursor;
|
|
8997
|
+
}
|
|
8998
|
+
throw new AppServerProtocolError("Codex App Server model/list pagination did not converge");
|
|
8999
|
+
}
|
|
9000
|
+
async discoverDirectories(relativeDirectory) {
|
|
9001
|
+
const canonicalRoot = await resolveCanonicalWorkingDirectory(this.connection.rootPath, ".");
|
|
9002
|
+
const canonicalDirectory = await resolveCanonicalWorkingDirectory(canonicalRoot, relativeDirectory);
|
|
9003
|
+
const entries = (await (0, import_promises12.readdir)(canonicalDirectory, {
|
|
9004
|
+
withFileTypes: true
|
|
9005
|
+
})).filter((entry) => entry.isDirectory()).filter((entry) => !entry.name.includes("\\")).sort((left, right) => left.name.localeCompare(right.name, void 0, {
|
|
9006
|
+
numeric: true,
|
|
9007
|
+
sensitivity: "base"
|
|
9008
|
+
}));
|
|
9009
|
+
const eligibleDirectories = entries.map((entry) => ({
|
|
9010
|
+
name: entry.name,
|
|
9011
|
+
relativePath: portableRelativeDirectory((0, import_node_path10.relative)(canonicalRoot, (0, import_node_path10.join)(canonicalDirectory, entry.name)))
|
|
9012
|
+
})).filter((entry) => entry.name.length <= 255 && entry.relativePath.length <= 1024);
|
|
9013
|
+
const directories = eligibleDirectories.slice(0, maximumDiscoveryDirectories);
|
|
9014
|
+
return {
|
|
9015
|
+
currentRelativeDirectory: portableRelativeDirectory((0, import_node_path10.relative)(canonicalRoot, canonicalDirectory)),
|
|
9016
|
+
directories,
|
|
9017
|
+
truncated: eligibleDirectories.length > maximumDiscoveryDirectories
|
|
9018
|
+
};
|
|
9019
|
+
}
|
|
8864
9020
|
async executeAttempt(claim) {
|
|
8865
9021
|
const durable = await DurableLocalCodexAttempt.create(this.store, this.connection.connectionId, this.connectorInstanceId, claim);
|
|
8866
9022
|
const active = createActiveAttempt(claim, durable, this.connection.rootPath);
|
|
@@ -10690,7 +10846,9 @@ async function installUserService(store, request2, runtime = defaultServiceManag
|
|
|
10690
10846
|
const capabilities = await detectServiceManagerCapabilities(runtime);
|
|
10691
10847
|
const selection = selectUserServiceManager(request2.preference, capabilities);
|
|
10692
10848
|
if (selection.manager === UserServiceManager.None) {
|
|
10693
|
-
await
|
|
10849
|
+
if (await readStoredServiceManager(store) === UserServiceManager.None) {
|
|
10850
|
+
await persistServiceManager(store, UserServiceManager.None);
|
|
10851
|
+
}
|
|
10694
10852
|
return {
|
|
10695
10853
|
detail: selection.detail,
|
|
10696
10854
|
installed: false,
|
|
@@ -10707,6 +10865,7 @@ async function installUserService(store, request2, runtime = defaultServiceManag
|
|
|
10707
10865
|
}
|
|
10708
10866
|
const candidates = await automaticManagerCandidates(store, capabilities);
|
|
10709
10867
|
const failures = [];
|
|
10868
|
+
let cleanupFailed = false;
|
|
10710
10869
|
for (const manager of candidates) {
|
|
10711
10870
|
try {
|
|
10712
10871
|
await replaceConfiguredManager(store, manager, options, runtime);
|
|
@@ -10717,10 +10876,18 @@ async function installUserService(store, request2, runtime = defaultServiceManag
|
|
|
10717
10876
|
};
|
|
10718
10877
|
} catch (error) {
|
|
10719
10878
|
failures.push(`${manager}: ${error instanceof Error ? error.message : String(error)}`);
|
|
10720
|
-
|
|
10879
|
+
try {
|
|
10880
|
+
await uninstallManager(manager, store, runtime);
|
|
10881
|
+
} catch (cleanupError) {
|
|
10882
|
+
failures.push(`${manager} cleanup: ${cleanupError instanceof Error ? cleanupError.message : String(cleanupError)}`);
|
|
10883
|
+
cleanupFailed = true;
|
|
10884
|
+
break;
|
|
10885
|
+
}
|
|
10721
10886
|
}
|
|
10722
10887
|
}
|
|
10723
|
-
|
|
10888
|
+
if (!cleanupFailed) {
|
|
10889
|
+
await persistServiceManager(store, UserServiceManager.None);
|
|
10890
|
+
}
|
|
10724
10891
|
return {
|
|
10725
10892
|
detail: failures.length === 0 ? selection.detail : `Automatic background service setup failed (${failures.join("; ")}). Pairing is complete, but the Connector must be started manually.`,
|
|
10726
10893
|
installed: false,
|
|
@@ -10729,12 +10896,12 @@ async function installUserService(store, request2, runtime = defaultServiceManag
|
|
|
10729
10896
|
}
|
|
10730
10897
|
function createServiceEnvironment(options) {
|
|
10731
10898
|
const inheritedPath = options.environment.PATH ?? process.env.PATH ?? "";
|
|
10732
|
-
const nodeDirectory = (0,
|
|
10733
|
-
const pathEntries = [nodeDirectory, ...inheritedPath.split(
|
|
10899
|
+
const nodeDirectory = (0, import_node_path11.dirname)(options.nodePath);
|
|
10900
|
+
const pathEntries = [nodeDirectory, ...inheritedPath.split(import_node_path11.delimiter)].filter((entry, index2, entries) => entry.length > 0 && entries.indexOf(entry) === index2);
|
|
10734
10901
|
return {
|
|
10735
10902
|
...options.environment,
|
|
10736
10903
|
HOME: options.environment.HOME ?? process.env.HOME ?? (0, import_node_os7.homedir)(),
|
|
10737
|
-
PATH: pathEntries.join(
|
|
10904
|
+
PATH: pathEntries.join(import_node_path11.delimiter)
|
|
10738
10905
|
};
|
|
10739
10906
|
}
|
|
10740
10907
|
async function restartUserService(store, runtime = defaultServiceManagerRuntime) {
|
|
@@ -10766,9 +10933,6 @@ async function refreshManagedUserService(store, options, runtime = defaultServic
|
|
|
10766
10933
|
};
|
|
10767
10934
|
try {
|
|
10768
10935
|
await installManager(manager, store, refreshedOptions, runtime);
|
|
10769
|
-
if (manager === UserServiceManager.Systemd) {
|
|
10770
|
-
await restartManager(manager, store, runtime);
|
|
10771
|
-
}
|
|
10772
10936
|
await persistServiceManager(store, manager, options.entrypointPath);
|
|
10773
10937
|
} catch (error) {
|
|
10774
10938
|
try {
|
|
@@ -10860,7 +11024,7 @@ async function automaticManagerCandidates(store, capabilities) {
|
|
|
10860
11024
|
async function replaceConfiguredManager(store, manager, options, runtime) {
|
|
10861
11025
|
const configuredManager = await readStoredServiceManager(store);
|
|
10862
11026
|
if (configuredManager !== UserServiceManager.None && configuredManager !== manager) {
|
|
10863
|
-
await
|
|
11027
|
+
await uninstallManager(configuredManager, store, runtime);
|
|
10864
11028
|
}
|
|
10865
11029
|
await installManager(manager, store, options, runtime);
|
|
10866
11030
|
await persistServiceManager(store, manager, options.entrypointPath);
|
|
@@ -10920,12 +11084,7 @@ async function stopManager(manager, store, runtime) {
|
|
|
10920
11084
|
]);
|
|
10921
11085
|
return;
|
|
10922
11086
|
}
|
|
10923
|
-
await
|
|
10924
|
-
"-c",
|
|
10925
|
-
supervisorConfigPath(store),
|
|
10926
|
-
"stop",
|
|
10927
|
-
supervisorProgramName
|
|
10928
|
-
]);
|
|
11087
|
+
await stopSupervisorProgram(store, runtime);
|
|
10929
11088
|
}
|
|
10930
11089
|
async function uninstallManager(manager, store, runtime) {
|
|
10931
11090
|
if (manager === UserServiceManager.None) {
|
|
@@ -10936,7 +11095,7 @@ async function uninstallManager(manager, store, runtime) {
|
|
|
10936
11095
|
"bootout",
|
|
10937
11096
|
`gui/${process.getuid?.() ?? 0}/${launchAgentLabel}`
|
|
10938
11097
|
]);
|
|
10939
|
-
await (0,
|
|
11098
|
+
await (0, import_promises13.rm)(launchAgentPath(), { force: true });
|
|
10940
11099
|
return;
|
|
10941
11100
|
}
|
|
10942
11101
|
if (manager === UserServiceManager.Systemd) {
|
|
@@ -10946,21 +11105,24 @@ async function uninstallManager(manager, store, runtime) {
|
|
|
10946
11105
|
"--now",
|
|
10947
11106
|
"moxt-machine-connector.service"
|
|
10948
11107
|
]);
|
|
10949
|
-
await (0,
|
|
11108
|
+
await (0, import_promises13.rm)(systemdUnitPath(), { force: true });
|
|
10950
11109
|
await runCommandIgnoringFailure(runtime, "systemctl", [
|
|
10951
11110
|
"--user",
|
|
10952
11111
|
"daemon-reload"
|
|
10953
11112
|
]);
|
|
10954
11113
|
return;
|
|
10955
11114
|
}
|
|
10956
|
-
await
|
|
10957
|
-
|
|
10958
|
-
|
|
10959
|
-
"
|
|
10960
|
-
|
|
10961
|
-
|
|
10962
|
-
|
|
10963
|
-
|
|
11115
|
+
const supervisorProcessId = await currentSupervisorProcessId(store, runtime);
|
|
11116
|
+
await stopSupervisorProgram(store, runtime);
|
|
11117
|
+
if (supervisorProcessId !== void 0) {
|
|
11118
|
+
await runtime.run("supervisorctl", [
|
|
11119
|
+
"-c",
|
|
11120
|
+
supervisorConfigPath(store),
|
|
11121
|
+
"shutdown"
|
|
11122
|
+
]);
|
|
11123
|
+
await waitForSupervisorExit(store, runtime, supervisorProcessId);
|
|
11124
|
+
}
|
|
11125
|
+
await (0, import_promises13.rm)(supervisorDirectory(store), {
|
|
10964
11126
|
force: true,
|
|
10965
11127
|
recursive: true
|
|
10966
11128
|
});
|
|
@@ -10986,7 +11148,7 @@ async function readStoredServiceManager(store) {
|
|
|
10986
11148
|
}
|
|
10987
11149
|
async function readManagedServiceDefinition(manager, store) {
|
|
10988
11150
|
try {
|
|
10989
|
-
return await (0,
|
|
11151
|
+
return await (0, import_promises13.readFile)(managedServiceDefinitionPath(manager, store), "utf8");
|
|
10990
11152
|
} catch (error) {
|
|
10991
11153
|
if (isNodeErrorCode4(error, "ENOENT"))
|
|
10992
11154
|
return void 0;
|
|
@@ -10995,8 +11157,8 @@ async function readManagedServiceDefinition(manager, store) {
|
|
|
10995
11157
|
}
|
|
10996
11158
|
async function restoreManagedServiceDefinition(manager, store, definition2, runtime) {
|
|
10997
11159
|
const path4 = managedServiceDefinitionPath(manager, store);
|
|
10998
|
-
await (0,
|
|
10999
|
-
await (0,
|
|
11160
|
+
await (0, import_promises13.mkdir)((0, import_node_path11.dirname)(path4), { recursive: true });
|
|
11161
|
+
await (0, import_promises13.writeFile)(path4, definition2, { encoding: "utf8", mode: 384 });
|
|
11000
11162
|
if (manager === UserServiceManager.Launchd) {
|
|
11001
11163
|
const domain = `gui/${process.getuid?.() ?? 0}`;
|
|
11002
11164
|
await runCommandIgnoringFailure(runtime, "launchctl", [
|
|
@@ -11045,7 +11207,7 @@ function parseProcessId(value) {
|
|
|
11045
11207
|
async function persistServiceManager(store, manager, managedEntrypointPath, desiredState = ManagedServiceDesiredState.Running) {
|
|
11046
11208
|
await store.writeServiceManager({
|
|
11047
11209
|
desiredState,
|
|
11048
|
-
...managedEntrypointPath ? { managedEntrypointPath: (0,
|
|
11210
|
+
...managedEntrypointPath ? { managedEntrypointPath: (0, import_node_path11.resolve)(managedEntrypointPath) } : {},
|
|
11049
11211
|
manager,
|
|
11050
11212
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
11051
11213
|
});
|
|
@@ -11058,9 +11220,9 @@ async function assertManagedServiceProvenance(store, candidateEntrypointPath) {
|
|
|
11058
11220
|
const stored = (await store.readServiceManager()).value;
|
|
11059
11221
|
if (!stored || stored.manager === UserServiceManager.None)
|
|
11060
11222
|
return;
|
|
11061
|
-
const candidate = (0,
|
|
11223
|
+
const candidate = (0, import_node_path11.resolve)(candidateEntrypointPath);
|
|
11062
11224
|
if (stored.managedEntrypointPath) {
|
|
11063
|
-
if ((0,
|
|
11225
|
+
if ((0, import_node_path11.resolve)(stored.managedEntrypointPath) !== candidate) {
|
|
11064
11226
|
throw new Error("The managed Connector belongs to a different CLI installation. Run service install from the owning CLI to transfer management.");
|
|
11065
11227
|
}
|
|
11066
11228
|
return;
|
|
@@ -11070,16 +11232,16 @@ async function assertManagedServiceProvenance(store, candidateEntrypointPath) {
|
|
|
11070
11232
|
}
|
|
11071
11233
|
}
|
|
11072
11234
|
async function isInsideSourceCheckout(path4) {
|
|
11073
|
-
let directory = (0,
|
|
11235
|
+
let directory = (0, import_node_path11.dirname)(path4);
|
|
11074
11236
|
while (true) {
|
|
11075
11237
|
try {
|
|
11076
|
-
await (0,
|
|
11238
|
+
await (0, import_promises13.stat)((0, import_node_path11.join)(directory, ".git"));
|
|
11077
11239
|
return true;
|
|
11078
11240
|
} catch (error) {
|
|
11079
11241
|
if (!isNodeErrorCode4(error, "ENOENT"))
|
|
11080
11242
|
throw error;
|
|
11081
11243
|
}
|
|
11082
|
-
const parent = (0,
|
|
11244
|
+
const parent = (0, import_node_path11.dirname)(directory);
|
|
11083
11245
|
if (parent === directory)
|
|
11084
11246
|
return false;
|
|
11085
11247
|
directory = parent;
|
|
@@ -11108,10 +11270,10 @@ function automaticSelectionDetail(manager) {
|
|
|
11108
11270
|
}
|
|
11109
11271
|
async function installLaunchAgent(store, options, runtime) {
|
|
11110
11272
|
const path4 = launchAgentPath();
|
|
11111
|
-
await (0,
|
|
11273
|
+
await (0, import_promises13.mkdir)((0, import_node_path11.dirname)(path4), { recursive: true });
|
|
11112
11274
|
const programArguments = [
|
|
11113
11275
|
options.nodePath,
|
|
11114
|
-
(0,
|
|
11276
|
+
(0, import_node_path11.resolve)(options.entrypointPath),
|
|
11115
11277
|
...options.commandArguments
|
|
11116
11278
|
];
|
|
11117
11279
|
const plist = `<?xml version="1.0" encoding="UTF-8"?>
|
|
@@ -11142,7 +11304,7 @@ ${Object.entries(options.environment).map(([name, value]) => ` <key>${escapeX
|
|
|
11142
11304
|
</dict>
|
|
11143
11305
|
</plist>
|
|
11144
11306
|
`;
|
|
11145
|
-
await (0,
|
|
11307
|
+
await (0, import_promises13.writeFile)(path4, plist, { encoding: "utf8", mode: 384 });
|
|
11146
11308
|
const domain = `gui/${process.getuid?.() ?? 0}`;
|
|
11147
11309
|
await runCommandIgnoringFailure(runtime, "launchctl", [
|
|
11148
11310
|
"bootout",
|
|
@@ -11158,10 +11320,10 @@ ${Object.entries(options.environment).map(([name, value]) => ` <key>${escapeX
|
|
|
11158
11320
|
}
|
|
11159
11321
|
async function installSystemdUserService(store, options, runtime) {
|
|
11160
11322
|
const path4 = systemdUnitPath();
|
|
11161
|
-
await (0,
|
|
11323
|
+
await (0, import_promises13.mkdir)((0, import_node_path11.dirname)(path4), { recursive: true });
|
|
11162
11324
|
const command = [
|
|
11163
11325
|
options.nodePath,
|
|
11164
|
-
(0,
|
|
11326
|
+
(0, import_node_path11.resolve)(options.entrypointPath),
|
|
11165
11327
|
...options.commandArguments
|
|
11166
11328
|
].map(escapeSystemdArgument).join(" ");
|
|
11167
11329
|
const unit = `[Unit]
|
|
@@ -11180,7 +11342,7 @@ ${Object.entries(options.environment).map(([name, value]) => `Environment=${esca
|
|
|
11180
11342
|
[Install]
|
|
11181
11343
|
WantedBy=default.target
|
|
11182
11344
|
`;
|
|
11183
|
-
await (0,
|
|
11345
|
+
await (0, import_promises13.writeFile)(path4, unit, { encoding: "utf8", mode: 384 });
|
|
11184
11346
|
await runtime.run("systemctl", ["--user", "daemon-reload"]);
|
|
11185
11347
|
await runtime.run("systemctl", [
|
|
11186
11348
|
"--user",
|
|
@@ -11188,6 +11350,11 @@ WantedBy=default.target
|
|
|
11188
11350
|
"--now",
|
|
11189
11351
|
"moxt-machine-connector.service"
|
|
11190
11352
|
]);
|
|
11353
|
+
await runtime.run("systemctl", [
|
|
11354
|
+
"--user",
|
|
11355
|
+
"restart",
|
|
11356
|
+
"moxt-machine-connector.service"
|
|
11357
|
+
]);
|
|
11191
11358
|
await runCommandIgnoringFailure(runtime, "loginctl", [
|
|
11192
11359
|
"enable-linger",
|
|
11193
11360
|
(0, import_node_os7.userInfo)().username
|
|
@@ -11196,8 +11363,8 @@ WantedBy=default.target
|
|
|
11196
11363
|
async function installSupervisorUserService(store, options, runtime) {
|
|
11197
11364
|
const directory = supervisorDirectory(store);
|
|
11198
11365
|
const configPath = supervisorConfigPath(store);
|
|
11199
|
-
await (0,
|
|
11200
|
-
await (0,
|
|
11366
|
+
await (0, import_promises13.mkdir)(directory, { recursive: true, mode: 448 });
|
|
11367
|
+
await (0, import_promises13.writeFile)(configPath, createSupervisorConfiguration(store, options), {
|
|
11201
11368
|
encoding: "utf8",
|
|
11202
11369
|
mode: 384
|
|
11203
11370
|
});
|
|
@@ -11211,7 +11378,7 @@ async function installSupervisorUserService(store, options, runtime) {
|
|
|
11211
11378
|
function createSupervisorConfiguration(store, options) {
|
|
11212
11379
|
const command = [
|
|
11213
11380
|
options.nodePath,
|
|
11214
|
-
(0,
|
|
11381
|
+
(0, import_node_path11.resolve)(options.entrypointPath),
|
|
11215
11382
|
...options.commandArguments
|
|
11216
11383
|
].map(escapeSupervisorArgument).join(" ");
|
|
11217
11384
|
const environment = Object.entries(options.environment).map(([name, value]) => `${name}="${escapeSupervisorEnvironment(value)}"`).join(",");
|
|
@@ -11235,7 +11402,7 @@ serverurl=unix://${supervisorSocketPath(store)}
|
|
|
11235
11402
|
|
|
11236
11403
|
[program:${supervisorProgramName}]
|
|
11237
11404
|
command=${command}
|
|
11238
|
-
directory=${escapeSupervisorPath((0,
|
|
11405
|
+
directory=${escapeSupervisorPath((0, import_node_path11.dirname)((0, import_node_path11.resolve)(options.entrypointPath)))}
|
|
11239
11406
|
environment=${environment}
|
|
11240
11407
|
autostart=true
|
|
11241
11408
|
autorestart=true
|
|
@@ -11256,7 +11423,7 @@ stderr_logfile_backups=3
|
|
|
11256
11423
|
async function restartSupervisorUserService(store, runtime) {
|
|
11257
11424
|
const configPath = supervisorConfigPath(store);
|
|
11258
11425
|
const supervisorProcessId = await currentSupervisorProcessId(store, runtime);
|
|
11259
|
-
const
|
|
11426
|
+
const stoppedConnector = await stopSupervisorProgram(store, runtime);
|
|
11260
11427
|
if (supervisorProcessId !== void 0) {
|
|
11261
11428
|
await runtime.run("supervisorctl", [
|
|
11262
11429
|
"-c",
|
|
@@ -11265,11 +11432,11 @@ async function restartSupervisorUserService(store, runtime) {
|
|
|
11265
11432
|
]);
|
|
11266
11433
|
await waitForSupervisorExit(store, runtime, supervisorProcessId);
|
|
11267
11434
|
}
|
|
11268
|
-
await startSupervisorUserService(store, runtime, supervisorProcessId,
|
|
11435
|
+
await startSupervisorUserService(store, runtime, supervisorProcessId, stoppedConnector.processId);
|
|
11269
11436
|
}
|
|
11270
11437
|
async function startSupervisorUserService(store, runtime, previousSupervisorProcessId, previousConnectorProcessId) {
|
|
11271
|
-
await (0,
|
|
11272
|
-
await (0,
|
|
11438
|
+
await (0, import_promises13.rm)(supervisorSocketPath(store), { force: true });
|
|
11439
|
+
await (0, import_promises13.rm)(supervisorPidPath(store), { force: true });
|
|
11273
11440
|
await runtime.run("supervisord", ["-c", supervisorConfigPath(store)], {
|
|
11274
11441
|
environment: sanitizeEnvironment(process.env),
|
|
11275
11442
|
timeoutMilliseconds: serviceManagerMutationTimeoutMilliseconds
|
|
@@ -11279,19 +11446,7 @@ async function startSupervisorUserService(store, runtime, previousSupervisorProc
|
|
|
11279
11446
|
}
|
|
11280
11447
|
async function reloadSupervisorConfiguration(store, runtime) {
|
|
11281
11448
|
const configPath = supervisorConfigPath(store);
|
|
11282
|
-
|
|
11283
|
-
if (processIdBeforeStop !== void 0) {
|
|
11284
|
-
await runtime.run("supervisorctl", [
|
|
11285
|
-
"-c",
|
|
11286
|
-
configPath,
|
|
11287
|
-
"stop",
|
|
11288
|
-
supervisorProgramName
|
|
11289
|
-
]);
|
|
11290
|
-
const processIdAfterStop = await currentSupervisorProgramProcessId(store, runtime);
|
|
11291
|
-
if (processIdAfterStop !== void 0) {
|
|
11292
|
-
throw new Error("Supervisor did not stop the existing Moxt Machine Connector process");
|
|
11293
|
-
}
|
|
11294
|
-
}
|
|
11449
|
+
await stopSupervisorProgram(store, runtime);
|
|
11295
11450
|
await runtime.run("supervisorctl", ["-c", configPath, "reread"]);
|
|
11296
11451
|
await runtime.run("supervisorctl", ["-c", configPath, "update"]);
|
|
11297
11452
|
const processId = await currentSupervisorProgramProcessId(store, runtime);
|
|
@@ -11328,6 +11483,30 @@ async function waitForSupervisorExit(store, runtime, processId) {
|
|
|
11328
11483
|
}
|
|
11329
11484
|
throw new Error(`Supervisor did not exit within ${supervisorExitTimeoutMilliseconds / 1e3} seconds`);
|
|
11330
11485
|
}
|
|
11486
|
+
async function stopSupervisorProgram(store, runtime) {
|
|
11487
|
+
const processId = await currentSupervisorProgramProcessId(store, runtime);
|
|
11488
|
+
if (processId === void 0)
|
|
11489
|
+
return {};
|
|
11490
|
+
await runtime.run("supervisorctl", [
|
|
11491
|
+
"-c",
|
|
11492
|
+
supervisorConfigPath(store),
|
|
11493
|
+
"stop",
|
|
11494
|
+
supervisorProgramName
|
|
11495
|
+
]);
|
|
11496
|
+
await waitForSupervisorProgramExit(store, runtime, processId);
|
|
11497
|
+
return { processId };
|
|
11498
|
+
}
|
|
11499
|
+
async function waitForSupervisorProgramExit(store, runtime, processId) {
|
|
11500
|
+
const deadline = serviceManagerCurrentTime(runtime) + supervisorExitTimeoutMilliseconds;
|
|
11501
|
+
while (serviceManagerCurrentTime(runtime) < deadline) {
|
|
11502
|
+
const reportedProcessId = await currentSupervisorProgramProcessId(store, runtime);
|
|
11503
|
+
if (reportedProcessId !== processId && !serviceProcessIsRunning(runtime, processId)) {
|
|
11504
|
+
return;
|
|
11505
|
+
}
|
|
11506
|
+
await serviceManagerDelay(runtime, 100);
|
|
11507
|
+
}
|
|
11508
|
+
throw new Error(`Supervisor did not stop Moxt Machine Connector process ${processId} within ${supervisorExitTimeoutMilliseconds / 1e3} seconds`);
|
|
11509
|
+
}
|
|
11331
11510
|
function serviceProcessIsRunning(runtime, processId) {
|
|
11332
11511
|
if (runtime.processIsRunning)
|
|
11333
11512
|
return runtime.processIsRunning(processId);
|
|
@@ -11366,7 +11545,7 @@ async function currentSupervisorProcessId(store, runtime) {
|
|
|
11366
11545
|
} catch {
|
|
11367
11546
|
}
|
|
11368
11547
|
try {
|
|
11369
|
-
const processId = parseProcessId(await (0,
|
|
11548
|
+
const processId = parseProcessId(await (0, import_promises13.readFile)(supervisorPidPath(store), "utf8"));
|
|
11370
11549
|
return processId !== void 0 && serviceProcessIsRunning(runtime, processId) ? processId : void 0;
|
|
11371
11550
|
} catch (error) {
|
|
11372
11551
|
if (isNodeErrorCode4(error, "ENOENT"))
|
|
@@ -11388,26 +11567,26 @@ async function currentSupervisorProgramProcessId(store, runtime) {
|
|
|
11388
11567
|
}
|
|
11389
11568
|
}
|
|
11390
11569
|
function launchAgentPath() {
|
|
11391
|
-
return (0,
|
|
11570
|
+
return (0, import_node_path11.join)(process.env.HOME ?? (0, import_node_os7.homedir)(), "Library", "LaunchAgents", `${launchAgentLabel}.plist`);
|
|
11392
11571
|
}
|
|
11393
11572
|
function systemdUnitPath() {
|
|
11394
|
-
const configHome = process.env.XDG_CONFIG_HOME ?? (0,
|
|
11395
|
-
return (0,
|
|
11573
|
+
const configHome = process.env.XDG_CONFIG_HOME ?? (0, import_node_path11.join)(process.env.HOME ?? (0, import_node_os7.homedir)(), ".config");
|
|
11574
|
+
return (0, import_node_path11.join)(configHome, "systemd", "user", "moxt-machine-connector.service");
|
|
11396
11575
|
}
|
|
11397
11576
|
function supervisorDirectory(store) {
|
|
11398
|
-
return (0,
|
|
11577
|
+
return (0, import_node_path11.join)(store.baseDirectory, "supervisor");
|
|
11399
11578
|
}
|
|
11400
11579
|
function supervisorConfigPath(store) {
|
|
11401
|
-
return (0,
|
|
11580
|
+
return (0, import_node_path11.join)(supervisorDirectory(store), "supervisord.conf");
|
|
11402
11581
|
}
|
|
11403
11582
|
function supervisorSocketPath(store) {
|
|
11404
|
-
return (0,
|
|
11583
|
+
return (0, import_node_path11.join)(supervisorDirectory(store), "supervisor.sock");
|
|
11405
11584
|
}
|
|
11406
11585
|
function supervisorPidPath(store) {
|
|
11407
|
-
return (0,
|
|
11586
|
+
return (0, import_node_path11.join)(supervisorDirectory(store), "supervisord.pid");
|
|
11408
11587
|
}
|
|
11409
11588
|
function supervisorLogPath(store) {
|
|
11410
|
-
return (0,
|
|
11589
|
+
return (0, import_node_path11.join)(supervisorDirectory(store), "supervisord.log");
|
|
11411
11590
|
}
|
|
11412
11591
|
async function commandSucceeds(runtime, command, argumentsList) {
|
|
11413
11592
|
try {
|
|
@@ -11429,13 +11608,6 @@ async function runCommandIgnoringFailure(runtime, command, argumentsList) {
|
|
|
11429
11608
|
return;
|
|
11430
11609
|
}
|
|
11431
11610
|
}
|
|
11432
|
-
async function uninstallManagerIgnoringFailure(manager, store, runtime) {
|
|
11433
|
-
try {
|
|
11434
|
-
await uninstallManager(manager, store, runtime);
|
|
11435
|
-
} catch {
|
|
11436
|
-
return;
|
|
11437
|
-
}
|
|
11438
|
-
}
|
|
11439
11611
|
function escapeXml(value) {
|
|
11440
11612
|
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """);
|
|
11441
11613
|
}
|
|
@@ -11474,15 +11646,15 @@ function serviceManagerCurrentTime(runtime) {
|
|
|
11474
11646
|
async function serviceManagerDelay(runtime, milliseconds) {
|
|
11475
11647
|
await (runtime.delay?.(milliseconds) ?? delay5(milliseconds));
|
|
11476
11648
|
}
|
|
11477
|
-
var import_node_child_process5,
|
|
11649
|
+
var import_node_child_process5, import_promises13, import_node_os7, import_node_path11, import_node_util2, execFileAsync, launchAgentLabel, serviceManagerProbeTimeoutMilliseconds, serviceManagerMutationTimeoutMilliseconds, supervisorProgramName, supervisorControlTimeoutMilliseconds, supervisorProgramStartSeconds, supervisorProgramStartRetries, supervisorProgramStopWaitSeconds, supervisorLifecycleBufferMilliseconds, supervisorExitTimeoutMilliseconds, supervisorProgramStartTimeoutMilliseconds, ServiceManagerPreference, UserServiceManager, defaultServiceManagerRuntime;
|
|
11478
11650
|
var init_service_manager = __esm({
|
|
11479
11651
|
"../machine-connector/dist/runtime/service-manager.js"() {
|
|
11480
11652
|
"use strict";
|
|
11481
11653
|
init_cjs_shims();
|
|
11482
11654
|
import_node_child_process5 = require("child_process");
|
|
11483
|
-
|
|
11655
|
+
import_promises13 = require("fs/promises");
|
|
11484
11656
|
import_node_os7 = require("os");
|
|
11485
|
-
|
|
11657
|
+
import_node_path11 = require("path");
|
|
11486
11658
|
import_node_util2 = require("util");
|
|
11487
11659
|
init_runtime_types();
|
|
11488
11660
|
init_shell_environment();
|
|
@@ -11547,8 +11719,9 @@ async function reconcileManagedDaemon(options, store = new MachineRuntimeStore()
|
|
|
11547
11719
|
if (await recordedServiceDesiredState(store) === ManagedServiceDesiredState.Stopped) {
|
|
11548
11720
|
return { manager, outcome: DaemonReconcileOutcome.Skipped };
|
|
11549
11721
|
}
|
|
11722
|
+
const configuredConnectionIds = (await store.listConnections()).map((connection) => connection.connectionId);
|
|
11550
11723
|
const initial = await reachableRuntimeStatus(store);
|
|
11551
|
-
if (initial?.cliVersion === options.cliVersion) {
|
|
11724
|
+
if (initial?.cliVersion === options.cliVersion && runtimeHasConnections(initial, configuredConnectionIds)) {
|
|
11552
11725
|
return { manager, outcome: DaemonReconcileOutcome.Skipped };
|
|
11553
11726
|
}
|
|
11554
11727
|
if (initial) {
|
|
@@ -11556,16 +11729,16 @@ async function reconcileManagedDaemon(options, store = new MachineRuntimeStore()
|
|
|
11556
11729
|
try {
|
|
11557
11730
|
managerOwnsProcess = await managedServiceOwnsProcess(manager, initial.pid, store);
|
|
11558
11731
|
} catch (error) {
|
|
11559
|
-
throw new DaemonRefreshError(
|
|
11732
|
+
throw new DaemonRefreshError(DaemonRefreshStage.Ownership, `could not verify that the reachable Connector belongs to ${manager}: ${errorMessage4(error)}`, { cause: error });
|
|
11560
11733
|
}
|
|
11561
11734
|
if (!managerOwnsProcess) {
|
|
11562
|
-
|
|
11735
|
+
throw new DaemonRefreshError(DaemonRefreshStage.Ownership, `${manager} does not own reachable daemon PID ${initial.pid}; stop that foreground or orphaned daemon before restarting the managed Connector`);
|
|
11563
11736
|
}
|
|
11564
11737
|
}
|
|
11565
11738
|
try {
|
|
11566
11739
|
await validateCliEntrypoint(options, store);
|
|
11567
11740
|
} catch (error) {
|
|
11568
|
-
throw new DaemonRefreshError(
|
|
11741
|
+
throw new DaemonRefreshError(DaemonRefreshStage.Validation, errorMessage4(error), {
|
|
11569
11742
|
cause: error
|
|
11570
11743
|
});
|
|
11571
11744
|
}
|
|
@@ -11576,44 +11749,48 @@ async function reconcileManagedDaemon(options, store = new MachineRuntimeStore()
|
|
|
11576
11749
|
try {
|
|
11577
11750
|
refresh = await refreshManagedUserService(store, {
|
|
11578
11751
|
commandArguments: [...options.commandArguments],
|
|
11579
|
-
entrypointPath: (0,
|
|
11752
|
+
entrypointPath: (0, import_node_path12.resolve)(options.entrypointPath),
|
|
11580
11753
|
environment: { ...options.environment },
|
|
11581
|
-
nodePath: (0,
|
|
11754
|
+
nodePath: (0, import_node_path12.resolve)(options.nodePath)
|
|
11582
11755
|
});
|
|
11583
11756
|
if (!refresh) {
|
|
11584
11757
|
throw new Error("The Connector service is no longer managed by Moxt");
|
|
11585
11758
|
}
|
|
11586
11759
|
} catch (error) {
|
|
11587
|
-
throw new DaemonRefreshError(
|
|
11760
|
+
throw new DaemonRefreshError(DaemonRefreshStage.Restart, error instanceof Error ? error.message : String(error), { cause: error });
|
|
11588
11761
|
}
|
|
11589
11762
|
const deadline = Date.now() + reconcileTimeoutMilliseconds;
|
|
11590
11763
|
while (Date.now() < deadline) {
|
|
11591
11764
|
const current2 = await reachableRuntimeStatus(store);
|
|
11592
|
-
if (current2?.cliVersion === options.cliVersion && current2.connectorInstanceId !== initial?.connectorInstanceId) {
|
|
11765
|
+
if (current2?.cliVersion === options.cliVersion && current2.connectorInstanceId !== initial?.connectorInstanceId && runtimeHasConnections(current2, configuredConnectionIds)) {
|
|
11593
11766
|
return { manager, outcome: DaemonReconcileOutcome.Restarted };
|
|
11594
11767
|
}
|
|
11595
11768
|
await delay6(100);
|
|
11596
11769
|
}
|
|
11597
|
-
const verificationMessage = initial ? `managed daemon did not report CLI ${options.cliVersion} with a new instance ID` : `managed daemon did not become reachable with CLI ${options.cliVersion}`;
|
|
11770
|
+
const verificationMessage = initial ? `managed daemon did not report CLI ${options.cliVersion} with a new instance ID and all configured connections` : `managed daemon did not become reachable with CLI ${options.cliVersion} and all configured connections`;
|
|
11598
11771
|
try {
|
|
11599
11772
|
await refresh.rollback();
|
|
11600
11773
|
} catch (error) {
|
|
11601
|
-
throw new DaemonRefreshError(
|
|
11774
|
+
throw new DaemonRefreshError(DaemonRefreshStage.Verification, `${verificationMessage}; restoring the previous service definition also failed: ${errorMessage4(error)}`, { cause: error });
|
|
11602
11775
|
}
|
|
11603
|
-
throw new DaemonRefreshError(
|
|
11776
|
+
throw new DaemonRefreshError(DaemonRefreshStage.Verification, verificationMessage);
|
|
11604
11777
|
} finally {
|
|
11605
11778
|
await lock.release();
|
|
11606
11779
|
}
|
|
11607
11780
|
}
|
|
11781
|
+
function runtimeHasConnections(status, connectionIds) {
|
|
11782
|
+
const runtimeConnectionIds = new Set(status.connections.map((connection) => connection.connectionId));
|
|
11783
|
+
return connectionIds.every((connectionId) => runtimeConnectionIds.has(connectionId));
|
|
11784
|
+
}
|
|
11608
11785
|
async function validateCliEntrypoint(options, store) {
|
|
11609
11786
|
await assertManagedServiceProvenance(store, options.entrypointPath);
|
|
11610
11787
|
if (options.commandArguments.length !== 2 || options.commandArguments[0] !== "machine" || options.commandArguments[1] !== "daemon") {
|
|
11611
11788
|
throw new Error("The managed daemon command must be `machine daemon`");
|
|
11612
11789
|
}
|
|
11613
|
-
const nodePath = await (0,
|
|
11614
|
-
const entrypointPath = await (0,
|
|
11615
|
-
await (0,
|
|
11616
|
-
await (0,
|
|
11790
|
+
const nodePath = await (0, import_promises14.realpath)((0, import_node_path12.resolve)(options.nodePath));
|
|
11791
|
+
const entrypointPath = await (0, import_promises14.realpath)((0, import_node_path12.resolve)(options.entrypointPath));
|
|
11792
|
+
await (0, import_promises14.access)(nodePath, import_promises14.constants.X_OK);
|
|
11793
|
+
await (0, import_promises14.access)(entrypointPath, import_promises14.constants.R_OK);
|
|
11617
11794
|
const probe = await execFileAsync2(nodePath, [entrypointPath, "--version"], {
|
|
11618
11795
|
encoding: "utf8",
|
|
11619
11796
|
env: {
|
|
@@ -11646,14 +11823,14 @@ function delay6(milliseconds) {
|
|
|
11646
11823
|
function errorMessage4(error) {
|
|
11647
11824
|
return error instanceof Error ? error.message : String(error);
|
|
11648
11825
|
}
|
|
11649
|
-
var import_node_child_process6,
|
|
11826
|
+
var import_node_child_process6, import_promises14, import_node_path12, import_node_util3, reconcileTimeoutMilliseconds, execFileAsync2, DaemonReconcileOutcome, DaemonRefreshStage, DaemonRefreshError;
|
|
11650
11827
|
var init_daemon_reconcile = __esm({
|
|
11651
11828
|
"../machine-connector/dist/runtime/daemon-reconcile.js"() {
|
|
11652
11829
|
"use strict";
|
|
11653
11830
|
init_cjs_shims();
|
|
11654
11831
|
import_node_child_process6 = require("child_process");
|
|
11655
|
-
|
|
11656
|
-
|
|
11832
|
+
import_promises14 = require("fs/promises");
|
|
11833
|
+
import_node_path12 = require("path");
|
|
11657
11834
|
import_node_util3 = require("util");
|
|
11658
11835
|
init_local_ipc();
|
|
11659
11836
|
init_process_lock();
|
|
@@ -11666,6 +11843,12 @@ var init_daemon_reconcile = __esm({
|
|
|
11666
11843
|
DaemonReconcileOutcome2["Restarted"] = "restarted";
|
|
11667
11844
|
DaemonReconcileOutcome2["Skipped"] = "skipped";
|
|
11668
11845
|
})(DaemonReconcileOutcome || (DaemonReconcileOutcome = {}));
|
|
11846
|
+
(function(DaemonRefreshStage2) {
|
|
11847
|
+
DaemonRefreshStage2["Ownership"] = "ownership";
|
|
11848
|
+
DaemonRefreshStage2["Restart"] = "restart";
|
|
11849
|
+
DaemonRefreshStage2["Validation"] = "validation";
|
|
11850
|
+
DaemonRefreshStage2["Verification"] = "verification";
|
|
11851
|
+
})(DaemonRefreshStage || (DaemonRefreshStage = {}));
|
|
11669
11852
|
DaemonRefreshError = class extends Error {
|
|
11670
11853
|
stage;
|
|
11671
11854
|
constructor(stage, message, options) {
|
|
@@ -11710,7 +11893,7 @@ async function runMachineDoctor(store) {
|
|
|
11710
11893
|
}
|
|
11711
11894
|
for (const connection of connections) {
|
|
11712
11895
|
try {
|
|
11713
|
-
await (0,
|
|
11896
|
+
await (0, import_promises15.access)(connection.rootPath, import_node_fs.constants.R_OK | import_node_fs.constants.X_OK);
|
|
11714
11897
|
checks.push({
|
|
11715
11898
|
detail: connection.rootPath,
|
|
11716
11899
|
name: `root:${connection.connectionId}`,
|
|
@@ -11725,7 +11908,7 @@ async function runMachineDoctor(store) {
|
|
|
11725
11908
|
}
|
|
11726
11909
|
const relayUrl = new URL(connection.relayOrigin);
|
|
11727
11910
|
try {
|
|
11728
|
-
const address = await (0,
|
|
11911
|
+
const address = await (0, import_promises16.lookup)(relayUrl.hostname);
|
|
11729
11912
|
checks.push({
|
|
11730
11913
|
detail: `${relayUrl.hostname} resolves to ${address.address}`,
|
|
11731
11914
|
name: `dns:${connection.connectionId}`,
|
|
@@ -11807,15 +11990,15 @@ async function runMachineDoctor(store) {
|
|
|
11807
11990
|
function errorMessage5(error) {
|
|
11808
11991
|
return error instanceof Error ? error.message : String(error);
|
|
11809
11992
|
}
|
|
11810
|
-
var import_node_child_process7,
|
|
11993
|
+
var import_node_child_process7, import_promises15, import_node_fs, import_promises16, import_node_util4, execFileAsync3, DoctorCheckStatus;
|
|
11811
11994
|
var init_doctor = __esm({
|
|
11812
11995
|
"../machine-connector/dist/runtime/doctor.js"() {
|
|
11813
11996
|
"use strict";
|
|
11814
11997
|
init_cjs_shims();
|
|
11815
11998
|
import_node_child_process7 = require("child_process");
|
|
11816
|
-
|
|
11999
|
+
import_promises15 = require("fs/promises");
|
|
11817
12000
|
import_node_fs = require("fs");
|
|
11818
|
-
|
|
12001
|
+
import_promises16 = require("dns/promises");
|
|
11819
12002
|
import_node_util4 = require("util");
|
|
11820
12003
|
init_local_ipc();
|
|
11821
12004
|
execFileAsync3 = (0, import_node_util4.promisify)(import_node_child_process7.execFile);
|
|
@@ -12085,7 +12268,7 @@ async function readRecentLogLines(store) {
|
|
|
12085
12268
|
}
|
|
12086
12269
|
async function readOptionalFile(path4) {
|
|
12087
12270
|
try {
|
|
12088
|
-
return await (0,
|
|
12271
|
+
return await (0, import_promises17.readFile)(path4, "utf8");
|
|
12089
12272
|
} catch (error) {
|
|
12090
12273
|
if (isMissingFile(error)) {
|
|
12091
12274
|
return "";
|
|
@@ -12144,13 +12327,13 @@ function isMissingFile(error) {
|
|
|
12144
12327
|
function errorMessage6(error) {
|
|
12145
12328
|
return error instanceof Error ? error.message : String(error);
|
|
12146
12329
|
}
|
|
12147
|
-
var
|
|
12330
|
+
var import_promises17, import_promises18, import_node_readline, alternateScreenEnter, alternateScreenExit, clearScreen, cursorHide, cursorShow, styleReset, styleHeader, styleSelected, refreshIntervalMilliseconds, maximumLogLines, MachineManagerView, MachineManagerAction, MachineManagerSnapshotDepth, InteractiveMachineManager;
|
|
12148
12331
|
var init_machine_manager = __esm({
|
|
12149
12332
|
"../machine-connector/dist/runtime/machine-manager.js"() {
|
|
12150
12333
|
"use strict";
|
|
12151
12334
|
init_cjs_shims();
|
|
12152
|
-
|
|
12153
|
-
|
|
12335
|
+
import_promises17 = require("fs/promises");
|
|
12336
|
+
import_promises18 = require("readline/promises");
|
|
12154
12337
|
import_node_readline = require("readline");
|
|
12155
12338
|
init_doctor();
|
|
12156
12339
|
init_local_ipc();
|
|
@@ -12384,7 +12567,7 @@ var init_machine_manager = __esm({
|
|
|
12384
12567
|
}
|
|
12385
12568
|
async runCommandAction(action) {
|
|
12386
12569
|
this.suspendTerminal();
|
|
12387
|
-
const reader = (0,
|
|
12570
|
+
const reader = (0, import_promises18.createInterface)({
|
|
12388
12571
|
input: process.stdin,
|
|
12389
12572
|
output: process.stdout
|
|
12390
12573
|
});
|
|
@@ -12625,7 +12808,7 @@ async function pairMachine(store, options) {
|
|
|
12625
12808
|
throw new Error("Local Machine pairing expired");
|
|
12626
12809
|
}
|
|
12627
12810
|
function displayNameForRoot(canonicalRoot) {
|
|
12628
|
-
const name = (0,
|
|
12811
|
+
const name = (0, import_node_path13.basename)(canonicalRoot);
|
|
12629
12812
|
return name.length > 0 ? name : canonicalRoot;
|
|
12630
12813
|
}
|
|
12631
12814
|
function getOperatingSystem() {
|
|
@@ -12647,7 +12830,7 @@ function delay7(milliseconds) {
|
|
|
12647
12830
|
setTimeout(resolvePromise, milliseconds);
|
|
12648
12831
|
});
|
|
12649
12832
|
}
|
|
12650
|
-
var import_node_child_process8, import_node_crypto11, import_node_os8,
|
|
12833
|
+
var import_node_child_process8, import_node_crypto11, import_node_os8, import_node_path13, connectedPairingStatus, rejectedPairingStatus, expiredPairingStatus, pairingPollMilliseconds;
|
|
12651
12834
|
var init_pairing = __esm({
|
|
12652
12835
|
"../machine-connector/dist/runtime/pairing.js"() {
|
|
12653
12836
|
"use strict";
|
|
@@ -12655,7 +12838,7 @@ var init_pairing = __esm({
|
|
|
12655
12838
|
import_node_child_process8 = require("child_process");
|
|
12656
12839
|
import_node_crypto11 = require("crypto");
|
|
12657
12840
|
import_node_os8 = require("os");
|
|
12658
|
-
|
|
12841
|
+
import_node_path13 = require("path");
|
|
12659
12842
|
init_contracts();
|
|
12660
12843
|
init_version();
|
|
12661
12844
|
init_enums();
|
|
@@ -12743,9 +12926,10 @@ function isMachineLifecycleMutation(command, commandArguments) {
|
|
|
12743
12926
|
async function connectCommand(store, argumentsList, entrypoint) {
|
|
12744
12927
|
const options = parseOptions(argumentsList);
|
|
12745
12928
|
const connectionCode = requiredOption(options, "code");
|
|
12746
|
-
const rootPath = (0,
|
|
12929
|
+
const rootPath = (0, import_node_path14.resolve)(options.root ?? process.cwd());
|
|
12747
12930
|
const serviceManagerPreference = requestedServiceManagerPreference(options);
|
|
12748
12931
|
await validateExplicitServiceManagerPreference(serviceManagerPreference);
|
|
12932
|
+
await assertConnectionRuntimeCanConverge(store, serviceManagerPreference);
|
|
12749
12933
|
writeLine("Internal Full Host Access: enabled");
|
|
12750
12934
|
writeLine(`Working root: ${rootPath}`);
|
|
12751
12935
|
const result = await pairMachine(store, {
|
|
@@ -12771,13 +12955,22 @@ async function connectCommand(store, argumentsList, entrypoint) {
|
|
|
12771
12955
|
if (service.installed) {
|
|
12772
12956
|
writeLine(`Service manager: ${service.manager}`);
|
|
12773
12957
|
try {
|
|
12774
|
-
await
|
|
12958
|
+
await waitForConnectedManagedDaemon(store, {
|
|
12959
|
+
cliVersion: entrypoint.cliVersion,
|
|
12960
|
+
connectionId: result.connection.connectionId,
|
|
12961
|
+
manager: service.manager,
|
|
12962
|
+
timeoutMilliseconds: entrypoint.serviceReadyTimeoutMilliseconds ?? 3e4
|
|
12963
|
+
});
|
|
12775
12964
|
writeLine("Moxt Machine Connector is online.");
|
|
12776
12965
|
} catch (error) {
|
|
12777
12966
|
if (serviceManagerPreference !== ServiceManagerPreference.Auto) {
|
|
12778
12967
|
throw error;
|
|
12779
12968
|
}
|
|
12780
12969
|
await uninstallUserService(store);
|
|
12970
|
+
const remainingRuntime = await reachableRuntimeStatus2(store);
|
|
12971
|
+
if (remainingRuntime) {
|
|
12972
|
+
throw new Error(`Automatic ${service.manager} setup did not converge the paired connection and daemon PID ${remainingRuntime.pid} is still running. Stop that foreground or orphaned daemon, then run \`moxt machine service install\`.`, { cause: error });
|
|
12973
|
+
}
|
|
12781
12974
|
await installUserService(store, {
|
|
12782
12975
|
options: {
|
|
12783
12976
|
commandArguments: entrypoint.commandArguments,
|
|
@@ -12793,6 +12986,10 @@ async function connectCommand(store, argumentsList, entrypoint) {
|
|
|
12793
12986
|
writeLine(" moxt machine daemon");
|
|
12794
12987
|
}
|
|
12795
12988
|
} else {
|
|
12989
|
+
const remainingRuntime = await reachableRuntimeStatus2(store);
|
|
12990
|
+
if (remainingRuntime && !remainingRuntime.connections.some((connection) => connection.connectionId === result.connection.connectionId)) {
|
|
12991
|
+
throw new Error(`Background service setup did not converge the paired connection and daemon PID ${remainingRuntime.pid} is still running without it. Stop that daemon, then run \`moxt machine service install\` or \`moxt machine daemon\`.`);
|
|
12992
|
+
}
|
|
12796
12993
|
writeLine(service.detail);
|
|
12797
12994
|
writeLine("Run manually:");
|
|
12798
12995
|
writeLine(" moxt machine daemon");
|
|
@@ -13013,23 +13210,75 @@ function requireInstalledServiceManager(manager) {
|
|
|
13013
13210
|
throw new Error("No background Connector service is installed. Run `moxt machine service install` or `moxt machine daemon`.");
|
|
13014
13211
|
}
|
|
13015
13212
|
}
|
|
13016
|
-
async function
|
|
13017
|
-
|
|
13213
|
+
async function assertConnectionRuntimeCanConverge(store, preference) {
|
|
13214
|
+
let status;
|
|
13215
|
+
try {
|
|
13216
|
+
status = (await requestRuntimeStatus(store)).status;
|
|
13217
|
+
} catch {
|
|
13218
|
+
return;
|
|
13219
|
+
}
|
|
13220
|
+
if (!status)
|
|
13221
|
+
return;
|
|
13222
|
+
if (preference === ServiceManagerPreference.None) {
|
|
13223
|
+
throw new Error(`Running Connector daemon PID ${status.pid} cannot safely load a newly paired connection without a restart. Stop it and retry pairing, then run \`moxt machine daemon\`.`);
|
|
13224
|
+
}
|
|
13225
|
+
const manager = await recordedServiceManager(store);
|
|
13226
|
+
if (manager === UserServiceManager.None) {
|
|
13227
|
+
throw new Error(`Running Connector daemon PID ${status.pid} cannot safely load a newly paired connection because it is not managed by a background service. Stop it and retry pairing.`);
|
|
13228
|
+
}
|
|
13229
|
+
let managerOwnsProcess;
|
|
13230
|
+
try {
|
|
13231
|
+
managerOwnsProcess = await managedServiceOwnsProcess(manager, status.pid, store);
|
|
13232
|
+
} catch (error) {
|
|
13233
|
+
throw new Error(`Running Connector daemon PID ${status.pid} cannot safely load a newly paired connection because ${manager} ownership could not be verified: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
13234
|
+
}
|
|
13235
|
+
if (!managerOwnsProcess) {
|
|
13236
|
+
throw new Error(`Running Connector daemon PID ${status.pid} cannot safely load a newly paired connection because ${manager} does not own it. Stop the foreground or orphaned daemon and retry pairing.`);
|
|
13237
|
+
}
|
|
13238
|
+
}
|
|
13239
|
+
async function waitForConnectedManagedDaemon(store, expectation) {
|
|
13240
|
+
const deadline = Date.now() + expectation.timeoutMilliseconds;
|
|
13241
|
+
let lastObservation = "the Connector did not answer its local status socket";
|
|
13018
13242
|
while (Date.now() < deadline) {
|
|
13019
13243
|
try {
|
|
13020
13244
|
const response = await requestRuntimeStatus(store);
|
|
13021
|
-
|
|
13245
|
+
const status = response.status;
|
|
13246
|
+
if (!status) {
|
|
13247
|
+
lastObservation = "the Connector returned no runtime status";
|
|
13248
|
+
await delay8(500);
|
|
13249
|
+
continue;
|
|
13250
|
+
}
|
|
13251
|
+
if (expectation.cliVersion && status.cliVersion !== expectation.cliVersion) {
|
|
13252
|
+
lastObservation = `the reachable daemon reports CLI ${status.cliVersion ?? "unknown"} instead of ${expectation.cliVersion}`;
|
|
13253
|
+
await delay8(500);
|
|
13254
|
+
continue;
|
|
13255
|
+
}
|
|
13256
|
+
if (!status.connections.some((connection) => connection.connectionId === expectation.connectionId)) {
|
|
13257
|
+
lastObservation = `the reachable daemon has not loaded connection ${expectation.connectionId}`;
|
|
13258
|
+
await delay8(500);
|
|
13259
|
+
continue;
|
|
13260
|
+
}
|
|
13261
|
+
if (await managedServiceOwnsProcess(expectation.manager, status.pid, store)) {
|
|
13022
13262
|
return;
|
|
13023
13263
|
}
|
|
13024
|
-
|
|
13025
|
-
|
|
13264
|
+
lastObservation = `${expectation.manager} does not own reachable daemon PID ${status.pid}`;
|
|
13265
|
+
} catch (error) {
|
|
13266
|
+
lastObservation = error instanceof Error ? error.message : String(error);
|
|
13026
13267
|
}
|
|
13268
|
+
await delay8(500);
|
|
13269
|
+
}
|
|
13270
|
+
throw new Error(`The service was installed but the paired connection did not converge on the managed Connector within ${expectation.timeoutMilliseconds / 1e3} seconds: ${lastObservation}`);
|
|
13271
|
+
}
|
|
13272
|
+
async function reachableRuntimeStatus2(store) {
|
|
13273
|
+
try {
|
|
13274
|
+
return (await requestRuntimeStatus(store)).status;
|
|
13275
|
+
} catch {
|
|
13276
|
+
return void 0;
|
|
13027
13277
|
}
|
|
13028
|
-
throw new Error("The service was installed but the Connector did not become online within 30 seconds");
|
|
13029
13278
|
}
|
|
13030
13279
|
async function readOptionalFile2(path4) {
|
|
13031
13280
|
try {
|
|
13032
|
-
return await (0,
|
|
13281
|
+
return await (0, import_promises19.readFile)(path4, "utf8");
|
|
13033
13282
|
} catch {
|
|
13034
13283
|
return "";
|
|
13035
13284
|
}
|
|
@@ -13058,13 +13307,13 @@ function delay8(milliseconds) {
|
|
|
13058
13307
|
setTimeout(resolvePromise, milliseconds);
|
|
13059
13308
|
});
|
|
13060
13309
|
}
|
|
13061
|
-
var
|
|
13310
|
+
var import_promises19, import_node_path14, defaultRelayOrigin;
|
|
13062
13311
|
var init_cli = __esm({
|
|
13063
13312
|
"../machine-connector/dist/cli.js"() {
|
|
13064
13313
|
"use strict";
|
|
13065
13314
|
init_cjs_shims();
|
|
13066
|
-
|
|
13067
|
-
|
|
13315
|
+
import_promises19 = require("fs/promises");
|
|
13316
|
+
import_node_path14 = require("path");
|
|
13068
13317
|
init_daemon();
|
|
13069
13318
|
init_daemon_reconcile();
|
|
13070
13319
|
init_doctor();
|
|
@@ -13084,6 +13333,7 @@ var dist_exports = {};
|
|
|
13084
13333
|
__export(dist_exports, {
|
|
13085
13334
|
DaemonReconcileOutcome: () => DaemonReconcileOutcome,
|
|
13086
13335
|
DaemonRefreshError: () => DaemonRefreshError,
|
|
13336
|
+
DaemonRefreshStage: () => DaemonRefreshStage,
|
|
13087
13337
|
DoctorCheckStatus: () => DoctorCheckStatus,
|
|
13088
13338
|
LocalIpcServer: () => LocalIpcServer,
|
|
13089
13339
|
MachineClaudePermissionMode: () => MachineClaudePermissionMode,
|
|
@@ -13358,7 +13608,7 @@ function getApiKeyOrUndefined() {
|
|
|
13358
13608
|
|
|
13359
13609
|
// src/utils/http.ts
|
|
13360
13610
|
function getUserAgent() {
|
|
13361
|
-
return `moxt-cli/${"0.10.0-beta.
|
|
13611
|
+
return `moxt-cli/${"0.10.0-beta.5"} (${(0, import_os.platform)()}/${(0, import_os.arch)()}) node/${process.versions.node}`;
|
|
13362
13612
|
}
|
|
13363
13613
|
async function sendRequest(method, path4, init) {
|
|
13364
13614
|
return await fetch(`${getApiBaseUrl()}${path4}`, {
|
|
@@ -26941,7 +27191,7 @@ var FLUSH_TIMEOUT_MS = 3e3;
|
|
|
26941
27191
|
var MAX_BATCH_SIZE = 100;
|
|
26942
27192
|
function commonLabels() {
|
|
26943
27193
|
return {
|
|
26944
|
-
cli_version: "0.10.0-beta.
|
|
27194
|
+
cli_version: "0.10.0-beta.5",
|
|
26945
27195
|
node_version: process.versions.node,
|
|
26946
27196
|
os: (0, import_node_os9.platform)(),
|
|
26947
27197
|
arch: (0, import_node_os9.arch)(),
|
|
@@ -26987,7 +27237,7 @@ async function flush() {
|
|
|
26987
27237
|
}
|
|
26988
27238
|
const batch = buffer.splice(0, MAX_BATCH_SIZE);
|
|
26989
27239
|
const payload = {
|
|
26990
|
-
release_id: "0.10.0-beta.
|
|
27240
|
+
release_id: "0.10.0-beta.5",
|
|
26991
27241
|
client_type: "cli",
|
|
26992
27242
|
metric_data_list: batch.map((m) => ({
|
|
26993
27243
|
profile: "cli",
|
|
@@ -27188,7 +27438,7 @@ function registryWorker() {
|
|
|
27188
27438
|
|
|
27189
27439
|
// src/update/prompt.ts
|
|
27190
27440
|
init_cjs_shims();
|
|
27191
|
-
var
|
|
27441
|
+
var import_promises20 = require("readline/promises");
|
|
27192
27442
|
async function promptForUpdate(input, output, currentVersion, latestVersion, timeoutMs) {
|
|
27193
27443
|
output.write(`
|
|
27194
27444
|
A new version of Moxt CLI is available: ${currentVersion} \u2192 ${latestVersion}
|
|
@@ -27201,7 +27451,7 @@ A new version of Moxt CLI is available: ${currentVersion} \u2192 ${latestVersion
|
|
|
27201
27451
|
const controller = new AbortController();
|
|
27202
27452
|
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
27203
27453
|
timeout.unref();
|
|
27204
|
-
const readline = (0,
|
|
27454
|
+
const readline = (0, import_promises20.createInterface)({ input, output, terminal: true });
|
|
27205
27455
|
try {
|
|
27206
27456
|
const answer = await readline.question("", { signal: controller.signal });
|
|
27207
27457
|
if (answer.trim() === "1") return "update";
|
|
@@ -27304,7 +27554,7 @@ function commandPath2(command) {
|
|
|
27304
27554
|
|
|
27305
27555
|
// src/update/daemon-reconcile-hook.ts
|
|
27306
27556
|
init_cjs_shims();
|
|
27307
|
-
var
|
|
27557
|
+
var import_node_path15 = require("path");
|
|
27308
27558
|
function installDaemonReconcileHook(program3, cliVersion) {
|
|
27309
27559
|
program3.hook("preAction", async (_thisCommand, actionCommand) => {
|
|
27310
27560
|
if (!isEligible2(actionCommand)) return;
|
|
@@ -27326,9 +27576,9 @@ function installDaemonReconcileHook(program3, cliVersion) {
|
|
|
27326
27576
|
await reconcileManagedDaemon2({
|
|
27327
27577
|
cliVersion,
|
|
27328
27578
|
commandArguments: ["machine", "daemon"],
|
|
27329
|
-
entrypointPath: (0,
|
|
27579
|
+
entrypointPath: (0, import_node_path15.resolve)(entrypointPath),
|
|
27330
27580
|
environment: {},
|
|
27331
|
-
nodePath: (0,
|
|
27581
|
+
nodePath: (0, import_node_path15.resolve)(process.execPath),
|
|
27332
27582
|
onActiveJobs: (count) => {
|
|
27333
27583
|
process.stderr.write(
|
|
27334
27584
|
`Warning: restarting the managed Connector will interrupt ${count} active ${count === 1 ? "Job" : "Jobs"}.
|
|
@@ -27370,9 +27620,9 @@ function commandPath3(command) {
|
|
|
27370
27620
|
}
|
|
27371
27621
|
|
|
27372
27622
|
// src/index.ts
|
|
27373
|
-
var program2 = createProgram("0.10.0-beta.
|
|
27374
|
-
installDaemonReconcileHook(program2, "0.10.0-beta.
|
|
27375
|
-
installUpdateHook(program2, "0.10.0-beta.
|
|
27623
|
+
var program2 = createProgram("0.10.0-beta.5");
|
|
27624
|
+
installDaemonReconcileHook(program2, "0.10.0-beta.5");
|
|
27625
|
+
installUpdateHook(program2, "0.10.0-beta.5");
|
|
27376
27626
|
instrumentProgram(program2);
|
|
27377
27627
|
installExitHandler();
|
|
27378
27628
|
program2.parseAsync(process.argv).then(async () => {
|