@moxt-ai/cli 0.8.0-beta.0 → 0.8.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/dist/index.cjs +1680 -275
- package/dist/index.cjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -551,8 +551,8 @@ var require_graceful_fs = __commonJS({
|
|
|
551
551
|
fs10.createReadStream = createReadStream;
|
|
552
552
|
fs10.createWriteStream = createWriteStream2;
|
|
553
553
|
var fs$readFile = fs10.readFile;
|
|
554
|
-
fs10.readFile =
|
|
555
|
-
function
|
|
554
|
+
fs10.readFile = readFile6;
|
|
555
|
+
function readFile6(path10, options, cb) {
|
|
556
556
|
if (typeof options === "function")
|
|
557
557
|
cb = options, options = null;
|
|
558
558
|
return go$readFile(path10, options, cb);
|
|
@@ -2550,8 +2550,8 @@ var require_graceful_fs2 = __commonJS({
|
|
|
2550
2550
|
fs10.createReadStream = createReadStream;
|
|
2551
2551
|
fs10.createWriteStream = createWriteStream2;
|
|
2552
2552
|
var fs$readFile = fs10.readFile;
|
|
2553
|
-
fs10.readFile =
|
|
2554
|
-
function
|
|
2553
|
+
fs10.readFile = readFile6;
|
|
2554
|
+
function readFile6(path10, options, cb) {
|
|
2555
2555
|
if (typeof options === "function")
|
|
2556
2556
|
cb = options, options = null;
|
|
2557
2557
|
return go$readFile(path10, options, cb);
|
|
@@ -5884,14 +5884,14 @@ var require_string_width = __commonJS({
|
|
|
5884
5884
|
"node_modules/.pnpm/string-width@4.2.3/node_modules/string-width/index.js"(exports2, module2) {
|
|
5885
5885
|
"use strict";
|
|
5886
5886
|
init_cjs_shims();
|
|
5887
|
-
var
|
|
5887
|
+
var stripAnsi3 = require_strip_ansi();
|
|
5888
5888
|
var isFullwidthCodePoint = require_is_fullwidth_code_point();
|
|
5889
5889
|
var emojiRegex = require_emoji_regex();
|
|
5890
5890
|
var stringWidth2 = (string) => {
|
|
5891
5891
|
if (typeof string !== "string" || string.length === 0) {
|
|
5892
5892
|
return 0;
|
|
5893
5893
|
}
|
|
5894
|
-
string =
|
|
5894
|
+
string = stripAnsi3(string);
|
|
5895
5895
|
if (string.length === 0) {
|
|
5896
5896
|
return 0;
|
|
5897
5897
|
}
|
|
@@ -9421,7 +9421,7 @@ var init_contracts = __esm({
|
|
|
9421
9421
|
});
|
|
9422
9422
|
|
|
9423
9423
|
// ../machine-connector/dist/protocol/v1/enums.js
|
|
9424
|
-
var MachineOperatingSystem, MachineConnectionTargetKind, MachineConnectionStatus, MachinePairingStatus, MachinePairingDecision, MachineJobKind, MachineJobStatus, MachineJobWakeReason, MachineJobEventKind, MachineJobOutputStream, MachineControlCommandKind, MachineCodexPermissionMode, MachineProtocolErrorCode;
|
|
9424
|
+
var MachineOperatingSystem, MachineConnectionTargetKind, MachineConnectionStatus, MachinePairingStatus, MachinePairingDecision, MachineJobKind, MachineJobStatus, MachineJobWakeReason, MachineJobEventKind, MachineJobOutputStream, MachineControlCommandKind, MachineCodexPermissionMode, MachineClaudePermissionMode, MachineProtocolErrorCode;
|
|
9425
9425
|
var init_enums = __esm({
|
|
9426
9426
|
"../machine-connector/dist/protocol/v1/enums.js"() {
|
|
9427
9427
|
"use strict";
|
|
@@ -9452,9 +9452,12 @@ var init_enums = __esm({
|
|
|
9452
9452
|
MachinePairingDecision2["Reject"] = "reject";
|
|
9453
9453
|
})(MachinePairingDecision || (MachinePairingDecision = {}));
|
|
9454
9454
|
(function(MachineJobKind2) {
|
|
9455
|
+
MachineJobKind2["ClaudeReply"] = "claude_reply";
|
|
9456
|
+
MachineJobKind2["ClaudeStart"] = "claude_start";
|
|
9455
9457
|
MachineJobKind2["CodexReply"] = "codex_reply";
|
|
9456
9458
|
MachineJobKind2["CodexStart"] = "codex_start";
|
|
9457
9459
|
MachineJobKind2["Command"] = "command";
|
|
9460
|
+
MachineJobKind2["ViewImage"] = "view_image";
|
|
9458
9461
|
})(MachineJobKind || (MachineJobKind = {}));
|
|
9459
9462
|
(function(MachineJobStatus2) {
|
|
9460
9463
|
MachineJobStatus2["Cancelled"] = "cancelled";
|
|
@@ -9493,6 +9496,9 @@ var init_enums = __esm({
|
|
|
9493
9496
|
(function(MachineCodexPermissionMode2) {
|
|
9494
9497
|
MachineCodexPermissionMode2["FullAccess"] = "full_access";
|
|
9495
9498
|
})(MachineCodexPermissionMode || (MachineCodexPermissionMode = {}));
|
|
9499
|
+
(function(MachineClaudePermissionMode2) {
|
|
9500
|
+
MachineClaudePermissionMode2["FullAccess"] = "full_access";
|
|
9501
|
+
})(MachineClaudePermissionMode || (MachineClaudePermissionMode = {}));
|
|
9496
9502
|
(function(MachineProtocolErrorCode2) {
|
|
9497
9503
|
MachineProtocolErrorCode2["BadProtocolVersion"] = "bad_protocol_version";
|
|
9498
9504
|
MachineProtocolErrorCode2["BindingMismatch"] = "binding_mismatch";
|
|
@@ -9672,6 +9678,12 @@ async function executeCommand(rootPath, spec, callbacks) {
|
|
|
9672
9678
|
return await executeProcess(spec.executable, spec.arguments, workingDirectory, spec.environment, spec.stdin, spec.timeoutSeconds, callbacks);
|
|
9673
9679
|
}
|
|
9674
9680
|
async function executeProcess(executable, argumentsList, workingDirectory, environment, stdin, timeoutSeconds, callbacks) {
|
|
9681
|
+
if (callbacks.canSpawn && !callbacks.canSpawn()) {
|
|
9682
|
+
return {
|
|
9683
|
+
exitCode: -1,
|
|
9684
|
+
status: MachineJobStatus.Cancelled
|
|
9685
|
+
};
|
|
9686
|
+
}
|
|
9675
9687
|
const child = (0, import_node_child_process2.spawn)(executable, argumentsList, {
|
|
9676
9688
|
cwd: workingDirectory,
|
|
9677
9689
|
detached: (0, import_node_os4.platform)() !== "win32",
|
|
@@ -9731,9 +9743,31 @@ async function executeProcess(executable, argumentsList, workingDirectory, envir
|
|
|
9731
9743
|
void handle.cancel();
|
|
9732
9744
|
}, timeoutSeconds * 1e3);
|
|
9733
9745
|
timeout2.unref();
|
|
9734
|
-
const
|
|
9746
|
+
const completion = processExitPromise.then(async (processExit2) => {
|
|
9747
|
+
await outputWrites;
|
|
9748
|
+
return {
|
|
9749
|
+
kind: "process_exit",
|
|
9750
|
+
processExit: processExit2
|
|
9751
|
+
};
|
|
9752
|
+
});
|
|
9753
|
+
const cancellation = handle.waitForCancellation().then(() => ({
|
|
9754
|
+
kind: "cancellation_deadline"
|
|
9755
|
+
}));
|
|
9756
|
+
const outcome = await Promise.race([completion, cancellation]);
|
|
9735
9757
|
clearTimeout(timeout2);
|
|
9736
|
-
|
|
9758
|
+
if (outcome.kind === "cancellation_deadline") {
|
|
9759
|
+
void outputWrites.catch(() => void 0);
|
|
9760
|
+
return timedOut ? {
|
|
9761
|
+
exitCode: -1,
|
|
9762
|
+
failureCode: "timeout",
|
|
9763
|
+
failureMessage: `Process exceeded ${timeoutSeconds} seconds`,
|
|
9764
|
+
status: MachineJobStatus.Failed
|
|
9765
|
+
} : {
|
|
9766
|
+
exitCode: -1,
|
|
9767
|
+
status: MachineJobStatus.Cancelled
|
|
9768
|
+
};
|
|
9769
|
+
}
|
|
9770
|
+
const { processExit } = outcome;
|
|
9737
9771
|
if (processExit.spawnError) {
|
|
9738
9772
|
return {
|
|
9739
9773
|
exitCode: -1,
|
|
@@ -9786,7 +9820,10 @@ async function resolveCanonicalWorkingDirectory(rootPath, relativeWorkingDirecto
|
|
|
9786
9820
|
}
|
|
9787
9821
|
async function terminateProcessTree(pid) {
|
|
9788
9822
|
if ((0, import_node_os4.platform)() === "win32") {
|
|
9789
|
-
const process11 = (0, import_node_child_process2.spawn)("taskkill", ["/pid", String(pid), "/t", "/f"], {
|
|
9823
|
+
const process11 = (0, import_node_child_process2.spawn)("taskkill", ["/pid", String(pid), "/t", "/f"], {
|
|
9824
|
+
stdio: "ignore",
|
|
9825
|
+
windowsHide: true
|
|
9826
|
+
});
|
|
9790
9827
|
await new Promise((resolvePromise) => {
|
|
9791
9828
|
process11.once("close", () => resolvePromise());
|
|
9792
9829
|
process11.once("error", () => resolvePromise());
|
|
@@ -9801,7 +9838,18 @@ async function terminateProcessTree(pid) {
|
|
|
9801
9838
|
}
|
|
9802
9839
|
return;
|
|
9803
9840
|
}
|
|
9804
|
-
|
|
9841
|
+
const gracefulDeadline = Date.now() + 3e3;
|
|
9842
|
+
while (Date.now() < gracefulDeadline) {
|
|
9843
|
+
try {
|
|
9844
|
+
process.kill(-pid, 0);
|
|
9845
|
+
} catch (error) {
|
|
9846
|
+
if (isMissingProcess(error)) {
|
|
9847
|
+
return;
|
|
9848
|
+
}
|
|
9849
|
+
throw error;
|
|
9850
|
+
}
|
|
9851
|
+
await delay2(Math.min(100, gracefulDeadline - Date.now()));
|
|
9852
|
+
}
|
|
9805
9853
|
try {
|
|
9806
9854
|
process.kill(-pid, "SIGKILL");
|
|
9807
9855
|
} catch (error) {
|
|
@@ -9821,7 +9869,7 @@ function delay2(milliseconds) {
|
|
|
9821
9869
|
setTimeout(resolvePromise, milliseconds);
|
|
9822
9870
|
});
|
|
9823
9871
|
}
|
|
9824
|
-
var import_node_child_process2, import_promises, import_node_os4, import_node_path9, RunningProcessHandle;
|
|
9872
|
+
var import_node_child_process2, import_promises, import_node_os4, import_node_path9, cancellationDeadlineMilliseconds, RunningProcessHandle;
|
|
9825
9873
|
var init_process_executor = __esm({
|
|
9826
9874
|
"../machine-connector/dist/runtime/process-executor.js"() {
|
|
9827
9875
|
"use strict";
|
|
@@ -9832,21 +9880,141 @@ var init_process_executor = __esm({
|
|
|
9832
9880
|
import_node_path9 = require("path");
|
|
9833
9881
|
init_enums();
|
|
9834
9882
|
init_invariants();
|
|
9883
|
+
cancellationDeadlineMilliseconds = 4e3;
|
|
9835
9884
|
RunningProcessHandle = class {
|
|
9836
9885
|
pid;
|
|
9837
9886
|
cancelled = false;
|
|
9887
|
+
cancellation;
|
|
9888
|
+
cancellationStarted;
|
|
9889
|
+
resolveCancellationStarted;
|
|
9838
9890
|
constructor(pid) {
|
|
9839
9891
|
this.pid = pid;
|
|
9892
|
+
this.cancellationStarted = new Promise((resolvePromise) => {
|
|
9893
|
+
this.resolveCancellationStarted = resolvePromise;
|
|
9894
|
+
});
|
|
9840
9895
|
}
|
|
9841
9896
|
wasCancelled() {
|
|
9842
9897
|
return this.cancelled;
|
|
9843
9898
|
}
|
|
9844
9899
|
async cancel() {
|
|
9900
|
+
if (this.cancellation) {
|
|
9901
|
+
await this.cancellation;
|
|
9902
|
+
return;
|
|
9903
|
+
}
|
|
9845
9904
|
this.cancelled = true;
|
|
9846
|
-
|
|
9905
|
+
this.cancellation = Promise.race([
|
|
9906
|
+
terminateProcessTree(this.pid),
|
|
9907
|
+
delay2(cancellationDeadlineMilliseconds)
|
|
9908
|
+
]);
|
|
9909
|
+
this.resolveCancellationStarted();
|
|
9910
|
+
await this.cancellation;
|
|
9911
|
+
}
|
|
9912
|
+
async waitForCancellation() {
|
|
9913
|
+
await this.cancellationStarted;
|
|
9914
|
+
await this.cancellation;
|
|
9915
|
+
}
|
|
9916
|
+
};
|
|
9917
|
+
}
|
|
9918
|
+
});
|
|
9919
|
+
|
|
9920
|
+
// ../machine-connector/dist/runtime/claude-executor.js
|
|
9921
|
+
async function executeClaudeStart(workingDirectory, spec, callbacks) {
|
|
9922
|
+
const sessionId = (0, import_node_crypto.randomUUID)();
|
|
9923
|
+
return await executeClaude(workingDirectory, [
|
|
9924
|
+
"--print",
|
|
9925
|
+
"--output-format",
|
|
9926
|
+
"stream-json",
|
|
9927
|
+
"--verbose",
|
|
9928
|
+
"--dangerously-skip-permissions",
|
|
9929
|
+
"--session-id",
|
|
9930
|
+
sessionId
|
|
9931
|
+
], spec.prompt, sessionId, callbacks);
|
|
9932
|
+
}
|
|
9933
|
+
async function executeClaudeReply(workingDirectory, spec, callbacks) {
|
|
9934
|
+
return await executeClaude(workingDirectory, [
|
|
9935
|
+
"--print",
|
|
9936
|
+
"--output-format",
|
|
9937
|
+
"stream-json",
|
|
9938
|
+
"--verbose",
|
|
9939
|
+
"--dangerously-skip-permissions",
|
|
9940
|
+
"--resume",
|
|
9941
|
+
spec.threadId
|
|
9942
|
+
], spec.prompt, spec.threadId, callbacks);
|
|
9943
|
+
}
|
|
9944
|
+
async function executeClaude(workingDirectory, argumentsList, prompt, expectedSessionId, callbacks) {
|
|
9945
|
+
const metadata = {
|
|
9946
|
+
threadId: expectedSessionId
|
|
9947
|
+
};
|
|
9948
|
+
let bufferedStdout = "";
|
|
9949
|
+
const processCallbacks = {
|
|
9950
|
+
canSpawn: callbacks.canSpawn,
|
|
9951
|
+
onOutput: async (output) => {
|
|
9952
|
+
await callbacks.onOutput(output.stream, output.text);
|
|
9953
|
+
if (output.stream !== MachineJobOutputStream.Stdout) {
|
|
9954
|
+
return;
|
|
9955
|
+
}
|
|
9956
|
+
bufferedStdout += output.text;
|
|
9957
|
+
const lines = bufferedStdout.split("\n");
|
|
9958
|
+
bufferedStdout = lines.pop() ?? "";
|
|
9959
|
+
for (const line of lines) {
|
|
9960
|
+
await processClaudeLine(line, metadata, callbacks);
|
|
9961
|
+
}
|
|
9962
|
+
},
|
|
9963
|
+
onSpawn: callbacks.onSpawn
|
|
9964
|
+
};
|
|
9965
|
+
const result = await executeProcess(process.env.MOXT_CLAUDE_PATH ?? "claude", argumentsList, workingDirectory, {}, prompt, 43200, processCallbacks);
|
|
9966
|
+
if (bufferedStdout.trim().length > 0) {
|
|
9967
|
+
await processClaudeLine(bufferedStdout, metadata, callbacks);
|
|
9968
|
+
}
|
|
9969
|
+
return {
|
|
9970
|
+
...result,
|
|
9971
|
+
finalMessage: metadata.finalMessage,
|
|
9972
|
+
threadId: metadata.threadId
|
|
9973
|
+
};
|
|
9974
|
+
}
|
|
9975
|
+
async function processClaudeLine(line, metadata, callbacks) {
|
|
9976
|
+
const event = parseClaudeEvent(line).value;
|
|
9977
|
+
if (event === void 0) {
|
|
9978
|
+
return;
|
|
9979
|
+
}
|
|
9980
|
+
if (isRecord(event)) {
|
|
9981
|
+
if (typeof event.session_id === "string") {
|
|
9982
|
+
metadata.threadId = event.session_id;
|
|
9983
|
+
}
|
|
9984
|
+
if (event.type === "result" && typeof event.result === "string") {
|
|
9985
|
+
metadata.finalMessage = event.result;
|
|
9986
|
+
}
|
|
9987
|
+
}
|
|
9988
|
+
await callbacks.onEvent(event);
|
|
9989
|
+
}
|
|
9990
|
+
function parseClaudeEvent(line) {
|
|
9991
|
+
const trimmed = line.trim();
|
|
9992
|
+
if (trimmed.length === 0) {
|
|
9993
|
+
return {};
|
|
9994
|
+
}
|
|
9995
|
+
try {
|
|
9996
|
+
return { value: JSON.parse(trimmed) };
|
|
9997
|
+
} catch {
|
|
9998
|
+
return {
|
|
9999
|
+
value: {
|
|
10000
|
+
message: trimmed,
|
|
10001
|
+
type: "unparsed_output"
|
|
9847
10002
|
}
|
|
9848
10003
|
};
|
|
9849
10004
|
}
|
|
10005
|
+
}
|
|
10006
|
+
function isRecord(value) {
|
|
10007
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10008
|
+
}
|
|
10009
|
+
var import_node_crypto;
|
|
10010
|
+
var init_claude_executor = __esm({
|
|
10011
|
+
"../machine-connector/dist/runtime/claude-executor.js"() {
|
|
10012
|
+
"use strict";
|
|
10013
|
+
init_cjs_shims();
|
|
10014
|
+
import_node_crypto = require("crypto");
|
|
10015
|
+
init_enums();
|
|
10016
|
+
init_process_executor();
|
|
10017
|
+
}
|
|
9850
10018
|
});
|
|
9851
10019
|
|
|
9852
10020
|
// ../machine-connector/dist/runtime/codex-executor.js
|
|
@@ -9880,6 +10048,7 @@ async function executeCodex(workingDirectory, outputPath, argumentsList, prompt,
|
|
|
9880
10048
|
const executionMetadata = {};
|
|
9881
10049
|
let bufferedStdout = "";
|
|
9882
10050
|
const processCallbacks = {
|
|
10051
|
+
canSpawn: callbacks.canSpawn,
|
|
9883
10052
|
onOutput: async (output) => {
|
|
9884
10053
|
await callbacks.onOutput(output.stream, output.text);
|
|
9885
10054
|
if (output.stream !== MachineJobOutputStream.Stdout) {
|
|
@@ -9922,7 +10091,7 @@ async function executeCodex(workingDirectory, outputPath, argumentsList, prompt,
|
|
|
9922
10091
|
};
|
|
9923
10092
|
}
|
|
9924
10093
|
function createOutputPath(runtimeDirectory) {
|
|
9925
|
-
return (0, import_node_path10.join)(runtimeDirectory, `codex-last-message-${(0,
|
|
10094
|
+
return (0, import_node_path10.join)(runtimeDirectory, `codex-last-message-${(0, import_node_crypto2.randomUUID)()}.txt`);
|
|
9926
10095
|
}
|
|
9927
10096
|
function parseCodexEvent(line) {
|
|
9928
10097
|
const trimmed = line.trim();
|
|
@@ -9941,7 +10110,7 @@ function parseCodexEvent(line) {
|
|
|
9941
10110
|
}
|
|
9942
10111
|
}
|
|
9943
10112
|
function extractThreadId(event) {
|
|
9944
|
-
if (!
|
|
10113
|
+
if (!isRecord2(event)) {
|
|
9945
10114
|
return {};
|
|
9946
10115
|
}
|
|
9947
10116
|
const directThreadId = event.thread_id;
|
|
@@ -9949,7 +10118,7 @@ function extractThreadId(event) {
|
|
|
9949
10118
|
return { value: directThreadId };
|
|
9950
10119
|
}
|
|
9951
10120
|
const thread = event.thread;
|
|
9952
|
-
if (
|
|
10121
|
+
if (isRecord2(thread) && typeof thread.id === "string") {
|
|
9953
10122
|
return { value: thread.id };
|
|
9954
10123
|
}
|
|
9955
10124
|
return {};
|
|
@@ -9964,7 +10133,7 @@ async function readOptionalOutput(path10) {
|
|
|
9964
10133
|
throw error;
|
|
9965
10134
|
}
|
|
9966
10135
|
}
|
|
9967
|
-
function
|
|
10136
|
+
function isRecord2(value) {
|
|
9968
10137
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9969
10138
|
}
|
|
9970
10139
|
function isNodeErrorCode(error, expectedCode) {
|
|
@@ -9973,14 +10142,14 @@ function isNodeErrorCode(error, expectedCode) {
|
|
|
9973
10142
|
}
|
|
9974
10143
|
return error.code === expectedCode;
|
|
9975
10144
|
}
|
|
9976
|
-
var import_promises2, import_node_path10,
|
|
10145
|
+
var import_promises2, import_node_path10, import_node_crypto2;
|
|
9977
10146
|
var init_codex_executor = __esm({
|
|
9978
10147
|
"../machine-connector/dist/runtime/codex-executor.js"() {
|
|
9979
10148
|
"use strict";
|
|
9980
10149
|
init_cjs_shims();
|
|
9981
10150
|
import_promises2 = require("fs/promises");
|
|
9982
10151
|
import_node_path10 = require("path");
|
|
9983
|
-
|
|
10152
|
+
import_node_crypto2 = require("crypto");
|
|
9984
10153
|
init_enums();
|
|
9985
10154
|
init_process_executor();
|
|
9986
10155
|
}
|
|
@@ -10002,12 +10171,12 @@ var init_runtime_types = __esm({
|
|
|
10002
10171
|
});
|
|
10003
10172
|
|
|
10004
10173
|
// ../machine-connector/dist/runtime/durable-job.js
|
|
10005
|
-
var
|
|
10174
|
+
var import_node_crypto3, DurableMachineJob;
|
|
10006
10175
|
var init_durable_job = __esm({
|
|
10007
10176
|
"../machine-connector/dist/runtime/durable-job.js"() {
|
|
10008
10177
|
"use strict";
|
|
10009
10178
|
init_cjs_shims();
|
|
10010
|
-
|
|
10179
|
+
import_node_crypto3 = require("crypto");
|
|
10011
10180
|
init_enums();
|
|
10012
10181
|
init_runtime_types();
|
|
10013
10182
|
DurableMachineJob = class _DurableMachineJob {
|
|
@@ -10111,7 +10280,7 @@ var init_durable_job = __esm({
|
|
|
10111
10280
|
addEvent(kind, payload, options) {
|
|
10112
10281
|
const event = {
|
|
10113
10282
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
10114
|
-
eventId: (0,
|
|
10283
|
+
eventId: (0, import_node_crypto3.randomUUID)(),
|
|
10115
10284
|
generation: this.job.claim.generation,
|
|
10116
10285
|
jobId: this.job.claim.jobId,
|
|
10117
10286
|
kind,
|
|
@@ -10137,6 +10306,326 @@ var init_durable_job = __esm({
|
|
|
10137
10306
|
}
|
|
10138
10307
|
});
|
|
10139
10308
|
|
|
10309
|
+
// ../machine-connector/dist/runtime/execution-cancellation.js
|
|
10310
|
+
var ExecutionCancellationReason, ExecutionCancellation;
|
|
10311
|
+
var init_execution_cancellation = __esm({
|
|
10312
|
+
"../machine-connector/dist/runtime/execution-cancellation.js"() {
|
|
10313
|
+
"use strict";
|
|
10314
|
+
init_cjs_shims();
|
|
10315
|
+
(function(ExecutionCancellationReason2) {
|
|
10316
|
+
ExecutionCancellationReason2["LeaseLost"] = "lease_lost";
|
|
10317
|
+
ExecutionCancellationReason2["Requested"] = "requested";
|
|
10318
|
+
ExecutionCancellationReason2["Stopping"] = "stopping";
|
|
10319
|
+
})(ExecutionCancellationReason || (ExecutionCancellationReason = {}));
|
|
10320
|
+
ExecutionCancellation = class {
|
|
10321
|
+
handle;
|
|
10322
|
+
reason;
|
|
10323
|
+
requested;
|
|
10324
|
+
resolveRequested;
|
|
10325
|
+
constructor() {
|
|
10326
|
+
this.requested = new Promise((resolvePromise) => {
|
|
10327
|
+
this.resolveRequested = resolvePromise;
|
|
10328
|
+
});
|
|
10329
|
+
}
|
|
10330
|
+
canSpawn() {
|
|
10331
|
+
return this.reason === void 0;
|
|
10332
|
+
}
|
|
10333
|
+
currentReason() {
|
|
10334
|
+
return this.reason;
|
|
10335
|
+
}
|
|
10336
|
+
register(handle) {
|
|
10337
|
+
this.handle = handle;
|
|
10338
|
+
if (this.reason !== void 0) {
|
|
10339
|
+
void handle.cancel();
|
|
10340
|
+
}
|
|
10341
|
+
}
|
|
10342
|
+
async request(reason) {
|
|
10343
|
+
if (this.reason === void 0) {
|
|
10344
|
+
this.reason = reason;
|
|
10345
|
+
this.resolveRequested(reason);
|
|
10346
|
+
}
|
|
10347
|
+
if (this.handle) {
|
|
10348
|
+
await this.handle.cancel();
|
|
10349
|
+
}
|
|
10350
|
+
}
|
|
10351
|
+
async wait() {
|
|
10352
|
+
return await this.requested;
|
|
10353
|
+
}
|
|
10354
|
+
};
|
|
10355
|
+
}
|
|
10356
|
+
});
|
|
10357
|
+
|
|
10358
|
+
// ../machine-connector/dist/runtime/image-viewer.js
|
|
10359
|
+
async function viewLocalMachineImage(rootPath, relativeImagePath) {
|
|
10360
|
+
validateRelativeImagePath(relativeImagePath);
|
|
10361
|
+
const canonicalRoot = await resolvePairedRoot(rootPath);
|
|
10362
|
+
const canonicalImage = await resolveImagePath(canonicalRoot, relativeImagePath);
|
|
10363
|
+
requireInsideRoot(canonicalRoot, canonicalImage);
|
|
10364
|
+
const imageStat = await statImage(canonicalImage, relativeImagePath);
|
|
10365
|
+
if (!imageStat.isFile()) {
|
|
10366
|
+
throw new Error(`Path is not a regular file: ${relativeImagePath}`);
|
|
10367
|
+
}
|
|
10368
|
+
if (imageStat.size > maximumLocalMachineImageBytes) {
|
|
10369
|
+
throw new Error(`Image exceeds the ${maximumLocalMachineImageBytes}-byte Local Machine view limit`);
|
|
10370
|
+
}
|
|
10371
|
+
const bytes = await readImageBytes(canonicalImage, relativeImagePath);
|
|
10372
|
+
if (bytes.length > maximumLocalMachineImageBytes) {
|
|
10373
|
+
throw new Error(`Image exceeds the ${maximumLocalMachineImageBytes}-byte Local Machine view limit`);
|
|
10374
|
+
}
|
|
10375
|
+
const mimeType = detectSupportedImageType(bytes);
|
|
10376
|
+
return {
|
|
10377
|
+
data: bytes.toString("base64"),
|
|
10378
|
+
mimeType,
|
|
10379
|
+
type: "image"
|
|
10380
|
+
};
|
|
10381
|
+
}
|
|
10382
|
+
async function resolvePairedRoot(rootPath) {
|
|
10383
|
+
try {
|
|
10384
|
+
return await (0, import_promises3.realpath)(rootPath);
|
|
10385
|
+
} catch {
|
|
10386
|
+
throw new Error("Paired Local Machine root is unavailable");
|
|
10387
|
+
}
|
|
10388
|
+
}
|
|
10389
|
+
async function resolveImagePath(canonicalRoot, relativeImagePath) {
|
|
10390
|
+
try {
|
|
10391
|
+
return await (0, import_promises3.realpath)((0, import_node_path11.resolve)(canonicalRoot, relativeImagePath));
|
|
10392
|
+
} catch {
|
|
10393
|
+
throw new Error(`Image could not be read: ${relativeImagePath}`);
|
|
10394
|
+
}
|
|
10395
|
+
}
|
|
10396
|
+
async function statImage(canonicalImage, relativeImagePath) {
|
|
10397
|
+
try {
|
|
10398
|
+
return await (0, import_promises3.stat)(canonicalImage);
|
|
10399
|
+
} catch {
|
|
10400
|
+
throw new Error(`Image could not be read: ${relativeImagePath}`);
|
|
10401
|
+
}
|
|
10402
|
+
}
|
|
10403
|
+
async function readImageBytes(canonicalImage, relativeImagePath) {
|
|
10404
|
+
try {
|
|
10405
|
+
return await (0, import_promises3.readFile)(canonicalImage);
|
|
10406
|
+
} catch {
|
|
10407
|
+
throw new Error(`Image could not be read: ${relativeImagePath}`);
|
|
10408
|
+
}
|
|
10409
|
+
}
|
|
10410
|
+
function validateRelativeImagePath(path10) {
|
|
10411
|
+
const segments = path10.split(/[\\/]/);
|
|
10412
|
+
if (path10.length === 0 || path10.length > 4096 || path10.includes("\0") || (0, import_node_path11.isAbsolute)(path10) || import_node_path11.win32.isAbsolute(path10) || segments.some((segment) => segment.length === 0 || segment === "." || segment === "..")) {
|
|
10413
|
+
throw new Error(`Invalid relative image path: ${path10}`);
|
|
10414
|
+
}
|
|
10415
|
+
}
|
|
10416
|
+
function requireInsideRoot(canonicalRoot, canonicalImage) {
|
|
10417
|
+
const relativePath = (0, import_node_path11.relative)(canonicalRoot, canonicalImage);
|
|
10418
|
+
if (relativePath === ".." || relativePath.startsWith(`..${import_node_path11.sep}`) || (0, import_node_path11.isAbsolute)(relativePath)) {
|
|
10419
|
+
throw new Error("Image path escapes paired root");
|
|
10420
|
+
}
|
|
10421
|
+
}
|
|
10422
|
+
function detectSupportedImageType(bytes) {
|
|
10423
|
+
if (startsWith(bytes, [255, 10]) || startsWith(bytes, [
|
|
10424
|
+
0,
|
|
10425
|
+
0,
|
|
10426
|
+
0,
|
|
10427
|
+
12,
|
|
10428
|
+
74,
|
|
10429
|
+
88,
|
|
10430
|
+
76,
|
|
10431
|
+
32,
|
|
10432
|
+
13,
|
|
10433
|
+
10,
|
|
10434
|
+
135,
|
|
10435
|
+
10
|
|
10436
|
+
])) {
|
|
10437
|
+
throw new Error("Unsupported image type: image/jxl");
|
|
10438
|
+
}
|
|
10439
|
+
if (startsWith(bytes, [255, 216, 255])) {
|
|
10440
|
+
if (bytes[3] === 247) {
|
|
10441
|
+
throw new Error("Unsupported image type: image/jls");
|
|
10442
|
+
}
|
|
10443
|
+
if (!isStructurallyValidJpeg(bytes)) {
|
|
10444
|
+
throw new Error("Corrupt image content: image/jpeg");
|
|
10445
|
+
}
|
|
10446
|
+
return "image/jpeg";
|
|
10447
|
+
}
|
|
10448
|
+
if (startsWith(bytes, [137, 80, 78, 71, 13, 10, 26, 10])) {
|
|
10449
|
+
const png = inspectPng(bytes);
|
|
10450
|
+
if (!png.valid) {
|
|
10451
|
+
throw new Error("Corrupt image content: image/png");
|
|
10452
|
+
}
|
|
10453
|
+
if (png.animated) {
|
|
10454
|
+
throw new Error("Unsupported image type: image/apng");
|
|
10455
|
+
}
|
|
10456
|
+
return "image/png";
|
|
10457
|
+
}
|
|
10458
|
+
if (startsWithAscii(bytes, 0, "GIF87a") || startsWithAscii(bytes, 0, "GIF89a")) {
|
|
10459
|
+
if (!isStructurallyValidGif(bytes)) {
|
|
10460
|
+
throw new Error("Corrupt image content: image/gif");
|
|
10461
|
+
}
|
|
10462
|
+
return "image/gif";
|
|
10463
|
+
}
|
|
10464
|
+
if (startsWithAscii(bytes, 0, "RIFF") && startsWithAscii(bytes, 8, "WEBP")) {
|
|
10465
|
+
const supportedChunk = startsWithAscii(bytes, 12, "VP8 ") || startsWithAscii(bytes, 12, "VP8L") || startsWithAscii(bytes, 12, "VP8X");
|
|
10466
|
+
const chunkSize = readUint32LE(bytes, 16);
|
|
10467
|
+
const expectedLength = 20 + chunkSize + chunkSize % 2;
|
|
10468
|
+
if (bytes.length < 20 || readUint32LE(bytes, 4) + 8 !== bytes.length || expectedLength !== bytes.length || startsWithAscii(bytes, 12, "VP8L") && (chunkSize < 1 || bytes[20] !== 47) || !supportedChunk) {
|
|
10469
|
+
throw new Error("Corrupt image content: image/webp");
|
|
10470
|
+
}
|
|
10471
|
+
return "image/webp";
|
|
10472
|
+
}
|
|
10473
|
+
if (startsWithAscii(bytes, 0, "BM")) {
|
|
10474
|
+
throw new Error("Unsupported image type: image/bmp");
|
|
10475
|
+
}
|
|
10476
|
+
throw new Error("Unsupported or unrecognized image content");
|
|
10477
|
+
}
|
|
10478
|
+
function inspectPng(bytes) {
|
|
10479
|
+
let offset = 8;
|
|
10480
|
+
let animated = false;
|
|
10481
|
+
let firstChunk = true;
|
|
10482
|
+
let hasImageData = false;
|
|
10483
|
+
while (offset + 12 <= bytes.length) {
|
|
10484
|
+
const chunkLength = readUint32BE(bytes, offset);
|
|
10485
|
+
const chunkTypeOffset = offset + 4;
|
|
10486
|
+
const nextOffset = offset + 12 + chunkLength;
|
|
10487
|
+
if (nextOffset <= offset || nextOffset > bytes.length) {
|
|
10488
|
+
return { animated, valid: false };
|
|
10489
|
+
}
|
|
10490
|
+
if (firstChunk && (!startsWithAscii(bytes, chunkTypeOffset, "IHDR") || chunkLength !== 13)) {
|
|
10491
|
+
return { animated, valid: false };
|
|
10492
|
+
}
|
|
10493
|
+
if (startsWithAscii(bytes, chunkTypeOffset, "acTL")) {
|
|
10494
|
+
animated = true;
|
|
10495
|
+
}
|
|
10496
|
+
if (startsWithAscii(bytes, chunkTypeOffset, "IDAT")) {
|
|
10497
|
+
hasImageData = true;
|
|
10498
|
+
}
|
|
10499
|
+
if (startsWithAscii(bytes, chunkTypeOffset, "IEND")) {
|
|
10500
|
+
return {
|
|
10501
|
+
animated,
|
|
10502
|
+
valid: chunkLength === 0 && hasImageData && nextOffset === bytes.length
|
|
10503
|
+
};
|
|
10504
|
+
}
|
|
10505
|
+
firstChunk = false;
|
|
10506
|
+
offset = nextOffset;
|
|
10507
|
+
}
|
|
10508
|
+
return { animated, valid: false };
|
|
10509
|
+
}
|
|
10510
|
+
function isStructurallyValidJpeg(bytes) {
|
|
10511
|
+
let offset = 2;
|
|
10512
|
+
let hasFrame = false;
|
|
10513
|
+
while (offset + 4 <= bytes.length) {
|
|
10514
|
+
if (bytes[offset] !== 255) {
|
|
10515
|
+
return false;
|
|
10516
|
+
}
|
|
10517
|
+
while (bytes[offset] === 255) {
|
|
10518
|
+
offset += 1;
|
|
10519
|
+
}
|
|
10520
|
+
const marker = bytes[offset];
|
|
10521
|
+
offset += 1;
|
|
10522
|
+
if (marker === void 0 || marker === 0 || marker === 217) {
|
|
10523
|
+
return false;
|
|
10524
|
+
}
|
|
10525
|
+
const segmentLength = readUint16BE(bytes, offset);
|
|
10526
|
+
if (segmentLength < 2 || offset + segmentLength > bytes.length) {
|
|
10527
|
+
return false;
|
|
10528
|
+
}
|
|
10529
|
+
if (marker >= 192 && marker <= 195 || marker >= 197 && marker <= 199 || marker >= 201 && marker <= 203 || marker >= 205 && marker <= 207) {
|
|
10530
|
+
hasFrame = segmentLength >= 8;
|
|
10531
|
+
}
|
|
10532
|
+
if (marker === 218) {
|
|
10533
|
+
return hasFrame && endsWith(bytes, [255, 217]);
|
|
10534
|
+
}
|
|
10535
|
+
offset += segmentLength;
|
|
10536
|
+
}
|
|
10537
|
+
return false;
|
|
10538
|
+
}
|
|
10539
|
+
function isStructurallyValidGif(bytes) {
|
|
10540
|
+
if (bytes.length < 14 || readUint16LE(bytes, 6) === 0 || readUint16LE(bytes, 8) === 0) {
|
|
10541
|
+
return false;
|
|
10542
|
+
}
|
|
10543
|
+
let offset = 13;
|
|
10544
|
+
const packedFields = bytes[10] ?? 0;
|
|
10545
|
+
if ((packedFields & 128) !== 0) {
|
|
10546
|
+
offset += 3 * (1 << (packedFields & 7) + 1);
|
|
10547
|
+
}
|
|
10548
|
+
let hasImage = false;
|
|
10549
|
+
while (offset < bytes.length) {
|
|
10550
|
+
const introducer = bytes[offset];
|
|
10551
|
+
offset += 1;
|
|
10552
|
+
if (introducer === 59) {
|
|
10553
|
+
return hasImage && offset === bytes.length;
|
|
10554
|
+
}
|
|
10555
|
+
if (introducer === 33) {
|
|
10556
|
+
offset += 1;
|
|
10557
|
+
} else if (introducer === 44) {
|
|
10558
|
+
if (offset + 9 > bytes.length) {
|
|
10559
|
+
return false;
|
|
10560
|
+
}
|
|
10561
|
+
const imagePackedFields = bytes[offset + 8] ?? 0;
|
|
10562
|
+
offset += 9;
|
|
10563
|
+
if ((imagePackedFields & 128) !== 0) {
|
|
10564
|
+
offset += 3 * (1 << (imagePackedFields & 7) + 1);
|
|
10565
|
+
}
|
|
10566
|
+
if (offset >= bytes.length) {
|
|
10567
|
+
return false;
|
|
10568
|
+
}
|
|
10569
|
+
offset += 1;
|
|
10570
|
+
hasImage = true;
|
|
10571
|
+
} else {
|
|
10572
|
+
return false;
|
|
10573
|
+
}
|
|
10574
|
+
while (offset < bytes.length) {
|
|
10575
|
+
const blockLength = bytes[offset] ?? 0;
|
|
10576
|
+
offset += 1;
|
|
10577
|
+
if (blockLength === 0) {
|
|
10578
|
+
break;
|
|
10579
|
+
}
|
|
10580
|
+
offset += blockLength;
|
|
10581
|
+
if (offset > bytes.length) {
|
|
10582
|
+
return false;
|
|
10583
|
+
}
|
|
10584
|
+
}
|
|
10585
|
+
}
|
|
10586
|
+
return false;
|
|
10587
|
+
}
|
|
10588
|
+
function readUint32BE(bytes, offset) {
|
|
10589
|
+
return (bytes[offset] ?? 0) * 16777216 + ((bytes[offset + 1] ?? 0) << 16) + ((bytes[offset + 2] ?? 0) << 8) + (bytes[offset + 3] ?? 0);
|
|
10590
|
+
}
|
|
10591
|
+
function readUint16BE(bytes, offset) {
|
|
10592
|
+
return ((bytes[offset] ?? 0) << 8) + (bytes[offset + 1] ?? 0);
|
|
10593
|
+
}
|
|
10594
|
+
function readUint16LE(bytes, offset) {
|
|
10595
|
+
return (bytes[offset] ?? 0) + ((bytes[offset + 1] ?? 0) << 8);
|
|
10596
|
+
}
|
|
10597
|
+
function readUint32LE(bytes, offset) {
|
|
10598
|
+
return (bytes[offset] ?? 0) + ((bytes[offset + 1] ?? 0) << 8) + ((bytes[offset + 2] ?? 0) << 16) + (bytes[offset + 3] ?? 0) * 16777216;
|
|
10599
|
+
}
|
|
10600
|
+
function startsWith(bytes, expected) {
|
|
10601
|
+
return bytes.length >= expected.length && expected.every((byte, index) => bytes[index] === byte);
|
|
10602
|
+
}
|
|
10603
|
+
function endsWith(bytes, expected) {
|
|
10604
|
+
const offset = bytes.length - expected.length;
|
|
10605
|
+
return offset >= 0 && expected.every((byte, index) => bytes[offset + index] === byte);
|
|
10606
|
+
}
|
|
10607
|
+
function startsWithAscii(bytes, offset, text) {
|
|
10608
|
+
if (bytes.length < offset + text.length) {
|
|
10609
|
+
return false;
|
|
10610
|
+
}
|
|
10611
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
10612
|
+
if (bytes[offset + index] !== text.charCodeAt(index)) {
|
|
10613
|
+
return false;
|
|
10614
|
+
}
|
|
10615
|
+
}
|
|
10616
|
+
return true;
|
|
10617
|
+
}
|
|
10618
|
+
var import_promises3, import_node_path11, maximumLocalMachineImageBytes;
|
|
10619
|
+
var init_image_viewer = __esm({
|
|
10620
|
+
"../machine-connector/dist/runtime/image-viewer.js"() {
|
|
10621
|
+
"use strict";
|
|
10622
|
+
init_cjs_shims();
|
|
10623
|
+
import_promises3 = require("fs/promises");
|
|
10624
|
+
import_node_path11 = require("path");
|
|
10625
|
+
maximumLocalMachineImageBytes = 1e7;
|
|
10626
|
+
}
|
|
10627
|
+
});
|
|
10628
|
+
|
|
10140
10629
|
// ../machine-connector/dist/runtime/local-ipc.js
|
|
10141
10630
|
async function requestRuntimeStatus(store) {
|
|
10142
10631
|
return await new Promise((resolvePromise, rejectPromise) => {
|
|
@@ -10160,12 +10649,12 @@ async function requestRuntimeStatus(store) {
|
|
|
10160
10649
|
});
|
|
10161
10650
|
});
|
|
10162
10651
|
}
|
|
10163
|
-
var
|
|
10652
|
+
var import_promises4, import_node_net, import_node_os5, LocalIpcServer;
|
|
10164
10653
|
var init_local_ipc = __esm({
|
|
10165
10654
|
"../machine-connector/dist/runtime/local-ipc.js"() {
|
|
10166
10655
|
"use strict";
|
|
10167
10656
|
init_cjs_shims();
|
|
10168
|
-
|
|
10657
|
+
import_promises4 = require("fs/promises");
|
|
10169
10658
|
import_node_net = require("net");
|
|
10170
10659
|
import_node_os5 = require("os");
|
|
10171
10660
|
LocalIpcServer = class {
|
|
@@ -10179,7 +10668,7 @@ var init_local_ipc = __esm({
|
|
|
10179
10668
|
async start() {
|
|
10180
10669
|
const socketPath = this.store.runtimeSocketPath();
|
|
10181
10670
|
if ((0, import_node_os5.platform)() !== "win32") {
|
|
10182
|
-
await (0,
|
|
10671
|
+
await (0, import_promises4.rm)(socketPath, { force: true });
|
|
10183
10672
|
}
|
|
10184
10673
|
this.server = (0, import_node_net.createServer)((socket) => {
|
|
10185
10674
|
let requestText = "";
|
|
@@ -10199,7 +10688,7 @@ var init_local_ipc = __esm({
|
|
|
10199
10688
|
this.server?.listen(socketPath, resolvePromise);
|
|
10200
10689
|
});
|
|
10201
10690
|
if ((0, import_node_os5.platform)() !== "win32") {
|
|
10202
|
-
await (0,
|
|
10691
|
+
await (0, import_promises4.chmod)(socketPath, 384);
|
|
10203
10692
|
}
|
|
10204
10693
|
}
|
|
10205
10694
|
async close() {
|
|
@@ -10210,7 +10699,7 @@ var init_local_ipc = __esm({
|
|
|
10210
10699
|
this.server?.close(() => resolvePromise());
|
|
10211
10700
|
});
|
|
10212
10701
|
if ((0, import_node_os5.platform)() !== "win32") {
|
|
10213
|
-
await (0,
|
|
10702
|
+
await (0, import_promises4.rm)(this.store.runtimeSocketPath(), { force: true });
|
|
10214
10703
|
}
|
|
10215
10704
|
}
|
|
10216
10705
|
handleRequest(requestText) {
|
|
@@ -10230,11 +10719,21 @@ var init_local_ipc = __esm({
|
|
|
10230
10719
|
}
|
|
10231
10720
|
});
|
|
10232
10721
|
|
|
10722
|
+
// ../machine-connector/dist/runtime/version.js
|
|
10723
|
+
var connectorVersion;
|
|
10724
|
+
var init_version = __esm({
|
|
10725
|
+
"../machine-connector/dist/runtime/version.js"() {
|
|
10726
|
+
"use strict";
|
|
10727
|
+
init_cjs_shims();
|
|
10728
|
+
connectorVersion = "0.2.0";
|
|
10729
|
+
}
|
|
10730
|
+
});
|
|
10731
|
+
|
|
10233
10732
|
// ../machine-connector/dist/runtime/relay-client.js
|
|
10234
10733
|
async function postJson(url, body, accessToken) {
|
|
10235
10734
|
const headers = {
|
|
10236
10735
|
"Content-Type": "application/json",
|
|
10237
|
-
"User-Agent":
|
|
10736
|
+
"User-Agent": `moxt-machine-connector/${connectorVersion}`
|
|
10238
10737
|
};
|
|
10239
10738
|
if (accessToken) {
|
|
10240
10739
|
headers.Authorization = `Bearer ${accessToken}`;
|
|
@@ -10282,6 +10781,7 @@ var init_relay_client = __esm({
|
|
|
10282
10781
|
"../machine-connector/dist/runtime/relay-client.js"() {
|
|
10283
10782
|
"use strict";
|
|
10284
10783
|
init_cjs_shims();
|
|
10784
|
+
init_version();
|
|
10285
10785
|
requestTimeoutMilliseconds = 65e3;
|
|
10286
10786
|
RelayHttpError = class extends Error {
|
|
10287
10787
|
responseBody;
|
|
@@ -10378,12 +10878,12 @@ var init_relay_client = __esm({
|
|
|
10378
10878
|
});
|
|
10379
10879
|
|
|
10380
10880
|
// ../machine-connector/dist/runtime/runtime-logger.js
|
|
10381
|
-
var
|
|
10881
|
+
var import_promises5, RuntimeLogger;
|
|
10382
10882
|
var init_runtime_logger = __esm({
|
|
10383
10883
|
"../machine-connector/dist/runtime/runtime-logger.js"() {
|
|
10384
10884
|
"use strict";
|
|
10385
10885
|
init_cjs_shims();
|
|
10386
|
-
|
|
10886
|
+
import_promises5 = require("fs/promises");
|
|
10387
10887
|
RuntimeLogger = class {
|
|
10388
10888
|
store;
|
|
10389
10889
|
constructor(store) {
|
|
@@ -10397,7 +10897,7 @@ var init_runtime_logger = __esm({
|
|
|
10397
10897
|
await this.write("error", message, metadata, this.store.runtimeErrorLogPath());
|
|
10398
10898
|
}
|
|
10399
10899
|
async write(level, message, metadata, path10) {
|
|
10400
|
-
await (0,
|
|
10900
|
+
await (0, import_promises5.appendFile)(path10, `${JSON.stringify({
|
|
10401
10901
|
level,
|
|
10402
10902
|
message,
|
|
10403
10903
|
metadata,
|
|
@@ -10419,10 +10919,10 @@ function defaultRuntimeDirectory() {
|
|
|
10419
10919
|
return override;
|
|
10420
10920
|
}
|
|
10421
10921
|
if ((0, import_node_os6.platform)() === "darwin") {
|
|
10422
|
-
return (0,
|
|
10922
|
+
return (0, import_node_path12.join)((0, import_node_os6.homedir)(), "Library", "Application Support", "Moxt", "Machine Connector");
|
|
10423
10923
|
}
|
|
10424
|
-
const stateHome = process.env.XDG_STATE_HOME ?? (0,
|
|
10425
|
-
return (0,
|
|
10924
|
+
const stateHome = process.env.XDG_STATE_HOME ?? (0, import_node_path12.join)((0, import_node_os6.homedir)(), ".local", "state");
|
|
10925
|
+
return (0, import_node_path12.join)(stateHome, "moxt", "machine-connector");
|
|
10426
10926
|
}
|
|
10427
10927
|
function isNodeErrorCode2(error, expectedCode) {
|
|
10428
10928
|
if (!(error instanceof Error) || !("code" in error)) {
|
|
@@ -10430,14 +10930,14 @@ function isNodeErrorCode2(error, expectedCode) {
|
|
|
10430
10930
|
}
|
|
10431
10931
|
return error.code === expectedCode;
|
|
10432
10932
|
}
|
|
10433
|
-
var
|
|
10933
|
+
var import_promises6, import_node_os6, import_node_path12, privateFileMode, privateDirectoryMode, MachineRuntimeStore;
|
|
10434
10934
|
var init_store = __esm({
|
|
10435
10935
|
"../machine-connector/dist/runtime/store.js"() {
|
|
10436
10936
|
"use strict";
|
|
10437
10937
|
init_cjs_shims();
|
|
10438
|
-
|
|
10938
|
+
import_promises6 = require("fs/promises");
|
|
10439
10939
|
import_node_os6 = require("os");
|
|
10440
|
-
|
|
10940
|
+
import_node_path12 = require("path");
|
|
10441
10941
|
privateFileMode = 384;
|
|
10442
10942
|
privateDirectoryMode = 448;
|
|
10443
10943
|
MachineRuntimeStore = class {
|
|
@@ -10446,15 +10946,15 @@ var init_store = __esm({
|
|
|
10446
10946
|
this.baseDirectory = baseDirectory;
|
|
10447
10947
|
}
|
|
10448
10948
|
async initialize() {
|
|
10449
|
-
await (0,
|
|
10949
|
+
await (0, import_promises6.mkdir)(this.jobsDirectory(), {
|
|
10450
10950
|
mode: privateDirectoryMode,
|
|
10451
10951
|
recursive: true
|
|
10452
10952
|
});
|
|
10453
|
-
await (0,
|
|
10454
|
-
await (0,
|
|
10953
|
+
await (0, import_promises6.chmod)(this.baseDirectory, privateDirectoryMode);
|
|
10954
|
+
await (0, import_promises6.chmod)(this.jobsDirectory(), privateDirectoryMode);
|
|
10455
10955
|
}
|
|
10456
10956
|
async getCanonicalRoot(rootPath) {
|
|
10457
|
-
return await (0,
|
|
10957
|
+
return await (0, import_promises6.realpath)(rootPath);
|
|
10458
10958
|
}
|
|
10459
10959
|
async readIdentity() {
|
|
10460
10960
|
return await this.readOptionalJson(this.identityPath());
|
|
@@ -10497,7 +10997,7 @@ var init_store = __esm({
|
|
|
10497
10997
|
await this.writePrivateJson(this.serviceManagerPath(), serviceManager);
|
|
10498
10998
|
}
|
|
10499
10999
|
async removeServiceManager() {
|
|
10500
|
-
await (0,
|
|
11000
|
+
await (0, import_promises6.rm)(this.serviceManagerPath(), { force: true });
|
|
10501
11001
|
}
|
|
10502
11002
|
async readJob(jobId) {
|
|
10503
11003
|
return await this.readOptionalJson(this.jobPath(jobId));
|
|
@@ -10508,7 +11008,7 @@ var init_store = __esm({
|
|
|
10508
11008
|
async listJobs() {
|
|
10509
11009
|
let names = [];
|
|
10510
11010
|
try {
|
|
10511
|
-
names = await (0,
|
|
11011
|
+
names = await (0, import_promises6.readdir)(this.jobsDirectory());
|
|
10512
11012
|
} catch (error) {
|
|
10513
11013
|
if (isNodeErrorCode2(error, "ENOENT")) {
|
|
10514
11014
|
return [];
|
|
@@ -10517,7 +11017,7 @@ var init_store = __esm({
|
|
|
10517
11017
|
}
|
|
10518
11018
|
const jobs = [];
|
|
10519
11019
|
for (const name of names.filter((entry) => entry.endsWith(".json"))) {
|
|
10520
|
-
const job = await this.readOptionalJson((0,
|
|
11020
|
+
const job = await this.readOptionalJson((0, import_node_path12.join)(this.jobsDirectory(), name));
|
|
10521
11021
|
if (job.value) {
|
|
10522
11022
|
jobs.push(job.value);
|
|
10523
11023
|
}
|
|
@@ -10525,40 +11025,40 @@ var init_store = __esm({
|
|
|
10525
11025
|
return jobs;
|
|
10526
11026
|
}
|
|
10527
11027
|
async deleteJob(jobId) {
|
|
10528
|
-
await (0,
|
|
11028
|
+
await (0, import_promises6.rm)(this.jobPath(jobId), { force: true });
|
|
10529
11029
|
}
|
|
10530
11030
|
runtimeLogPath() {
|
|
10531
|
-
return (0,
|
|
11031
|
+
return (0, import_node_path12.join)(this.baseDirectory, "machine-connector.log");
|
|
10532
11032
|
}
|
|
10533
11033
|
runtimeErrorLogPath() {
|
|
10534
|
-
return (0,
|
|
11034
|
+
return (0, import_node_path12.join)(this.baseDirectory, "machine-connector.error.log");
|
|
10535
11035
|
}
|
|
10536
11036
|
runtimeStatusPath() {
|
|
10537
|
-
return (0,
|
|
11037
|
+
return (0, import_node_path12.join)(this.baseDirectory, "runtime-status.json");
|
|
10538
11038
|
}
|
|
10539
11039
|
runtimeSocketPath() {
|
|
10540
11040
|
if ((0, import_node_os6.platform)() === "win32") {
|
|
10541
11041
|
return String.raw`\\.\pipe\moxt-machine-connector`;
|
|
10542
11042
|
}
|
|
10543
|
-
return (0,
|
|
11043
|
+
return (0, import_node_path12.join)(this.baseDirectory, "machine-connector.sock");
|
|
10544
11044
|
}
|
|
10545
11045
|
connectionsPath() {
|
|
10546
|
-
return (0,
|
|
11046
|
+
return (0, import_node_path12.join)(this.baseDirectory, "connections.json");
|
|
10547
11047
|
}
|
|
10548
11048
|
identityPath() {
|
|
10549
|
-
return (0,
|
|
11049
|
+
return (0, import_node_path12.join)(this.baseDirectory, "identity.json");
|
|
10550
11050
|
}
|
|
10551
11051
|
serviceManagerPath() {
|
|
10552
|
-
return (0,
|
|
11052
|
+
return (0, import_node_path12.join)(this.baseDirectory, "service-manager.json");
|
|
10553
11053
|
}
|
|
10554
11054
|
privateKeyPath() {
|
|
10555
|
-
return (0,
|
|
11055
|
+
return (0, import_node_path12.join)(this.baseDirectory, "device-private-key.pem");
|
|
10556
11056
|
}
|
|
10557
11057
|
jobsDirectory() {
|
|
10558
|
-
return (0,
|
|
11058
|
+
return (0, import_node_path12.join)(this.baseDirectory, "jobs");
|
|
10559
11059
|
}
|
|
10560
11060
|
jobPath(jobId) {
|
|
10561
|
-
return (0,
|
|
11061
|
+
return (0, import_node_path12.join)(this.jobsDirectory(), `${jobId}.json`);
|
|
10562
11062
|
}
|
|
10563
11063
|
async readOptionalJson(path10) {
|
|
10564
11064
|
const content = await this.readOptionalText(path10);
|
|
@@ -10569,7 +11069,7 @@ var init_store = __esm({
|
|
|
10569
11069
|
}
|
|
10570
11070
|
async readOptionalText(path10) {
|
|
10571
11071
|
try {
|
|
10572
|
-
return { value: await (0,
|
|
11072
|
+
return { value: await (0, import_promises6.readFile)(path10, "utf8") };
|
|
10573
11073
|
} catch (error) {
|
|
10574
11074
|
if (isNodeErrorCode2(error, "ENOENT")) {
|
|
10575
11075
|
return {};
|
|
@@ -10582,64 +11082,104 @@ var init_store = __esm({
|
|
|
10582
11082
|
`);
|
|
10583
11083
|
}
|
|
10584
11084
|
async writePrivateText(path10, value) {
|
|
10585
|
-
await (0,
|
|
11085
|
+
await (0, import_promises6.mkdir)((0, import_node_path12.dirname)(path10), {
|
|
10586
11086
|
mode: privateDirectoryMode,
|
|
10587
11087
|
recursive: true
|
|
10588
11088
|
});
|
|
10589
11089
|
const temporaryPath = `${path10}.${process.pid}.tmp`;
|
|
10590
|
-
await (0,
|
|
11090
|
+
await (0, import_promises6.writeFile)(temporaryPath, value, {
|
|
10591
11091
|
encoding: "utf8",
|
|
10592
11092
|
mode: privateFileMode
|
|
10593
11093
|
});
|
|
10594
|
-
await (0,
|
|
10595
|
-
await (0,
|
|
11094
|
+
await (0, import_promises6.chmod)(temporaryPath, privateFileMode);
|
|
11095
|
+
await (0, import_promises6.rename)(temporaryPath, path10);
|
|
10596
11096
|
}
|
|
10597
11097
|
};
|
|
10598
11098
|
}
|
|
10599
11099
|
});
|
|
10600
11100
|
|
|
10601
11101
|
// ../machine-connector/dist/runtime/daemon.js
|
|
11102
|
+
function isPermanentRelayFailure(error) {
|
|
11103
|
+
return error instanceof RelayHttpError && (error.status === 400 || error.status === 401 || error.status === 403 || error.status === 404 || error.status === 409 || error.status === 410);
|
|
11104
|
+
}
|
|
11105
|
+
async function withDeadline(operation, deadline) {
|
|
11106
|
+
if (deadline === void 0) {
|
|
11107
|
+
return await operation;
|
|
11108
|
+
}
|
|
11109
|
+
const remaining = deadline - Date.now();
|
|
11110
|
+
if (remaining <= 0) {
|
|
11111
|
+
throw new Error("Operation exceeded its foreground deadline");
|
|
11112
|
+
}
|
|
11113
|
+
return await Promise.race([
|
|
11114
|
+
operation,
|
|
11115
|
+
delay3(remaining).then(() => {
|
|
11116
|
+
throw new Error("Operation exceeded its foreground deadline");
|
|
11117
|
+
})
|
|
11118
|
+
]);
|
|
11119
|
+
}
|
|
10602
11120
|
function delay3(milliseconds) {
|
|
10603
11121
|
return new Promise((resolvePromise) => {
|
|
10604
11122
|
setTimeout(resolvePromise, milliseconds);
|
|
10605
11123
|
});
|
|
10606
11124
|
}
|
|
10607
|
-
var import_node_os7,
|
|
11125
|
+
var import_node_os7, import_node_crypto4, claimTimeoutSeconds, controlTimeoutSeconds, eventUploadIntervalMilliseconds, agentOutputLimitBytes, defaultLeaseSeconds, defaultNetworkRetryMilliseconds, defaultLeaseSafetyMarginMilliseconds, defaultTerminalForegroundBudgetMilliseconds, maximumTerminalRetryMilliseconds, TerminalUploadOutcome, MachineConnectorDaemon;
|
|
10608
11126
|
var init_daemon = __esm({
|
|
10609
11127
|
"../machine-connector/dist/runtime/daemon.js"() {
|
|
10610
11128
|
"use strict";
|
|
10611
11129
|
init_cjs_shims();
|
|
10612
11130
|
import_node_os7 = require("os");
|
|
10613
|
-
|
|
11131
|
+
import_node_crypto4 = require("crypto");
|
|
10614
11132
|
init_enums();
|
|
10615
11133
|
init_contracts();
|
|
11134
|
+
init_claude_executor();
|
|
10616
11135
|
init_codex_executor();
|
|
10617
11136
|
init_durable_job();
|
|
11137
|
+
init_execution_cancellation();
|
|
11138
|
+
init_image_viewer();
|
|
10618
11139
|
init_local_ipc();
|
|
10619
11140
|
init_process_executor();
|
|
10620
11141
|
init_relay_client();
|
|
10621
11142
|
init_runtime_logger();
|
|
10622
11143
|
init_runtime_types();
|
|
10623
11144
|
init_store();
|
|
10624
|
-
|
|
11145
|
+
init_version();
|
|
10625
11146
|
claimTimeoutSeconds = 30;
|
|
10626
11147
|
controlTimeoutSeconds = 30;
|
|
10627
|
-
leaseSeconds = 90;
|
|
10628
11148
|
eventUploadIntervalMilliseconds = 500;
|
|
10629
|
-
|
|
10630
|
-
|
|
11149
|
+
agentOutputLimitBytes = 2e6;
|
|
11150
|
+
defaultLeaseSeconds = 90;
|
|
11151
|
+
defaultNetworkRetryMilliseconds = 2e3;
|
|
11152
|
+
defaultLeaseSafetyMarginMilliseconds = 1e4;
|
|
11153
|
+
defaultTerminalForegroundBudgetMilliseconds = 5e3;
|
|
11154
|
+
maximumTerminalRetryMilliseconds = 6e4;
|
|
11155
|
+
(function(TerminalUploadOutcome2) {
|
|
11156
|
+
TerminalUploadOutcome2["PermanentFailure"] = "permanent_failure";
|
|
11157
|
+
TerminalUploadOutcome2["RetryableFailure"] = "retryable_failure";
|
|
11158
|
+
TerminalUploadOutcome2["Uploaded"] = "uploaded";
|
|
11159
|
+
})(TerminalUploadOutcome || (TerminalUploadOutcome = {}));
|
|
10631
11160
|
MachineConnectorDaemon = class {
|
|
10632
11161
|
store;
|
|
10633
11162
|
activeJobs = /* @__PURE__ */ new Map();
|
|
10634
|
-
connectorInstanceId = (0,
|
|
11163
|
+
connectorInstanceId = (0, import_node_crypto4.randomUUID)();
|
|
11164
|
+
executionTasks = /* @__PURE__ */ new Set();
|
|
10635
11165
|
logger;
|
|
10636
11166
|
startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
10637
11167
|
connections = [];
|
|
10638
11168
|
ipcServer;
|
|
10639
11169
|
stopping = false;
|
|
10640
|
-
|
|
11170
|
+
leaseSafetyMarginMilliseconds;
|
|
11171
|
+
leaseSeconds;
|
|
11172
|
+
networkRetryMilliseconds;
|
|
11173
|
+
random;
|
|
11174
|
+
terminalForegroundBudgetMilliseconds;
|
|
11175
|
+
constructor(store = new MachineRuntimeStore(), options = {}) {
|
|
10641
11176
|
this.store = store;
|
|
10642
11177
|
this.logger = new RuntimeLogger(store);
|
|
11178
|
+
this.leaseSafetyMarginMilliseconds = options.leaseSafetyMarginMilliseconds ?? defaultLeaseSafetyMarginMilliseconds;
|
|
11179
|
+
this.leaseSeconds = options.leaseSeconds ?? defaultLeaseSeconds;
|
|
11180
|
+
this.networkRetryMilliseconds = options.networkRetryMilliseconds ?? defaultNetworkRetryMilliseconds;
|
|
11181
|
+
this.random = options.random ?? Math.random;
|
|
11182
|
+
this.terminalForegroundBudgetMilliseconds = options.terminalForegroundBudgetMilliseconds ?? defaultTerminalForegroundBudgetMilliseconds;
|
|
10643
11183
|
}
|
|
10644
11184
|
async start() {
|
|
10645
11185
|
if (process.getuid?.() === 0) {
|
|
@@ -10661,13 +11201,12 @@ var init_daemon = __esm({
|
|
|
10661
11201
|
await Promise.all(this.connections.map(async (connection) => {
|
|
10662
11202
|
await this.runConnection(connection);
|
|
10663
11203
|
}));
|
|
11204
|
+
await this.waitForExecutionTasks();
|
|
10664
11205
|
}
|
|
10665
11206
|
async stop() {
|
|
10666
11207
|
this.stopping = true;
|
|
10667
11208
|
await Promise.all([...this.activeJobs.values()].map(async (activeJob) => {
|
|
10668
|
-
|
|
10669
|
-
await activeJob.handle.cancel();
|
|
10670
|
-
}
|
|
11209
|
+
await activeJob.cancellation.request(ExecutionCancellationReason.Stopping);
|
|
10671
11210
|
}));
|
|
10672
11211
|
await this.ipcServer?.close();
|
|
10673
11212
|
await this.logger.info("Moxt Machine Connector stopped");
|
|
@@ -10675,13 +11214,12 @@ var init_daemon = __esm({
|
|
|
10675
11214
|
getStatus() {
|
|
10676
11215
|
return {
|
|
10677
11216
|
activeJobs: [...this.activeJobs.values()].map((activeJob) => {
|
|
10678
|
-
const job = activeJob.durableJob.snapshot();
|
|
10679
11217
|
return {
|
|
10680
11218
|
connectionId: activeJob.connection.connectionId,
|
|
10681
|
-
jobId:
|
|
10682
|
-
kind:
|
|
10683
|
-
phase:
|
|
10684
|
-
relativeWorkingDirectory:
|
|
11219
|
+
jobId: activeJob.claim.jobId,
|
|
11220
|
+
kind: activeJob.claim.kind,
|
|
11221
|
+
phase: activeJob.durableJob?.snapshot().phase ?? PersistedMachineJobPhase.Claimed,
|
|
11222
|
+
relativeWorkingDirectory: activeJob.claim.relativeWorkingDirectory
|
|
10685
11223
|
};
|
|
10686
11224
|
}),
|
|
10687
11225
|
connections: this.connections.map((connection) => ({
|
|
@@ -10721,23 +11259,23 @@ var init_daemon = __esm({
|
|
|
10721
11259
|
}
|
|
10722
11260
|
async runClaimLoop(connection, relay) {
|
|
10723
11261
|
while (!this.stopping) {
|
|
10724
|
-
if (this.hasActiveJobForConnection(connection.connectionId)) {
|
|
10725
|
-
await this.waitUntilStop(500);
|
|
10726
|
-
continue;
|
|
10727
|
-
}
|
|
10728
11262
|
try {
|
|
10729
11263
|
const response = await relay.claim({
|
|
10730
11264
|
connectorInstanceId: this.connectorInstanceId,
|
|
10731
|
-
leaseSeconds,
|
|
11265
|
+
leaseSeconds: this.leaseSeconds,
|
|
10732
11266
|
protocolVersion: machineProtocolVersion,
|
|
10733
11267
|
timeoutSeconds: claimTimeoutSeconds
|
|
10734
11268
|
});
|
|
10735
11269
|
if (response.job) {
|
|
10736
|
-
|
|
11270
|
+
const activeJob = this.reserveClaim(connection, relay, response.job);
|
|
11271
|
+
if (this.stopping) {
|
|
11272
|
+
await activeJob.cancellation.request(ExecutionCancellationReason.Stopping);
|
|
11273
|
+
}
|
|
11274
|
+
this.startClaimExecution(activeJob);
|
|
10737
11275
|
}
|
|
10738
11276
|
} catch (error) {
|
|
10739
11277
|
await this.logger.error(`Job claim failed for connection ${connection.connectionId}`, error);
|
|
10740
|
-
await this.waitUntilStop(networkRetryMilliseconds);
|
|
11278
|
+
await this.waitUntilStop(this.networkRetryMilliseconds);
|
|
10741
11279
|
}
|
|
10742
11280
|
}
|
|
10743
11281
|
}
|
|
@@ -10750,40 +11288,79 @@ var init_daemon = __esm({
|
|
|
10750
11288
|
protocolVersion: machineProtocolVersion,
|
|
10751
11289
|
timeoutSeconds: controlTimeoutSeconds
|
|
10752
11290
|
});
|
|
10753
|
-
cursor = response.nextCursor;
|
|
10754
11291
|
for (const command of response.commands) {
|
|
10755
11292
|
await this.handleControl(relay, command);
|
|
11293
|
+
cursor = command.cursor;
|
|
11294
|
+
}
|
|
11295
|
+
if (response.commands.length === 0) {
|
|
11296
|
+
cursor = response.nextCursor;
|
|
10756
11297
|
}
|
|
10757
11298
|
} catch (error) {
|
|
10758
11299
|
await this.logger.error(`Control poll failed for connection ${connection.connectionId}`, error);
|
|
10759
|
-
await this.waitUntilStop(networkRetryMilliseconds);
|
|
11300
|
+
await this.waitUntilStop(this.networkRetryMilliseconds);
|
|
10760
11301
|
}
|
|
10761
11302
|
}
|
|
10762
11303
|
}
|
|
10763
|
-
|
|
10764
|
-
const durableJob = await DurableMachineJob.create(this.store, connection.connectionId, claim);
|
|
11304
|
+
reserveClaim(connection, relay, claim) {
|
|
10765
11305
|
const activeJob = {
|
|
10766
|
-
|
|
11306
|
+
cancellation: new ExecutionCancellation(),
|
|
11307
|
+
claim,
|
|
10767
11308
|
connection,
|
|
10768
|
-
durableJob,
|
|
10769
11309
|
eventUploadQueue: Promise.resolve(),
|
|
11310
|
+
leaseExpiresAt: Date.parse(claim.leaseExpiresAt),
|
|
10770
11311
|
relay
|
|
10771
11312
|
};
|
|
10772
11313
|
this.activeJobs.set(claim.jobId, activeJob);
|
|
11314
|
+
return activeJob;
|
|
11315
|
+
}
|
|
11316
|
+
startClaimExecution(activeJob) {
|
|
11317
|
+
const jobId = activeJob.claim.jobId;
|
|
11318
|
+
const executionTask = this.executeClaim(activeJob);
|
|
11319
|
+
this.executionTasks.add(executionTask);
|
|
11320
|
+
void executionTask.then(() => {
|
|
11321
|
+
this.executionTasks.delete(executionTask);
|
|
11322
|
+
}, (error) => {
|
|
11323
|
+
this.executionTasks.delete(executionTask);
|
|
11324
|
+
void this.logger.error(`Local Machine Job ${jobId} escaped its execution boundary`, error).catch((loggingError) => {
|
|
11325
|
+
process.stderr.write(`Failed to record Local Machine Job ${jobId} execution error: ${String(loggingError)}
|
|
11326
|
+
`);
|
|
11327
|
+
});
|
|
11328
|
+
});
|
|
11329
|
+
}
|
|
11330
|
+
async executeClaim(activeJob) {
|
|
11331
|
+
const { claim } = activeJob;
|
|
10773
11332
|
try {
|
|
11333
|
+
const durableJob = await DurableMachineJob.create(this.store, activeJob.connection.connectionId, claim);
|
|
11334
|
+
activeJob.durableJob = durableJob;
|
|
11335
|
+
if (activeJob.cancellation.currentReason() !== void 0) {
|
|
11336
|
+
await durableJob.markTerminal(this.cancellationResult(activeJob));
|
|
11337
|
+
await this.finishTerminalUpload(activeJob);
|
|
11338
|
+
return;
|
|
11339
|
+
}
|
|
10774
11340
|
await durableJob.markRunning();
|
|
10775
|
-
await this.
|
|
11341
|
+
const ownsLease = await this.confirmRunning(activeJob);
|
|
11342
|
+
if (!ownsLease) {
|
|
11343
|
+
await durableJob.markTerminal(this.cancellationResult(activeJob));
|
|
11344
|
+
await this.finishTerminalUpload(activeJob);
|
|
11345
|
+
return;
|
|
11346
|
+
}
|
|
10776
11347
|
const uploadLoop = this.runEventUploadLoop(activeJob);
|
|
10777
11348
|
const leaseLoop = this.runLeaseLoop(activeJob);
|
|
10778
|
-
const
|
|
11349
|
+
const execution = this.runExecutor(activeJob);
|
|
11350
|
+
const executionResult = await Promise.race([
|
|
11351
|
+
execution,
|
|
11352
|
+
activeJob.cancellation.wait().then(() => this.cancellationResult(activeJob))
|
|
11353
|
+
]);
|
|
11354
|
+
void execution.catch(() => void 0);
|
|
10779
11355
|
await durableJob.markTerminal(executionResult);
|
|
10780
|
-
|
|
11356
|
+
await this.finishTerminalUpload(activeJob);
|
|
10781
11357
|
await Promise.all([uploadLoop, leaseLoop]);
|
|
10782
|
-
if (uploaded) {
|
|
10783
|
-
await durableJob.markUploaded();
|
|
10784
|
-
}
|
|
10785
11358
|
} catch (error) {
|
|
10786
11359
|
await this.logger.error(`Local Machine Job ${claim.jobId} failed in Connector`, error);
|
|
11360
|
+
const durableJob = activeJob.durableJob;
|
|
11361
|
+
if (!durableJob) {
|
|
11362
|
+
return;
|
|
11363
|
+
}
|
|
10787
11364
|
const message = error instanceof Error ? error.message : "Unknown Connector error";
|
|
10788
11365
|
await durableJob.markTerminal({
|
|
10789
11366
|
exitCode: -1,
|
|
@@ -10791,30 +11368,28 @@ var init_daemon = __esm({
|
|
|
10791
11368
|
failureMessage: message,
|
|
10792
11369
|
status: MachineJobStatus.Failed
|
|
10793
11370
|
});
|
|
10794
|
-
|
|
10795
|
-
if (uploaded) {
|
|
10796
|
-
await durableJob.markUploaded();
|
|
10797
|
-
}
|
|
11371
|
+
await this.finishTerminalUpload(activeJob);
|
|
10798
11372
|
} finally {
|
|
10799
11373
|
this.activeJobs.delete(claim.jobId);
|
|
10800
11374
|
}
|
|
10801
11375
|
}
|
|
10802
11376
|
async runExecutor(activeJob) {
|
|
10803
|
-
const
|
|
10804
|
-
const
|
|
10805
|
-
|
|
10806
|
-
|
|
10807
|
-
void handle.cancel();
|
|
10808
|
-
}
|
|
10809
|
-
};
|
|
11377
|
+
const durableJob = this.requireDurableJob(activeJob);
|
|
11378
|
+
const { claim } = activeJob;
|
|
11379
|
+
const registerProcess = activeJob.cancellation.register.bind(activeJob.cancellation);
|
|
11380
|
+
const canSpawn = activeJob.cancellation.canSpawn.bind(activeJob.cancellation);
|
|
10810
11381
|
if (claim.kind === MachineJobKind.Command) {
|
|
10811
11382
|
const request2 = claim.requestPayload;
|
|
10812
11383
|
const result = await executeCommand(activeJob.connection.rootPath, {
|
|
10813
11384
|
...request2,
|
|
10814
11385
|
relativeWorkingDirectory: claim.relativeWorkingDirectory
|
|
10815
11386
|
}, {
|
|
11387
|
+
canSpawn,
|
|
10816
11388
|
onOutput: async (output) => {
|
|
10817
|
-
|
|
11389
|
+
if (activeJob.cancellation.currentReason() !== void 0) {
|
|
11390
|
+
return;
|
|
11391
|
+
}
|
|
11392
|
+
await durableJob.appendOutput(output.stream, output.text, request2.outputLimitBytes);
|
|
10818
11393
|
},
|
|
10819
11394
|
onSpawn: registerProcess
|
|
10820
11395
|
});
|
|
@@ -10823,13 +11398,31 @@ var init_daemon = __esm({
|
|
|
10823
11398
|
result: { exitCode: result.exitCode }
|
|
10824
11399
|
};
|
|
10825
11400
|
}
|
|
11401
|
+
if (claim.kind === MachineJobKind.ViewImage) {
|
|
11402
|
+
const request2 = claim.requestPayload;
|
|
11403
|
+
return {
|
|
11404
|
+
exitCode: 0,
|
|
11405
|
+
result: await viewLocalMachineImage(activeJob.connection.rootPath, request2.path),
|
|
11406
|
+
status: MachineJobStatus.Succeeded
|
|
11407
|
+
};
|
|
11408
|
+
}
|
|
10826
11409
|
const workingDirectory = await resolveCanonicalWorkingDirectory(activeJob.connection.rootPath, claim.relativeWorkingDirectory);
|
|
11410
|
+
if (!canSpawn()) {
|
|
11411
|
+
return this.cancellationResult(activeJob);
|
|
11412
|
+
}
|
|
10827
11413
|
const callbacks = {
|
|
11414
|
+
canSpawn,
|
|
10828
11415
|
onEvent: async (event) => {
|
|
10829
|
-
|
|
11416
|
+
if (activeJob.cancellation.currentReason() !== void 0) {
|
|
11417
|
+
return;
|
|
11418
|
+
}
|
|
11419
|
+
await durableJob.appendProgress(event);
|
|
10830
11420
|
},
|
|
10831
11421
|
onOutput: async (stream, text) => {
|
|
10832
|
-
|
|
11422
|
+
if (activeJob.cancellation.currentReason() !== void 0) {
|
|
11423
|
+
return;
|
|
11424
|
+
}
|
|
11425
|
+
await durableJob.appendOutput(stream, text, agentOutputLimitBytes);
|
|
10833
11426
|
},
|
|
10834
11427
|
onSpawn: registerProcess
|
|
10835
11428
|
};
|
|
@@ -10862,82 +11455,158 @@ var init_daemon = __esm({
|
|
|
10862
11455
|
threadId: result.threadId ?? request2.threadId
|
|
10863
11456
|
};
|
|
10864
11457
|
}
|
|
11458
|
+
if (claim.kind === MachineJobKind.ClaudeStart) {
|
|
11459
|
+
const request2 = claim.requestPayload;
|
|
11460
|
+
const result = await executeClaudeStart(workingDirectory, {
|
|
11461
|
+
...request2,
|
|
11462
|
+
relativeWorkingDirectory: claim.relativeWorkingDirectory
|
|
11463
|
+
}, callbacks);
|
|
11464
|
+
return {
|
|
11465
|
+
...result,
|
|
11466
|
+
result: {
|
|
11467
|
+
finalMessage: result.finalMessage,
|
|
11468
|
+
threadId: result.threadId
|
|
11469
|
+
}
|
|
11470
|
+
};
|
|
11471
|
+
}
|
|
11472
|
+
if (claim.kind === MachineJobKind.ClaudeReply) {
|
|
11473
|
+
const request2 = claim.requestPayload;
|
|
11474
|
+
const result = await executeClaudeReply(workingDirectory, {
|
|
11475
|
+
...request2,
|
|
11476
|
+
relativeWorkingDirectory: claim.relativeWorkingDirectory
|
|
11477
|
+
}, callbacks);
|
|
11478
|
+
return {
|
|
11479
|
+
...result,
|
|
11480
|
+
result: {
|
|
11481
|
+
finalMessage: result.finalMessage,
|
|
11482
|
+
threadId: result.threadId ?? request2.threadId
|
|
11483
|
+
},
|
|
11484
|
+
threadId: result.threadId ?? request2.threadId
|
|
11485
|
+
};
|
|
11486
|
+
}
|
|
10865
11487
|
throw new Error(`Unsupported Local Machine Job kind: ${claim.kind}`);
|
|
10866
11488
|
}
|
|
10867
11489
|
async runEventUploadLoop(activeJob) {
|
|
11490
|
+
const durableJob = this.requireDurableJob(activeJob);
|
|
10868
11491
|
while (!this.stopping) {
|
|
10869
|
-
const phase = activeJob.durableJob.snapshot().phase;
|
|
10870
11492
|
await this.tryFlushEvents(activeJob);
|
|
10871
|
-
if (phase
|
|
11493
|
+
if (durableJob.snapshot().phase !== PersistedMachineJobPhase.Running) {
|
|
10872
11494
|
return;
|
|
10873
11495
|
}
|
|
10874
11496
|
await this.waitUntilStop(eventUploadIntervalMilliseconds);
|
|
10875
11497
|
}
|
|
10876
11498
|
}
|
|
10877
11499
|
async runLeaseLoop(activeJob) {
|
|
11500
|
+
let retryMilliseconds = this.networkRetryMilliseconds;
|
|
10878
11501
|
while (!this.stopping) {
|
|
10879
|
-
const
|
|
10880
|
-
if (
|
|
11502
|
+
const durableJob = this.requireDurableJob(activeJob);
|
|
11503
|
+
if (durableJob.snapshot().phase !== PersistedMachineJobPhase.Running) {
|
|
11504
|
+
return;
|
|
11505
|
+
}
|
|
11506
|
+
const remaining = activeJob.leaseExpiresAt - Date.now();
|
|
11507
|
+
if (remaining <= this.leaseSafetyMarginMilliseconds) {
|
|
11508
|
+
await activeJob.cancellation.request(ExecutionCancellationReason.LeaseLost);
|
|
10881
11509
|
return;
|
|
10882
11510
|
}
|
|
10883
|
-
const
|
|
11511
|
+
const renewalAt = activeJob.leaseExpiresAt - this.leaseSeconds * 1e3 / 2;
|
|
11512
|
+
if (Date.now() < renewalAt) {
|
|
11513
|
+
await this.waitUntilStop(Math.min(250, renewalAt - Date.now()));
|
|
11514
|
+
continue;
|
|
11515
|
+
}
|
|
10884
11516
|
try {
|
|
10885
|
-
await activeJob.relay.renewLease({
|
|
10886
|
-
generation:
|
|
10887
|
-
jobId:
|
|
10888
|
-
leaseSeconds,
|
|
10889
|
-
leaseToken:
|
|
11517
|
+
const response = await activeJob.relay.renewLease({
|
|
11518
|
+
generation: activeJob.claim.generation,
|
|
11519
|
+
jobId: activeJob.claim.jobId,
|
|
11520
|
+
leaseSeconds: this.leaseSeconds,
|
|
11521
|
+
leaseToken: activeJob.claim.leaseToken,
|
|
10890
11522
|
protocolVersion: machineProtocolVersion,
|
|
10891
|
-
runToken:
|
|
11523
|
+
runToken: activeJob.claim.runToken
|
|
10892
11524
|
});
|
|
11525
|
+
const leaseExpiresAt = Date.parse(response.leaseExpiresAt);
|
|
11526
|
+
if (!Number.isFinite(leaseExpiresAt) || leaseExpiresAt <= Date.now()) {
|
|
11527
|
+
throw new Error("Relay returned an invalid lease deadline");
|
|
11528
|
+
}
|
|
11529
|
+
activeJob.leaseExpiresAt = leaseExpiresAt;
|
|
11530
|
+
retryMilliseconds = this.networkRetryMilliseconds;
|
|
10893
11531
|
} catch (error) {
|
|
10894
|
-
await this.logger.error(`Lease renewal failed for Job ${
|
|
11532
|
+
await this.logger.error(`Lease renewal failed for Job ${activeJob.claim.jobId}`, error);
|
|
11533
|
+
if (isPermanentRelayFailure(error)) {
|
|
11534
|
+
await activeJob.cancellation.request(ExecutionCancellationReason.LeaseLost);
|
|
11535
|
+
return;
|
|
11536
|
+
}
|
|
11537
|
+
const retryBudget = activeJob.leaseExpiresAt - Date.now() - this.leaseSafetyMarginMilliseconds;
|
|
11538
|
+
if (retryBudget <= 0) {
|
|
11539
|
+
await activeJob.cancellation.request(ExecutionCancellationReason.LeaseLost);
|
|
11540
|
+
return;
|
|
11541
|
+
}
|
|
11542
|
+
await this.waitUntilStop(Math.min(retryMilliseconds, retryBudget));
|
|
11543
|
+
retryMilliseconds = Math.min(retryMilliseconds * 2, maximumTerminalRetryMilliseconds);
|
|
10895
11544
|
}
|
|
10896
11545
|
}
|
|
10897
11546
|
}
|
|
10898
|
-
async
|
|
10899
|
-
|
|
10900
|
-
|
|
10901
|
-
|
|
10902
|
-
|
|
10903
|
-
|
|
10904
|
-
|
|
10905
|
-
|
|
10906
|
-
|
|
10907
|
-
|
|
10908
|
-
|
|
10909
|
-
|
|
10910
|
-
|
|
10911
|
-
|
|
10912
|
-
|
|
10913
|
-
|
|
10914
|
-
|
|
10915
|
-
|
|
10916
|
-
|
|
10917
|
-
|
|
10918
|
-
|
|
10919
|
-
|
|
10920
|
-
|
|
10921
|
-
|
|
10922
|
-
|
|
10923
|
-
|
|
10924
|
-
|
|
10925
|
-
|
|
10926
|
-
|
|
11547
|
+
async tryUploadTerminal(activeJob, budgetMilliseconds) {
|
|
11548
|
+
if (this.stopping) {
|
|
11549
|
+
return TerminalUploadOutcome.RetryableFailure;
|
|
11550
|
+
}
|
|
11551
|
+
const deadline = budgetMilliseconds === void 0 ? void 0 : Date.now() + budgetMilliseconds;
|
|
11552
|
+
try {
|
|
11553
|
+
await this.flushAllEvents(activeJob, deadline);
|
|
11554
|
+
const job = this.requireDurableJob(activeJob).snapshot();
|
|
11555
|
+
if (!job.finalStatus) {
|
|
11556
|
+
throw new Error(`Job ${job.claim.jobId} has no terminal status`);
|
|
11557
|
+
}
|
|
11558
|
+
await withDeadline(activeJob.relay.updateJob({
|
|
11559
|
+
exitCode: job.finalExitCode,
|
|
11560
|
+
failureCode: job.finalFailureCode,
|
|
11561
|
+
failureMessage: job.finalFailureMessage,
|
|
11562
|
+
generation: job.claim.generation,
|
|
11563
|
+
jobId: job.claim.jobId,
|
|
11564
|
+
leaseToken: job.claim.leaseToken,
|
|
11565
|
+
nextStatus: job.finalStatus,
|
|
11566
|
+
outputTruncated: job.outputTruncated,
|
|
11567
|
+
protocolVersion: machineProtocolVersion,
|
|
11568
|
+
result: job.finalResult,
|
|
11569
|
+
runToken: job.claim.runToken,
|
|
11570
|
+
threadId: job.finalThreadId
|
|
11571
|
+
}), deadline);
|
|
11572
|
+
return TerminalUploadOutcome.Uploaded;
|
|
11573
|
+
} catch (error) {
|
|
11574
|
+
await this.logger.error(`Terminal upload failed for Job ${activeJob.claim.jobId}`, error);
|
|
11575
|
+
return isPermanentRelayFailure(error) ? TerminalUploadOutcome.PermanentFailure : TerminalUploadOutcome.RetryableFailure;
|
|
11576
|
+
}
|
|
11577
|
+
}
|
|
11578
|
+
async retryTerminalUpload(activeJob) {
|
|
11579
|
+
let retryMilliseconds = this.networkRetryMilliseconds;
|
|
11580
|
+
while (!this.stopping) {
|
|
11581
|
+
const jitteredDelay = retryMilliseconds * (0.75 + this.random() * 0.5);
|
|
11582
|
+
await this.waitUntilStop(jitteredDelay);
|
|
11583
|
+
const outcome = await this.tryUploadTerminal(activeJob);
|
|
11584
|
+
if (outcome === TerminalUploadOutcome.Uploaded || outcome === TerminalUploadOutcome.PermanentFailure) {
|
|
11585
|
+
await this.requireDurableJob(activeJob).markUploaded();
|
|
11586
|
+
return;
|
|
10927
11587
|
}
|
|
11588
|
+
retryMilliseconds = Math.min(retryMilliseconds * 2, maximumTerminalRetryMilliseconds);
|
|
10928
11589
|
}
|
|
10929
|
-
return false;
|
|
10930
11590
|
}
|
|
10931
|
-
async
|
|
10932
|
-
|
|
10933
|
-
|
|
11591
|
+
async finishTerminalUpload(activeJob) {
|
|
11592
|
+
const outcome = await this.tryUploadTerminal(activeJob, this.terminalForegroundBudgetMilliseconds);
|
|
11593
|
+
if (outcome === TerminalUploadOutcome.Uploaded || outcome === TerminalUploadOutcome.PermanentFailure) {
|
|
11594
|
+
await this.requireDurableJob(activeJob).markUploaded();
|
|
11595
|
+
return;
|
|
11596
|
+
}
|
|
11597
|
+
void this.retryTerminalUpload(activeJob);
|
|
11598
|
+
}
|
|
11599
|
+
async flushAllEvents(activeJob, deadline) {
|
|
11600
|
+
const durableJob = this.requireDurableJob(activeJob);
|
|
11601
|
+
while (durableJob.pendingEvents().length > 0) {
|
|
11602
|
+
await withDeadline(this.flushEvents(activeJob), deadline);
|
|
10934
11603
|
}
|
|
10935
11604
|
}
|
|
10936
11605
|
async tryFlushEvents(activeJob) {
|
|
10937
11606
|
try {
|
|
10938
11607
|
await this.flushEvents(activeJob);
|
|
10939
11608
|
} catch (error) {
|
|
10940
|
-
await this.logger.error(`Event upload failed for Job ${activeJob.
|
|
11609
|
+
await this.logger.error(`Event upload failed for Job ${activeJob.claim.jobId}`, error);
|
|
10941
11610
|
}
|
|
10942
11611
|
}
|
|
10943
11612
|
async flushEvents(activeJob) {
|
|
@@ -10948,23 +11617,23 @@ var init_daemon = __esm({
|
|
|
10948
11617
|
await nextUpload;
|
|
10949
11618
|
}
|
|
10950
11619
|
async flushPendingEvents(activeJob) {
|
|
10951
|
-
const
|
|
11620
|
+
const durableJob = this.requireDurableJob(activeJob);
|
|
11621
|
+
const events = durableJob.pendingEvents();
|
|
10952
11622
|
if (events.length === 0) {
|
|
10953
11623
|
return;
|
|
10954
11624
|
}
|
|
10955
|
-
const job =
|
|
11625
|
+
const job = durableJob.snapshot();
|
|
11626
|
+
const previousAcknowledgement = job.acknowledgedSequence;
|
|
10956
11627
|
const response = await activeJob.relay.appendEvents(job.claim.jobId, job.claim.generation, job.claim.leaseToken, job.claim.runToken, machineProtocolVersion, events);
|
|
10957
|
-
|
|
10958
|
-
|
|
10959
|
-
|
|
10960
|
-
|
|
10961
|
-
await this.reportRunning(activeJob);
|
|
10962
|
-
} catch (error) {
|
|
10963
|
-
await this.logger.error(`Running state upload failed for Job ${activeJob.durableJob.snapshot().claim.jobId}`, error);
|
|
11628
|
+
const acknowledgedSequence = response.acknowledgedSequence;
|
|
11629
|
+
const maximumSentSequence = events.at(-1)?.sequence;
|
|
11630
|
+
if (!Number.isInteger(acknowledgedSequence) || maximumSentSequence === void 0 || acknowledgedSequence <= previousAcknowledgement || acknowledgedSequence > maximumSentSequence) {
|
|
11631
|
+
throw new Error(`Relay did not advance event acknowledgement for Job ${job.claim.jobId}`);
|
|
10964
11632
|
}
|
|
11633
|
+
await durableJob.acknowledge(acknowledgedSequence);
|
|
10965
11634
|
}
|
|
10966
11635
|
async reportRunning(activeJob) {
|
|
10967
|
-
const job = activeJob.
|
|
11636
|
+
const job = this.requireDurableJob(activeJob).snapshot();
|
|
10968
11637
|
await activeJob.relay.updateJob({
|
|
10969
11638
|
generation: job.claim.generation,
|
|
10970
11639
|
jobId: job.claim.jobId,
|
|
@@ -10975,14 +11644,33 @@ var init_daemon = __esm({
|
|
|
10975
11644
|
runToken: job.claim.runToken
|
|
10976
11645
|
});
|
|
10977
11646
|
}
|
|
11647
|
+
async confirmRunning(activeJob) {
|
|
11648
|
+
let retryMilliseconds = this.networkRetryMilliseconds;
|
|
11649
|
+
while (!this.stopping && activeJob.cancellation.currentReason() === void 0) {
|
|
11650
|
+
try {
|
|
11651
|
+
await this.reportRunning(activeJob);
|
|
11652
|
+
return true;
|
|
11653
|
+
} catch (error) {
|
|
11654
|
+
await this.logger.error(`Running state upload failed for Job ${activeJob.claim.jobId}`, error);
|
|
11655
|
+
if (isPermanentRelayFailure(error) || activeJob.leaseExpiresAt - Date.now() - this.leaseSafetyMarginMilliseconds <= 0) {
|
|
11656
|
+
await activeJob.cancellation.request(ExecutionCancellationReason.LeaseLost);
|
|
11657
|
+
return false;
|
|
11658
|
+
}
|
|
11659
|
+
const retryBudget = activeJob.leaseExpiresAt - Date.now() - this.leaseSafetyMarginMilliseconds;
|
|
11660
|
+
await Promise.race([
|
|
11661
|
+
this.waitUntilStop(Math.min(retryMilliseconds, retryBudget)),
|
|
11662
|
+
activeJob.cancellation.wait()
|
|
11663
|
+
]);
|
|
11664
|
+
retryMilliseconds = Math.min(retryMilliseconds * 2, maximumTerminalRetryMilliseconds);
|
|
11665
|
+
}
|
|
11666
|
+
}
|
|
11667
|
+
return false;
|
|
11668
|
+
}
|
|
10978
11669
|
async handleControl(relay, command) {
|
|
10979
11670
|
const activeJob = this.activeJobs.get(command.jobId);
|
|
10980
11671
|
let outcome = MachineJobStatus.Interrupted;
|
|
10981
11672
|
if (activeJob) {
|
|
10982
|
-
activeJob.
|
|
10983
|
-
if (activeJob.handle) {
|
|
10984
|
-
await activeJob.handle.cancel();
|
|
10985
|
-
}
|
|
11673
|
+
await activeJob.cancellation.request(ExecutionCancellationReason.Requested);
|
|
10986
11674
|
outcome = MachineJobStatus.Cancelled;
|
|
10987
11675
|
}
|
|
10988
11676
|
await relay.acknowledgeControl({
|
|
@@ -10991,18 +11679,12 @@ var init_daemon = __esm({
|
|
|
10991
11679
|
protocolVersion: machineProtocolVersion
|
|
10992
11680
|
});
|
|
10993
11681
|
}
|
|
10994
|
-
|
|
10995
|
-
|
|
10996
|
-
|
|
10997
|
-
|
|
10998
|
-
|
|
10999
|
-
while (Date.now() < deadline) {
|
|
11000
|
-
if (this.stopping || activeJob.durableJob.snapshot().phase === PersistedMachineJobPhase.TerminalPendingUpload) {
|
|
11001
|
-
return false;
|
|
11002
|
-
}
|
|
11003
|
-
await delay3(Math.min(250, deadline - Date.now()));
|
|
11682
|
+
async waitForExecutionTasks() {
|
|
11683
|
+
while (this.executionTasks.size > 0) {
|
|
11684
|
+
await Promise.all([...this.executionTasks].map(async (executionTask) => {
|
|
11685
|
+
await executionTask.catch(() => void 0);
|
|
11686
|
+
}));
|
|
11004
11687
|
}
|
|
11005
|
-
return !this.stopping;
|
|
11006
11688
|
}
|
|
11007
11689
|
async waitUntilStop(milliseconds) {
|
|
11008
11690
|
const deadline = Date.now() + milliseconds;
|
|
@@ -11010,6 +11692,27 @@ var init_daemon = __esm({
|
|
|
11010
11692
|
await delay3(Math.min(250, deadline - Date.now()));
|
|
11011
11693
|
}
|
|
11012
11694
|
}
|
|
11695
|
+
cancellationResult(activeJob) {
|
|
11696
|
+
const reason = activeJob.cancellation.currentReason();
|
|
11697
|
+
if (reason === ExecutionCancellationReason.LeaseLost) {
|
|
11698
|
+
return {
|
|
11699
|
+
exitCode: -1,
|
|
11700
|
+
failureCode: "lease_lost",
|
|
11701
|
+
failureMessage: "Connector stopped local execution after losing the Job lease",
|
|
11702
|
+
status: MachineJobStatus.Interrupted
|
|
11703
|
+
};
|
|
11704
|
+
}
|
|
11705
|
+
return {
|
|
11706
|
+
exitCode: -1,
|
|
11707
|
+
status: MachineJobStatus.Cancelled
|
|
11708
|
+
};
|
|
11709
|
+
}
|
|
11710
|
+
requireDurableJob(activeJob) {
|
|
11711
|
+
if (!activeJob.durableJob) {
|
|
11712
|
+
throw new Error(`Job ${activeJob.claim.jobId} is not durably initialized`);
|
|
11713
|
+
}
|
|
11714
|
+
return activeJob.durableJob;
|
|
11715
|
+
}
|
|
11013
11716
|
async recoverInterruptedJobs() {
|
|
11014
11717
|
const jobs = await this.store.listJobs();
|
|
11015
11718
|
for (const job of jobs) {
|
|
@@ -11031,20 +11734,18 @@ var init_daemon = __esm({
|
|
|
11031
11734
|
});
|
|
11032
11735
|
}
|
|
11033
11736
|
const activeJob = {
|
|
11034
|
-
|
|
11737
|
+
cancellation: new ExecutionCancellation(),
|
|
11738
|
+
claim: job.claim,
|
|
11035
11739
|
connection,
|
|
11036
11740
|
durableJob,
|
|
11037
11741
|
eventUploadQueue: Promise.resolve(),
|
|
11742
|
+
leaseExpiresAt: Date.parse(job.claim.leaseExpiresAt),
|
|
11038
11743
|
relay
|
|
11039
11744
|
};
|
|
11040
|
-
|
|
11041
|
-
|
|
11042
|
-
|
|
11043
|
-
|
|
11044
|
-
}
|
|
11045
|
-
}).finally(() => {
|
|
11046
|
-
this.activeJobs.delete(job.claim.jobId);
|
|
11047
|
-
});
|
|
11745
|
+
if (job.finalStatus === MachineJobStatus.Cancelled) {
|
|
11746
|
+
await activeJob.cancellation.request(ExecutionCancellationReason.Requested);
|
|
11747
|
+
}
|
|
11748
|
+
void this.retryTerminalUpload(activeJob);
|
|
11048
11749
|
}
|
|
11049
11750
|
}
|
|
11050
11751
|
};
|
|
@@ -11076,7 +11777,7 @@ async function runMachineDoctor(store) {
|
|
|
11076
11777
|
}
|
|
11077
11778
|
for (const connection of connections) {
|
|
11078
11779
|
try {
|
|
11079
|
-
await (0,
|
|
11780
|
+
await (0, import_promises7.access)(connection.rootPath, import_node_fs5.constants.R_OK | import_node_fs5.constants.X_OK);
|
|
11080
11781
|
checks.push({
|
|
11081
11782
|
detail: connection.rootPath,
|
|
11082
11783
|
name: `root:${connection.connectionId}`,
|
|
@@ -11091,7 +11792,7 @@ async function runMachineDoctor(store) {
|
|
|
11091
11792
|
}
|
|
11092
11793
|
const relayUrl = new URL(connection.relayOrigin);
|
|
11093
11794
|
try {
|
|
11094
|
-
const address = await (0,
|
|
11795
|
+
const address = await (0, import_promises8.lookup)(relayUrl.hostname);
|
|
11095
11796
|
checks.push({
|
|
11096
11797
|
detail: `${relayUrl.hostname} resolves to ${address.address}`,
|
|
11097
11798
|
name: `dns:${connection.connectionId}`,
|
|
@@ -11154,20 +11855,34 @@ async function runMachineDoctor(store) {
|
|
|
11154
11855
|
status: DoctorCheckStatus.Warning
|
|
11155
11856
|
});
|
|
11156
11857
|
}
|
|
11858
|
+
try {
|
|
11859
|
+
const result = await execFileAsync(process.env.MOXT_CLAUDE_PATH ?? "claude", ["--version"]);
|
|
11860
|
+
checks.push({
|
|
11861
|
+
detail: result.stdout.trim(),
|
|
11862
|
+
name: "claude",
|
|
11863
|
+
status: DoctorCheckStatus.Passed
|
|
11864
|
+
});
|
|
11865
|
+
} catch (error) {
|
|
11866
|
+
checks.push({
|
|
11867
|
+
detail: errorMessage(error),
|
|
11868
|
+
name: "claude",
|
|
11869
|
+
status: DoctorCheckStatus.Warning
|
|
11870
|
+
});
|
|
11871
|
+
}
|
|
11157
11872
|
return checks;
|
|
11158
11873
|
}
|
|
11159
11874
|
function errorMessage(error) {
|
|
11160
11875
|
return error instanceof Error ? error.message : String(error);
|
|
11161
11876
|
}
|
|
11162
|
-
var import_node_child_process3,
|
|
11877
|
+
var import_node_child_process3, import_promises7, import_node_fs5, import_promises8, import_node_util4, execFileAsync, DoctorCheckStatus;
|
|
11163
11878
|
var init_doctor = __esm({
|
|
11164
11879
|
"../machine-connector/dist/runtime/doctor.js"() {
|
|
11165
11880
|
"use strict";
|
|
11166
11881
|
init_cjs_shims();
|
|
11167
11882
|
import_node_child_process3 = require("child_process");
|
|
11168
|
-
|
|
11883
|
+
import_promises7 = require("fs/promises");
|
|
11169
11884
|
import_node_fs5 = require("fs");
|
|
11170
|
-
|
|
11885
|
+
import_promises8 = require("dns/promises");
|
|
11171
11886
|
import_node_util4 = require("util");
|
|
11172
11887
|
init_local_ipc();
|
|
11173
11888
|
execFileAsync = (0, import_node_util4.promisify)(import_node_child_process3.execFile);
|
|
@@ -11179,6 +11894,673 @@ var init_doctor = __esm({
|
|
|
11179
11894
|
}
|
|
11180
11895
|
});
|
|
11181
11896
|
|
|
11897
|
+
// ../machine-connector/dist/runtime/machine-manager.js
|
|
11898
|
+
function machineManagerActions() {
|
|
11899
|
+
return [
|
|
11900
|
+
{
|
|
11901
|
+
action: MachineManagerAction.Refresh,
|
|
11902
|
+
label: "Refresh now"
|
|
11903
|
+
},
|
|
11904
|
+
{
|
|
11905
|
+
action: MachineManagerAction.Connect,
|
|
11906
|
+
label: "Pair a new machine connection"
|
|
11907
|
+
},
|
|
11908
|
+
{
|
|
11909
|
+
action: MachineManagerAction.Disconnect,
|
|
11910
|
+
label: "Disconnect the selected connection"
|
|
11911
|
+
},
|
|
11912
|
+
{
|
|
11913
|
+
action: MachineManagerAction.Doctor,
|
|
11914
|
+
label: "Run diagnostics"
|
|
11915
|
+
},
|
|
11916
|
+
{
|
|
11917
|
+
action: MachineManagerAction.Logs,
|
|
11918
|
+
label: "Open recent logs"
|
|
11919
|
+
},
|
|
11920
|
+
{
|
|
11921
|
+
action: MachineManagerAction.ServiceInstall,
|
|
11922
|
+
label: "Install the Connector service"
|
|
11923
|
+
},
|
|
11924
|
+
{
|
|
11925
|
+
action: MachineManagerAction.ServiceRestart,
|
|
11926
|
+
label: "Restart the Connector service"
|
|
11927
|
+
},
|
|
11928
|
+
{
|
|
11929
|
+
action: MachineManagerAction.ServiceStop,
|
|
11930
|
+
label: "Stop the Connector service"
|
|
11931
|
+
},
|
|
11932
|
+
{
|
|
11933
|
+
action: MachineManagerAction.ServiceUninstall,
|
|
11934
|
+
label: "Uninstall the Connector service"
|
|
11935
|
+
},
|
|
11936
|
+
{
|
|
11937
|
+
action: MachineManagerAction.Quit,
|
|
11938
|
+
label: "Quit"
|
|
11939
|
+
}
|
|
11940
|
+
];
|
|
11941
|
+
}
|
|
11942
|
+
function ensureInteractiveTerminal(inputIsTty, outputIsTty) {
|
|
11943
|
+
if (!inputIsTty || !outputIsTty) {
|
|
11944
|
+
throw new Error("moxt machine manager requires an interactive TTY. Use `moxt machine status`, `logs`, or `doctor` in non-interactive scripts.");
|
|
11945
|
+
}
|
|
11946
|
+
}
|
|
11947
|
+
async function collectMachineManagerSnapshot(store, depth) {
|
|
11948
|
+
const connections = await store.listConnections();
|
|
11949
|
+
const jobs = await store.listJobs();
|
|
11950
|
+
const serviceManager = (await store.readServiceManager()).value;
|
|
11951
|
+
const runtime = {};
|
|
11952
|
+
try {
|
|
11953
|
+
runtime.value = (await requestRuntimeStatus(store)).status;
|
|
11954
|
+
} catch {
|
|
11955
|
+
runtime.value = void 0;
|
|
11956
|
+
}
|
|
11957
|
+
const checks = depth === MachineManagerSnapshotDepth.WithDoctor ? await runMachineDoctor(store) : [];
|
|
11958
|
+
return {
|
|
11959
|
+
checks,
|
|
11960
|
+
connections: connections.map(toManagerConnection),
|
|
11961
|
+
jobs: jobs.map(toManagerJob).sort((left, right) => right.updatedAt.localeCompare(left.updatedAt)),
|
|
11962
|
+
logLines: await readRecentLogLines(store),
|
|
11963
|
+
refreshedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
11964
|
+
runtime: runtime.value,
|
|
11965
|
+
serviceManager: serviceManager?.manager
|
|
11966
|
+
};
|
|
11967
|
+
}
|
|
11968
|
+
function renderMachineManager(snapshot, state, requestedWidth, requestedHeight) {
|
|
11969
|
+
const width = Math.max(24, requestedWidth);
|
|
11970
|
+
const height = Math.max(8, requestedHeight);
|
|
11971
|
+
const lines = [];
|
|
11972
|
+
const online = snapshot.runtime !== void 0;
|
|
11973
|
+
lines.push(styledLine(` MOXT MACHINE MANAGER ${online ? "ONLINE" : "OFFLINE"} ${snapshot.serviceManager ?? "no service"}`, width, styleHeader));
|
|
11974
|
+
lines.push(fitLine(renderTabs(state.view), width));
|
|
11975
|
+
lines.push(repeatCharacter("\u2500", width));
|
|
11976
|
+
const contentHeight = Math.max(1, height - 5);
|
|
11977
|
+
const content = state.actionMenuOpen ? renderActions(state) : renderView(snapshot, state);
|
|
11978
|
+
for (const line of content.slice(0, contentHeight)) {
|
|
11979
|
+
lines.push(fitLine(line, width));
|
|
11980
|
+
}
|
|
11981
|
+
while (lines.length < height - 2) {
|
|
11982
|
+
lines.push(" ".repeat(width));
|
|
11983
|
+
}
|
|
11984
|
+
lines.push(repeatCharacter("\u2500", width));
|
|
11985
|
+
lines.push(fitLine(state.message ?? "[A] Actions [Tab/1-5] View [Up/Down] Select [R] Refresh [Q] Quit", width));
|
|
11986
|
+
return lines.slice(0, height).join("\n");
|
|
11987
|
+
}
|
|
11988
|
+
async function runMachineManager(store, commandRunner) {
|
|
11989
|
+
ensureInteractiveTerminal(Boolean(process.stdin.isTTY), Boolean(process.stdout.isTTY));
|
|
11990
|
+
const manager = new InteractiveMachineManager(store, commandRunner);
|
|
11991
|
+
await manager.run();
|
|
11992
|
+
}
|
|
11993
|
+
function renderTabs(selected) {
|
|
11994
|
+
const labels = [
|
|
11995
|
+
"1 Overview",
|
|
11996
|
+
"2 Connections",
|
|
11997
|
+
"3 Jobs",
|
|
11998
|
+
"4 Logs",
|
|
11999
|
+
"5 Doctor"
|
|
12000
|
+
];
|
|
12001
|
+
return labels.map((label, index) => index === selected ? `[${label}]` : ` ${label} `).join(" ");
|
|
12002
|
+
}
|
|
12003
|
+
function renderView(snapshot, state) {
|
|
12004
|
+
if (state.view === MachineManagerView.Overview) {
|
|
12005
|
+
return renderOverview(snapshot);
|
|
12006
|
+
}
|
|
12007
|
+
if (state.view === MachineManagerView.Connections) {
|
|
12008
|
+
return renderConnections(snapshot, state.selectedRowIndex);
|
|
12009
|
+
}
|
|
12010
|
+
if (state.view === MachineManagerView.Jobs) {
|
|
12011
|
+
return renderJobs(snapshot, state.selectedRowIndex);
|
|
12012
|
+
}
|
|
12013
|
+
if (state.view === MachineManagerView.Logs) {
|
|
12014
|
+
return renderLogs(snapshot);
|
|
12015
|
+
}
|
|
12016
|
+
return renderDoctor(snapshot);
|
|
12017
|
+
}
|
|
12018
|
+
function renderOverview(snapshot) {
|
|
12019
|
+
const runtime = snapshot.runtime;
|
|
12020
|
+
const lines = [
|
|
12021
|
+
"",
|
|
12022
|
+
` Daemon ${runtime ? `ONLINE PID ${runtime.pid} v${runtime.version}` : "OFFLINE"}`,
|
|
12023
|
+
` Service ${snapshot.serviceManager ?? "not installed"}`,
|
|
12024
|
+
` Connections ${snapshot.connections.length}`,
|
|
12025
|
+
` Active Jobs ${runtime?.activeJobs.length ?? 0}`,
|
|
12026
|
+
` Stored Jobs ${snapshot.jobs.length}`,
|
|
12027
|
+
` Refreshed ${formatTimestamp(snapshot.refreshedAt)}`,
|
|
12028
|
+
""
|
|
12029
|
+
];
|
|
12030
|
+
if (snapshot.connections.length === 0) {
|
|
12031
|
+
lines.push(' No connections. Press A and choose "Pair a new machine connection".');
|
|
12032
|
+
return lines;
|
|
12033
|
+
}
|
|
12034
|
+
lines.push(" Connected roots");
|
|
12035
|
+
for (const connection of snapshot.connections) {
|
|
12036
|
+
lines.push(` ${connection.machineName} ${connection.rootPath}`);
|
|
12037
|
+
}
|
|
12038
|
+
return lines;
|
|
12039
|
+
}
|
|
12040
|
+
function renderConnections(snapshot, selectedRowIndex) {
|
|
12041
|
+
if (snapshot.connections.length === 0) {
|
|
12042
|
+
return ["", " No connections", " Press A to pair a machine."];
|
|
12043
|
+
}
|
|
12044
|
+
const lines = [
|
|
12045
|
+
" MACHINE ROOT WORKSPACE / TARGET"
|
|
12046
|
+
];
|
|
12047
|
+
snapshot.connections.forEach((connection, index) => {
|
|
12048
|
+
const marker = index === selectedRowIndex ? ">" : " ";
|
|
12049
|
+
lines.push(`${marker} ${connection.machineName} ${connection.rootPath} ${connection.workspaceId} / ${connection.targetId}`);
|
|
12050
|
+
lines.push(` ${connection.connectionId} ${connection.relayOrigin}`);
|
|
12051
|
+
});
|
|
12052
|
+
return lines;
|
|
12053
|
+
}
|
|
12054
|
+
function renderJobs(snapshot, selectedRowIndex) {
|
|
12055
|
+
if (snapshot.jobs.length === 0) {
|
|
12056
|
+
return ["", " No Jobs have been stored on this machine."];
|
|
12057
|
+
}
|
|
12058
|
+
const lines = [" STATUS KIND JOB / COMMAND"];
|
|
12059
|
+
snapshot.jobs.forEach((job, index) => {
|
|
12060
|
+
const marker = index === selectedRowIndex ? ">" : " ";
|
|
12061
|
+
lines.push(`${marker} ${job.status ?? job.phase} ${job.kind} ${job.command ?? job.jobId}`);
|
|
12062
|
+
lines.push(` ${job.jobId} ${job.relativeWorkingDirectory} ${formatTimestamp(job.updatedAt)}`);
|
|
12063
|
+
});
|
|
12064
|
+
return lines;
|
|
12065
|
+
}
|
|
12066
|
+
function renderLogs(snapshot) {
|
|
12067
|
+
if (snapshot.logLines.length === 0) {
|
|
12068
|
+
return ["", " No Connector logs are available."];
|
|
12069
|
+
}
|
|
12070
|
+
return snapshot.logLines.map((line) => ` ${line}`);
|
|
12071
|
+
}
|
|
12072
|
+
function renderDoctor(snapshot) {
|
|
12073
|
+
if (snapshot.checks.length === 0) {
|
|
12074
|
+
return [
|
|
12075
|
+
"",
|
|
12076
|
+
" Diagnostics have not run yet.",
|
|
12077
|
+
' Press A and choose "Run diagnostics".'
|
|
12078
|
+
];
|
|
12079
|
+
}
|
|
12080
|
+
return snapshot.checks.map((check) => ` ${check.status.padEnd(7)} ${check.name}: ${check.detail}`);
|
|
12081
|
+
}
|
|
12082
|
+
function renderActions(state) {
|
|
12083
|
+
const lines = [
|
|
12084
|
+
" Actions",
|
|
12085
|
+
" Use Up/Down and Enter. Esc closes this menu.",
|
|
12086
|
+
""
|
|
12087
|
+
];
|
|
12088
|
+
machineManagerActions().forEach((definition, index) => {
|
|
12089
|
+
const selected = index === state.selectedActionIndex;
|
|
12090
|
+
const line = `${selected ? ">" : " "} ${definition.label}`;
|
|
12091
|
+
lines.push(selected ? `${styleSelected}${line}${styleReset}` : line);
|
|
12092
|
+
});
|
|
12093
|
+
return lines;
|
|
12094
|
+
}
|
|
12095
|
+
function rowCountForView(snapshot, view) {
|
|
12096
|
+
if (view === MachineManagerView.Connections) {
|
|
12097
|
+
return snapshot.connections.length;
|
|
12098
|
+
}
|
|
12099
|
+
if (view === MachineManagerView.Jobs) {
|
|
12100
|
+
return snapshot.jobs.length;
|
|
12101
|
+
}
|
|
12102
|
+
return 0;
|
|
12103
|
+
}
|
|
12104
|
+
function toManagerConnection(connection) {
|
|
12105
|
+
return {
|
|
12106
|
+
connectionId: connection.connectionId,
|
|
12107
|
+
machineName: connection.machineName,
|
|
12108
|
+
relayOrigin: connection.relayOrigin,
|
|
12109
|
+
rootDisplayName: connection.rootDisplayName,
|
|
12110
|
+
rootPath: connection.rootPath,
|
|
12111
|
+
targetId: connection.targetId,
|
|
12112
|
+
targetKind: connection.targetKind,
|
|
12113
|
+
workspaceId: connection.workspaceId
|
|
12114
|
+
};
|
|
12115
|
+
}
|
|
12116
|
+
function toManagerJob(job) {
|
|
12117
|
+
return {
|
|
12118
|
+
command: formatPersistedCommand(job).value,
|
|
12119
|
+
connectionId: job.connectionId,
|
|
12120
|
+
jobId: job.claim.jobId,
|
|
12121
|
+
kind: job.claim.kind,
|
|
12122
|
+
phase: job.phase,
|
|
12123
|
+
relativeWorkingDirectory: job.claim.relativeWorkingDirectory,
|
|
12124
|
+
status: job.finalStatus,
|
|
12125
|
+
updatedAt: job.updatedAt
|
|
12126
|
+
};
|
|
12127
|
+
}
|
|
12128
|
+
function formatPersistedCommand(job) {
|
|
12129
|
+
if (job.claim.kind !== "command") {
|
|
12130
|
+
return {};
|
|
12131
|
+
}
|
|
12132
|
+
if (!isRecord3(job.claim.requestPayload)) {
|
|
12133
|
+
return {};
|
|
12134
|
+
}
|
|
12135
|
+
const executable = job.claim.requestPayload.executable;
|
|
12136
|
+
const argumentsValue = job.claim.requestPayload.arguments;
|
|
12137
|
+
if (typeof executable !== "string" || !Array.isArray(argumentsValue) || !argumentsValue.every((argument) => typeof argument === "string")) {
|
|
12138
|
+
return {};
|
|
12139
|
+
}
|
|
12140
|
+
return {
|
|
12141
|
+
value: [executable, ...argumentsValue].map(formatCommandArgument).join(" ")
|
|
12142
|
+
};
|
|
12143
|
+
}
|
|
12144
|
+
function formatCommandArgument(value) {
|
|
12145
|
+
return /^[A-Za-z0-9_./:@%+=,-]+$/.test(value) ? value : JSON.stringify(value);
|
|
12146
|
+
}
|
|
12147
|
+
async function readRecentLogLines(store) {
|
|
12148
|
+
const normal = await readOptionalFile(store.runtimeLogPath());
|
|
12149
|
+
const errors = await readOptionalFile(store.runtimeErrorLogPath());
|
|
12150
|
+
return [...normal.split("\n"), ...errors.split("\n")].filter((line) => line.length > 0).slice(-maximumLogLines);
|
|
12151
|
+
}
|
|
12152
|
+
async function readOptionalFile(path10) {
|
|
12153
|
+
try {
|
|
12154
|
+
return await (0, import_promises9.readFile)(path10, "utf8");
|
|
12155
|
+
} catch (error) {
|
|
12156
|
+
if (isMissingFile(error)) {
|
|
12157
|
+
return "";
|
|
12158
|
+
}
|
|
12159
|
+
throw error;
|
|
12160
|
+
}
|
|
12161
|
+
}
|
|
12162
|
+
async function questionWithDefault(reader, label, defaultValue) {
|
|
12163
|
+
const suffix = defaultValue.length > 0 ? ` [${defaultValue}]` : "";
|
|
12164
|
+
const answer = (await reader.question(`${label}${suffix}: `)).trim();
|
|
12165
|
+
return answer.length > 0 ? answer : defaultValue;
|
|
12166
|
+
}
|
|
12167
|
+
function appendOption(argumentsList, name, value) {
|
|
12168
|
+
if (value.length > 0) {
|
|
12169
|
+
argumentsList.push(name, value);
|
|
12170
|
+
}
|
|
12171
|
+
}
|
|
12172
|
+
function styledLine(value, width, style) {
|
|
12173
|
+
return `${style}${fitLine(value, width)}${styleReset}`;
|
|
12174
|
+
}
|
|
12175
|
+
function fitLine(value, width) {
|
|
12176
|
+
const plainValue = stripAnsi2(value);
|
|
12177
|
+
if (plainValue.length > width) {
|
|
12178
|
+
if (width <= 1) {
|
|
12179
|
+
return plainValue.slice(0, width);
|
|
12180
|
+
}
|
|
12181
|
+
return `${plainValue.slice(0, width - 1)}\u2026`;
|
|
12182
|
+
}
|
|
12183
|
+
if (value.includes("\x1B[")) {
|
|
12184
|
+
return value;
|
|
12185
|
+
}
|
|
12186
|
+
return value.padEnd(width);
|
|
12187
|
+
}
|
|
12188
|
+
function stripAnsi2(value) {
|
|
12189
|
+
return value.replaceAll(styleHeader, "").replaceAll(styleSelected, "").replaceAll(styleReset, "");
|
|
12190
|
+
}
|
|
12191
|
+
function repeatCharacter(value, count) {
|
|
12192
|
+
return value.repeat(count);
|
|
12193
|
+
}
|
|
12194
|
+
function wrapIndex(value, count) {
|
|
12195
|
+
return (value % count + count) % count;
|
|
12196
|
+
}
|
|
12197
|
+
function formatTimestamp(value) {
|
|
12198
|
+
const timestamp = Date.parse(value);
|
|
12199
|
+
if (Number.isNaN(timestamp)) {
|
|
12200
|
+
return value;
|
|
12201
|
+
}
|
|
12202
|
+
return new Date(timestamp).toLocaleString();
|
|
12203
|
+
}
|
|
12204
|
+
function isRecord3(value) {
|
|
12205
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12206
|
+
}
|
|
12207
|
+
function isMissingFile(error) {
|
|
12208
|
+
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
12209
|
+
}
|
|
12210
|
+
function errorMessage2(error) {
|
|
12211
|
+
return error instanceof Error ? error.message : String(error);
|
|
12212
|
+
}
|
|
12213
|
+
var import_promises9, import_promises10, import_node_readline, alternateScreenEnter, alternateScreenExit, clearScreen, cursorHide, cursorShow, styleReset, styleHeader, styleSelected, refreshIntervalMilliseconds, maximumLogLines, MachineManagerView, MachineManagerAction, MachineManagerSnapshotDepth, InteractiveMachineManager;
|
|
12214
|
+
var init_machine_manager = __esm({
|
|
12215
|
+
"../machine-connector/dist/runtime/machine-manager.js"() {
|
|
12216
|
+
"use strict";
|
|
12217
|
+
init_cjs_shims();
|
|
12218
|
+
import_promises9 = require("fs/promises");
|
|
12219
|
+
import_promises10 = require("readline/promises");
|
|
12220
|
+
import_node_readline = require("readline");
|
|
12221
|
+
init_doctor();
|
|
12222
|
+
init_local_ipc();
|
|
12223
|
+
alternateScreenEnter = "\x1B[?1049h";
|
|
12224
|
+
alternateScreenExit = "\x1B[?1049l";
|
|
12225
|
+
clearScreen = "\x1B[2J\x1B[H";
|
|
12226
|
+
cursorHide = "\x1B[?25l";
|
|
12227
|
+
cursorShow = "\x1B[?25h";
|
|
12228
|
+
styleReset = "\x1B[0m";
|
|
12229
|
+
styleHeader = "\x1B[1;30;46m";
|
|
12230
|
+
styleSelected = "\x1B[30;47m";
|
|
12231
|
+
refreshIntervalMilliseconds = 1e3;
|
|
12232
|
+
maximumLogLines = 200;
|
|
12233
|
+
(function(MachineManagerView2) {
|
|
12234
|
+
MachineManagerView2[MachineManagerView2["Overview"] = 0] = "Overview";
|
|
12235
|
+
MachineManagerView2[MachineManagerView2["Connections"] = 1] = "Connections";
|
|
12236
|
+
MachineManagerView2[MachineManagerView2["Jobs"] = 2] = "Jobs";
|
|
12237
|
+
MachineManagerView2[MachineManagerView2["Logs"] = 3] = "Logs";
|
|
12238
|
+
MachineManagerView2[MachineManagerView2["Doctor"] = 4] = "Doctor";
|
|
12239
|
+
})(MachineManagerView || (MachineManagerView = {}));
|
|
12240
|
+
(function(MachineManagerAction2) {
|
|
12241
|
+
MachineManagerAction2["Refresh"] = "refresh";
|
|
12242
|
+
MachineManagerAction2["Connect"] = "connect";
|
|
12243
|
+
MachineManagerAction2["Disconnect"] = "disconnect";
|
|
12244
|
+
MachineManagerAction2["Doctor"] = "doctor";
|
|
12245
|
+
MachineManagerAction2["Logs"] = "logs";
|
|
12246
|
+
MachineManagerAction2["ServiceInstall"] = "service_install";
|
|
12247
|
+
MachineManagerAction2["ServiceRestart"] = "service_restart";
|
|
12248
|
+
MachineManagerAction2["ServiceStop"] = "service_stop";
|
|
12249
|
+
MachineManagerAction2["ServiceUninstall"] = "service_uninstall";
|
|
12250
|
+
MachineManagerAction2["Quit"] = "quit";
|
|
12251
|
+
})(MachineManagerAction || (MachineManagerAction = {}));
|
|
12252
|
+
(function(MachineManagerSnapshotDepth2) {
|
|
12253
|
+
MachineManagerSnapshotDepth2["Basic"] = "basic";
|
|
12254
|
+
MachineManagerSnapshotDepth2["WithDoctor"] = "with_doctor";
|
|
12255
|
+
})(MachineManagerSnapshotDepth || (MachineManagerSnapshotDepth = {}));
|
|
12256
|
+
InteractiveMachineManager = class {
|
|
12257
|
+
store;
|
|
12258
|
+
commandRunner;
|
|
12259
|
+
checks = [];
|
|
12260
|
+
refreshTimer;
|
|
12261
|
+
refreshing = false;
|
|
12262
|
+
resolveRun;
|
|
12263
|
+
snapshot = {
|
|
12264
|
+
checks: [],
|
|
12265
|
+
connections: [],
|
|
12266
|
+
jobs: [],
|
|
12267
|
+
logLines: [],
|
|
12268
|
+
refreshedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
12269
|
+
};
|
|
12270
|
+
state = {
|
|
12271
|
+
actionMenuOpen: false,
|
|
12272
|
+
selectedActionIndex: 0,
|
|
12273
|
+
selectedRowIndex: 0,
|
|
12274
|
+
view: MachineManagerView.Overview
|
|
12275
|
+
};
|
|
12276
|
+
stopped = false;
|
|
12277
|
+
terminalSuspended = true;
|
|
12278
|
+
constructor(store, commandRunner) {
|
|
12279
|
+
this.store = store;
|
|
12280
|
+
this.commandRunner = commandRunner;
|
|
12281
|
+
}
|
|
12282
|
+
async run() {
|
|
12283
|
+
await this.refresh(MachineManagerSnapshotDepth.Basic);
|
|
12284
|
+
this.enterTerminal();
|
|
12285
|
+
try {
|
|
12286
|
+
await new Promise((resolvePromise) => {
|
|
12287
|
+
this.resolveRun = resolvePromise;
|
|
12288
|
+
});
|
|
12289
|
+
} finally {
|
|
12290
|
+
this.leaveTerminal();
|
|
12291
|
+
}
|
|
12292
|
+
}
|
|
12293
|
+
enterTerminal() {
|
|
12294
|
+
(0, import_node_readline.emitKeypressEvents)(process.stdin);
|
|
12295
|
+
process.stdin.setRawMode(true);
|
|
12296
|
+
process.stdin.resume();
|
|
12297
|
+
process.stdin.on("keypress", this.onKeypress);
|
|
12298
|
+
process.stdout.on("resize", this.onResize);
|
|
12299
|
+
process.on("SIGINT", this.onTerminationSignal);
|
|
12300
|
+
process.on("SIGTERM", this.onTerminationSignal);
|
|
12301
|
+
process.stdout.write(`${alternateScreenEnter}${cursorHide}${clearScreen}`);
|
|
12302
|
+
this.terminalSuspended = false;
|
|
12303
|
+
this.refreshTimer = setInterval(() => {
|
|
12304
|
+
void this.refresh(MachineManagerSnapshotDepth.Basic);
|
|
12305
|
+
}, refreshIntervalMilliseconds);
|
|
12306
|
+
this.render();
|
|
12307
|
+
}
|
|
12308
|
+
leaveTerminal() {
|
|
12309
|
+
if (this.refreshTimer) {
|
|
12310
|
+
clearInterval(this.refreshTimer);
|
|
12311
|
+
this.refreshTimer = void 0;
|
|
12312
|
+
}
|
|
12313
|
+
process.stdin.off("keypress", this.onKeypress);
|
|
12314
|
+
process.stdout.off("resize", this.onResize);
|
|
12315
|
+
process.off("SIGINT", this.onTerminationSignal);
|
|
12316
|
+
process.off("SIGTERM", this.onTerminationSignal);
|
|
12317
|
+
if (process.stdin.isTTY) {
|
|
12318
|
+
process.stdin.setRawMode(false);
|
|
12319
|
+
}
|
|
12320
|
+
process.stdin.pause();
|
|
12321
|
+
process.stdout.write(`${cursorShow}${styleReset}${alternateScreenExit}`);
|
|
12322
|
+
}
|
|
12323
|
+
onResize = () => {
|
|
12324
|
+
this.render();
|
|
12325
|
+
};
|
|
12326
|
+
onTerminationSignal = () => {
|
|
12327
|
+
this.stop();
|
|
12328
|
+
};
|
|
12329
|
+
onKeypress = (text, key) => {
|
|
12330
|
+
if (key.ctrl && key.name === "c") {
|
|
12331
|
+
this.stop();
|
|
12332
|
+
return;
|
|
12333
|
+
}
|
|
12334
|
+
if (key.name === "q" || text === "q") {
|
|
12335
|
+
this.stop();
|
|
12336
|
+
return;
|
|
12337
|
+
}
|
|
12338
|
+
if (key.name === "a" || text === "a" || text === "?") {
|
|
12339
|
+
this.state.actionMenuOpen = !this.state.actionMenuOpen;
|
|
12340
|
+
this.state.message = void 0;
|
|
12341
|
+
this.render();
|
|
12342
|
+
return;
|
|
12343
|
+
}
|
|
12344
|
+
if (key.name === "escape") {
|
|
12345
|
+
this.state.actionMenuOpen = false;
|
|
12346
|
+
this.render();
|
|
12347
|
+
return;
|
|
12348
|
+
}
|
|
12349
|
+
if (key.name === "up") {
|
|
12350
|
+
this.moveSelection(-1);
|
|
12351
|
+
return;
|
|
12352
|
+
}
|
|
12353
|
+
if (key.name === "down") {
|
|
12354
|
+
this.moveSelection(1);
|
|
12355
|
+
return;
|
|
12356
|
+
}
|
|
12357
|
+
if (key.name === "return" && this.state.actionMenuOpen) {
|
|
12358
|
+
void this.executeSelectedAction();
|
|
12359
|
+
return;
|
|
12360
|
+
}
|
|
12361
|
+
if (key.name === "tab" || key.name === "right") {
|
|
12362
|
+
this.changeView(1);
|
|
12363
|
+
return;
|
|
12364
|
+
}
|
|
12365
|
+
if (key.name === "left") {
|
|
12366
|
+
this.changeView(-1);
|
|
12367
|
+
return;
|
|
12368
|
+
}
|
|
12369
|
+
if (text === "r") {
|
|
12370
|
+
void this.refresh(MachineManagerSnapshotDepth.Basic);
|
|
12371
|
+
return;
|
|
12372
|
+
}
|
|
12373
|
+
const viewNumber = Number(text);
|
|
12374
|
+
if (Number.isInteger(viewNumber) && viewNumber >= 1 && viewNumber <= 5) {
|
|
12375
|
+
this.state.view = viewNumber - 1;
|
|
12376
|
+
this.state.selectedRowIndex = 0;
|
|
12377
|
+
this.state.actionMenuOpen = false;
|
|
12378
|
+
this.render();
|
|
12379
|
+
}
|
|
12380
|
+
};
|
|
12381
|
+
moveSelection(delta) {
|
|
12382
|
+
const rowCount = this.state.actionMenuOpen ? machineManagerActions().length : rowCountForView(this.snapshot, this.state.view);
|
|
12383
|
+
if (rowCount === 0) {
|
|
12384
|
+
return;
|
|
12385
|
+
}
|
|
12386
|
+
if (this.state.actionMenuOpen) {
|
|
12387
|
+
this.state.selectedActionIndex = wrapIndex(this.state.selectedActionIndex + delta, rowCount);
|
|
12388
|
+
} else {
|
|
12389
|
+
this.state.selectedRowIndex = wrapIndex(this.state.selectedRowIndex + delta, rowCount);
|
|
12390
|
+
}
|
|
12391
|
+
this.render();
|
|
12392
|
+
}
|
|
12393
|
+
changeView(delta) {
|
|
12394
|
+
this.state.view = wrapIndex(this.state.view + delta, 5);
|
|
12395
|
+
this.state.selectedRowIndex = 0;
|
|
12396
|
+
this.state.actionMenuOpen = false;
|
|
12397
|
+
this.state.message = void 0;
|
|
12398
|
+
this.render();
|
|
12399
|
+
}
|
|
12400
|
+
async refresh(depth) {
|
|
12401
|
+
if (this.refreshing || this.stopped) {
|
|
12402
|
+
return;
|
|
12403
|
+
}
|
|
12404
|
+
this.refreshing = true;
|
|
12405
|
+
try {
|
|
12406
|
+
const snapshot = await collectMachineManagerSnapshot(this.store, depth);
|
|
12407
|
+
if (snapshot.checks.length > 0) {
|
|
12408
|
+
this.checks = snapshot.checks;
|
|
12409
|
+
}
|
|
12410
|
+
this.snapshot = {
|
|
12411
|
+
...snapshot,
|
|
12412
|
+
checks: this.checks
|
|
12413
|
+
};
|
|
12414
|
+
this.state.message = void 0;
|
|
12415
|
+
} catch (error) {
|
|
12416
|
+
this.state.message = errorMessage2(error);
|
|
12417
|
+
} finally {
|
|
12418
|
+
this.refreshing = false;
|
|
12419
|
+
this.render();
|
|
12420
|
+
}
|
|
12421
|
+
}
|
|
12422
|
+
render() {
|
|
12423
|
+
if (this.stopped || this.terminalSuspended || !process.stdout.isTTY) {
|
|
12424
|
+
return;
|
|
12425
|
+
}
|
|
12426
|
+
process.stdout.write(`${clearScreen}${renderMachineManager(this.snapshot, this.state, process.stdout.columns ?? 80, process.stdout.rows ?? 24)}`);
|
|
12427
|
+
}
|
|
12428
|
+
async executeSelectedAction() {
|
|
12429
|
+
const definition = machineManagerActions()[this.state.selectedActionIndex];
|
|
12430
|
+
this.state.actionMenuOpen = false;
|
|
12431
|
+
if (definition.action === MachineManagerAction.Quit) {
|
|
12432
|
+
this.stop();
|
|
12433
|
+
return;
|
|
12434
|
+
}
|
|
12435
|
+
if (definition.action === MachineManagerAction.Refresh) {
|
|
12436
|
+
await this.refresh(MachineManagerSnapshotDepth.Basic);
|
|
12437
|
+
return;
|
|
12438
|
+
}
|
|
12439
|
+
if (definition.action === MachineManagerAction.Doctor) {
|
|
12440
|
+
this.state.view = MachineManagerView.Doctor;
|
|
12441
|
+
await this.refresh(MachineManagerSnapshotDepth.WithDoctor);
|
|
12442
|
+
return;
|
|
12443
|
+
}
|
|
12444
|
+
if (definition.action === MachineManagerAction.Logs) {
|
|
12445
|
+
this.state.view = MachineManagerView.Logs;
|
|
12446
|
+
await this.refresh(MachineManagerSnapshotDepth.Basic);
|
|
12447
|
+
return;
|
|
12448
|
+
}
|
|
12449
|
+
await this.runCommandAction(definition.action);
|
|
12450
|
+
}
|
|
12451
|
+
async runCommandAction(action) {
|
|
12452
|
+
this.suspendTerminal();
|
|
12453
|
+
const reader = (0, import_promises10.createInterface)({
|
|
12454
|
+
input: process.stdin,
|
|
12455
|
+
output: process.stdout
|
|
12456
|
+
});
|
|
12457
|
+
try {
|
|
12458
|
+
const argumentsList = await this.buildCommandArguments(reader, action);
|
|
12459
|
+
if (argumentsList.length > 0) {
|
|
12460
|
+
await this.commandRunner.run(argumentsList);
|
|
12461
|
+
}
|
|
12462
|
+
} catch (error) {
|
|
12463
|
+
process.stdout.write(`
|
|
12464
|
+
Error: ${errorMessage2(error)}
|
|
12465
|
+
`);
|
|
12466
|
+
}
|
|
12467
|
+
await reader.question("\nPress Enter to return to the manager...");
|
|
12468
|
+
reader.close();
|
|
12469
|
+
this.resumeTerminal();
|
|
12470
|
+
await this.refresh(MachineManagerSnapshotDepth.Basic);
|
|
12471
|
+
}
|
|
12472
|
+
suspendTerminal() {
|
|
12473
|
+
this.terminalSuspended = true;
|
|
12474
|
+
process.stdin.off("keypress", this.onKeypress);
|
|
12475
|
+
process.stdout.off("resize", this.onResize);
|
|
12476
|
+
process.stdin.setRawMode(false);
|
|
12477
|
+
process.stdout.write(`${cursorShow}${styleReset}${alternateScreenExit}`);
|
|
12478
|
+
}
|
|
12479
|
+
resumeTerminal() {
|
|
12480
|
+
(0, import_node_readline.emitKeypressEvents)(process.stdin);
|
|
12481
|
+
process.stdin.setRawMode(true);
|
|
12482
|
+
process.stdin.resume();
|
|
12483
|
+
process.stdin.on("keypress", this.onKeypress);
|
|
12484
|
+
process.stdout.on("resize", this.onResize);
|
|
12485
|
+
process.stdout.write(`${alternateScreenEnter}${cursorHide}${clearScreen}`);
|
|
12486
|
+
this.terminalSuspended = false;
|
|
12487
|
+
}
|
|
12488
|
+
async buildCommandArguments(reader, action) {
|
|
12489
|
+
if (action === MachineManagerAction.Connect) {
|
|
12490
|
+
return await this.buildConnectArguments(reader);
|
|
12491
|
+
}
|
|
12492
|
+
if (action === MachineManagerAction.Disconnect) {
|
|
12493
|
+
return await this.buildDisconnectArguments(reader);
|
|
12494
|
+
}
|
|
12495
|
+
if (action === MachineManagerAction.ServiceInstall) {
|
|
12496
|
+
const manager = await questionWithDefault(reader, "Service manager (auto/systemd/supervisor/none)", "auto");
|
|
12497
|
+
return ["service", "install", "--service-manager", manager];
|
|
12498
|
+
}
|
|
12499
|
+
if (action === MachineManagerAction.ServiceRestart) {
|
|
12500
|
+
return ["service", "restart"];
|
|
12501
|
+
}
|
|
12502
|
+
if (action === MachineManagerAction.ServiceStop) {
|
|
12503
|
+
return ["service", "stop"];
|
|
12504
|
+
}
|
|
12505
|
+
if (action === MachineManagerAction.ServiceUninstall) {
|
|
12506
|
+
return ["service", "uninstall"];
|
|
12507
|
+
}
|
|
12508
|
+
return [];
|
|
12509
|
+
}
|
|
12510
|
+
async buildConnectArguments(reader) {
|
|
12511
|
+
const code = (await reader.question("Pairing code: ")).trim();
|
|
12512
|
+
if (code.length === 0) {
|
|
12513
|
+
throw new Error("Pairing code is required");
|
|
12514
|
+
}
|
|
12515
|
+
const root = await questionWithDefault(reader, "Working root", process.cwd());
|
|
12516
|
+
const relay = (await reader.question("Relay origin (leave blank for the default): ")).trim();
|
|
12517
|
+
const name = (await reader.question("Machine name (leave blank for the hostname): ")).trim();
|
|
12518
|
+
const serviceManager = await questionWithDefault(reader, "Service manager (auto/systemd/supervisor/none)", "auto");
|
|
12519
|
+
const noOpen = (await reader.question("Skip opening the confirmation page? [y/N]: ")).trim().toLowerCase();
|
|
12520
|
+
const argumentsList = [
|
|
12521
|
+
"connect",
|
|
12522
|
+
"--code",
|
|
12523
|
+
code,
|
|
12524
|
+
"--root",
|
|
12525
|
+
root,
|
|
12526
|
+
"--service-manager",
|
|
12527
|
+
serviceManager
|
|
12528
|
+
];
|
|
12529
|
+
appendOption(argumentsList, "--relay", relay);
|
|
12530
|
+
appendOption(argumentsList, "--name", name);
|
|
12531
|
+
if (noOpen === "y" || noOpen === "yes") {
|
|
12532
|
+
argumentsList.push("--no-open");
|
|
12533
|
+
}
|
|
12534
|
+
return argumentsList;
|
|
12535
|
+
}
|
|
12536
|
+
async buildDisconnectArguments(reader) {
|
|
12537
|
+
const selected = this.snapshot.connections[this.state.selectedRowIndex];
|
|
12538
|
+
const connectionId = await questionWithDefault(reader, "Connection ID", selected?.connectionId ?? "");
|
|
12539
|
+
if (connectionId.length === 0) {
|
|
12540
|
+
throw new Error("Connection ID is required");
|
|
12541
|
+
}
|
|
12542
|
+
const confirmed = (await reader.question(`Disconnect ${connectionId}? [y/N]: `)).trim().toLowerCase();
|
|
12543
|
+
if (confirmed !== "y" && confirmed !== "yes") {
|
|
12544
|
+
return [];
|
|
12545
|
+
}
|
|
12546
|
+
const localOnly = (await reader.question("Remove local state without contacting Moxt? [y/N]: ")).trim().toLowerCase();
|
|
12547
|
+
const argumentsList = ["disconnect", "--connection", connectionId];
|
|
12548
|
+
if (localOnly === "y" || localOnly === "yes") {
|
|
12549
|
+
argumentsList.push("--local-only");
|
|
12550
|
+
}
|
|
12551
|
+
return argumentsList;
|
|
12552
|
+
}
|
|
12553
|
+
stop() {
|
|
12554
|
+
if (this.stopped) {
|
|
12555
|
+
return;
|
|
12556
|
+
}
|
|
12557
|
+
this.stopped = true;
|
|
12558
|
+
this.resolveRun?.();
|
|
12559
|
+
}
|
|
12560
|
+
};
|
|
12561
|
+
}
|
|
12562
|
+
});
|
|
12563
|
+
|
|
11182
12564
|
// ../machine-connector/dist/runtime/device-identity.js
|
|
11183
12565
|
async function ensureMachineIdentity(store) {
|
|
11184
12566
|
const existingIdentity = (await store.readIdentity()).value;
|
|
@@ -11202,7 +12584,7 @@ async function ensureMachineIdentity(store) {
|
|
|
11202
12584
|
});
|
|
11203
12585
|
const identity = {
|
|
11204
12586
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
11205
|
-
deviceKeyFingerprint: (0,
|
|
12587
|
+
deviceKeyFingerprint: (0, import_node_crypto5.createHash)("sha256").update(keyPair.publicKey, "utf8").digest("hex"),
|
|
11206
12588
|
publicKeyPem: keyPair.publicKey
|
|
11207
12589
|
};
|
|
11208
12590
|
await store.writePrivateKey(keyPair.privateKey);
|
|
@@ -11218,12 +12600,12 @@ function decryptPairingCredentials(privateKeyPem, encryptedCredentials) {
|
|
|
11218
12600
|
if (envelope.version !== 1 || envelope.algorithm !== "RSA-OAEP-256+A256GCM") {
|
|
11219
12601
|
throw new Error("Unsupported Local Machine credentials envelope");
|
|
11220
12602
|
}
|
|
11221
|
-
const encryptionKey = (0,
|
|
12603
|
+
const encryptionKey = (0, import_node_crypto5.privateDecrypt)({
|
|
11222
12604
|
key: privateKeyPem,
|
|
11223
12605
|
oaepHash: "sha256",
|
|
11224
|
-
padding:
|
|
12606
|
+
padding: import_node_crypto5.constants.RSA_PKCS1_OAEP_PADDING
|
|
11225
12607
|
}, Buffer.from(envelope.encryptedKey, "base64url"));
|
|
11226
|
-
const decipher = (0,
|
|
12608
|
+
const decipher = (0, import_node_crypto5.createDecipheriv)("aes-256-gcm", encryptionKey, Buffer.from(envelope.initializationVector, "base64url"));
|
|
11227
12609
|
decipher.setAuthTag(Buffer.from(envelope.authenticationTag, "base64url"));
|
|
11228
12610
|
const decrypted = Buffer.concat([
|
|
11229
12611
|
decipher.update(Buffer.from(envelope.ciphertext, "base64url")),
|
|
@@ -11231,14 +12613,14 @@ function decryptPairingCredentials(privateKeyPem, encryptedCredentials) {
|
|
|
11231
12613
|
]);
|
|
11232
12614
|
return JSON.parse(decrypted.toString("utf8"));
|
|
11233
12615
|
}
|
|
11234
|
-
var
|
|
12616
|
+
var import_node_crypto5, import_node_util5, generateKeyPairAsync;
|
|
11235
12617
|
var init_device_identity = __esm({
|
|
11236
12618
|
"../machine-connector/dist/runtime/device-identity.js"() {
|
|
11237
12619
|
"use strict";
|
|
11238
12620
|
init_cjs_shims();
|
|
11239
|
-
|
|
12621
|
+
import_node_crypto5 = require("crypto");
|
|
11240
12622
|
import_node_util5 = require("util");
|
|
11241
|
-
generateKeyPairAsync = (0, import_node_util5.promisify)(
|
|
12623
|
+
generateKeyPairAsync = (0, import_node_util5.promisify)(import_node_crypto5.generateKeyPair);
|
|
11242
12624
|
}
|
|
11243
12625
|
});
|
|
11244
12626
|
|
|
@@ -11249,16 +12631,16 @@ async function pairMachine(store, options) {
|
|
|
11249
12631
|
const identity = await ensureMachineIdentity(store);
|
|
11250
12632
|
const machineName = options.machineName ?? (0, import_node_os8.hostname)();
|
|
11251
12633
|
const operatingSystem = getOperatingSystem();
|
|
11252
|
-
const rootHandle = (0,
|
|
12634
|
+
const rootHandle = (0, import_node_crypto6.createHash)("sha256").update(identity.identity.deviceKeyFingerprint, "utf8").update("\0").update(canonicalRoot, "utf8").digest("base64url");
|
|
11253
12635
|
const client = new PairingRelayClient(options.relayOrigin);
|
|
11254
12636
|
const proposal = await client.propose({
|
|
11255
12637
|
connectionCode: options.connectionCode,
|
|
11256
|
-
connectorVersion
|
|
12638
|
+
connectorVersion,
|
|
11257
12639
|
devicePublicKey: identity.identity.publicKeyPem,
|
|
11258
12640
|
machineName,
|
|
11259
12641
|
operatingSystem,
|
|
11260
12642
|
protocolVersion: machineProtocolVersion,
|
|
11261
|
-
rootDisplayName: (0,
|
|
12643
|
+
rootDisplayName: (0, import_node_path13.basename)(canonicalRoot),
|
|
11262
12644
|
rootHandle
|
|
11263
12645
|
});
|
|
11264
12646
|
options.onConfirmation?.(proposal.confirmationUrl);
|
|
@@ -11279,14 +12661,14 @@ async function pairMachine(store, options) {
|
|
|
11279
12661
|
accessToken: credentials.accessToken,
|
|
11280
12662
|
accessTokenExpiresAt: credentials.accessTokenExpiresAt,
|
|
11281
12663
|
connectionId: credentials.connectionId,
|
|
11282
|
-
connectorVersion
|
|
12664
|
+
connectorVersion,
|
|
11283
12665
|
heartbeatIntervalSeconds: credentials.heartbeatIntervalSeconds,
|
|
11284
12666
|
machineId: credentials.machineId,
|
|
11285
12667
|
machineName,
|
|
11286
12668
|
operatingSystem,
|
|
11287
12669
|
refreshToken: credentials.refreshToken,
|
|
11288
12670
|
relayOrigin: options.relayOrigin.replace(/\/+$/, ""),
|
|
11289
|
-
rootDisplayName: (0,
|
|
12671
|
+
rootDisplayName: (0, import_node_path13.basename)(canonicalRoot),
|
|
11290
12672
|
rootHandle,
|
|
11291
12673
|
rootPath: canonicalRoot,
|
|
11292
12674
|
targetId: credentials.targetId,
|
|
@@ -11325,16 +12707,17 @@ function delay4(milliseconds) {
|
|
|
11325
12707
|
setTimeout(resolvePromise, milliseconds);
|
|
11326
12708
|
});
|
|
11327
12709
|
}
|
|
11328
|
-
var import_node_child_process4,
|
|
12710
|
+
var import_node_child_process4, import_node_crypto6, import_node_os8, import_node_path13, connectedPairingStatus, rejectedPairingStatus, expiredPairingStatus, pairingPollMilliseconds;
|
|
11329
12711
|
var init_pairing = __esm({
|
|
11330
12712
|
"../machine-connector/dist/runtime/pairing.js"() {
|
|
11331
12713
|
"use strict";
|
|
11332
12714
|
init_cjs_shims();
|
|
11333
12715
|
import_node_child_process4 = require("child_process");
|
|
11334
|
-
|
|
12716
|
+
import_node_crypto6 = require("crypto");
|
|
11335
12717
|
import_node_os8 = require("os");
|
|
11336
|
-
|
|
12718
|
+
import_node_path13 = require("path");
|
|
11337
12719
|
init_contracts();
|
|
12720
|
+
init_version();
|
|
11338
12721
|
init_enums();
|
|
11339
12722
|
init_device_identity();
|
|
11340
12723
|
init_relay_client();
|
|
@@ -11511,12 +12894,12 @@ async function installUserService(store, request2, runtime = defaultServiceManag
|
|
|
11511
12894
|
}
|
|
11512
12895
|
function createServiceEnvironment(options) {
|
|
11513
12896
|
const inheritedPath = options.environment.PATH ?? process.env.PATH ?? "";
|
|
11514
|
-
const nodeDirectory = (0,
|
|
11515
|
-
const pathEntries = [nodeDirectory, ...inheritedPath.split(
|
|
12897
|
+
const nodeDirectory = (0, import_node_path14.dirname)(options.nodePath);
|
|
12898
|
+
const pathEntries = [nodeDirectory, ...inheritedPath.split(import_node_path14.delimiter)].filter((entry, index, entries) => entry.length > 0 && entries.indexOf(entry) === index);
|
|
11516
12899
|
return {
|
|
11517
12900
|
...options.environment,
|
|
11518
12901
|
HOME: options.environment.HOME ?? process.env.HOME ?? (0, import_node_os9.homedir)(),
|
|
11519
|
-
PATH: pathEntries.join(
|
|
12902
|
+
PATH: pathEntries.join(import_node_path14.delimiter)
|
|
11520
12903
|
};
|
|
11521
12904
|
}
|
|
11522
12905
|
async function restartUserService(store, runtime = defaultServiceManagerRuntime) {
|
|
@@ -11631,7 +13014,7 @@ async function uninstallManager(manager, store, runtime) {
|
|
|
11631
13014
|
"bootout",
|
|
11632
13015
|
`gui/${process.getuid?.() ?? 0}/${launchAgentLabel}`
|
|
11633
13016
|
]);
|
|
11634
|
-
await (0,
|
|
13017
|
+
await (0, import_promises11.rm)(launchAgentPath(), { force: true });
|
|
11635
13018
|
return;
|
|
11636
13019
|
}
|
|
11637
13020
|
if (manager === UserServiceManager.Systemd) {
|
|
@@ -11641,7 +13024,7 @@ async function uninstallManager(manager, store, runtime) {
|
|
|
11641
13024
|
"--now",
|
|
11642
13025
|
"moxt-machine-connector.service"
|
|
11643
13026
|
]);
|
|
11644
|
-
await (0,
|
|
13027
|
+
await (0, import_promises11.rm)(systemdUnitPath(), { force: true });
|
|
11645
13028
|
await runCommandIgnoringFailure(runtime, "systemctl", [
|
|
11646
13029
|
"--user",
|
|
11647
13030
|
"daemon-reload"
|
|
@@ -11655,7 +13038,7 @@ async function uninstallManager(manager, store, runtime) {
|
|
|
11655
13038
|
supervisorProgramName
|
|
11656
13039
|
]);
|
|
11657
13040
|
await runCommandIgnoringFailure(runtime, "supervisorctl", ["-c", supervisorConfigPath(store), "shutdown"]);
|
|
11658
|
-
await (0,
|
|
13041
|
+
await (0, import_promises11.rm)(supervisorDirectory(store), {
|
|
11659
13042
|
force: true,
|
|
11660
13043
|
recursive: true
|
|
11661
13044
|
});
|
|
@@ -11723,10 +13106,10 @@ function automaticSelectionDetail(manager) {
|
|
|
11723
13106
|
}
|
|
11724
13107
|
async function installLaunchAgent(store, options, runtime) {
|
|
11725
13108
|
const path10 = launchAgentPath();
|
|
11726
|
-
await (0,
|
|
13109
|
+
await (0, import_promises11.mkdir)((0, import_node_path14.dirname)(path10), { recursive: true });
|
|
11727
13110
|
const programArguments = [
|
|
11728
13111
|
options.nodePath,
|
|
11729
|
-
(0,
|
|
13112
|
+
(0, import_node_path14.resolve)(options.entrypointPath),
|
|
11730
13113
|
...options.commandArguments
|
|
11731
13114
|
];
|
|
11732
13115
|
const plist = `<?xml version="1.0" encoding="UTF-8"?>
|
|
@@ -11757,7 +13140,7 @@ ${Object.entries(options.environment).map(([name, value]) => ` <key>${escapeX
|
|
|
11757
13140
|
</dict>
|
|
11758
13141
|
</plist>
|
|
11759
13142
|
`;
|
|
11760
|
-
await (0,
|
|
13143
|
+
await (0, import_promises11.writeFile)(path10, plist, { encoding: "utf8", mode: 384 });
|
|
11761
13144
|
const domain = `gui/${process.getuid?.() ?? 0}`;
|
|
11762
13145
|
await runCommandIgnoringFailure(runtime, "launchctl", [
|
|
11763
13146
|
"bootout",
|
|
@@ -11773,10 +13156,10 @@ ${Object.entries(options.environment).map(([name, value]) => ` <key>${escapeX
|
|
|
11773
13156
|
}
|
|
11774
13157
|
async function installSystemdUserService(store, options, runtime) {
|
|
11775
13158
|
const path10 = systemdUnitPath();
|
|
11776
|
-
await (0,
|
|
13159
|
+
await (0, import_promises11.mkdir)((0, import_node_path14.dirname)(path10), { recursive: true });
|
|
11777
13160
|
const command = [
|
|
11778
13161
|
options.nodePath,
|
|
11779
|
-
(0,
|
|
13162
|
+
(0, import_node_path14.resolve)(options.entrypointPath),
|
|
11780
13163
|
...options.commandArguments
|
|
11781
13164
|
].map(escapeSystemdArgument).join(" ");
|
|
11782
13165
|
const unit = `[Unit]
|
|
@@ -11795,7 +13178,7 @@ ${Object.entries(options.environment).map(([name, value]) => `Environment=${esca
|
|
|
11795
13178
|
[Install]
|
|
11796
13179
|
WantedBy=default.target
|
|
11797
13180
|
`;
|
|
11798
|
-
await (0,
|
|
13181
|
+
await (0, import_promises11.writeFile)(path10, unit, { encoding: "utf8", mode: 384 });
|
|
11799
13182
|
await runtime.run("systemctl", ["--user", "daemon-reload"]);
|
|
11800
13183
|
await runtime.run("systemctl", [
|
|
11801
13184
|
"--user",
|
|
@@ -11811,15 +13194,15 @@ WantedBy=default.target
|
|
|
11811
13194
|
async function installSupervisorUserService(store, options, runtime) {
|
|
11812
13195
|
const directory = supervisorDirectory(store);
|
|
11813
13196
|
const configPath = supervisorConfigPath(store);
|
|
11814
|
-
await (0,
|
|
11815
|
-
await (0,
|
|
13197
|
+
await (0, import_promises11.mkdir)(directory, { recursive: true, mode: 448 });
|
|
13198
|
+
await (0, import_promises11.writeFile)(configPath, createSupervisorConfiguration(store, options), {
|
|
11816
13199
|
encoding: "utf8",
|
|
11817
13200
|
mode: 384
|
|
11818
13201
|
});
|
|
11819
13202
|
const supervisorWasRunning = await supervisorIsRunning(store, runtime);
|
|
11820
13203
|
if (!supervisorWasRunning) {
|
|
11821
|
-
await (0,
|
|
11822
|
-
await (0,
|
|
13204
|
+
await (0, import_promises11.rm)(supervisorSocketPath(store), { force: true });
|
|
13205
|
+
await (0, import_promises11.rm)(supervisorPidPath(store), { force: true });
|
|
11823
13206
|
await runtime.run("supervisord", ["-c", configPath]);
|
|
11824
13207
|
await waitForSupervisorControl(store, runtime);
|
|
11825
13208
|
return;
|
|
@@ -11831,7 +13214,7 @@ async function installSupervisorUserService(store, options, runtime) {
|
|
|
11831
13214
|
function createSupervisorConfiguration(store, options) {
|
|
11832
13215
|
const command = [
|
|
11833
13216
|
options.nodePath,
|
|
11834
|
-
(0,
|
|
13217
|
+
(0, import_node_path14.resolve)(options.entrypointPath),
|
|
11835
13218
|
...options.commandArguments
|
|
11836
13219
|
].map(escapeSupervisorArgument).join(" ");
|
|
11837
13220
|
const environment = Object.entries(options.environment).map(([name, value]) => `${name}="${escapeSupervisorEnvironment(value)}"`).join(",");
|
|
@@ -11855,7 +13238,7 @@ serverurl=unix://${supervisorSocketPath(store)}
|
|
|
11855
13238
|
|
|
11856
13239
|
[program:${supervisorProgramName}]
|
|
11857
13240
|
command=${command}
|
|
11858
|
-
directory=${escapeSupervisorPath((0,
|
|
13241
|
+
directory=${escapeSupervisorPath((0, import_node_path14.dirname)((0, import_node_path14.resolve)(options.entrypointPath)))}
|
|
11859
13242
|
environment=${environment}
|
|
11860
13243
|
autostart=true
|
|
11861
13244
|
autorestart=true
|
|
@@ -11876,8 +13259,8 @@ stderr_logfile_backups=3
|
|
|
11876
13259
|
async function restartSupervisorUserService(store, runtime) {
|
|
11877
13260
|
const configPath = supervisorConfigPath(store);
|
|
11878
13261
|
if (!await supervisorIsRunning(store, runtime)) {
|
|
11879
|
-
await (0,
|
|
11880
|
-
await (0,
|
|
13262
|
+
await (0, import_promises11.rm)(supervisorSocketPath(store), { force: true });
|
|
13263
|
+
await (0, import_promises11.rm)(supervisorPidPath(store), { force: true });
|
|
11881
13264
|
await runtime.run("supervisord", ["-c", configPath]);
|
|
11882
13265
|
await waitForSupervisorControl(store, runtime);
|
|
11883
13266
|
return;
|
|
@@ -11916,26 +13299,26 @@ async function waitForSupervisorControl(store, runtime) {
|
|
|
11916
13299
|
throw new Error("Supervisor did not become ready within 5 seconds");
|
|
11917
13300
|
}
|
|
11918
13301
|
function launchAgentPath() {
|
|
11919
|
-
return (0,
|
|
13302
|
+
return (0, import_node_path14.join)((0, import_node_os9.homedir)(), "Library", "LaunchAgents", `${launchAgentLabel}.plist`);
|
|
11920
13303
|
}
|
|
11921
13304
|
function systemdUnitPath() {
|
|
11922
|
-
const configHome = process.env.XDG_CONFIG_HOME ?? (0,
|
|
11923
|
-
return (0,
|
|
13305
|
+
const configHome = process.env.XDG_CONFIG_HOME ?? (0, import_node_path14.join)((0, import_node_os9.homedir)(), ".config");
|
|
13306
|
+
return (0, import_node_path14.join)(configHome, "systemd", "user", "moxt-machine-connector.service");
|
|
11924
13307
|
}
|
|
11925
13308
|
function supervisorDirectory(store) {
|
|
11926
|
-
return (0,
|
|
13309
|
+
return (0, import_node_path14.join)(store.baseDirectory, "supervisor");
|
|
11927
13310
|
}
|
|
11928
13311
|
function supervisorConfigPath(store) {
|
|
11929
|
-
return (0,
|
|
13312
|
+
return (0, import_node_path14.join)(supervisorDirectory(store), "supervisord.conf");
|
|
11930
13313
|
}
|
|
11931
13314
|
function supervisorSocketPath(store) {
|
|
11932
|
-
return (0,
|
|
13315
|
+
return (0, import_node_path14.join)(supervisorDirectory(store), "supervisor.sock");
|
|
11933
13316
|
}
|
|
11934
13317
|
function supervisorPidPath(store) {
|
|
11935
|
-
return (0,
|
|
13318
|
+
return (0, import_node_path14.join)(supervisorDirectory(store), "supervisord.pid");
|
|
11936
13319
|
}
|
|
11937
13320
|
function supervisorLogPath(store) {
|
|
11938
|
-
return (0,
|
|
13321
|
+
return (0, import_node_path14.join)(supervisorDirectory(store), "supervisord.log");
|
|
11939
13322
|
}
|
|
11940
13323
|
async function commandSucceeds(runtime, command, argumentsList) {
|
|
11941
13324
|
try {
|
|
@@ -11985,15 +13368,15 @@ function delay5(milliseconds) {
|
|
|
11985
13368
|
setTimeout(resolvePromise, milliseconds);
|
|
11986
13369
|
});
|
|
11987
13370
|
}
|
|
11988
|
-
var import_node_child_process5,
|
|
13371
|
+
var import_node_child_process5, import_promises11, import_node_os9, import_node_path14, import_node_util6, execFileAsync2, launchAgentLabel, supervisorProgramName, ServiceManagerPreference, UserServiceManager, defaultServiceManagerRuntime;
|
|
11989
13372
|
var init_service_manager = __esm({
|
|
11990
13373
|
"../machine-connector/dist/runtime/service-manager.js"() {
|
|
11991
13374
|
"use strict";
|
|
11992
13375
|
init_cjs_shims();
|
|
11993
13376
|
import_node_child_process5 = require("child_process");
|
|
11994
|
-
|
|
13377
|
+
import_promises11 = require("fs/promises");
|
|
11995
13378
|
import_node_os9 = require("os");
|
|
11996
|
-
|
|
13379
|
+
import_node_path14 = require("path");
|
|
11997
13380
|
import_node_util6 = require("util");
|
|
11998
13381
|
execFileAsync2 = (0, import_node_util6.promisify)(import_node_child_process5.execFile);
|
|
11999
13382
|
launchAgentLabel = "ai.moxt.machine-connector";
|
|
@@ -12051,6 +13434,14 @@ async function runMachineCli(argumentsList, entrypoint) {
|
|
|
12051
13434
|
await disconnectCommand(store, commandArguments);
|
|
12052
13435
|
return;
|
|
12053
13436
|
}
|
|
13437
|
+
if (command === "manager") {
|
|
13438
|
+
await runMachineManager(store, {
|
|
13439
|
+
run: async (managerArguments) => {
|
|
13440
|
+
await runMachineCli(managerArguments, entrypoint);
|
|
13441
|
+
}
|
|
13442
|
+
});
|
|
13443
|
+
return;
|
|
13444
|
+
}
|
|
12054
13445
|
if (command === "daemon") {
|
|
12055
13446
|
await daemonCommand(store);
|
|
12056
13447
|
return;
|
|
@@ -12064,7 +13455,7 @@ async function runMachineCli(argumentsList, entrypoint) {
|
|
|
12064
13455
|
async function connectCommand(store, argumentsList, entrypoint) {
|
|
12065
13456
|
const options = parseOptions(argumentsList);
|
|
12066
13457
|
const connectionCode = requiredOption(options, "code");
|
|
12067
|
-
const rootPath = (0,
|
|
13458
|
+
const rootPath = (0, import_node_path15.resolve)(options.root ?? process.cwd());
|
|
12068
13459
|
const serviceManagerPreference = requestedServiceManagerPreference(options);
|
|
12069
13460
|
await validateExplicitServiceManagerPreference(serviceManagerPreference);
|
|
12070
13461
|
writeLine("Internal Full Host Access: enabled");
|
|
@@ -12154,8 +13545,8 @@ async function statusCommand(store, argumentsList) {
|
|
|
12154
13545
|
async function logsCommand(store, argumentsList) {
|
|
12155
13546
|
const options = parseOptions(argumentsList);
|
|
12156
13547
|
const lines = Number(options.lines ?? "100");
|
|
12157
|
-
const normalLog = await
|
|
12158
|
-
const errorLog = await
|
|
13548
|
+
const normalLog = await readOptionalFile2(store.runtimeLogPath());
|
|
13549
|
+
const errorLog = await readOptionalFile2(store.runtimeErrorLogPath());
|
|
12159
13550
|
writeLine([...normalLog.split("\n"), ...errorLog.split("\n")].filter((line) => line.length > 0).slice(-lines).join("\n"));
|
|
12160
13551
|
}
|
|
12161
13552
|
async function doctorCommand(store, argumentsList) {
|
|
@@ -12298,9 +13689,9 @@ async function waitForDaemonOnline(store) {
|
|
|
12298
13689
|
}
|
|
12299
13690
|
throw new Error("The service was installed but the Connector did not become online within 30 seconds");
|
|
12300
13691
|
}
|
|
12301
|
-
async function
|
|
13692
|
+
async function readOptionalFile2(path10) {
|
|
12302
13693
|
try {
|
|
12303
|
-
return await (0,
|
|
13694
|
+
return await (0, import_promises12.readFile)(path10, "utf8");
|
|
12304
13695
|
} catch {
|
|
12305
13696
|
return "";
|
|
12306
13697
|
}
|
|
@@ -12314,6 +13705,7 @@ Usage:
|
|
|
12314
13705
|
moxt machine logs [--lines 100]
|
|
12315
13706
|
moxt machine doctor [--json]
|
|
12316
13707
|
moxt machine disconnect --connection <id> [--local-only]
|
|
13708
|
+
moxt machine manager
|
|
12317
13709
|
moxt machine service install [--service-manager <auto|systemd|supervisor|none>]
|
|
12318
13710
|
moxt machine service <restart|stop|uninstall>
|
|
12319
13711
|
`);
|
|
@@ -12327,16 +13719,17 @@ function delay6(milliseconds) {
|
|
|
12327
13719
|
setTimeout(resolvePromise, milliseconds);
|
|
12328
13720
|
});
|
|
12329
13721
|
}
|
|
12330
|
-
var
|
|
13722
|
+
var import_promises12, import_node_path15, defaultRelayOrigin;
|
|
12331
13723
|
var init_cli = __esm({
|
|
12332
13724
|
"../machine-connector/dist/cli.js"() {
|
|
12333
13725
|
"use strict";
|
|
12334
13726
|
init_cjs_shims();
|
|
12335
|
-
|
|
12336
|
-
|
|
13727
|
+
import_promises12 = require("fs/promises");
|
|
13728
|
+
import_node_path15 = require("path");
|
|
12337
13729
|
init_daemon();
|
|
12338
13730
|
init_doctor();
|
|
12339
13731
|
init_local_ipc();
|
|
13732
|
+
init_machine_manager();
|
|
12340
13733
|
init_pairing();
|
|
12341
13734
|
init_relay_client();
|
|
12342
13735
|
init_service_manager();
|
|
@@ -12350,6 +13743,7 @@ var dist_exports = {};
|
|
|
12350
13743
|
__export(dist_exports, {
|
|
12351
13744
|
DoctorCheckStatus: () => DoctorCheckStatus,
|
|
12352
13745
|
LocalIpcServer: () => LocalIpcServer,
|
|
13746
|
+
MachineClaudePermissionMode: () => MachineClaudePermissionMode,
|
|
12353
13747
|
MachineCodexPermissionMode: () => MachineCodexPermissionMode,
|
|
12354
13748
|
MachineConnectionStatus: () => MachineConnectionStatus,
|
|
12355
13749
|
MachineConnectionTargetKind: () => MachineConnectionTargetKind,
|
|
@@ -12360,6 +13754,9 @@ __export(dist_exports, {
|
|
|
12360
13754
|
MachineJobOutputStream: () => MachineJobOutputStream,
|
|
12361
13755
|
MachineJobStatus: () => MachineJobStatus,
|
|
12362
13756
|
MachineJobWakeReason: () => MachineJobWakeReason,
|
|
13757
|
+
MachineManagerAction: () => MachineManagerAction,
|
|
13758
|
+
MachineManagerSnapshotDepth: () => MachineManagerSnapshotDepth,
|
|
13759
|
+
MachineManagerView: () => MachineManagerView,
|
|
12363
13760
|
MachineOperatingSystem: () => MachineOperatingSystem,
|
|
12364
13761
|
MachinePairingDecision: () => MachinePairingDecision,
|
|
12365
13762
|
MachinePairingStatus: () => MachinePairingStatus,
|
|
@@ -12379,20 +13776,27 @@ __export(dist_exports, {
|
|
|
12379
13776
|
assertRelativeWorkingDirectory: () => assertRelativeWorkingDirectory,
|
|
12380
13777
|
assertValidJobTransition: () => assertValidJobTransition,
|
|
12381
13778
|
assertWaitTimeout: () => assertWaitTimeout,
|
|
13779
|
+
collectMachineManagerSnapshot: () => collectMachineManagerSnapshot,
|
|
12382
13780
|
createServiceEnvironment: () => createServiceEnvironment,
|
|
12383
13781
|
createSupervisorConfiguration: () => createSupervisorConfiguration,
|
|
12384
13782
|
defaultRuntimeDirectory: () => defaultRuntimeDirectory,
|
|
12385
13783
|
detectServiceManagerCapabilities: () => detectServiceManagerCapabilities,
|
|
13784
|
+
ensureInteractiveTerminal: () => ensureInteractiveTerminal,
|
|
13785
|
+
executeClaudeReply: () => executeClaudeReply,
|
|
13786
|
+
executeClaudeStart: () => executeClaudeStart,
|
|
12386
13787
|
installUserService: () => installUserService,
|
|
12387
13788
|
isTerminalJobStatus: () => isTerminalJobStatus,
|
|
13789
|
+
machineManagerActions: () => machineManagerActions,
|
|
12388
13790
|
machineProtocolVersion: () => machineProtocolVersion,
|
|
12389
13791
|
pairMachine: () => pairMachine,
|
|
12390
13792
|
parseServiceManagerPreference: () => parseServiceManagerPreference,
|
|
13793
|
+
renderMachineManager: () => renderMachineManager,
|
|
12391
13794
|
requestRuntimeStatus: () => requestRuntimeStatus,
|
|
12392
13795
|
resolveWorkingDirectory: () => resolveWorkingDirectory,
|
|
12393
13796
|
restartUserService: () => restartUserService,
|
|
12394
13797
|
runMachineCli: () => runMachineCli,
|
|
12395
13798
|
runMachineDoctor: () => runMachineDoctor,
|
|
13799
|
+
runMachineManager: () => runMachineManager,
|
|
12396
13800
|
selectUserServiceManager: () => selectUserServiceManager,
|
|
12397
13801
|
stopUserService: () => stopUserService,
|
|
12398
13802
|
uninstallUserService: () => uninstallUserService,
|
|
@@ -12405,8 +13809,10 @@ var init_dist = __esm({
|
|
|
12405
13809
|
init_v1();
|
|
12406
13810
|
init_cli();
|
|
12407
13811
|
init_daemon();
|
|
13812
|
+
init_claude_executor();
|
|
12408
13813
|
init_doctor();
|
|
12409
13814
|
init_local_ipc();
|
|
13815
|
+
init_machine_manager();
|
|
12410
13816
|
init_pairing();
|
|
12411
13817
|
init_relay_client();
|
|
12412
13818
|
init_runtime_types();
|
|
@@ -12516,7 +13922,7 @@ var retryifyAsync = (fn, options) => {
|
|
|
12516
13922
|
throw error;
|
|
12517
13923
|
const delay7 = Math.round(interval * Math.random());
|
|
12518
13924
|
if (delay7 > 0) {
|
|
12519
|
-
const delayPromise = new Promise((
|
|
13925
|
+
const delayPromise = new Promise((resolve5) => setTimeout(resolve5, delay7));
|
|
12520
13926
|
return delayPromise.then(() => attempt.apply(void 0, args));
|
|
12521
13927
|
} else {
|
|
12522
13928
|
return attempt.apply(void 0, args);
|
|
@@ -14132,14 +15538,14 @@ var TimeoutError = class extends Error {
|
|
|
14132
15538
|
|
|
14133
15539
|
// node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/utils/timeout.js
|
|
14134
15540
|
async function timeout(request2, init, abortController, options) {
|
|
14135
|
-
return new Promise((
|
|
15541
|
+
return new Promise((resolve5, reject) => {
|
|
14136
15542
|
const timeoutId = setTimeout(() => {
|
|
14137
15543
|
if (abortController) {
|
|
14138
15544
|
abortController.abort();
|
|
14139
15545
|
}
|
|
14140
15546
|
reject(new TimeoutError(request2));
|
|
14141
15547
|
}, options.timeout);
|
|
14142
|
-
void options.fetch(request2, init).then(
|
|
15548
|
+
void options.fetch(request2, init).then(resolve5).catch(reject).then(() => {
|
|
14143
15549
|
clearTimeout(timeoutId);
|
|
14144
15550
|
});
|
|
14145
15551
|
});
|
|
@@ -14148,7 +15554,7 @@ async function timeout(request2, init, abortController, options) {
|
|
|
14148
15554
|
// node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/utils/delay.js
|
|
14149
15555
|
init_cjs_shims();
|
|
14150
15556
|
async function delay(ms, { signal }) {
|
|
14151
|
-
return new Promise((
|
|
15557
|
+
return new Promise((resolve5, reject) => {
|
|
14152
15558
|
if (signal) {
|
|
14153
15559
|
signal.throwIfAborted();
|
|
14154
15560
|
signal.addEventListener("abort", abortHandler, { once: true });
|
|
@@ -14159,7 +15565,7 @@ async function delay(ms, { signal }) {
|
|
|
14159
15565
|
}
|
|
14160
15566
|
const timeoutId = setTimeout(() => {
|
|
14161
15567
|
signal?.removeEventListener("abort", abortHandler);
|
|
14162
|
-
|
|
15568
|
+
resolve5();
|
|
14163
15569
|
}, ms);
|
|
14164
15570
|
});
|
|
14165
15571
|
}
|
|
@@ -16067,7 +17473,7 @@ function getApiKeyOrUndefined() {
|
|
|
16067
17473
|
|
|
16068
17474
|
// src/utils/http.ts
|
|
16069
17475
|
function getUserAgent() {
|
|
16070
|
-
return `moxt-cli/${"0.8.0-beta.
|
|
17476
|
+
return `moxt-cli/${"0.8.0-beta.2"} (${(0, import_os2.platform)()}/${(0, import_os2.arch)()}) node/${process.versions.node}`;
|
|
16071
17477
|
}
|
|
16072
17478
|
async function fetchApi(method, path10, body) {
|
|
16073
17479
|
const apiKey = getApiKey();
|
|
@@ -16234,8 +17640,8 @@ function readCommentContentFile(path10) {
|
|
|
16234
17640
|
if (!fs5.existsSync(path10)) {
|
|
16235
17641
|
throw new FileCommentOptionsError(`Error: comment content file not found: ${path10}`);
|
|
16236
17642
|
}
|
|
16237
|
-
const
|
|
16238
|
-
if (!
|
|
17643
|
+
const stat2 = fs5.statSync(path10);
|
|
17644
|
+
if (!stat2.isFile()) {
|
|
16239
17645
|
throw new FileCommentOptionsError(`Error: comment content path is not a file: ${path10}`);
|
|
16240
17646
|
}
|
|
16241
17647
|
const buffer2 = fs5.readFileSync(path10);
|
|
@@ -16754,9 +18160,9 @@ function registerMachineCommand(program3) {
|
|
|
16754
18160
|
"--root",
|
|
16755
18161
|
options.root ?? process.cwd()
|
|
16756
18162
|
];
|
|
16757
|
-
|
|
16758
|
-
|
|
16759
|
-
|
|
18163
|
+
appendOption2(argumentsList, "--relay", options.relay);
|
|
18164
|
+
appendOption2(argumentsList, "--name", options.name);
|
|
18165
|
+
appendOption2(
|
|
16760
18166
|
argumentsList,
|
|
16761
18167
|
"--service-manager",
|
|
16762
18168
|
options.serviceManager
|
|
@@ -16773,11 +18179,7 @@ function registerMachineCommand(program3) {
|
|
|
16773
18179
|
]);
|
|
16774
18180
|
});
|
|
16775
18181
|
machine.command("logs").description("Show recent Connector logs").option("--lines <count>", "Number of lines", "100").action(async (options) => {
|
|
16776
|
-
await runConnectorCli([
|
|
16777
|
-
"logs",
|
|
16778
|
-
"--lines",
|
|
16779
|
-
options.lines ?? "100"
|
|
16780
|
-
]);
|
|
18182
|
+
await runConnectorCli(["logs", "--lines", options.lines ?? "100"]);
|
|
16781
18183
|
});
|
|
16782
18184
|
machine.command("doctor").description("Diagnose the Local Machine connection").option("--json", "Emit machine-readable JSON").action(async (options) => {
|
|
16783
18185
|
await runConnectorCli([
|
|
@@ -16799,6 +18201,9 @@ function registerMachineCommand(program3) {
|
|
|
16799
18201
|
}
|
|
16800
18202
|
await runConnectorCli(argumentsList);
|
|
16801
18203
|
});
|
|
18204
|
+
machine.command("manager").description("Open the interactive Local Machine manager").action(async () => {
|
|
18205
|
+
await runConnectorCli(["manager"]);
|
|
18206
|
+
});
|
|
16802
18207
|
machine.command("service").description("Manage the user-level Connector service").argument("<action>", "install, restart, stop, or uninstall").addOption(
|
|
16803
18208
|
new Option(
|
|
16804
18209
|
"--service-manager <manager>",
|
|
@@ -16806,7 +18211,7 @@ function registerMachineCommand(program3) {
|
|
|
16806
18211
|
).choices(["auto", "systemd", "supervisor", "none"]).default("auto")
|
|
16807
18212
|
).action(async (action, options) => {
|
|
16808
18213
|
const argumentsList = ["service", action];
|
|
16809
|
-
|
|
18214
|
+
appendOption2(
|
|
16810
18215
|
argumentsList,
|
|
16811
18216
|
"--service-manager",
|
|
16812
18217
|
options.serviceManager
|
|
@@ -16826,7 +18231,7 @@ async function runConnectorCli(argumentsList) {
|
|
|
16826
18231
|
nodePath: process.execPath
|
|
16827
18232
|
});
|
|
16828
18233
|
}
|
|
16829
|
-
function
|
|
18234
|
+
function appendOption2(argumentsList, flag, value) {
|
|
16830
18235
|
if (value) {
|
|
16831
18236
|
argumentsList.push(flag, value);
|
|
16832
18237
|
}
|
|
@@ -17295,8 +18700,8 @@ function readDescFile(path10) {
|
|
|
17295
18700
|
if (!fs8.existsSync(path10)) {
|
|
17296
18701
|
throw new WorkflowOptionsError(`Error: desc file not found: ${path10}`);
|
|
17297
18702
|
}
|
|
17298
|
-
const
|
|
17299
|
-
if (!
|
|
18703
|
+
const stat2 = fs8.statSync(path10);
|
|
18704
|
+
if (!stat2.isFile()) {
|
|
17300
18705
|
throw new WorkflowOptionsError(`Error: desc file is not a file: ${path10}`);
|
|
17301
18706
|
}
|
|
17302
18707
|
const buffer2 = fs8.readFileSync(path10);
|
|
@@ -17313,11 +18718,11 @@ function readCommentContentFile2(path10) {
|
|
|
17313
18718
|
if (!fs8.existsSync(path10)) {
|
|
17314
18719
|
throw new WorkflowOptionsError(`Error: comment content file not found: ${path10}`);
|
|
17315
18720
|
}
|
|
17316
|
-
const
|
|
17317
|
-
if (!
|
|
18721
|
+
const stat2 = fs8.statSync(path10);
|
|
18722
|
+
if (!stat2.isFile()) {
|
|
17318
18723
|
throw new WorkflowOptionsError(`Error: comment content path is not a file: ${path10}`);
|
|
17319
18724
|
}
|
|
17320
|
-
if (
|
|
18725
|
+
if (stat2.size > MAX_COMMENT_CONTENT_BYTES) {
|
|
17321
18726
|
throw new WorkflowOptionsError(
|
|
17322
18727
|
`Error: comment content file must be at most ${MAX_COMMENT_CONTENT_LENGTH} characters.`
|
|
17323
18728
|
);
|
|
@@ -18229,7 +19634,7 @@ var FLUSH_TIMEOUT_MS = 3e3;
|
|
|
18229
19634
|
var MAX_BATCH_SIZE = 100;
|
|
18230
19635
|
function commonLabels() {
|
|
18231
19636
|
return {
|
|
18232
|
-
cli_version: "0.8.0-beta.
|
|
19637
|
+
cli_version: "0.8.0-beta.2",
|
|
18233
19638
|
node_version: process.versions.node,
|
|
18234
19639
|
os: (0, import_node_os10.platform)(),
|
|
18235
19640
|
arch: (0, import_node_os10.arch)(),
|
|
@@ -18275,7 +19680,7 @@ async function flush() {
|
|
|
18275
19680
|
}
|
|
18276
19681
|
const batch = buffer.splice(0, MAX_BATCH_SIZE);
|
|
18277
19682
|
const payload = {
|
|
18278
|
-
release_id: "0.8.0-beta.
|
|
19683
|
+
release_id: "0.8.0-beta.2",
|
|
18279
19684
|
client_type: "cli",
|
|
18280
19685
|
metric_data_list: batch.map((m) => ({
|
|
18281
19686
|
profile: "cli",
|
|
@@ -18420,9 +19825,9 @@ function installExitHandler() {
|
|
|
18420
19825
|
|
|
18421
19826
|
// src/index.ts
|
|
18422
19827
|
updateNotifier({
|
|
18423
|
-
pkg: { name: "@moxt-ai/cli", version: "0.8.0-beta.
|
|
19828
|
+
pkg: { name: "@moxt-ai/cli", version: "0.8.0-beta.2" }
|
|
18424
19829
|
}).notify();
|
|
18425
|
-
var program2 = createProgram("0.8.0-beta.
|
|
19830
|
+
var program2 = createProgram("0.8.0-beta.2");
|
|
18426
19831
|
instrumentProgram(program2);
|
|
18427
19832
|
installExitHandler();
|
|
18428
19833
|
program2.parseAsync(process.argv).then(async () => {
|